/soc/2015/nakulgulati/main: 9bdc2510a71e: hangouts: channel, gsi...

[email protected]
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 9bdc2510a71e71bf7b52e7c4cfc80a7e6c9e736c
Author:	 Nakul Gulati
Date:	 2015-08-12 04:25 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/9bdc2510a71e

Description:

hangouts: channel, gsid and sid in one request instead of two

diffstat:

 libpurple/protocols/hangouts/channel.c |  61 ++++++---------------------------
 libpurple/protocols/hangouts/channel.h |   3 -
 2 files changed, 11 insertions(+), 53 deletions(-)

diffs (109 lines):

diff --git a/libpurple/protocols/hangouts/channel.c b/libpurple/protocols/hangouts/channel.c
--- a/libpurple/protocols/hangouts/channel.c
+++ b/libpurple/protocols/hangouts/channel.c
@@ -82,67 +82,24 @@ hangouts_channel_set_access_token (Hango
 }
 
 static void
-hangouts_channel_get_sid_cb (PurpleHttpConnection *http_conn,
-			     PurpleHttpResponse *response, gpointer *user_data)
-{
-  HangoutsChannel *channel;
-  gchar *res;
-  JsonNode *node;
-
-  channel = user_data;
-  res = purple_http_response_get_data (response, NULL);
-
-  node = hangouts_json_node_new (res, -1, FALSE);
-
-  purple_debug_misc ("hangouts-channel", "sid res: %s", res);
-}
-
-void
-hangouts_channel_get_sid (HangoutsChannel *channel)
-{
-  HangoutsChannelPrivate *priv;
-  PurpleHttpRequest *request;
-  gchar *params;
-
-  priv = channel->priv;
-
-  params = g_strdup_printf ("?ctype=hangouts"
-			    "&RID=81187"
-			    "&VER=8"
-			    "&gessionid=%s",
-			    priv->gession_id);
-  request = purple_http_request_new (
-      g_strdup_printf ("%s%s%s", HANGOUTS_CHANNEL_URL, "channel/bind", params));
-
-  purple_http_request_set_method (request, "POST");
-  purple_http_request_set_max_len (request, -1);
-  purple_http_request_set_cookie_jar (request, priv->cj);
-  purple_http_request_header_add (
-      request, "Authorization",
-      g_strdup_printf ("Bearer %s", priv->access_token));
-  purple_http_request (priv->gc, request, hangouts_channel_get_sid_cb, channel);
-}
-
-static void
 hangouts_channel_get_gsid_cb (PurpleHttpConnection *http_conn,
-			      PurpleHttpResponse *response, gpointer *user_data)
+			      PurpleHttpResponse *response, gpointer user_data)
 {
   /*[
-   * 12880, expires_in
-   * "<gsid>" gsid
+   * [0,["c","<sid>","",8]],
+   * [1,[{"gsid":"<gsid>"}]]
    * ]
    */
   gchar *res_raw;
-  gchar *gsid;
   JsonNode *node;
   HangoutsChannel *channel;
 
   channel = user_data;
   res_raw = purple_http_response_get_data (response, NULL);
   node = hangouts_json_node_new (res_raw, -1, FALSE);
-  channel->priv->gession_id = hangouts_json_node_get_str (node, "$[1]", NULL);
+  channel->priv->sid = hangouts_json_node_get_str (node, "$[0][1][1]", NULL);
+  channel->priv->gession_id = hangouts_json_node_get_str(node, "$[1][1][0].gsid", NULL);
   purple_debug_misc ("hangouts-channel", "gsid: %s", channel->priv->gession_id);
-  hangouts_channel_get_sid (channel);
 
   json_node_free (node);
 }
@@ -152,13 +109,17 @@ hangouts_channel_get_gsid (HangoutsChann
 {
   HangoutsChannelPrivate *priv;
   PurpleHttpRequest *request;
+  gchar *end_point;
+  gchar *params;
 
   priv = channel->priv;
+  end_point = "channel/bind";
+  params = g_strdup_printf ("?VER=8&RID=81187&ctype=hangouts");
 
   request = purple_http_request_new (
-      g_strdup_printf ("%s%s", HANGOUTS_CHANNEL_URL, "gsid"));
+      g_strconcat (HANGOUTS_CHANNEL_URL, end_point, params));
 
-  purple_http_request_set_method (request, "GET");
+  purple_http_request_set_method (request, "POST");
   purple_http_request_set_max_len (request, -1);
   purple_http_request_set_cookie_jar (request, priv->cj);
   purple_http_request_header_add (
diff --git a/libpurple/protocols/hangouts/channel.h b/libpurple/protocols/hangouts/channel.h
--- a/libpurple/protocols/hangouts/channel.h
+++ b/libpurple/protocols/hangouts/channel.h
@@ -39,9 +39,6 @@ HangoutsChannel *
 hangouts_channel_new (PurpleConnection *gc);
 
 void
-hangouts_channel_get_sid (HangoutsChannel *channel);
-
-void
 hangouts_channel_get_gsid (HangoutsChannel *channel);
 
 #endif /* _HANGOUTS_CHANNEL_H_ */

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.