summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/client.h20
-rw-r--r--protocols/FacebookRM/src/communication.cpp20
-rw-r--r--protocols/FacebookRM/src/contacts.cpp10
-rw-r--r--protocols/FacebookRM/src/messages.cpp7
-rw-r--r--protocols/FacebookRM/src/process.cpp10
5 files changed, 49 insertions, 18 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 902477e573..58bbeb5a41 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -39,7 +39,7 @@ public:
{
username_ = password_ = \
chat_sequence_num_ = chat_channel_host_ = chat_channel_partition_ = \
- dtsg_ = logout_hash_ = chat_sticky_num_ = chat_sticky_pool_ = chat_conn_num_ = chat_clientid_ = chat_traceid_ = "";
+ dtsg_ = csrf_ = logout_hash_ = chat_sticky_num_ = chat_sticky_pool_ = chat_conn_num_ = chat_clientid_ = chat_traceid_ = "";
msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = 0;
@@ -67,6 +67,7 @@ public:
std::string password_;
std::string dtsg_;
+ std::string csrf_;
std::string logout_hash_;
std::string chat_channel_;
std::string chat_channel_host_;
@@ -140,6 +141,22 @@ public:
////////////////////////////////////////////////////////////
+ // Helpers for data
+
+ std::string __inline phstamp(std::string data) {
+ std::stringstream out;
+ out << '2' << this->csrf_ << (int)data.length();
+ return out.str();
+ }
+
+ std::string __inline ttstamp() {
+ std::stringstream out;
+ out << '1' << this->csrf_;
+ return out.str();
+ }
+
+ ////////////////////////////////////////////////////////////
+
// Login handling
bool login(const char *username, const char *password);
@@ -171,6 +188,7 @@ public:
bool channel();
int send_message(MCONTACT, std::string message_recipient, std::string message_text, std::string *error_text, MessageMethod method, std::string captchaPersistData = "", std::string captcha = "");
+
////////////////////////////////////////////////////////////
// Status handling
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 3cefc8a822..053ed0c0e4 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -995,7 +995,15 @@ bool facebook_client::home()
}
this->dtsg_ = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
- parent->debugLogA(" Got self dtsg: %s", this->dtsg_.c_str());
+ {
+ // Compute csrf_ 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();
+ }
+ parent->debugLogA(" Got self dtsg: %s (csrf: %s)", this->dtsg_.c_str(), this->csrf_.c_str());
if (this->dtsg_.empty()) {
parent->debugLogA("!!!!! Empty dtsg. Source code:\n%s", resp.data.c_str());
@@ -1219,7 +1227,7 @@ int facebook_client::send_message(MCONTACT hContact, std::string message_recipie
data += "&__user=" + this->self_.user_id;
data += "&__a=1";
data += "&fb_dtsg=" + this->dtsg_;
- data += "&phstamp=0";
+ data += "&phstamp=" + phstamp(data);
resp = flap(REQUEST_MESSAGE_SEND_INBOX, &data);
break;
@@ -1253,7 +1261,7 @@ int facebook_client::send_message(MCONTACT hContact, std::string message_recipie
data += "&fb_dtsg=" + this->dtsg_;
data += "&__user=" + this->self_.user_id;
data += "&__a=1";
- data += "&phstamp=0";
+ data += "&phstamp=" + phstamp(data);
resp = flap(REQUEST_MESSAGE_SEND_CHAT, &data);
break;
@@ -1277,7 +1285,7 @@ int facebook_client::send_message(MCONTACT hContact, std::string message_recipie
data += "&message_batch[0][message_id]=";
data += "&fb_dtsg=" + this->dtsg_;
data += "&__user=" + this->self_.user_id;
- data += "&phstamp=0";
+ data += "&phstamp=" + phstamp(data);
resp = flap(REQUEST_MESSAGE_SEND_CHAT, &data);
break;
@@ -1397,13 +1405,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=0";
+ 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=0";
+ 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/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 2e99856a7f..7e76fdb4b7 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -161,7 +161,7 @@ std::string FacebookProto::ThreadIDToContactID(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=0";
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
data += "&threads[thread_ids][0]=" + utils::url::encode(thread_id);
std::string user_id = "";
@@ -252,7 +252,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=0";
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
std::string thread_id = utils::url::encode(std::string(_T2A(fbc->thread_id.c_str())));
@@ -403,10 +403,11 @@ void FacebookProto::DeleteContactFromServer(void *data)
std::string id = (*(std::string*)data);
delete data;
- std::string query = "norefresh=true&unref=button_dropdown&confirmed=1&phstamp=0&__a=1";
+ std::string query = "norefresh=true&unref=button_dropdown&confirmed=1&__a=1";
query += "&fb_dtsg=" + facy.dtsg_;
query += "&uid=" + id;
query += "&__user=" + facy.self_.user_id;
+ query += "&phstamp=" + facy.phstamp(query);
std::string get_query = "norefresh=true&unref=button_dropdown&uid=" + id;
@@ -610,9 +611,10 @@ void FacebookProto::SendPokeWorker(void *p)
delete p;
std::string data = "poke_target=" + id;
- data += "&do_confirm=0&phstamp=0";
+ data += "&do_confirm=0";
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
+ data += "&phstamp=" + facy.phstamp(data);
// 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 08b72eab59..269c0aeb91 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -88,7 +88,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
std::string post_data = "threads[group_ids][0]=" + utils::url::encode(data->chat_id);
post_data += "&fb_dtsg=" + facy.dtsg_;
post_data += "&__user=" + facy.self_.user_id;
- post_data += "&phstamp=0";
+ post_data += "&phstamp=" + facy.phstamp(post_data);
http::response resp = facy.flap(REQUEST_THREAD_INFO, &post_data);
@@ -161,7 +161,8 @@ void FacebookProto::SendTypingWorker(void *p)
data += utils::url::encode(std::string(id));
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&lsd=&phstamp=0&__user=" + facy.self_.user_id;
+ data += "&lsd=&__user=" + facy.self_.user_id;
+ data += "&phstamp=" + facy.phstamp(data);
http::response resp = facy.flap(REQUEST_TYPING_SEND, &data);
}
@@ -188,7 +189,7 @@ void FacebookProto::ReadMessageWorker(void *p)
std::string data = "ids[" + utils::url::encode(std::string(id)) + "]=true";
data += "&fb_dtsg=" + facy.dtsg_;
data += "&__user=" + facy.self_.user_id;
- data += "&__a=1&__dyn=&__req=&ttstamp=0";
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
facy.flap(REQUEST_MARK_READ, &data);
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 4770f61323..39c9811c62 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -34,7 +34,7 @@ void FacebookProto::ProcessBuddyList(void*)
facy.handle_entry("ProcessBuddyList");
// Prepare update data
- std::string post_data = "user=" + facy.self_.user_id + "&fetch_mobile=true&phstamp=0&fb_dtsg=" + facy.dtsg_ + "&__user=" + facy.self_.user_id + "&cached_user_info_ids=";
+ std::string post_data = "user=" + facy.self_.user_id + "&fetch_mobile=true&fb_dtsg=" + facy.dtsg_ + "&__user=" + facy.self_.user_id + "&cached_user_info_ids=";
int counter = 0;
for (List::Item< facebook_user >* i = facy.buddies.begin(); i != NULL; i = i->next, counter++)
@@ -42,6 +42,8 @@ void FacebookProto::ProcessBuddyList(void*)
post_data += i->data->user_id + "%2C";
}
+ post_data += "&phstamp=" + facy.phstamp(post_data);
+
// Get buddy list
http::response resp = facy.flap(REQUEST_BUDDY_LIST, &post_data);
@@ -297,7 +299,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=0";
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
http::response resp = facy.flap(REQUEST_UNREAD_THREADS, &data);
@@ -356,7 +358,7 @@ void FacebookProto::ProcessUnreadMessage(void *p)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=0";
+ 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]);
@@ -457,7 +459,7 @@ void FacebookProto::LoadLastMessages(void *p)
std::string data = "client=mercury";
data += "&__user=" + facy.self_.user_id;
data += "&fb_dtsg=" + facy.dtsg_;
- data += "&__a=1&__dyn=&__req=&ttstamp=0";
+ data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
bool isChat = isChatRoom(hContact);