From a28a6ed80c01d5d1e000249e67125ac7dd4c0b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 16 Dec 2015 11:43:35 +0000 Subject: Facebook: Fix login for some other people too (parsing also differently specified cookies) git-svn-id: http://svn.miranda-ng.org/main/trunk@15873 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/communication.cpp | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'protocols/FacebookRM/src') diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 047a71a0d9..98e49ae0d9 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -727,6 +727,27 @@ 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 &cookies) { + std::string::size_type pos = 0; + while ((pos = data.find(search, pos)) != std::string::npos) { + pos += search.length(); + + std::string::size_type pos2 = data.find("\",\"", pos); + if (pos2 == std::string::npos) + continue; + + std::string name = data.substr(pos, pos2 - pos); + + pos = pos2 + 3; + pos2 = data.find("\"", pos); + if (pos2 == std::string::npos) + continue; + + std::string value = data.substr(pos, pos2 - pos); + cookies[name] = utils::text::html_entities_decode(value); + } +} + bool facebook_client::login(const char *username, const char *password) { handle_entry("login"); @@ -743,25 +764,9 @@ bool facebook_client::login(const char *username, const char *password) // Get initial cookies http::response resp = flap(REQUEST_LOGIN); - // Also parse deferred cookies set by JavaScript - std::string::size_type pos = 0; - while ((pos = resp.data.find("[\"DeferredCookie\",\"addToQueue\",[],[\"", pos)) != std::string::npos) { - pos += 36; - - std::string::size_type pos2 = resp.data.find("\",\"", pos); - if (pos2 == std::string::npos) - continue; - - std::string name = resp.data.substr(pos, pos2 - pos); - - pos = pos2 + 3; - pos2 = resp.data.find("\"", pos); - if (pos2 == std::string::npos) - continue; - - std::string value = resp.data.substr(pos, pos2 - pos); - cookies[name] = utils::text::html_entities_decode(value); - } + // Also parse cookies set by JavaScript (more variant exists in time, so check all known now) + parseJsCookies("[\"DeferredCookie\",\"addToQueue\",[],[\"", resp.data, cookies); + parseJsCookies("[\"Cookie\",\"setIfFirstPartyContext\",[],[[\"", resp.data, cookies); } // Prepare login data -- cgit v1.2.3