/soc/2015/nakulgulati/main: fd808a8be54d: hangouts: channel, sub...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Wed Aug 12 23:11:50 EDT 2015
Changeset: fd808a8be54d406d9ac0b5214082cadbb3082f00
Author: Nakul Gulati
Date: 2015-08-13 11:11 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/fd808a8be54d
Description:
hangouts: channel, subscribe to events
diffstat:
libpurple/protocols/hangouts/channel.c | 75 +++++++++++++++++++++++++++++++++-
libpurple/protocols/hangouts/channel.h | 7 ++-
2 files changed, 78 insertions(+), 4 deletions(-)
diffs (127 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,13 +83,81 @@ hangouts_channel_set_access_token (Hango
}
static void
+hangouts_channel_subscribe_cb (PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer user_data)
+{
+ gchar *raw;
+
+ raw = purple_http_response_get_data (response, NULL);
+ purple_debug_misc ("hangouts-channel-subscribe", "response: %s", raw);
+}
+
+void
+hangouts_channel_subscribe (HangoutsChannel *channel)
+{
+ HangoutsChannelPrivate *priv;
+ PurpleHttpRequest *request;
+ gchar *end_point;
+ gchar *params;
+ guint64 *timestamp;
+ gchar *req0, *req1, *req2, *body;
+
+ timestamp = (unsigned) time (NULL);
+ purple_debug_misc ("hangouts-channel-time", "timestamp: %u", timestamp);
+ req0 =
+ g_strdup_printf (
+ "{\"1\":{\"1\":{\"1\":{\"1\":3,\"2\":2}},\"2\":{\"1\":{\"1\":3,\"2\":2},\"2\":\"\",\"3\":\"JS\",\"4\":\"lcsclient\"},\"3\":%u,\"4\":0,\"5\":\"c1\"},\"2\":{}}",
+ timestamp);
+ req1 =
+ g_strdup_printf (
+ "{\"1\":{\"1\":{\"1\":{\"1\":3,\"2\":2}},\"2\":{\"1\":{\"1\":3,\"2\":2},\"2\":\"\",\"3\":\"JS\",\"4\":\"lcsclient\"},\"3\":%u,\"4\":%u,\"5\":\"c3\"},\"3\":{\"1\":{\"1\":\"babel\"}}}",
+ timestamp, timestamp);
+
+ req2 =
+ g_strdup_printf (
+ "{\"1\":{\"1\":{\"1\":{\"1\":3,\"2\":2}},\"2\":{\"1\":{\"1\":3,\"2\":2},\"2\":\"\",\"3\":\"JS\",\"4\":\"lcsclient\"},\"3\":%u,\"4\":%u,\"5\":\"c4\"},\"3\":{\"1\":{\"1\":\"hangout_invite\"}}}",
+ timestamp, timestamp);
+
+ body = g_strdup_printf ("count=3&ofs=0&req0_p=%s&req1_p=%s&req2_p=%s", req0,
+ req1, req2);
+
+ priv = channel->priv;
+ end_point = "channel/bind";
+ params = g_strdup_printf ("?ctype=hangouts"
+ "&RID=81188"
+ "&VER=8"
+ "&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_header_add (request, "X-Origin",
+ g_strdup ("https://talkgadget.google.com"));
+ purple_http_request_header_add (request, "X-Goog-AuthUser", g_strdup ("0"));
+ purple_http_request_header_add (request, "Content-Type",
+ "application/x-www-form-urlencoded");
+ purple_http_request_set_contents (request, g_strcompress (body), -1);
+ purple_http_request (priv->gc, request, hangouts_channel_subscribe_cb,
+ channel);
+
+}
+
+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);
+ purple_debug_misc ("hangouts-channel-long-poll", "response: %s", raw);
}
void
@@ -114,8 +182,9 @@ hangouts_channel_long_poll (HangoutsChan
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_method (request, "GET");
purple_http_request_set_max_len (request, -1);
+ purple_http_request_set_timeout (request, -1);
purple_http_request_set_cookie_jar (request, priv->cj);
purple_http_request_header_add (
request, "Authorization",
@@ -155,6 +224,8 @@ hangouts_channel_get_gsid_cb (PurpleHttp
json_node_free (node);
hangouts_channel_long_poll (channel);
+ purple_debug_misc("hangouts-prpl", "back from sleep");
+ hangouts_channel_subscribe(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
@@ -31,12 +31,15 @@ struct _HangoutsChannelClass
GType
hangouts_channel_get_type (void);
+HangoutsChannel *
+hangouts_channel_new (PurpleConnection *gc);
+
void
hangouts_channel_set_access_token (HangoutsChannel *channel,
gchar *access_token);
-HangoutsChannel *
-hangouts_channel_new (PurpleConnection *gc);
+void
+hangouts_channel_subscribe (HangoutsChannel *channel);
void
hangouts_channel_long_poll (HangoutsChannel *channel);
More information about the Commits
mailing list