/soc/2015/nakulgulati/main: ea8f530f9d28: hangouts: pvt token pa...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Thu Aug 6 22:26:34 EDT 2015


Changeset: ea8f530f9d28a6bfb34fa2912aacea491544425f
Author:	 Nakul Gulati
Date:	 2015-08-07 10:26 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/ea8f530f9d28

Description:

hangouts: pvt token parse, linked chat init parser

diffstat:

 libpurple/protocols/hangouts/api.c |  63 ++++++++++++++++---------------------
 1 files changed, 28 insertions(+), 35 deletions(-)

diffs (144 lines):

diff --git a/libpurple/protocols/hangouts/api.c b/libpurple/protocols/hangouts/api.c
--- a/libpurple/protocols/hangouts/api.c
+++ b/libpurple/protocols/hangouts/api.c
@@ -216,7 +216,7 @@ hangouts_api_fetch_cookies_cb (PurpleHtt
 							     "Set-Cookie");
   hangouts_api_parse_header (priv->cookies, headers);
 
-  //hangouts_api_get_private_token (api);
+  hangouts_api_get_private_token (api);
 }
 
 void
@@ -234,17 +234,12 @@ hangouts_api_fetch_login_cookies (Hangou
   username = purple_account_get_username (acct);
   password = purple_connection_get_password (gc);
 
-  url = "https://accounts.google.com/ServiceLoginAuth";
-  /*request_body = g_strdup_printf ("&PersistentCookie=yes"
-   "&Email=%s"
-   "&Passwd=%s"
-   "&GALX=%s",
-   username, password, priv->cookies->GALX);*/
-  request_body =
-      g_strdup_printf (
-	  "GALX=%s&continue=https://talkgadget.google.com/talkgadget/gauth?verify=true&skipvpage=true&_utf8=☃&bgresponse=js_disabled&pstMsg=0&dnConn=&checkConnection=&checkedDomains=youtube&Email=nakul.gulati@st.niituniversity.in&Passwd=glukan4294&signIn=Přihlásit se&PersistentCookie=yes&rmShown=1",
-	  priv->cookies->GALX);
-  request = purple_http_request_new (url);
+  request_body = g_strdup_printf ("&PersistentCookie=yes"
+				  "&Email=%s"
+				  "&Passwd=%s"
+				  "&GALX=%s",
+				  username, password, priv->cookies->GALX);
+  request = purple_http_request_new (HANGOUTS_API_LOGIN_URL);
 
   purple_http_request_set_method (request, "POST");
   purple_http_request_set_max_len (request, -1);
@@ -284,10 +279,8 @@ hangouts_api_get_galx_cookie (HangoutsAp
 
   priv = api->priv;
   gc = priv->gc;
-  /*url = "https://accounts.google.com/ServiceLogin?service=ah&passive=true";*/
-  url =
-      "https://accounts.google.com/ServiceLogin?passive=true&skipvpage=true&continue=https://talkgadget.google.com/talkgadget/gauth?verify%3Dtrue&authuser=0";
-  request = purple_http_request_new (url);
+
+  request = purple_http_request_new (HANGOUTS_API_GALX_COOKIE_URL);
   cookieJar = purple_http_cookie_jar_new ();
 
   purple_http_request_set_method (request, "GET");
@@ -341,7 +334,6 @@ hangouts_api_auth_with_code (HangoutsApi
 
   priv = api->priv;
   gc = priv->gc;
-  request = purple_http_request_new (HANGOUTS_API_OAUTH2_TOKEN_URL);
 
   request_data = g_strdup_printf (
       "client_id=%s&"
@@ -352,6 +344,7 @@ hangouts_api_auth_with_code (HangoutsApi
       HANGOUTS_API_OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE,
       HANGOUTS_API_OAUTH2_REDIRECT_URI);
 
+  request = purple_http_request_new (HANGOUTS_API_OAUTH2_TOKEN_URL);
   purple_http_request_set_method (request, "POST");
   purple_http_request_header_set (request, "Content-Type",
 				  "application/x-www-form-urlencoded");
@@ -365,27 +358,38 @@ hangouts_api_get_private_token_cb (Purpl
 				   PurpleHttpResponse *response,
 				   gpointer user_data)
 {
+  HangoutsApi *api;
   gchar *raw_res;
+  gchar *start, *end, *pvt;
 
+  api = user_data;
   raw_res = purple_http_response_get_data (response, NULL);
 
   purple_debug_misc ("hangouts_prpl", "res: %s", raw_res);
-  //TODO parse pvt token
+
+  start = strchr (raw_res, ',');
+  start += 2;
+  end = strchr (start, ',');
+  end--;
+
+  api->priv->pvt_token = g_strndup (start, end - start);
+
+  purple_debug_misc ("hangouts_prpl", "pvt: %s", api->priv->pvt_token);
+
+  hangouts_api_get_chat_init (api);
+
 }
 
 void
 hangouts_api_get_private_token (HangoutsApi *api)
 {
   HangoutsApiPrivate *priv;
-  HangoutsApiCookies *cookies;
   PurpleConnection *gc;
   PurpleHttpRequest *request;
 
   priv = api->priv;
   gc = priv->gc;
-  cookies = priv->cookies;
-  request = purple_http_request_new (
-      "https://talkgadget.google.com/talkgadget/_/extension-start");
+  request = purple_http_request_new (HANGOUTS_API_PVT_TOKEN_URL);
 
   purple_http_request_set_method (request, "GET");
   purple_http_request_header_add (
@@ -413,14 +417,12 @@ void
 hangouts_api_get_chat_init (HangoutsApi *api)
 {
   HangoutsApiPrivate *priv;
-  HangoutsApiCookies *cookies;
   PurpleConnection *gc;
   PurpleHttpRequest *request;
   const gchar *url_with_param;
 
   priv = api->priv;
   gc = priv->gc;
-  cookies = priv->cookies;
 
   url_with_param = g_strconcat (HANGOUTS_API_CHAT_INIT_URL, "?",
 				HANGOUTS_API_CHAT_INIT_PARAMS(priv->pvt_token));
@@ -429,17 +431,8 @@ hangouts_api_get_chat_init (HangoutsApi 
   purple_http_request_set_method (request, "GET");
   purple_http_request_set_max_len (request, -1);
   purple_http_request_header_add (
-      request, "Cookie", g_strdup_printf ("APISID %s", cookies->APISID));
-  purple_http_request_header_add (request, "Cookie",
-				  g_strdup_printf ("HSID %s", cookies->HSID));
-  purple_http_request_header_add (request, "Cookie",
-				  g_strdup_printf ("NID %s", cookies->NID));
-  purple_http_request_header_add (
-      request, "Cookie", g_strdup_printf ("SAPISID %s", cookies->SAPISID));
-  purple_http_request_header_add (request, "Cookie",
-				  g_strdup_printf ("SID %s", cookies->SID));
-  purple_http_request_header_add (request, "Cookie",
-				  g_strdup_printf ("SSID %s", cookies->SSID));
+      request, "Authorization",
+      g_strdup_printf ("Bearer %s", priv->access_token));
   purple_http_request (gc, request, hangouts_api_get_chat_init_cb, api);
 
 }



More information about the Commits mailing list