summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-11-26 08:44:18 +0000
committerRobert Pösel <robyer@seznam.cz>2014-11-26 08:44:18 +0000
commitc1d2d5892eda3070975bbb82ac4f2e35d7bc139e (patch)
tree5902759b93eed462f1b8815a19b9f9e35d674046 /protocols
parentf5e38aaba573fa720894433ae746b3a7a741356e (diff)
Facebook: Various optimizations and cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@11083 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/avatars.cpp2
-rw-r--r--protocols/FacebookRM/src/captcha.cpp2
-rw-r--r--protocols/FacebookRM/src/chat.cpp2
-rw-r--r--protocols/FacebookRM/src/client.h14
-rw-r--r--protocols/FacebookRM/src/communication.cpp26
-rw-r--r--protocols/FacebookRM/src/connection.cpp2
-rw-r--r--protocols/FacebookRM/src/contacts.cpp22
-rw-r--r--protocols/FacebookRM/src/entities.h42
-rw-r--r--protocols/FacebookRM/src/json.cpp62
-rw-r--r--protocols/FacebookRM/src/list.hpp7
-rw-r--r--protocols/FacebookRM/src/messages.cpp6
-rw-r--r--protocols/FacebookRM/src/process.cpp13
-rw-r--r--protocols/FacebookRM/src/proto.cpp2
-rw-r--r--protocols/FacebookRM/src/proto.h10
-rw-r--r--protocols/FacebookRM/src/utils.cpp39
-rw-r--r--protocols/FacebookRM/src/utils.h16
16 files changed, 117 insertions, 150 deletions
diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp
index c4715d71f4..0be1b41b65 100644
--- a/protocols/FacebookRM/src/avatars.cpp
+++ b/protocols/FacebookRM/src/avatars.cpp
@@ -41,7 +41,7 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *
return true;
}
-void FacebookProto::CheckAvatarChange(MCONTACT hContact, std::string image_url)
+void FacebookProto::CheckAvatarChange(MCONTACT hContact, const std::string &image_url)
{
std::tstring::size_type pos = image_url.rfind("/");
diff --git a/protocols/FacebookRM/src/captcha.cpp b/protocols/FacebookRM/src/captcha.cpp
index 3abec878f7..b3909e53d1 100644
--- a/protocols/FacebookRM/src/captcha.cpp
+++ b/protocols/FacebookRM/src/captcha.cpp
@@ -106,7 +106,7 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam
bool FacebookProto::RunCaptchaForm(std::string captchaUrl, std::string &result)
{
debugLogA("RunCaptchaForm: reading picture from %s", captchaUrl.c_str());
- result = "";
+ result.clear();
NETLIBHTTPREQUEST req = { sizeof(req) };
req.requestType = REQUEST_GET;
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp
index b4a8f3511e..2ceaeec16d 100644
--- a/protocols/FacebookRM/src/chat.cpp
+++ b/protocols/FacebookRM/src/chat.cpp
@@ -52,7 +52,7 @@ void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char
// TODO: keep it here or move it somewhere else?
std::map<std::tstring, facebook_chatroom*>::iterator chatroom = facy.chat_rooms.find(tchat_id);
if (chatroom != facy.chat_rooms.end()) {
- chatroom->second->message_readers = "";
+ chatroom->second->message_readers.clear();
}
}
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index c4087c5f4c..d69c311363 100644
--- a/protocols/FacebookRM/src/client.h
+++ b/protocols/FacebookRM/src/client.h
@@ -37,10 +37,6 @@ public:
facebook_client()
{
- username_ = password_ = \
- chat_sequence_num_ = chat_channel_host_ = chat_channel_partition_ = \
- dtsg_ = csrf_ = logout_hash_ = chat_sticky_num_ = chat_sticky_pool_ = chat_conn_num_ = chat_clientid_ = chat_traceid_ = "";
-
msgid_ = error_count_ = last_feeds_update_ = last_notification_time_ = 0;
https_ = is_idle_ = is_typing_ = false;
@@ -131,9 +127,9 @@ public:
unsigned int error_count_;
- bool handle_entry(std::string method);
- bool handle_success(std::string method);
- bool handle_error(std::string method, int force_disconnect = 0);
+ bool handle_entry(const std::string &method);
+ bool handle_success(const std::string &method);
+ bool handle_error(const std::string &method, int force_disconnect = 0);
void __inline increment_error() { this->error_count_++; }
void __inline decrement_error() { if (error_count_ > 0) error_count_--; }
@@ -143,7 +139,7 @@ public:
// Helpers for data
- std::string __inline phstamp(std::string data) {
+ std::string __inline phstamp(const std::string &data) {
std::stringstream out;
out << '2' << this->csrf_ << (int)data.length();
return out.str();
@@ -188,7 +184,7 @@ public:
std::map<std::string, int> messages_ignore;
bool channel();
- int send_message(MCONTACT, std::string message_recipient, std::string message_text, std::string *error_text, MessageMethod method, std::string captchaPersistData = "", std::string captcha = "");
+ int send_message(MCONTACT, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captchaPersistData = "", const std::string &captcha = "");
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp
index 398093fe3f..773abb937a 100644
--- a/protocols/FacebookRM/src/communication.cpp
+++ b/protocols/FacebookRM/src/communication.cpp
@@ -132,7 +132,7 @@ http::response facebook_client::flap(RequestType request_type, std::string* requ
pos += 8;
int error_num = atoi(resp.data.substr(pos, resp.data.find(",", pos) - pos).c_str());
if (error_num != 0) {
- std::string error = "";
+ std::string error;
pos = resp.data.find("\"errorDescription\":\"", pos);
if (pos != std::string::npos) {
@@ -142,7 +142,7 @@ http::response facebook_client::flap(RequestType request_type, std::string* requ
error = ptrA( mir_utf8decodeA(error.c_str()));
}
- std::string title = "";
+ std::string title;
pos = resp.data.find("\"errorSummary\":\"", pos);
if (pos != std::string::npos) {
pos += 16;
@@ -168,20 +168,20 @@ http::response facebook_client::flap(RequestType request_type, std::string* requ
return resp;
}
-bool facebook_client::handle_entry(std::string method)
+bool facebook_client::handle_entry(const std::string &method)
{
parent->debugLogA(" >> Entering %s()", method.c_str());
return true;
}
-bool facebook_client::handle_success(std::string method)
+bool facebook_client::handle_success(const std::string &method)
{
parent->debugLogA(" << Quitting %s()", method.c_str());
reset_error();
return true;
}
-bool facebook_client::handle_error(std::string method, int action)
+bool facebook_client::handle_error(const std::string &method, int action)
{
increment_error();
parent->debugLogA("!!!!! %s(): Something with Facebook went wrong", method.c_str());
@@ -818,15 +818,17 @@ bool facebook_client::login(const char *username, const char *password)
if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end())
{
+ std::string location = resp.headers["Location"];
+
// Check for invalid requests
- if (resp.headers["Location"].find("invalid_request.php") != std::string::npos) {
+ if (location.find("invalid_request.php") != std::string::npos) {
client_notify(TranslateT("Login error: Invalid request."));
parent->debugLogA(" ! ! Login error: Invalid request.");
return handle_error("login", FORCE_QUIT);
}
// Check whether some Facebook things are required
- if (resp.headers["Location"].find("help.php") != std::string::npos)
+ if (location.find("help.php") != std::string::npos)
{
client_notify(TranslateT("Login error: Some Facebook things are required."));
parent->debugLogA(" ! ! Login error: Some Facebook things are required.");
@@ -834,7 +836,7 @@ bool facebook_client::login(const char *username, const char *password)
}
// Check whether setting Machine name is required
- if (resp.headers["Location"].find("/checkpoint/") != std::string::npos)
+ if (location.find("/checkpoint/") != std::string::npos)
{
resp = flap(REQUEST_SETUP_MACHINE, NULL, NULL, REQUEST_GET);
@@ -974,7 +976,9 @@ bool facebook_client::logout()
http::response resp = flap(REQUEST_LOGOUT, &data);
- this->username_ = this->password_ = this->self_.user_id = "";
+ this->username_.clear();
+ this->password_.clear();
+ this->self_.user_id.clear();
switch (resp.code)
{
@@ -1210,14 +1214,14 @@ bool facebook_client::channel()
}
}
-int facebook_client::send_message(MCONTACT hContact, std::string message_recipient, std::string message_text, std::string *error_text, MessageMethod method, std::string captcha_persist_data, std::string captcha)
+int facebook_client::send_message(MCONTACT hContact, const std::string &message_recipient, const std::string &message_text, std::string *error_text, MessageMethod method, const std::string &captcha_persist_data, const std::string &captcha)
{
ScopedLock s(send_message_lock_);
handle_entry("send_message");
http::response resp;
- std::string data = "";
+ std::string data;
if (!captcha.empty()) {
data += "&captcha_persist_data=" + captcha_persist_data;
diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp
index d1a10bb756..d0d33ab838 100644
--- a/protocols/FacebookRM/src/connection.cpp
+++ b/protocols/FacebookRM/src/connection.cpp
@@ -201,7 +201,7 @@ void FacebookProto::UpdateLoop(void *)
time_t tim = ::time(NULL);
debugLogA(">>>>> Entering Facebook::UpdateLoop[%d]", tim);
- for (int i = -1; !isOffline(); i = ++i % 50)
+ for (int i = -1; !isOffline(); i = (i + 1) % 50)
{
if (i != -1) {
ProcessBuddyList(NULL);
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 7e76fdb4b7..5da990e616 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common.h"
-void updateStringUtf(FacebookProto *proto, MCONTACT hContact, const char *key, std::string value) {
+void updateStringUtf(FacebookProto *proto, MCONTACT hContact, const char *key, const std::string &value) {
bool update_required = true;
DBVARIANT dbv;
@@ -52,7 +52,7 @@ void FacebookProto::SaveName(MCONTACT hContact, const facebook_user *fbu)
updateStringUtf(this, hContact, FACEBOOK_KEY_FIRST_NAME, names.size() > 0 ? names.front().c_str() : "");
updateStringUtf(this, hContact, FACEBOOK_KEY_LAST_NAME, names.size() > 1 ? names.back().c_str() : "");
- std::string middle = "";
+ std::string middle;
if (names.size() > 2) {
for (std::string::size_type i = 1; i < names.size() - 1; i++) {
if (!middle.empty())
@@ -75,7 +75,7 @@ bool FacebookProto::IsMyContact(MCONTACT hContact, bool include_chat)
return false;
}
-MCONTACT FacebookProto::ChatIDToHContact(std::tstring chat_id)
+MCONTACT FacebookProto::ChatIDToHContact(const std::tstring &chat_id)
{
// First check cache
std::map<std::tstring, MCONTACT>::iterator it = facy.chat_id_to_hcontact.find(chat_id);
@@ -102,7 +102,7 @@ MCONTACT FacebookProto::ChatIDToHContact(std::tstring chat_id)
return 0;
}
-MCONTACT FacebookProto::ContactIDToHContact(std::string user_id)
+MCONTACT FacebookProto::ContactIDToHContact(const std::string &user_id)
{
// First check cache
std::map<std::string, MCONTACT>::iterator it = facy.user_id_to_hcontact.find(user_id);
@@ -129,7 +129,7 @@ MCONTACT FacebookProto::ContactIDToHContact(std::string user_id)
return 0;
}
-std::string FacebookProto::ThreadIDToContactID(std::string thread_id)
+std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
{
// First check cache
std::map<std::string, std::string>::iterator it = facy.thread_id_to_user_id.find(thread_id);
@@ -164,7 +164,7 @@ std::string FacebookProto::ThreadIDToContactID(std::string thread_id)
data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp();
data += "&threads[thread_ids][0]=" + utils::url::encode(thread_id);
- std::string user_id = "";
+ std::string user_id;
http::response resp = facy.flap(REQUEST_THREAD_INFO, &data);
if (resp.code == HTTP_CODE_OK) {
@@ -277,7 +277,9 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
unsigned int namesCount = 3; // how many names should be in room name; max. 5
for (std::map<std::string, std::string>::iterator it = fbc->participants.begin(); it != fbc->participants.end(); ++it) {
- if (it->second.empty())
+ std::string participant = it->second;
+
+ if (participant.empty())
continue;
if (!fbc->chat_name.empty())
@@ -285,11 +287,11 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
std::string name;
std::string::size_type pos;
- if ((pos = it->second.find(" ")) != std::string::npos) {
- name = it->second.substr(0, pos);
+ if ((pos = participant.find(" ")) != std::string::npos) {
+ name = participant.substr(0, pos);
}
else {
- name = it->second;
+ name = participant;
}
fbc->chat_name += _A2T(name.c_str());
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 35c062d4af..99e171348b 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -45,29 +45,12 @@ struct facebook_user
facebook_user()
{
this->handle = NULL;
- this->user_id = this->real_name = this->nick = this->username = this->image_url = "";
this->status_id = ID_STATUS_OFFLINE;
this->gender = this->last_active = 0;
this->deleted = this->idle = false;
this->client = CLIENT_WEB;
}
- facebook_user(facebook_user* fu)
- {
- this->handle = fu->handle;
- this->user_id = fu->user_id;
- this->real_name = fu->real_name;
- this->nick = fu->nick;
- this->username = fu->username;
- this->status_id = fu->status_id;
- this->gender = fu->gender;
- this->last_active = fu->last_active;
- this->image_url = fu->image_url;
- this->deleted = fu->deleted;
- this->idle = fu->idle;
- this->client = fu->client;
- }
-
TCHAR *getMirVer()
{
switch (this->client) {
@@ -117,29 +100,12 @@ struct facebook_message
facebook_message()
{
- this->user_id = this->message_text = this->sender_name = this->message_id = this->thread_id = this->timestamp = "";
this->time = 0;
this->isUnread = this->isIncoming = true;
this->isChat = false;
this->type = MESSAGE;
this->flag_ = 0;
}
-
- facebook_message(const facebook_message& msg)
- {
- this->user_id = msg.user_id;
- this->sender_name = msg.sender_name;
- this->message_text = msg.message_text;
- this->message_id = msg.message_id;
- this->message_id = msg.thread_id;
- this->timestamp = msg.timestamp;
- this->time = msg.time;
- this->isIncoming = msg.isIncoming;
- this->isUnread = msg.isUnread;
- this->isChat = msg.isChat;
- this->type = msg.type;
- this->flag_ = msg.flag_;
- }
};
struct facebook_notification
@@ -154,7 +120,6 @@ struct facebook_notification
facebook_notification()
{
- this->user_id = this->text = this->link = this->id = "";
this->time = 0;
this->seen = false;
this->hWndPopup = NULL;
@@ -168,10 +133,7 @@ struct facebook_newsfeed
std::string text;
std::string link;
- facebook_newsfeed()
- {
- this->user_id = this->title = this->text = this->link = "";
- }
+ facebook_newsfeed() {}
};
struct send_chat
@@ -208,7 +170,6 @@ struct popup_data
struct status_data
{
status_data() {
- this->user_id = this->text = this->url = this->place = this->privacy = "";
this->isPage = false;
}
std::string user_id;
@@ -223,7 +184,6 @@ struct status_data
struct wall_data
{
wall_data() {
- this->user_id = "";
this->title = NULL;
this->isPage = false;
}
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index 98ac75790f..4f7649475d 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -116,13 +116,13 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user
bool b;
// "webStatus" and "otherStatus" are marked as "WEB" on FB website
- if ((b = json_as_pstring(webStatus) == "active") || json_as_pstring(otherStatus) == "active") {
+ if ((b = (json_as_pstring(webStatus) == "active")) || json_as_pstring(otherStatus) == "active") {
current->status_id = ID_STATUS_ONLINE;
current->client = b ? CLIENT_WEB : CLIENT_OTHER;
}
// "fbAppStatus" and "messengerStatus" are marked as "MOBILE" on FB website
- if ((b = json_as_pstring(fbAppStatus) == "active") || json_as_pstring(messengerStatus) == "active") {
+ if ((b = (json_as_pstring(fbAppStatus) == "active")) || json_as_pstring(messengerStatus) == "active") {
current->status_id = ID_STATUS_ONTHEPHONE;
current->client = b ? CLIENT_APP : CLIENT_MESSENGER;
}
@@ -288,7 +288,7 @@ int facebook_json_parser::parse_notifications(void *data, std::map< std::string,
return EXIT_SUCCESS;
}
-bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text)
+bool ignore_duplicits(FacebookProto *proto, const std::string &mid, const std::string &text)
{
ScopedLock s(proto->facy.send_message_lock_);
@@ -305,14 +305,14 @@ bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text)
return false;
}
-void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE *it, std::string thread_id, std::string other_user_fbid)
+void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE *it, const std::string &thread_id, std::string other_user_fbid)
{
// Process attachements and stickers
JSONNODE *has_attachment = json_get(it, "has_attachment");
if (has_attachment != NULL && json_as_bool(has_attachment)) {
// Append attachements
- std::string type = "";
- std::string attachments_text = "";
+ std::string type;
+ std::string attachments_text;
JSONNODE *attachments = json_get(it, "attachments");
for (unsigned int j = 0; j < json_size(attachments); j++) {
JSONNODE *itAttachment = json_at(attachments, j);
@@ -467,25 +467,28 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
std::tstring tid = json_as_string(threadid);
std::string reader_id = json_as_pstring(reader);
- std::map<std::tstring, facebook_chatroom*>::iterator chatroom = proto->facy.chat_rooms.find(tid);
- if (chatroom != proto->facy.chat_rooms.end()) {
- std::map<std::string, std::string>::const_iterator participant = chatroom->second->participants.find(reader_id);
- if (participant == chatroom->second->participants.end()) {
+ std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid);
+ if (it != proto->facy.chat_rooms.end()) {
+ facebook_chatroom *chatroom = it->second;
+ std::map<std::string, std::string> participants = chatroom->participants;
+
+ std::map<std::string, std::string>::const_iterator participant = participants.find(reader_id);
+ if (participant == participants.end()) {
// TODO: load name of this participant
std::string name = reader_id;
- chatroom->second->participants.insert(std::make_pair(reader_id, name));
+ participants.insert(std::make_pair(reader_id, name));
proto->AddChatContact(tid.c_str(), reader_id.c_str(), name.c_str());
}
- participant = chatroom->second->participants.find(reader_id);
- if (participant != chatroom->second->participants.end()) {
+ participant = participants.find(reader_id);
+ if (participant != participants.end()) {
MCONTACT hChatContact = proto->ChatIDToHContact(tid);
- if (!chatroom->second->message_readers.empty())
- chatroom->second->message_readers += ", ";
- chatroom->second->message_readers += participant->second;
+ if (!chatroom->message_readers.empty())
+ chatroom->message_readers += ", ";
+ chatroom->message_readers += participant->second;
- ptrT readers(mir_utf8decodeT(chatroom->second->message_readers.c_str()));
+ ptrT readers(mir_utf8decodeT(chatroom->message_readers.c_str()));
StatusTextData st = { 0 };
st.cbSize = sizeof(st);
@@ -565,7 +568,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
message->isChat = (gthreadinfo != NULL && json_as_pstring(gthreadinfo) != "null");
if (!message->isChat && !message->isIncoming) {
- message->sender_name = "";
+ message->sender_name.clear();
message->user_id = proto->ThreadIDToContactID(message->thread_id); // TODO: Check if we have contact with this user_id in friendlist and otherwise do something different?
}
@@ -656,17 +659,20 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
std::tstring tid = json_as_string(thread_);
std::string from_id = json_as_pstring(from_);
- std::map<std::tstring, facebook_chatroom*>::iterator chatroom = proto->facy.chat_rooms.find(tid);
- if (chatroom != proto->facy.chat_rooms.end()) {
- std::map<std::string, std::string>::const_iterator participant = chatroom->second->participants.find(from_id);
- if (participant == chatroom->second->participants.end()) {
+ std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid);
+ if (it != proto->facy.chat_rooms.end()) {
+ facebook_chatroom *chatroom = it->second;
+ std::map<std::string, std::string> participants = chatroom->participants;
+
+ std::map<std::string, std::string>::const_iterator participant = participants.find(from_id);
+ if (participant == participants.end()) {
// TODO: load name of this participant
std::string name = from_id;
proto->AddChatContact(tid.c_str(), from_id.c_str(), name.c_str());
}
- participant = chatroom->second->participants.find(from_id);
- if (participant != chatroom->second->participants.end()) {
+ participant = participants.find(from_id);
+ if (participant != participants.end()) {
MCONTACT hChatContact = proto->ChatIDToHContact(tid);
ptrT name(mir_utf8decodeT(participant->second.c_str()));
@@ -761,7 +767,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
message->time = utils::time::fix_timestamp(json_as_float(timestamp));
message->user_id = id;
message->message_id = message_id;
- message->sender_name = "";
+ message->sender_name.clear();
message->thread_id = json_as_pstring(thread_id_);
message->type = CALL;
@@ -1022,7 +1028,7 @@ int facebook_json_parser::parse_thread_info(void* data, std::string* user_id)
return EXIT_FAILURE;
}
- std::map<std::string, std::string> thread_ids;
+ //std::map<std::string, std::string> thread_ids;
for (unsigned int i = 0; i < json_size(threads); i++) {
JSONNODE *it = json_at(threads, i);
JSONNODE *canonical = json_get(it, "canonical_fbid");
@@ -1064,7 +1070,7 @@ int facebook_json_parser::parse_user_info(void* data, facebook_user* fbu)
return EXIT_FAILURE;
}
- std::map<std::string, std::string> user_ids;
+ //std::map<std::string, std::string> user_ids;
for (unsigned int i = 0; i < json_size(profiles); i++) {
JSONNODE *it = json_at(profiles, i);
@@ -1118,7 +1124,7 @@ int facebook_json_parser::parse_chat_info(void* data, facebook_chatroom* fbc)
}
}*/
- std::map<std::string, std::string> thread_ids;
+ //std::map<std::string, std::string> thread_ids;
for (unsigned int i = 0; i < json_size(threads); i++) {
JSONNODE *it = json_at(threads, i);
diff --git a/protocols/FacebookRM/src/list.hpp b/protocols/FacebookRM/src/list.hpp
index 851645509b..d54811bb15 100644
--- a/protocols/FacebookRM/src/list.hpp
+++ b/protocols/FacebookRM/src/list.hpp
@@ -135,11 +135,8 @@ namespace List
help->prev->next = help->next;
help->next->prev = help->prev;
}
- if (help != NULL)
- {
- this->count--;
- delete help;
- }
+ this->count--;
+ delete help;
break;
}
}
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp
index 269c0aeb91..d25514fb4a 100644
--- a/protocols/FacebookRM/src/messages.cpp
+++ b/protocols/FacebookRM/src/messages.cpp
@@ -47,7 +47,7 @@ void FacebookProto::SendMsgWorker(void *p)
ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, 0);
} else {
int retries = 5;
- std::string error_text = "";
+ std::string error_text;
int result = SEND_MESSAGE_ERROR;
while (result == SEND_MESSAGE_ERROR && retries > 0) {
result = facy.send_message(data->hContact, std::string(id), data->msg, &error_text, retries % 2 == 0 ? MESSAGE_INBOX : MESSAGE_MERCURY);
@@ -73,7 +73,7 @@ void FacebookProto::SendChatMsgWorker(void *p)
return;
send_chat *data = static_cast<send_chat*>(p);
- std::string err_message = "";
+ std::string err_message;
// replace %% back to %, because chat automatically does this to sent messages
utils::text::replace_all(&data->msg, "%%", "%");
@@ -194,7 +194,7 @@ void FacebookProto::ReadMessageWorker(void *p)
facy.flap(REQUEST_MARK_READ, &data);
}
-void FacebookProto::StickerAsSmiley(std::string sticker, std::string url, MCONTACT hContact)
+void FacebookProto::StickerAsSmiley(std::string sticker, const std::string &url, MCONTACT hContact)
{
std::string b64 = ptrA( mir_base64_encode((PBYTE)sticker.c_str(), (unsigned)sticker.length()));
b64 = utils::url::encode(b64);
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 93692db613..bfb5904701 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -710,7 +710,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo
facy.chat_rooms.insert(std::make_pair(tthread_id, fbc));
}
- MCONTACT hChatContact;
+ MCONTACT hChatContact = NULL;
// RM TODO: better use check if chatroom exists/is in db/is online... no?
// like: if (ChatIDToHContact(tthread_id) == NULL) {
ptrA users(GetChatUsers(tthread_id.c_str()));
@@ -878,11 +878,12 @@ void FacebookProto::ShowNotifications() {
// Show popups for unseen notifications and/or write them to chatroom
for (std::map<std::string, facebook_notification*>::iterator it = facy.notifications.begin(); it != facy.notifications.end(); ++it) {
- if (it->second != NULL && !it->second->seen) {
- debugLogA(" Showing popup for notification: %s", it->second->text.c_str());
- ptrT szText(mir_utf8decodeT(it->second->text.c_str()));
- it->second->hWndPopup = NotifyEvent(m_tszUserName, szText, ContactIDToHContact(it->second->user_id), FACEBOOK_EVENT_NOTIFICATION, &it->second->link, &it->second->id);
- it->second->seen = true;
+ facebook_notification *notification = it->second;
+ if (notification != NULL && !notification->seen) {
+ debugLogA(" Showing popup for notification: %s", notification->text.c_str());
+ ptrT szText(mir_utf8decodeT(notification->text.c_str()));
+ notification->hWndPopup = NotifyEvent(m_tszUserName, szText, ContactIDToHContact(notification->user_id), FACEBOOK_EVENT_NOTIFICATION, &notification->link, &notification->id);
+ notification->seen = true;
}
}
}
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp
index a3d0564ec9..ffd21442c9 100644
--- a/protocols/FacebookRM/src/proto.cpp
+++ b/protocols/FacebookRM/src/proto.cpp
@@ -367,7 +367,7 @@ int FacebookProto::GetInfo(MCONTACT hContact, int infoType)
INT_PTR FacebookProto::GetMyAwayMsg(WPARAM wParam, LPARAM lParam)
{
ptrT statusMsg(getTStringA("StatusMsg"));
- if (statusMsg == NULL || _tcslen(statusMsg) == 0)
+ if (statusMsg == NULL || statusMsg[0] == '\0')
return 0;
return (lParam & SGMA_UNICODE) ? (INT_PTR)mir_t2u(statusMsg) : (INT_PTR)mir_t2a(statusMsg);
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 98b7d0e7cb..fc869b581c 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -200,9 +200,9 @@ public:
// Contacts handling
bool IsMyContact(MCONTACT, bool include_chat = false);
- MCONTACT ContactIDToHContact(std::string);
- MCONTACT ChatIDToHContact(std::tstring);
- std::string ThreadIDToContactID(std::string thread_id);
+ MCONTACT ContactIDToHContact(const std::string&);
+ MCONTACT ChatIDToHContact(const std::tstring&);
+ std::string ThreadIDToContactID(const std::string&);
void LoadContactInfo(facebook_user* fbu);
MCONTACT AddToContactList(facebook_user*, ContactType type, bool force_add = false);
void SetAllContactStatuses(int status);
@@ -233,9 +233,9 @@ public:
// Helpers
std::tstring GetAvatarFolder();
bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url);
- void CheckAvatarChange(MCONTACT hContact, std::string image_url);
+ void CheckAvatarChange(MCONTACT hContact, const std::string &image_url);
void ToggleStatusMenuItems(BOOL bEnable);
- void StickerAsSmiley(std::string stickerId, std::string url, MCONTACT hContact);
+ void StickerAsSmiley(std::string stickerId, const std::string &url, MCONTACT hContact);
void SaveName(MCONTACT hContact, const facebook_user *fbu);
void OpenUrl(std::string url);
void __cdecl OpenUrlThread(void*);
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 1ecaa1328c..39ab01e2a0 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -63,7 +63,7 @@ DWORD utils::time::fix_timestamp(unsigned __int64 mili_timestamp)
return (DWORD) mili_timestamp;
}
-DWORD utils::conversion::to_timestamp(std::string data)
+DWORD utils::conversion::to_timestamp(const std::string &data)
{
DWORD timestamp = NULL;
if (!utils::conversion::from_string<DWORD>(timestamp, data, std::dec)) {
@@ -97,7 +97,7 @@ std::string utils::conversion::to_string(void* data, WORD type)
return out.str();
}
-void utils::text::replace_first(std::string* data, std::string from, std::string to)
+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)
@@ -106,7 +106,7 @@ void utils::text::replace_first(std::string* data, std::string from, std::string
}
}
-void utils::text::replace_all(std::string* data, std::string from, std::string to)
+void utils::text::replace_all(std::string* data, const std::string &from, const std::string &to)
{
std::string::size_type position = 0;
@@ -117,7 +117,7 @@ void utils::text::replace_all(std::string* data, std::string from, std::string t
}
}
-unsigned int utils::text::count_all(std::string* data, std::string term)
+unsigned int utils::text::count_all(std::string* data, const std::string &term)
{
unsigned int count = 0;
std::string::size_type position = 0;
@@ -172,7 +172,7 @@ std::string utils::text::html_entities_decode(std::string data)
// http://www.natural-innovations.com/wa/doc-charset.html
// http://webdesign.about.com/library/bl_htmlcodes.htm
- std::string new_string = "";
+ 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) == '#')
@@ -208,7 +208,7 @@ std::string utils::text::edit_html(std::string data)
{
std::string::size_type end = 0;
std::string::size_type start = 0;
- std::string new_string = "";
+ std::string new_string;
while (end != std::string::npos)
{
@@ -224,7 +224,7 @@ std::string utils::text::edit_html(std::string data)
start = end = 0;
data = new_string;
- new_string = "";
+ new_string.clear();
while (end != std::string::npos)
{
@@ -241,7 +241,7 @@ std::string utils::text::edit_html(std::string data)
// Remove "Translate" link
start = end = 0;
data = new_string;
- new_string = "";
+ new_string.clear();
while (end != std::string::npos)
{
end = data.find("role=\\\"button\\\">", start);
@@ -291,9 +291,9 @@ std::string utils::text::edit_html(std::string data)
}
-std::string utils::text::remove_html(std::string data)
+std::string utils::text::remove_html(const std::string &data)
{
- std::string new_string = "";
+ std::string new_string;
for (std::string::size_type i = 0; i < data.length(); i++)
{
@@ -312,9 +312,9 @@ std::string utils::text::remove_html(std::string data)
return new_string;
}
-std::string utils::text::slashu_to_utf8(std::string data)
+std::string utils::text::slashu_to_utf8(const std::string &data)
{
- std::string new_string = "";
+ std::string new_string;
for (std::string::size_type i = 0; i < data.length(); i++)
{
@@ -332,7 +332,7 @@ std::string utils::text::slashu_to_utf8(std::string data)
return new_string;
}
-std::string utils::text::trim(std::string data, bool rtrim)
+std::string utils::text::trim(const std::string &data, bool rtrim)
{
std::string spaces = " \t\r\n";
std::string::size_type begin = rtrim ? 0 : data.find_first_not_of(spaces);
@@ -341,7 +341,7 @@ std::string utils::text::trim(std::string data, bool rtrim)
return (end != std::string::npos) ? data.substr(begin, end + 1 - begin) : "";
}
-void utils::text::explode(std::string str, std::string separator, std::vector<std::string>* results)
+void utils::text::explode(std::string str, const std::string &separator, std::vector<std::string>* results)
{
std::string::size_type pos;
pos = str.find_first_of(separator);
@@ -360,7 +360,7 @@ void utils::text::explode(std::string str, std::string separator, std::vector<st
std::string utils::text::source_get_value(std::string* data, unsigned int argument_count, ...)
{
va_list arg;
- std::string ret = "";
+ std::string ret;
std::string::size_type start = 0, end = 0;
va_start(arg, argument_count);
@@ -389,7 +389,7 @@ std::string utils::text::source_get_value(std::string* data, unsigned int argume
std::string utils::text::source_get_value2(std::string* data, const char *term, const char *endings, bool wholeString)
{
std::string::size_type start = 0, end = 0;
- std::string ret = "";
+ std::string ret;
start = data->find(term);
if (start != std::string::npos) {
@@ -408,13 +408,13 @@ std::string utils::text::source_get_value2(std::string* data, const char *term,
std::string utils::text::source_get_form_data(std::string* data)
{
- std::string values = "";
+ std::string values;
std::string::size_type start = 0;
start = data->find("<input", start);
while (start != std::string::npos) {
start++;
- std::string attr = "", value = "";
+ std::string attr, value;
std::string::size_type pos = data->find("name=\"", start);
if (pos != std::string::npos) {
@@ -449,8 +449,9 @@ std::string utils::text::rand_string(int len, const char *chars)
{
std::stringstream out;
+ int strLen = (int)strlen(chars);
for (int i = 0; i < len; ++i) {
- out << chars[utils::number::random(0, (int)strlen(chars))];
+ out << chars[utils::number::random(0, strLen)];
}
return out.str();
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h
index 69315ae1e0..6a5943e0a3 100644
--- a/protocols/FacebookRM/src/utils.h
+++ b/protocols/FacebookRM/src/utils.h
@@ -53,25 +53,25 @@ namespace utils
namespace text
{
- void replace_first(std::string* data, std::string from, std::string to);
- void replace_all(std::string* data, std::string from, std::string to);
- unsigned int count_all(std::string* data, std::string term);
+ void replace_first(std::string* data, const std::string &from, const std::string &to);
+ void replace_all(std::string* data, const std::string &from, const std::string &to);
+ unsigned int count_all(std::string* data, const std::string &term);
std::string html_entities_decode(std::string data);
std::string edit_html(std::string data);
- std::string remove_html(std::string data);
- std::string slashu_to_utf8(std::string data);
- std::string trim(std::string data, bool rtrim = false);
+ std::string remove_html(const std::string &data);
+ std::string slashu_to_utf8(const std::string &data);
+ std::string trim(const std::string &data, bool rtrim = false);
std::string source_get_value(std::string* data, unsigned int argument_count, ...);
std::string source_get_value2(std::string* data, const char *term, const char *endings, bool wholeString = false);
std::string source_get_form_data(std::string* data);
std::string rand_string(int len, const char *chars = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz");
- void explode(std::string str, std::string separator, std::vector<std::string>* results);
+ void explode(std::string str, const std::string &separator, std::vector<std::string>* results);
void append_ordinal(unsigned long value, std::string* data);
};
namespace conversion
{
- DWORD to_timestamp(std::string data);
+ DWORD to_timestamp(const std::string &data);
std::string to_string(void*, WORD type);
template <class T>