/soc/2015/nakulgulati/main: 6e224ae224ff: hangouts: api get pvt ...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Sat Aug 1 16:20:28 EDT 2015


Changeset: 6e224ae224ffa7adbd759a6b6690109633ba4a03
Author:	 Nakul Gulati
Date:	 2015-08-02 03:57 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/6e224ae224ff

Description:

hangouts: api get pvt token

diffstat:

 libpurple/protocols/hangouts/api.c |  132 +++++++++++++++++++++++++-----------
 libpurple/protocols/hangouts/api.h |   22 +++--
 2 files changed, 105 insertions(+), 49 deletions(-)

diffs (256 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
@@ -34,14 +34,16 @@ enum _HangoutsConversationOffTheRecordSt
   HANGOUTS_OFF_THE_RECORD = 1, HANGOUTS_ON_THE_RECORD = 2
 };
 
-struct _HangoutsApiCookies{
+struct _HangoutsApiCookies
+{
   gchar *APISID;
+  gchar *GALX;
   gchar *HSID;
   gchar *NID;
   gchar *SAPISID;
   gchar *SID;
   gchar *SSID;
-  gchar *test;
+
 };
 
 struct _HangoutsApiPrivate
@@ -50,7 +52,6 @@ struct _HangoutsApiPrivate
   PurpleHttpCookieJar *cookie_jar;
   HangoutsApiCookies *cookies;
 
-  gchar *galx;
   gchar *api_key;
   gchar *access_token;
   gchar *header_date;
@@ -76,10 +77,9 @@ hangouts_api_dispose (GObject *obj)
       purple_http_conn_cancel_all (priv->gc);
     }
 
-  purple_http_cookie_jar_unref(priv->cookie_jar);
+  purple_http_cookie_jar_unref (priv->cookie_jar);
 
-  g_free(priv->cookies);
-  g_free (priv->galx);
+  g_free (priv->cookies);
   g_free (priv->access_token);
   g_free (priv->api_key);
   g_free (priv->client_id);
@@ -113,12 +113,10 @@ hangouts_api_new (PurpleConnection *gc)
 {
   HangoutsApi *api;
   HangoutsApiPrivate *priv;
-  HangoutsApiCookies *cookies;
 
   api = g_object_new (HANGOUTS_TYPE_API, NULL);
   priv = api->priv;
-  cookies = malloc(sizeof(HangoutsApiCookies));
-  priv->cookies = cookies;
+  priv->cookies = g_new0(HangoutsApiCookies, 1);
 
   priv->gc = gc;
 
@@ -130,7 +128,7 @@ hangouts_api_parse_header (HangoutsApiCo
 {
   GList *l;
 
-  for(l = headers; l!=NULL; l=l->next)
+  for (l = headers; l != NULL; l = l->next)
     {
       const gchar *cookie = l->data;
       const gchar *eqsign, *semicolon;
@@ -146,26 +144,32 @@ hangouts_api_parse_header (HangoutsApiCo
       else
 	value = g_strdup (eqsign);
 
-      if(g_str_equal(name, "APISID")){
-	  cookies->APISID = value;
-      }
-      else if(g_str_equal(name, "HSID")){
-	  cookies->HSID = value;
-      }
-      else if(g_str_equal(name, "NID")){
-	  cookies->NID = value;
-      }
-      else if(g_str_equal(name, "SAPISID")){
-	  cookies->SAPISID = value;
-      }
-      else if(g_str_equal(name, "SID")){
-	  cookies->SID = value;
-      }
-      else if(g_str_equal(name, "SSID")){
-	  cookies->SSID = value;
-      }
-      g_free(name);
-      g_free(value);
+      if (g_str_equal (name, "APISID"))
+	{
+	  cookies->APISID = g_strdup (value);
+	}
+      else if (g_str_equal (name, "HSID"))
+	{
+	  cookies->HSID = g_strdup (value);
+	}
+      else if (g_str_equal (name, "NID"))
+	{
+	  cookies->NID = g_strdup (value);
+	}
+      else if (g_str_equal (name, "SAPISID"))
+	{
+	  cookies->SAPISID = g_strdup (value);
+	}
+      else if (g_str_equal (name, "SID"))
+	{
+	  cookies->SID = g_strdup (value);
+	}
+      else if (g_str_equal (name, "SSID"))
+	{
+	  cookies->SSID = g_strdup (value);
+	}
+      g_free (name);
+      g_free (value);
 
     }
 }
@@ -185,6 +189,8 @@ hangouts_api_fetch_cookies_cb (PurpleHtt
   GList *headers = purple_http_response_get_headers_by_name (response,
 							     "Set-Cookie");
   hangouts_api_parse_header (priv->cookies, headers);
+
+  hangouts_api_get_private_token (api);
 }
 
 void
@@ -203,13 +209,11 @@ hangouts_api_fetch_login_cookies (Hangou
   password = purple_connection_get_password (gc);
 
   url = "https://accounts.google.com/ServiceLoginAuth";
-  request_body = g_strdup_printf (
-      "Email=%s"
-      "&Passwd=%s"
-      "&PersistentCookie=yes"
-      "&GALX=%s"
-      "&Page=PasswordSeparationSignIn",
-      username, password, priv->galx);
+  request_body = g_strdup_printf ("&PersistentCookie=yes"
+				  "&Email=%s"
+				  "&Passwd=%s"
+				  "&GALX=%s",
+				  username, password, priv->cookies->GALX);
   request = purple_http_request_new (url);
 
   purple_http_request_set_method (request, "POST");
@@ -231,11 +235,12 @@ hangouts_api_get_galx_cookie_cb (PurpleH
   HangoutsApiPrivate *priv = api->priv;
 
   priv->cookie_jar = purple_http_conn_get_cookie_jar (http_conn);
-  priv->galx = purple_http_cookie_jar_get (priv->cookie_jar, "GALX");
+  priv->cookies->GALX = purple_http_cookie_jar_get (priv->cookie_jar, "GALX");
 
-  purple_debug_misc ("hangouts-prpl", "galx: %s", priv->galx);
-
-  hangouts_api_fetch_login_cookies (api);
+  if (!g_str_equal (priv->cookies->GALX, ""))
+    {
+      hangouts_api_fetch_login_cookies (api);
+    }
 }
 
 void
@@ -258,6 +263,51 @@ hangouts_api_get_galx_cookie (HangoutsAp
   purple_http_request (gc, request, hangouts_api_get_galx_cookie_cb, api);
 }
 
+static void
+hangouts_api_get_private_token_cb (PurpleHttpConnection *http_conn,
+				   PurpleHttpResponse *response,
+				   gpointer user_data)
+{
+  gchar *raw_res;
+
+  raw_res = purple_http_response_get_data (response, NULL);
+
+  purple_debug_misc ("hangouts_prpl", "res: %s", raw_res);
+  //TODO parse pvt token
+}
+
+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 (HANGOUTS_API_PVT_TOKEN_URL);
+
+  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));
+
+  purple_http_request (gc, request, hangouts_api_get_private_token_cb, api);
+
+}
+
 gchar *
 hangouts_api_get_request_header (HangoutsApi *api)
 {
diff --git a/libpurple/protocols/hangouts/api.h b/libpurple/protocols/hangouts/api.h
--- a/libpurple/protocols/hangouts/api.h
+++ b/libpurple/protocols/hangouts/api.h
@@ -24,15 +24,18 @@
 
 #include "connection.h"
 
-#define HANGOUTS_ORIGIN_URL "https://talkgadget.google.com"
-#define HANGOUTS_IMAGE_UPLOAD_URL "http://docs.google.com/upload/photos/resumable"
-#define HANGOUTS_PVT_TOKEN_URL "https://talkgadget.google.com/talkgadget/_/extension-start"
-#define HANGOUTS_CHAT_INIT_URL "https://talkgadget.google.com/u/0/talkgadget/_/chat"
-#define HANGOUTS_API_BASE_URL "https://www.googleapis.com/chat/v1ios/"
+#define HANGOUTS_API_GALX_COOKIE_URL "https://accounts.google.com/ServiceLogin?service=ah&passive=true"
+#define HANGOUTS_API_LOGIN_URL "https://accounts.google.com/ServiceLoginAuth"
 
-#define HANGOUTS_PROP "aChromeExtension"
-#define HANGOUTS_FID "gtn-roster-iframe-id"
-#define HANGOUTS_EC "[\"ci:ec\",true,true,false]"
+#define HANGOUTS_API_ORIGIN_URL "https://talkgadget.google.com"
+#define HANGOUTS_API_IMAGE_UPLOAD_URL "http://docs.google.com/upload/photos/resumable"
+#define HANGOUTS_API_PVT_TOKEN_URL "https://talkgadget.google.com/talkgadget/_/extension-start"
+#define HANGOUTS_API_CHAT_INIT_URL "https://talkgadget.google.com/u/0/talkgadget/_/chat"
+#define HANGOUTS_API_BASE_URL "https://clients6.google.com/chat/v1/"
+
+#define HANGOUTS_API_PROP "aChromeExtension"
+#define HANGOUTS_API_FID "gtn-roster-iframe-id"
+#define HANGOUTS_API_EC "[\"ci:ec\",true,true,false]"
 
 #define HANGOUTS_CHAT_INIT_PARAMS(pvt) g_strdup_printf("prop=%s&fid=%s&ec=%s&pvt=%s",HANGOUTS_PROP,HANGOUTS_FID,HANGOUTS_EC,pvt)
 
@@ -78,6 +81,9 @@ hangouts_api_get_galx_cookie (HangoutsAp
 void
 hangouts_api_fetch_login_cookies (HangoutsApi *api);
 
+void
+hangouts_api_get_private_token(HangoutsApi *api);
+
 gchar *
 hangouts_api_get_request_header (HangoutsApi *api);
 



More information about the Commits mailing list