summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/FacebookRM')
-rw-r--r--protocols/FacebookRM/src/channel.cpp59
-rw-r--r--protocols/FacebookRM/src/chat.cpp82
-rw-r--r--protocols/FacebookRM/src/client.h66
-rw-r--r--protocols/FacebookRM/src/communication.cpp82
-rw-r--r--protocols/FacebookRM/src/contacts.cpp200
-rw-r--r--protocols/FacebookRM/src/feeds.cpp30
-rw-r--r--protocols/FacebookRM/src/history.cpp81
-rw-r--r--protocols/FacebookRM/src/http_request.h234
-rw-r--r--protocols/FacebookRM/src/login.cpp70
-rw-r--r--protocols/FacebookRM/src/messages.cpp105
-rw-r--r--protocols/FacebookRM/src/notifications.cpp44
-rw-r--r--protocols/FacebookRM/src/process.cpp46
-rw-r--r--protocols/FacebookRM/src/profile.cpp44
-rw-r--r--protocols/FacebookRM/src/proto.cpp11
-rw-r--r--protocols/FacebookRM/src/search.cpp12
-rw-r--r--protocols/FacebookRM/src/status.cpp44
-rw-r--r--protocols/FacebookRM/src/utils.cpp106
17 files changed, 592 insertions, 724 deletions
diff --git a/protocols/FacebookRM/src/channel.cpp b/protocols/FacebookRM/src/channel.cpp
index 9498209ff2..320ced31b4 100644
--- a/protocols/FacebookRM/src/channel.cpp
+++ b/protocols/FacebookRM/src/channel.cpp
@@ -25,53 +25,56 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////
// receiving updates, sending activity ping
-ChannelRequest::ChannelRequest(facebook_client *fc, Type type) :
- HttpRequest(REQUEST_POST, FORMAT,
- type == PULL ? FACEBOOK_SERVER_CHAT "/pull" : FACEBOOK_SERVER_CHAT "/active_ping",
- fc->chat_conn_num_.empty() ? "0" : fc->chat_conn_num_.c_str(),
- fc->chat_channel_host_.c_str())
+HttpRequest* facebook_client::channelRequest(facebook_client::Type type)
{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FORMAT,
+ (type == PULL) ? FACEBOOK_SERVER_CHAT "/pull" : FACEBOOK_SERVER_CHAT "/active_ping",
+ chat_conn_num_.empty() ? "0" : chat_conn_num_.c_str(),
+ chat_channel_host_.c_str());
+
if (type == PULL) {
- timeout = 65 * 1000;
- Persistent = CHANNEL;
+ p->timeout = 65 * 1000;
+ p->Persistent = p->CHANNEL;
}
bool isPing = (type == PING);
- Url << CHAR_PARAM("channel", fc->chat_channel_.empty() ? ("p_" + fc->self_.user_id).c_str() : fc->chat_channel_.c_str());
+ p->Url << CHAR_PARAM("channel", chat_channel_.empty() ? ("p_" + self_.user_id).c_str() : chat_channel_.c_str());
if (!isPing)
- Url << CHAR_PARAM("seq", fc->chat_sequence_num_.empty() ? "0" : fc->chat_sequence_num_.c_str());
+ p->Url << CHAR_PARAM("seq", chat_sequence_num_.empty() ? "0" : chat_sequence_num_.c_str());
- Url
- << CHAR_PARAM("partition", fc->chat_channel_partition_.empty() ? "0" : fc->chat_channel_partition_.c_str())
- << CHAR_PARAM("clientid", fc->chat_clientid_.c_str())
- << CHAR_PARAM("cb", utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz", &fc->random_).c_str());
+ p->Url
+ << CHAR_PARAM("partition", chat_channel_partition_.empty() ? "0" : chat_channel_partition_.c_str())
+ << CHAR_PARAM("clientid", chat_clientid_.c_str())
+ << CHAR_PARAM("cb", utils::text::rand_string(4, "0123456789abcdefghijklmnopqrstuvwxyz", &random_).c_str());
- int idleSeconds = fc->parent->IdleSeconds();
- Url << INT_PARAM("idle", idleSeconds); // Browser is sending "idle" always, even if it's "0"
+ int idleSeconds = parent->IdleSeconds();
+ p->Url << INT_PARAM("idle", idleSeconds); // Browser is sending "idle" always, even if it's "0"
if (!isPing) {
- Url << CHAR_PARAM("qp", "y") << CHAR_PARAM("pws", "fresh") << INT_PARAM("isq", 487632);
- Url << INT_PARAM("msgs_recv", fc->chat_msgs_recv_);
+ p->Url << CHAR_PARAM("qp", "y") << CHAR_PARAM("pws", "fresh") << INT_PARAM("isq", 487632);
+ p->Url << INT_PARAM("msgs_recv", chat_msgs_recv_);
// TODO: sometimes there is &tur=1711 and &qpmade=<some actual timestamp> and &isq=487632
// Url << "request_batch=1"; // it somehow batches up more responses to one - then response has special "t=batched" type and "batches" array with the data
// Url << "msgr_region=LLA"; // it was here only for first pull, same as request_batch
}
- Url << INT_PARAM("cap", 8) // TODO: what's this item? Sometimes it's 0, sometimes 8
- << CHAR_PARAM("uid", fc->self_.user_id.c_str())
- << CHAR_PARAM("viewer_uid", fc->self_.user_id.c_str());
+ p->Url << INT_PARAM("cap", 8) // TODO: what's this item? Sometimes it's 0, sometimes 8
+ << CHAR_PARAM("uid", self_.user_id.c_str())
+ << CHAR_PARAM("viewer_uid", self_.user_id.c_str());
- if (!fc->chat_sticky_num_.empty() && !fc->chat_sticky_pool_.empty()) {
- Url << CHAR_PARAM("sticky_token", fc->chat_sticky_num_.c_str());
- Url << CHAR_PARAM("sticky_pool", fc->chat_sticky_pool_.c_str());
+ if (!chat_sticky_num_.empty() && !chat_sticky_pool_.empty()) {
+ p->Url << CHAR_PARAM("sticky_token", chat_sticky_num_.c_str());
+ p->Url << CHAR_PARAM("sticky_pool", chat_sticky_pool_.c_str());
}
- if (!isPing && !fc->chat_traceid_.empty())
- Url << CHAR_PARAM("traceid", fc->chat_traceid_.c_str());
+ if (!isPing && !chat_traceid_.empty())
+ p->Url << CHAR_PARAM("traceid", chat_traceid_.c_str());
- if (fc->parent->isInvisible())
- Url << CHAR_PARAM("state", "offline");
+ if (parent->isInvisible())
+ p->Url << CHAR_PARAM("state", "offline");
else if (isPing || idleSeconds < 60)
- Url << CHAR_PARAM("state", "active");
+ p->Url << CHAR_PARAM("state", "active");
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index bca2ee561b..85e31f545e 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -24,6 +24,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <m_history.h>
#include <m_userinfo.h>
+enum ChatMenuItems
+{
+ IDM_INVITE = 10, IDM_EXIT,
+
+ IDM_DETAILS = 20, IDM_HISTORY
+};
+
+static const struct gc_item LogMenuItems[] =
+{
+ { LPGENW("&Invite user..."), IDM_INVITE, MENU_ITEM, FALSE },
+ { LPGENW("E&xit chat session"), IDM_EXIT, MENU_ITEM, FALSE },
+};
+
+static const struct gc_item NickMenuItems[] =
+{
+ { LPGENW("User &details"), IDM_DETAILS, MENU_ITEM, FALSE },
+ { LPGENW("User &history"), IDM_HISTORY, MENU_ITEM, FALSE },
+};
+
void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old)
{
// replace % to %% to not interfere with chat color codes
@@ -93,6 +112,16 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
}
break;
+ case GC_USER_LOGMENU:
+ switch (hook->dwData) {
+ case IDM_INVITE:
+ break;
+
+ case IDM_EXIT:
+ break;
+ }
+ break;
+
case GC_USER_NICKLISTMENU:
MCONTACT hContact = 0;
if (hook->dwData == 10 || hook->dwData == 20) {
@@ -106,17 +135,13 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
}
switch (hook->dwData) {
- case 10:
+ case IDM_DETAILS:
CallService(MS_USERINFO_SHOWDIALOG, hContact);
break;
- case 20:
+ case IDM_HISTORY:
CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact);
break;
-
- case 110:
- //chat_leave(id);
- break;
}
break;
@@ -298,39 +323,13 @@ INT_PTR FacebookProto::OnLeaveChat(WPARAM wParam, LPARAM)
int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam)
{
GCMENUITEMS *gcmi = (GCMENUITEMS*)lParam;
+ if (mir_strcmp(gcmi->pszModule, m_szModuleName))
+ return 0;
- if (gcmi == nullptr || _stricmp(gcmi->pszModule, m_szModuleName)) return 0;
-
- if (gcmi->Type == MENU_ON_LOG) {
- static const struct gc_item Items[] =
- {
- { LPGENW("&Invite user..."), 10, MENU_ITEM, FALSE },
- { LPGENW("&Leave chat session"), 20, MENU_ITEM, FALSE }
- };
- Chat_AddMenuItems(gcmi->hMenu, _countof(Items), Items);
- }
- else if (gcmi->Type == MENU_ON_NICKLIST) {
- if (!_stricmp(facy.self_.user_id.c_str(), _T2A(gcmi->pszUID))) {
- /*static const struct gc_item Items[] =
- {
- { LPGENW("User &details"), 10, MENU_ITEM, FALSE },
- { LPGENW("User &history"), 20, MENU_ITEM, FALSE },
- { L"", 100, MENU_SEPARATOR, FALSE },
- { LPGENW("&Leave chat session"), 110, MENU_ITEM, FALSE }
- };
- gcmi->nItems = _countof(Items);
- gcmi->Item = (gc_item*)Items;*/
- }
- else {
- static const struct gc_item Items[] =
- {
- { LPGENW("User &details"), 10, MENU_ITEM, FALSE },
- { LPGENW("User &history"), 20, MENU_ITEM, FALSE }
- };
- Chat_AddMenuItems(gcmi->hMenu, _countof(Items), Items);
- }
- }
-
+ if (gcmi->Type == MENU_ON_LOG)
+ Chat_AddMenuItems(gcmi->hMenu, _countof(LogMenuItems), LogMenuItems);
+ else if (gcmi->Type == MENU_ON_NICKLIST)
+ Chat_AddMenuItems(gcmi->hMenu, _countof(NickMenuItems), NickMenuItems);
return 0;
}
@@ -469,8 +468,7 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc)
for (std::string::size_type i = 0; i < namelessIds.size(); i++)
userIds.insert(mir_strdup(namelessIds.at(i).c_str()));
- HttpRequest *request = new UserInfoRequest(&facy, userIds);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.userInfoRequest(userIds));
FreeList(userIds);
userIds.destroy();
@@ -508,9 +506,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
return;
// request info about chat thread
- HttpRequest *request = new ThreadInfoRequest(&facy, true, fbc->thread_id.c_str());
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(true, fbc->thread_id.c_str()));
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("LoadChatInfo");
return;
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index 1a99885826..e3875ab14e 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -144,7 +144,7 @@ public:
// Helpers for data
- __inline const char *__dyn() {
+ __inline const char *__dyn() const {
return "7AzkXxaA4ojgDxyLqzGomzEbHGbGey8WhLFwgoqwWhE98nwgUaoepovHyodEbbxW4E4u3ucDBwJx62i2PxOcG4K1Zxa2m4oqyUf8oCK251G6XDwnU567oeo5m4pHxC326U6OfBwHx";
// FIXME: What's this value and where it come from? Looks like it is the same through all requests.
}
@@ -156,7 +156,7 @@ public:
return CMStringA(buffer);
}
- __inline const char *__rev() {
+ __inline const char *__rev() const {
return "3553943";
}
@@ -204,6 +204,68 @@ public:
http::response sendRequest(class HttpRequest *request);
bool save_url(const std::string &url, const std::wstring &filename, HNETLIBCONN &nlc);
+ // channel.cpp
+ enum Type { PULL, PING };
+ HttpRequest* channelRequest(Type type);
+
+ // contacts.cpp
+ HttpRequest* addFriendRequest(const char *userId);
+ HttpRequest* deleteFriendRequest(const char *userId);
+ HttpRequest* getFriendshipsRequest();
+ HttpRequest* answerFriendshipRequest(const char *userId, bool bConfirm);
+ HttpRequest* cancelFriendshipRequest(const char *userId);
+
+ HttpRequest* userInfoRequest(const LIST<char> &userIds);
+ HttpRequest* userInfoAllRequest();
+
+ // feeds.cpp
+ HttpRequest* newsfeedRequest();
+ HttpRequest* memoriesRequest();
+
+ // history.cpp
+ HttpRequest* threadInfoRequest(bool isChat, const char *id, const char* timestamp = nullptr, int limit = -1);
+ HttpRequest* threadInfoRequest(const LIST<char> &ids, int offset, int limit);
+ HttpRequest* unreadThreadsRequest();
+
+ // login.cpp
+ HttpRequest* loginRequest();
+ HttpRequest* loginRequest(const char *username, const char *password, const char *urlData, const char *bodyData);
+ HttpRequest* logoutRequest();
+ HttpRequest* loginSmsRequest(const char *dtsg);
+ HttpRequest* setupMachineRequest();
+ HttpRequest* setupMachineRequest(const char *dtsg, const char *nh, const char *submit);
+
+ // messages.cpp
+ HttpRequest* sendMessageRequest(const char *userId, const char *threadId, const char *messageId, const char *messageText, bool isChat, const char *captcha, const char *captchaPersistData);
+ HttpRequest* sendTypingRequest(const char *userId, bool isChat, bool isTyping);
+ HttpRequest* markMessageReadRequest(const LIST<char> &ids);
+
+ // notifications.cpp
+ HttpRequest* getNotificationsRequest(int count);
+ HttpRequest* markNotificationReadRequest(const char *id);
+
+ // profile.cpp
+ HttpRequest* homeRequest();
+ HttpRequest* dtsgRequest();
+ HttpRequest* profileRequest(const char *data);
+ HttpRequest* profileInfoRequest(const char *userId);
+ HttpRequest* profilePictureRequest(const char *userId);
+
+ // search.cpp
+ HttpRequest* searchRequest(const char *query, int s, int pn, const char *ssid);
+
+ // status.cpp
+ HttpRequest* reconnectRequest();
+ HttpRequest* setVisibilityRequest(bool online);
+
+ // utils.cpp
+ HttpRequest* linkScraperRequest(status_data *status);
+ HttpRequest* refreshCaptchaRequest(const char *captchaPersistData);
+ HttpRequest* getPagesRequest();
+ HttpRequest* switchIdentityRequest(const char *userId);
+ HttpRequest* sharePostRequest(status_data *status, const char *linkData);
+ HttpRequest* sendPokeRequest(const char *userId);
+
////////////////////////////////////////////////////////////
// Netlib handle
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index d2ea31ddd1..9dd90ab7c8 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -58,19 +58,19 @@ http::response facebook_client::sendRequest(HttpRequest *request)
// Set persistent connection (or not)
switch (request->Persistent) {
- case ChannelRequest::NONE:
+ case HttpRequest::PersistentType::NONE:
request->nlc = nullptr;
request->flags &= ~NLHRF_PERSISTENT;
break;
- case ChannelRequest::CHANNEL:
+ case HttpRequest::PersistentType::CHANNEL:
request->nlc = hChannelCon;
request->flags |= NLHRF_PERSISTENT;
break;
- case ChannelRequest::MESSAGES:
+ case HttpRequest::PersistentType::MESSAGES:
request->nlc = hMessagesCon;
request->flags |= NLHRF_PERSISTENT;
break;
- case ChannelRequest::DEFAULT:
+ case HttpRequest::PersistentType::DEFAULT:
s.lock();
request->nlc = hFcbCon;
request->flags |= NLHRF_PERSISTENT;
@@ -84,15 +84,15 @@ http::response facebook_client::sendRequest(HttpRequest *request)
// Remember the persistent connection handle (or not)
switch (request->Persistent) {
- case ChannelRequest::NONE:
+ case HttpRequest::PersistentType::NONE:
break;
- case ChannelRequest::CHANNEL:
+ case HttpRequest::PersistentType::CHANNEL:
hChannelCon = pnlhr ? pnlhr->nlc : nullptr;
break;
- case ChannelRequest::MESSAGES:
+ case HttpRequest::PersistentType::MESSAGES:
hMessagesCon = pnlhr ? pnlhr->nlc : nullptr;
break;
- case ChannelRequest::DEFAULT:
+ case HttpRequest::PersistentType::DEFAULT:
s.unlock();
hFcbCon = pnlhr ? pnlhr->nlc : nullptr;
break;
@@ -415,8 +415,7 @@ bool facebook_client::login(const char *username, const char *password)
cookies["datr"] = device;
// Get initial cookies
- LoginRequest *request = new LoginRequest();
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(loginRequest());
// Also parse cookies set by JavaScript
parseJsCookies("[\"CookieCore\",\"setWithoutChecksIfFirstPartyContext\",[],[\"", resp.data, cookies);
@@ -430,8 +429,7 @@ bool facebook_client::login(const char *username, const char *password)
}
// Send validation
- HttpRequest *request = new LoginRequest(username, password, getData.c_str(), postData.c_str());
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(loginRequest(username, password, getData.c_str(), postData.c_str()));
// Save Device ID
if (!cookies["datr"].empty())
@@ -449,8 +447,7 @@ bool facebook_client::login(const char *username, const char *password)
// Check whether login checks are required
if (location.find("/checkpoint/") != std::string::npos) {
- request = new SetupMachineRequest();
- resp = sendRequest(request);
+ resp = sendRequest(setupMachineRequest());
if (resp.data.find("login_approvals_no_phones") != std::string::npos) {
// Code approval - but no phones in account
@@ -476,7 +473,7 @@ bool facebook_client::login(const char *username, const char *password)
// We need verification code from user (he can get it via Facebook application on phone or by requesting code via SMS)
const char *givenCode = guardDialog.GetCode();
- request = new SetupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
+ HttpRequest *request = setupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
request->Body << CHAR_PARAM("approvals_code", givenCode);
resp = sendRequest(request);
@@ -498,7 +495,7 @@ bool facebook_client::login(const char *username, const char *password)
std::string fb_dtsg = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
std::string nh = utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"");
- request = new SetupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
+ HttpRequest *request = setupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
request->Body << "&name_action_selected=save_device"; // Save device - or "dont_save"
resp = sendRequest(request);
}
@@ -509,9 +506,7 @@ bool facebook_client::login(const char *username, const char *password)
if (resp.data.find("name=\"submit[Continue]\"") != std::string::npos) {
std::string fb_dtsg = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
std::string nh = utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"");
-
- request = new SetupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
- resp = sendRequest(request);
+ resp = sendRequest(setupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue"));
}
// In this step might be needed identity confirmation
@@ -542,14 +537,14 @@ bool facebook_client::login(const char *username, const char *password)
std::string fb_dtsg = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
std::string nh = utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"");
- request = new SetupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "This was me"); // Recognize device (or "This wasn't me" - this will force to change account password)
- resp = sendRequest(request);
+ // Recognize device (or "This wasn't me" - this will force to change account password)
+ resp = sendRequest(setupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "This was me"));
// 3) Save last device
fb_dtsg = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
nh = utils::text::source_get_value(&resp.data, 3, "name=\"nh\"", "value=\"", "\"");
- request = new SetupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
+ HttpRequest *request = setupMachineRequest(fb_dtsg.c_str(), nh.c_str(), "Continue");
request->Body << "&name_action_selected=save_device"; // Save device - or "dont_save"
resp = sendRequest(request);
}
@@ -642,8 +637,7 @@ bool facebook_client::logout()
{
handle_entry("logout");
- LogoutRequest *request = new LogoutRequest(this->dtsg_.c_str(), this->logout_hash_.c_str());
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(logoutRequest());
this->username_.clear();
this->password_.clear();
@@ -664,7 +658,7 @@ bool facebook_client::home()
handle_entry("home");
// get fb_dtsg
- http::response resp = sendRequest(new DtsgRequest());
+ http::response resp = sendRequest(dtsgRequest());
this->dtsg_ = utils::url::encode(utils::text::source_get_value(&resp.data, 3, "name=\"fb_dtsg\"", "value=\"", "\""));
{
@@ -684,7 +678,7 @@ bool facebook_client::home()
parent->debugLogA(" Got self dtsg");
- resp = sendRequest(new HomeRequest());
+ resp = sendRequest(homeRequest());
switch (resp.code) {
case HTTP_CODE_OK:
@@ -745,8 +739,7 @@ bool facebook_client::home()
// Final attempt to get avatar as on some pages is only link to photo page and not link to image itself
if (this->self_.image_url.empty()) {
- HttpRequest *request = new ProfilePictureRequest(this->mbasicWorks, self_.user_id.c_str());
- http::response resp2 = sendRequest(request);
+ http::response resp2 = sendRequest(profilePictureRequest(self_.user_id.c_str()));
// Get avatar (from mbasic version of photo page)
this->self_.image_url = utils::text::html_entities_decode(utils::text::source_get_value(&resp2.data, 3, "id=\"root", "<img src=\"", "\""));
@@ -792,9 +785,7 @@ bool facebook_client::chat_state(bool online)
{
handle_entry("chat_state");
- HttpRequest *request = new SetVisibilityRequest(this, online);
- http::response resp = sendRequest(request);
-
+ http::response resp = sendRequest(setVisibilityRequest(online));
if (!resp.error_title.empty())
return handle_error("chat_state");
@@ -806,7 +797,7 @@ bool facebook_client::reconnect()
handle_entry("reconnect");
// Request reconnect
- http::response resp = sendRequest(new ReconnectRequest(this));
+ http::response resp = sendRequest(reconnectRequest());
switch (resp.code) {
case HTTP_CODE_OK:
@@ -850,9 +841,7 @@ bool facebook_client::channel()
handle_entry("channel");
// Get updates
- ChannelRequest *request = new ChannelRequest(this, ChannelRequest::PULL);
- http::response resp = sendRequest(request);
-
+ http::response resp = sendRequest(channelRequest(PULL));
if (resp.data.empty()) // Something went wrong
return handle_error("channel");
@@ -953,8 +942,7 @@ bool facebook_client::activity_ping()
handle_entry("activity_ping");
- ChannelRequest *request = new ChannelRequest(this, ChannelRequest::PING);
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(channelRequest(PING));
// Remember this last ping time
parent->m_pingTS = ::time(nullptr);
@@ -990,10 +978,8 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
http::response resp;
{
- HttpRequest *request = new SendMessageRequest(this, userId, threadId, messageId.c_str(), message_text.c_str(), isChatRoom, captcha.c_str(), captcha_persist_data.c_str());
-
mir_cslock s(send_message_lock_);
- resp = sendRequest(request);
+ resp = sendRequest(sendMessageRequest(userId, threadId, messageId.c_str(), message_text.c_str(), isChatRoom, captcha.c_str(), captcha_persist_data.c_str()));
*error_text = resp.error_text;
@@ -1047,9 +1033,7 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
parent->debugLogA(" Got imageUrl (first): %s", imageUrl.c_str());
parent->debugLogA(" Got captchaPersistData (first): %s", captchaPersistData.c_str());
- HttpRequest *request = new RefreshCaptchaRequest(this, captchaPersistData.c_str());
- http::response capResp = sendRequest(request);
-
+ http::response capResp = sendRequest(refreshCaptchaRequest(captchaPersistData.c_str()));
if (capResp.code == HTTP_CODE_OK) {
imageUrl = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&capResp.data, 3, "img class=\\\"img\\\"", "src=\\\"", "\\\"")));
captchaPersistData = utils::text::source_get_value(&capResp.data, 3, "\\\"captcha_persist_data\\\"", "value=\\\"", "\\\"");
@@ -1099,13 +1083,12 @@ bool facebook_client::post_status(status_data *status)
if (status->isPage) {
// Switch to page identity by which name we will share this post
- sendRequest(new SwitchIdentityRequest(this->dtsg_.c_str(), status->user_id.c_str()));
+ sendRequest(switchIdentityRequest(status->user_id.c_str()));
}
std::string linkData;
if (!status->url.empty()) {
- HttpRequest *request = new LinkScraperRequest(this, status);
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(linkScraperRequest(status));
std::string temp = utils::text::html_entities_decode(utils::text::slashu_to_utf8(resp.data));
std::string form = utils::text::source_get_value(&temp, 2, "<form", "</form>");
@@ -1114,11 +1097,10 @@ bool facebook_client::post_status(status_data *status)
// FIXME: Rework to some "scraped_link" structure to simplify working with it?
}
- HttpRequest *request = new SharePostRequest(this, status, linkData.c_str());
- http::response resp = sendRequest(request);
+ http::response resp = sendRequest(sharePostRequest(status, linkData.c_str()));
if (status->isPage) // Switch back to our identity
- sendRequest(new SwitchIdentityRequest(this->dtsg_.c_str(), this->self_.user_id.c_str()));
+ sendRequest(switchIdentityRequest(self_.user_id.c_str()));
// cleanup status elements (delete users)
for (std::vector<facebook_user*>::size_type i = 0; i < status->users.size(); i++)
@@ -1172,7 +1154,7 @@ bool facebook_client::save_url(const std::string &url, const std::wstring &filen
bool facebook_client::sms_code(const char *fb_dtsg)
{
- http::response resp = sendRequest(new LoginSmsRequest(this, fb_dtsg));
+ http::response resp = sendRequest(loginSmsRequest(fb_dtsg));
if (resp.data.find("\"is_valid\":true", 0) == std::string::npos) {
// Code wasn't send
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 16d9a0bb73..dfab64a60f 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -170,8 +170,7 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
if (isOffline())
return "";
- HttpRequest *request = new ThreadInfoRequest(&facy, true, thread_id.c_str());
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(true, thread_id.c_str()));
std::string user_id;
@@ -200,8 +199,7 @@ void FacebookProto::LoadContactInfo(facebook_user* fbu)
LIST<char> userIds(1);
userIds.insert(mir_strdup(fbu->user_id.c_str()));
- HttpRequest *request = new UserInfoRequest(&facy, userIds);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.userInfoRequest(userIds));
FreeList(userIds);
userIds.destroy();
@@ -292,7 +290,7 @@ void FacebookProto::DeleteContactFromServer(void *data)
return;
// Delete contact from server
- HttpRequest *request = new DeleteFriendRequest(&facy, id.c_str());
+ HttpRequest *request = facy.deleteFriendRequest(id.c_str());
http::response resp = facy.sendRequest(request);
if (resp.data.find("\"payload\":null", 0) != std::string::npos) {
@@ -326,7 +324,7 @@ void FacebookProto::AddContactToServer(void *data)
return;
// Request friendship
- HttpRequest *request = new AddFriendRequest(&facy, id.c_str());
+ HttpRequest *request = facy.addFriendRequest(id.c_str());
http::response resp = facy.sendRequest(request);
if (resp.data.find("\"success\":true", 0) != std::string::npos) {
@@ -362,8 +360,7 @@ void FacebookProto::ApproveContactToServer(void *data)
return;
// Confirm friendship request
- HttpRequest *request = new AnswerFriendshipRequest(&facy, id, AnswerFriendshipRequest::CONFIRM);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.answerFriendshipRequest(id, true));
if (resp.data.find("\"success\":true") != std::string::npos) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND);
@@ -393,9 +390,7 @@ void FacebookProto::CancelFriendsRequest(void *data)
return;
// Cancel (our) friendship request
- HttpRequest *request = new CancelFriendshipRequest(&facy, id);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.cancelFriendshipRequest(id));
if (resp.data.find("\"payload\":null", 0) != std::string::npos) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
NotifyEvent(m_tszUserName, TranslateT("Request for friendship was canceled."), 0, EVENT_FRIENDSHIP);
@@ -424,8 +419,7 @@ void FacebookProto::IgnoreFriendshipRequest(void *data)
return;
// Ignore friendship request
- HttpRequest *request = new AnswerFriendshipRequest(&facy, id, AnswerFriendshipRequest::REJECT);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.answerFriendshipRequest(id, false));
if (resp.data.find("\"success\":true") != std::string::npos) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
@@ -456,8 +450,7 @@ void FacebookProto::SendPokeWorker(void *p)
}
// Send poke
- HttpRequest *request = new SendPokeRequest(&facy, id->c_str());
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.sendPokeRequest(id->c_str()));
if (resp.data.find("\"payload\":null", 0) != std::string::npos) {
resp.data = utils::text::slashu_to_utf8(
@@ -524,7 +517,7 @@ void FacebookProto::RefreshUserInfo(void *data)
CheckAvatarChange(hContact, fbu.image_url);
// Load additional info from profile page (e.g., birthday)
- http::response resp = facy.sendRequest(new ProfileInfoRequest(facy.mbasicWorks, fbu.user_id.c_str()));
+ http::response resp = facy.sendRequest(facy.profileInfoRequest(fbu.user_id.c_str()));
if (resp.code == HTTP_CODE_OK) {
std::string birthday = utils::text::source_get_value(&resp.data, 4, ">Birthday</", "<td", ">", "</td>");
@@ -609,113 +602,134 @@ void FacebookProto::StopTyping(MCONTACT hContact)
}
/////////////////////////////////////////////////////////////////////////////////////////
+// handling friends requests
-UserInfoRequest::UserInfoRequest(facebook_client *fc, const LIST<char> &userIds) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/chat/user_info/")
-{
- Url << INT_PARAM("dpr", 1);
-
- for (int i = 0; i < userIds.getCount(); i++) {
- CMStringA id(::FORMAT, "ids[%i]", i);
- Body << CHAR_PARAM(id, ptrA(mir_urlEncode(userIds[i])));
- }
-
- Body
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << INT_PARAM("__a", 1)
- << INT_PARAM("__be", 1)
- << CHAR_PARAM("__pc", "PHASED:DEFAULT");
-}
-
-UserInfoAllRequest::UserInfoAllRequest(facebook_client *fc) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/chat/user_info_all/")
+HttpRequest* facebook_client::addFriendRequest(const char *userId)
{
- Url
- << INT_PARAM("dpr", 1)
- << CHAR_PARAM("viewer", fc->self_.user_id.c_str());
-
- Body
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("__pc", "PHASED:DEFAULT")
- << INT_PARAM("__a", 1)
- << INT_PARAM("__be", -1);
-}
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/add_friend/action.php");
+
+ p->Url << INT_PARAM("__a", 1);
-AddFriendRequest::AddFriendRequest(facebook_client *fc, const char *userId) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/add_friend/action.php")
-{
- Url << INT_PARAM("__a", 1);
-
- Body
+ p->Body
<< CHAR_PARAM("to_friend", userId)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
<< CHAR_PARAM("action", "add_friend")
<< CHAR_PARAM("how_found", "profile_button")
<< CHAR_PARAM("ref_param", "ts")
<< CHAR_PARAM("no_flyout_on_click", "false");
+
+ return p;
}
-DeleteFriendRequest::DeleteFriendRequest(facebook_client *fc, const char *userId) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/profile/removefriendconfirm.php")
+HttpRequest* facebook_client::deleteFriendRequest(const char *userId)
{
- Url
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/profile/removefriendconfirm.php");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< BOOL_PARAM("norefresh", true)
<< CHAR_PARAM("unref", "button_dropdown")
<< CHAR_PARAM("uid", userId);
- Body
+ p->Body
<< CHAR_PARAM("uid", userId)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
<< CHAR_PARAM("norefresh", "true")
<< CHAR_PARAM("unref", "button_dropdown")
<< INT_PARAM("confirmed", 1)
<< INT_PARAM("__a", 1);
+
+ return p;
}
-CancelFriendshipRequest::CancelFriendshipRequest(facebook_client *fc, const char *userId) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/friends/requests/cancel.php")
+HttpRequest* facebook_client::getFriendshipsRequest()
{
- Url << INT_PARAM("__a", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FORMAT, "%s/friends/center/requests/", mbasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE);
+
+ p->flags |= NLHRF_REDIRECT;
- Body
+ return p;
+}
+
+HttpRequest* facebook_client::cancelFriendshipRequest(const char *userId)
+{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/friends/requests/cancel.php");
+
+ p->Url << INT_PARAM("__a", 1);
+
+ p->Body
<< INT_PARAM("confirmed", 1)
<< CHAR_PARAM("friend", userId)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str());
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str());
+
+ return p;
}
-AnswerFriendshipRequest::AnswerFriendshipRequest(facebook_client *fc, const char *userId, Answer answer) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/requests/friends/ajax/")
+HttpRequest* facebook_client::answerFriendshipRequest(const char *userId, bool bConfirm)
{
- Url << INT_PARAM("__a", 1);
-
- const char *action = "";
- switch (answer) {
- case CONFIRM:
- action = "confirm";
- break;
- case REJECT:
- action = "reject";
- break;
- }
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/requests/friends/ajax/");
+
+ p->Url << INT_PARAM("__a", 1);
- Body
- << CHAR_PARAM("action", action)
+ p->Body
+ << CHAR_PARAM("action", (bConfirm) ? "confirm" : "reject")
<< CHAR_PARAM("id", userId)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str());
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str());
+
+ return p;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// requesting user info
+
+HttpRequest* facebook_client::userInfoRequest(const LIST<char> &userIds)
+{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/chat/user_info/");
+
+ p->Url << INT_PARAM("dpr", 1);
+
+ for (int i = 0; i < userIds.getCount(); i++) {
+ CMStringA id(::FORMAT, "ids[%i]", i);
+ p->Body << CHAR_PARAM(id, ptrA(mir_urlEncode(userIds[i])));
+ }
+
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << INT_PARAM("__a", 1)
+ << INT_PARAM("__be", 1)
+ << CHAR_PARAM("__pc", "PHASED:DEFAULT");
+
+ return p;
+}
+
+HttpRequest* facebook_client::userInfoAllRequest()
+{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/chat/user_info_all/");
+
+ p->Url
+ << INT_PARAM("dpr", 1)
+ << CHAR_PARAM("viewer", self_.user_id.c_str());
+
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("__pc", "PHASED:DEFAULT")
+ << INT_PARAM("__a", 1)
+ << INT_PARAM("__be", -1);
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/feeds.cpp b/protocols/FacebookRM/src/feeds.cpp
index 9e94c57f6e..b4bda2d578 100644
--- a/protocols/FacebookRM/src/feeds.cpp
+++ b/protocols/FacebookRM/src/feeds.cpp
@@ -23,24 +23,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
// getting newsfeed posts
-NewsfeedRequest::NewsfeedRequest(facebook_client *fc) :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/home/generic.php")
+HttpRequest* facebook_client::newsfeedRequest()
{
- BYTE feed_type = fc->parent->getByte(FACEBOOK_KEY_FEED_TYPE, 0);
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/home/generic.php");
+
+ BYTE feed_type = parent->getByte(FACEBOOK_KEY_FEED_TYPE, 0);
if (feed_type >= _countof(feed_types))
feed_type = 0;
- Url
+ p->Url
<< CHAR_PARAM("sk", feed_types[feed_type].id)
<< CHAR_PARAM("key", (feed_type < 2) ? "nf" : feed_types[feed_type].id)
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
<< INT_PARAM("__a", 1);
+
+ return p;
}
-MemoriesRequest::MemoriesRequest(facebook_client *fc) :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/onthisday/story/query/")
+HttpRequest* facebook_client::memoriesRequest()
{
- Url
+ HttpRequest * p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/onthisday/story/query/");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< INT_PARAM("start_index", 0)
<< INT_PARAM("num_stories", 20)
@@ -49,8 +53,10 @@ MemoriesRequest::MemoriesRequest(facebook_client *fc) :
<< INT_PARAM("__be", -1)
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT64_PARAM("timestamp", ::time(nullptr))
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str());
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("__user", self_.user_id.c_str());
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/history.cpp b/protocols/FacebookRM/src/history.cpp
index e1abb1dbeb..d5193f3bdf 100644
--- a/protocols/FacebookRM/src/history.cpp
+++ b/protocols/FacebookRM/src/history.cpp
@@ -22,18 +22,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-ThreadInfoRequest::ThreadInfoRequest(facebook_client *fc, bool isChat, const char *id, const char* timestamp, int limit) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/api/graphqlbatch/")
+HttpRequest* facebook_client::threadInfoRequest(bool isChat, const char *id, const char* timestamp, int limit)
{
- setCommonBody(fc);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/api/graphqlbatch/");
- // FIXME: FB removed /ajax/mercury/thread_info requests and now all messaging stuff does through /api/graphqlbatch/ - all loading of threads, (unread) messages, list of contacts in groupchat, etc.
- // All these request must be rewritten to the new request. Preparation is below but unfinished.
+ p->Body
+ << CHAR_PARAM("batch_name", "MessengerGraphQLThreadFetcherRe")
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << INT_PARAM("__a", 1)
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << INT_PARAM("__be", 1)
+ << CHAR_PARAM("__pc", "PHASED:DEFAULT")
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str());
- //const char *type = isChat ? "thread_fbids" : "user_ids";
- std::string id_ = id; // FIXME: Rewrite this without std::string...
+ std::string id_ = id;
if (isChat) {
- // NOTE: Remove "id." prefix as here we need to give threadFbId and not threadId
if (id_.substr(0, 3) == "id.")
id_ = id_.substr(3);
}
@@ -54,14 +59,26 @@ ThreadInfoRequest::ThreadInfoRequest(facebook_client *fc, bool isChat, const cha
o0 << CHAR_PARAM("doc_id", "1549485615075443") << JSON_PARAM("query_params", query_params);
root << JSON_PARAM("o0", o0);
- Body << CHAR_PARAM("queries", utils::url::encode(root.write()).c_str());
+ p->Body << CHAR_PARAM("queries", utils::url::encode(root.write()).c_str());
+
+ return p;
}
// Request both thread info and messages for more threads
-ThreadInfoRequest::ThreadInfoRequest(facebook_client *fc, const LIST<char> &ids, int offset, int limit) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/api/graphqlbatch/")
+HttpRequest* facebook_client::threadInfoRequest(const LIST<char> &ids, int offset, int limit)
{
- setCommonBody(fc);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/api/graphqlbatch/");
+
+ p->Body
+ << CHAR_PARAM("batch_name", "MessengerGraphQLThreadFetcherRe")
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << INT_PARAM("__a", 1)
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << INT_PARAM("__be", 1)
+ << CHAR_PARAM("__pc", "PHASED:DEFAULT")
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str());
for (int i = 0; i < ids.getCount(); i++) {
// NOTE: Remove "id." prefix as here we need to give threadFbId and not threadId
@@ -72,44 +89,34 @@ ThreadInfoRequest::ThreadInfoRequest(facebook_client *fc, const LIST<char> &ids,
// Load messages
CMStringA begin(::FORMAT, "messages[%s][%s]", "thread_fbids", idEncoded);
- Body
+ p->Body
<< INT_PARAM(CMStringA(::FORMAT, "%s[offset]", begin.c_str()), offset)
<< INT_PARAM(CMStringA(::FORMAT, "%s[limit]", begin.c_str()), limit)
<< CHAR_PARAM(CMStringA(::FORMAT, "threads[%s][%i]", "thread_fbids", i), idEncoded);
}
-}
-void ThreadInfoRequest::setCommonBody(facebook_client *fc)
-{
- Body
- << CHAR_PARAM("batch_name", "MessengerGraphQLThreadFetcherRe")
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << INT_PARAM("__a", 1)
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << INT_PARAM("__be", 1)
- << CHAR_PARAM("__pc", "PHASED:DEFAULT")
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("jazoest", "265816910476541027556899745586581711208287100122699749108");
+ return p;
}
-UnreadThreadsRequest::UnreadThreadsRequest(facebook_client *fc) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/mercury/unread_threads.php")
+HttpRequest* facebook_client::unreadThreadsRequest()
{
- Url << INT_PARAM("dpr", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/mercury/unread_threads.php");
- Body
+ p->Url << INT_PARAM("dpr", 1);
+
+ p->Body
<< CHAR_PARAM("folders[0]", "inbox")
<< CHAR_PARAM("folders[1]", "other") // TODO: "other" is probably unused, and there is now "pending" instead
<< CHAR_PARAM("client", "mercury")
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__a", 1)
<< INT_PARAM("__be", -1);
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/http_request.h b/protocols/FacebookRM/src/http_request.h
index 523d7d6af8..0c2aa14e67 100644
--- a/protocols/FacebookRM/src/http_request.h
+++ b/protocols/FacebookRM/src/http_request.h
@@ -26,8 +26,6 @@ class HttpRequest : public NETLIBHTTPREQUEST, public MZeroedObject
CMStringA url;
protected:
- enum HttpRequestUrlFormat { FORMAT };
-
class HttpRequestUrl
{
friend HttpRequest;
@@ -206,7 +204,7 @@ public:
Persistent = DEFAULT;
}
- HttpRequest(int type, HttpRequestUrlFormat, LPCSTR urlFormat, ...)
+ HttpRequest(int type, CMStringDataFormat, LPCSTR urlFormat, ...)
: Url(*this, urlFormat, (va_start(formatArgs, urlFormat), formatArgs)), Headers(*this)
{
cbSize = sizeof(NETLIBHTTPREQUEST);
@@ -246,234 +244,4 @@ public:
}
};
-/////////////////////////////////////////////////////////////////////////////////////////
-// channel.cpp
-
-struct ChannelRequest : public HttpRequest
-{
- enum Type { PULL, PING };
-
- ChannelRequest(facebook_client *fc, Type type);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// contact.cpp
-
-// getting frienship requests (using mobile website)
-struct GetFriendshipsRequest : public HttpRequest
-{
- GetFriendshipsRequest(bool mobileBasicWorks) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/friends/center/requests/", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE)
- {
- flags |= NLHRF_REDIRECT;
- }
-};
-
-// getting info about particular friend
-struct UserInfoRequest : public HttpRequest
-{ UserInfoRequest(facebook_client *fc, const LIST<char> &userIds);
-};
-
-// getting info about all friends
-struct UserInfoAllRequest : public HttpRequest
-{ UserInfoAllRequest(facebook_client *fc);
-};
-
-// requesting friendships
-struct AddFriendRequest : public HttpRequest
-{ AddFriendRequest(facebook_client *fc, const char *userId);
-};
-
-// deleting friendships
-struct DeleteFriendRequest : public HttpRequest
-{ DeleteFriendRequest(facebook_client *fc, const char *userId);
-};
-
-// canceling (our) friendship request
-struct CancelFriendshipRequest : public HttpRequest
-{ CancelFriendshipRequest(facebook_client *fc, const char *userId);
-};
-
-// approving or ignoring friendship requests
-struct AnswerFriendshipRequest : public HttpRequest
-{
- enum Answer { CONFIRM, REJECT };
-
- AnswerFriendshipRequest(facebook_client *fc, const char *userId, Answer answer);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// feeds.cpp
-
-// getting newsfeed posts
-struct NewsfeedRequest : public HttpRequest
-{ NewsfeedRequest(facebook_client *fc);
-};
-
-// getting memories ("on this day") posts
-struct MemoriesRequest : public HttpRequest
-{ MemoriesRequest(facebook_client *fc);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// history.cpp
-
-// getting thread info and messages
-class ThreadInfoRequest : public HttpRequest
-{
- void setCommonBody(facebook_client *fc);
-
-public:
- // Request only messages history
- ThreadInfoRequest(facebook_client *fc, bool isChat, const char *id, const char* timestamp = nullptr, int limit = -1);
- ThreadInfoRequest(facebook_client *fc, const LIST<char> &ids, int offset, int limit);
-};
-
-// getting unread threads
-struct UnreadThreadsRequest : public HttpRequest
-{ UnreadThreadsRequest(facebook_client *fc);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// login.cpp
-
-// connecting physically
-struct LoginRequest : public HttpRequest
-{
- LoginRequest();
- LoginRequest(const char *username, const char *password, const char *urlData, const char *bodyData);
-};
-
-// disconnecting physically
-struct LogoutRequest : public HttpRequest
-{ LogoutRequest(const char *dtsg, const char *logoutHash);
-};
-
-// request to receive login code via SMS
-struct LoginSmsRequest : public HttpRequest
-{ LoginSmsRequest(facebook_client *fc, const char *dtsg);
-};
-
-// setting machine name
-struct SetupMachineRequest : public HttpRequest
-{
- SetupMachineRequest();
- SetupMachineRequest(const char *dtsg, const char *nh, const char *submit);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// messages.cpp
-
-// sending messages
-struct SendMessageRequest : public HttpRequest
-{ SendMessageRequest(facebook_client *fc, const char *userId, const char *threadId, const char *messageId, const char *messageText, bool isChat, const char *captcha, const char *captchaPersistData);
-};
-
-// sending typing notification
-struct SendTypingRequest : public HttpRequest
-{ SendTypingRequest(facebook_client *fc, const char *userId, bool isChat, bool isTyping);
-};
-
-struct MarkMessageReadRequest : public HttpRequest
-{ MarkMessageReadRequest(facebook_client *fc, const LIST<char> &ids);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// notifications.cpp
-
-// getting notifications
-struct GetNotificationsRequest : public HttpRequest
-{ GetNotificationsRequest(facebook_client *fc, int count);
-};
-
-// marking notifications read
-struct MarkNotificationReadRequest : public HttpRequest
-{ MarkNotificationReadRequest(facebook_client *fc, const char *id);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// profile.cpp
-
-// getting own name, avatar, ...
-struct HomeRequest : public HttpRequest
-{ HomeRequest();
-};
-
-// getting fb_dtsg
-struct DtsgRequest : public HttpRequest
-{ DtsgRequest();
-};
-
-// request mobile page containing profile picture
-struct ProfilePictureRequest : public HttpRequest
-{ ProfilePictureRequest(bool mobileBasicWorks, const char *userId);
-};
-
-// request mobile page containing user profile
-struct ProfileRequest : public HttpRequest
-{ ProfileRequest(bool mobileBasicWorks, const char *data);
-};
-
-// request mobile page containing user profile by his id, and in english language (for parsing data)
-struct ProfileInfoRequest : public HttpRequest
-{ ProfileInfoRequest(bool mobileBasicWorks, const char *userId);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// search.cpp
-
-// searching
-struct SearchRequest : public HttpRequest
-{ SearchRequest(bool mobileBasicWorks, const char *query, int s, int pn, const char *ssid);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// status.cpp
-
-// getting info about channel and connecting to it
-struct ReconnectRequest : public HttpRequest
-{ ReconnectRequest(facebook_client *fc);
-};
-
-// setting chat visibility
-struct SetVisibilityRequest : public HttpRequest
-{ SetVisibilityRequest(facebook_client *fc, bool online);
-};
-
-//////////////////////////////////////////////////////////////////////////////////////////
-// utils.cpp
-
-// getting data for given url (for sending/posting reasons)
-struct LinkScraperRequest : public HttpRequest
-{ LinkScraperRequest(facebook_client *fc, status_data *status);
-};
-
-// refreshing captcha dialog (changing captcha type)
-struct RefreshCaptchaRequest : public HttpRequest
-{ RefreshCaptchaRequest(facebook_client *fc, const char *captchaPersistData);
-};
-
-// getting owned/admined pages list
-struct GetPagesRequest : public HttpRequest
-{
- GetPagesRequest() :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/bookmarks/pages")
- {}
-};
-
-// changing identity to post status for pages
-struct SwitchIdentityRequest : public HttpRequest
-{ SwitchIdentityRequest(const char *dtsg, const char *userId);
-};
-
-// posting status to our or friends's wall
-struct SharePostRequest : public HttpRequest
-{ SharePostRequest(facebook_client *fc, status_data *status, const char *linkData);
-};
-
-// sending pokes
-struct SendPokeRequest : public HttpRequest
-{ SendPokeRequest(facebook_client *fc, const char *userId);
-};
-
#endif //_HTTP_REQUEST_H_ \ No newline at end of file
diff --git a/protocols/FacebookRM/src/login.cpp b/protocols/FacebookRM/src/login.cpp
index 8547da48d2..1c585dda3d 100644
--- a/protocols/FacebookRM/src/login.cpp
+++ b/protocols/FacebookRM/src/login.cpp
@@ -25,78 +25,92 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////////////
// connecting physically
-LoginRequest::LoginRequest() :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_LOGIN "/login.php")
+HttpRequest* facebook_client::loginRequest()
{
- Url << INT_PARAM("login_attempt", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_LOGIN "/login.php");
+ p->Url << INT_PARAM("login_attempt", 1);
+ return p;
}
-LoginRequest::LoginRequest(const char *username, const char *password, const char *urlData, const char *bodyData) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_LOGIN "/login.php")
+HttpRequest* facebook_client::loginRequest(const char *username, const char *password, const char *urlData, const char *bodyData)
{
- Persistent = NONE;
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_LOGIN "/login.php");
- Url
+ p->Persistent = p->NONE;
+
+ p->Url
<< INT_PARAM("login_attempt", 1)
<< urlData; // additional data parsed from form
- Body
+ p->Body
<< INT_PARAM("persistent", 1)
<< CHAR_PARAM("email", ptrA(mir_urlEncode(username)))
<< CHAR_PARAM("pass", ptrA(mir_urlEncode(password)))
<< CHAR_PARAM("lgndim", "eyJ3IjoxOTIwLCJoIjoxMDgwLCJhdyI6MTgzNCwiYWgiOjEwODAsImMiOjMyfQ==") // means base64 encoded: {"w":1920,"h":1080,"aw":1834,"ah":1080,"c":32}
<< bodyData; // additional data parsed from form
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// request to receive login code via SMS
-LoginSmsRequest::LoginSmsRequest(facebook_client *fc, const char *dtsg) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/login/approvals/send_sms")
+HttpRequest* facebook_client::loginSmsRequest(const char *dtsg)
{
- Url << INT_PARAM("dpr", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/login/approvals/send_sms");
+
+ p->Url << INT_PARAM("dpr", 1);
- Body
+ p->Body
<< CHAR_PARAM("method_requested", "sms_requested")
<< INT_PARAM("__a", 1)
<< INT_PARAM("__user", 0)
<< INT_PARAM("__be", 0)
<< CHAR_PARAM("__pc", "EXP1:DEFAULT")
<< CHAR_PARAM("current_time", (utils::time::unix_timestamp() + ".000").c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
<< CHAR_PARAM("fb_dtsg", dtsg)
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__rev", fc->__rev());
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__rev", __rev());
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// setting machine name
-SetupMachineRequest::SetupMachineRequest() :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/checkpoint/")
+HttpRequest* facebook_client::setupMachineRequest()
{
- Url << "next";
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/checkpoint/");
+ p->Url << "next";
+ return p;
}
-SetupMachineRequest::SetupMachineRequest(const char *dtsg, const char *nh, const char *submit) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/checkpoint/")
+HttpRequest* facebook_client::setupMachineRequest(const char *dtsg, const char *nh, const char *submit)
{
- Url << "next";
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/checkpoint/");
- Body
+ p->Url << "next";
+
+ p->Body
<< CHAR_PARAM(CMStringA(::FORMAT, "submit[%s]", submit), submit)
<< CHAR_PARAM("nh", nh)
<< CHAR_PARAM("fb_dtsg", dtsg);
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// disconnecting physically
-LogoutRequest::LogoutRequest(const char *dtsg, const char *logoutHash) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/logout.php")
+HttpRequest* facebook_client::logoutRequest()
{
- Body
- << CHAR_PARAM("fb_dtsg", dtsg)
- << CHAR_PARAM("h", logoutHash);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/logout.php");
+
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("h", logout_hash_.c_str());
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index d6284c43ea..5957cf4ba7 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -82,8 +82,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
tid = tid_;
else {
// request info about chat thread
- HttpRequest *request = new ThreadInfoRequest(&facy, true, data->chat_id.c_str());
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(true, data->chat_id.c_str()));
tid = utils::text::source_get_value(&resp.data, 2, "\"thread_id\":\"", "\"");
if (!tid.empty() && tid.compare("null"))
@@ -143,11 +142,8 @@ void FacebookProto::SendTypingWorker(void *p)
const char *value = (isChatRoom(typing->hContact) ? FACEBOOK_KEY_TID : FACEBOOK_KEY_ID);
ptrA id(getStringA(typing->hContact, value));
- if (id != nullptr) {
- bool isChat = isChatRoom(typing->hContact);
- HttpRequest *request = new SendTypingRequest(&facy, id, isChat, typing->status == PROTOTYPE_SELFTYPING_ON);
- http::response resp = facy.sendRequest(request);
- }
+ if (id != nullptr)
+ http::response resp = facy.sendRequest(facy.sendTypingRequest(id, isChatRoom(typing->hContact), typing->status == PROTOTYPE_SELFTYPING_ON));
delete typing;
}
@@ -184,8 +180,7 @@ void FacebookProto::ReadMessageWorker(void *p)
hContacts->clear();
delete hContacts;
- HttpRequest *request = new MarkMessageReadRequest(&facy, ids);
- facy.sendRequest(request);
+ facy.sendRequest(facy.markMessageReadRequest(ids));
FreeList(ids);
ids.destroy();
@@ -223,8 +218,7 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url,
//////////////////////////////////////////////////////////////////////////////////////////
-SendMessageRequest::SendMessageRequest(
- facebook_client *fc,
+HttpRequest* facebook_client::sendMessageRequest(
const char *userId,
const char *threadId,
const char *messageId,
@@ -232,33 +226,34 @@ SendMessageRequest::SendMessageRequest(
bool isChat,
const char *captcha,
const char *captchaPersistData)
- : HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/messaging/send/")
{
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/messaging/send/");
+
// Don't notify errors for this request, because we're getting them inline in messaging window
- NotifyErrors = false;
+ p->NotifyErrors = false;
// Use own persistent connection for sending messages
- Persistent = MESSAGES;
+ p->Persistent = p->MESSAGES;
- Url << INT_PARAM("dpr", 1);
+ p->Url << INT_PARAM("dpr", 1);
if (mir_strlen(captcha) > 0)
- Body << CHAR_PARAM("captcha_persist_data", captchaPersistData) << CHAR_PARAM("captcha_response", captcha);
+ p->Body << CHAR_PARAM("captcha_persist_data", captchaPersistData) << CHAR_PARAM("captcha_response", captcha);
- Body << CHAR_PARAM("client", "mercury") << CHAR_PARAM("action_type", "ma-type:user-generated-message");
+ p->Body << CHAR_PARAM("client", "mercury") << CHAR_PARAM("action_type", "ma-type:user-generated-message");
// Experimental sticker sending support
std::string message_text = messageText; // FIXME: Rewrite this without std::string...
if (message_text.substr(0, 10) == "[[sticker:" && message_text.substr(message_text.length() - 2) == "]]")
// TODO: For sending GIF images instead of "sticker_id=" there is "image_ids[0]=", otherwise it's same
- Body
+ p->Body
<< "body="
<< CHAR_PARAM("sticker_id", ptrA(mir_urlEncode(message_text.substr(10, message_text.length() - 10 - 2).c_str())))
<< BOOL_PARAM("has_attachment", true);
else
- Body << CHAR_PARAM("body", ptrA(mir_urlEncode(messageText))) << BOOL_PARAM("has_attachment", false);
+ p->Body << CHAR_PARAM("body", ptrA(mir_urlEncode(messageText))) << BOOL_PARAM("has_attachment", false);
- Body
+ p->Body
<< INT_PARAM("ephemeral_ttl_mode", 0)
<< CHAR_PARAM("message_id", messageId)
<< CHAR_PARAM("offline_threading_id", messageId); // Same as message ID
@@ -269,57 +264,63 @@ SendMessageRequest::SendMessageRequest(
if (threadFbid.substr(0, 3) == "id.")
threadFbid = threadFbid.substr(3);
- Body << CHAR_PARAM("thread_fbid", threadFbid.c_str());
+ p->Body << CHAR_PARAM("thread_fbid", threadFbid.c_str());
}
else
- Body
+ p->Body
<< CHAR_PARAM("other_user_fbid", userId)
<< CHAR_PARAM("specific_to_list[0]", CMStringA(::FORMAT, "fbid:%s", userId))
- << CHAR_PARAM("specific_to_list[1]", CMStringA(::FORMAT, "fbid:%s", fc->self_.user_id.c_str()));
+ << CHAR_PARAM("specific_to_list[1]", CMStringA(::FORMAT, "fbid:%s", self_.user_id.c_str()));
- Body
+ p->Body
// << "signature_id=" // TODO: How to generate signature ID? It is present only when sending via "mercury"
<< CHAR_PARAM("source", "source:chat:web") // or "source:titan:web" for web_messenger
<< CHAR_PARAM("timestamp", utils::time::mili_timestamp().c_str())
<< CHAR_PARAM("ui_push_phase", "V3")
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
<< INT_PARAM("__a", 1)
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__be", -1);
+
+ return p;
}
-SendTypingRequest::SendTypingRequest(facebook_client *fc, const char *userId, bool isChat, bool isTyping) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/messaging/typ.php")
+HttpRequest* facebook_client::sendTypingRequest(const char *userId, bool isChat, bool isTyping)
{
- Url << INT_PARAM("dpr", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/messaging/typ.php");
+
+ p->Url << INT_PARAM("dpr", 1);
ptrA idEncoded(mir_urlEncode(userId));
- Body
+ p->Body
<< INT_PARAM("typ", isTyping ? 1 : 0)
<< CHAR_PARAM("to", isChat ? "" : idEncoded)
<< CHAR_PARAM("thread", idEncoded)
<< CHAR_PARAM("source", "mercury-chat")
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__a", 1)
<< INT_PARAM("__be", -1);
+
+ return p;
}
-MarkMessageReadRequest::MarkMessageReadRequest(facebook_client *fc, const LIST<char> &ids) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/mercury/change_read_status.php")
+HttpRequest* facebook_client::markMessageReadRequest(const LIST<char> &ids)
{
- Url << INT_PARAM("__a", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/mercury/change_read_status.php");
+
+ p->Url << INT_PARAM("__a", 1);
for (int i = 0; i < ids.getCount(); i++) {
std::string id_ = ids[i];
@@ -328,15 +329,17 @@ MarkMessageReadRequest::MarkMessageReadRequest(facebook_client *fc, const LIST<c
id_ = id_.substr(3);
CMStringA id(::FORMAT, "ids[%s]", ptrA(mir_urlEncode(id_.c_str())));
- Body << BOOL_PARAM(id, true);
+ p->Body << BOOL_PARAM(id, true);
}
- Body
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
<< INT_PARAM("__a", 1);
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/notifications.cpp b/protocols/FacebookRM/src/notifications.cpp
index eee2574fce..a4f5ae5925 100644
--- a/protocols/FacebookRM/src/notifications.cpp
+++ b/protocols/FacebookRM/src/notifications.cpp
@@ -25,40 +25,46 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////////////
// getting notifications
-GetNotificationsRequest::GetNotificationsRequest(facebook_client *fc, int count) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/notifications/client/get.php")
+HttpRequest* facebook_client::getNotificationsRequest(int count)
{
- Url << INT_PARAM("dpr", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/notifications/client/get.php");
+
+ p->Url << INT_PARAM("dpr", 1);
- Body
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
+ p->Body
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
// << "cursor=" // when loading more
<< INT_PARAM("length", count) // number of items to load
// << "businessID=" // probably for pages?
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__be", -1)
<< INT_PARAM("__a", 1);
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// marking notifications read
-MarkNotificationReadRequest::MarkNotificationReadRequest(facebook_client *fc, const char *id) :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/notifications/mark_read.php")
+HttpRequest* facebook_client::markNotificationReadRequest(const char *id)
{
- Url
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/notifications/mark_read.php");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< INT_PARAM("seen", 0)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
<< CHAR_PARAM("alert_ids%5B0%5D", ptrA(mir_urlEncode(id)));
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index c484fffd76..bb228332c4 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -46,9 +46,7 @@ void FacebookProto::ProcessFriendList(void*)
facy.handle_entry("load_friends");
// Get friends list
- HttpRequest *request = new UserInfoAllRequest(&facy);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.userInfoAllRequest());
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("load_friends");
return;
@@ -179,9 +177,7 @@ void FacebookProto::ProcessUnreadMessages(void*)
facy.handle_entry("ProcessUnreadMessages");
- HttpRequest *request = new UnreadThreadsRequest(&facy);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.unreadThreadsRequest());
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("ProcessUnreadMessages");
return;
@@ -229,8 +225,7 @@ void FacebookProto::ProcessUnreadMessage(void *pParam)
for (std::vector<std::string>::size_type i = 0; i < threads->size(); i++)
ids.insert(mir_strdup(threads->at(i).c_str()));
- HttpRequest *request = new ThreadInfoRequest(&facy, ids, offset, limit);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(ids, offset, limit));
FreeList(ids);
ids.destroy();
@@ -287,9 +282,7 @@ void FacebookProto::LoadLastMessages(void *pParam)
int count = min(FACEBOOK_MESSAGES_ON_OPEN_LIMIT, getByte(FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT, DEFAULT_MESSAGES_ON_OPEN_COUNT));
- HttpRequest *request = new ThreadInfoRequest(&facy, isChat, (const char*)item_id, nullptr, count);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(isChat, (const char*)item_id, nullptr, count));
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error("LoadLastMessages");
return;
@@ -345,8 +338,7 @@ void FacebookProto::LoadHistory(void *pParam)
}
// first get info about this thread and how many messages is there
- http::response resp = facy.sendRequest(new ThreadInfoRequest(&facy, isChat, item_id));
-
+ http::response resp = facy.sendRequest(facy.threadInfoRequest(isChat, item_id));
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error("LoadHistory");
return;
@@ -388,7 +380,7 @@ void FacebookProto::LoadHistory(void *pParam)
break;
// Load batch of messages
- resp = facy.sendRequest(new ThreadInfoRequest(&facy, isChat, item_id, firstTimestamp.c_str(), messagesPerBatch));
+ resp = facy.sendRequest(facy.threadInfoRequest(isChat, item_id, firstTimestamp.c_str(), messagesPerBatch));
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error("LoadHistory");
@@ -638,9 +630,7 @@ void FacebookProto::ProcessMemories(void *p)
facy.handle_entry(__FUNCTION__);
- HttpRequest *request = new MemoriesRequest(&facy);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.memoriesRequest());
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error(__FUNCTION__);
return;
@@ -987,9 +977,7 @@ void FacebookProto::ProcessNotifications(void *p)
facy.handle_entry("notifications");
// Get notifications
- HttpRequest *request = new GetNotificationsRequest(&facy, FACEBOOK_NOTIFICATIONS_LOAD_COUNT);
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.getNotificationsRequest(FACEBOOK_NOTIFICATIONS_LOAD_COUNT));
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("notifications");
return;
@@ -1030,13 +1018,13 @@ void FacebookProto::ProcessFriendRequests(void *p)
facy.handle_entry("friendRequests");
// Get load friendships
- http::response resp = facy.sendRequest(new GetFriendshipsRequest(facy.mbasicWorks));
+ http::response resp = facy.sendRequest(facy.getFriendshipsRequest());
// Workaround not working "mbasic." website for some people
if (!resp.isValid()) {
// Remember it didn't worked and try it again (internally it will use "m." this time)
facy.mbasicWorks = false;
- resp = facy.sendRequest(new GetFriendshipsRequest(facy.mbasicWorks));
+ resp = facy.sendRequest(facy.getFriendshipsRequest());
}
if (resp.code != HTTP_CODE_OK) {
@@ -1130,8 +1118,7 @@ void FacebookProto::ProcessFeeds(void *p)
facy.handle_entry("feeds");
// Get feeds
- HttpRequest *request = new NewsfeedRequest(&facy);
- http::response resp = facy.sendRequest(request);
+ http::response resp = facy.sendRequest(facy.newsfeedRequest());
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error("feeds");
return;
@@ -1175,8 +1162,7 @@ void FacebookProto::ProcessPages(void*)
facy.handle_entry("load_pages");
// Get feeds
- http::response resp = facy.sendRequest(new GetPagesRequest());
-
+ http::response resp = facy.sendRequest(facy.getPagesRequest());
if (resp.code != HTTP_CODE_OK) {
facy.handle_error("load_pages");
return;
@@ -1224,9 +1210,7 @@ void FacebookProto::SearchAckThread(void *targ)
int pn = 1;
while (count < 50 && !isOffline()) {
- SearchRequest *request = new SearchRequest(facy.mbasicWorks, search.c_str(), count, pn, ssid.c_str());
- http::response resp = facy.sendRequest(request);
-
+ http::response resp = facy.sendRequest(facy.searchRequest(search.c_str(), count, pn, ssid.c_str()));
if (resp.code == HTTP_CODE_OK) {
std::string items = utils::text::source_get_value(&resp.data, 4, "<body", "</form", "<table", "</table>");
@@ -1333,14 +1317,14 @@ void FacebookProto::SearchIdAckThread(void *targ)
search = utils::url::encode(search);
if (!isOffline() && !search.empty()) {
- http::response resp = facy.sendRequest(new ProfileRequest(facy.mbasicWorks, search.c_str()));
+ http::response resp = facy.sendRequest(facy.profileRequest(search.c_str()));
if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) {
search = utils::text::source_get_value(&resp.headers["Location"], 2, FACEBOOK_SERVER_MBASIC"/", "_rdr");
// Use only valid username redirects
if (search.find("home.php") == std::string::npos)
- resp = facy.sendRequest(new ProfileRequest(facy.mbasicWorks, search.c_str()));
+ resp = facy.sendRequest(facy.profileRequest(search.c_str()));
}
if (resp.code == HTTP_CODE_OK) {
diff --git a/protocols/FacebookRM/src/profile.cpp b/protocols/FacebookRM/src/profile.cpp
index 6b0e8a4250..2f2ff39712 100644
--- a/protocols/FacebookRM/src/profile.cpp
+++ b/protocols/FacebookRM/src/profile.cpp
@@ -25,51 +25,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////////////
// getting own name, avatar, ...
-HomeRequest::HomeRequest() :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_MOBILE "/profile.php")
+HttpRequest* facebook_client::homeRequest()
{
- flags |= NLHRF_REDIRECT;
-
- Url << CHAR_PARAM("v", "info");
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_MOBILE "/profile.php");
+ p->flags |= NLHRF_REDIRECT;
+ p->Url << CHAR_PARAM("v", "info");
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// getting fb_dtsg
-DtsgRequest::DtsgRequest() :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_MOBILE "/profile/basic/intro/bio/")
+HttpRequest* facebook_client::dtsgRequest()
{
- flags |= NLHRF_REDIRECT;
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_MOBILE "/profile/basic/intro/bio/");
+ p->flags |= NLHRF_REDIRECT;
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// request mobile page containing profile picture
-ProfilePictureRequest::ProfilePictureRequest(bool mobileBasicWorks, const char *userId) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/profile/picture/view/", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE)
+HttpRequest* facebook_client::profilePictureRequest(const char *userId)
{
- flags |= NLHRF_REDIRECT;
-
- Url << CHAR_PARAM("profile_id", userId);
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FORMAT, "%s/profile/picture/view/", mbasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE);
+ p->flags |= NLHRF_REDIRECT;
+ p->Url << CHAR_PARAM("profile_id", userId);
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// request mobile page containing user profile
-ProfileRequest::ProfileRequest(bool mobileBasicWorks, const char *data) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/%s", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE, data)
+HttpRequest* facebook_client::profileRequest(const char *data)
{
- Url << CHAR_PARAM("v", "info");
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FORMAT, "%s/%s", mbasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE, data);
+ p->Url << CHAR_PARAM("v", "info");
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// request mobile page containing user profile by his id, and in english language (for parsing data)
-ProfileInfoRequest::ProfileInfoRequest(bool mobileBasicWorks, const char *userId) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/profile.php", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE)
+HttpRequest* facebook_client::profileInfoRequest(const char *userId)
{
- Url
- << CHAR_PARAM("id", userId)
- << CHAR_PARAM("v", "info")
- << CHAR_PARAM("locale", "en_US");
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FORMAT, "%s/profile.php", mbasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE);
+ p->Url << CHAR_PARAM("id", userId) << CHAR_PARAM("v", "info") << CHAR_PARAM("locale", "en_US");
+ return p;
}
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index e2fde204d4..500fac2d50 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -898,15 +898,8 @@ void FacebookProto::ReadNotificationWorker(void *p)
return;
std::string *id = (std::string*)p;
-
- if (isOffline()) {
- delete id;
- return;
- }
-
- HttpRequest *request = new MarkNotificationReadRequest(&facy, id->c_str());
- facy.sendRequest(request);
-
+ if (!isOffline())
+ facy.sendRequest(facy.markNotificationReadRequest(id->c_str()));
delete id;
}
diff --git a/protocols/FacebookRM/src/search.cpp b/protocols/FacebookRM/src/search.cpp
index f64f868339..38293868f1 100644
--- a/protocols/FacebookRM/src/search.cpp
+++ b/protocols/FacebookRM/src/search.cpp
@@ -23,16 +23,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
// searching
-SearchRequest::SearchRequest(bool mobileBasicWorks, const char *query, int s, int pn, const char *ssid) :
- HttpRequest(REQUEST_GET, FORMAT, "%s/search/", mobileBasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE)
+HttpRequest* facebook_client::searchRequest(const char *query, int s, int pn, const char *ssid)
{
- flags |= NLHRF_REDIRECT;
+ HttpRequest* p = new HttpRequest(REQUEST_GET, FORMAT, "%s/search/", mbasicWorks ? FACEBOOK_SERVER_MBASIC : FACEBOOK_SERVER_MOBILE);
+ p->flags |= NLHRF_REDIRECT;
- Url
+ p->Url
<< CHAR_PARAM("q", query)
<< INT_PARAM("s", s)
<< INT_PARAM("pn", pn);
if (mir_strlen(ssid) > 0)
- Url << CHAR_PARAM("ssid", ssid);
+ p->Url << CHAR_PARAM("ssid", ssid);
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/status.cpp b/protocols/FacebookRM/src/status.cpp
index f6ba5e9963..0c1d5e5421 100644
--- a/protocols/FacebookRM/src/status.cpp
+++ b/protocols/FacebookRM/src/status.cpp
@@ -25,39 +25,45 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////////////////////////
// getting info about channel and connecting to it
-ReconnectRequest::ReconnectRequest(facebook_client *fc) :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/presence/reconnect.php")
+HttpRequest* facebook_client::reconnectRequest()
{
- Url
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/ajax/presence/reconnect.php");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__be", -1)
- << CHAR_PARAM("reason", fc->chat_reconnect_reason_.empty() ? "6" : fc->chat_reconnect_reason_.c_str())
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev());
+ << CHAR_PARAM("reason", chat_reconnect_reason_.empty() ? "6" : chat_reconnect_reason_.c_str())
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev());
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// setting chat visibility
-SetVisibilityRequest::SetVisibilityRequest(facebook_client *fc, bool online) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/chat/privacy/visibility.php")
+HttpRequest* facebook_client::setVisibilityRequest(bool online)
{
- Url << INT_PARAM("dpr", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/chat/privacy/visibility.php");
+
+ p->Url << INT_PARAM("dpr", 1);
- Body
+ p->Body
<< INT_PARAM("visibility", online ? 1 : 0)
<< INT_PARAM("window_id", 0)
<< INT_PARAM("__a", 1)
<< CHAR_PARAM("__pc", "PHASED:DEFAULT")
<< INT_PARAM("__be", -1)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev());
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev());
+
+ return p;
}
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 019ccddeea..3e14cc930f 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -23,43 +23,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
//////////////////////////////////////////////////////////////////////////////////////////
+// getting owned/admined pages list
+
+HttpRequest* facebook_client::getPagesRequest()
+{
+ return new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/bookmarks/pages");
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
// refreshing captcha dialog (changing captcha type)
-RefreshCaptchaRequest::RefreshCaptchaRequest(facebook_client *fc, const char *captchaPersistData) :
- HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/captcha/refresh_ajax.php")
+HttpRequest* facebook_client::refreshCaptchaRequest(const char *captchaPersistData)
{
- Url
+ HttpRequest *p = new HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/captcha/refresh_ajax.php");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< CHAR_PARAM("new_captcha_type", "TFBCaptcha")
<< CHAR_PARAM("skipped_captcha_data", captchaPersistData)
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("__rev", fc->__rev())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str());
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("__rev", __rev())
+ << CHAR_PARAM("__user", self_.user_id.c_str());
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// getting data for given url (for sending/posting reasons)
-LinkScraperRequest::LinkScraperRequest(facebook_client *fc, status_data *status) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/composerx/attachment/link/scraper/")
+HttpRequest* facebook_client::linkScraperRequest(status_data *status)
{
- Url
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/composerx/attachment/link/scraper/");
+
+ p->Url
<< INT_PARAM("__a", 1)
<< INT_PARAM("composerurihash", 2)
<< CHAR_PARAM("scrape_url", ptrA(mir_urlEncode(status->url.c_str())));
- Body
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("targetid", status->user_id.empty() ? fc->self_.user_id.c_str() : status->user_id.c_str())
- << CHAR_PARAM("xhpc_targetid", status->user_id.empty() ? fc->self_.user_id.c_str() : status->user_id.c_str())
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("targetid", status->user_id.empty() ? self_.user_id.c_str() : status->user_id.c_str())
+ << CHAR_PARAM("xhpc_targetid", status->user_id.empty() ? self_.user_id.c_str() : status->user_id.c_str())
<< INT_PARAM("istimeline", 1)
<< CHAR_PARAM("composercontext", "composer")
<< INT_PARAM("onecolumn", 1)
<< CHAR_PARAM("nctr[_mod]", "pagelet_timeline_recent")
<< INT_PARAM("__a", 1)
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", status->isPage && !status->user_id.empty() ? status->user_id.c_str() : fc->self_.user_id.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", status->isPage && !status->user_id.empty() ? status->user_id.c_str() : self_.user_id.c_str())
<< CHAR_PARAM("loaded_components[0]", "maininput")
<< CHAR_PARAM("loaded_components[1]", "backdateicon")
<< CHAR_PARAM("loaded_components[2]", "withtaggericon")
@@ -80,36 +92,41 @@ LinkScraperRequest::LinkScraperRequest(facebook_client *fc, status_data *status)
<< CHAR_PARAM("loaded_components[17]", "backdatepicker")
<< CHAR_PARAM("loaded_components[18]", "placetagger")
<< CHAR_PARAM("loaded_components[19]", "citysharericon");
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// changing identity to post status for pages
-SwitchIdentityRequest::SwitchIdentityRequest(const char *dtsg, const char *userId) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/identity_switch.php")
+HttpRequest* facebook_client::switchIdentityRequest(const char *userId)
{
- Url << INT_PARAM("__a", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/identity_switch.php");
+
+ p->Url << INT_PARAM("__a", 1);
- Body << CHAR_PARAM("fb_dtsg", dtsg) << CHAR_PARAM("user_id", userId) << CHAR_PARAM("url", FACEBOOK_URL_HOMEPAGE);
+ p->Body << CHAR_PARAM("fb_dtsg", dtsg_.c_str()) << CHAR_PARAM("user_id", userId) << CHAR_PARAM("url", FACEBOOK_URL_HOMEPAGE);
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// posting status to our or friends's wall
-SharePostRequest::SharePostRequest(facebook_client *fc, status_data *status, const char *linkData) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/updatestatus.php")
+HttpRequest* facebook_client::sharePostRequest(status_data *status, const char *linkData)
{
- Url << INT_PARAM("__a", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/ajax/updatestatus.php");
- ptrA text(mir_urlEncode(status->text.c_str()));
+ p->Url << INT_PARAM("__a", 1);
- Body
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__dyn", fc->__dyn())
- << CHAR_PARAM("__req", fc->__req())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str())
- << CHAR_PARAM("__user", status->isPage && !status->user_id.empty() ? status->user_id.c_str() : fc->self_.user_id.c_str())
- << CHAR_PARAM("xhpc_targetid", status->user_id.empty() ? fc->self_.user_id.c_str() : status->user_id.c_str())
+ ptrA text(mir_urlEncode(status->text.c_str()));
+ p->Body
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__dyn", __dyn())
+ << CHAR_PARAM("__req", __req())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str())
+ << CHAR_PARAM("__user", status->isPage && !status->user_id.empty() ? status->user_id.c_str() : self_.user_id.c_str())
+ << CHAR_PARAM("xhpc_targetid", status->user_id.empty() ? self_.user_id.c_str() : status->user_id.c_str())
<< CHAR_PARAM("xhpc_message", text)
<< CHAR_PARAM("xhpc_message_text", text)
<< CHAR_PARAM("xhpc_context", "profile")
@@ -120,38 +137,43 @@ SharePostRequest::SharePostRequest(facebook_client *fc, status_data *status, con
<< CHAR_PARAM("nctr[_mod]", "pagelet_composer");
if (!status->isPage)
- Body << CHAR_PARAM("audience[0][value]", fc->get_privacy_type().c_str());
+ p->Body << CHAR_PARAM("audience[0][value]", get_privacy_type().c_str());
if (!status->place.empty())
- Body << CHAR_PARAM("composertags_place_name", ptrA(mir_urlEncode(status->place.c_str())));
+ p->Body << CHAR_PARAM("composertags_place_name", ptrA(mir_urlEncode(status->place.c_str())));
// Status with users
for (std::vector<facebook_user*>::size_type i = 0; i < status->users.size(); i++) {
CMStringA withId(::FORMAT, "composertags_with[%i]", i);
CMStringA withName(::FORMAT, "text_composertags_with[%i]", i);
- Body
+ p->Body
<< CHAR_PARAM(withId.c_str(), status->users[i]->user_id.c_str())
<< CHAR_PARAM(withName.c_str(), status->users[i]->real_name.c_str());
}
// Link attachment
if (mir_strlen(linkData) > 0)
- Body << linkData;
+ p->Body << linkData;
+
+ return p;
}
//////////////////////////////////////////////////////////////////////////////////////////
// sending pokes
-SendPokeRequest::SendPokeRequest(facebook_client *fc, const char *userId) :
- HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/pokes/dialog/")
+HttpRequest* facebook_client::sendPokeRequest(const char *userId)
{
- Url << INT_PARAM("__a", 1);
+ HttpRequest *p = new HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/pokes/dialog/");
- Body
+ p->Url << INT_PARAM("__a", 1);
+
+ p->Body
<< INT_PARAM("do_confirm", 0)
<< CHAR_PARAM("poke_target", userId)
- << CHAR_PARAM("fb_dtsg", fc->dtsg_.c_str())
- << CHAR_PARAM("__user", fc->self_.user_id.c_str())
- << CHAR_PARAM("ttstamp", fc->ttstamp_.c_str());
+ << CHAR_PARAM("fb_dtsg", dtsg_.c_str())
+ << CHAR_PARAM("__user", self_.user_id.c_str())
+ << CHAR_PARAM("ttstamp", ttstamp_.c_str());
+
+ return p;
}