summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-12-20 19:10:47 +0000
committerRobert Pösel <robyer@seznam.cz>2014-12-20 19:10:47 +0000
commit58e5ea7bf98f8468f869522c89ffe961112bd98d (patch)
tree69cd89a853c4f315247e5724c6005a3d9e5d1e4e /protocols
parent9f98d623506e7b7a86561152807526aeb2bb5be3 (diff)
Facebook: Various code improvements (as reported by Coverity analyser); version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@11546 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/client.h4
-rw-r--r--protocols/FacebookRM/src/connection.cpp2
-rw-r--r--protocols/FacebookRM/src/contacts.cpp64
-rw-r--r--protocols/FacebookRM/src/dialogs.cpp2
-rw-r--r--protocols/FacebookRM/src/entities.h4
-rw-r--r--protocols/FacebookRM/src/json.cpp69
-rw-r--r--protocols/FacebookRM/src/json.h18
-rw-r--r--protocols/FacebookRM/src/messages.cpp5
-rw-r--r--protocols/FacebookRM/src/process.cpp89
-rw-r--r--protocols/FacebookRM/src/proto.cpp18
-rw-r--r--protocols/FacebookRM/src/proto.h1
-rw-r--r--protocols/FacebookRM/src/theme.cpp2
-rw-r--r--protocols/FacebookRM/src/utils.cpp1
-rw-r--r--protocols/FacebookRM/src/version.h2
14 files changed, 137 insertions, 144 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index ca121b8722..bc1fb30d97 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -41,10 +41,12 @@ public:
https_ = is_idle_ = is_typing_ = false;
- buddies_lock_ = send_message_lock_ = notifications_lock_ = NULL;
+ buddies_lock_ = send_message_lock_ = notifications_lock_ = cookies_lock_ = NULL;
hMsgCon = NULL;
hFcbCon = NULL;
fcb_conn_lock_ = NULL;
+ handle_ = NULL;
+ parent = NULL;
}
HANDLE hMsgCon;
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index dfeabb0973..e38706ae61 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -92,7 +92,7 @@ void FacebookProto::ChangeStatus(void*)
debugLogA("***** Beginning SignOn process");
- m_enableChat = getBool(FACEBOOK_KEY_ENABLE_CHATS, true);
+ m_enableChat = getBool(FACEBOOK_KEY_ENABLE_CHATS, DEFAULT_ENABLE_CHATS);
m_iStatus = facy.self_.status_id = ID_STATUS_CONNECTING;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 6e7c281d17..a7196e5653 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -406,13 +406,11 @@ void FacebookProto::DeleteContactFromServer(void *data)
if (data == NULL)
return;
- if (isOffline()) {
- delete (std::string*)data;
- return;
- }
+ std::string id = *(std::string*)data;
+ delete (std::string*)data;
- std::string id = (*(std::string*)data);
- delete data;
+ if (isOffline())
+ return;
std::string query = "norefresh=true&unref=button_dropdown&confirmed=1&__a=1";
query += "&fb_dtsg=" + facy.dtsg_;
@@ -457,13 +455,11 @@ void FacebookProto::AddContactToServer(void *data)
if (data == NULL)
return;
- if (isOffline()) {
- delete (std::string*)data;
- return;
- }
+ std::string id = *(std::string*)data;
+ delete (std::string*)data;
- std::string id = (*(std::string*)data);
- delete data;
+ if (isOffline())
+ return;
std::string query = "action=add_friend&how_found=profile_button&ref_param=ts&outgoing_id=&unwanted=&logging_location=&no_flyout_on_click=false&ego_log_data=&lsd=";
query += "&fb_dtsg=" + facy.dtsg_;
@@ -486,7 +482,6 @@ void FacebookProto::AddContactToServer(void *data)
if (resp.code != HTTP_CODE_OK)
facy.handle_error("AddContactToServer");
-
}
void FacebookProto::ApproveContactToServer(void *data)
@@ -496,15 +491,13 @@ void FacebookProto::ApproveContactToServer(void *data)
if (data == NULL)
return;
- if (isOffline()) {
- delete (MCONTACT*)data;
- return;
- }
-
MCONTACT hContact = *(MCONTACT*)data;
- delete data;
+ delete (MCONTACT*)data;
+
+ if (isOffline())
+ return;
- ptrA id(ptrA(getStringA(hContact, FACEBOOK_KEY_ID)));
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (!id)
return;
@@ -534,13 +527,11 @@ void FacebookProto::CancelFriendsRequest(void *data)
if (data == NULL)
return;
- if (isOffline()) {
- delete (MCONTACT*)data;
- return;
- }
-
MCONTACT hContact = *(MCONTACT*)data;
- delete data;
+ delete (MCONTACT*)data;
+
+ if (isOffline())
+ return;
ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (!id)
@@ -572,13 +563,11 @@ void FacebookProto::IgnoreFriendshipRequest(void *data)
if (data == NULL)
return;
- if (isOffline()) {
- delete (MCONTACT*)data;
- return;
- }
-
MCONTACT hContact = *(MCONTACT*)data;
- delete data;
+ delete (MCONTACT*)data;
+
+ if (isOffline())
+ return;
ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (!id)
@@ -614,15 +603,14 @@ void FacebookProto::SendPokeWorker(void *p)
if (p == NULL)
return;
+ std::string *id = (std::string*)p;
+
if (isOffline()) {
- delete (std::string*)p;
+ delete id;
return;
}
- std::string id = (*(std::string*)p);
- delete p;
-
- std::string data = "poke_target=" + id;
+ std::string data = "poke_target=" + *id;
data += "&do_confirm=0";
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
@@ -648,6 +636,8 @@ void FacebookProto::SendPokeWorker(void *p)
}
facy.handle_success("SendPokeWorker");
+
+ delete id;
}
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp
index d124c2191d..d6a94a4f1a 100644
--- a/protocols/FacebookRM/src/dialogs.cpp
+++ b/protocols/FacebookRM/src/dialogs.cpp
@@ -398,6 +398,8 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
case IDC_SECURE_CHANNEL:
if (IsDlgButtonChecked(hwnd, IDC_SECURE_CHANNEL))
MessageBox(hwnd, TranslateT("Note: Make sure you have disabled 'Validate SSL certificates' option in Network options to work properly."), proto->m_tszUserName, MB_OK);
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
default:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 99e171348b..384e0b2ec9 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -71,7 +71,9 @@ struct facebook_user
struct facebook_chatroom
{
- facebook_chatroom(std::tstring thread_id) : thread_id(thread_id) {}
+ facebook_chatroom(std::tstring thread_id) : thread_id(thread_id) {
+ this->last_active = 0;
+ }
std::tstring thread_id;
std::tstring chat_name;
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index b7f85d04d5..a8d8e8ea7a 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -22,10 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common.h"
-int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user >* buddy_list)
+int facebook_json_parser::parse_buddy_list(std::string *data, List::List< facebook_user >* buddy_list)
{
facebook_user* current = NULL;
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -196,9 +196,9 @@ void parseUser(JSONNODE *it, facebook_user *fbu)
}
}
-int facebook_json_parser::parse_friends(void* data, std::map< std::string, facebook_user* >* friends)
+int facebook_json_parser::parse_friends(std::string *data, std::map< std::string, facebook_user* >* friends)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -222,9 +222,9 @@ int facebook_json_parser::parse_friends(void* data, std::map< std::string, faceb
}
-int facebook_json_parser::parse_notifications(void *data, std::map< std::string, facebook_notification* > *notifications)
+int facebook_json_parser::parse_notifications(std::string *data, std::map< std::string, facebook_notification* > *notifications)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -396,7 +396,7 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE
}
}
-int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_notification* >* notifications, bool inboxOnly)
+int facebook_json_parser::parse_messages(std::string *data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_notification* >* notifications, bool inboxOnly)
{
// remove old received messages from map
for (std::map<std::string, int>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end();) {
@@ -409,7 +409,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
}
}
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -457,7 +457,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
if (!proto->m_enableChat)
continue;
- std::tstring tid = json_as_string(threadid);
+ std::tstring tid = ptrT(json_as_string(threadid));
std::string reader_id = json_as_pstring(reader);
std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid);
@@ -656,7 +656,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
if (from_ == NULL || thread_ == NULL || st_ == NULL)
continue;
- std::tstring tid = json_as_string(thread_);
+ std::tstring tid = ptrT(json_as_string(thread_));
std::string from_id = json_as_pstring(from_);
std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid);
@@ -714,8 +714,9 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
else if (t == "buddylist_overlay") {
// we opened/closed chat window - pretty useless info for us
continue;
- }
- else if (t == "ticker_update:home") {
+ } else if (t == "ticker_update:home") {
+ JSONNODE *actor_ = json_get(it, "actor");
+ JSONNODE *time_ = json_get(it, "time");
JSONNODE *story_ = json_get(it, "story_xhp");
std::string text = json_as_pstring(story_);
@@ -747,7 +748,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
if (!log_data_ || !log_body_ || !thread_id_ || !log_type_)
continue;
- std::tstring thread_id = json_as_string(thread_id_);
+ std::tstring thread_id = ptrT(json_as_string(thread_id_));
std::string type = json_as_pstring(log_type_);
std::string message_text = json_as_pstring(log_body_);
@@ -816,9 +817,9 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::string >* threads, bool inboxOnly)
+int facebook_json_parser::parse_unread_threads(std::string *data, std::vector< std::string >* threads, bool inboxOnly)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -852,9 +853,9 @@ int facebook_json_parser::parse_unread_threads(void* data, std::vector< std::str
return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_thread_messages(void* data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_chatroom* >* chatrooms, bool unreadOnly, bool inboxOnly)
+int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< facebook_message* >* messages, std::map< std::string, facebook_chatroom* >* chatrooms, bool unreadOnly, bool inboxOnly)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -908,7 +909,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
chatrooms->erase(iter); // this is not chatroom
}
else {
- iter->second->chat_name = json_as_string(name); // TODO: create name from users if there is no name...
+ iter->second->chat_name = ptrT(json_as_string(name)); // TODO: create name from users if there is no name...
JSONNODE *participants = json_get(it, "participants");
for (unsigned int j = 0; j < json_size(participants); j++) {
@@ -970,6 +971,12 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
if (message_text.empty())
continue;
+ bool isUnread = (is_unread != NULL && json_as_bool(is_unread));
+
+ // Ignore read messages if we want only unread messages
+ if (unreadOnly && !isUnread)
+ continue;
+
facebook_message* message = new facebook_message();
message->message_text = message_text;
if (author_email != NULL)
@@ -978,11 +985,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
message->thread_id = thread_id;
message->message_id = message_id;
message->isIncoming = (author_id != proto->facy.self_.user_id);
- message->isUnread = (is_unread != NULL && json_as_bool(is_unread));
-
- // Ignore read messages if we want only unread messages
- if (unreadOnly && !message->isUnread)
- continue;
+ message->isUnread = isUnread;
std::map<std::string, facebook_chatroom*>::iterator iter = chatrooms->find(thread_id);
if (iter != chatrooms->end()) {
@@ -996,8 +999,8 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
std::map<std::string, std::string>::iterator iter = thread_ids.find(thread_id);
if (iter != thread_ids.end()) {
message->user_id = iter->second; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
- }
- else {
+ } else {
+ delete message;
continue;
}
}
@@ -1008,9 +1011,9 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo
return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_thread_info(void* data, std::string* user_id)
+int facebook_json_parser::parse_thread_info(std::string *data, std::string* user_id)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -1047,9 +1050,9 @@ int facebook_json_parser::parse_thread_info(void* data, std::string* user_id)
}
-int facebook_json_parser::parse_user_info(void* data, facebook_user* fbu)
+int facebook_json_parser::parse_user_info(std::string *data, facebook_user* fbu)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -1081,9 +1084,9 @@ int facebook_json_parser::parse_user_info(void* data, facebook_user* fbu)
return EXIT_SUCCESS;
}
-int facebook_json_parser::parse_chat_info(void* data, facebook_chatroom* fbc)
+int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* fbc)
{
- std::string jsonData = static_cast<std::string*>(data)->substr(9);
+ std::string jsonData = data->substr(9);
JSONROOT root(jsonData.c_str());
if (root == NULL)
@@ -1129,7 +1132,7 @@ int facebook_json_parser::parse_chat_info(void* data, facebook_chatroom* fbc)
if (thread_id_ == NULL || is_canonical_user_ == NULL || json_as_bool(is_canonical_user_))
continue;
- std::tstring tid = json_as_string(thread_id_);
+ std::tstring tid = ptrT(json_as_string(thread_id_));
// TODO: allow more users to parse at once
if (fbc->thread_id != tid) {
@@ -1143,7 +1146,7 @@ int facebook_json_parser::parse_chat_info(void* data, facebook_chatroom* fbc)
fbc->participants.insert(std::make_pair(user_id.substr(5), ""));
}
- fbc->chat_name = json_as_string(name_);
+ fbc->chat_name = ptrT(json_as_string(name_));
}
return EXIT_SUCCESS;
diff --git a/protocols/FacebookRM/src/json.h b/protocols/FacebookRM/src/json.h
index cae57eb412..ed224cd805 100644
--- a/protocols/FacebookRM/src/json.h
+++ b/protocols/FacebookRM/src/json.h
@@ -30,15 +30,15 @@ class facebook_json_parser
{
public:
FacebookProto* proto;
- int parse_buddy_list(void*, List::List< facebook_user >*);
- int parse_friends(void*, std::map< std::string, facebook_user* >*);
- int parse_notifications(void*, std::map< std::string, facebook_notification* >*);
- int parse_messages(void*, std::vector< facebook_message* >*, std::map< std::string, facebook_notification* >*, bool inboxOnly);
- int parse_unread_threads(void*, std::vector< std::string >*, bool inboxOnly);
- int parse_thread_messages(void*, std::vector< facebook_message* >*, std::map< std::string, facebook_chatroom* >*, bool unreadOnly, bool inboxOnly);
- int parse_thread_info(void* data, std::string* user_id);
- int parse_user_info(void* data, facebook_user* fbu);
- int parse_chat_info(void* data, facebook_chatroom* fbc);
+ int parse_buddy_list(std::string*, List::List< facebook_user >*);
+ int parse_friends(std::string*, std::map< std::string, facebook_user* >*);
+ int parse_notifications(std::string*, std::map< std::string, facebook_notification* >*);
+ int parse_messages(std::string*, std::vector< facebook_message* >*, std::map< std::string, facebook_notification* >*, bool inboxOnly);
+ int parse_unread_threads(std::string*, std::vector< std::string >*, bool inboxOnly);
+ int parse_thread_messages(std::string*, std::vector< facebook_message* >*, std::map< std::string, facebook_chatroom* >*, bool unreadOnly, bool inboxOnly);
+ int parse_thread_info(std::string* data, std::string* user_id);
+ int parse_user_info(std::string* data, facebook_user* fbu);
+ int parse_chat_info(std::string* data, facebook_chatroom* fbc);
facebook_json_parser(FacebookProto* proto)
{
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index de6811cf2c..192ef1fb8c 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -114,11 +114,10 @@ void FacebookProto::SendChatMsgWorker(void *p)
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);
+ std::string message = (flags & PREF_UNICODE) ? ptrA(mir_utf8encode(msg)) : msg;
facy.msgid_ = (facy.msgid_ % 1024) + 1;
- ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, msg, (HANDLE)facy.msgid_));
+ ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, (HANDLE)facy.msgid_));
return facy.msgid_;
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 36b95aad68..c0e6f28ee2 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -56,7 +56,7 @@ void FacebookProto::ProcessBuddyList(void*)
CODE_BLOCK_TRY
- facebook_json_parser* p = new facebook_json_parser(this);
+ facebook_json_parser* p = new facebook_json_parser(this);
p->parse_buddy_list(&resp.data, &facy.buddies);
delete p;
@@ -338,21 +338,20 @@ void FacebookProto::ProcessUnreadMessages(void*)
facy.handle_success("ProcessUnreadMessages");
}
-void FacebookProto::ProcessUnreadMessage(void *p)
+void FacebookProto::ProcessUnreadMessage(void *data)
{
- if (p == NULL)
+ if (data == NULL)
return;
+ std::vector<std::string> *threads = (std::vector<std::string>*)data;
+
if (isOffline()) {
- delete (std::vector<std::string>*)p;
+ delete threads;
return;
}
facy.handle_entry("ProcessUnreadMessage");
- std::vector<std::string> threads = *(std::vector<std::string>*)p;
- delete (std::vector<std::string>*)p;
-
int offset = 0;
int limit = 21;
@@ -363,14 +362,14 @@ void FacebookProto::ProcessUnreadMessage(void *p)
http::response resp;
- while (!threads.empty()) {
+ while (!threads->empty()) {
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
- for (std::vector<std::string>::size_type i = 0; i < threads.size(); i++) {
- std::string thread_id = utils::url::encode(threads[i]);
+ for (std::vector<std::string>::size_type i = 0; i < threads->size(); i++) {
+ std::string thread_id = utils::url::encode(threads->at(i));
// request messages from thread
data += "&messages[thread_ids][" + thread_id;
@@ -389,7 +388,7 @@ void FacebookProto::ProcessUnreadMessage(void *p)
CODE_BLOCK_TRY
- std::vector<facebook_message*> messages;
+ std::vector<facebook_message*> messages;
std::map<std::string, facebook_chatroom*> chatrooms;
facebook_json_parser* p = new facebook_json_parser(this);
@@ -431,11 +430,11 @@ void FacebookProto::ProcessUnreadMessage(void *p)
CODE_BLOCK_CATCH
- debugLogA("***** Error processing unread messages: %s", e.what());
+ debugLogA("***** Error processing unread messages: %s", e.what());
CODE_BLOCK_END
- facy.handle_success("ProcessUnreadMessage");
+ facy.handle_success("ProcessUnreadMessage");
}
else {
facy.handle_error("ProcessUnreadMessage");
@@ -444,8 +443,10 @@ void FacebookProto::ProcessUnreadMessage(void *p)
offset += limit;
limit = 20; // TODO: use better limits?
- threads.clear(); // TODO: if we have limit messages from one user, there may be more unread messages... continue with it... otherwise remove that threadd from threads list -- or do it in json parser? hm = allow more than "limit" unread messages to be parsed
+ threads->clear(); // TODO: if we have limit messages from one user, there may be more unread messages... continue with it... otherwise remove that threadd from threads list -- or do it in json parser? hm = allow more than "limit" unread messages to be parsed
}
+
+ delete threads;
}
void FacebookProto::LoadLastMessages(void *p)
@@ -849,19 +850,16 @@ void FacebookProto::ProcessMessages(void* data)
if (data == NULL)
return;
+ std::string* resp = (std::string*)data;
+
if (isOffline()) {
- delete (std::string*)data;
+ delete resp;
return;
}
- std::string* resp = (std::string*)data;
-
// receive messages from all folders by default, use hidden setting to receive only inbox messages
bool inboxOnly = getBool(FACEBOOK_KEY_INBOX_ONLY, 0);
- if (isOffline())
- goto exit;
-
debugLogA("***** Starting processing messages");
CODE_BLOCK_TRY
@@ -869,7 +867,7 @@ void FacebookProto::ProcessMessages(void* data)
std::vector< facebook_message* > messages;
facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_messages(data, &messages, &facy.notifications, inboxOnly);
+ p->parse_messages(resp, &messages, &facy.notifications, inboxOnly);
delete p;
bool local_timestamp = getBool(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0);
@@ -886,7 +884,6 @@ void FacebookProto::ProcessMessages(void* data)
CODE_BLOCK_END
- exit :
delete resp;
}
@@ -929,7 +926,7 @@ void FacebookProto::ProcessNotifications(void*)
CODE_BLOCK_TRY
- facebook_json_parser* p = new facebook_json_parser(this);
+ facebook_json_parser* p = new facebook_json_parser(this);
p->parse_notifications(&(resp.data), &facy.notifications);
delete p;
@@ -971,8 +968,7 @@ void FacebookProto::ProcessFriendRequests(void*)
if ((pos2 = reqs.find("<img src=", pos)) != std::string::npos) {
req = reqs.substr(pos, pos2 - pos);
pos = pos2 + 9;
- }
- else {
+ } else {
req = reqs.substr(pos);
last = true;
}
@@ -981,18 +977,19 @@ void FacebookProto::ProcessFriendRequests(void*)
std::string time = utils::text::source_get_value2(&get, "seenrequesttime=", "&\"");
std::string reason = utils::text::remove_html(utils::text::source_get_value(&req, 3, "<span", ">", "</span>"));
- facebook_user *fbu = new facebook_user();
- fbu->real_name = utils::text::remove_html(utils::text::source_get_value(&req, 3, "<strong", ">", "</strong>"));
- fbu->user_id = utils::text::source_get_value2(&get, "id=", "&\"");
+ facebook_user fbu;
+ fbu.real_name = utils::text::remove_html(utils::text::source_get_value(&req, 3, "<strong", ">", "</strong>"));
+ fbu.user_id = utils::text::source_get_value2(&get, "id=", "&\"");
- if (!fbu->user_id.empty() && !fbu->real_name.empty())
- {
- MCONTACT hContact = AddToContactList(fbu, CONTACT_APPROVE);
+ if (!fbu.user_id.empty() && !fbu.real_name.empty()) {
+ MCONTACT hContact = AddToContactList(&fbu, CONTACT_APPROVE);
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_APPROVE);
+ bool isNew = false;
ptrA oldTime(getStringA(hContact, "RequestTime"));
if (oldTime == NULL || strcmp(oldTime, time.c_str())) {
// This is new request
+ isNew = true;
setString(hContact, "RequestTime", time.c_str());
//blob is: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ), reason(ASCIIZ)
@@ -1003,26 +1000,21 @@ void FacebookProto::ProcessFriendRequests(void*)
dbei.timestamp = ::time(NULL);
dbei.flags = DBEF_UTF;
dbei.eventType = EVENTTYPE_AUTHREQUEST;
- dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + fbu->real_name.length() + fbu->user_id.length() + reason.length() + 5);
+ dbei.cbBlob = (DWORD)(sizeof(DWORD) * 2 + fbu.real_name.length() + fbu.user_id.length() + reason.length() + 5);
PBYTE pCurBlob = dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob);
*(PDWORD)pCurBlob = 0; pCurBlob += sizeof(DWORD); // UID
*(PDWORD)pCurBlob = (DWORD)hContact; pCurBlob += sizeof(DWORD); // Contact Handle
- strcpy((char*)pCurBlob, fbu->real_name.data()); pCurBlob += fbu->real_name.length() + 1; // Nickname
+ strcpy((char*)pCurBlob, fbu.real_name.data()); pCurBlob += fbu.real_name.length() + 1; // Nickname
*pCurBlob = '\0'; pCurBlob++; // First Name
*pCurBlob = '\0'; pCurBlob++; // Last Name
- strcpy((char*)pCurBlob, fbu->user_id.data()); pCurBlob += fbu->user_id.length() + 1; // E-mail (we use it for string ID)
+ strcpy((char*)pCurBlob, fbu.user_id.data()); pCurBlob += fbu.user_id.length() + 1; // E-mail (we use it for string ID)
strcpy((char*)pCurBlob, reason.data()); pCurBlob += reason.length() + 1; // Reason (we use it for info about common friends)
db_event_add(0, &dbei);
-
- debugLogA(" (New) Friendship request from: %s (%s) [%s]", fbu->real_name.c_str(), fbu->user_id.c_str(), time.c_str());
}
- else {
- debugLogA(" (Old) Friendship request from: %s (%s) [%s]", fbu->real_name.c_str(), fbu->user_id.c_str(), time.c_str());
- }
- }
- else {
+ debugLogA(" (%s) Friendship request from: %s (%s) [%s]", (isNew ? "New" : "Old"), fbu.real_name.c_str(), fbu.user_id.c_str(), time.c_str());
+ } else {
debugLogA(" !!! Wrong friendship request");
debugLogA("%s", req.c_str());
}
@@ -1180,16 +1172,13 @@ void FacebookProto::ProcessFeeds(void*)
for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++)
{
- ptrT tszTitle(mir_utf8decodeT(news[i]->title.c_str()));
- ptrT tszText(mir_utf8decodeT(news[i]->text.c_str()));
-
// Truncate text of newsfeed when it's too long
- if (_tcslen(tszText) > MAX_NEWSFEED_LEN) {
- TCHAR buf[MAX_NEWSFEED_LEN + 3 + 1] = { 0 };
- _tcsncpy(buf, tszText, MAX_NEWSFEED_LEN);
- _tcsncpy(&buf[MAX_NEWSFEED_LEN], _T("..."), 3);
- tszText = buf;
- }
+ std::tstring text = ptrT(mir_utf8decodeT(news[i]->text.c_str()));
+ if (text.length() > MAX_NEWSFEED_LEN)
+ text = text.substr(0, MAX_NEWSFEED_LEN) + _T("...");
+
+ ptrT tszTitle(mir_utf8decodeT(news[i]->title.c_str()));
+ ptrT tszText(mir_tstrdup(text.c_str()));
NotifyEvent(tszTitle, tszText, this->ContactIDToHContact(news[i]->user_id), FACEBOOK_EVENT_NEWSFEED, &news[i]->link);
delete news[i];
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 94fc964b18..aacb6f08a7 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -35,9 +35,13 @@ PROTO<FacebookProto>(proto_name, username)
facy.send_message_lock_ = CreateMutex(NULL, FALSE, NULL);
facy.fcb_conn_lock_ = CreateMutex(NULL, FALSE, NULL);
facy.notifications_lock_ = CreateMutex(NULL, FALSE, NULL);
+ facy.cookies_lock_ = CreateMutex(NULL, FALSE, NULL);
+
+ m_hMenuRoot = m_hMenuServicesRoot = m_hStatusMind = NULL;
m_invisible = false;
m_signingOut = false;
+ m_enableChat = DEFAULT_ENABLE_CHATS;
// Load custom locale, if set
ptrA locale(getStringA(FACEBOOK_KEY_LOCALE));
@@ -118,6 +122,7 @@ FacebookProto::~FacebookProto()
WaitForSingleObject(facy.buddies_lock_, IGNORE);
WaitForSingleObject(facy.send_message_lock_, IGNORE);
WaitForSingleObject(facy.notifications_lock_, IGNORE);
+ WaitForSingleObject(facy.cookies_lock_, IGNORE);
CloseHandle(signon_lock_);
CloseHandle(avatar_lock_);
@@ -127,6 +132,7 @@ FacebookProto::~FacebookProto()
CloseHandle(facy.send_message_lock_);
CloseHandle(facy.fcb_conn_lock_);
CloseHandle(facy.notifications_lock_);
+ CloseHandle(facy.cookies_lock_);
}
//////////////////////////////////////////////////////////////////////////////
@@ -864,20 +870,20 @@ void FacebookProto::ReadNotificationWorker(void *p)
if (p == NULL)
return;
+ std::string *id = (std::string*)p;
+
if (isOffline()) {
- delete (std::string*)p;
+ delete id;
return;
}
- std::string *id = static_cast<std::string*>(p);
-
std::string data = "seen=0&asyncSignal=&__dyn=&__req=a&alert_ids%5B0%5D=" + utils::url::encode(*id);
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
facy.flap(REQUEST_NOTIFICATIONS_READ, NULL, &data);
- delete p;
+ delete id;
}
/**
@@ -982,8 +988,8 @@ void FacebookProto::InitPopups()
void FacebookProto::InitHotkeys()
{
char text[200];
- strcpy(text, m_szModuleName);
- char* tDest = text + strlen(text);
+ mir_strncpy(text, m_szModuleName, 100);
+ char *tDest = text + strlen(text);
HOTKEYDESC hkd = { sizeof(hkd) };
hkd.pszName = text;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index ce78c98f4a..9c7153309f 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -253,7 +253,6 @@ public:
std::vector<HANDLE> popupClasses;
std::string last_status_msg_;
- HANDLE hSmileysFolder_;
std::vector<MCONTACT> avatar_queue;
static void CALLBACK APC_callback(ULONG_PTR p);
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index 67b6701a2f..387388f712 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -197,7 +197,7 @@ int FacebookProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
int FacebookProto::OnBuildStatusMenu(WPARAM, LPARAM)
{
char text[200];
- strcpy(text, m_szModuleName);
+ mir_strncpy(text, m_szModuleName, 100);
char *tDest = text + strlen(text);
CLISTMENUITEM mi = { sizeof(mi) };
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 4ca4e0ea85..48f15876e9 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -80,6 +80,7 @@ std::string utils::conversion::to_string(void* data, WORD type)
{
case UTILS_CONV_BOOLEAN:
out << (data ? "true" : "false");
+ break;
case UTILS_CONV_TIME_T:
out << (*(time_t*)data);
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index f093240753..fd1aaf6101 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
#define __RELEASE_NUM 9
-#define __BUILD_NUM 7
+#define __BUILD_NUM 8
#include <stdver.h>