From b7639142c91c6fa38285fdc6de661a0b36d41fbe Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 10 Jul 2013 20:20:46 +0000 Subject: protocol DB helpers for Facebook git-svn-id: http://svn.miranda-ng.org/main/trunk@5316 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/avatars.cpp | 10 ++-- protocols/FacebookRM/src/communication.cpp | 34 ++++++------- protocols/FacebookRM/src/connection.cpp | 14 +++--- protocols/FacebookRM/src/contacts.cpp | 50 +++++++++--------- protocols/FacebookRM/src/db.h | 15 ------ protocols/FacebookRM/src/dialogs.cpp | 81 +++++++++++++++--------------- protocols/FacebookRM/src/json.cpp | 8 +-- protocols/FacebookRM/src/messages.cpp | 17 +++---- protocols/FacebookRM/src/process.cpp | 64 ++++++++++++----------- protocols/FacebookRM/src/proto.cpp | 22 ++++---- protocols/FacebookRM/src/theme.cpp | 4 +- 11 files changed, 146 insertions(+), 173 deletions(-) (limited to 'protocols') diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index 77802300f0..8f5f1d00f3 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -25,7 +25,7 @@ along with this program. If not, see . bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url) { DBVARIANT dbv; - if (!db_get_s(ai.hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, &dbv)) { + if (!getString(ai.hContact, FACEBOOK_KEY_AV_URL, &dbv)) { std::string new_url = dbv.pszVal; db_free(&dbv); @@ -35,7 +35,7 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string * if (url) *url = new_url; - if (!db_get_ts(ai.hContact, m_szModuleName, FACEBOOK_KEY_ID, &dbv)) { + if (!getTString(ai.hContact, FACEBOOK_KEY_ID, &dbv)) { std::string ext = new_url.substr(new_url.rfind('.')); std::tstring filename = GetAvatarFolder() + L'\\' + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); db_free(&dbv); @@ -57,7 +57,7 @@ void FacebookProto::CheckAvatarChange(HANDLE hContact, std::string image_url) if (image_url.empty()) return; - bool big_avatars = db_get_b(NULL, m_szModuleName, FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS) != 0; + bool big_avatars = getBool(FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS); // We've got url to avatar of default size 32x32px, let's change it to slightly bigger (50x50px) - looks like maximum size for square format std::tstring::size_type pos = image_url.rfind("/s32x32/"); @@ -73,14 +73,14 @@ void FacebookProto::CheckAvatarChange(HANDLE hContact, std::string image_url) DBVARIANT dbv; bool update_required = true; - if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, &dbv)) + if (!getString(hContact, FACEBOOK_KEY_AV_URL, &dbv)) { update_required = image_url != dbv.pszVal; db_free(&dbv); } if (update_required || !hContact) { - db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, image_url.c_str()); + setString(hContact, FACEBOOK_KEY_AV_URL, image_url.c_str()); if (hContact) { db_set_b(hContact, "ContactPhoto", "NeedUpdate", 1); diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 2a79fa8e87..c1b012672f 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -112,7 +112,7 @@ http::response facebook_client::flap(RequestType request_type, std::string* requ // is compaired in all communication requests } - if (db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_VALIDATE_RESPONSE, 0) == 1) + if (parent->getByte(FACEBOOK_KEY_VALIDATE_RESPONSE, 0) == 1) validate_response(&resp); return resp; @@ -126,7 +126,7 @@ bool facebook_client::validate_response(http::response* resp) return false; } - if (db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_VALIDATE_RESPONSE, 0) == 2) { + if (parent->getByte(FACEBOOK_KEY_VALIDATE_RESPONSE, 0) == 2) { return true; } @@ -193,7 +193,7 @@ bool facebook_client::handle_error(std::string method, int action) increment_error(); parent->Log("!!!!! %s(): Something with Facebook went wrong", method.c_str()); - bool result = (error_count_ <= (UINT)db_get_b(NULL,parent->m_szModuleName,FACEBOOK_KEY_TIMEOUTS_LIMIT,FACEBOOK_TIMEOUTS_LIMIT)); + bool result = (error_count_ <= (UINT)parent->getByte(FACEBOOK_KEY_TIMEOUTS_LIMIT, FACEBOOK_TIMEOUTS_LIMIT)); if (action == FORCE_DISCONNECT || action == FORCE_QUIT) result = false; @@ -212,14 +212,10 @@ bool facebook_client::handle_error(std::string method, int action) DWORD facebook_client::choose_security_level(RequestType request_type) { if (this->https_) - { - if (request_type != REQUEST_MESSAGES_RECEIVE - || db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS_CHANNEL, DEFAULT_FORCE_HTTPS_CHANNEL)) + if (request_type != REQUEST_MESSAGES_RECEIVE || parent->getByte(FACEBOOK_KEY_FORCE_HTTPS_CHANNEL, DEFAULT_FORCE_HTTPS_CHANNEL)) return NLHRF_SSL; - } - switch (request_type) - { + switch (request_type) { case REQUEST_LOGIN: case REQUEST_SETUP_MACHINE: return NLHRF_SSL; @@ -558,7 +554,7 @@ NETLIBHTTPHEADER* facebook_client::get_request_headers(int request_type, int* he std::string facebook_client::get_newsfeed_type() { - BYTE feed_type = db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_FEED_TYPE, 0); + BYTE feed_type = parent->getByte(FACEBOOK_KEY_FEED_TYPE, 0); if (feed_type < 0 || feed_type >= SIZEOF(feed_types)) feed_type = 0; return feed_types[feed_type].id; @@ -566,7 +562,7 @@ std::string facebook_client::get_newsfeed_type() std::string facebook_client::get_server_type() { - BYTE server_type = db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_SERVER_TYPE, 0); + BYTE server_type = parent->getByte(FACEBOOK_KEY_SERVER_TYPE, 0); if (server_type < 0 || server_type >= SIZEOF(server_types)) server_type = 0; return server_types[server_type].id; @@ -574,7 +570,7 @@ std::string facebook_client::get_server_type() std::string facebook_client::get_privacy_type() { - BYTE privacy_type = db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_PRIVACY_TYPE, 0); + BYTE privacy_type = parent->getByte(FACEBOOK_KEY_PRIVACY_TYPE, 0); if (privacy_type < 0 || privacy_type >= SIZEOF(privacy_types)) privacy_type = 0; return privacy_types[privacy_type].id; @@ -666,7 +662,7 @@ bool facebook_client::login(const std::string &username,const std::string &passw data += "&email=" + utils::url::encode(username); data += "&pass=" + utils::url::encode(password); - ptrA locale(db_get_sa(NULL, parent->m_szModuleName, FACEBOOK_KEY_LOCALE)); + ptrA locale(parent->getStringA(FACEBOOK_KEY_LOCALE)); if (locale != NULL) data += "&locale=" + std::string(locale); @@ -678,7 +674,7 @@ bool facebook_client::login(const std::string &username,const std::string &passw // Save Device ID if (cookies["datr"].length()) - db_set_s(NULL, parent->m_szModuleName, FACEBOOK_KEY_DEVICE_ID, cookies["datr"].c_str()); + parent->setString(FACEBOOK_KEY_DEVICE_ID, cookies["datr"].c_str()); if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) { @@ -692,7 +688,7 @@ bool facebook_client::login(const std::string &username,const std::string &passw // Check whether HTTPS connection is required and we don't have it enabled if (!this->https_ && resp.headers["Location"].find("https://") != std::string::npos) { client_notify(TranslateT("Your account requires HTTPS connection. Activating.")); - db_set_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS, 1); + parent->setByte(FACEBOOK_KEY_FORCE_HTTPS, 1); this->https_ = true; return login(username, password); } @@ -784,7 +780,7 @@ bool facebook_client::login(const std::string &username,const std::string &passw case HTTP_CODE_FOUND: // Found and redirected to Home, Logged in, everything is OK if (cookies.find("c_user") != cookies.end()) { this->self_.user_id = cookies.find("c_user")->second; - db_set_s(NULL,parent->m_szModuleName,FACEBOOK_KEY_ID,this->self_.user_id.c_str()); + parent->setString(FACEBOOK_KEY_ID, this->self_.user_id.c_str()); parent->Log(" Got self user id: %s", this->self_.user_id.c_str()); return handle_success("login"); } else { @@ -797,7 +793,7 @@ bool facebook_client::login(const std::string &username,const std::string &passw bool facebook_client::logout() { - if (db_get_b(NULL, parent->m_szModuleName, FACEBOOK_KEY_DISABLE_LOGOUT, 0)) + if (parent->getByte(FACEBOOK_KEY_DISABLE_LOGOUT, 0)) return true; handle_entry("logout"); @@ -1184,7 +1180,7 @@ bool facebook_client::send_message(std::string message_recipient, std::string me { HANDLE hContact = parent->ContactIDToHContact(message_recipient); if (hContact != NULL) - db_set_w(hContact,parent->m_szModuleName,"Status",ID_STATUS_OFFLINE); + parent->setWord(hContact, "Status", ID_STATUS_OFFLINE); return false; } break; @@ -1222,7 +1218,7 @@ bool facebook_client::set_status(const std::string &status_text) return handle_success("set_status"); std::string text = utils::url::encode(status_text); - ptrA place = db_get_sa(NULL, parent->m_szModuleName, FACEBOOK_KEY_PLACE); + ptrA place(parent->getStringA(FACEBOOK_KEY_PLACE)); std::string data = "fb_dtsg=" + (this->dtsg_.length() ? this->dtsg_ : "0"); data += "&xhpc_context=home&xhpc_ismeta=1&xhpc_timeline=&xhpc_composerid=u_jsonp_2_0&is_explicit_place=&composertags_place=&composer_session_id=0&composertags_city=&disable_location_sharing=false&composer_predicted_city=&nctr[_mod]=pagelet_composer&__a=1&__dyn=&__req=1f&phstamp=0"; diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index c1692a6cca..84e40254de 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -43,7 +43,7 @@ void FacebookProto::ChangeStatus(void*) facy.logout(); - deleteSetting("LogonTS"); + delSetting("LogonTS"); facy.clear_cookies(); facy.buddies.clear(); @@ -145,7 +145,7 @@ bool FacebookProto::NegotiateConnection() DBVARIANT dbv = {0}; error = true; - if (!db_get_s(NULL,m_szModuleName,FACEBOOK_KEY_LOGIN,&dbv)) + if (!getString(FACEBOOK_KEY_LOGIN, &dbv)) { user = dbv.pszVal; db_free(&dbv); @@ -158,7 +158,7 @@ bool FacebookProto::NegotiateConnection() } error = true; - if (!db_get_s(NULL,m_szModuleName,FACEBOOK_KEY_PASS,&dbv)) + if (!getString(FACEBOOK_KEY_PASS, &dbv)) { CallService(MS_DB_CRYPT_DECODESTRING,strlen(dbv.pszVal)+1, reinterpret_cast(dbv.pszVal)); @@ -173,7 +173,7 @@ bool FacebookProto::NegotiateConnection() } // Load machine name - if (!db_get_s(NULL,m_szModuleName,FACEBOOK_KEY_DEVICE_ID,&dbv)) + if (!getString(FACEBOOK_KEY_DEVICE_ID, &dbv)) { facy.cookies["datr"] = dbv.pszVal; db_free(&dbv); @@ -183,13 +183,11 @@ bool FacebookProto::NegotiateConnection() facy.last_feeds_update_ = ::time(NULL); // Get info about secured connection - facy.https_ = db_get_b(NULL, m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS, DEFAULT_FORCE_HTTPS) != 0; + facy.https_ = getByte(FACEBOOK_KEY_FORCE_HTTPS, DEFAULT_FORCE_HTTPS) != 0; // Create default group for new contacts - if (!db_get_ts(NULL, m_szModuleName, FACEBOOK_KEY_DEF_GROUP, &dbv) && lstrlen(dbv.ptszVal) > 0) - { + if (!getTString(FACEBOOK_KEY_DEF_GROUP, &dbv) && lstrlen(dbv.ptszVal) > 0) CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)dbv.ptszVal); - } return facy.login(user, pass); } diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 58c9237aa4..07086cb981 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -29,7 +29,7 @@ bool FacebookProto::IsMyContact(HANDLE hContact, bool include_chat) if (include_chat) return true; else - return !db_get_b(hContact, m_szModuleName, "ChatRoom", 0); + return !getByte(hContact, "ChatRoom", 0); } return false; } @@ -40,7 +40,7 @@ HANDLE FacebookProto::ChatIDToHContact(std::string chat_id) if (!IsMyContact(hContact, true)) continue; - ptrA id = db_get_sa(hContact, m_szModuleName, "ChatRoomID"); + ptrA id( getStringA(hContact, "ChatRoomID")); if (id && !strcmp(id, chat_id.c_str())) return hContact; } @@ -54,7 +54,7 @@ HANDLE FacebookProto::ContactIDToHContact(std::string user_id) if (!IsMyContact(hContact)) continue; - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); if (id && !strcmp(id, user_id.c_str())) return hContact; } @@ -79,11 +79,11 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, boo { if(CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hContact,(LPARAM)m_szModuleName) == 0) { - db_set_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,fbu->user_id.c_str()); + setString(hContact, FACEBOOK_KEY_ID, fbu->user_id.c_str()); std::string homepage = FACEBOOK_URL_PROFILE + fbu->user_id; - db_set_s(hContact, m_szModuleName,"Homepage", homepage.c_str()); - db_set_s(hContact, m_szModuleName, "MirVer", fbu->status_id == ID_STATUS_ONTHEPHONE ? FACEBOOK_MOBILE : FACEBOOK_NAME); + setString(hContact, "Homepage", homepage.c_str()); + setString(hContact, "MirVer", fbu->status_id == ID_STATUS_ONTHEPHONE ? FACEBOOK_MOBILE : FACEBOOK_NAME); db_unset(hContact, "CList", "MyHandle"); @@ -97,12 +97,12 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, boo } if (fbu->gender) - db_set_b(hContact, m_szModuleName, "Gender", fbu->gender); + setByte(hContact, "Gender", fbu->gender); if (!fbu->image_url.empty()) - db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_AV_URL, fbu->image_url.c_str()); + setString(hContact, FACEBOOK_KEY_AV_URL, fbu->image_url.c_str()); - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, type); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, type); if (getByte(FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, 0)) CallService(MS_IGNORE_IGNORE, (WPARAM)hContact, (LPARAM)IGNOREEVENT_USERONLINE); @@ -119,18 +119,18 @@ HANDLE FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, boo void FacebookProto::SetAllContactStatuses(int status, bool reset_client) { for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - if (db_get_b(hContact,m_szModuleName,"ChatRoom",0)) + if (getByte(hContact, "ChatRoom", 0)) continue; if (reset_client) { ptrT mirver = db_get_tsa(hContact, m_szModuleName, "MirVer"); if (!mirver || _tcscmp(mirver, _T(FACEBOOK_NAME))) - db_set_ts(hContact, m_szModuleName, "MirVer", _T(FACEBOOK_NAME)); + setTString(hContact, "MirVer", _T(FACEBOOK_NAME)); /*std::tstring foldername = GetAvatarFolder() + L"\\smileys\\"; TCHAR *path = _tcsdup(foldername.c_str()); - if (db_get_b(NULL,m_szModuleName,FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { + if (getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { SMADD_CONT cont; cont.cbSize = sizeof(SMADD_CONT); cont.hContact = hContact; @@ -141,8 +141,8 @@ void FacebookProto::SetAllContactStatuses(int status, bool reset_client) }*/ } - if (db_get_w(hContact,m_szModuleName,"Status",ID_STATUS_OFFLINE) != status) - db_set_w(hContact,m_szModuleName,"Status",status); + if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != status) + setWord(hContact, "Status", status); } } @@ -179,9 +179,9 @@ void FacebookProto::DeleteContactFromServer(void *data) // If contact wasn't deleted from database if (hContact != NULL) { - db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE); - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); - db_set_dw(hContact, m_szModuleName, FACEBOOK_KEY_DELETED, ::time(NULL)); + setWord(hContact, "Status", ID_STATUS_OFFLINE); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); + setDword(hContact, FACEBOOK_KEY_DELETED, ::time(NULL)); } NotifyEvent(m_tszUserName, TranslateT("Contact was removed from your server list."), NULL, FACEBOOK_EVENT_OTHER); @@ -219,12 +219,11 @@ void FacebookProto::AddContactToServer(void *data) // If contact wasn't deleted from database if (hContact != NULL) - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_REQUEST); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_REQUEST); NotifyEvent(m_tszUserName, TranslateT("Request for friendship was sent."), NULL, FACEBOOK_EVENT_OTHER); - } else { - facy.client_notify(TranslateT("Error occured when requesting friendship.")); } + else facy.client_notify(TranslateT("Error occured when requesting friendship.")); if (resp.code != HTTP_CODE_OK) facy.handle_error("AddContactToServer"); @@ -246,7 +245,7 @@ void FacebookProto::ApproveContactToServer(void *data) std::string get_data = "id="; - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); get_data += id; http::response resp = facy.flap(REQUEST_APPROVE_FRIEND, &post_data, &get_data); @@ -254,7 +253,7 @@ void FacebookProto::ApproveContactToServer(void *data) // Process result data facy.validate_response(&resp); - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); } void FacebookProto::CancelFriendsRequest(void *data) @@ -271,7 +270,7 @@ void FacebookProto::CancelFriendsRequest(void *data) query += "&fb_dtsg=" + facy.dtsg_; query += "&__user=" + facy.self_.user_id; - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); query += "&friend=" + std::string(id); // Get unread inbox threads @@ -282,11 +281,10 @@ void FacebookProto::CancelFriendsRequest(void *data) if (resp.data.find("\"payload\":null", 0) != std::string::npos) { - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); NotifyEvent(m_tszUserName, TranslateT("Request for friendship was canceled."), NULL, FACEBOOK_EVENT_OTHER); - } else { - facy.client_notify(TranslateT("Error occured when canceling friendship request.")); } + else facy.client_notify(TranslateT("Error occured when canceling friendship request.")); if (resp.code != HTTP_CODE_OK) facy.handle_error("CancelFriendsRequest"); diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index a5f46e33f8..59c575da46 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -22,21 +22,6 @@ along with this program. If not, see . #pragma once -// DB macros -#define getByte(setting, error) db_get_b(NULL, m_szModuleName, setting, error) -#define setByte(setting, value) db_set_b(NULL, m_szModuleName, setting, value) -#define getWord(setting, error) db_get_w(NULL, m_szModuleName, setting, error) -#define setWord(setting, value) db_set_w(NULL, m_szModuleName, setting, value) -#define getDword(setting, error) db_get_dw(NULL, m_szModuleName, setting, error) -#define setDword(setting, value) db_set_dw(NULL, m_szModuleName, setting, value) -#define getString(setting, dest) db_get_s(NULL, m_szModuleName, setting, dest) -#define setString(setting, value) db_set_s(NULL, m_szModuleName, setting, value) -#define getTString(setting, dest) db_get_ts(NULL, m_szModuleName, setting, dest) -#define setTString(setting, value) db_set_ts(NULL, m_szModuleName, setting, value) -#define getU8String(setting, dest) db_get_utf(NULL, m_szModuleName, setting, dest) -#define setU8String(setting, value) db_set_utf(NULL, m_szModuleName, setting, value) -#define deleteSetting(setting) db_unset(NULL, m_szModuleName, setting) - // DB keys #define FACEBOOK_KEY_LOGIN "Email" #define FACEBOOK_KEY_ID "ID" diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index 166c0c3f12..d4bf908282 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -24,7 +24,7 @@ along with this program. If not, see . static BOOL LoadDBCheckState(FacebookProto* ppro, HWND hwnd, int idCtrl, const char* szSetting, BYTE bDef) { - BOOL state = db_get_b(NULL, ppro->m_szModuleName, szSetting, bDef); + BOOL state = ppro->getByte(szSetting, bDef); CheckDlgButton(hwnd, idCtrl, state); return state; } @@ -32,7 +32,7 @@ static BOOL LoadDBCheckState(FacebookProto* ppro, HWND hwnd, int idCtrl, const c static BOOL StoreDBCheckState(FacebookProto* ppro, HWND hwnd, int idCtrl, const char* szSetting) { BOOL state = IsDlgButtonChecked(hwnd, idCtrl); - db_set_b(NULL, ppro->m_szModuleName, szSetting, (BYTE)state); + ppro->setByte(szSetting, (BYTE)state); return state; } @@ -131,9 +131,9 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara for(size_t i=0; i(Translate(privacy_types[i].name))); - SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_SETCURSEL, db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_PRIVACY_TYPE, 0), 0); + SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_SETCURSEL, proto->getByte(FACEBOOK_KEY_PRIVACY_TYPE, 0), 0); - ptrA name = db_get_sa(NULL, proto->m_szModuleName, FACEBOOK_KEY_NAME); + ptrA name( proto->getStringA(FACEBOOK_KEY_NAME)); if (name != NULL) { std::string firstname = name; std::string::size_type pos = firstname.find(" "); @@ -171,10 +171,10 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara GetDlgItemText(hwnd,IDC_PLACE, placeT, SIZEOF(placeT)); ShowWindow(hwnd,SW_HIDE); - ptrA place = mir_utf8encodeT(placeT); - db_set_s(NULL, proto->m_szModuleName, FACEBOOK_KEY_PLACE, place); + ptrA place( mir_utf8encodeT(placeT)); + proto->setString(FACEBOOK_KEY_PLACE, place); - db_set_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_PRIVACY_TYPE, SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0)); + proto->setByte(FACEBOOK_KEY_PRIVACY_TYPE, SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0)); char *narrow = mir_utf8encodeT(mindMessageT); if (proto->last_status_msg_ != narrow) @@ -277,16 +277,15 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp GetDlgItemTextA(hwnd,IDC_PW,str,sizeof(str)); CallService(MS_DB_CRYPT_ENCODESTRING,sizeof(str),reinterpret_cast(str)); - db_set_s(NULL,proto->m_szModuleName,FACEBOOK_KEY_PASS,str); + proto->setString(FACEBOOK_KEY_PASS, str); GetDlgItemText(hwnd,IDC_GROUP,tstr,sizeof(tstr)); if (lstrlen(tstr) > 0) { - db_set_ts(NULL,proto->m_szModuleName,FACEBOOK_KEY_DEF_GROUP,tstr); + proto->setTString(FACEBOOK_KEY_DEF_GROUP, tstr); CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)tstr); } - else - db_unset(NULL,proto->m_szModuleName,FACEBOOK_KEY_DEF_GROUP); + else proto->delSetting(FACEBOOK_KEY_DEF_GROUP); StoreDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY); StoreDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS); @@ -317,7 +316,7 @@ INT_PTR CALLBACK FBOptionsAdvancedProc(HWND hwnd, UINT message, WPARAM wparam, L for(size_t i=0; i(Translate(server_types[i].name))); - SendDlgItemMessage(hwnd, IDC_URL_SERVER, CB_SETCURSEL, db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_SERVER_TYPE, 0), 0); + SendDlgItemMessage(hwnd, IDC_URL_SERVER, CB_SETCURSEL, proto->getByte(FACEBOOK_KEY_SERVER_TYPE, 0), 0); LoadDBCheckState(proto, hwnd, IDC_SECURE, FACEBOOK_KEY_FORCE_HTTPS, DEFAULT_FORCE_HTTPS); LoadDBCheckState(proto, hwnd, IDC_SECURE_CHANNEL, FACEBOOK_KEY_FORCE_HTTPS_CHANNEL, DEFAULT_FORCE_HTTPS_CHANNEL); @@ -351,7 +350,7 @@ INT_PTR CALLBACK FBOptionsAdvancedProc(HWND hwnd, UINT message, WPARAM wparam, L case WM_NOTIFY: if (reinterpret_cast(lparam)->code == PSN_APPLY) { - db_set_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_SERVER_TYPE, SendDlgItemMessage(hwnd, IDC_URL_SERVER, CB_GETCURSEL, 0, 0)); + proto->setByte(FACEBOOK_KEY_SERVER_TYPE, SendDlgItemMessage(hwnd, IDC_URL_SERVER, CB_GETCURSEL, 0, 0)); StoreDBCheckState(proto, hwnd, IDC_SECURE, FACEBOOK_KEY_FORCE_HTTPS); StoreDBCheckState(proto, hwnd, IDC_LOGGING, FACEBOOK_KEY_LOGGING_ENABLE); @@ -363,10 +362,10 @@ INT_PTR CALLBACK FBOptionsAdvancedProc(HWND hwnd, UINT message, WPARAM wparam, L StoreDBCheckState(proto, hwnd, IDC_SEND_SEEN, FACEBOOK_KEY_MARK_READ); BOOL setStatus = IsDlgButtonChecked(hwnd, IDC_SET_STATUS); - BOOL setStatusOld = db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS); + BOOL setStatusOld = proto->getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS); if (setStatus != setStatusOld) { - db_set_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_SET_MIRANDA_STATUS, setStatus); + proto->setByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, setStatus); if (setStatus && proto->isOnline()) proto->ForkThread(&FacebookProto::SetAwayMsgWorker, NULL); } @@ -400,7 +399,7 @@ INT_PTR CALLBACK FBEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpa SendDlgItemMessageA(hwnd,IDC_FEED_TYPE,CB_INSERTSTRING,i, reinterpret_cast(Translate(feed_types[i].name))); } - SendDlgItemMessage(hwnd, IDC_FEED_TYPE, CB_SETCURSEL, db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_FEED_TYPE, 0), 0); + SendDlgItemMessage(hwnd, IDC_FEED_TYPE, CB_SETCURSEL, proto->getByte(FACEBOOK_KEY_FEED_TYPE, 0), 0); LoadDBCheckState(proto, hwnd, IDC_SYSTRAY_NOTIFY, FACEBOOK_KEY_SYSTRAY_NOTIFY, DEFAULT_SYSTRAY_NOTIFY); LoadDBCheckState(proto, hwnd, IDC_NOTIFICATIONS_ENABLE, FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE); @@ -408,18 +407,18 @@ INT_PTR CALLBACK FBEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpa LoadDBCheckState(proto, hwnd, IDC_CLIENT_ENABLE, FACEBOOK_KEY_EVENT_CLIENT_ENABLE, DEFAULT_EVENT_CLIENT_ENABLE); LoadDBCheckState(proto, hwnd, IDC_OTHER_ENABLE, FACEBOOK_KEY_EVENT_OTHER_ENABLE, DEFAULT_EVENT_OTHER_ENABLE); - SendDlgItemMessage(hwnd, IDC_COLBACK, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLBACK,DEFAULT_EVENT_COLBACK)); - SendDlgItemMessage(hwnd, IDC_COLTEXT, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLTEXT,DEFAULT_EVENT_COLTEXT)); - SetDlgItemInt(hwnd, IDC_TIMEOUT,db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_TIMEOUT, 0),TRUE); - SendDlgItemMessage(hwnd, IDC_COLBACK2, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_COLBACK,DEFAULT_EVENT_COLBACK)); - SendDlgItemMessage(hwnd, IDC_COLTEXT2, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_COLTEXT,DEFAULT_EVENT_COLTEXT)); - SetDlgItemInt(hwnd, IDC_TIMEOUT2,db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_TIMEOUT, 0),TRUE); - SendDlgItemMessage(hwnd, IDC_COLBACK3, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_COLBACK,DEFAULT_EVENT_COLBACK)); - SendDlgItemMessage(hwnd, IDC_COLTEXT3, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_COLTEXT,DEFAULT_EVENT_COLTEXT)); - SetDlgItemInt(hwnd, IDC_TIMEOUT3,db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_TIMEOUT, 0),TRUE); - SendDlgItemMessage(hwnd, IDC_COLBACK4, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_COLBACK,DEFAULT_EVENT_COLBACK)); - SendDlgItemMessage(hwnd, IDC_COLTEXT4, CPM_SETCOLOUR, 0, db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_COLTEXT,DEFAULT_EVENT_COLTEXT)); - SetDlgItemInt(hwnd, IDC_TIMEOUT4,db_get_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_TIMEOUT, 0),TRUE); + SendDlgItemMessage(hwnd, IDC_COLBACK, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLBACK,DEFAULT_EVENT_COLBACK)); + SendDlgItemMessage(hwnd, IDC_COLTEXT, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLTEXT,DEFAULT_EVENT_COLTEXT)); + SetDlgItemInt(hwnd, IDC_TIMEOUT, proto->getDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_TIMEOUT, 0),TRUE); + SendDlgItemMessage(hwnd, IDC_COLBACK2, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_FEEDS_COLBACK,DEFAULT_EVENT_COLBACK)); + SendDlgItemMessage(hwnd, IDC_COLTEXT2, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_FEEDS_COLTEXT,DEFAULT_EVENT_COLTEXT)); + SetDlgItemInt(hwnd, IDC_TIMEOUT2, proto->getDword(FACEBOOK_KEY_EVENT_FEEDS_TIMEOUT, 0),TRUE); + SendDlgItemMessage(hwnd, IDC_COLBACK3, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_OTHER_COLBACK,DEFAULT_EVENT_COLBACK)); + SendDlgItemMessage(hwnd, IDC_COLTEXT3, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_OTHER_COLTEXT,DEFAULT_EVENT_COLTEXT)); + SetDlgItemInt(hwnd, IDC_TIMEOUT3, proto->getDword(FACEBOOK_KEY_EVENT_OTHER_TIMEOUT, 0),TRUE); + SendDlgItemMessage(hwnd, IDC_COLBACK4, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_CLIENT_COLBACK,DEFAULT_EVENT_COLBACK)); + SendDlgItemMessage(hwnd, IDC_COLTEXT4, CPM_SETCOLOUR, 0, proto->getDword(FACEBOOK_KEY_EVENT_CLIENT_COLTEXT,DEFAULT_EVENT_COLTEXT)); + SetDlgItemInt(hwnd, IDC_TIMEOUT4, proto->getDword(FACEBOOK_KEY_EVENT_CLIENT_TIMEOUT, 0),TRUE); LoadDBCheckState(proto, hwnd, IDC_NOTIFICATIONS_DEFAULT, FACEBOOK_KEY_EVENT_NOTIFICATIONS_DEFAULT, 0); LoadDBCheckState(proto, hwnd, IDC_FEEDS_DEFAULT, FACEBOOK_KEY_EVENT_FEEDS_DEFAULT, 0); @@ -473,7 +472,7 @@ INT_PTR CALLBACK FBEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpa { if (reinterpret_cast(lparam)->code == PSN_APPLY) { - db_set_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_FEED_TYPE, SendDlgItemMessage(hwnd, IDC_FEED_TYPE, CB_GETCURSEL, 0, 0)); + proto->setByte(FACEBOOK_KEY_FEED_TYPE, SendDlgItemMessage(hwnd, IDC_FEED_TYPE, CB_GETCURSEL, 0, 0)); StoreDBCheckState(proto, hwnd, IDC_SYSTRAY_NOTIFY, FACEBOOK_KEY_SYSTRAY_NOTIFY); @@ -487,21 +486,21 @@ INT_PTR CALLBACK FBEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpa StoreDBCheckState(proto, hwnd, IDC_OTHER_DEFAULT, FACEBOOK_KEY_EVENT_OTHER_DEFAULT); StoreDBCheckState(proto, hwnd, IDC_CLIENT_DEFAULT, FACEBOOK_KEY_EVENT_CLIENT_DEFAULT); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT,NULL,TRUE)); + proto->setDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT,NULL,TRUE)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK2,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT2,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_FEEDS_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT2,NULL,TRUE)); + proto->setDword(FACEBOOK_KEY_EVENT_FEEDS_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK2,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_FEEDS_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT2,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_FEEDS_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT2,NULL,TRUE)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK3,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT3,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_OTHER_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT3,NULL,TRUE)); + proto->setDword(FACEBOOK_KEY_EVENT_OTHER_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK3,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_OTHER_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT3,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_OTHER_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT3,NULL,TRUE)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK4,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT4,CPM_GETCOLOUR,0,0)); - db_set_dw(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_CLIENT_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT4,NULL,TRUE)); + proto->setDword(FACEBOOK_KEY_EVENT_CLIENT_COLBACK, SendDlgItemMessage(hwnd,IDC_COLBACK4,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_CLIENT_COLTEXT, SendDlgItemMessage(hwnd,IDC_COLTEXT4,CPM_GETCOLOUR,0,0)); + proto->setDword(FACEBOOK_KEY_EVENT_CLIENT_TIMEOUT, GetDlgItemInt(hwnd,IDC_TIMEOUT4,NULL,TRUE)); } } return TRUE; diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 426e867475..32909c95b4 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -344,7 +344,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa dbei.flags = DBEF_SENT | DBEF_UTF; dbei.szModule = proto->m_szModuleName; - bool local_time = db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0; + bool local_time = proto->getByte(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0; dbei.timestamp = local_time ? ::time(NULL) : utils::time::fix_timestamp(time_sent.Value()); dbei.cbBlob = (DWORD)message_text.length() + 1; @@ -469,7 +469,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa } else if (type.Value() == "notification_json") // event notification { - if (!db_get_b(NULL, proto->m_szModuleName, FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) + if (!proto->getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) continue; const Array& notificationsArray = objMember["nodes"]; @@ -510,8 +510,8 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa HANDLE hContact = proto->AddToContactList(&fbu, CONTACT_FRIEND); - if (db_get_w(hContact, proto->m_szModuleName, "Status", 0) == ID_STATUS_OFFLINE) - db_set_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_ONLINE); + if (proto->getWord(hContact, "Status", 0) == ID_STATUS_OFFLINE) + proto->setWord(hContact, "Status", ID_STATUS_ONLINE); const Number& state = objMember["st"]; if (state.Value() == 1) diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index d801fefe35..3fe97730f5 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -45,7 +45,7 @@ void FacebookProto::SendMsgWorker(void *p) { ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)Translate("You cannot send messages when you are offline.")); } - else if (!db_get_s(data->hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) + else if (!getString(data->hContact, FACEBOOK_KEY_ID, &dbv)) { //ParseSmileys(data->msg, data->hContact); @@ -81,7 +81,7 @@ void FacebookProto::SendChatMsgWorker(void *p) if (hContact) { std::string tid; DBVARIANT dbv; - if (!db_get_s(hContact, m_szModuleName, FACEBOOK_KEY_TID, &dbv)) { + if (!getString(hContact, FACEBOOK_KEY_TID, &dbv)) { tid = dbv.pszVal; db_free(&dbv); } else { @@ -94,7 +94,7 @@ void FacebookProto::SendChatMsgWorker(void *p) facy.validate_response(&resp); tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\""); - db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_TID, tid.c_str()); + setString(hContact, FACEBOOK_KEY_TID, tid.c_str()); Log(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str()); } @@ -132,8 +132,7 @@ void FacebookProto::SendTypingWorker(void *p) send_typing *typing = static_cast(p); // Dont send typing notifications to contacts, that are offline or not friends - if (db_get_w(typing->hContact,m_szModuleName,"Status", 0) == ID_STATUS_OFFLINE - || db_get_b(typing->hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) + if (getWord(typing->hContact, "Status", 0) == ID_STATUS_OFFLINE || getWord(typing->hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) return; // TODO RM: maybe better send typing optimalization @@ -147,7 +146,7 @@ void FacebookProto::SendTypingWorker(void *p) } DBVARIANT dbv; - if (!db_get_s(typing->hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) + if (!getString(typing->hContact, FACEBOOK_KEY_ID, &dbv)) { std::string data = "&source=mercury-chat"; data += (typing->status == PROTOTYPE_SELFTYPING_ON ? "&typ=1" : "&typ=0"); // PROTOTYPE_SELFTYPING_OFF @@ -170,7 +169,7 @@ void FacebookProto::ReadMessageWorker(void *p) HANDLE hContact = static_cast(p); - if (!db_get_b(NULL, m_szModuleName, FACEBOOK_KEY_MARK_READ, 1)) { + if (!getByte(FACEBOOK_KEY_MARK_READ, 1)) { // old variant - no seen info updated ptrA id( db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID)); if (id == NULL) return; @@ -183,7 +182,7 @@ void FacebookProto::ReadMessageWorker(void *p) facy.flap(REQUEST_ASYNC, &data); } else { // new variant - with seen info - ptrA mid( db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_MESSAGE_ID)); + ptrA mid( getStringA(hContact, FACEBOOK_KEY_MESSAGE_ID)); if (mid == NULL) return; std::string data = "ids[" + std::string(mid) + "]=true"; @@ -197,7 +196,7 @@ void FacebookProto::ReadMessageWorker(void *p) void FacebookProto::ParseSmileys(std::string message, HANDLE hContact) { - if (!db_get_b(NULL,m_szModuleName,FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) + if (!getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) return; HANDLE nlc = NULL; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index fa13cc2b86..3338d5de34 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -42,7 +42,7 @@ void FacebookProto::ProcessBuddyList(void* data) p->parse_buddy_list(data, &facy.buddies); delete p; - bool use_mobile_status = db_get_b(NULL,m_szModuleName,FACEBOOK_KEY_LOAD_MOBILE, DEFAULT_LOAD_MOBILE) != 0; + bool use_mobile_status = getByte(FACEBOOK_KEY_LOAD_MOBILE, DEFAULT_LOAD_MOBILE) != 0; for (List::Item< facebook_user >* i = facy.buddies.begin(); i != NULL;) { @@ -73,19 +73,18 @@ void FacebookProto::ProcessBuddyList(void* data) DBVARIANT dbv; TCHAR* client = on_mobile ? _T(FACEBOOK_MOBILE) : _T(FACEBOOK_NAME); - if (!db_get_ts(hContact,m_szModuleName,"MirVer",&dbv)) { + if (!getTString(hContact, "MirVer", &dbv)) { if (_tcscmp(dbv.ptszVal, client)) - db_set_ts(hContact,m_szModuleName,"MirVer",client); + setTString(hContact, "MirVer", client); db_free(&dbv); - } else { - db_set_ts(hContact,m_szModuleName,"MirVer",client); } + else setTString(hContact, "MirVer", client); } if (fbu->status_id == ID_STATUS_OFFLINE || fbu->deleted) { if (fbu->handle) - db_set_w(fbu->handle, m_szModuleName, "Status", ID_STATUS_OFFLINE); + setWord(fbu->handle, "Status", ID_STATUS_OFFLINE); std::string to_delete(i->key); i = i->next; @@ -96,24 +95,24 @@ void FacebookProto::ProcessBuddyList(void* data) if (!fbu->handle) // just been added fbu->handle = AddToContactList(fbu, CONTACT_FRIEND); - if (db_get_w(fbu->handle, m_szModuleName, "Status", 0) != fbu->status_id) - db_set_w(fbu->handle, m_szModuleName, "Status", fbu->status_id); + if (getWord(fbu->handle, "Status", 0) != fbu->status_id) + setWord(fbu->handle, "Status", fbu->status_id); - if (db_get_dw(fbu->handle, m_szModuleName, "LastActiveTS", 0) != fbu->last_active) { + if (getDword(fbu->handle, "LastActiveTS", 0) != fbu->last_active) { if (fbu->last_active > 0) - db_set_dw(fbu->handle, m_szModuleName, "LastActiveTS", fbu->last_active); + setDword(fbu->handle, "LastActiveTS", fbu->last_active); else - db_unset(fbu->handle, m_szModuleName, "LastActiveTS"); + delSetting(fbu->handle, "LastActiveTS"); } - if (db_get_b(fbu->handle, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) { - db_set_b(fbu->handle, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); + if (getByte(fbu->handle, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) { + setByte(fbu->handle, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); // TODO: remove that popup and use "Contact added you" event? } // Wasn't contact removed from "server-list" someday? - if (db_get_dw(fbu->handle, m_szModuleName, FACEBOOK_KEY_DELETED, 0)) { - db_unset(fbu->handle, m_szModuleName, FACEBOOK_KEY_DELETED); + if (getDword(fbu->handle, FACEBOOK_KEY_DELETED, 0)) { + delSetting(fbu->handle, FACEBOOK_KEY_DELETED); std::string url = FACEBOOK_URL_PROFILE + fbu->user_id; @@ -159,12 +158,12 @@ void FacebookProto::ProcessFriendList(void* data) // Check and update old contacts for (HANDLE hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { - if (db_get_b(hContact,m_szModuleName,"ChatRoom",0)) + if (getByte(hContact, "ChatRoom", 0)) continue; DBVARIANT dbv; facebook_user *fbu; - if (!db_get_s(hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv)) { + if (!getString(hContact, FACEBOOK_KEY_ID, &dbv)) { std::string id = dbv.pszVal; db_free(&dbv); @@ -180,8 +179,8 @@ void FacebookProto::ProcessFriendList(void* data) // TODO RM: remove, because contacts cant change it, so its only for "first run" // - but what with contacts, that was added after logon? // Update gender - if (db_get_b(hContact, m_szModuleName, "Gender", 0) != fbu->gender) - db_set_b(hContact, m_szModuleName, "Gender", fbu->gender); + if (getByte(hContact, "Gender", 0) != fbu->gender) + setByte(hContact, "Gender", fbu->gender); // Update real name if (!db_get_utf(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv)) @@ -195,14 +194,14 @@ void FacebookProto::ProcessFriendList(void* data) db_set_utf(hContact, m_szModuleName, FACEBOOK_KEY_NICK, fbu->real_name.c_str()); } - if (db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) { - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); + if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) { + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND); // TODO: remove that popup and use "Contact added you" event? } // Wasn't contact removed from "server-list" someday? - if (db_get_dw(hContact, m_szModuleName, FACEBOOK_KEY_DELETED, 0)) { - db_unset(hContact, m_szModuleName, FACEBOOK_KEY_DELETED); + if (getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { + delSetting(hContact, FACEBOOK_KEY_DELETED); std::string url = FACEBOOK_URL_PROFILE + fbu->user_id; @@ -220,12 +219,12 @@ void FacebookProto::ProcessFriendList(void* data) // Contact was removed from "server-list", notify it // Wasnt we already been notified about this contact? And was this real friend? - if (!db_get_dw(hContact, m_szModuleName, FACEBOOK_KEY_DELETED, 0) - && db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) == CONTACT_FRIEND) + if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0) + && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) == CONTACT_FRIEND) { - db_set_dw(hContact, m_szModuleName, FACEBOOK_KEY_DELETED, ::time(NULL)); - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); + setDword(hContact, FACEBOOK_KEY_DELETED, ::time(NULL)); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); std::string contactname = id; if (!db_get_utf(hContact, m_szModuleName, FACEBOOK_KEY_NAME, &dbv)) { @@ -248,7 +247,6 @@ void FacebookProto::ProcessFriendList(void* data) facebook_user *fbu = iter->second; HANDLE hContact = AddToContactList(fbu, CONTACT_FRIEND, true); // This contact is surely new ...are you sure? -// db_set_w(hContact, m_szModuleName, "Status", ID_STATUS_OFFLINE); } LOG("***** Friend list processed"); @@ -411,7 +409,7 @@ void FacebookProto::ProcessMessages(void* data) p->parse_messages(data, &messages, ¬ifications); delete p; - bool local_timestamp = getByte(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0; + bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0); for(std::vector::size_type i=0; isender_name; HANDLE hContact = AddToContactList(&fbu, CONTACT_NONE); - db_set_s(hContact, m_szModuleName, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str()); + setString(hContact, FACEBOOK_KEY_MESSAGE_ID, messages[i]->message_id.c_str()); // TODO: if contact is newly added, get his user info // TODO: maybe create new "receiveMsg" function and use it for offline and channel messages? @@ -562,19 +560,19 @@ void FacebookProto::ProcessFriendRequests(void*) if (fbu->user_id.length() && fbu->real_name.length()) { HANDLE hContact = AddToContactList(fbu, CONTACT_APPROVE); - db_set_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_APPROVE); + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_APPROVE); bool seen = false; DBVARIANT dbv; - if (!db_get_s(hContact, m_szModuleName, "RequestTime", &dbv)) { + if (!getString(hContact, "RequestTime", &dbv)) { seen = !strcmp(dbv.pszVal, time.c_str()); db_free(&dbv); } if (!seen) { // This is new request - db_set_s(hContact, m_szModuleName, "RequestTime", time.c_str()); + setString(hContact, "RequestTime", time.c_str()); //blob is: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ) //blob is: 0(DWORD), hContact(HANDLE), nick(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ), ""(ASCIIZ) diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index d362447736..5bc721b63a 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -162,7 +162,7 @@ int FacebookProto::SetStatus(int new_status) case ID_STATUS_IDLE: default: m_iDesiredStatus = ID_STATUS_INVISIBLE; - if (db_get_b(NULL,m_szModuleName,FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES)) + if (getByte(FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES)) break; case ID_STATUS_ONLINE: case ID_STATUS_FREECHAT: @@ -482,15 +482,15 @@ INT_PTR FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam) std::string url = FACEBOOK_URL_PROFILE; - ptrA val = db_get_sa(hContact, m_szModuleName, "Homepage"); + ptrA val( getStringA(hContact, "Homepage")); if (val != NULL) { // Homepage link already present, get it url = val; } else { // No homepage link, create and save it - val = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + val = getStringA(hContact, FACEBOOK_KEY_ID); url += val; - db_set_s(hContact, m_szModuleName, "Homepage", url.c_str()); + setString(hContact, "Homepage", url.c_str()); } OpenUrl(url); @@ -504,7 +504,7 @@ INT_PTR FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam) if (wParam == 0 || !IsMyContact(hContact)) return 1; - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); std::string url = FACEBOOK_URL_PROFILE; url += facy.self_.user_id; @@ -521,7 +521,7 @@ INT_PTR FacebookProto::Poke(WPARAM wParam,LPARAM lParam) HANDLE hContact = reinterpret_cast(wParam); - ptrA id(db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID)); + ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); if (id == NULL) return 1; @@ -539,8 +539,8 @@ INT_PTR FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam) HANDLE hContact = reinterpret_cast(wParam); // Ignore groupchats and, if deleting, also not-friends - if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) - || (deleting && db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND)) + if (getByte(hContact, "ChatRoom", 0) + || (deleting && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND)) return 0; ptrT tname = db_get_tsa(hContact, m_szModuleName, FACEBOOK_KEY_NAME); @@ -551,7 +551,7 @@ INT_PTR FacebookProto::CancelFriendship(WPARAM wParam,LPARAM lParam) mir_sntprintf(tstr,SIZEOF(tstr),TranslateT("Do you want to cancel your friendship with '%s'?"), tname); if (MessageBox(0, tstr, m_tszUserName, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2) == IDYES) { - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); if (id == NULL) return 1; @@ -576,7 +576,7 @@ INT_PTR FacebookProto::RequestFriendship(WPARAM wParam,LPARAM lParam) HANDLE hContact = reinterpret_cast(wParam); - ptrA id = db_get_sa(hContact, m_szModuleName, FACEBOOK_KEY_ID); + ptrA id( getStringA(hContact, FACEBOOK_KEY_ID)); if (id == NULL) return 1; @@ -645,7 +645,7 @@ void FacebookProto::OpenUrl(std::string url) } // Make absolute url - bool useHttps = db_get_b(NULL, m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS, 1) > 0; + bool useHttps = getByte(FACEBOOK_KEY_FORCE_HTTPS, 1) > 0; url = (useHttps ? HTTP_PROTO_SECURE : HTTP_PROTO_REGULAR) + facy.get_server_type() + url; } diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp index c67474a25a..f7c6889c66 100644 --- a/protocols/FacebookRM/src/theme.cpp +++ b/protocols/FacebookRM/src/theme.cpp @@ -146,7 +146,7 @@ void UninitContactMenus() int FacebookProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam) { HANDLE hContact = reinterpret_cast(wParam); - bool isChatroom = db_get_b(hContact, m_szModuleName, "ChatRoom", 0) > 0; + bool isChatroom = getByte(hContact, "ChatRoom", 0) > 0; Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_PROFILE], true); Menu_ShowItem(g_hContactMenuItems[CMI_VISIT_FRIENDSHIP], !isChatroom); @@ -154,7 +154,7 @@ int FacebookProto::OnPrebuildContactMenu(WPARAM wParam,LPARAM lParam) if (!isOffline() && !isChatroom) { bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0; - BYTE type = db_get_b(hContact, m_szModuleName, FACEBOOK_KEY_CONTACT_TYPE, 0); + BYTE type = getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0); Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_ASK], ctrlPressed || type == CONTACT_NONE || !type); Menu_ShowItem(g_hContactMenuItems[CMI_AUTH_GRANT], ctrlPressed || type == CONTACT_APPROVE); -- cgit v1.2.3