/soc/2015/nakulgulati/main: c5f0414ecc8f: hangouts: api-dropped ...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Fri Aug 21 23:09:22 EDT 2015


Changeset: c5f0414ecc8ff9a80acb30141419de88abaa74bc
Author:	 Nakul Gulati
Date:	 2015-08-21 06:31 +0530
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/c5f0414ecc8f

Description:

hangouts: api-dropped cookie login flow in favor of OAuth

diffstat:

 libpurple/protocols/hangouts/api.c |  167 +-----------------------------------
 libpurple/protocols/hangouts/api.h |   16 ---
 2 files changed, 6 insertions(+), 177 deletions(-)

diffs (263 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
@@ -48,18 +48,6 @@ enum HangoutsChatInitPathIndex
   HANGOUTS_CHAT_INIT_SYNC_TIMESTAMP = 5
 };
 
-struct _HangoutsApiCookies
-{
-  gchar *APISID;
-  gchar *GALX;
-  gchar *HSID;
-  gchar *NID;
-  gchar *SAPISID;
-  gchar *SID;
-  gchar *SSID;
-
-};
-
 struct _HangoutsApiPrivate
 {
   PurpleConnection *gc;
@@ -67,8 +55,6 @@ struct _HangoutsApiPrivate
 
   HangoutsChannel *channel;
 
-  HangoutsApiCookies *cookies;
-
   JsonNode *chat_init_dict;
 
   gchar *api_key;
@@ -115,7 +101,6 @@ hangouts_api_dispose (GObject *obj)
 
   json_node_free (priv->chat_init_dict);
 
-  g_free (priv->cookies);
   g_free (priv->access_token);
   g_free (priv->api_key);
   g_free (priv->client_id);
@@ -143,12 +128,12 @@ hangouts_api_class_init (HangoutsApiClas
       		NULL);
   
   g_signal_new ("get-chat-init",
-		  G_TYPE_FROM_CLASS(klass),
-		  G_SIGNAL_ACTION, 0,
-		  NULL, NULL,
-		  g_cclosure_marshal_VOID__VOID,
-		  G_TYPE_NONE,
-		  NULL);
+		G_TYPE_FROM_CLASS(klass),
+		G_SIGNAL_ACTION, 0,
+		NULL, NULL,
+		g_cclosure_marshal_VOID__VOID,
+		G_TYPE_NONE,
+		NULL);
 }
 
 static void
@@ -185,7 +170,6 @@ hangouts_api_new (PurpleConnection *gc)
   api = g_object_new (HANGOUTS_TYPE_API, NULL);
   priv = api->priv;
   priv->channel = hangouts_channel_new (gc);
-  priv->cookies = g_new0(HangoutsApiCookies, 1);
   priv->gc = gc;
 
   g_signal_connect(priv->channel, "connect",
@@ -215,144 +199,6 @@ hangouts_api_get_connection (HangoutsApi
   return gc;
 }
 
-void
-hangouts_api_parse_header (HangoutsApiCookies *cookies, GList *headers)
-{
-  GList *l;
-
-  for (l = headers; l != NULL; l = l->next)
-    {
-      const gchar *cookie = l->data;
-      const gchar *eqsign, *semicolon;
-      gchar *name, *value;
-
-      eqsign = strchr (cookie, '=');
-      semicolon = strchr (cookie, ';');
-
-      name = g_strndup (cookie, eqsign - cookie);
-      eqsign++;
-      if (semicolon != NULL)
-	value = g_strndup (eqsign, semicolon - eqsign);
-      else
-	value = g_strdup (eqsign);
-
-      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);
-
-    }
-}
-
-static void
-hangouts_api_fetch_cookies_cb (PurpleHttpConnection *http_conn,
-			       PurpleHttpResponse *response, gpointer user_data)
-{
-  HangoutsApi *api;
-  HangoutsApiPrivate *priv;
-
-  api = user_data;
-  priv = api->priv;
-
-  PurpleHttpCookieJar *cj = purple_http_conn_get_cookie_jar (http_conn);
-
-  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
-hangouts_api_fetch_login_cookies (HangoutsApi *api)
-{
-  PurpleConnection *gc;
-  PurpleAccount *acct;
-  PurpleHttpRequest *request;
-  HangoutsApiPrivate *priv;
-  gchar *username, *password, *request_body;
-
-  priv = api->priv;
-  gc = priv->gc;
-  acct = purple_connection_get_account (gc);
-  username = purple_account_get_username (acct);
-  password = purple_connection_get_password (gc);
-
-  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);
-  purple_http_request_header_add (request, "Content-Type",
-				  "application/x-www-form-urlencoded");
-  purple_http_request_set_contents (request, request_body, -1);
-  purple_http_request_set_cookie_jar (request, priv->cookie_jar);
-  purple_http_request_set_max_redirects (request, 0);
-  purple_http_request (gc, request, hangouts_api_fetch_cookies_cb, api);
-}
-
-static void
-hangouts_api_get_galx_cookie_cb (PurpleHttpConnection *http_conn,
-				 PurpleHttpResponse *response,
-				 gpointer user_data)
-{
-  HangoutsApi *api = user_data;
-  HangoutsApiPrivate *priv = api->priv;
-
-  priv->cookie_jar = purple_http_conn_get_cookie_jar (http_conn);
-  priv->cookies->GALX = purple_http_cookie_jar_get (priv->cookie_jar, "GALX");
-
-  if (!g_str_equal (priv->cookies->GALX, ""))
-    {
-      hangouts_api_fetch_login_cookies (api);
-    }
-}
-
-void
-hangouts_api_get_galx_cookie (HangoutsApi *api)
-{
-  PurpleHttpRequest *request;
-  PurpleHttpCookieJar *cookieJar;
-  HangoutsApiPrivate *priv;
-  PurpleConnection *gc;
-
-  priv = api->priv;
-  gc = priv->gc;
-
-  request = purple_http_request_new (HANGOUTS_API_GALX_COOKIE_URL);
-  cookieJar = purple_http_cookie_jar_new ();
-
-  purple_http_request_set_method (request, "GET");
-  purple_http_request_set_cookie_jar (request, cookieJar);
-  purple_http_request (gc, request, hangouts_api_get_galx_cookie_cb, api);
-}
-
 static void
 hangouts_api_auth_with_code_cb (PurpleHttpConnection *http_conn,
 				PurpleHttpResponse *response,
@@ -784,4 +630,3 @@ hangouts_api_setactiveclient (HangoutsAp
 
   hangouts_api_request (api, &info, FALSE, body);
 }
-
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
@@ -45,9 +45,6 @@ response_type=code\
 #define HANGOUTS_API_OAUTH2_GRANT_TYPE_AUTHORIZATION_CODE "authorization_code"
 #define HANGOUTS_API_OAUTH2_GRANT_TYPE_REFRESH_CODE "refresh_token"
 
-#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_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"
@@ -74,7 +71,6 @@ typedef struct _HangoutsApi HangoutsApi;
 typedef struct _HangoutsApiClass HangoutsApiClass;
 typedef struct _HangoutsApiPrivate HangoutsApiPrivate;
 typedef struct _HangoutsApiHttpInfo HangoutsApiHttpInfo;
-typedef struct _HangoutsApiCookies HangoutsApiCookies;
 
 struct _HangoutsApi
 {
@@ -99,15 +95,6 @@ hangouts_api_set_refresh_token (Hangouts
 PurpleConnection *
 hangouts_api_get_connection(HangoutsApi *api);
 
-HangoutsApi *
-hangouts_api_new_from_oauth (PurpleConnection *gc, gchar *access_token);
-
-void
-hangouts_api_parse_header (HangoutsApiCookies *cookies, GList *headers);
-
-void
-hangouts_api_get_galx_cookie (HangoutsApi *api);
-
 void
 hangouts_api_auth_with_code (HangoutsApi *api, gchar *auth_code);
 
@@ -115,9 +102,6 @@ void
 hangouts_api_oauth_refresh_token (HangoutsApi *api);
 
 void
-hangouts_api_fetch_login_cookies (HangoutsApi *api);
-
-void
 hangouts_api_get_private_token (HangoutsApi *api);
 
 void



More information about the Commits mailing list