summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/FacebookRM/src/avatars.cpp23
-rw-r--r--protocols/FacebookRM/src/chat.cpp140
-rw-r--r--protocols/FacebookRM/src/communication.cpp360
-rw-r--r--protocols/FacebookRM/src/connection.cpp42
-rw-r--r--protocols/FacebookRM/src/contacts.cpp38
-rw-r--r--protocols/FacebookRM/src/dialogs.cpp367
-rw-r--r--protocols/FacebookRM/src/events.cpp8
-rw-r--r--protocols/FacebookRM/src/http_request.h29
-rw-r--r--protocols/FacebookRM/src/json.cpp31
-rw-r--r--protocols/FacebookRM/src/list.hpp35
-rw-r--r--protocols/FacebookRM/src/main.cpp2
-rw-r--r--protocols/FacebookRM/src/messages.cpp22
-rw-r--r--protocols/FacebookRM/src/process.cpp168
-rw-r--r--protocols/FacebookRM/src/proto.cpp96
-rw-r--r--protocols/FacebookRM/src/proto.h3
-rw-r--r--protocols/FacebookRM/src/requests/history.h6
-rw-r--r--protocols/FacebookRM/src/requests/utils.h26
-rw-r--r--protocols/FacebookRM/src/theme.cpp3
-rw-r--r--utils/std_string_utils.cpp62
19 files changed, 621 insertions, 840 deletions
diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp
index d0a9952833..2b533181eb 100644
--- a/protocols/FacebookRM/src/avatars.cpp
+++ b/protocols/FacebookRM/src/avatars.cpp
@@ -92,20 +92,17 @@ void FacebookProto::UpdateAvatarWorker(void *)
std::string params = getBool(FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS) ? "?width=200&height=200" : "?width=80&height=80";
- for (;;)
- {
+ for (;;) {
std::string url;
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.hContact = avatar_queue[0];
- if (Miranda_IsTerminated())
- {
+ if (Miranda_IsTerminated()) {
debugLogA("*** Terminating avatar update early: %s", url.c_str());
break;
}
- if (GetDbAvatarInfo(ai, &url))
- {
+ if (GetDbAvatarInfo(ai, &url)) {
debugLogA("*** Updating avatar: %s", url.c_str());
bool success = facy.save_url(url + params, ai.filename, nlc);
@@ -134,8 +131,7 @@ INT_PTR FacebookProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
int res = 0;
- switch (wParam)
- {
+ switch (wParam) {
case AF_MAXSIZE:
((POINT*)lParam)->x = -1;
((POINT*)lParam)->y = -1;
@@ -162,7 +158,7 @@ INT_PTR FacebookProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
res = 0;
break;
- case AF_ENABLED:
+ case AF_ENABLED:
case AF_FETCHIFPROTONOTVISIBLE:
case AF_FETCHIFCONTACTOFFLINE:
res = 1;
@@ -178,8 +174,7 @@ INT_PTR FacebookProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
return GAIR_NOAVATAR;
PROTO_AVATAR_INFORMATION* pai = (PROTO_AVATAR_INFORMATION*)lParam;
- if (GetDbAvatarInfo(*pai, nullptr))
- {
+ if (GetDbAvatarInfo(*pai, nullptr)) {
bool fileExist = _waccess(pai->filename, 0) == 0;
bool needLoad;
@@ -188,13 +183,11 @@ INT_PTR FacebookProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
else
needLoad = (wParam & GAIF_FORCE) || !fileExist;
- if (needLoad)
- {
+ if (needLoad) {
debugLogA("*** Starting avatar request thread for %s", _T2A(pai->filename));
ScopedLock s(avatar_lock_);
- if (std::find(avatar_queue.begin(), avatar_queue.end(), pai->hContact) == avatar_queue.end())
- {
+ if (std::find(avatar_queue.begin(), avatar_queue.end(), pai->hContact) == avatar_queue.end()) {
bool is_empty = avatar_queue.empty();
avatar_queue.push_back(pai->hContact);
if (is_empty)
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index 883ebae58b..6cb3900306 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -62,7 +62,6 @@ void FacebookProto::RenameChat(const char *chat_id, const char *name)
int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
{
GCHOOK *hook = reinterpret_cast<GCHOOK*>(lParam);
-
if (mir_strcmp(hook->pszModule, m_szModuleName))
return 0;
@@ -70,86 +69,82 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam)
if (!mir_wstrcmp(hook->ptszID, _A2W(FACEBOOK_NOTIFICATIONS_CHATROOM)))
return 0;
- switch (hook->iType)
- {
+ switch (hook->iType) {
case GC_USER_MESSAGE:
- {
- std::string msg = _T2A(hook->ptszText, CP_UTF8);
- std::string chat_id = _T2A(hook->ptszID, CP_UTF8);
+ {
+ std::string msg = _T2A(hook->ptszText, CP_UTF8);
+ std::string chat_id = _T2A(hook->ptszID, CP_UTF8);
- if (isOnline()) {
- debugLogA(" > Chat - Outgoing message");
- ForkThread(&FacebookProto::SendChatMsgWorker, new send_chat(chat_id, msg));
+ if (isOnline()) {
+ debugLogA(" > Chat - Outgoing message");
+ ForkThread(&FacebookProto::SendChatMsgWorker, new send_chat(chat_id, msg));
+ }
}
-
break;
- }
case GC_USER_PRIVMESS:
- {
- facebook_user fbu;
- fbu.user_id = _T2A(hook->ptszUID, CP_UTF8);
-
- // Find this contact in list or add new temporary contact
- MCONTACT hContact = AddToContactList(&fbu, false, true);
-
- if (!hContact)
- break;
-
- CallService(MS_MSG_SENDMESSAGEW, hContact);
- break;
- }
-
- /*
- case GC_USER_LOGMENU:
- {
- switch(hook->dwData)
- {
- case 10:
- DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog,
- LPARAM(new invite_chat_param(item->id, this)));
- break;
-
- case 20:
- //chat_leave(id);
- break;
- }
- break;
- }
- */
-
- case GC_USER_NICKLISTMENU:
- {
- MCONTACT hContact = NULL;
- if (hook->dwData == 10 || hook->dwData == 20) {
+ {
facebook_user fbu;
fbu.user_id = _T2A(hook->ptszUID, CP_UTF8);
// Find this contact in list or add new temporary contact
- hContact = AddToContactList(&fbu, false, true);
-
+ MCONTACT hContact = AddToContactList(&fbu, false, true);
if (!hContact)
break;
+
+ CallService(MS_MSG_SENDMESSAGEW, hContact);
}
+ break;
- switch (hook->dwData)
+ /*
+ case GC_USER_LOGMENU:
+ {
+ switch(hook->dwData)
{
case 10:
- CallService(MS_USERINFO_SHOWDIALOG, hContact);
- break;
+ DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CHATROOM_INVITE), NULL, invite_to_chat_dialog,
+ LPARAM(new invite_chat_param(item->id, this)));
+ break;
case 20:
- CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact);
- break;
+ //chat_leave(id);
+ break;
+ }
+ break;
+ }
+ */
+
+ case GC_USER_NICKLISTMENU:
+ {
+ MCONTACT hContact = NULL;
+ if (hook->dwData == 10 || hook->dwData == 20) {
+ facebook_user fbu;
+ fbu.user_id = _T2A(hook->ptszUID, CP_UTF8);
+
+ // Find this contact in list or add new temporary contact
+ hContact = AddToContactList(&fbu, false, true);
+
+ if (!hContact)
+ break;
+ }
+
+ switch (hook->dwData) {
+ case 10:
+ CallService(MS_USERINFO_SHOWDIALOG, hContact);
+ break;
+
+ case 20:
+ CallService(MS_HISTORY_SHOWCONTACTHISTORY, hContact);
+ break;
+
+ case 110:
+ //chat_leave(id);
+ break;
+ }
- case 110:
- //chat_leave(id);
break;
}
- break;
- }
-
case GC_USER_LEAVE:
case GC_SESSION_TERMINATE:
break;
@@ -270,9 +265,8 @@ INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM)
std::string thread_id = threadId;
auto it = facy.chat_rooms.find(thread_id);
- if (it != facy.chat_rooms.end()) {
+ if (it != facy.chat_rooms.end())
fbc = it->second;
- }
else {
// We don't have this chat loaded in memory yet, lets load some info (name, list of users)
fbc = new facebook_chatroom(thread_id);
@@ -313,9 +307,8 @@ INT_PTR FacebookProto::OnLeaveChat(WPARAM wParam, LPARAM)
Chat_Control(m_szModuleName, idT, SESSION_OFFLINE);
Chat_Terminate(m_szModuleName, idT);
- if (!wParam) {
+ if (!wParam)
facy.clear_chatrooms();
- }
else if (!IsSpecialChatRoom(wParam)) {
ptrA threadId(getStringA(wParam, FACEBOOK_KEY_TID));
if (!threadId)
@@ -337,8 +330,7 @@ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam)
if (gcmi == nullptr || _stricmp(gcmi->pszModule, m_szModuleName)) return 0;
- if (gcmi->Type == MENU_ON_LOG)
- {
+ if (gcmi->Type == MENU_ON_LOG) {
static const struct gc_item Items[] =
{
{ LPGENW("&Invite user..."), 10, MENU_ITEM, FALSE },
@@ -346,10 +338,8 @@ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam)
};
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)))
- {
+ 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 },
@@ -360,8 +350,7 @@ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam)
gcmi->nItems = _countof(Items);
gcmi->Item = (gc_item*)Items;*/
}
- else
- {
+ else {
static const struct gc_item Items[] =
{
{ LPGENW("User &details"), 10, MENU_ITEM, FALSE },
@@ -374,7 +363,8 @@ int FacebookProto::OnGCMenuHook(WPARAM, LPARAM lParam)
return 0;
}
-bool FacebookProto::IsSpecialChatRoom(MCONTACT hContact) {
+bool FacebookProto::IsSpecialChatRoom(MCONTACT hContact)
+{
if (!isChatRoom(hContact))
return false;
@@ -382,7 +372,8 @@ bool FacebookProto::IsSpecialChatRoom(MCONTACT hContact) {
return id && !mir_strcmp(id, FACEBOOK_NOTIFICATIONS_CHATROOM);
}
-void FacebookProto::PrepareNotificationsChatRoom() {
+void FacebookProto::PrepareNotificationsChatRoom()
+{
if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM))
return;
@@ -401,7 +392,8 @@ void FacebookProto::PrepareNotificationsChatRoom() {
}
}
-void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notification) {
+void FacebookProto::UpdateNotificationsChatRoom(facebook_notification *notification)
+{
if (!getBool(FACEBOOK_KEY_NOTIFICATIONS_CHATROOM, DEFAULT_NOTIFICATIONS_CHATROOM))
return;
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 715557dcda..6e243c993e 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -51,19 +51,8 @@ http::response facebook_client::sendRequest(HttpRequest *request)
<< CHAR_VALUE("User-Agent", g_strUserAgent.c_str())
<< CHAR_VALUE("Cookie", ptrA(load_cookies())); // FIXME: Rework load_cookies to not do strdup
- if (request->requestType == REQUEST_POST) {
- request->Headers
- << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
- }
-
- // TODO: rather change http_request than doing this ifdef magic here?
-/*#ifdef _DEBUG
- request->flags &= ~NLHRF_NODUMP;
- request->flags |= NLHRF_DUMPASTEXT;
-#else
- request->flags &= ~NLHRF_DUMPASTEXT;
- request->flags |= NLHRF_NODUMP;
-#endif*/
+ if (request->requestType == REQUEST_POST)
+ request->Headers << CHAR_VALUE("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
// Set persistent connection (or not)
switch (request->Persistent) {
@@ -136,9 +125,8 @@ http::response facebook_client::sendRequest(HttpRequest *request)
pos += 20;
std::string::size_type pos2 = resp.data.find("\",\"", pos);
- if (pos2 == std::string::npos) {
+ if (pos2 == std::string::npos)
pos2 = resp.data.find("\"", pos);
- }
error = resp.data.substr(pos, pos2 - pos);
error = utils::text::trim(utils::text::html_entities_decode(utils::text::remove_html(utils::text::slashu_to_utf8(error))));
@@ -244,15 +232,13 @@ char* facebook_client::load_cookies()
std::string cookieString;
- if (!cookies.empty()) {
- for (std::map< std::string, std::string >::iterator iter = cookies.begin(); iter != cookies.end(); ++iter)
- {
+ if (!cookies.empty())
+ for (std::map< std::string, std::string >::iterator iter = cookies.begin(); iter != cookies.end(); ++iter) {
cookieString.append(iter->first);
cookieString.append(1, '=');
cookieString.append(iter->second);
cookieString.append(1, ';');
}
- }
return mir_strdup(cookieString.c_str());
}
@@ -274,9 +260,8 @@ void facebook_client::store_headers(http::response* resp, NETLIBHTTPHEADER* head
cookies.erase(cookie_name);
else
cookies[cookie_name] = cookie_value;
- } else {
- resp->headers[header_name] = header_value;
}
+ else resp->headers[header_name] = header_value;
}
}
@@ -348,11 +333,10 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const s
// try to get name of this participant
auto participant = participants.find(readerId);
- if (participant != participants.end()) {
+ if (participant != participants.end())
name = participant->second.nick;
- }
}
-
+
std::wstring treaders;
// Load old readers
@@ -369,9 +353,8 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const s
parent->setDword(hContact, FACEBOOK_KEY_MESSAGE_READ, timestamp);
readers.insert(std::make_pair(hContact, timestamp));
parent->MessageRead(hContact);
- if (ServiceExists(MS_MESSAGESTATE_UPDATE))
- {
- MessageReadData data(timestamp, MRD_TYPE_READTIME);
+ if (ServiceExists(MS_MESSAGESTATE_UPDATE)) {
+ MessageReadData data(timestamp, MRD_TYPE_READTIME);
CallService(MS_MESSAGESTATE_UPDATE, hContact, (LPARAM)&data);
}
}
@@ -381,23 +364,23 @@ void facebook_client::insert_reader(MCONTACT hContact, time_t timestamp, const s
*/
void facebook_client::erase_reader(MCONTACT hContact)
{
- if (parent->isChatRoom(hContact)) {
+ if (parent->isChatRoom(hContact))
parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READERS);
- }
-
+
parent->delSetting(hContact, FACEBOOK_KEY_MESSAGE_READ);
readers.erase(hContact);
Srmm_SetStatusText(hContact, nullptr);
}
-void loginError(FacebookProto *proto, std::string error_str) {
+void loginError(FacebookProto *proto, std::string error_str)
+{
utils::text::replace_all(&error_str, "<br \\/>", "\n");
utils::text::replace_all(&error_str, "\n\n\n", "\n\n");
error_str = utils::text::trim(
utils::text::html_entities_decode(
- utils::text::remove_html(error_str)));
+ utils::text::remove_html(error_str)));
proto->debugLogA("!!! Login error: %s", !error_str.empty() ? error_str.c_str() : "Unknown error");
@@ -407,7 +390,8 @@ void loginError(FacebookProto *proto, std::string error_str) {
proto->facy.client_notify(buf);
}
-void parseJsCookies(const std::string &search, const std::string &data, std::map<std::string, std::string> &cookies) {
+void parseJsCookies(const std::string &search, const std::string &data, std::map<std::string, std::string> &cookies)
+{
std::string::size_type pos = 0;
while ((pos = data.find(search, pos)) != std::string::npos) {
pos += search.length();
@@ -467,8 +451,7 @@ bool facebook_client::login(const char *username, const char *password)
if (!cookies["datr"].empty())
parent->setString(FACEBOOK_KEY_DEVICE_ID, cookies["datr"].c_str());
- if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end())
- {
+ if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) {
std::string location = resp.headers["Location"];
// Check for invalid requests
@@ -518,19 +501,14 @@ bool facebook_client::login(const char *username, const char *password)
parent->debugLogA("!!! Login error: Too many invalid attempts to verification code.");
return handle_error("login", FORCE_QUIT);
}
- else {
- client_notify(TranslateT("You entered wrong verification code. Try it again."));
- }
+ else client_notify(TranslateT("You entered wrong verification code. Try it again."));
}
- else {
- // After successful verification is showed different page - classic form to save device (as handled at the bottom)
+ else // After successful verification is showed different page - classic form to save device (as handled at the bottom)
break;
- }
}
// Save this actual device
- if (resp.data.find("name=\"submit[Continue]\"") != std::string::npos
- && resp.data.find("name=\"name_action_selected\"") != std::string::npos) {
+ if (resp.data.find("name=\"submit[Continue]\"") != std::string::npos && resp.data.find("name=\"name_action_selected\"") != 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=\"", "\"");
@@ -566,9 +544,8 @@ bool facebook_client::login(const char *username, const char *password)
std::string activity = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "<body", "</strong></div>", "</div>"));
activity = utils::text::trim(utils::text::html_entities_decode(utils::text::remove_html(activity)));
- if (!activity.empty()) {
+ if (!activity.empty())
tszMessage.AppendFormat(L"\n\n%s", ptrW(mir_utf8decodeW(activity.c_str())));
- }
if (MessageBox(nullptr, tszMessage, tszTitle, MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1) != IDYES) {
// We will cancel connecting right away, because we don't want to handle password changing via Miranda
@@ -585,7 +562,7 @@ bool facebook_client::login(const char *username, const char *password)
// 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");
request->Body << "&name_action_selected=save_device"; // Save device - or "dont_save"
resp = sendRequest(request);
@@ -598,7 +575,8 @@ bool facebook_client::login(const char *username, const char *password)
parent->delSetting(FACEBOOK_KEY_DEVICE_ID);
parent->setByte(FACEBOOK_KEY_TRIED_DELETING_DEVICE_ID, 1);
return login(username, password);
- } else {
+ }
+ else {
// Reset flag
parent->delSetting(FACEBOOK_KEY_TRIED_DELETING_DEVICE_ID);
// Facebook things that computer was infected by malware and needs cleaning
@@ -610,43 +588,40 @@ bool facebook_client::login(const char *username, const char *password)
}
}
- switch (resp.code)
- {
+ switch (resp.code) {
case HTTP_CODE_FAKE_DISCONNECTED:
- {
// When is error only because timeout, try login once more
if (handle_error("login"))
return login(username, password);
else
return handle_error("login", FORCE_QUIT);
- }
case HTTP_CODE_OK: // OK page returned, but that is regular login page we don't want in fact
- {
// Check whether captcha code is required
if (resp.data.find("id=\"captcha\"") != std::string::npos) {
client_notify(TranslateT("Login error: Captcha code is required. You need to confirm this device from web browser."));
parent->debugLogA("!!! Login error: Captcha code is required.");
return handle_error("login", FORCE_QUIT);
}
+ else {
+ // Get and notify error message
+ std::string error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "[\"LoginFormError\"", "\"__html\":\"", "\"}"));
+ if (error.empty())
+ error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "role=\"alert\"", ">", "</div"));
+ if (error.empty())
+ error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "id=\"globalContainer\"", ">", "</div"));
+ if (error.empty())
+ error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 2, "<strong>", "</strong"));
+ loginError(parent, error);
+ }
+ // fall through
- // Get and notify error message
- std::string error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "[\"LoginFormError\"", "\"__html\":\"", "\"}"));
- if (error.empty())
- error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "role=\"alert\"", ">", "</div"));
- if (error.empty())
- error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "id=\"globalContainer\"", ">", "</div"));
- if (error.empty())
- error = utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 2, "<strong>", "</strong"));
- loginError(parent, error);
- }
case HTTP_CODE_FORBIDDEN: // Forbidden
case HTTP_CODE_NOT_FOUND: // Not Found
default:
return handle_error("login", FORCE_QUIT);
case HTTP_CODE_FOUND: // Found and redirected somewhere
- {
if (resp.headers.find("Location") != resp.headers.end()) {
std::string redirectUrl = resp.headers["Location"];
std::string expectedUrl = HTTP_PROTO_SECURE FACEBOOK_SERVER_REGULAR "/";
@@ -655,7 +630,7 @@ bool facebook_client::login(const char *username, const char *password)
std::string::size_type pos = redirectUrl.rfind("?");
if (pos != std::string::npos)
redirectUrl = redirectUrl.substr(0, pos);
-
+
if (redirectUrl != expectedUrl) {
// Unexpected redirect, but we try to ignore it - maybe we were logged in anyway
parent->debugLogA("!!! Login error: Unexpected redirect: %s (Original: %s) (Expected: %s)", redirectUrl.c_str(), resp.headers["Location"].c_str(), expectedUrl.c_str());
@@ -675,7 +650,6 @@ bool facebook_client::login(const char *username, const char *password)
return handle_error("login", FORCE_QUIT);
}
}
- }
}
bool facebook_client::logout()
@@ -689,8 +663,7 @@ bool facebook_client::logout()
this->password_.clear();
this->self_.user_id.clear();
- switch (resp.code)
- {
+ switch (resp.code) {
case HTTP_CODE_OK:
case HTTP_CODE_FOUND:
return handle_success("logout");
@@ -711,115 +684,114 @@ bool facebook_client::home()
{
// Compute ttstamp from dtsg_
std::stringstream csrf;
- for (unsigned int i = 0; i < this->dtsg_.length(); i++) {
+ for (unsigned int i = 0; i < this->dtsg_.length(); i++)
csrf << (int)this->dtsg_.at(i);
- }
+
this->ttstamp_ = "2" + csrf.str();
- }
+ }
if (this->dtsg_.empty()) {
parent->debugLogA("!!! Empty dtsg. Source code:\n%s", resp.data.c_str());
client_notify(TranslateT("Could not load communication token. You should report this and wait for plugin update."));
return handle_error("home", FORCE_QUIT);
- } else {
- parent->debugLogA(" Got self dtsg");
}
+
+ parent->debugLogA(" Got self dtsg");
resp = sendRequest(new HomeRequest());
- switch (resp.code)
- {
+ switch (resp.code) {
case HTTP_CODE_OK:
- {
- std::string touchSearch = "{\"id\":" + this->self_.user_id;
- std::string touchData = utils::text::source_get_value(&resp.data, 2, touchSearch.c_str(), "}");
+ {
+ std::string touchSearch = "{\"id\":" + this->self_.user_id;
+ std::string touchData = utils::text::source_get_value(&resp.data, 2, touchSearch.c_str(), "}");
- // Get real name (from touch version)
- if (!touchData.empty())
- this->self_.real_name = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&touchData, 2, "\"name\":\"", "\"")));
+ // Get real name (from touch version)
+ if (!touchData.empty())
+ this->self_.real_name = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&touchData, 2, "\"name\":\"", "\"")));
- // Another attempt to get real name (from mbasic version)
- if (this->self_.real_name.empty())
- this->self_.real_name = utils::text::source_get_value(&resp.data, 4, "id=\"root", "<strong", ">", "</strong>");
+ // Another attempt to get real name (from mbasic version)
+ if (this->self_.real_name.empty())
+ this->self_.real_name = utils::text::source_get_value(&resp.data, 4, "id=\"root", "<strong", ">", "</strong>");
- // Try to get name again, if we've got some some weird version of Facebook
- if (this->self_.real_name.empty())
- this->self_.real_name = utils::text::source_get_value(&resp.data, 5, "id=\"root", "</a>", "<div", ">", "</div>");
+ // Try to get name again, if we've got some some weird version of Facebook
+ if (this->self_.real_name.empty())
+ this->self_.real_name = utils::text::source_get_value(&resp.data, 5, "id=\"root", "</a>", "<div", ">", "</div>");
- // Another attempt to get name
- if (this->self_.real_name.empty())
- this->self_.real_name = utils::text::source_get_value(&resp.data, 5, "id=\"root", "</td>", "<div", ">", "</td>");
+ // Another attempt to get name
+ if (this->self_.real_name.empty())
+ this->self_.real_name = utils::text::source_get_value(&resp.data, 5, "id=\"root", "</td>", "<div", ">", "</td>");
- // Get and strip optional nickname
- std::string::size_type pos = this->self_.real_name.find("<span class=\"alternate_name\">");
- if (pos != std::string::npos) {
- this->self_.nick = utils::text::source_get_value(&this->self_.real_name, 2, "<span class=\"alternate_name\">(", ")</span>");
- parent->debugLogA(" Got self nick name: %s", this->self_.nick.c_str());
+ // Get and strip optional nickname
+ std::string::size_type pos = this->self_.real_name.find("<span class=\"alternate_name\">");
+ if (pos != std::string::npos) {
+ this->self_.nick = utils::text::source_get_value(&this->self_.real_name, 2, "<span class=\"alternate_name\">(", ")</span>");
+ parent->debugLogA(" Got self nick name: %s", this->self_.nick.c_str());
- this->self_.real_name = this->self_.real_name.substr(0, pos - 1);
- }
-
- // Another attempt to get optional nickname
- if (this->self_.nick.empty())
- this->self_.nick = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "class=\\\"alternate_name\\\"", ">(", ")\\u003C\\/")));
-
- this->self_.real_name = utils::text::remove_html(this->self_.real_name);
- parent->debugLogA(" Got self real name (nickname): %s (%s)", this->self_.real_name.c_str(), this->self_.nick.c_str());
- parent->SaveName(NULL, &this->self_);
-
- // Get avatar (from touch version)
- if (!touchData.empty())
- this->self_.image_url = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&touchData, 2, "\"pic\":\"", "\"")));
-
- // Another attempt to get avatar(from mbasic version)
- if (this->self_.image_url.empty())
- this->self_.image_url = utils::text::source_get_value(&resp.data, 3, "id=\"root", "<img src=\"", "\"");
-
- // Another attempt to get avatar
- if (this->self_.image_url.empty()) {
- this->self_.image_url = utils::text::source_get_value(&resp.data, 3, "id=\"root", "/photo.php?", "\"");
-
- // Prepare this special url (not direct image url) to be handled correctly in CheckAvatarChange()
- // It must contain "/" at the beginning and also shouldn't contain "?" as parameters after that are stripped
- if (!this->self_.image_url.empty())
- this->self_.image_url = "/" + this->self_.image_url;
- }
-
- // 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);
-
- // 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=\"", "\""));
+ this->self_.real_name = this->self_.real_name.substr(0, pos - 1);
+ }
+
+ // Another attempt to get optional nickname
+ if (this->self_.nick.empty())
+ this->self_.nick = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&resp.data, 3, "class=\\\"alternate_name\\\"", ">(", ")\\u003C\\/")));
+
+ this->self_.real_name = utils::text::remove_html(this->self_.real_name);
+ parent->debugLogA(" Got self real name (nickname): %s (%s)", this->self_.real_name.c_str(), this->self_.nick.c_str());
+ parent->SaveName(NULL, &this->self_);
// Get avatar (from touch version)
+ if (!touchData.empty())
+ this->self_.image_url = utils::text::html_entities_decode(utils::text::slashu_to_utf8(utils::text::source_get_value(&touchData, 2, "\"pic\":\"", "\"")));
+
+ // Another attempt to get avatar(from mbasic version)
if (this->self_.image_url.empty())
- this->self_.image_url = utils::text::html_entities_decode(utils::text::source_get_value(&resp2.data, 3, "id=\"root", "background-image: url(&quot;", "&quot;)"));
+ this->self_.image_url = utils::text::source_get_value(&resp.data, 3, "id=\"root", "<img src=\"", "\"");
- // Sometimes even Facebook doesn't show any picture at all! So just ignore this error in that case...
+ // Another attempt to get avatar
if (this->self_.image_url.empty()) {
- parent->debugLogA("!!! Empty avatar even from avatar page. Source code:\n%s", resp2.data.c_str());
-
- // Set dumb avatar "url" (see how it works in CheckAvatarChange()) so we can't tell if/when the avatar changed, but it will be loaded at least once
- this->self_.image_url = "/NO_AVATAR/";
+ this->self_.image_url = utils::text::source_get_value(&resp.data, 3, "id=\"root", "/photo.php?", "\"");
+
+ // Prepare this special url (not direct image url) to be handled correctly in CheckAvatarChange()
+ // It must contain "/" at the beginning and also shouldn't contain "?" as parameters after that are stripped
+ if (!this->self_.image_url.empty())
+ this->self_.image_url = "/" + this->self_.image_url;
}
- }
- parent->debugLogA(" Got self avatar: %s", this->self_.image_url.c_str());
- parent->CheckAvatarChange(NULL, this->self_.image_url);
+ // 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);
- // Get logout hash
- this->logout_hash_ = utils::text::source_get_value2(&resp.data, "/logout.php?h=", "&\"");
- parent->debugLogA(" Got self logout hash: %s", this->logout_hash_.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=\"", "\""));
- if (this->self_.real_name.empty() || this->self_.image_url.empty() || this->logout_hash_.empty()) {
- parent->debugLogA("!!! Empty nick/avatar/hash. Source code:\n%s", resp.data.c_str());
- client_notify(TranslateT("Could not load all required data. Plugin may still work correctly, but you should report this and wait for plugin update."));
- }
+ // Get avatar (from touch version)
+ if (this->self_.image_url.empty())
+ this->self_.image_url = utils::text::html_entities_decode(utils::text::source_get_value(&resp2.data, 3, "id=\"root", "background-image: url(&quot;", "&quot;)"));
+
+ // Sometimes even Facebook doesn't show any picture at all! So just ignore this error in that case...
+ if (this->self_.image_url.empty()) {
+ parent->debugLogA("!!! Empty avatar even from avatar page. Source code:\n%s", resp2.data.c_str());
+
+ // Set dumb avatar "url" (see how it works in CheckAvatarChange()) so we can't tell if/when the avatar changed, but it will be loaded at least once
+ this->self_.image_url = "/NO_AVATAR/";
+ }
+ }
+ parent->debugLogA(" Got self avatar: %s", this->self_.image_url.c_str());
+ parent->CheckAvatarChange(NULL, this->self_.image_url);
+
+ // Get logout hash
+ this->logout_hash_ = utils::text::source_get_value2(&resp.data, "/logout.php?h=", "&\"");
+ parent->debugLogA(" Got self logout hash: %s", this->logout_hash_.c_str());
+
+ if (this->self_.real_name.empty() || this->self_.image_url.empty() || this->logout_hash_.empty()) {
+ parent->debugLogA("!!! Empty nick/avatar/hash. Source code:\n%s", resp.data.c_str());
+ client_notify(TranslateT("Could not load all required data. Plugin may still work correctly, but you should report this and wait for plugin update."));
+ }
+ }
return handle_success("home");
- }
+
case HTTP_CODE_FOUND:
// Work-around for replica_down, f**king hell what's that?
parent->debugLogA("!!! REPLICA_DOWN is back in force!");
@@ -850,39 +822,37 @@ bool facebook_client::reconnect()
// Request reconnect
http::response resp = sendRequest(new ReconnectRequest(this));
- switch (resp.code)
- {
+ switch (resp.code) {
case HTTP_CODE_OK:
- {
- this->chat_channel_ = utils::text::source_get_value(&resp.data, 2, "\"user_channel\":\"", "\"");
- parent->debugLogA(" Got self channel: %s", this->chat_channel_.c_str());
+ {
+ this->chat_channel_ = utils::text::source_get_value(&resp.data, 2, "\"user_channel\":\"", "\"");
+ parent->debugLogA(" Got self channel: %s", this->chat_channel_.c_str());
- this->chat_channel_partition_ = utils::text::source_get_value2(&resp.data, "\"partition\":", ",}");
- parent->debugLogA(" Got self channel partition: %s", this->chat_channel_partition_.c_str());
+ this->chat_channel_partition_ = utils::text::source_get_value2(&resp.data, "\"partition\":", ",}");
+ parent->debugLogA(" Got self channel partition: %s", this->chat_channel_partition_.c_str());
- this->chat_channel_host_ = utils::text::source_get_value(&resp.data, 2, "\"host\":\"", "\"");
- parent->debugLogA(" Got self channel host: %s", this->chat_channel_host_.c_str());
+ this->chat_channel_host_ = utils::text::source_get_value(&resp.data, 2, "\"host\":\"", "\"");
+ parent->debugLogA(" Got self channel host: %s", this->chat_channel_host_.c_str());
- this->chat_sequence_num_ = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}");
- parent->debugLogA(" Got self sequence number: %s", this->chat_sequence_num_.c_str());
-
- this->chat_conn_num_ = utils::text::source_get_value2(&resp.data, "\"max_conn\":", ",}");
- parent->debugLogA(" Got self max_conn: %s", this->chat_conn_num_.c_str());
+ this->chat_sequence_num_ = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}");
+ parent->debugLogA(" Got self sequence number: %s", this->chat_sequence_num_.c_str());
- this->chat_sticky_num_ = utils::text::source_get_value(&resp.data, 2, "\"sticky_token\":\"", "\"");
- parent->debugLogA(" Got self sticky_token: %s", this->chat_sticky_num_.c_str());
+ this->chat_conn_num_ = utils::text::source_get_value2(&resp.data, "\"max_conn\":", ",}");
+ parent->debugLogA(" Got self max_conn: %s", this->chat_conn_num_.c_str());
- //std::string retry_interval = utils::text::source_get_value2(&resp.data, "\"retry_interval\":", ",}");
- //parent->debugLogA(" Got self retry_interval: %s", retry_interval.c_str());
+ this->chat_sticky_num_ = utils::text::source_get_value(&resp.data, 2, "\"sticky_token\":\"", "\"");
+ parent->debugLogA(" Got self sticky_token: %s", this->chat_sticky_num_.c_str());
- //std::string visibility = utils::text::source_get_value2(&resp.data, "\"visibility\":", ",}");
- //parent->debugLogA(" Got self visibility: %s", visibility.c_str());
+ //std::string retry_interval = utils::text::source_get_value2(&resp.data, "\"retry_interval\":", ",}");
+ //parent->debugLogA(" Got self retry_interval: %s", retry_interval.c_str());
- // Send activity_ping after each reconnect
- activity_ping();
+ //std::string visibility = utils::text::source_get_value2(&resp.data, "\"visibility\":", ",}");
+ //parent->debugLogA(" Got self visibility: %s", visibility.c_str());
+ // Send activity_ping after each reconnect
+ activity_ping();
+ }
return handle_success("reconnect");
- }
default:
return handle_error("reconnect", FORCE_DISCONNECT);
@@ -897,16 +867,13 @@ bool facebook_client::channel()
ChannelRequest *request = new ChannelRequest(this, ChannelRequest::PULL);
http::response resp = sendRequest(request);
- if (resp.data.empty()) {
- // Something went wrong
+ if (resp.data.empty()) // Something went wrong
return handle_error("channel");
- }
// Load traceId, if present
std::string traceId = utils::text::source_get_value(&resp.data, 2, "\"tr\":\"", "\"");
- if (!traceId.empty()) {
+ if (!traceId.empty())
this->chat_traceid_ = traceId;
- }
std::string type = utils::text::source_get_value(&resp.data, 2, "\"t\":\"", "\"");
parent->debugLogA("Pull response type = %s", type.c_str());
@@ -972,14 +939,11 @@ bool facebook_client::channel()
this->chat_sequence_num_ = seq;
}
- else {
- // No type? This shouldn't happen unless there is a big API change.
+ else // No type? This shouldn't happen unless there is a big API change.
return handle_error("channel");
- }
// Return
- switch (resp.code)
- {
+ switch (resp.code) {
case HTTP_CODE_OK:
return handle_success("channel");
@@ -1023,12 +987,11 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
bool isChatRoom = parent->isChatRoom(hContact);
- ptrA userId( parent->getStringA(hContact, FACEBOOK_KEY_ID));
- ptrA threadId( parent->getStringA(hContact, FACEBOOK_KEY_TID));
-
+ ptrA userId(parent->getStringA(hContact, FACEBOOK_KEY_ID));
+ ptrA threadId(parent->getStringA(hContact, FACEBOOK_KEY_TID));
+
// Check if we have userId/threadId to be able to send message
- if ((isChatRoom && (threadId == NULL || !mir_strcmp(threadId, "null")))
- || (!isChatRoom && (userId == NULL || !mir_strcmp(userId, "null")))) {
+ if ((isChatRoom && (threadId == NULL || !mir_strcmp(threadId, "null"))) || (!isChatRoom && (userId == NULL || !mir_strcmp(userId, "null")))) {
// This shouldn't happen unless user manually deletes some data via Database Editor++
*error_text = Translate("Contact doesn't have required data in database.");
@@ -1040,10 +1003,9 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
std::string messageId = utils::text::rand_string(10, "123456789", &this->random_);
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());
- ScopedLock s(send_message_lock_);
+ ScopedLock s(send_message_lock_);
resp = sendRequest(request);
*error_text = resp.error_text;
@@ -1076,11 +1038,11 @@ int facebook_client::send_message(int seqid, MCONTACT hContact, const std::strin
}
switch (resp.error_number) {
- case 0:
+ case 0:
// Everything is OK
break;
- // case 1356002: // You are offline (probably you can't use mercury or some other request when chat is offline)
+ // case 1356002: // You are offline (probably you can't use mercury or some other request when chat is offline)
case 1356003: // Contact is offline
parent->setWord(hContact, "Status", ID_STATUS_OFFLINE);
@@ -1161,22 +1123,19 @@ bool facebook_client::post_status(status_data *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>");
utils::text::replace_all(&form, "\\\"", "\"");
- linkData += utils::text::source_get_form_data(&form);
+ linkData += utils::text::source_get_form_data(&form);
// 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);
- if (status->isPage) {
- // Switch back to our identity
+ if (status->isPage) // Switch back to our identity
sendRequest(new SwitchIdentityRequest(this->dtsg_.c_str(), this->self_.user_id.c_str()));
- }
// cleanup status elements (delete users)
- for (std::vector<facebook_user*>::size_type i = 0; i < status->users.size(); i++) {
+ for (std::vector<facebook_user*>::size_type i = 0; i < status->users.size(); i++)
delete status->users[i];
- }
status->users.clear();
if (resp.isValid()) {
@@ -1192,16 +1151,13 @@ bool facebook_client::post_status(status_data *status)
bool facebook_client::save_url(const std::string &url, const std::wstring &filename, HNETLIBCONN &nlc)
{
NETLIBHTTPREQUEST req = { sizeof(req) };
- NETLIBHTTPREQUEST *resp;
req.requestType = REQUEST_GET;
req.szUrl = const_cast<char*>(url.c_str());
req.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT | NLHRF_NODUMP;
req.nlc = nlc;
- resp = Netlib_HttpTransaction(handle_, &req);
-
bool ret = false;
-
+ NETLIBHTTPREQUEST *resp = Netlib_HttpTransaction(handle_, &req);
if (resp) {
nlc = resp->nlc;
parent->debugLogA("@@@ Saving URL %s to file %s", url.c_str(), _T2A(filename.c_str()));
@@ -1222,9 +1178,7 @@ bool facebook_client::save_url(const std::string &url, const std::wstring &filen
Netlib_FreeHttpRequest(resp);
}
- else {
- nlc = nullptr;
- }
+ else nlc = nullptr;
return ret;
}
@@ -1241,4 +1195,4 @@ bool facebook_client::sms_code(const char *fb_dtsg)
parent->NotifyEvent(parent->m_tszUserName, TranslateT("Verification SMS code was sent to your mobile phone."), NULL, EVENT_OTHER);
return true;
-} \ No newline at end of file
+}
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index 1b3feca6b8..c8c3bd2329 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -29,8 +29,8 @@ void FacebookProto::ChangeStatus(void*)
int new_status = m_iDesiredStatus;
int old_status = m_iStatus;
- if (new_status == ID_STATUS_OFFLINE)
- { // Logout
+ if (new_status == ID_STATUS_OFFLINE) {
+ // Logout
debugLogA("### Beginning SignOff process");
m_signingOut = true;
@@ -74,13 +74,6 @@ void FacebookProto::ChangeStatus(void*)
facy.pages.clear();
facy.typers.clear();
- // Clear thread/user id caches?
- /* Right now it's commented out because it's not really needed to erase - maybe only when user changes login/pass in same account, but even then it shouldn't cause problems
- facy.thread_id_to_user_id.clear();
- facy.chat_id_to_hcontact.clear();
- facy.user_id_to_hcontact.clear();
- */
-
// Close connection handle
if (facy.hFcbCon)
Netlib_CloseHandle(facy.hFcbCon);
@@ -94,8 +87,8 @@ void FacebookProto::ChangeStatus(void*)
return;
}
- else if (old_status == ID_STATUS_OFFLINE)
- { // Login
+ else if (old_status == ID_STATUS_OFFLINE) {
+ // Login
SYSTEMTIME t;
GetLocalTime(&t);
debugLogA("[%d.%d.%d] Using Facebook Protocol RM %s", t.wDay, t.wMonth, t.wYear, __VERSION_STRING_DOTS);
@@ -112,8 +105,7 @@ void FacebookProto::ChangeStatus(void*)
// Workaround for not working "mbasic." for some users - reset this flag at every login
facy.mbasicWorks = true;
- if (NegotiateConnection() && facy.home() && facy.reconnect())
- {
+ if (NegotiateConnection() && facy.home() && facy.reconnect()) {
// Load all friends
ProcessFriendList(nullptr);
@@ -166,15 +158,10 @@ void FacebookProto::ChangeStatus(void*)
ToggleStatusMenuItems(true);
debugLogA("*** SignOn complete");
}
- else
- { // Change between online/away/invisible statuses
- if (new_status == ID_STATUS_INVISIBLE) {
+ else { // Change between online/away/invisible statuses
+ if (new_status == ID_STATUS_INVISIBLE)
// When switching to invisible (from online/away), we need to set all contacts offline as we won't receive no status updates from Facebook
SetAllContactStatuses(ID_STATUS_OFFLINE);
- }
- else if (old_status == ID_STATUS_INVISIBLE) {
- // TODO: When switching from invisible, we should somehow load all the contacts statuses...
- }
}
bool wasAwayOrInvisible = (old_status == ID_STATUS_AWAY || old_status == ID_STATUS_INVISIBLE);
@@ -234,12 +221,10 @@ void FacebookProto::UpdateLoop(void *)
time_t tim = ::time(nullptr);
debugLogA(">>> Entering Facebook::UpdateLoop[%d]", tim);
- for (int i = -1; !isOffline(); i = (i + 1) % 50)
- {
- if (i != -1) {
+ for (int i = -1; !isOffline(); i = (i + 1) % 50) {
+ if (i != -1)
if (getByte(FACEBOOK_KEY_EVENT_FEEDS_ENABLE, DEFAULT_EVENT_FEEDS_ENABLE))
ProcessFeeds(nullptr);
- }
debugLogA("*** FacebookProto::UpdateLoop[%d] going to sleep...", tim);
if (WaitForSingleObjectEx(update_loop_lock_, GetPollRate() * 1000, true) != WAIT_TIMEOUT)
@@ -256,8 +241,7 @@ void FacebookProto::MessageLoop(void *)
time_t tim = ::time(nullptr);
debugLogA(">>> Entering Facebook::MessageLoop[%d]", tim);
- while (facy.channel())
- {
+ while (facy.channel()) {
if (isOffline() || m_signingOut)
break;
@@ -276,9 +260,5 @@ void FacebookProto::MessageLoop(void *)
BYTE FacebookProto::GetPollRate()
{
BYTE poll_rate = getByte(FACEBOOK_KEY_POLL_RATE, FACEBOOK_DEFAULT_POLL_RATE);
-
- return (
- (poll_rate >= FACEBOOK_MINIMAL_POLL_RATE &&
- poll_rate <= FACEBOOK_MAXIMAL_POLL_RATE)
- ? poll_rate : FACEBOOK_DEFAULT_POLL_RATE);
+ return ((poll_rate >= FACEBOOK_MINIMAL_POLL_RATE && poll_rate <= FACEBOOK_MAXIMAL_POLL_RATE) ? poll_rate : FACEBOOK_DEFAULT_POLL_RATE);
}
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 5a3f14ac93..91d52145fd 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -169,10 +169,10 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
// We don't have any contact with this thread_id cached, we must ask server
if (isOffline())
return "";
-
+
HttpRequest *request = new ThreadInfoRequest(&facy, true, thread_id.c_str());
http::response resp = facy.sendRequest(request);
-
+
std::string user_id;
if (resp.code == HTTP_CODE_OK) {
@@ -183,7 +183,7 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
facy.thread_id_to_user_id.insert(std::make_pair(thread_id, user_id));
debugLogA("*** Thread info processed");
- }
+ }
catch (const std::exception &e) {
debugLogA("*** Error processing thread info: %s", e.what());
}
@@ -246,7 +246,7 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc)
user.role = ROLE_FRIEND;
else
user.role = ROLE_NONE;
- }
+ }
user.loaded = true;
}
@@ -256,9 +256,6 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc)
}
}
- // if (isOffline())
- // return;
-
if (!namelessIds.empty()) {
// we have some contacts without name, let's load them all from the server
@@ -269,7 +266,7 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc)
HttpRequest *request = new UserInfoRequest(&facy, userIds);
http::response resp = facy.sendRequest(request);
-
+
FreeList(userIds);
userIds.destroy();
@@ -291,7 +288,7 @@ void FacebookProto::JoinChatrooms()
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
if (!isChatRoom(hContact))
continue;
-
+
// Ignore archived and unsubscribed chats
if (getBool(hContact, FACEBOOK_KEY_CHAT_IS_ARCHIVED, false) || !getBool(hContact, FACEBOOK_KEY_CHAT_IS_SUBSCRIBED, true))
continue;
@@ -423,8 +420,7 @@ void FacebookProto::DeleteContactFromServer(void *data)
HttpRequest *request = new DeleteFriendRequest(&facy, id.c_str());
http::response resp = facy.sendRequest(request);
- if (resp.data.find("\"payload\":null", 0) != std::string::npos)
- {
+ if (resp.data.find("\"payload\":null", 0) != std::string::npos) {
// FIXME: Remember that we deleted this contact, so we won't accidentally add him at status change
/* facebook_user* fbu = facy.buddies.find(id);
if (fbu != NULL)
@@ -502,8 +498,7 @@ void FacebookProto::ApproveContactToServer(void *data)
HttpRequest *request = new AnswerFriendshipRequest(&facy, id, AnswerFriendshipRequest::CONFIRM);
http::response resp = facy.sendRequest(request);
- if (resp.data.find("\"success\":true") != std::string::npos)
- {
+ if (resp.data.find("\"success\":true") != std::string::npos) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_FRIEND);
NotifyEvent(m_tszUserName, TranslateT("Request for friendship was accepted."), NULL, EVENT_FRIENDSHIP);
}
@@ -534,8 +529,7 @@ void FacebookProto::CancelFriendsRequest(void *data)
HttpRequest *request = new CancelFriendshipRequest(&facy, id);
http::response resp = facy.sendRequest(request);
- if (resp.data.find("\"payload\":null", 0) != std::string::npos)
- {
+ 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."), NULL, EVENT_FRIENDSHIP);
}
@@ -566,8 +560,7 @@ void FacebookProto::IgnoreFriendshipRequest(void *data)
HttpRequest *request = new AnswerFriendshipRequest(&facy, id, AnswerFriendshipRequest::REJECT);
http::response resp = facy.sendRequest(request);
- if (resp.data.find("\"success\":true") != std::string::npos)
- {
+ if (resp.data.find("\"success\":true") != std::string::npos) {
setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
NotifyEvent(m_tszUserName, TranslateT("Request for friendship was ignored."), NULL, EVENT_FRIENDSHIP);
@@ -633,7 +626,7 @@ void FacebookProto::RefreshUserInfo(void *data)
ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, (HANDLE)nullptr, 0);
return;
}
-
+
facebook_user fbu;
fbu.user_id = user_id;
@@ -730,12 +723,12 @@ int FacebookProto::OnContactDeleted(WPARAM wParam, LPARAM)
// Cancel friendship (with confirmation)
CancelFriendship(hContact, 1);
-
return 0;
}
-void FacebookProto::StartTyping(MCONTACT hContact) {
+void FacebookProto::StartTyping(MCONTACT hContact)
+{
// ignore if contact is already typing
if (facy.typers.find(hContact) != facy.typers.end())
return;
@@ -745,7 +738,8 @@ void FacebookProto::StartTyping(MCONTACT hContact) {
facy.typers.insert(hContact);
}
-void FacebookProto::StopTyping(MCONTACT hContact) {
+void FacebookProto::StopTyping(MCONTACT hContact)
+{
// ignore if contact is not typing
if (facy.typers.find(hContact) == facy.typers.end())
return;
@@ -753,4 +747,4 @@ void FacebookProto::StopTyping(MCONTACT hContact) {
// show notification and remove from typing set
CallService(MS_PROTO_CONTACTISTYPING, hContact, (LPARAM)PROTOTYPE_CONTACTTYPING_OFF);
facy.typers.erase(hContact);
-} \ No newline at end of file
+}
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp
index b6c0318689..0331ce0bd7 100644
--- a/protocols/FacebookRM/src/dialogs.cpp
+++ b/protocols/FacebookRM/src/dialogs.cpp
@@ -40,42 +40,37 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
{
FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- switch (message)
- {
+ switch (message) {
case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwnd);
+ {
+ TranslateDialogDefault(hwnd);
- proto = reinterpret_cast<FacebookProto*>(lparam);
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
+ proto = reinterpret_cast<FacebookProto*>(lparam);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
- ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
- if (login != NULL)
- SetDlgItemTextA(hwnd, IDC_UN, login);
+ ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
+ if (login != NULL)
+ SetDlgItemTextA(hwnd, IDC_UN, login);
- ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
- if (password != NULL)
- SetDlgItemTextA(hwnd, IDC_PW, password);
+ ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
+ if (password != NULL)
+ SetDlgItemTextA(hwnd, IDC_PW, password);
- if (!proto->isOffline())
- {
- SendDlgItemMessage(hwnd, IDC_UN, EM_SETREADONLY, 1, 0);
- SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, 1, 0);
+ if (!proto->isOffline()) {
+ SendDlgItemMessage(hwnd, IDC_UN, EM_SETREADONLY, 1, 0);
+ SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, 1, 0);
+ }
+ return TRUE;
}
- return TRUE;
- }
case WM_COMMAND:
- if (LOWORD(wparam) == IDC_NEWACCOUNTLINK)
- {
+ if (LOWORD(wparam) == IDC_NEWACCOUNTLINK) {
proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
return TRUE;
}
- if (HIWORD(wparam) == EN_CHANGE && reinterpret_cast<HWND>(lparam) == GetFocus())
- {
- switch (LOWORD(wparam))
- {
+ if (HIWORD(wparam) == EN_CHANGE && reinterpret_cast<HWND>(lparam) == GetFocus()) {
+ switch (LOWORD(wparam)) {
case IDC_UN:
case IDC_PW:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
@@ -84,8 +79,7 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
break;
case WM_NOTIFY:
- if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
- {
+ if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY) {
char str[128];
GetDlgItemTextA(hwnd, IDC_UN, str, _countof(str));
@@ -122,8 +116,7 @@ void ClistPrepare(FacebookProto *proto, MCONTACT hItem, HWND hwndList)
if (hItem == NULL)
hItem = (MCONTACT)::SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0);
- while (hItem)
- {
+ while (hItem) {
MCONTACT hItemN = (MCONTACT)::SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_NEXT, (LPARAM)hItem);
if (IsHContactGroup(hItem)) {
@@ -170,7 +163,8 @@ void GetSelectedContacts(FacebookProto *proto, MCONTACT hItem, HWND hwndList, st
}
}
-void ResizeHorizontal(HWND hwnd, bool wide) {
+void ResizeHorizontal(HWND hwnd, bool wide)
+{
RECT r = { 0, 0, wide ? 422 : 271, 116 };
MapDialogRect(hwnd, &r);
r.bottom += GetSystemMetrics(SM_CYSMCAPTION);
@@ -186,64 +180,62 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
{
post_status_data *data;
- switch (message)
- {
+ switch (message) {
case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwnd);
+ {
+ TranslateDialogDefault(hwnd);
- Window_SetIcon_IcoLib(hwnd, GetIconHandle("mind"));
+ Window_SetIcon_IcoLib(hwnd, GetIconHandle("mind"));
- data = reinterpret_cast<post_status_data*>(lparam);
+ data = reinterpret_cast<post_status_data*>(lparam);
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
- SendDlgItemMessage(hwnd, IDC_MINDMSG, EM_LIMITTEXT, FACEBOOK_MIND_LIMIT, 0);
- SendDlgItemMessage(hwnd, IDC_URL, EM_LIMITTEXT, 1024, 0);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
+ SendDlgItemMessage(hwnd, IDC_MINDMSG, EM_LIMITTEXT, FACEBOOK_MIND_LIMIT, 0);
+ SendDlgItemMessage(hwnd, IDC_URL, EM_LIMITTEXT, 1024, 0);
- ptrW place(data->proto->getWStringA(FACEBOOK_KEY_PLACE));
- SetDlgItemText(hwnd, IDC_PLACE, place != NULL ? place : L"Miranda NG");
+ ptrW place(data->proto->getWStringA(FACEBOOK_KEY_PLACE));
+ SetDlgItemText(hwnd, IDC_PLACE, place != NULL ? place : L"Miranda NG");
- bShowContacts = data->proto->getByte("PostStatusExpand", 0) > 0;
- ResizeHorizontal(hwnd, bShowContacts);
+ bShowContacts = data->proto->getByte("PostStatusExpand", 0) > 0;
+ ResizeHorizontal(hwnd, bShowContacts);
- HWND hwndClist = GetDlgItem(hwnd, IDC_CCLIST);
- SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) & ~CLS_HIDEOFFLINE);
+ HWND hwndClist = GetDlgItem(hwnd, IDC_CCLIST);
+ SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) & ~CLS_HIDEOFFLINE);
- for (std::vector<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
- SendDlgItemMessage(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(data->walls[i]->title));
- SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, 0, 0);
- SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, data->proto->getByte(FACEBOOK_KEY_LAST_WALL, 0), 0);
- RefreshPrivacy(hwnd, data);
+ for (std::vector<wall_data*>::size_type i = 0; i < data->walls.size(); i++)
+ SendDlgItemMessage(hwnd, IDC_WALL, CB_INSERTSTRING, i, reinterpret_cast<LPARAM>(data->walls[i]->title));
+ SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, 0, 0);
+ SendDlgItemMessage(hwnd, IDC_WALL, CB_SETCURSEL, data->proto->getByte(FACEBOOK_KEY_LAST_WALL, 0), 0);
+ RefreshPrivacy(hwnd, data);
- ptrA firstname(data->proto->getStringA(FACEBOOK_KEY_FIRST_NAME));
- if (firstname != NULL) {
- char title[100];
- mir_snprintf(title, Translate("What's on your mind, %s?"), firstname);
- SetWindowTextA(hwnd, title);
+ ptrA firstname(data->proto->getStringA(FACEBOOK_KEY_FIRST_NAME));
+ if (firstname != NULL) {
+ char title[100];
+ mir_snprintf(title, Translate("What's on your mind, %s?"), firstname);
+ SetWindowTextA(hwnd, title);
+ }
}
- }
- EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
- return TRUE;
+ EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
+ return TRUE;
case WM_NOTIFY:
- {
- NMCLISTCONTROL *nmc = (NMCLISTCONTROL *)lparam;
- if (nmc->hdr.idFrom == IDC_CCLIST) {
- switch (nmc->hdr.code) {
- case CLN_LISTREBUILT:
- data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- ClistPrepare(data->proto, NULL, nmc->hdr.hwndFrom);
- break;
+ {
+ NMCLISTCONTROL *nmc = (NMCLISTCONTROL *)lparam;
+ if (nmc->hdr.idFrom == IDC_CCLIST) {
+ switch (nmc->hdr.code) {
+ case CLN_LISTREBUILT:
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ ClistPrepare(data->proto, NULL, nmc->hdr.hwndFrom);
+ break;
+ }
}
}
- }
- break;
+ break;
case WM_COMMAND:
- switch (LOWORD(wparam))
- {
+ switch (LOWORD(wparam)) {
case IDC_WALL:
if (HIWORD(wparam) == CBN_SELCHANGE) {
data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
@@ -269,59 +261,60 @@ INT_PTR CALLBACK FBMindProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lpara
break;
case IDOK:
- {
- data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ {
+ data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- wchar_t mindMessageT[FACEBOOK_MIND_LIMIT + 1];
- wchar_t urlT[1024];
- wchar_t placeT[100];
+ wchar_t mindMessageT[FACEBOOK_MIND_LIMIT + 1];
+ wchar_t urlT[1024];
+ wchar_t placeT[100];
- GetDlgItemText(hwnd, IDC_MINDMSG, mindMessageT, _countof(mindMessageT));
- GetDlgItemText(hwnd, IDC_PLACE, placeT, _countof(placeT));
- GetDlgItemText(hwnd, IDC_URL, urlT, _countof(urlT));
- ShowWindow(hwnd, SW_HIDE);
+ GetDlgItemText(hwnd, IDC_MINDMSG, mindMessageT, _countof(mindMessageT));
+ GetDlgItemText(hwnd, IDC_PLACE, placeT, _countof(placeT));
+ GetDlgItemText(hwnd, IDC_URL, urlT, _countof(urlT));
+ ShowWindow(hwnd, SW_HIDE);
- int wall_id = SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0);
- int privacy_id = SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0);
+ int wall_id = SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCURSEL, 0, 0);
+ int privacy_id = SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCURSEL, 0, 0);
- data->proto->setWString(FACEBOOK_KEY_PLACE, placeT);
- data->proto->setByte("PostStatusExpand", bShowContacts);
+ data->proto->setWString(FACEBOOK_KEY_PLACE, placeT);
+ data->proto->setByte("PostStatusExpand", bShowContacts);
- // remember last wall, only when there are more options
- if (SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCOUNT, 0, 0) > 1)
- data->proto->setByte(FACEBOOK_KEY_LAST_WALL, wall_id);
+ // remember last wall, only when there are more options
+ if (SendDlgItemMessage(hwnd, IDC_WALL, CB_GETCOUNT, 0, 0) > 1)
+ data->proto->setByte(FACEBOOK_KEY_LAST_WALL, wall_id);
- // remember last privacy, only when there are more options
- if (SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCOUNT, 0, 0) > 1)
- data->proto->setByte(FACEBOOK_KEY_PRIVACY_TYPE, privacy_id);
+ // remember last privacy, only when there are more options
+ if (SendDlgItemMessage(hwnd, IDC_PRIVACY, CB_GETCOUNT, 0, 0) > 1)
+ data->proto->setByte(FACEBOOK_KEY_PRIVACY_TYPE, privacy_id);
- status_data *status = new status_data();
- status->user_id = data->walls[wall_id]->user_id;
- status->isPage = data->walls[wall_id]->isPage;
- status->privacy = privacy_types[privacy_id].id;
- status->place = T2Utf(placeT);
- status->url = _T2A(urlT);
+ status_data *status = new status_data();
+ status->user_id = data->walls[wall_id]->user_id;
+ status->isPage = data->walls[wall_id]->isPage;
+ status->privacy = privacy_types[privacy_id].id;
+ status->place = T2Utf(placeT);
+ status->url = _T2A(urlT);
- HWND hwndList = GetDlgItem(hwnd, IDC_CCLIST);
- GetSelectedContacts(data->proto, NULL, hwndList, &status->users);
+ HWND hwndList = GetDlgItem(hwnd, IDC_CCLIST);
+ GetSelectedContacts(data->proto, NULL, hwndList, &status->users);
- T2Utf narrow(mindMessageT);
- status->text = narrow;
+ T2Utf narrow(mindMessageT);
+ status->text = narrow;
- if (status->user_id == data->proto->facy.self_.user_id && data->proto->last_status_msg_ != (char*)narrow)
- data->proto->last_status_msg_ = narrow;
+ if (status->user_id == data->proto->facy.self_.user_id && data->proto->last_status_msg_ != (char*)narrow)
+ data->proto->last_status_msg_ = narrow;
- data->proto->ForkThread(&FacebookProto::SetAwayMsgWorker, status);
+ data->proto->ForkThread(&FacebookProto::SetAwayMsgWorker, status);
- EndDialog(hwnd, wparam);
- return TRUE;
- }
+ EndDialog(hwnd, wparam);
+ return TRUE;
+ }
case IDCANCEL:
EndDialog(hwnd, wparam);
return TRUE;
-
- } break;
+ }
+ break;
+
case WM_DESTROY:
data = reinterpret_cast<post_status_data*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
@@ -340,62 +333,60 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
{
FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- switch (message)
- {
-
+ switch (message) {
case WM_INITDIALOG:
- {
- TranslateDialogDefault(hwnd);
-
- proto = reinterpret_cast<FacebookProto*>(lparam);
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
+ {
+ TranslateDialogDefault(hwnd);
- ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
- if (login != NULL)
- SetDlgItemTextA(hwnd, IDC_UN, login);
+ proto = reinterpret_cast<FacebookProto*>(lparam);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam);
- ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
- if (password != NULL)
- SetDlgItemTextA(hwnd, IDC_PW, password);
+ ptrA login(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_LOGIN));
+ if (login != NULL)
+ SetDlgItemTextA(hwnd, IDC_UN, login);
- if (!proto->isOffline()) {
- SendDlgItemMessage(hwnd, IDC_UN, EM_SETREADONLY, TRUE, 0);
- SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, TRUE, 0);
- }
+ ptrA password(db_get_sa(NULL, proto->ModuleName(), FACEBOOK_KEY_PASS));
+ if (password != NULL)
+ SetDlgItemTextA(hwnd, IDC_PW, password);
- SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, FACEBOOK_GROUP_NAME_LIMIT, 0);
+ if (!proto->isOffline()) {
+ SendDlgItemMessage(hwnd, IDC_UN, EM_SETREADONLY, TRUE, 0);
+ SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, TRUE, 0);
+ }
- if (proto->m_tszDefaultGroup != NULL)
- SetDlgItemText(hwnd, IDC_GROUP, proto->m_tszDefaultGroup);
+ SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, FACEBOOK_GROUP_NAME_LIMIT, 0);
- LoadDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, DEFAULT_DISABLE_STATUS_NOTIFY);
- LoadDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS);
- LoadDBCheckState(proto, hwnd, IDC_NAME_AS_NICK, FACEBOOK_KEY_NAME_AS_NICK, DEFAULT_NAME_AS_NICK);
- LoadDBCheckState(proto, hwnd, IDC_LOAD_ALL_CONTACTS, FACEBOOK_KEY_LOAD_ALL_CONTACTS, DEFAULT_LOAD_ALL_CONTACTS);
- LoadDBCheckState(proto, hwnd, IDC_PAGES_ALWAYS_ONLINE, FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE);
+ if (proto->m_tszDefaultGroup != NULL)
+ SetDlgItemText(hwnd, IDC_GROUP, proto->m_tszDefaultGroup);
- } return TRUE;
+ LoadDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY, DEFAULT_DISABLE_STATUS_NOTIFY);
+ LoadDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS);
+ LoadDBCheckState(proto, hwnd, IDC_NAME_AS_NICK, FACEBOOK_KEY_NAME_AS_NICK, DEFAULT_NAME_AS_NICK);
+ LoadDBCheckState(proto, hwnd, IDC_LOAD_ALL_CONTACTS, FACEBOOK_KEY_LOAD_ALL_CONTACTS, DEFAULT_LOAD_ALL_CONTACTS);
+ LoadDBCheckState(proto, hwnd, IDC_PAGES_ALWAYS_ONLINE, FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE);
+ }
+ return TRUE;
case WM_COMMAND:
- {
- switch (LOWORD(wparam)) {
- case IDC_NEWACCOUNTLINK:
- proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
- return TRUE;
- case IDC_UN:
- case IDC_PW:
- case IDC_GROUP:
- if (HIWORD(wparam) == EN_CHANGE && (HWND)lparam == GetFocus())
+ {
+ switch (LOWORD(wparam)) {
+ case IDC_NEWACCOUNTLINK:
+ proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
+ return TRUE;
+ case IDC_UN:
+ case IDC_PW:
+ case IDC_GROUP:
+ if (HIWORD(wparam) == EN_CHANGE && (HWND)lparam == GetFocus())
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
+ default:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
- default:
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ }
}
- } break;
+ break;
case WM_NOTIFY:
- if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
- {
+ if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY) {
char str[128]; wchar_t tstr[128];
GetDlgItemTextA(hwnd, IDC_UN, str, _countof(str));
@@ -405,8 +396,7 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
proto->setString(FACEBOOK_KEY_PASS, str);
GetDlgItemText(hwnd, IDC_GROUP, tstr, _countof(tstr));
- if (tstr[0] != '\0')
- {
+ if (tstr[0] != '\0') {
proto->m_tszDefaultGroup = mir_wstrdup(tstr);
proto->setWString(FACEBOOK_KEY_DEF_GROUP, tstr);
Clist_GroupCreate(0, tstr);
@@ -414,18 +404,16 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp
else {
proto->delSetting(FACEBOOK_KEY_DEF_GROUP);
proto->m_tszDefaultGroup = nullptr;
- }
+ }
StoreDBCheckState(proto, hwnd, IDC_SET_IGNORE_STATUS, FACEBOOK_KEY_DISABLE_STATUS_NOTIFY);
StoreDBCheckState(proto, hwnd, IDC_BIGGER_AVATARS, FACEBOOK_KEY_BIG_AVATARS);
StoreDBCheckState(proto, hwnd, IDC_NAME_AS_NICK, FACEBOOK_KEY_NAME_AS_NICK);
StoreDBCheckState(proto, hwnd, IDC_LOAD_ALL_CONTACTS, FACEBOOK_KEY_LOAD_ALL_CONTACTS);
StoreDBCheckState(proto, hwnd, IDC_PAGES_ALWAYS_ONLINE, FACEBOOK_KEY_PAGES_ALWAYS_ONLINE);
-
return TRUE;
}
break;
-
}
return FALSE;
@@ -435,11 +423,8 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
{
FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- switch (message)
- {
-
+ switch (message) {
case WM_INITDIALOG:
- {
TranslateDialogDefault(hwnd);
proto = reinterpret_cast<FacebookProto*>(lparam);
@@ -450,22 +435,19 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
LoadDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES, DEFAULT_MAP_STATUSES);
LoadDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES, DEFAULT_LOAD_PAGES);
LoadDBCheckState(proto, hwnd, IDC_TYPING_WHEN_INVISIBLE, FACEBOOK_KEY_TYPING_WHEN_INVISIBLE, DEFAULT_TYPING_WHEN_INVISIBLE);
-
return TRUE;
- }
case WM_COMMAND: {
- //switch (LOWORD(wparam)) {
- //default:
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- break;
- //}
- //break;
- }
+ //switch (LOWORD(wparam)) {
+ //default:
+ SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
+ break;
+ //}
+ //break;
+ }
case WM_NOTIFY:
- if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
- {
+ if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY) {
StoreDBCheckState(proto, hwnd, IDC_DISCONNECT_CHAT, FACEBOOK_KEY_DISCONNECT_CHAT);
StoreDBCheckState(proto, hwnd, IDC_MAP_STATUSES, FACEBOOK_KEY_MAP_STATUSES);
StoreDBCheckState(proto, hwnd, IDC_LOAD_PAGES, FACEBOOK_KEY_LOAD_PAGES);
@@ -473,8 +455,7 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
BOOL setStatus = IsDlgButtonChecked(hwnd, IDC_SET_STATUS);
BOOL setStatusOld = proto->getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, DEFAULT_SET_MIRANDA_STATUS);
- if (setStatus != setStatusOld)
- {
+ if (setStatus != setStatusOld) {
proto->setByte(FACEBOOK_KEY_SET_MIRANDA_STATUS, setStatus);
if (setStatus && proto->isOnline())
proto->ForkThread(&FacebookProto::SetAwayMsgWorker, nullptr);
@@ -489,16 +470,12 @@ INT_PTR CALLBACK FBOptionsStatusesProc(HWND hwnd, UINT message, WPARAM, LPARAM l
return FALSE;
}
-
INT_PTR CALLBACK FBOptionsEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- switch (message)
- {
-
+ switch (message) {
case WM_INITDIALOG:
- {
TranslateDialogDefault(hwnd);
proto = reinterpret_cast<FacebookProto*>(lparam);
@@ -521,12 +498,10 @@ INT_PTR CALLBACK FBOptionsEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPA
LoadDBCheckState(proto, hwnd, IDC_TICKER_ENABLE, FACEBOOK_KEY_EVENT_TICKER_ENABLE, DEFAULT_EVENT_TICKER_ENABLE);
LoadDBCheckState(proto, hwnd, IDC_ON_THIS_DAY_ENABLE, FACEBOOK_KEY_EVENT_ON_THIS_DAY_ENABLE, DEFAULT_EVENT_ON_THIS_DAY_ENABLE);
LoadDBCheckState(proto, hwnd, IDC_FILTER_ADS, FACEBOOK_KEY_FILTER_ADS, DEFAULT_FILTER_ADS);
-
- } return TRUE;
+ return TRUE;
case WM_COMMAND:
- switch (LOWORD(wparam))
- {
+ switch (LOWORD(wparam)) {
case IDC_FEED_TYPE:
case IDC_URL_SERVER:
if (HIWORD(wparam) == CBN_SELCHANGE)
@@ -538,9 +513,7 @@ INT_PTR CALLBACK FBOptionsEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPA
return TRUE;
case WM_NOTIFY:
- {
- if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
- {
+ if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY) {
proto->setByte(FACEBOOK_KEY_FEED_TYPE, SendDlgItemMessage(hwnd, IDC_FEED_TYPE, CB_GETCURSEL, 0, 0));
proto->setByte(FACEBOOK_KEY_SERVER_TYPE, SendDlgItemMessage(hwnd, IDC_URL_SERVER, CB_GETCURSEL, 0, 0));
@@ -554,8 +527,7 @@ INT_PTR CALLBACK FBOptionsEventsProc(HWND hwnd, UINT message, WPARAM wparam, LPA
StoreDBCheckState(proto, hwnd, IDC_ON_THIS_DAY_ENABLE, FACEBOOK_KEY_EVENT_ON_THIS_DAY_ENABLE);
StoreDBCheckState(proto, hwnd, IDC_FILTER_ADS, FACEBOOK_KEY_FILTER_ADS);
}
- } return TRUE;
-
+ return TRUE;
}
return FALSE;
@@ -565,11 +537,9 @@ INT_PTR CALLBACK FBOptionsMessagingProc(HWND hwnd, UINT message, WPARAM wparam,
{
FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
- switch (message)
- {
+ switch (message) {
case WM_INITDIALOG:
- {
TranslateDialogDefault(hwnd);
proto = reinterpret_cast<FacebookProto*>(lparam);
@@ -582,19 +552,17 @@ INT_PTR CALLBACK FBOptionsMessagingProc(HWND hwnd, UINT message, WPARAM wparam,
LoadDBCheckState(proto, hwnd, IDC_ENABLE_CHATS, FACEBOOK_KEY_ENABLE_CHATS, DEFAULT_ENABLE_CHATS);
LoadDBCheckState(proto, hwnd, IDC_HIDE_CHATS, FACEBOOK_KEY_HIDE_CHATS, DEFAULT_HIDE_CHATS);
LoadDBCheckState(proto, hwnd, IDC_JOIN_EXISTING_CHATS, FACEBOOK_KEY_JOIN_EXISTING_CHATS, DEFAULT_JOIN_EXISTING_CHATS);
-
- int count = proto->getByte(FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT, 10);
- count = min(count, FACEBOOK_MESSAGES_ON_OPEN_LIMIT);
- SetDlgItemInt(hwnd, IDC_MESSAGES_COUNT, count, TRUE);
-
+ {
+ int count = proto->getByte(FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT, 10);
+ count = min(count, FACEBOOK_MESSAGES_ON_OPEN_LIMIT);
+ SetDlgItemInt(hwnd, IDC_MESSAGES_COUNT, count, TRUE);
+ }
SendDlgItemMessage(hwnd, IDC_MESSAGES_COUNT, EM_LIMITTEXT, 2, 0);
SendDlgItemMessage(hwnd, IDC_MESSAGES_COUNT_SPIN, UDM_SETRANGE32, 1, 99);
-
- } return TRUE;
+ return TRUE;
case WM_COMMAND:
- switch (LOWORD(wparam))
- {
+ switch (LOWORD(wparam)) {
case IDC_MESSAGES_COUNT:
if (HIWORD(wparam) == EN_CHANGE && (HWND)lparam == GetFocus())
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
@@ -605,9 +573,7 @@ INT_PTR CALLBACK FBOptionsMessagingProc(HWND hwnd, UINT message, WPARAM wparam,
return TRUE;
case WM_NOTIFY:
- {
- if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
- {
+ if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY) {
StoreDBCheckState(proto, hwnd, IDC_CUSTOM_SMILEYS, FACEBOOK_KEY_CUSTOM_SMILEYS);
StoreDBCheckState(proto, hwnd, IDC_KEEP_UNREAD, FACEBOOK_KEY_KEEP_UNREAD);
StoreDBCheckState(proto, hwnd, IDC_MESSAGES_ON_OPEN, FACEBOOK_KEY_MESSAGES_ON_OPEN);
@@ -620,8 +586,7 @@ INT_PTR CALLBACK FBOptionsMessagingProc(HWND hwnd, UINT message, WPARAM wparam,
count = min(count, FACEBOOK_MESSAGES_ON_OPEN_LIMIT);
proto->setByte(FACEBOOK_KEY_MESSAGES_ON_OPEN_COUNT, count);
}
- } return TRUE;
-
+ return TRUE;
}
return FALSE;
diff --git a/protocols/FacebookRM/src/events.cpp b/protocols/FacebookRM/src/events.cpp
index 56972e30c6..a0552d1e54 100644
--- a/protocols/FacebookRM/src/events.cpp
+++ b/protocols/FacebookRM/src/events.cpp
@@ -29,8 +29,7 @@ HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact,
char name[256];
- switch (type)
- {
+ switch (type) {
case EVENT_CLIENT:
mir_snprintf(name, "%s_%s", m_szModuleName, "Client");
break;
@@ -60,12 +59,11 @@ HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact,
break;
case EVENT_ON_THIS_DAY:
- mir_snprintf(name, "%s_%s", m_szModuleName, "Memories");
+ mir_snprintf(name, "%s_%s", m_szModuleName, "Memories");
break;
}
- if (!getByte(FACEBOOK_KEY_SYSTRAY_NOTIFY, DEFAULT_SYSTRAY_NOTIFY))
- {
+ if (!getByte(FACEBOOK_KEY_SYSTRAY_NOTIFY, DEFAULT_SYSTRAY_NOTIFY)) {
if (ServiceExists(MS_POPUP_ADDPOPUPCLASS)) {
// TODO: if popup with particular ID is already showed, just update his content
diff --git a/protocols/FacebookRM/src/http_request.h b/protocols/FacebookRM/src/http_request.h
index 1d025f1501..39c031ea04 100644
--- a/protocols/FacebookRM/src/http_request.h
+++ b/protocols/FacebookRM/src/http_request.h
@@ -21,28 +21,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
struct VALUE
{
LPCSTR szName;
- __forceinline VALUE(LPCSTR _name) : szName(_name) { }
+ __forceinline VALUE(LPCSTR _name) : szName(_name) {}
};
struct INT_VALUE : public VALUE
{
int iValue;
__forceinline INT_VALUE(LPCSTR _name, int _value)
- : VALUE(_name), iValue(_value) { }
+ : VALUE(_name), iValue(_value)
+ {}
};
struct LONG_VALUE : public VALUE
{
LONGLONG llValue;
__forceinline LONG_VALUE(LPCSTR _name, LONGLONG _value)
- : VALUE(_name), llValue(_value) { }
+ : VALUE(_name), llValue(_value)
+ {}
};
struct CHAR_VALUE : public VALUE
{
LPCSTR szValue;
__forceinline CHAR_VALUE(LPCSTR _name, LPCSTR _value)
- : VALUE(_name), szValue(_value) { }
+ : VALUE(_name), szValue(_value)
+ {}
};
struct FORMAT_VALUE : public VALUE
@@ -73,7 +76,7 @@ protected:
friend HttpRequest;
private:
- HttpRequest &request;
+ HttpRequest & request;
HttpRequestUrl(HttpRequest &request, const char *url) : request(request)
{
@@ -90,7 +93,7 @@ protected:
HttpRequestUrl& operator=(const HttpRequestUrl&); // to prevent copying;
public:
- HttpRequestUrl &operator<<(const VALUE &param)
+ HttpRequestUrl & operator<<(const VALUE &param)
{
request.AddUrlParameter(param.szName);
return *this;
@@ -141,7 +144,7 @@ protected:
}
public:
- HttpRequestHeaders(HttpRequest &request) : request(request) { }
+ HttpRequestHeaders(HttpRequest &request) : request(request) {}
HttpRequestHeaders& operator<<(const VALUE &param)
{
@@ -169,14 +172,13 @@ protected:
void AppendSeparator()
{
- if (!content.IsEmpty())
- {
+ if (!content.IsEmpty()) {
content.AppendChar('&');
}
}
public:
- HttpRequestBody() { }
+ HttpRequestBody() {}
HttpRequestBody & operator<<(const VALUE &param)
{
@@ -213,7 +215,7 @@ protected:
return *this;
}
- char * ToString()
+ char* ToString()
{
return content.GetBuffer();
}
@@ -233,7 +235,7 @@ public:
HttpRequestUrl Url;
HttpRequestHeaders Headers;
HttpRequestBody Body;
-
+
enum PersistentType { NONE, DEFAULT, CHANNEL, MESSAGES };
bool NotifyErrors;
@@ -268,8 +270,7 @@ public:
virtual ~HttpRequest()
{
- for (int i = 0; i < headersCount; i++)
- {
+ for (int i = 0; i < headersCount; i++) {
mir_free(headers[i].szName);
mir_free(headers[i].szValue);
}
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 369e2fdafd..01beebc0e4 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -67,13 +67,14 @@ void parseUser(const JSONNode &it, facebook_user *fbu)
case 2: // male
fbu->gender = 77;
break;
- // case 7: // not available female?
- // case 11: // page
+ // case 7: // not available female?
+ // case 11: // page
}
}
}
-void FacebookProto::ParseMessageType(facebook_message &message, const JSONNode &log_type_, const JSONNode &log_body_, const JSONNode &log_data_) {
+void FacebookProto::ParseMessageType(facebook_message &message, const JSONNode &log_type_, const JSONNode &log_body_, const JSONNode &log_data_)
+{
if (!log_type_ || !log_body_ || !log_data_)
return;
@@ -263,7 +264,8 @@ bool FacebookProto::IgnoreDuplicates(const std::string &mid)
return false;
}
-std::string absolutizeUrl(std::string &url) {
+std::string absolutizeUrl(std::string &url)
+{
if (url.find("/") == 0) {
url = HTTP_PROTO_SECURE FACEBOOK_SERVER_REGULAR + url;
}
@@ -278,7 +280,7 @@ void FacebookProto::ParseAttachments(std::string &message_text, const JSONNode &
const JSONNode &attachments_ = delta_["attachments"];
if (!attachments_ || attachments_.empty())
return;
-
+
for (auto itAttachment = attachments_.begin(); itAttachment != attachments_.end(); ++itAttachment) {
const JSONNode &attach_ = legacy ? (*itAttachment) : (*itAttachment)["mercury"];
@@ -500,7 +502,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
const JSONNode &time_ = delta_["actionTimestampMs"];
if (!time_)
continue;
-
+
time_t timestamp = utils::time::from_string(time_.as_string());
// for multi chats (not available for single)
@@ -512,7 +514,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
if (actor_ && thread_) {
// multi chat
-
+
// ignore if disabled
if (!m_enableChat)
continue;
@@ -604,7 +606,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
else if (cls == "ThreadName") {
// changed thread name (multi user chat)
const JSONNode &meta_ = delta_["messageMetadata"];
-
+
const JSONNode &name_ = delta_["name"]; // new name of the chat (could be empty)
std::string data = (name_ ? name_.as_string() : "");
@@ -617,7 +619,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
else if (cls == "ParticipantLeftGroupThread") {
// user was removed from multi user chat
const JSONNode &meta_ = delta_["messageMetadata"];
-
+
const JSONNode &leftParticipantFbId_ = delta_["leftParticipantFbId"];
std::string data = (leftParticipantFbId_ ? leftParticipantFbId_.as_string() : "");
@@ -661,7 +663,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
const JSONNode &text_ = (*itNodes)["unaggregatedTitle"]; // notifications one by one, not grouped
if (!text_)
continue;
-
+
const JSONNode &text = text_["text"];
const JSONNode &url = (*itNodes)["url"];
const JSONNode &alert_id = (*itNodes)["alert_id"];
@@ -722,7 +724,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
if (!html_ || !href_ || !unread_ || unread_.as_int() == 0)
continue;
-
+
std::string text = utils::text::remove_html(utils::text::slashu_to_utf8(html_.as_string()));
std::string url = href_.as_string();
std::string alert_id = alertId_.as_string();
@@ -952,7 +954,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
if (la_ /*&& status != ID_STATUS_ONLINE*/) {
time_t last_active = utils::time::from_string(la_.as_string());
-
+
// we should set IdleTS only when contact is IDLE, or OFFLINE
//if (getDword(hContact, "IdleTS", 0) != last_active) {
// if (/*(fbu->idle || status == ID_STATUS_OFFLINE) &&*/ last_active > 0)
@@ -1002,7 +1004,8 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag
setWString(hContact, "MirVer", client);
}
}
- } else if (t == "ticker_update:home") {
+ }
+ else if (t == "ticker_update:home") {
if (!getByte(FACEBOOK_KEY_EVENT_TICKER_ENABLE, DEFAULT_EVENT_TICKER_ENABLE))
continue;
@@ -1415,7 +1418,7 @@ int FacebookProto::ParseMessagesCount(std::string *data, int *messagesCount, int
const JSONNode &message_count_ = (*it)["message_count"];
const JSONNode &unread_count_ = (*it)["unread_count"];
- if (!message_count_|| !unread_count_)
+ if (!message_count_ || !unread_count_)
return EXIT_FAILURE;
*messagesCount = message_count_.as_int();
diff --git a/protocols/FacebookRM/src/list.hpp b/protocols/FacebookRM/src/list.hpp
index 91737e750c..df63158b78 100644
--- a/protocols/FacebookRM/src/list.hpp
+++ b/protocols/FacebookRM/src/list.hpp
@@ -31,7 +31,7 @@ namespace List
T* data;
Item< T >* prev;
Item< T >* next;
-
+
Item()
{
this->data = NULL;
@@ -51,7 +51,7 @@ namespace List
Item< T >* first;
Item< T >* last;
unsigned int count;
-
+
public:
List()
{
@@ -86,11 +86,11 @@ namespace List
void insert(Item< T >* item)
{
- if (this->empty())
- {
+ if (this->empty()) {
this->first = this->last = item;
this->count = 1;
- } else { // TODO: key sorting/comparation
+ }
+ else { // TODO: key sorting/comparation
item->next = this->first;
this->first->prev = item;
this->first = item;
@@ -108,34 +108,29 @@ namespace List
void erase(std::string key)
{
Item< T >* help = this->first;
- while (help != NULL)
- {
+ while (help != NULL) {
if (help->key.compare(key) != 0)
help = help->next;
- else
- {
- if (help == this->first)
- {
+ else {
+ if (help == this->first) {
this->first = help->next;
if (this->first != NULL)
this->first->prev = NULL;
else
this->last = NULL;
}
- else if (help == this->last)
- {
+ else if (help == this->last) {
this->last = help->prev;
if (this->last != NULL)
this->last->next = NULL;
else
this->first = NULL;
}
- else
- {
+ else {
help->prev->next = help->next;
help->next->prev = help->prev;
}
- this->count--;
+ this->count--;
delete help;
break;
}
@@ -151,8 +146,7 @@ namespace List
T* find(std::string key)
{
Item< T >* help = this->begin();
- while (help != NULL)
- {
+ while (help != NULL) {
if (help->key.compare(key) != 0)
help = help->next;
else
@@ -179,12 +173,11 @@ namespace List
void clear()
{
Item< T >* help;
- while (this->first != NULL)
- {
+ while (this->first != NULL) {
help = this->first;
this->first = this->first->next;
delete help;
- }
+ }
this->last = NULL;
this->count = 0;
}
diff --git a/protocols/FacebookRM/src/main.cpp b/protocols/FacebookRM/src/main.cpp
index fbf0eef6df..880c1ffb40 100644
--- a/protocols/FacebookRM/src/main.cpp
+++ b/protocols/FacebookRM/src/main.cpp
@@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// TODO: Make following as "globals" structure?
-CLIST_INTERFACE* pcli;
+CLIST_INTERFACE *pcli;
int hLangpack;
HINSTANCE g_hInstance;
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 941f7f0327..587c55803b 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -38,30 +38,26 @@ void FacebookProto::SendMsgWorker(void *p)
ptrA id(getStringA(data->hContact, FACEBOOK_KEY_ID));
- if (!isOnline()) {
+ if (!isOnline())
ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)Translate("You cannot send messages when you are offline."));
- }
- else if (id == NULL) {
+ else if (id == NULL)
ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, 0);
- }
else {
int tries = getByte(FACEBOOK_KEY_SEND_MESSAGE_TRIES, 1);
tries = min(max(tries, 1), 5);
std::string error_text;
int result = SEND_MESSAGE_ERROR;
- while (result == SEND_MESSAGE_ERROR && tries-- > 0) {
+ while (result == SEND_MESSAGE_ERROR && tries-- > 0)
result = facy.send_message(data->msgid, data->hContact, data->msg, &error_text);
- }
+
if (result == SEND_MESSAGE_OK) {
ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)data->msgid, 0);
// Remove from "readers" list and clear statusbar
facy.erase_reader(data->hContact);
}
- else {
- ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)error_text.c_str());
- }
+ else ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, (HANDLE)data->msgid, (LPARAM)error_text.c_str());
}
delete data;
@@ -82,9 +78,8 @@ void FacebookProto::SendChatMsgWorker(void *p)
if (hContact) {
ptrA tid_(getStringA(hContact, FACEBOOK_KEY_TID));
std::string tid;
- if (tid_ != NULL && mir_strcmp(tid_, "null")) {
+ if (tid_ != NULL && mir_strcmp(tid_, "null"))
tid = tid_;
- }
else {
// request info about chat thread
HttpRequest *request = new ThreadInfoRequest(&facy, true, data->chat_id.c_str());
@@ -113,7 +108,7 @@ int FacebookProto::SendMsg(MCONTACT hContact, int, const char *msg)
{
std::string message = msg;
unsigned int msgId = InterlockedIncrement(&facy.msgid_);
-
+
ForkThread(&FacebookProto::SendMsgWorker, new send_direct(hContact, message, msgId));
return msgId;
}
@@ -187,7 +182,7 @@ void FacebookProto::ReadMessageWorker(void *p)
ids.insert(mir_strdup(id));
}
-
+
hContacts->clear();
delete hContacts;
@@ -225,6 +220,5 @@ void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url,
cont.hContact = hContact;
cont.type = 0;
cont.path = dir;
-
CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont);
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index eb856d06f3..72b18db514 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -77,18 +77,16 @@ void FacebookProto::ProcessFriendList(void*)
}
// If this contact is page, set it as invisible (if enabled in options)
- if (pagesAlwaysOnline && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_PAGE) {
+ if (pagesAlwaysOnline && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_PAGE)
setWord(hContact, "Status", ID_STATUS_INVISIBLE);
- }
- facebook_user *fbu;
ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
if (id != NULL) {
std::map< std::string, facebook_user* >::iterator iter;
if ((iter = friends.find(std::string(id))) != friends.end()) {
// Found contact, update it and remove from map
- fbu = iter->second;
+ facebook_user *fbu = iter->second;
// TODO RM: remove, because contacts cant change it, so its only for "first run"
// - but what with contacts, that was added after logon?
@@ -100,9 +98,8 @@ void FacebookProto::ProcessFriendList(void*)
delSetting(hContact, "RealName");
// Update real name and nick
- if (!fbu->real_name.empty()) {
+ if (!fbu->real_name.empty())
SaveName(hContact, fbu);
- }
// Update username
if (!fbu->username.empty())
@@ -227,12 +224,11 @@ void FacebookProto::ProcessUnreadMessage(void *pParam)
// TODO: First load info about amount of unread messages, then load exactly this amount for each thread
- while (!threads->empty()) {
-
+ while (!threads->empty()) {
+
LIST<char> ids(1);
- for (std::vector<std::string>::size_type i = 0; i < threads->size(); i++) {
+ 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);
@@ -254,9 +250,7 @@ void FacebookProto::ProcessUnreadMessage(void *pParam)
facy.handle_success("ProcessUnreadMessage");
}
- else {
- facy.handle_error("ProcessUnreadMessage");
- }
+ else facy.handle_error("ProcessUnreadMessage");
offset += limit;
limit = 20; // TODO: use better limits?
@@ -283,7 +277,6 @@ void FacebookProto::LoadLastMessages(void *pParam)
return;
bool isChat = isChatRoom(hContact);
-
if (isChat && (!m_enableChat || IsSpecialChatRoom(hContact))) // disabled chats or special chatroom (e.g. nofitications)
return;
@@ -295,7 +288,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, count);
+ HttpRequest *request = new ThreadInfoRequest(&facy, isChat, (const char*)item_id, count);
http::response resp = facy.sendRequest(request);
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
@@ -343,10 +336,8 @@ void FacebookProto::LoadHistory(void *pParam)
facy.handle_entry("LoadHistory");
bool isChat = isChatRoom(hContact);
- if (isChat) // TODO: Support chats?
+ if (isChat)
return;
- /*if (isChat && (!m_enableChat || IsSpecialChatRoom(hContact))) // disabled chats or special chatroom (e.g. nofitications)
- return;*/
ptrA item_id(getStringA(hContact, isChat ? FACEBOOK_KEY_TID : FACEBOOK_KEY_ID));
if (item_id == NULL) {
@@ -489,24 +480,23 @@ void FacebookProto::LoadHistory(void *pParam)
// Reset loading history flag
facy.loading_history = false;
- if (ServiceExists(MS_POPUP_CHANGETEXTW) && popupHwnd) {
+ if (ServiceExists(MS_POPUP_CHANGETEXTW) && popupHwnd)
PUChangeTextW(popupHwnd, TranslateT("Loading history completed."));
- } else if (ServiceExists(MS_POPUP_ADDPOPUPW)) {
+ else if (ServiceExists(MS_POPUP_ADDPOPUPW)) {
pd.iSeconds = 5;
wcsncpy(pd.lptzText, TranslateT("Loading history completed."), MAX_SECONDLINE);
popupHwnd = (HWND)CallService(MS_POPUP_ADDPOPUPW, (WPARAM)&pd, (LPARAM)0);
}
- // PUDeletePopup(popupHwnd);
}
-void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news, DWORD &last_post_time, bool filterAds = true) {
+void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news, DWORD &last_post_time, bool filterAds = true)
+{
std::string::size_type pos = 0;
UINT limit = 0;
DWORD new_time = last_post_time;
- while ((pos = text.find("fbUserPost\"", pos)) != std::string::npos && limit <= 25)
- {
+ while ((pos = text.find("fbUserPost\"", pos)) != std::string::npos && limit <= 25) {
std::string post = text.substr(pos, text.find("</form>", pos) - pos);
pos += 5;
@@ -527,40 +517,30 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
}
DWORD ttime;
- if (!utils::conversion::from_string<DWORD>(ttime, time, std::dec)) {
- //debugLogA("!!! - Newsfeed with wrong/empty time (probably wrong parsing)\n%s", post.c_str());
+ if (!utils::conversion::from_string<DWORD>(ttime, time, std::dec))
continue;
- }
- if (ttime > new_time) {
+ if (ttime > new_time)
new_time = ttime; // remember newest time from all these posts
- //debugLogA(" - Newsfeed time: %d (new)", ttime);
- }
- else if (ttime <= last_post_time) {
- //debugLogA(" - Newsfeed time: %d (ignored)", ttime);
+ else if (ttime <= last_post_time)
continue; // ignore posts older than newest post of previous check
- }
- else {
- //debugLogA(" - Newsfeed time: %d (normal)", ttime);
- }
std::string timeandloc = utils::text::trim(utils::text::html_entities_decode(utils::text::remove_html(time_text)));
std::string post_place = utils::text::source_get_value(&post, 4, "</abbr>", "<a", ">", "</a>");
post_place = utils::text::trim(utils::text::remove_html(post_place));
- if (!post_place.empty()) {
+ if (!post_place.empty())
timeandloc += " ยท " + post_place;
- }
// in title keep only name, end of events like "X shared link" put into message
std::string::size_type pos2 = post_header.find("</a>");
std::string header_author = utils::text::trim(
utils::text::html_entities_decode(
- utils::text::remove_html(
- post_header.substr(0, pos2))));
+ utils::text::remove_html(
+ post_header.substr(0, pos2))));
std::string header_rest = utils::text::trim(
utils::text::html_entities_decode(
- utils::text::remove_html(
- post_header.substr(pos2, post_header.length() - pos2))));
+ utils::text::remove_html(
+ post_header.substr(pos2, post_header.length() - pos2))));
// Strip "Translate" and other buttons
do {
@@ -570,9 +550,9 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
if (pos2 != std::string::npos) {
std::string::size_type pos3 = post_message.find("</a>", pos2);
std::string tmp = post_message.substr(0, pos2);
- if (pos3 != std::string::npos) {
+ if (pos3 != std::string::npos)
tmp += post_message.substr(pos3, post_message.length() - pos3);
- }
+
post_message = tmp;
}
}
@@ -580,9 +560,8 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
// Strip "See more" link
pos2 = post_message.find("<span class=\"see_more_link_inner\">");
- if (pos2 != std::string::npos) {
+ if (pos2 != std::string::npos)
post_message = post_message.substr(0, pos2);
- }
// Process attachment (if present)
std::string post_attachment = "";
@@ -598,19 +577,15 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
post_attachment = utils::text::trim(
utils::text::html_entities_decode(
- utils::text::remove_html(post_attachment)));
+ utils::text::remove_html(post_attachment)));
post_attachment = utils::text::truncate_utf8(post_attachment, MAX_LINK_DESCRIPTION_LEN);
- if (post_attachment.empty()) {
- // This is some textless attachment, so mention it
+ if (post_attachment.empty()) // This is some textless attachment, so mention it
post_attachment = ptrA(mir_utf8encode(Translate("<attachment without text>")));
- }
}
- post_message = utils::text::trim(
- utils::text::html_entities_decode(
- utils::text::remove_html(post_message)));
+ post_message = utils::text::trim(utils::text::html_entities_decode(utils::text::remove_html(post_message)));
// Truncate text of newsfeed when it's too long
post_message = utils::text::truncate_utf8(post_message, MAX_NEWSFEED_LEN);
@@ -628,9 +603,7 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
facebook_newsfeed* nf = new facebook_newsfeed;
nf->title = header_author;
-
nf->user_id = utils::text::source_get_value(&post_header, 2, "user.php?id=", "&amp;");
-
nf->link = utils::text::html_entities_decode(post_link);
// Check if we don't want to show ads posts
@@ -641,13 +614,9 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
nf->text = utils::text::trim(content);
if (filtered || nf->title.empty() || nf->text.empty()) {
- //debugLogA(" \\ Newsfeed (time: %d) is filtered: %s", ttime, filtered ? "advertisement" : (nf->title.empty() ? "title empty" : "text empty"));
delete nf;
continue;
}
- else {
- //debugLogA(" Got newsfeed (time: %d)", ttime);
- }
news.push_back(nf);
pos++;
@@ -663,9 +632,8 @@ void FacebookProto::ProcessMemories(void *p)
return;
bool manuallyTriggered = (p == MANUALLY_TRIGGERED);
- if (manuallyTriggered) {
+ if (manuallyTriggered)
facy.info_notify(TranslateT("Loading memories..."));
- }
size_t numMemories = 0;
@@ -690,14 +658,12 @@ void FacebookProto::ProcessMemories(void *p)
DWORD new_time = 0;
parseFeeds(html, news, new_time, true);
- if (!news.empty()) {
+ if (!news.empty())
Skin_PlaySound("Memories");
- }
numMemories = news.size();
- for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++)
- {
+ for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++) {
ptrW tszTitle(mir_utf8decodeW(news[i]->title.c_str()));
ptrW tszText(mir_utf8decodeW(news[i]->text.c_str()));
@@ -771,9 +737,8 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
std::string thread_id = msg.thread_id.c_str();
auto it = facy.chat_rooms.find(thread_id);
- if (it != facy.chat_rooms.end()) {
+ if (it != facy.chat_rooms.end())
fbc = it->second;
- }
else {
// In Naseem's spam mode we ignore outgoing messages sent from other instances
if (naseemsSpamMode && !msg.isIncoming)
@@ -795,9 +760,8 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
// Set thread id (TID) for later
setString(hChatContact, FACEBOOK_KEY_TID, fbc->thread_id.c_str());
- for (auto jt = fbc->participants.begin(); jt != fbc->participants.end(); ++jt) {
+ for (auto jt = fbc->participants.begin(); jt != fbc->participants.end(); ++jt)
AddChatContact(fbc->thread_id.c_str(), jt->second, false);
- }
}
if (!hChatContact)
@@ -820,9 +784,8 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
std::string name = msg.user_id; // fallback to numeric id
{
auto jt = fbc->participants.find(msg.user_id);
- if (jt != fbc->participants.end()) {
+ if (jt != fbc->participants.end())
name = jt->second.nick;
- }
}
switch (msg.type) {
@@ -861,14 +824,17 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo
}
}
break;
- case THREAD_NAME: {
- UpdateChat(thread_id.c_str(), nullptr, nullptr, msg.message_text.c_str());
+
+ case THREAD_NAME:
+ {
+ UpdateChat(thread_id.c_str(), nullptr, nullptr, msg.message_text.c_str());
- std::string chatName = (!msg.data.empty() ? msg.data : GenerateChatName(fbc));
- // proto->RenameChat(thread_id.c_str(), chatName.c_str()); // this don't work, why?
- setStringUtf(hChatContact, FACEBOOK_KEY_NICK, chatName.c_str());
+ std::string chatName = (!msg.data.empty() ? msg.data : GenerateChatName(fbc));
+ // proto->RenameChat(thread_id.c_str(), chatName.c_str()); // this don't work, why?
+ setStringUtf(hChatContact, FACEBOOK_KEY_NICK, chatName.c_str());
+ }
break;
- }
+
case THREAD_IMAGE:
UpdateChat(thread_id.c_str(), nullptr, nullptr, msg.message_text.c_str());
break;
@@ -984,7 +950,8 @@ void FacebookProto::ProcessMessages(void* data)
delete resp;
}
-void FacebookProto::ShowNotifications() {
+void FacebookProto::ShowNotifications()
+{
ScopedLock s(facy.notifications_lock_);
// Show popups for unseen notifications and/or write them to chatroom
@@ -1050,9 +1017,8 @@ void FacebookProto::ProcessFriendRequests(void *p)
return;
bool manuallyTriggered = (p == MANUALLY_TRIGGERED);
- if (manuallyTriggered) {
+ if (manuallyTriggered)
facy.info_notify(TranslateT("Loading friendship requests..."));
- }
facy.handle_entry("friendRequests");
@@ -1086,11 +1052,12 @@ void FacebookProto::ProcessFriendRequests(void *p)
if ((pos2 = reqs.find("</table>", pos)) != std::string::npos) {
req = reqs.substr(pos, pos2 - pos);
pos = pos2 + 8;
- } else {
+ }
+ else {
req = reqs.substr(pos);
last = true;
}
-
+
std::string get = utils::text::source_get_value(&req, 2, "notifications.php?", "\"");
std::string time = utils::text::source_get_value2(&get, "seenrequesttime=", "&\"");
std::string reason = utils::text::remove_html(utils::text::source_get_value(&req, 4, "</a>", "<div", ">", "</div>"));
@@ -1150,16 +1117,14 @@ void FacebookProto::ProcessFeeds(void *p)
return;
bool manuallyTriggered = (p == MANUALLY_TRIGGERED);
- if (manuallyTriggered) {
+ if (manuallyTriggered)
facy.info_notify(TranslateT("Loading wall posts..."));
- }
facy.handle_entry("feeds");
// Get feeds
HttpRequest *request = new NewsfeedRequest(&facy);
http::response resp = facy.sendRequest(request);
-
if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error("feeds");
return;
@@ -1171,17 +1136,15 @@ void FacebookProto::ProcessFeeds(void *p)
parseFeeds(resp.data, news, new_time, filterAds);
- if (!news.empty()) {
+ if (!news.empty())
Skin_PlaySound("NewsFeed");
- }
if (manuallyTriggered) {
CMStringW text(FORMAT, TranslateT("Found %d wall posts."), news.size());
facy.info_notify(text.GetBuffer());
}
- for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++)
- {
+ for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++) {
ptrW tszTitle(mir_utf8decodeW(news[i]->title.c_str()));
ptrW tszText(mir_utf8decodeW(news[i]->text.c_str()));
MCONTACT hContact = ContactIDToHContact(news[i]->user_id);
@@ -1253,13 +1216,11 @@ void FacebookProto::SearchAckThread(void *targ)
std::string ssid;
int pn = 1;
- while (count < 50 && !isOffline())
- {
+ while (count < 50 && !isOffline()) {
SearchRequest *request = new SearchRequest(facy.mbasicWorks, search.c_str(), count, pn, ssid.c_str());
http::response resp = facy.sendRequest(request);
- if (resp.code == HTTP_CODE_OK)
- {
+ if (resp.code == HTTP_CODE_OK) {
std::string items = utils::text::source_get_value(&resp.data, 4, "<body", "</form", "<table", "</table>");
std::string::size_type pos = 0;
@@ -1309,10 +1270,8 @@ void FacebookProto::SearchAckThread(void *targ)
name = name.substr(0, pos2);
}
}
- else {
- // This is group or event, let's ignore that
+ else // This is group or event, let's ignore that
continue;
- }
// ignore self contact and empty ids
if (id.empty() || id == facy.self_.user_id)
@@ -1340,9 +1299,7 @@ void FacebookProto::SearchAckThread(void *targ)
if (ssid.empty())
break; // No more results
}
- else {
- break;
- }
+ else break;
}
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, targ, 0);
@@ -1368,8 +1325,7 @@ void FacebookProto::SearchIdAckThread(void *targ)
}
search = utils::url::encode(search);
- if (!isOffline() && !search.empty())
- {
+ if (!isOffline() && !search.empty()) {
http::response resp = facy.sendRequest(new ProfileRequest(facy.mbasicWorks, search.c_str()));
if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) {
@@ -1380,19 +1336,17 @@ void FacebookProto::SearchIdAckThread(void *targ)
resp = facy.sendRequest(new ProfileRequest(facy.mbasicWorks, search.c_str()));
}
- if (resp.code == HTTP_CODE_OK)
- {
+ if (resp.code == HTTP_CODE_OK) {
std::string about = utils::text::source_get_value(&resp.data, 2, "id=\"root\"", "</body>");
std::string id = utils::text::source_get_value2(&about, ";id=", "&\"");
if (id.empty())
id = utils::text::source_get_value2(&about, "?bid=", "&\"");
std::string name = utils::text::source_get_value(&about, 3, "<strong", ">", "</strong");
- if (name.empty()) {
+ if (name.empty())
name = utils::text::source_get_value(&resp.data, 2, "<title>", "</title>");
- }
- std::string surname;
+ std::string surname;
std::string::size_type pos;
if ((pos = name.find(" ")) != std::string::npos) {
surname = name.substr(pos + 1, name.length() - pos - 1);
@@ -1400,7 +1354,7 @@ void FacebookProto::SearchIdAckThread(void *targ)
}
// ignore self contact and empty ids
- if (!id.empty() && id != facy.self_.user_id){
+ if (!id.empty() && id != facy.self_.user_id) {
ptrW tid(mir_utf8decodeW(id.c_str()));
ptrW tname(mir_utf8decodeW(name.c_str()));
ptrW tsurname(mir_utf8decodeW(surname.c_str()));
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index 17698d6e29..4d42208359 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -145,17 +145,16 @@ FacebookProto::~FacebookProto()
DWORD_PTR FacebookProto::GetCaps(int type, MCONTACT)
{
- switch (type)
- {
+ switch (type) {
case PFLAGNUM_1:
- {
- DWORD_PTR flags = PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | /*PF1_ADDED |*/ PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES; // | PF1_VISLIST | PF1_INVISLIST;
+ {
+ DWORD_PTR flags = PF1_IM | PF1_CHAT | PF1_SERVERCLIST | PF1_AUTHREQ | /*PF1_ADDED |*/ PF1_BASICSEARCH | PF1_SEARCHBYEMAIL | PF1_SEARCHBYNAME | PF1_ADDSEARCHRES; // | PF1_VISLIST | PF1_INVISLIST;
- if (getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS))
- return flags |= PF1_MODEMSG;
- else
- return flags |= PF1_MODEMSGRECV;
- }
+ if (getByte(FACEBOOK_KEY_SET_MIRANDA_STATUS))
+ return flags |= PF1_MODEMSG;
+ else
+ return flags |= PF1_MODEMSGRECV;
+ }
case PFLAGNUM_2:
return PF2_ONLINE | PF2_SHORTAWAY | PF2_INVISIBLE | PF2_ONTHEPHONE | PF2_IDLE;
case PFLAGNUM_3:
@@ -189,8 +188,7 @@ int FacebookProto::SetStatus(int new_status)
}
// Routing statuses not supported by Facebook
- switch (new_status)
- {
+ switch (new_status) {
case ID_STATUS_ONLINE:
case ID_STATUS_AWAY:
case ID_STATUS_INVISIBLE:
@@ -368,8 +366,7 @@ int FacebookProto::OnIdleChanged(WPARAM, LPARAM lParam)
// Respect user choice about (not) notifying idle to protocols
if (privacy) {
// Reset it to 0 if there is some time already
- if (m_idleTS)
- {
+ if (m_idleTS) {
m_idleTS = 0;
delSetting("IdleTS");
}
@@ -389,7 +386,8 @@ int FacebookProto::OnIdleChanged(WPARAM, LPARAM lParam)
// Compute time when user really became idle
m_idleTS = time(nullptr) - mii.idleTime * 60;
setDword("IdleTS", m_idleTS);
- } else {
+ }
+ else {
// User stopped being idle
m_idleTS = 0;
delSetting("IdleTS");
@@ -413,8 +411,7 @@ INT_PTR FacebookProto::GetNotificationsCount(WPARAM, LPARAM)
int FacebookProto::OnEvent(PROTOEVENTTYPE event, WPARAM wParam, LPARAM lParam)
{
- switch (event)
- {
+ switch (event) {
case EV_PROTO_ONLOAD:
return OnModulesLoaded(wParam, lParam);
@@ -600,7 +597,7 @@ int FacebookProto::OnPreCreateEvent(WPARAM, LPARAM lParam)
evt->dbei->timestamp = it->second;
facy.messages_timestamp.erase(it);
}
-
+
return 1;
}
@@ -619,25 +616,22 @@ INT_PTR FacebookProto::CheckNewsfeeds(WPARAM, LPARAM)
INT_PTR FacebookProto::CheckFriendRequests(WPARAM, LPARAM)
{
- if (!isOffline()) {
+ if (!isOffline())
ForkThread(&FacebookProto::ProcessFriendRequests, MANUALLY_TRIGGERED);
- }
return 0;
}
INT_PTR FacebookProto::CheckNotifications(WPARAM, LPARAM)
{
- if (!isOffline()) {
+ if (!isOffline())
ForkThread(&FacebookProto::ProcessNotifications, MANUALLY_TRIGGERED);
- }
return 0;
}
INT_PTR FacebookProto::CheckMemories(WPARAM, LPARAM)
{
- if (!isOffline()) {
+ if (!isOffline())
ForkThread(&FacebookProto::ProcessMemories, MANUALLY_TRIGGERED);
- }
return 0;
}
@@ -649,10 +643,8 @@ INT_PTR FacebookProto::VisitProfile(WPARAM wParam, LPARAM)
std::string url = FACEBOOK_URL_PROFILE;
ptrA val(getStringA(hContact, "Homepage"));
- if (val != NULL) {
- // Homepage link already present, get it
+ if (val != NULL) // Homepage link already present, get it
url = val;
- }
else {
// No homepage link, create and save it
val = getStringA(hContact, FACEBOOK_KEY_ID);
@@ -832,7 +824,6 @@ INT_PTR FacebookProto::ApproveFriendship(WPARAM wParam, LPARAM)
return 1;
MCONTACT *hContact = new MCONTACT((MCONTACT)wParam);
-
ForkThread(&FacebookProto::ApproveContactToServer, hContact);
return 0;
}
@@ -843,9 +834,7 @@ INT_PTR FacebookProto::DenyFriendship(WPARAM wParam, LPARAM)
return 1;
MCONTACT *hContact = new MCONTACT((MCONTACT)wParam);
-
ForkThread(&FacebookProto::IgnoreFriendshipRequest, hContact);
-
return 0;
}
@@ -879,7 +868,8 @@ MCONTACT FacebookProto::HContactFromAuthEvent(MEVENT hEvent)
return DbGetAuthEventContact(&dbei);
}
-void FacebookProto::OpenUrlThread(void *p) {
+void FacebookProto::OpenUrlThread(void *p)
+{
if (p == nullptr)
return;
@@ -890,7 +880,8 @@ void FacebookProto::OpenUrlThread(void *p) {
delete data;
}
-std::string FacebookProto::PrepareUrl(std::string url) {
+std::string FacebookProto::PrepareUrl(std::string url)
+{
std::string::size_type pos = url.find(FACEBOOK_SERVER_DOMAIN);
bool isFacebookUrl = (pos != std::string::npos);
bool isAbsoluteUrl = (url.find("://") != std::string::npos);
@@ -898,14 +889,14 @@ std::string FacebookProto::PrepareUrl(std::string url) {
// Do nothing with absolute non-Facebook URLs
if (isAbsoluteUrl && !isFacebookUrl)
return url;
-
+
// Transform absolute URL to relative
if (isAbsoluteUrl) {
// Check and ignore special subdomains
std::string subdomain = utils::text::source_get_value(&url, 2, "://", "." FACEBOOK_SERVER_DOMAIN);
if (subdomain == "developers")
return url;
-
+
// Make relative url
url = url.substr(pos + mir_strlen(FACEBOOK_SERVER_DOMAIN));
@@ -957,31 +948,30 @@ void FacebookProto::ReadNotificationWorker(void *p)
*/
LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- switch (message)
- {
+ switch (message) {
case WM_COMMAND:
case WM_CONTEXTMENU:
- {
- // Get the plugin data (we need the Popup service to do it)
- popup_data *data = (popup_data *)PUGetPluginData(hwnd);
- if (data != nullptr) {
- if (!data->notification_id.empty())
- data->proto->ForkThread(&FacebookProto::ReadNotificationWorker, new std::string(data->notification_id));
-
- if (message == WM_COMMAND && !data->url.empty())
- data->proto->OpenUrl(data->url);
- }
+ {
+ // Get the plugin data (we need the Popup service to do it)
+ popup_data *data = (popup_data *)PUGetPluginData(hwnd);
+ if (data != nullptr) {
+ if (!data->notification_id.empty())
+ data->proto->ForkThread(&FacebookProto::ReadNotificationWorker, new std::string(data->notification_id));
- // After a click, destroy popup
- PUDeletePopup(hwnd);
- } break;
+ if (message == WM_COMMAND && !data->url.empty())
+ data->proto->OpenUrl(data->url);
+ }
+
+ // After a click, destroy popup
+ PUDeletePopup(hwnd);
+ } break;
case UM_FREEPLUGINDATA:
- {
- // After close, free
- popup_data *data = (popup_data *)PUGetPluginData(hwnd);
- delete data;
- } return FALSE;
+ {
+ // After close, free
+ popup_data *data = (popup_data *)PUGetPluginData(hwnd);
+ delete data;
+ } return FALSE;
default:
break;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index f31981a500..d3306433f9 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -127,7 +127,6 @@ public:
// Services
INT_PTR __cdecl GetMyAwayMsg(WPARAM, LPARAM);
- INT_PTR __cdecl SetMyAwayMsg(WPARAM, LPARAM);
INT_PTR __cdecl SvcCreateAccMgrUI(WPARAM, LPARAM);
INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM);
INT_PTR __cdecl GetAvatarInfo(WPARAM, LPARAM);
@@ -278,8 +277,6 @@ public:
std::string last_status_msg_;
std::vector<MCONTACT> avatar_queue;
- static void CALLBACK APC_callback(ULONG_PTR p);
-
// Information providing
HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = NULL, std::string *notification_id = NULL, const char *icon = NULL);
void ShowNotifications();
diff --git a/protocols/FacebookRM/src/requests/history.h b/protocols/FacebookRM/src/requests/history.h
index b7cf3f42c1..ad3e4c19e1 100644
--- a/protocols/FacebookRM/src/requests/history.h
+++ b/protocols/FacebookRM/src/requests/history.h
@@ -29,7 +29,7 @@ class ThreadInfoRequest : public HttpRequest
{
public:
// Request only messages history
- ThreadInfoRequest(facebook_client *fc, bool isChat, const char *id, int offset, const char *timestamp, int limit) :
+ ThreadInfoRequest(facebook_client *fc, bool isChat, const char *id, int /*offset*/, const char* /*timestamp*/, int limit) :
HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/api/graphqlbatch/")
{
setCommonBody(fc);
@@ -62,7 +62,7 @@ public:
else
query_params << NULL_PARAM("before");
- o0 << CHAR_PARAM("doc_id", id) << JSON_PARAM("query_params", query_params);
+ o0 << CHAR_PARAM("doc_id", id) << JSON_PARAM("query_params", query_params);
root << JSON_PARAM("o0", o0);
@@ -72,7 +72,7 @@ public:
// example request data we need to send: { "o0":{"doc_id":"456789456123","query_params" : {"id":"123456789","message_limit" : 20,"load_messages" : 1,"load_read_receipts" : false,"before" : null}} }
-
+
/*
//if (loadMessages) {
// Grrr, offset doesn't work at all, we need to use timestamps to get back in history...
diff --git a/protocols/FacebookRM/src/requests/utils.h b/protocols/FacebookRM/src/requests/utils.h
index 6cf4aaa1ee..e6b8c84c3c 100644
--- a/protocols/FacebookRM/src/requests/utils.h
+++ b/protocols/FacebookRM/src/requests/utils.h
@@ -93,7 +93,7 @@ class GetPagesRequest : public HttpRequest
public:
GetPagesRequest() :
HttpRequest(REQUEST_GET, FACEBOOK_SERVER_REGULAR "/bookmarks/pages")
- { }
+ {}
};
// changing identity to post status for pages
@@ -103,13 +103,8 @@ public:
SwitchIdentityRequest(const char *dtsg, const char *userId) :
HttpRequest(REQUEST_POST, FACEBOOK_SERVER_REGULAR "/identity_switch.php")
{
- Url
- << "__a=1";
-
- Body
- << CHAR_VALUE("fb_dtsg", dtsg)
- << CHAR_VALUE("user_id", userId)
- << CHAR_VALUE("url", FACEBOOK_URL_HOMEPAGE);
+ Url << "__a=1";
+ Body << CHAR_VALUE("fb_dtsg", dtsg) << CHAR_VALUE("user_id", userId) << CHAR_VALUE("url", FACEBOOK_URL_HOMEPAGE);
}
};
@@ -131,7 +126,7 @@ public:
<< CHAR_VALUE("__req", fc->__req())
<< CHAR_VALUE("ttstamp", fc->ttstamp_.c_str())
<< CHAR_VALUE("__user", status->isPage && !status->user_id.empty() ? status->user_id.c_str() : fc->self_.user_id.c_str())
- << CHAR_VALUE("xhpc_targetid", status->user_id.empty() ? fc->self_.user_id.c_str() : status->user_id.c_str())
+ << CHAR_VALUE("xhpc_targetid", status->user_id.empty() ? fc->self_.user_id.c_str() : status->user_id.c_str())
<< CHAR_VALUE("xhpc_message", text)
<< CHAR_VALUE("xhpc_message_text", text)
<< "xhpc_context=profile"
@@ -146,13 +141,11 @@ public:
<< "disable_location_sharing=false"
<< "nctr[_mod]=pagelet_composer";
- if (!status->isPage) {
+ if (!status->isPage)
Body << CHAR_VALUE("audience[0][value]", fc->get_privacy_type().c_str());
- }
- if (!status->place.empty()) {
+ if (!status->place.empty())
Body << CHAR_VALUE("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++) {
@@ -166,9 +159,8 @@ public:
// Link attachment
if (mir_strlen(linkData) > 0) {
- Body
- << linkData;
- // << "no_picture=0" // for disabling link preview image
+ Body << linkData;
+ // << "no_picture=0" // for disabling link preview image
}
}
};
@@ -185,7 +177,7 @@ public:
Body
<< "do_confirm=0"
- << CHAR_VALUE("poke_target", userId)
+ << CHAR_VALUE("poke_target", userId)
<< CHAR_VALUE("fb_dtsg", fc->dtsg_.c_str())
<< CHAR_VALUE("__user", fc->self_.user_id.c_str())
<< CHAR_VALUE("ttstamp", fc->ttstamp_.c_str());
diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp
index 7d28554273..3ecd9e5779 100644
--- a/protocols/FacebookRM/src/theme.cpp
+++ b/protocols/FacebookRM/src/theme.cpp
@@ -222,8 +222,7 @@ int FacebookProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM)
Menu_ShowItem(g_hContactMenuPostStatus, !bIsChatroom);
Menu_ShowItem(g_hContactMenuLoadHistory, !bIsChatroom);
- if (!isOffline() && !bIsChatroom && !bIsPage)
- {
+ if (!isOffline() && !bIsChatroom && !bIsPage) {
bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
Menu_ShowItem(g_hContactMenuAuthAsk, ctrlPressed || type == CONTACT_NONE || !type);
diff --git a/utils/std_string_utils.cpp b/utils/std_string_utils.cpp
index 5d0d736e43..c227ff65bd 100644
--- a/utils/std_string_utils.cpp
+++ b/utils/std_string_utils.cpp
@@ -27,10 +27,8 @@ std::string utils::url::encode(const std::string &s)
std::string utils::url::decode(std::string data)
{
std::string new_string;
- for (std::string::size_type i = 0; i < data.length(); i++)
- {
- if (data.at(i) == '%' && (i + 2) < data.length())
- {
+ for (std::string::size_type i = 0; i < data.length(); i++) {
+ if (data.at(i) == '%' && (i + 2) < data.length()) {
std::string num = data.substr(i + 1, 2);
unsigned long udn = strtoul(num.c_str(), nullptr, 16);
utils::text::append_ordinal(udn, &new_string);
@@ -78,8 +76,7 @@ std::string utils::conversion::to_string(void* data, WORD type)
{
std::stringstream out;
- switch (type)
- {
+ switch (type) {
case UTILS_CONV_BOOLEAN:
out << (data ? "true" : "false");
break;
@@ -103,8 +100,7 @@ std::string utils::conversion::to_string(void* data, WORD type)
void utils::text::replace_first(std::string* data, const std::string &from, const std::string &to)
{
std::string::size_type position = data->find(from);
- if (position != std::string::npos)
- {
+ if (position != std::string::npos) {
data->replace(position, from.size(), to);
}
}
@@ -113,8 +109,7 @@ void utils::text::replace_all(std::string* data, const std::string &from, const
{
std::string::size_type position = 0;
- while ((position = data->find(from, position)) != std::string::npos)
- {
+ while ((position = data->find(from, position)) != std::string::npos) {
data->replace(position, from.size(), to);
position += to.size();
}
@@ -124,8 +119,7 @@ void utils::text::treplace_all(std::wstring* data, const std::wstring &from, con
{
std::wstring::size_type position = 0;
- while ((position = data->find(from, position)) != std::wstring::npos)
- {
+ while ((position = data->find(from, position)) != std::wstring::npos) {
data->replace(position, from.size(), to);
position++;
}
@@ -136,8 +130,7 @@ unsigned int utils::text::count_all(std::string* data, const std::string &term)
unsigned int count = 0;
std::string::size_type position = 0;
- while ((position = data->find(term, position)) != std::string::npos)
- {
+ while ((position = data->find(term, position)) != std::string::npos) {
count++;
position++;
}
@@ -147,27 +140,23 @@ unsigned int utils::text::count_all(std::string* data, const std::string &term)
void utils::text::append_ordinal(unsigned long value, std::string* data)
{
- if (value <= 127)
- { // U+0000 .. U+007F
+ if (value <= 127) { // U+0000 .. U+007F
*data += (char)value;
}
- else if (value >= 128 && value <= 2047)
- { // U+0080 .. U+07FF
+ else if (value >= 128 && value <= 2047) { // U+0080 .. U+07FF
*data += (char)(192 + (value / 64));
*data += (char)(128 + (value % 64));
}
- else if (value >= 2048 && value <= 65535)
- { // U+0800 .. U+FFFF
+ else if (value >= 2048 && value <= 65535) { // U+0800 .. U+FFFF
*data += (char)(224 + (value / 4096));
*data += (char)(128 + ((value / 64) % 64));
*data += (char)(128 + (value % 64));
}
- else
- {
+ else {
*data += (char)((value >> 24) & 0xFF);
*data += (char)((value >> 16) & 0xFF);
*data += (char)((value >> 8) & 0xFF);
- *data += (char)((value)& 0xFF);
+ *data += (char)((value) & 0xFF);
}
}
@@ -198,10 +187,8 @@ std::string utils::text::html_entities_decode(std::string data)
// http://webdesign.about.com/library/bl_htmlcodes.htm
std::string new_string;
- for (std::string::size_type i = 0; i < data.length(); i++)
- {
- if (data.at(i) == '&' && (i + 1) < data.length() && data.at(i + 1) == '#')
- {
+ for (std::string::size_type i = 0; i < data.length(); i++) {
+ if (data.at(i) == '&' && (i + 1) < data.length() && data.at(i + 1) == '#') {
std::string::size_type comma = data.find(";", i);
if (comma != std::string::npos) {
bool hexa = false;
@@ -234,10 +221,8 @@ std::string utils::text::remove_html(const std::string &data)
{
std::string new_string;
- for (std::string::size_type i = 0; i < data.length(); i++)
- {
- if (data.at(i) == '<' && (i + 1) < data.length() && data.at(i + 1) != ' ')
- {
+ for (std::string::size_type i = 0; i < data.length(); i++) {
+ if (data.at(i) == '<' && (i + 1) < data.length() && data.at(i + 1) != ' ') {
i = data.find(">", i);
if (i == std::string::npos)
break;
@@ -255,10 +240,8 @@ std::string utils::text::slashu_to_utf8(const std::string &data)
{
std::string new_string;
- for (std::string::size_type i = 0; i < data.length(); i++)
- {
- if (data.at(i) == '\\' && (i + 1) < data.length() && data.at(i + 1) == 'u')
- {
+ for (std::string::size_type i = 0; i < data.length(); i++) {
+ if (data.at(i) == '\\' && (i + 1) < data.length() && data.at(i + 1) == 'u') {
unsigned long udn = strtoul(data.substr(i + 2, 4).c_str(), nullptr, 16);
append_ordinal(udn, &new_string);
i += 5;
@@ -304,10 +287,8 @@ std::string utils::text::source_get_value(std::string* data, unsigned int argume
va_start(arg, argument_count);
- for (unsigned int i = argument_count; i > 0; i--)
- {
- if (i == 1)
- {
+ for (unsigned int i = argument_count; i > 0; i--) {
+ if (i == 1) {
end = data->find(va_arg(arg, char*), start);
if (start == std::string::npos || end == std::string::npos)
break;
@@ -417,7 +398,8 @@ std::string utils::text::rand_string(int len, const char *chars, unsigned int *n
return out.str();
}
-std::string utils::text::truncate_utf8(const std::string &text, size_t maxLength) {
+std::string utils::text::truncate_utf8(const std::string &text, size_t maxLength)
+{
// To not split some unicode character we need to transform it to wchar_t first, then split it, and then convert it back, because we want std::string as result
// TODO: Probably there is much simpler and nicer way
std::wstring wtext = ptrW(mir_utf8decodeW(text.c_str()));