From 12700d9f44720743b82b9129ca16073e4418a362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Fri, 12 Jul 2013 14:12:18 +0000 Subject: Facebook: - added ability to search friends by ID or username - fixed crash when using AddContactPlus git-svn-id: http://svn.miranda-ng.org/main/trunk@5341 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/communication.cpp | 14 +++++- protocols/FacebookRM/src/constants.h | 11 +++-- protocols/FacebookRM/src/process.cpp | 78 +++++++++++++++++++++++++----- protocols/FacebookRM/src/proto.cpp | 36 ++++++++------ protocols/FacebookRM/src/proto.h | 1 + protocols/FacebookRM/src/utils.cpp | 4 +- protocols/FacebookRM/src/utils.h | 2 +- 7 files changed, 110 insertions(+), 36 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index c1b012672f..5ef0009d30 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -225,6 +225,7 @@ DWORD facebook_client::choose_security_level(RequestType request_type) // case REQUEST_DTSG: // case REQUEST_BUDDY_LIST: // case REQUEST_LOAD_FRIENDS: +// case REQUEST_USER_INFO: // case REQUEST_LOAD_REQUESTS: // case REQUEST_SEARCH: // case REQUEST_DELETE_FRIEND: @@ -282,7 +283,8 @@ int facebook_client::choose_method(RequestType request_type) // case REQUEST_FEEDS: // case REQUEST_NOTIFICATIONS: // case REQUEST_RECONNECT: -// case REQUEST_LOAD_FRIENDS: +// case REQUEST_LOAD_FRIENDS: +// case REQUEST_USER_INFO: // case REQUEST_LOAD_REQUESTS: // case REQUEST_SEARCH: // case REQUEST_UNREAD_THREADS: @@ -322,6 +324,7 @@ std::string facebook_client::choose_server(RequestType request_type, std::string case REQUEST_SEARCH: case REQUEST_UNREAD_THREADS: case REQUEST_UNREAD_MESSAGES: + case REQUEST_USER_INFO: return FACEBOOK_SERVER_MOBILE; // case REQUEST_LOGOUT: @@ -378,6 +381,15 @@ std::string facebook_client::choose_action(RequestType request_type, std::string return action; } + case REQUEST_USER_INFO: + { + std::string action = "/%s?v=info"; + if (get_data != NULL) { + utils::text::replace_all(&action, "%s", *get_data); + } + return action; + } + case REQUEST_LOAD_REQUESTS: { return "/friends/"; diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 764dadcda2..9fa288bb7b 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -94,16 +94,17 @@ enum RequestType { REQUEST_LOAD_REQUESTS, // getting friend requests REQUEST_STATUS_SET, // setting my "What's on my mind?" - REQUEST_SEARCH, // searching + REQUEST_SEARCH, // searching REQUEST_POKE, // sending pokes REQUEST_NOTIFICATIONS_READ, // marking notifications read REQUEST_BUDDY_LIST, // getting regular updates (friends online, ...) REQUEST_LOAD_FRIENDS, // getting list of all friends - REQUEST_REQUEST_FRIEND, // requesting friends - REQUEST_APPROVE_FRIEND, // approving friends - REQUEST_DELETE_FRIEND, // deleting friends - REQUEST_CANCEL_REQUEST, // canceling friends request + REQUEST_USER_INFO, // getting info about particular user + REQUEST_REQUEST_FRIEND, // requesting friendships + REQUEST_APPROVE_FRIEND, // approving friendships + REQUEST_DELETE_FRIEND, // deleting friendships + REQUEST_CANCEL_REQUEST, // canceling friendship request REQUEST_MESSAGE_SEND, // sending message REQUEST_MESSAGE_SEND2, // sending message through inbox diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 3338d5de34..3212fe1bc5 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -771,11 +771,11 @@ void FacebookProto::SearchAckThread(void *targ) if (id.empty() || id == facy.self_.user_id) continue; - TCHAR* tid = mir_utf8decodeT(id.c_str()); - TCHAR* tname = mir_utf8decodeT(name.c_str()); - TCHAR* tsurname = mir_utf8decodeT(surname.c_str()); - TCHAR* tnick = mir_utf8decodeT(nick.c_str()); - TCHAR* tcommon = mir_utf8decodeT(common.c_str()); + ptrT tid = mir_utf8decodeT(id.c_str()); + ptrT tname = mir_utf8decodeT(utils::text::special_expressions_decode(name).c_str()); + ptrT tsurname = mir_utf8decodeT(utils::text::special_expressions_decode(surname).c_str()); + ptrT tnick = mir_utf8decodeT(utils::text::special_expressions_decode(nick).c_str()); + ptrT tcommon = mir_utf8decodeT(utils::text::special_expressions_decode(common).c_str()); PROTOSEARCHRESULT isr = {0}; isr.cbSize = sizeof(isr); @@ -787,15 +787,9 @@ void FacebookProto::SearchAckThread(void *targ) isr.email = tcommon; ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, targ, (LPARAM)&isr); - - mir_free(tid); - mir_free(tnick); - mir_free(tname); - mir_free(tsurname); - mir_free(tcommon); } - ssid = utils::text::source_get_value(&items, 3, "id=\"more_objects\"", "ssid=", "&"); + ssid = utils::text::source_get_value(&items, 3, "id=\"more_objects\"", "ssid=", "&"); if (ssid.empty()) break; // No more results } @@ -808,3 +802,63 @@ void FacebookProto::SearchAckThread(void *targ) mir_free(targ); mir_free(arg); } + +void FacebookProto::SearchIdAckThread(void *targ) +{ + facy.handle_entry("searchIdAckThread"); + + char *arg = mir_utf8encodeT((TCHAR*)targ); + std::string search = utils::url::encode(arg); + + if (!isOffline()) + { + http::response resp = facy.flap(REQUEST_USER_INFO, NULL, &search); + + if (resp.code == HTTP_CODE_FOUND && resp.headers.find("Location") != resp.headers.end()) { + search = utils::text::source_get_value2(&resp.headers["Location"], FACEBOOK_SERVER_MOBILE"/", "?", true); + resp = facy.flap(REQUEST_USER_INFO, NULL, &search); + } + + facy.validate_response(&resp); + + if (resp.code == HTTP_CODE_OK) + { + std::string about = utils::text::source_get_value(&resp.data, 2, "
", "id, CP_UTF8); - char *name = mir_t2a_cp(psr->firstName, CP_UTF8); - char *surname = mir_t2a_cp(psr->lastName, CP_UTF8); + ptrA id = mir_t2a_cp(psr->id, CP_UTF8); + ptrA name = mir_t2a_cp(psr->firstName, CP_UTF8); + ptrA surname = mir_t2a_cp(psr->lastName, CP_UTF8); facebook_user fbu; fbu.user_id = id; - fbu.real_name = name; - fbu.real_name += " "; - fbu.real_name += surname; + if (name != NULL) + fbu.real_name = name; + if (surname != NULL) { + fbu.real_name += " "; + fbu.real_name += surname; + } HANDLE hContact = AddToContactList(&fbu, CONTACT_NONE); if (hContact) { @@ -255,10 +263,6 @@ HANDLE FacebookProto::AddToList(int flags, PROTOSEARCHRESULT* psr) } } - mir_free(id); - mir_free(name); - mir_free(surname); - return hContact; } diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index e36af93199..0352945043 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -150,6 +150,7 @@ public: void __cdecl ProcessNotifications(void*); void __cdecl ProcessFriendRequests(void*); void __cdecl SearchAckThread(void*); + void __cdecl SearchIdAckThread(void*); // Worker threads void __cdecl SignOn(void*); diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp index 44de994a73..6851154a89 100644 --- a/protocols/FacebookRM/src/utils.cpp +++ b/protocols/FacebookRM/src/utils.cpp @@ -405,7 +405,7 @@ std::string utils::text::source_get_value(std::string* data, unsigned int argume return ret; } -std::string utils::text::source_get_value2(std::string* data, const char *term, const char *endings) +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; @@ -417,6 +417,8 @@ std::string utils::text::source_get_value2(std::string* data, const char *term, end = data->find_first_of(endings, start); if (end != std::string::npos) { ret = data->substr(start, end - start); + } else if (wholeString) { + ret = data->substr(start); } } diff --git a/protocols/FacebookRM/src/utils.h b/protocols/FacebookRM/src/utils.h index c0c8e680d3..b794290195 100644 --- a/protocols/FacebookRM/src/utils.h +++ b/protocols/FacebookRM/src/utils.h @@ -62,7 +62,7 @@ namespace utils std::string slashu_to_utf8(std::string data); std::string trim(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); + std::string source_get_value2(std::string* data, const char *term, const char *endings, bool wholeString = false); void explode(std::string str, std::string separator, std::vector* results); void append_ordinal(unsigned long value, std::string* data); }; -- cgit v1.2.3