summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/FacebookRM/src/entities.h2
-rw-r--r--protocols/FacebookRM/src/json.cpp54
-rw-r--r--protocols/FacebookRM/src/utils.cpp4
-rw-r--r--protocols/FacebookRM/src/utils.h4
4 files changed, 40 insertions, 24 deletions
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h
index 38869e326c..26f64e79c1 100644
--- a/protocols/FacebookRM/src/entities.h
+++ b/protocols/FacebookRM/src/entities.h
@@ -31,7 +31,7 @@ struct facebook_user
unsigned int status_id;
unsigned int gender;
- unsigned int last_active;
+ DWORD last_active;
std::string image_url;
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp
index d6b7bfb8cd..2cdec7824a 100644
--- a/protocols/FacebookRM/src/json.cpp
+++ b/protocols/FacebookRM/src/json.cpp
@@ -32,12 +32,16 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user
return EXIT_FAILURE;
JSONNODE *payload = json_get(root, "payload");
- if (payload == NULL)
+ if (payload == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
JSONNODE *list = json_get(payload, "buddy_list");
- if (list == NULL)
+ if (list == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
// Set all contacts in map to offline
for (List::Item< facebook_user >* i = buddy_list->begin(); i != NULL; i = i->next) {
@@ -64,10 +68,10 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user
// Find mobile friends
JSONNODE *mobileFriends = json_get(list, "mobile_friends");
- if (mobileFriends != NULL) {
+ if (mobileFriends != NULL) {
for (unsigned int i = 0; i < json_size(mobileFriends); i++) {
JSONNODE *it = json_at(mobileFriends, i);
- char *id = json_name(it);
+ char *id = json_as_string(it);
current = buddy_list->find(id);
if (current == NULL) {
@@ -125,7 +129,6 @@ int facebook_json_parser::parse_buddy_list(void* data, List::List< facebook_user
}
json_delete(root);
-
return EXIT_SUCCESS;
}
@@ -138,8 +141,10 @@ int facebook_json_parser::parse_friends(void* data, std::map< std::string, faceb
return EXIT_FAILURE;
JSONNODE *payload = json_get(root, "payload");
- if (payload == NULL)
+ if (payload == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
for (unsigned int i = 0; i < json_size(payload); i++) {
JSONNODE *it = json_at(payload, i);
@@ -174,6 +179,7 @@ int facebook_json_parser::parse_friends(void* data, std::map< std::string, faceb
friends->insert(std::make_pair(id, fbu));
}
+ json_delete(root);
return EXIT_SUCCESS;
}
@@ -187,12 +193,16 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_
return EXIT_FAILURE;
JSONNODE *payload = json_get(root, "payload");
- if (payload == NULL)
+ if (payload == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
JSONNODE *list = json_get(payload, "notifications");
- if (list == NULL)
+ if (list == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
for (unsigned int i = 0; i < json_size(list); i++) {
JSONNODE *it = json_at(list, i);
@@ -217,6 +227,7 @@ int facebook_json_parser::parse_notifications(void *data, std::vector< facebook_
notifications->push_back(notification);
}
+ json_delete(root);
return EXIT_SUCCESS;
}
@@ -238,14 +249,16 @@ bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text) {
int facebook_json_parser::parse_messages(void* data, std::vector< facebook_message* >* messages, std::vector< facebook_notification* >* notifications)
{
std::string jsonData = static_cast< std::string* >(data)->substr(9);
-
+
JSONNODE *root = json_parse(jsonData.c_str());
if (root == NULL)
return EXIT_FAILURE;
JSONNODE *ms = json_get(root, "ms");
- if (ms == NULL)
+ if (ms == NULL) {
+ json_delete(root);
return EXIT_FAILURE;
+ }
for (unsigned int i = 0; i < json_size(ms); i++) {
JSONNODE *it = json_at(ms, i);
@@ -311,7 +324,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
dbei.szModule = proto->m_szModuleName;
bool local_time = proto->getByte(FACEBOOK_KEY_LOCAL_TIMESTAMP, 0) != 0;
- dbei.timestamp = local_time || time == NULL ? ::time(NULL) : utils::time::fix_timestamp(json_as_int(time));
+ dbei.timestamp = local_time || time == NULL ? ::time(NULL) : utils::time::fix_timestamp(json_as_float(time));
dbei.cbBlob = (DWORD)message_text.length() + 1;
dbei.pBlob = (PBYTE)message_text.c_str();
@@ -322,7 +335,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
// Incomming message
facebook_message* message = new facebook_message();
message->message_text = message_text;
- message->time = utils::time::fix_timestamp(json_as_int(time));
+ message->time = utils::time::fix_timestamp(json_as_float(time));
message->user_id = from_id;
message->message_id = message_id;
@@ -350,7 +363,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
HANDLE hContact = proto->ContactIDToHContact(json_as_string(reader));
if (hContact) {
TCHAR ttime[64], tstr[100];
- _tcsftime(ttime, SIZEOF(ttime), _T("%X"), utils::conversion::fbtime_to_timeinfo(json_as_int(time)));
+ _tcsftime(ttime, SIZEOF(ttime), _T("%X"), utils::conversion::fbtime_to_timeinfo(json_as_float(time)));
mir_sntprintf(tstr, SIZEOF(tstr), TranslateT("Message read: %s"), ttime);
CallService(MS_MSG_SETSTATUSTEXT, (WPARAM)hContact, (LPARAM)tstr);
@@ -389,7 +402,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
facebook_message* message = new facebook_message();
message->message_text = message_text;
message->sender_name = utils::text::special_expressions_decode(utils::text::slashu_to_utf8(id));
- message->time = utils::time::fix_timestamp(json_as_int(timestamp));
+ message->time = utils::time::fix_timestamp(json_as_float(timestamp));
message->user_id = id; // TODO: Check if we have contact with this ID in friendlist and otherwise do something different?
message->message_id = message_id;
@@ -466,7 +479,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
if (time == NULL || text == NULL || url == NULL || alert_id == NULL)
continue;
- unsigned long timestamp = json_as_int(time);
+ unsigned __int64 timestamp = json_as_float(time);
if (timestamp > proto->facy.last_notification_time_) {
// Only new notifications
proto->facy.last_notification_time_ = timestamp;
@@ -520,17 +533,20 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa
bool isVisible = (visibility != NULL) && json_as_bool(visibility);
proto->Log(" Requested chat switch to %s", isVisible ? "Online" : "Offline");
proto->SetStatus(isVisible ? ID_STATUS_ONLINE : ID_STATUS_INVISIBLE);
- }
+ }
}
else
continue;
}
- // remove received messages from map
- for (std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ++it) {
+ // remove received messages from map
+ for (std::map<std::string, bool>::iterator it = proto->facy.messages_ignore.begin(); it != proto->facy.messages_ignore.end(); ) {
if (it->second)
- proto->facy.messages_ignore.erase(it);
+ it = proto->facy.messages_ignore.erase(it);
+ else
+ ++it;
}
+ json_delete(root);
return EXIT_SUCCESS;
}
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 6851154a89..f0cae3be7e 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -53,7 +53,7 @@ std::string utils::time::mili_timestamp()
return timestamp;
}
-DWORD utils::time::fix_timestamp(double mili_timestamp)
+DWORD utils::time::fix_timestamp(unsigned __int64 mili_timestamp)
{
// If it is really mili_timestamp
if (mili_timestamp > 100000000000) {
@@ -71,7 +71,7 @@ DWORD utils::conversion::to_timestamp(std::string data)
return timestamp;
}
-struct tm *utils::conversion::fbtime_to_timeinfo(double timestamp) {
+struct tm *utils::conversion::fbtime_to_timeinfo(unsigned __int64 timestamp) {
time_t time = utils::time::fix_timestamp(timestamp);
return localtime(&time);
}
diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h
index b794290195..7f2766d91f 100644
--- a/protocols/FacebookRM/src/utils.h
+++ b/protocols/FacebookRM/src/utils.h
@@ -43,7 +43,7 @@ namespace utils
{
std::string unix_timestamp();
std::string mili_timestamp();
- DWORD fix_timestamp(double);
+ DWORD fix_timestamp(unsigned __int64 mili_timestamp);
};
namespace number
@@ -70,7 +70,7 @@ namespace utils
namespace conversion
{
DWORD to_timestamp(std::string data);
- struct tm *fbtime_to_timeinfo(double timestamp);
+ struct tm *fbtime_to_timeinfo(unsigned __int64 timestamp);
std::string to_string(void*, WORD type);
template <class T>