/soc/2015/nakulgulati/main: fb423d04c23b: hangouts: channel long...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Wed Aug 12 23:11:50 EDT 2015
Changeset: fb423d04c23ba2389b24cb04d2a305fda0843217
Author: Nakul Gulati
Date: 2015-08-13 09:00 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/fb423d04c23b
Description:
hangouts: channel long poll request
diffstat:
libpurple/protocols/hangouts/channel.c | 55 ++++++++++++++++++++++++++++++++-
libpurple/protocols/hangouts/channel.h | 3 +
2 files changed, 56 insertions(+), 2 deletions(-)
diffs (95 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
@@ -83,6 +83,48 @@ hangouts_channel_set_access_token (Hango
}
static void
+hangouts_channel_long_poll_cb (PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer user_data)
+{
+ gchar *raw;
+
+ raw = purple_http_response_get_data (response, NULL);
+ purple_debug_misc ("hangouts-channel", "response: %s", raw);
+}
+
+void
+hangouts_channel_long_poll (HangoutsChannel *channel)
+{
+ HangoutsChannelPrivate *priv;
+ PurpleHttpRequest *request;
+ gchar *end_point;
+ gchar *params;
+
+ priv = channel->priv;
+ end_point = "channel/bind";
+
+ params = g_strdup_printf ("?ctype=hangouts"
+ "&RID=rpc"
+ "&VER=8"
+ "&TYPE=xmlhttp"
+ "&CI=0"
+ "&gsessionid=%s"
+ "&SID=%s",
+ priv->gession_id, priv->sid);
+ request = purple_http_request_new (
+ g_strconcat (HANGOUTS_CHANNEL_URL, end_point, params, NULL));
+
+ 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_long_poll_cb,
+ channel);
+}
+
+static void
hangouts_channel_get_gsid_cb (PurpleHttpConnection *http_conn,
PurpleHttpResponse *response, gpointer user_data)
{
@@ -92,18 +134,27 @@ hangouts_channel_get_gsid_cb (PurpleHttp
* ]
*/
gchar *res_raw;
+ gchar *gsid;
+ gchar *sid;
JsonNode *node;
HangoutsChannel *channel;
+ HangoutsChannelPrivate *priv;
channel = user_data;
+ priv = channel->priv;
res_raw = purple_http_response_get_data (response, NULL);
+ purple_debug_misc ("hangouts-channel", "raw: %s", res_raw);
res_raw = strstr (res_raw, "\n");
res_raw++;
node = hangouts_json_node_new (res_raw, -1, FALSE);
- 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);
+ sid = hangouts_json_node_get_str (node, "$[0][1][1]", NULL);
+ gsid = hangouts_json_node_get_str (node, "$[1][1][0].gsid", NULL);
+
+ priv->sid = g_strdup (sid);
+ priv->gession_id = g_strdup (gsid);
json_node_free (node);
+ hangouts_channel_long_poll (channel);
}
void
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,6 +39,9 @@ HangoutsChannel *
hangouts_channel_new (PurpleConnection *gc);
void
+hangouts_channel_long_poll (HangoutsChannel *channel);
+
+void
hangouts_channel_get_gsid (HangoutsChannel *channel);
#endif /* _HANGOUTS_CHANNEL_H_ */
More information about the Commits
mailing list