summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2015-09-01 21:17:10 +0000
committerRobert Pösel <robyer@seznam.cz>2015-09-01 21:17:10 +0000
commit62869feea2d58ccc8d585803305994b3fd529792 (patch)
tree68ff6d299690e0ba7d56282bfb313b5735e85bdd /protocols
parent140039aa214f240421dc3b629d15d5ed506c72af (diff)
Facebook: Various fixes
* Use InterlockedIncrement for msgId * Remove old phstamp parameter and use fixed ttstamp instead * Use __req parameter in requests * Use __rev parameter with static value in requests (hopefully it's better than empty) git-svn-id: http://svn.miranda-ng.org/main/trunk@15139 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/client.h26
-rw-r--r--protocols/FacebookRM/src/communication.cpp18
-rw-r--r--protocols/FacebookRM/src/connection.cpp1
-rw-r--r--protocols/FacebookRM/src/contacts.cpp8
-rw-r--r--protocols/FacebookRM/src/messages.cpp17
-rw-r--r--protocols/FacebookRM/src/process.cpp12
-rw-r--r--protocols/FacebookRM/src/proto.cpp2
7 files changed, 42 insertions, 42 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index fa3f11db09..7f95567e12 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -37,7 +37,7 @@ public:
facebook_client()
{
- msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = chat_msgs_recv_ = 0;
+ msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = random_ = chat_msgs_recv_ = chat_req_ = 0;
is_typing_ = false;
@@ -69,7 +69,7 @@ public:
std::string password_;
std::string dtsg_;
- std::string csrf_;
+ std::string ttstamp_;
std::string logout_hash_;
std::string chat_channel_;
std::string chat_channel_host_;
@@ -84,8 +84,9 @@ public:
bool is_typing_;
time_t last_feeds_update_;
time_t last_notification_time_;
- int msgid_;
+ volatile unsigned int msgid_;
int chat_msgs_recv_;
+ volatile unsigned int chat_req_;
////////////////////////////////////////////////////////////
@@ -144,16 +145,19 @@ public:
// Helpers for data
- std::string __inline phstamp(const std::string &data) {
- std::stringstream out;
- out << '2' << this->csrf_ << (int)data.length();
- return out.str();
+ std::string __inline __dyn() {
+ return ""; // FIXME: What's this value and where it come from? Looks like it is the same through all requests.
}
- std::string __inline ttstamp() {
- std::stringstream out;
- out << '1' << this->csrf_;
- return out.str();
+ std::string __inline __req() {
+ // Increment request number and convert it to string with radix 36 (whole numbers + whole alphabet)
+ char buffer[10];
+ itoa(InterlockedIncrement(&this->chat_req_), buffer, 36);
+ return std::string(buffer);
+ }
+
+ std::string __inline __rev() {
+ return "1911928"; // FIXME: Some version of communication protocol? On 1.9.2015 was used "1911928"
}
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 65b89cd28b..13b60b3c20 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -3,7 +3,7 @@
Facebook plugin for Miranda Instant Messenger
_____________________________________________
-Copyright © 2009-11 Michal Zelinka, 2011-15 Robert Pösel
+Copyright � 2009-11 Michal Zelinka, 2011-15 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
@@ -931,12 +931,12 @@ bool facebook_client::home()
this->dtsg_ = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
{
- // Compute csrf_ from dtsg_
+ // Compute ttstamp from dtsg_
std::stringstream csrf;
for (unsigned int i = 0; i < this->dtsg_.length(); i++) {
csrf << (int)this->dtsg_.at(i);
}
- this->csrf_ = csrf.str();
+ this->ttstamp_ = "2" + csrf.str();
}
if (this->dtsg_.empty()) {
@@ -1053,9 +1053,6 @@ bool facebook_client::reconnect()
this->chat_sequence_num_ = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}");
parent->debugLogA(" Got self sequence number: %s", this->chat_sequence_num_.c_str());
- // TODO: I'm not sure this goes to 0 after reconnect, or it is always same as chat_sequence_num_ (when watching website it was always same)
- this->chat_msgs_recv_ = 0;
-
this->chat_conn_num_ = utils::text::source_get_value2(&resp.data, "\"max_conn\":", ",}");
parent->debugLogA(" Got self max_conn: %s", this->chat_conn_num_.c_str());
@@ -1133,8 +1130,7 @@ bool facebook_client::channel()
parent->debugLogA(" Got self sequence number: %s", seq.c_str());
if (type == "msg") {
- // Update msgs_recv number
- // TODO: I'm not sure this is updated regarding "msg" received and reseted after reconnect, or it is always same as chat_sequence_num_ (when watching website it was always same)
+ // Update msgs_recv number for every "msg" type we receive (during fullRefresh/reload responses it stays the same)
this->chat_msgs_recv_++;
}
@@ -1261,7 +1257,7 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
data += "&client=mercury&__a=1&__dyn&__req&__rev";
data += "&fb_dtsg=" + this->dtsg_;
data += "&__user=" + this->self_.user_id;
- data += "&ttstamp=" + ttstamp();
+ data += "&ttstamp=" + ttstamp_;
{
ScopedLock s(send_message_lock_);
@@ -1380,13 +1376,13 @@ bool facebook_client::post_status(status_data *status)
data = "fb_dtsg=" + this->dtsg_;
data += "&targetid=" + (status->user_id.empty() ? this->self_.user_id : status->user_id);
data += "&xhpc_targetid=" + (status->user_id.empty() ? this->self_.user_id : status->user_id);
- data += "&istimeline=1&composercontext=composer&onecolumn=1&nctr[_mod]=pagelet_timeline_recent&__a=1&ttstamp=" + ttstamp();
+ data += "&istimeline=1&composercontext=composer&onecolumn=1&nctr[_mod]=pagelet_timeline_recent&__a=1&ttstamp=" + ttstamp_;
data += "&__user=" + (status->isPage && !status->user_id.empty() ? status->user_id : this->self_.user_id);
data += "&loaded_components[0]=maininput&loaded_components[1]=backdateicon&loaded_components[2]=withtaggericon&loaded_components[3]=cameraicon&loaded_components[4]=placetaggericon&loaded_components[5]=mainprivacywidget&loaded_components[6]=withtaggericon&loaded_components[7]=backdateicon&loaded_components[8]=placetaggericon&loaded_components[9]=cameraicon&loaded_components[10]=mainprivacywidget&loaded_components[11]=maininput&loaded_components[12]=explicitplaceinput&loaded_components[13]=hiddenplaceinput&loaded_components[14]=placenameinput&loaded_components[15]=hiddensessionid&loaded_components[16]=withtagger&loaded_components[17]=backdatepicker&loaded_components[18]=placetagger&loaded_components[19]=citysharericon";
http::response resp = flap(REQUEST_LINK_SCRAPER, &data, &status->url);
std::string temp = utils::text::html_entities_decode(utils::text::slashu_to_utf8(resp.data));
- data = "&xhpc_context=profile&xhpc_ismeta=1&xhpc_timeline=1&xhpc_composerid=u_jsonp_2_0&is_explicit_place=&composertags_place=&composer_session_id=&composertags_city=&disable_location_sharing=false&composer_predicted_city=&nctr[_mod]=pagelet_composer&__a=1&__dyn=&__req=1f&ttstamp=" + ttstamp();
+ data = "&xhpc_context=profile&xhpc_ismeta=1&xhpc_timeline=1&xhpc_composerid=u_jsonp_2_0&is_explicit_place=&composertags_place=&composer_session_id=&composertags_city=&disable_location_sharing=false&composer_predicted_city=&nctr[_mod]=pagelet_composer&__a=1&__dyn=&__req=1f&ttstamp=" + ttstamp_;
std::string form = utils::text::source_get_value(&temp, 2, "<form", "</form>");
utils::text::replace_all(&form, "\\\"", "\"");
data += "&" + utils::text::source_get_form_data(&form) + "&";
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index ec68c4c4ad..02d267e375 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -58,6 +58,7 @@ void FacebookProto::ChangeStatus(void*)
facy.chat_sticky_num_.clear();
facy.chat_sticky_pool_.clear();
facy.chat_msgs_recv_ = 0;
+ facy.chat_req_ = 0;
facy.clear_cookies();
facy.clear_notifications();
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 05afa3ed0c..0b94c31701 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -176,7 +176,7 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp_;
data += "&threads[thread_ids][0]=" + utils::url::encode(thread_id);
std::string user_id;
@@ -267,7 +267,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp_;
std::string thread_id = utils::url::encode(fbc->thread_id);
@@ -424,7 +424,7 @@ void FacebookProto::DeleteContactFromServer(void *data)
query += "&fb_dtsg=" + facy.dtsg_;
query += "&uid=" + id;
query += "&__user=" + facy.self_.user_id;
- query += "&phstamp=" + facy.phstamp(query);
+ query += "&ttstamp=" + facy.ttstamp_;
std::string get_query = "norefresh=true&unref=button_dropdown&uid=" + id;
@@ -622,7 +622,7 @@ void FacebookProto::SendPokeWorker(void *p)
data += "&do_confirm=0";
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
- data += "&phstamp=" + facy.phstamp(data);
+ data += "&ttstamp=" + facy.ttstamp_;
// Send poke
http::response resp = facy.flap(REQUEST_POKE, &data);
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 6d31e15ed0..bb123962e7 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -3,7 +3,7 @@
Facebook plugin for Miranda Instant Messenger
_____________________________________________
-Copyright © 2009-11 Michal Zelinka, 2011-15 Robert Pösel
+Copyright � 2009-11 Michal Zelinka, 2011-15 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
@@ -91,7 +91,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
std::string post_data = "threads[thread_ids][0]=" + utils::url::encode(data->chat_id);
post_data += "&fb_dtsg=" + facy.dtsg_;
post_data += "&__user=" + facy.self_.user_id;
- post_data += "&phstamp=" + facy.phstamp(post_data);
+ post_data += "&ttstamp=" + facy.ttstamp_;
http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data);
@@ -114,12 +114,11 @@ void FacebookProto::SendChatMsgWorker(void *p)
int FacebookProto::SendMsg(MCONTACT hContact, int, const char *msg)
{
- // TODO: msg comes as Unicode (retyped wchar_t*), why should we convert it as ANSI to UTF-8? o_O
std::string message = msg;
-
- facy.msgid_ = (facy.msgid_ % 1024) + 1;
- ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, facy.msgid_));
- return facy.msgid_;
+ unsigned int msgId = InterlockedIncrement(&facy.msgid_);
+
+ ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, msgId));
+ return msgId;
}
int FacebookProto::UserIsTyping(MCONTACT hContact, int type)
@@ -165,7 +164,7 @@ void FacebookProto::SendTypingWorker(void *p)
data += "&fb_dtsg=" + facy.dtsg_;
data += "&lsd=&__user=" + facy.self_.user_id;
- data += "&phstamp=" + facy.phstamp(data);
+ data += "&ttstamp=" + facy.ttstramp_;
http::response resp = facy.flap(REQUEST_TYPING_SEND, &data);
}
@@ -190,7 +189,7 @@ void FacebookProto::ReadMessageWorker(void *p)
std::string data = "fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp_;
for (std::set<MCONTACT>::iterator it = hContacts->begin(); it != hContacts->end(); ++it) {
MCONTACT hContact = *it;
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index c49d9cbb72..96aa8d1949 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -58,7 +58,7 @@ void FacebookProto::ProcessBuddyList(void*)
post_data += i->data->user_id + "%2C";
}
- post_data += "&phstamp=" + facy.phstamp(post_data);
+ post_data += "&ttstamp=" + facy.ttstamp_;
// Get buddy list
http::response resp = facy.flap(REQUEST_BUDDY_LIST, &post_data);
@@ -301,7 +301,7 @@ void FacebookProto::ProcessUnreadMessages(void*)
data += "&client=mercury";
data += "__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp_;
http::response resp = facy.flap(REQUEST_UNREAD_THREADS, &data);
@@ -359,7 +359,7 @@ void FacebookProto::ProcessUnreadMessage(void *pParam)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ 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->at(i));
@@ -460,7 +460,7 @@ void FacebookProto::LoadLastMessages(void *pParam)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp_;
bool isChat = isChatRoom(hContact);
@@ -586,7 +586,7 @@ void FacebookProto::SyncThreads(void*)
data += "&folders[0]=inbox";
if (!inboxOnly)
data += "&folders[1]=other";
- data += "&__req=7&__a=1&__dyn=&__req=&__rev=&ttstamp=" + facy.ttstamp();
+ data += "&__req=7&__a=1&__dyn=&__req=&__rev=&ttstamp=" + facy.ttstamp_;
debugLogA(" Facebook's milli timestamp for sync: %s", time.c_str());
@@ -1072,7 +1072,7 @@ void FacebookProto::ProcessNotifications(void*)
data += "&cursor="; // when loading more
data += "&length=" + utils::conversion::to_string(&count, UTILS_CONV_UNSIGNED_NUMBER); // number of items to load
data += "&businessID="; // probably for pages?
- data += "&ttstamp=" + facy.ttstamp();
+ data += "&ttstamp=" + facy.ttstamp_;
// Get notifications
http::response resp = facy.flap(REQUEST_NOTIFICATIONS, &data);
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index cfa288d696..7992d2785d 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -921,7 +921,7 @@ void FacebookProto::ReadNotificationWorker(void *p)
std::string data = "seen=0&asyncSignal=&__dyn=&__rev=&__req=&alert_ids%5B0%5D=" + utils::url::encode(*id);
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
- data += "&ttstamp=" + facy.ttstamp();
+ data += "&ttstamp=" + facy.ttstamp_;
facy.flap(REQUEST_NOTIFICATIONS_READ, NULL, &data);