/soc/2015/nakulgulati/main: ba945ddc9be5: hangouts: json wrapper...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Mon Aug 10 08:30:57 EDT 2015


Changeset: ba945ddc9be5e87bb2767810104a421d8ca72c84
Author:	 Nakul Gulati
Date:	 2015-08-10 20:30 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/ba945ddc9be5

Description:

hangouts: json wrapper begin

diffstat:

 libpurple/protocols/hangouts/Makefile.am    |   2 ++
 libpurple/protocols/hangouts/Makefile.mingw |   1 +
 libpurple/protocols/hangouts/api.c          |  16 +++++++++++++---
 libpurple/protocols/hangouts/channel.c      |  22 +++++++++++++++++-----
 4 files changed, 33 insertions(+), 8 deletions(-)

diffs (139 lines):

diff --git a/libpurple/protocols/hangouts/Makefile.am b/libpurple/protocols/hangouts/Makefile.am
--- a/libpurple/protocols/hangouts/Makefile.am
+++ b/libpurple/protocols/hangouts/Makefile.am
@@ -12,6 +12,8 @@ HANGOUTSSOURCES = \
 	channel.c \
 	hangouts.h \
 	hangouts.c \
+	json.h \
+	json.c \
 	util.h \
 	util.c 
 
diff --git a/libpurple/protocols/hangouts/Makefile.mingw b/libpurple/protocols/hangouts/Makefile.mingw
--- a/libpurple/protocols/hangouts/Makefile.mingw
+++ b/libpurple/protocols/hangouts/Makefile.mingw
@@ -42,6 +42,7 @@ C_SRC =	\
 			auth.c
 			channel.c
 			hangouts.c
+			json.c
 			util.c
 
 OBJECTS = $(C_SRC:%.c=%.o)
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
@@ -26,6 +26,7 @@
 #include "http.h"
 
 #include "api.h"
+#include "channel.h"
 #include "util.h"
 //TODO api call backs
 
@@ -59,6 +60,8 @@ struct _HangoutsApiPrivate
   PurpleConnection *gc;
   PurpleHttpCookieJar *cookie_jar;
 
+  HangoutsChannel *channel;
+
   HangoutsApiCookies *cookies;
   HangoutsApiOAuthData *oauth_data;
 
@@ -130,6 +133,7 @@ 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->oauth_data = g_new0(HangoutsApiOAuthData, 1);
   priv->gc = gc;
@@ -284,10 +288,12 @@ hangouts_api_auth_with_code_cb (PurpleHt
   JsonParser *parser;
   JsonObject *json_ob;
   HangoutsApi *api;
+  HangoutsApiPrivate *priv;
   HangoutsApiOAuthData *oauth_data;
   gchar *error, *access_token, *refresh_token;
 
   api = user_data;
+  priv = api->priv;
   oauth_data = api->priv->oauth_data;
   gchar *raw_res = purple_http_response_get_data (response, NULL);
   purple_debug_misc ("hangouts-prpl", "raw:\n%s", raw_res);
@@ -300,14 +306,18 @@ hangouts_api_auth_with_code_cb (PurpleHt
     error = json_object_get_string_member (json_ob, "error");
 
   if (json_object_has_member (json_ob, "access_token"))
-    api->priv->access_token = g_strdup (
-	json_object_get_string_member (json_ob, "access_token"));
+    {
+      priv->access_token = g_strdup (
+	  json_object_get_string_member (json_ob, "access_token"));
+      hangouts_channel_set_access_token (priv->channel, priv->access_token);
+    }
 
   if (json_object_has_member (json_ob, "refresh_token"))
     oauth_data->refresh_token = g_strdup (
 	json_object_get_string_member (json_ob, "refresh_token"));
 
-  hangouts_api_get_private_token (api);
+  //hangouts_api_get_private_token (api);
+  hangouts_channel_get_gsid (api->priv->channel);
 }
 
 void
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
@@ -5,6 +5,7 @@
 
 #include "channel.h"
 #include "api.h"
+#include "json.h"
 
 struct _HangoutsChannelPrivate
 {
@@ -84,11 +85,21 @@ static void
 hangouts_channel_get_gsid_cb (PurpleHttpConnection *http_conn,
 			      PurpleHttpResponse *response, gpointer *data)
 {
-  purple_debug_misc("hangouts-channel", "gsid callback");
+  /*[
+   * 12880, expires_in
+   * "<gsid>" gsid
+   * ]
+   */
+  gchar *res_raw;
+  gchar *gsid;
+  JsonNode *node;
+  HangoutsChannel *channel;
 
-  gchar *res_raw = purple_http_response_get_data(response, NULL);
+  channel = 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);
 
-  purple_debug_misc("hangouts-channel", "response: %s", res_raw);
 }
 
 void
@@ -100,7 +111,7 @@ hangouts_channel_get_gsid (HangoutsChann
   priv = channel->priv;
 
   request = purple_http_request_new (
-      g_strdup_printf ("%s%s",HANGOUTS_CHANNEL_URL, "gsid"));
+      g_strdup_printf ("%s%s", HANGOUTS_CHANNEL_URL, "gsid"));
 
   purple_http_request_set_method (request, "GET");
   purple_http_request_set_max_len (request, -1);
@@ -108,5 +119,6 @@ hangouts_channel_get_gsid (HangoutsChann
   purple_http_request_header_add (
       request, "Authorization",
       g_strdup_printf ("Bearer %s", priv->access_token));
-  purple_http_request(priv->gc, request, hangouts_channel_get_gsid_cb, channel);
+  purple_http_request (priv->gc, request, hangouts_channel_get_gsid_cb,
+		       channel);
 }



More information about the Commits mailing list