diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-08-07 00:09:49 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-08-07 00:09:49 +0000 |
commit | 868e1f90c63aec0b5a22db8bfd65ed482326b0f4 (patch) | |
tree | 5cb6147bd0bbd71d5f245fa5db291f16d193fb5e /protocols/FacebookRM | |
parent | 2a8f165b498b1f8210f97e8c1f55d226d9b95da4 (diff) |
Facebook: Remove DBVARIANT where possible
git-svn-id: http://svn.miranda-ng.org/main/trunk@10101 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r-- | protocols/FacebookRM/src/connection.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/dialogs.cpp | 61 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 480 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 24 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 12 |
5 files changed, 276 insertions, 303 deletions
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index b234928fc4..21cadf807d 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -143,8 +143,6 @@ bool FacebookProto::NegotiateConnection() { debugLogA("***** Negotiating connection with Facebook"); - DBVARIANT dbv = {0}; - ptrA username( getStringA(FACEBOOK_KEY_LOGIN)); if (!username || !strlen(username)) { NotifyEvent(m_tszUserName,TranslateT("Please enter a username."),NULL,FACEBOOK_EVENT_CLIENT); diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index 326cb85326..c3af445c23 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -38,37 +38,33 @@ static BOOL StoreDBCheckState(FacebookProto* ppro, HWND hwnd, int idCtrl, const INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
- FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
+ FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
switch (message)
{
case WM_INITDIALOG:
+ {
TranslateDialogDefault(hwnd);
proto = reinterpret_cast<FacebookProto*>(lparam);
- SetWindowLongPtr(hwnd,GWLP_USERDATA,lparam);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
- DBVARIANT dbv;
- if (!db_get_s(0,proto->ModuleName(),FACEBOOK_KEY_LOGIN,&dbv))
- {
- SetDlgItemTextA(hwnd,IDC_UN,dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
+ if (login != NULL)
+ SetDlgItemTextA(hwnd, IDC_UN, login);
- if (!db_get_s(0,proto->ModuleName(),FACEBOOK_KEY_PASS,&dbv))
- {
- SetDlgItemTextA(hwnd,IDC_PW,dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
+ if (password != NULL)
+ SetDlgItemTextA(hwnd, IDC_PW, password);
if (!proto->isOffline())
{
- SendMessage(GetDlgItem(hwnd,IDC_UN),EM_SETREADONLY,1,0);
- SendMessage(GetDlgItem(hwnd,IDC_PW),EM_SETREADONLY,1,0);
+ SendMessage(GetDlgItem(hwnd, IDC_UN), EM_SETREADONLY, 1, 0);
+ SendMessage(GetDlgItem(hwnd, IDC_PW), EM_SETREADONLY, 1, 0);
}
return TRUE;
-
+ }
case WM_COMMAND:
if (LOWORD(wparam) == IDC_NEWACCOUNTLINK)
{
@@ -92,11 +88,11 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp {
char str[128];
- GetDlgItemTextA(hwnd,IDC_UN,str,sizeof(str));
- db_set_s(0,proto->ModuleName(),FACEBOOK_KEY_LOGIN,str);
+ GetDlgItemTextA(hwnd, IDC_UN, str, sizeof(str));
+ db_set_s(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN, str);
- GetDlgItemTextA(hwnd,IDC_PW,str,sizeof(str));
- db_set_s(0,proto->ModuleName(),FACEBOOK_KEY_PASS,str);
+ GetDlgItemTextA(hwnd, IDC_PW, str, sizeof(str));
+ db_set_s(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS, str);
return TRUE;
}
break;
@@ -345,18 +341,13 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp proto = reinterpret_cast<FacebookProto*>(lparam);
SetWindowLongPtr(hwnd,GWLP_USERDATA,lparam);
- DBVARIANT dbv;
- if (!db_get_s(0,proto->ModuleName(),FACEBOOK_KEY_LOGIN,&dbv))
- {
- SetDlgItemTextA(hwnd,IDC_UN,dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
+ if (login != NULL)
+ SetDlgItemTextA(hwnd, IDC_UN, login);
- if (!db_get_s(0,proto->ModuleName(),FACEBOOK_KEY_PASS,&dbv))
- {
- SetDlgItemTextA(hwnd,IDC_PW,dbv.pszVal);
- db_free(&dbv);
- }
+ ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
+ if (password!= NULL)
+ SetDlgItemTextA(hwnd, IDC_PW, password);
if (!proto->isOffline())
{
@@ -366,11 +357,9 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, FACEBOOK_GROUP_NAME_LIMIT, 0);
- if (!db_get_ts(0,proto->ModuleName(),FACEBOOK_KEY_DEF_GROUP,&dbv))
- {
- SetDlgItemText(hwnd,IDC_GROUP,dbv.ptszVal);
- db_free(&dbv);
- }
+ ptrT group(db_get_tsa(NULL, proto->ModuleName(), FACEBOOK_KEY_DEF_GROUP));
+ if (group != NULL)
+ SetDlgItemText(hwnd, IDC_GROUP, group);
LoadDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, DEFAULT_DISABLE_STATUS_NOTIFY);
LoadDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS);
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 559377c02d..841ca24f17 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -1,241 +1,239 @@ -/*
-
-Facebook plugin for Miranda Instant Messenger
-_____________________________________________
-
-Copyright © 2009-11 Michal Zelinka, 2011-13 Robert Pösel
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "common.h"
-
-int FacebookProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre)
-{
- StopTyping(hContact);
-
- // Remove from "readers" list and clear statusbar
- facy.readers.erase(hContact);
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, NULL);
-
- return Proto_RecvMessage(hContact, pre);
-}
-
-void FacebookProto::SendMsgWorker(void *p)
-{
- if(p == NULL)
- return;
-
- send_direct *data = static_cast<send_direct*>(p);
-
- DBVARIANT dbv;
-
- if (!isOnline())
- {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)Translate("You cannot send messages when you are offline."));
- }
- else if (!getString(data->hContact, FACEBOOK_KEY_ID, &dbv))
- {
- //ParseSmileys(data->msg, data->hContact);
-
- int retries = 5;
- std::string error_text = "";
- bool result = false;
- while (!result && retries > 0) {
- result = facy.send_message(data->hContact, dbv.pszVal, data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY);
- retries--;
- }
- if (result) {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, data->msgid, 0);
-
- // Remove from "readers" list and clear statusbar
- facy.readers.erase(data->hContact);
- CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)data->hContact, NULL);
- } else {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)error_text.c_str());
- }
- db_free(&dbv);
- }
-
- delete data;
-}
-
-void FacebookProto::SendChatMsgWorker(void *p)
-{
- if(p == NULL)
- return;
-
- send_chat *data = static_cast<send_chat*>(p);
- std::string err_message = "";
-
- // replace %% back to %, because chat automatically does this to sent messages
- utils::text::replace_all(&data->msg, "%%", "%");
-
- MCONTACT hContact = ChatIDToHContact(std::tstring(_A2T(data->chat_id.c_str())));
- if (hContact) {
- std::string tid;
- DBVARIANT dbv;
- if (!getString(hContact, FACEBOOK_KEY_TID, &dbv)) {
- tid = dbv.pszVal;
- db_free(&dbv);
- } else {
- std::string post_data = "threads[group_ids][0]=" + utils::url::encode(data->chat_id);
- post_data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0");
- post_data += "&__user=" + facy.self_.user_id;
- post_data += "&phstamp=0";
-
- http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data);
-
- tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\"");
- setString(hContact, FACEBOOK_KEY_TID, tid.c_str());
- debugLogA(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str());
- }
-
- if (!tid.empty()) {
- if (facy.send_message(hContact, tid, data->msg, &err_message, MESSAGE_TID))
- UpdateChat(_A2T(data->chat_id.c_str()), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str());
- else
- UpdateChat(_A2T(data->chat_id.c_str()), NULL, NULL, err_message.c_str());
- }
- }
-
- delete data;
-}
-
-int FacebookProto::SendMsg(MCONTACT hContact, int flags, const char *msg)
-{
- // TODO: msg comes as Unicode (retyped wchar_t*), why should we convert it as ANSI to UTF-8? o_O
- if (flags & PREF_UNICODE)
- msg = mir_utf8encode(msg);
-
- facy.msgid_ = (facy.msgid_ % 1024) + 1;
- ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, msg, (HANDLE)facy.msgid_));
- return facy.msgid_;
-}
-
-int FacebookProto::UserIsTyping(MCONTACT hContact,int type)
-{
- if (hContact && isOnline())
- ForkThread(&FacebookProto::SendTypingWorker, new send_typing(hContact, type));
-
- return 0;
-}
-
-void FacebookProto::SendTypingWorker(void *p)
-{
- if (p == NULL)
- return;
-
- send_typing *typing = static_cast<send_typing*>(p);
-
- // Dont send typing notifications to not friends - Facebook won't give them that info anyway
- if (!isChatRoom(typing->hContact) && getWord(typing->hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) {
- delete typing;
- return;
- }
-
- // TODO RM: maybe better send typing optimalization
- facy.is_typing_ = (typing->status == PROTOTYPE_SELFTYPING_ON);
- SleepEx(2000, true);
-
- if (!facy.is_typing_ == (typing->status == PROTOTYPE_SELFTYPING_ON)) {
- delete typing;
- return;
- }
-
- const char *value = (isChatRoom(typing->hContact) ? FACEBOOK_KEY_TID : FACEBOOK_KEY_ID);
- ptrA id( getStringA(typing->hContact, value));
- if (id != NULL) {
- std::string data = "&source=mercury-chat";
- data += (typing->status == PROTOTYPE_SELFTYPING_ON ? "&typ=1" : "&typ=0");
-
- data += "&to=";
- if (isChatRoom(typing->hContact))
- data += "&thread=";
- data += utils::url::encode(std::string(id));
-
- data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0");
- data += "&lsd=&phstamp=0&__user=" + facy.self_.user_id;
-
- http::response resp = facy.flap(REQUEST_TYPING_SEND, &data);
- }
-
- delete typing;
-}
-
-void FacebookProto::ReadMessageWorker(void *p)
-{
- if (p == NULL)
- return;
-
- MCONTACT hContact = (MCONTACT)p;
-
- if (getBool(FACEBOOK_KEY_KEEP_UNREAD, 0) || getBool(hContact, FACEBOOK_KEY_KEEP_UNREAD, 0))
- return;
-
- // mark message read (also send seen info)
- ptrA tid( getStringA(hContact, FACEBOOK_KEY_TID));
- if (tid == NULL)
- return;
-
- std::string data = "ids[" + utils::url::encode(std::string(tid)) + "]=true";
- data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0");
- data += "&__user=" + facy.self_.user_id;
- data += "&__a=1&__dyn=&__req=&ttstamp=0";
-
- facy.flap(REQUEST_MARK_READ, &data);
-}
-
-void FacebookProto::ParseSmileys(std::string message, MCONTACT hContact)
-{
- if (!getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS))
- return;
-
- HANDLE nlc = NULL;
- std::string::size_type pos = 0;
- bool anything = false;
- while ((pos = message.find("[[", pos)) != std::string::npos) {
- std::string::size_type pos2 = message.find("]]", pos);
- if (pos2 == std::string::npos)
- break;
-
- std::string smiley = message.substr(pos, pos2+2-pos);
- pos = pos2;
-
- std::string url = FACEBOOK_URL_PICTURE;
- utils::text::replace_first(&url, "%s", smiley.substr(2, smiley.length()-4));
-
- std::string b64 = ptrA( mir_base64_encode((PBYTE)smiley.c_str(), (unsigned)smiley.length()));
- b64 = utils::url::encode(b64);
-
- std::tstring filename = GetAvatarFolder() + L"\\smileys\\" + (TCHAR*)_A2T(b64.c_str()) + _T(".jpg");
- FILE *f = _tfopen(filename.c_str(), _T("r"));
- if (f) {
- fclose(f);
- } else {
- facy.save_url(url, filename, nlc);
- }
- ptrT path( _tcsdup(filename.c_str()));
-
- SMADD_CONT cont;
- cont.cbSize = sizeof(SMADD_CONT);
- cont.hContact = hContact;
- cont.type = 1;
- cont.path = path;
-
- CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
- }
- Netlib_CloseHandle(nlc);
-}
+/* + +Facebook plugin for Miranda Instant Messenger +_____________________________________________ + +Copyright � 2009-11 Michal Zelinka, 2011-13 Robert P�sel + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "common.h" + +int FacebookProto::RecvMsg(MCONTACT hContact, PROTORECVEVENT *pre) +{ + StopTyping(hContact); + + // Remove from "readers" list and clear statusbar + facy.readers.erase(hContact); + CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, NULL); + + return Proto_RecvMessage(hContact, pre); +} + +void FacebookProto::SendMsgWorker(void *p) +{ + if(p == NULL) + return; + + send_direct *data = static_cast<send_direct*>(p); + + ptrA id(getStringA(data->hContact, FACEBOOK_KEY_ID)); + + if (!isOnline()) { + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)Translate("You cannot send messages when you are offline.")); + } else if (id == NULL) { + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, 0); + } else { + //ParseSmileys(data->msg, data->hContact); + + int retries = 5; + std::string error_text = ""; + bool result = false; + while (!result && retries > 0) { + result = facy.send_message(data->hContact, std::string(id), data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY); + retries--; + } + if (result) { + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, data->msgid, 0); + + // Remove from "readers" list and clear statusbar + facy.readers.erase(data->hContact); + CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)data->hContact, NULL); + } + else { + ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, (LPARAM)error_text.c_str()); + } + } + + delete data; +} + +void FacebookProto::SendChatMsgWorker(void *p) +{ + if(p == NULL) + return; + + send_chat *data = static_cast<send_chat*>(p); + std::string err_message = ""; + + // replace %% back to %, because chat automatically does this to sent messages + utils::text::replace_all(&data->msg, "%%", "%"); + + MCONTACT hContact = ChatIDToHContact(std::tstring(_A2T(data->chat_id.c_str()))); + if (hContact) { + ptrA tid_(getStringA(hContact, FACEBOOK_KEY_TID)); + std::string tid; + if (tid_ != NULL) { + tid = tid_; + } else { + std::string post_data = "threads[group_ids][0]=" + utils::url::encode(data->chat_id); + post_data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); + post_data += "&__user=" + facy.self_.user_id; + post_data += "&phstamp=0"; + + http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data); + + tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\""); + setString(hContact, FACEBOOK_KEY_TID, tid.c_str()); + debugLogA(" Got thread info: %s = %s", data->chat_id.c_str(), tid.c_str()); + } + + if (!tid.empty()) { + if (facy.send_message(hContact, tid, data->msg, &err_message, MESSAGE_TID)) + UpdateChat(_A2T(data->chat_id.c_str()), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str()); + else + UpdateChat(_A2T(data->chat_id.c_str()), NULL, NULL, err_message.c_str()); + } + } + + delete data; +} + +int FacebookProto::SendMsg(MCONTACT hContact, int flags, const char *msg) +{ + // TODO: msg comes as Unicode (retyped wchar_t*), why should we convert it as ANSI to UTF-8? o_O + if (flags & PREF_UNICODE) + msg = mir_utf8encode(msg); + + facy.msgid_ = (facy.msgid_ % 1024) + 1; + ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, msg, (HANDLE)facy.msgid_)); + return facy.msgid_; +} + +int FacebookProto::UserIsTyping(MCONTACT hContact,int type) +{ + if (hContact && isOnline()) + ForkThread(&FacebookProto::SendTypingWorker, new send_typing(hContact, type)); + + return 0; +} + +void FacebookProto::SendTypingWorker(void *p) +{ + if (p == NULL) + return; + + send_typing *typing = static_cast<send_typing*>(p); + + // Dont send typing notifications to not friends - Facebook won't give them that info anyway + if (!isChatRoom(typing->hContact) && getWord(typing->hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) != CONTACT_FRIEND) { + delete typing; + return; + } + + // TODO RM: maybe better send typing optimalization + facy.is_typing_ = (typing->status == PROTOTYPE_SELFTYPING_ON); + SleepEx(2000, true); + + if (!facy.is_typing_ == (typing->status == PROTOTYPE_SELFTYPING_ON)) { + delete typing; + return; + } + + const char *value = (isChatRoom(typing->hContact) ? FACEBOOK_KEY_TID : FACEBOOK_KEY_ID); + ptrA id( getStringA(typing->hContact, value)); + if (id != NULL) { + std::string data = "&source=mercury-chat"; + data += (typing->status == PROTOTYPE_SELFTYPING_ON ? "&typ=1" : "&typ=0"); + + data += "&to="; + if (isChatRoom(typing->hContact)) + data += "&thread="; + data += utils::url::encode(std::string(id)); + + data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); + data += "&lsd=&phstamp=0&__user=" + facy.self_.user_id; + + http::response resp = facy.flap(REQUEST_TYPING_SEND, &data); + } + + delete typing; +} + +void FacebookProto::ReadMessageWorker(void *p) +{ + if (p == NULL) + return; + + MCONTACT hContact = (MCONTACT)p; + + if (getBool(FACEBOOK_KEY_KEEP_UNREAD, 0) || getBool(hContact, FACEBOOK_KEY_KEEP_UNREAD, 0)) + return; + + // mark message read (also send seen info) + ptrA tid( getStringA(hContact, FACEBOOK_KEY_TID)); + if (tid == NULL) + return; + + std::string data = "ids[" + utils::url::encode(std::string(tid)) + "]=true"; + data += "&fb_dtsg=" + (facy.dtsg_.length() ? facy.dtsg_ : "0"); + data += "&__user=" + facy.self_.user_id; + data += "&__a=1&__dyn=&__req=&ttstamp=0"; + + facy.flap(REQUEST_MARK_READ, &data); +} + +void FacebookProto::ParseSmileys(std::string message, MCONTACT hContact) +{ + if (!getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) + return; + + HANDLE nlc = NULL; + std::string::size_type pos = 0; + bool anything = false; + while ((pos = message.find("[[", pos)) != std::string::npos) { + std::string::size_type pos2 = message.find("]]", pos); + if (pos2 == std::string::npos) + break; + + std::string smiley = message.substr(pos, pos2+2-pos); + pos = pos2; + + std::string url = FACEBOOK_URL_PICTURE; + utils::text::replace_first(&url, "%s", smiley.substr(2, smiley.length()-4)); + + std::string b64 = ptrA( mir_base64_encode((PBYTE)smiley.c_str(), (unsigned)smiley.length())); + b64 = utils::url::encode(b64); + + std::tstring filename = GetAvatarFolder() + L"\\smileys\\" + (TCHAR*)_A2T(b64.c_str()) + _T(".jpg"); + FILE *f = _tfopen(filename.c_str(), _T("r")); + if (f) { + fclose(f); + } else { + facy.save_url(url, filename, nlc); + } + ptrT path( _tcsdup(filename.c_str())); + + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = hContact; + cont.type = 1; + cont.path = path; + + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); + } + Netlib_CloseHandle(nlc); +} diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index f3d91e02f1..357e6dd655 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -180,15 +180,12 @@ void FacebookProto::ProcessFriendList(void*) if ( isChatRoom(hContact)) continue; - DBVARIANT dbv; facebook_user *fbu; - if (!getString(hContact, FACEBOOK_KEY_ID, &dbv)) { - std::string id = dbv.pszVal; - db_free(&dbv); - + ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); + if (id != NULL) { std::map< std::string, facebook_user* >::iterator iter; - if ((iter = friends.find(id)) != friends.end()) { + if ((iter = friends.find(std::string(id))) != friends.end()) { // Found contact, update it and remove from map fbu = iter->second; @@ -247,8 +244,10 @@ void FacebookProto::ProcessFriendList(void*) if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0) && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) == CONTACT_FRIEND) { setDword(hContact, FACEBOOK_KEY_DELETED, ::time(NULL)); setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); - + std::string contactname = id; + + DBVARIANT dbv; if (!getStringUtf(hContact, FACEBOOK_KEY_NICK, &dbv)) { contactname = dbv.pszVal; db_free(&dbv); @@ -874,15 +873,8 @@ void FacebookProto::ProcessFriendRequests(void*) MCONTACT hContact = AddToContactList(fbu, CONTACT_APPROVE); setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_APPROVE); - bool seen = false; - - DBVARIANT dbv; - if (!getString(hContact, "RequestTime", &dbv)) { - seen = !strcmp(dbv.pszVal, time.c_str()); - db_free(&dbv); - } - - if (!seen) { + ptrA oldTime(getStringA(hContact, "RequestTime")); + if (oldTime == NULL || strcmp(oldTime, time.c_str())) { // This is new request setString(hContact, "RequestTime", time.c_str()); diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index 0f8685b91b..8d9338be37 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -346,15 +346,11 @@ int FacebookProto::GetInfo(MCONTACT hContact, int infoType) INT_PTR FacebookProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam) { - DBVARIANT dbv = { DBVT_TCHAR }; - if (!getTString("StatusMsg", &dbv) && lstrlen(dbv.ptszVal) != 0) - { - int res = (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(dbv.ptszVal) : (INT_PTR)mir_t2a(dbv.ptszVal); - db_free(&dbv); - return res; - } else { + ptrT statusMsg(getTStringA("StatusMsg")); + if (statusMsg == NULL || _tcslen(statusMsg) == 0) return 0; - } + + return (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(statusMsg) : (INT_PTR)mir_t2a(statusMsg); } int FacebookProto::OnIdleChanged(WPARAM wParam, LPARAM lParam) |