/soc/2015/nakulgulati/main: 492f466b53c5: hangouts: api chat dat...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Sat Aug 8 22:56:37 EDT 2015


Changeset: 492f466b53c5588c194395c1686ebfbe86693242
Author:	 Nakul Gulati
Date:	 2015-08-09 10:55 +0800
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/492f466b53c5

Description:

hangouts: api chat data initialize

diffstat:

 libpurple/protocols/hangouts/api.c |  73 ++++++++++++++++++++++++++++++++++++-
 libpurple/protocols/hangouts/api.h |   5 ++
 2 files changed, 76 insertions(+), 2 deletions(-)

diffs (132 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
@@ -70,7 +70,7 @@ struct _HangoutsApiPrivate
   gchar *header_version;
   gchar *header_id;
   gchar *pvt_token;
-  GTimeVal *last_sync_timestamp;
+  gchar *last_sync_timestamp;
 };
 
 struct _HangoutsApiHttpInfo
@@ -448,12 +448,16 @@ hangouts_api_get_chat_init_cb (PurpleHtt
   const gchar *raw_res;
   GHashTable *chat_init_tab;
   JsonNode *root;
+  HangoutsApi *api;
 
   raw_res = purple_http_response_get_data (response, NULL);
+  api = user_data;
 
   chat_init_tab = hangouts_util_parse (raw_res);
   root = hangouts_util_construct_json_dictionary (chat_init_tab);
 
+  hangouts_api_set_chat_init_data (api, root);
+
   g_hash_table_destroy (chat_init_tab);
   json_node_free (root);
 }
@@ -482,6 +486,71 @@ hangouts_api_get_chat_init (HangoutsApi 
 
 }
 
+void
+hangouts_api_set_chat_init_data (HangoutsApi *api, JsonNode *dict)
+{
+  /*
+   * api_key -> $.ds:7[0][2]
+   * email -> $.ds:34[0][2]
+   * header_date -> $.ds:2[0][4]
+   * header_version -> $.ds:2[0][6]
+   * header_id -> $.ds:4[0][7]
+   * sync_timestamp -> $.ds:21[0][1][4]
+   */
+
+  JsonPath *path;
+  JsonArray *j_array;
+  JsonNode *node;
+  gchar *value;
+  HangoutsApiPrivate *priv;
+
+  priv = api->priv;
+  path = json_path_new ();
+
+  json_path_compile (path, "$.ds:7[0][2]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->api_key = value;
+
+  json_path_compile (path, "$.ds:34[0][2]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->email = value;
+
+  json_path_compile (path, "$.ds:2[0][4]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->header_date = value;
+
+  json_path_compile (path, "$.ds:2[0][6]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->header_version = value;
+
+  json_path_compile (path, "$.ds:4[0][7]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->header_id = value;
+
+  json_path_compile (path, "$.ds:21[0][1][4]", NULL);
+  node = json_path_match (path, dict);
+
+  j_array = json_node_dup_array (node);
+  value = json_array_get_string_element (j_array, 0);
+  priv->last_sync_timestamp = value;
+
+}
+
 gchar *
 hangouts_api_get_request_header (HangoutsApi *api)
 {
@@ -560,7 +629,7 @@ hangouts_api_syncallevents (HangoutsApi 
     { hangouts_api_syncallevents_cb, "conversations/syncallnewevents", "POST" };
 
   gchar *header, *body;
-  GTimeVal *time_stamp;
+  gchar *time_stamp;
 
   time_stamp = api->priv->last_sync_timestamp;
   header = hangouts_api_get_request_header (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
@@ -22,6 +22,8 @@
 #ifndef _API_H
 #define _API_H
 
+#include <json-glib/json-glib.h>
+
 #include "connection.h"
 
 #define HANGOUTS_API_OAUTH2_CLIENT_ID "1021803392181-71juemdl03adpl2n0tso7nl7hq83g2qg.apps.googleusercontent.com"
@@ -116,6 +118,9 @@ hangouts_api_get_private_token (Hangouts
 void
 hangouts_api_get_chat_init (HangoutsApi *api);
 
+void
+hangouts_api_set_chat_init_data (HangoutsApi *api, JsonNode *dict);
+
 gchar *
 hangouts_api_get_request_header (HangoutsApi *api);
 



More information about the Commits mailing list