diff --git a/application/Account.cpp b/application/Account.cpp index 82299fd..ed8d6f1 100644 --- a/application/Account.cpp +++ b/application/Account.cpp @@ -31,11 +31,13 @@ Account::Account(bigtime_t instanceId, ChatProtocol* cayap, fProtocol->Init(this); // Find user's settings path - BPath path(AccountPath(addOnSignature, fProtocol->Signature())); + BPath path = AccountPath(addOnSignature, fProtocol->Signature()); if (path.InitCheck() == B_OK) { path.Append(name); fProtocol->SetName(name); + fProtocol->SetAccountCachePath(AccountCachePath(name)); + fProtocol->SetAddOnCachePath(AddOnCachePath(addOnSignature)); // Load settings file BFile file(path.Path(), B_READ_ONLY); diff --git a/application/ChatProtocol.h b/application/ChatProtocol.h index 722bb61..36c7f5c 100644 --- a/application/ChatProtocol.h +++ b/application/ChatProtocol.h @@ -88,9 +88,11 @@ public: //! Protocol icon virtual BBitmap* Icon() const { return NULL; } - //! Add-on's path - virtual void SetAddOnPath(BPath path) = 0; + //! Pertinent paths virtual BPath AddOnPath() = 0; + virtual void SetAddOnPath(BPath path) = 0; + virtual void SetAccountCachePath(BPath path) { }; + virtual void SetAddOnCachePath(BPath path) { }; //! Name of account file (leaf) virtual const char* GetName() = 0; diff --git a/application/ChatProtocolAddOn.cpp b/application/ChatProtocolAddOn.cpp index 0e0fffd..2fa16fe 100644 --- a/application/ChatProtocolAddOn.cpp +++ b/application/ChatProtocolAddOn.cpp @@ -52,7 +52,7 @@ ChatProtocol* ChatProtocolAddOn::ProtocolAt(int32 i) const { ChatProtocol* proto = fGetProtocol(i); - proto->SetAddOnPath(BPath(fPath.String())); + proto->SetAddOnPath(fPath.String()); return proto; } diff --git a/application/Contact.cpp b/application/Contact.cpp index 0ad3d9b..bb1f374 100644 --- a/application/Contact.cpp +++ b/application/Contact.cpp @@ -35,8 +35,5 @@ Contact::_EnsureCachePath() { if (fCachePath.InitCheck() == B_OK) return; - fCachePath.SetTo(ContactCachePath(fLooper->Protocol()->GetName(), - fID.String())); + fCachePath = ContactCachePath(fLooper->Protocol()->GetName(), fID.String()); } - - diff --git a/application/Conversation.cpp b/application/Conversation.cpp index e4ccdc0..c1410fc 100644 --- a/application/Conversation.cpp +++ b/application/Conversation.cpp @@ -636,8 +636,7 @@ Conversation::_EnsureCachePath() { if (fCachePath.InitCheck() == B_OK) return; - fCachePath.SetTo(RoomCachePath(fLooper->Protocol()->GetName(), - fID.String())); + fCachePath = RoomCachePath(fLooper->Protocol()->GetName(), fID.String()); } diff --git a/application/ProtocolSettings.cpp b/application/ProtocolSettings.cpp index 749e281..ef29129 100644 --- a/application/ProtocolSettings.cpp +++ b/application/ProtocolSettings.cpp @@ -49,7 +49,7 @@ ProtocolSettings::Accounts() const { BObjectList list(true); - BPath path(AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature())); + BPath path = AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()); if (path.InitCheck() != B_OK) return list; @@ -93,7 +93,7 @@ ProtocolSettings::Load(const char* account, BMessage** settings) status_t ret = B_ERROR; // Find user's settings path - BPath path(AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature())); + BPath path = AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()); if ((ret = path.InitCheck()) != B_OK) return ret; @@ -127,7 +127,7 @@ status_t ProtocolSettings::Save(const char* account, BMessage settings) { // Find user's settings path - BPath path(AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature())); + BPath path = AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()); status_t ret; if ((ret = path.InitCheck()) != B_OK) @@ -146,7 +146,7 @@ ProtocolSettings::Rename(const char* from, const char* to) status_t ret = B_ERROR; // Find user's settings path - BPath path(AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature())); + BPath path = AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()); if ((ret = path.InitCheck()) != B_OK) return ret; @@ -168,7 +168,7 @@ ProtocolSettings::Delete(const char* account) status_t ret = B_ERROR; // Find user's settings path - BPath path(AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature())); + BPath path = AccountPath(fAddOn->Signature(), fAddOn->ProtoSignature()); if ((ret = path.InitCheck()) != B_OK) return ret; diff --git a/application/Server.cpp b/application/Server.cpp index 4743c1e..09dfd23 100644 --- a/application/Server.cpp +++ b/application/Server.cpp @@ -627,7 +627,7 @@ Server::ImMessage(BMessage* msg) // Join cached rooms BEntry entry; char fileName[B_FILE_NAME_LENGTH] = {'\0'}; - BDirectory dir(RoomsCachePath(looper->Protocol()->GetName())); + BDirectory dir(RoomsCachePath(looper->Protocol()->GetName()).Path()); while (dir.GetNextEntry(&entry, true) == B_OK) if (entry.GetName(fileName) == B_OK) { diff --git a/application/User.cpp b/application/User.cpp index aa1785c..a860c28 100644 --- a/application/User.cpp +++ b/application/User.cpp @@ -227,8 +227,7 @@ User::_EnsureCachePath() { if (fCachePath.InitCheck() == B_OK) return; - fCachePath.SetTo(UserCachePath(fLooper->Protocol()->GetName(), - fID.String())); + fCachePath = UserCachePath(fLooper->Protocol()->GetName(), fID.String()); } diff --git a/application/Utils.cpp b/application/Utils.cpp index 80a2c3d..b42af5d 100644 --- a/application/Utils.cpp +++ b/application/Utils.cpp @@ -150,88 +150,104 @@ AccountPath(const char* signature, const char* subsignature) } -const char* +BPath CachePath() { - BPath path(SettingsPath()); - if (path.InitCheck() != B_OK) - return NULL; - - path.Append("Cache"); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - return path.Path(); + BPath path = SettingsPath(); + path.Append("Cache/"); + create_directory(path.Path(), 0755); + return path; } -const char* +BPath AccountCachePath(const char* accountName) { - BPath path(CachePath()); - path.Append("Accounts"); - if (path.InitCheck() != B_OK) - return NULL; - + BPath path = CachePath(); + path.Append("Accounts/"); path.Append(accountName); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - return path.Path(); + create_directory(path.Path(), 0755); + return path; } -const char* +BPath RoomsCachePath(const char* accountName) { - BPath path(AccountCachePath(accountName)); - if (path.InitCheck() != B_OK) - return NULL; - - path.Append("Rooms"); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - return path.Path(); + return RoomsCachePath(AccountCachePath(accountName)); } -const char* +BPath +RoomsCachePath(BPath accPath) +{ + accPath.Append("Rooms/"); + create_directory(accPath.Path(), 0755); + return accPath; +} + + +BPath RoomCachePath(const char* accountName, const char* roomIdentifier) { - BPath path(RoomsCachePath(accountName)); - if (path.InitCheck() != B_OK) - return NULL; - - path.Append(roomIdentifier); - return path.Path(); + return RoomCachePath(AccountCachePath(accountName), roomIdentifier); } -const char* +BPath +RoomCachePath(BPath accPath, const char* roomIdentifier) +{ + BPath path = RoomsCachePath(accPath); + path.Append(roomIdentifier); + return path; +} + + +BPath UserCachePath(const char* accountName, const char* userIdentifier) { - BPath path(AccountCachePath(accountName)); - if (path.InitCheck() != B_OK) - return NULL; - - path.Append("Users"); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - path.Append(userIdentifier); - return path.Path(); + return UserCachePath(AccountCachePath(accountName), userIdentifier); } -const char* +BPath +UserCachePath(BPath accPath, const char* userIdentifier) +{ + accPath.Append("Users/"); + create_directory(accPath.Path(), 0755); + + accPath.Append(userIdentifier); + return accPath; +} + + +BPath ContactCachePath(const char* accountName, const char* userIdentifier) { - BPath path(AccountCachePath(accountName)); - if (path.InitCheck() != B_OK) - return NULL; - path.Append("Contacts"); + return ContactCachePath(AccountCachePath(accountName), userIdentifier); +} - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - path.Append(userIdentifier); - return path.Path(); + +BPath +ContactCachePath(BPath accPath, const char* userIdentifier) +{ + accPath.Append("Contacts/"); + create_directory(accPath.Path(), 0755); + + accPath.Append(userIdentifier); + return accPath; +} + + +BPath +AddOnCachePath(const char* signature) +{ + BPath path = CachePath(); + path.Append("Add-Ons/"); + path.Append(signature); + + create_directory(path.Path(), 0755); + return path; } diff --git a/application/Utils.h b/application/Utils.h index ec88b82..6f0fc81 100644 --- a/application/Utils.h +++ b/application/Utils.h @@ -36,12 +36,17 @@ const char* SettingsPath(); const char* AccountsPath(); const char* AccountPath(const char* signature, const char* subsignature); -const char* CachePath(); -const char* AccountCachePath(const char* accountName); -const char* RoomsCachePath(const char* accountName); -const char* RoomCachePath(const char* accountName, const char* roomIdentifier); -const char* UserCachePath(const char* accountName, const char* userIdentifier); -const char* ContactCachePath(const char* accountName, const char* userIdentifier); +BPath CachePath(); +BPath AccountCachePath(const char* accountName); +BPath RoomsCachePath(const char* accountName); +BPath RoomsCachePath(BPath accPath); +BPath RoomCachePath(const char* accountName, const char* roomIdentifier); +BPath RoomCachePath(BPath accPath, const char* roomIdentifier); +BPath UserCachePath(const char* accountName, const char* userIdentifier); +BPath UserCachePath(BPath accPath, const char* userIdentifier); +BPath ContactCachePath(const char* accountName, const char* userIdentifier); +BPath ContactCachePath(BPath accPath, const char* userIdentifier); +BPath AddOnCachePath(const char* signature); rgb_color TintColor(rgb_color color, int severity); rgb_color ForegroundColor(rgb_color background); @@ -55,4 +60,3 @@ extern "C" status_t our_image(image_info& image); #endif // _APP_UTILS_H - diff --git a/protocols/irc/IrcProtocol.cpp b/protocols/irc/IrcProtocol.cpp index 694b692..6f79088 100644 --- a/protocols/irc/IrcProtocol.cpp +++ b/protocols/irc/IrcProtocol.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2021, Jaidyn Levesque + * Copyright 2021-2022, Jaidyn Levesque * Copyright 2017, Akshay Agarwal * All rights reserved. Distributed under the terms of the MIT license. */ @@ -37,7 +37,7 @@ connect_thread(void* data) IrcProtocol* protocol = (IrcProtocol*)data; protocol->Connect(); status_t status = protocol->Loop(); - exit(status); + return status; } @@ -1275,7 +1275,7 @@ IrcProtocol::_RoleTitle(UserRole role) const char* IrcProtocol::_ContactsCache() { - BPath path(AccountCachePath(fName)); + BPath path(fCachePath); path.Append("contact_list"); return path.Path(); } @@ -1286,7 +1286,7 @@ IrcProtocol::_JoinDefaultRooms() { // Hardcoded default room… I'm so awful, aren't I? ;-) if (fServer == "irc.oftc.net") { - BFile room(RoomCachePath(fName, "#haiku"), B_READ_ONLY); + BFile room(RoomCachePath(fCachePath, "#haiku").Path(), B_READ_ONLY); if (room.InitCheck() != B_OK) { BString cmd("JOIN #haiku"); _SendIrc(cmd); diff --git a/protocols/irc/IrcProtocol.h b/protocols/irc/IrcProtocol.h index aee40c6..384dd58 100644 --- a/protocols/irc/IrcProtocol.h +++ b/protocols/irc/IrcProtocol.h @@ -1,5 +1,5 @@ /* - * Copyright 2021, Jaidyn Levesque + * Copyright 2021-2022, Jaidyn Levesque * Copyright 2017, Akshay Agarwal * All rights reserved. Distributed under the terms of the MIT license. */ @@ -45,6 +45,7 @@ public: virtual BBitmap* Icon() const; + virtual void SetAccountCachepath(BPath path) { fCachePath = path; } virtual void SetAddOnPath(BPath path) { fAddOnPath = path; } virtual BPath AddOnPath() { return fAddOnPath; } @@ -151,6 +152,7 @@ private: BStringList fOfflineContacts; BPath fAddOnPath; + BPath fCachePath; BString fName; ChatProtocolMessengerInterface* fMessenger; bool fReady; diff --git a/protocols/purple/PurpleApp.cpp b/protocols/purple/PurpleApp.cpp index f2cefe0..1c79dce 100644 --- a/protocols/purple/PurpleApp.cpp +++ b/protocols/purple/PurpleApp.cpp @@ -115,6 +115,11 @@ PurpleApp::MessageReceived(BMessage* msg) { BString accName = msg->FindString("account_name"); BString username = fAccounts.ValueFor(accName); + BString accountCache = msg->FindString("account_cache"); + fAddOnCache = msg->FindString("addon_cache"); + + fAccountCache.AddItem(accName, accountCache); + int64 thread; if (username.IsEmpty() == true || msg->FindInt64("thread_id", &thread) != B_OK) @@ -1956,13 +1961,7 @@ purple_connection_error_name(const PurpleConnectionErrorInfo* error) const char* purple_cache() { - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - return NULL; - path.Append(APP_NAME "/Cache/Add-Ons/" PURPLE_ADDON); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - return path.Path(); + return ((PurpleApp*)be_app)->fAddOnCache; } @@ -1970,26 +1969,25 @@ const char* account_cache(PurpleAccount* account) { const char* purple_user = purple_account_get_username(account); - const char* cardie_user = NULL; + const char* app_user = NULL; StringMap usernames = ((PurpleApp*)be_app)->fAccounts; for (int i = 0; i < usernames.CountItems(); i++) if (usernames.ValueAt(i) == purple_user) { - cardie_user = usernames.KeyAt(i); + app_user = usernames.KeyAt(i); break; } - if (cardie_user == NULL) - return NULL; - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - return NULL; - path.Append(APP_NAME "/Cache/Accounts/"); - path.Append(cardie_user); + const char* path = NULL; + if (app_user != NULL) { + bool found = false; + path = ((PurpleApp*)be_app)->fAccountCache.ValueFor(app_user, &found).String(); - if (create_directory(path.Path(), 0755) != B_OK) - return NULL; - return path.Path(); + if (found == false || create_directory(path, 0755) != B_OK) + path = NULL; + } + + return path; } diff --git a/protocols/purple/PurpleApp.h b/protocols/purple/PurpleApp.h index a53f036..2fe865d 100644 --- a/protocols/purple/PurpleApp.h +++ b/protocols/purple/PurpleApp.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -86,8 +87,11 @@ public: HashMap fInviteList; StringMap fUserNicks; // Purple username → Nickname for Cardie StringMap fAccounts; // Cardie account name → Purple username + StringMap fAccountCache; // Cardie account name → Cache path RoomMap fRoomlists; // Purple account → Purple roomlist + BString fAddOnCache; + private: void _SendSysText(PurpleConversation* conv, const char* text); diff --git a/protocols/purple/PurpleProtocol.cpp b/protocols/purple/PurpleProtocol.cpp index 6f00514..38d3ade 100644 --- a/protocols/purple/PurpleProtocol.cpp +++ b/protocols/purple/PurpleProtocol.cpp @@ -260,6 +260,8 @@ PurpleProtocol::UpdateSettings(BMessage* msg) BMessage* account = new BMessage(PURPLE_REGISTER_THREAD); account->AddInt64("thread_id", fBirdThread); + account->AddString("addon_cache", fAddOnCachePath.Path()); + account->AddString("account_cache", fAccountCachePath.Path()); _SendPrplMessage(account); resume_thread(fBirdThread); @@ -330,6 +332,13 @@ PurpleProtocol::Icon() const } +BPath +PurpleProtocol::AddOnPath() +{ + return fAddOnPath; +} + + void PurpleProtocol::SetAddOnPath(BPath path) { @@ -337,10 +346,17 @@ PurpleProtocol::SetAddOnPath(BPath path) } -BPath -PurpleProtocol::AddOnPath() +void +PurpleProtocol::SetAccountCachePath(BPath path) { - return fAddOnPath; + fAccountCachePath = path; +} + + +void +PurpleProtocol::SetAddOnCachePath(BPath path) +{ + fAddOnCachePath = path; } diff --git a/protocols/purple/PurpleProtocol.h b/protocols/purple/PurpleProtocol.h index a1c5bd6..6c0687f 100644 --- a/protocols/purple/PurpleProtocol.h +++ b/protocols/purple/PurpleProtocol.h @@ -66,8 +66,10 @@ public: virtual BBitmap* Icon() const; - virtual void SetAddOnPath(BPath path); virtual BPath AddOnPath(); + virtual void SetAddOnPath(BPath path); + virtual void SetAccountCachePath(BPath path); + virtual void SetAddOnCachePath(BPath path); virtual const char* GetName(); virtual void SetName(const char* name); @@ -92,6 +94,8 @@ private: BString fName; BPath fAddOnPath; + BPath fAccountCachePath; + BPath fAddOnCachePath; BString fSignature; BString fFriendlySignature; diff --git a/protocols/xmpp/JabberHandler.cpp b/protocols/xmpp/JabberHandler.cpp index 1b32b30..a5d55db 100644 --- a/protocols/xmpp/JabberHandler.cpp +++ b/protocols/xmpp/JabberHandler.cpp @@ -1,6 +1,6 @@ /* * Copyright 2010, Pier Luigi Fiorini. All rights reserved. - * Copyright 2021, Jaidyn Levesque. All rights reserved. + * Copyright 2021-2022, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the GPL v2 License. * * Authors: diff --git a/protocols/xmpp/JabberHandler.h b/protocols/xmpp/JabberHandler.h index b766005..0c9e97e 100644 --- a/protocols/xmpp/JabberHandler.h +++ b/protocols/xmpp/JabberHandler.h @@ -1,6 +1,6 @@ /* * Copyright 2010, Pier Luigi Fiorini. All rights reserved. - * Copyright 2021, Jaidyn Levesque. All rights reserved. + * Copyright 2021-2022, Jaidyn Levesque. All rights reserved. * Distributed under the terms of the GPL v2 License. */ #ifndef _JABBER_HANDLER_H