/soc/2015/nakulgulati/main: ef6095f6d139: hangouts: channel get_...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Mon Aug 10 05:58:48 EDT 2015
Changeset: ef6095f6d139e973581335a31271ad05b5237a44
Author: Nakul Gulati
Date: 2015-08-10 17:47 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/ef6095f6d139
Description:
hangouts: channel get_gsid
diffstat:
libpurple/protocols/hangouts/channel.c | 99 +++++++++++++++++++++++++++++++++-
libpurple/protocols/hangouts/channel.h | 14 ++++
2 files changed, 111 insertions(+), 2 deletions(-)
diffs (159 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
@@ -1,17 +1,112 @@
+#include <glib.h>
+
+#include "connection.h"
+#include "http.h"
+
#include "channel.h"
+#include "api.h"
-#include <glib.h>
+struct _HangoutsChannelPrivate
+{
+ PurpleConnection *gc;
+ PurpleHttpCookieJar *cj;
+
+ gboolean connected;
+ gboolean subscribed;
+
+ gchar *access_token;
+ gchar *gession_id;
+ gchar *sid;
+};
G_DEFINE_TYPE(HangoutsChannel, hangouts_channel, G_TYPE_OBJECT);
static void
+hangouts_channel_dispose (GObject *obj)
+{
+ HangoutsChannelPrivate *priv = HANGOUTS_CHANNEL(obj)->priv;
+
+ if (G_LIKELY(priv->gc != NULL))
+ {
+ purple_http_conn_cancel_all (priv->gc);
+ }
+
+ g_free (priv->gession_id);
+ g_free (priv->sid);
+}
+
+static void
hangouts_channel_class_init (HangoutsChannelClass *klass)
{
-
+ GObjectClass *g_class = G_OBJECT_CLASS(klass);
+ g_type_class_add_private (g_class, sizeof(HangoutsChannelPrivate));
+ g_class->dispose = hangouts_channel_dispose;
}
static void
hangouts_channel_init (HangoutsChannel *channel)
{
+ HangoutsChannelPrivate *priv;
+ priv = G_TYPE_INSTANCE_GET_PRIVATE(channel, HANGOUTS_TYPE_CHANNEL,
+ HangoutsChannelPrivate);
+
+ channel->priv = priv;
}
+
+HangoutsChannel *
+hangouts_channel_new (PurpleConnection *gc)
+{
+ HangoutsChannel *channel;
+ HangoutsChannelPrivate *priv;
+
+ channel = g_object_new (HANGOUTS_TYPE_CHANNEL, NULL);
+ priv = channel->priv;
+ priv->cj = purple_http_cookie_jar_new ();
+ priv->gc = gc;
+
+ return channel;
+}
+
+void
+hangouts_channel_set_access_token (HangoutsChannel *channel,
+ gchar *access_token)
+{
+ HangoutsChannelPrivate *priv;
+
+ g_return_if_fail(access_token!=NULL);
+
+ priv = channel->priv;
+ priv->access_token = g_strdup (access_token);
+}
+
+static void
+hangouts_channel_get_gsid_cb (PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer *data)
+{
+ purple_debug_misc("hangouts-channel", "gsid callback");
+
+ gchar *res_raw = purple_http_response_get_data(response, NULL);
+
+ purple_debug_misc("hangouts-channel", "response: %s", res_raw);
+}
+
+void
+hangouts_channel_get_gsid (HangoutsChannel *channel)
+{
+ HangoutsChannelPrivate *priv;
+ PurpleHttpRequest *request;
+
+ priv = channel->priv;
+
+ request = purple_http_request_new (
+ g_strdup_printf ("%s%s",HANGOUTS_CHANNEL_URL, "gsid"));
+
+ purple_http_request_set_method (request, "GET");
+ 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_gsid_cb, channel);
+}
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
@@ -4,6 +4,8 @@
#include <glib.h>
#include <glib-object.h>
+#define HANGOUTS_CHANNEL_URL "https://0.client-channel.google.com/client-channel/"
+
#define HANGOUTS_TYPE_CHANNEL (hangouts_channel_get_type ())
#define HANGOUTS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), HANGOUTS_TYPE_CHANNEL, HangoutsChannel))
#define HANGOUTS_IS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), HANGOUTS_TYPE_CHANNEL))
@@ -13,10 +15,12 @@
typedef struct _HangoutsChannel HangoutsChannel;
typedef struct _HangoutsChannelClass HangoutsChannelClass;
+typedef struct _HangoutsChannelPrivate HangoutsChannelPrivate;
struct _HangoutsChannel
{
GObject parent;
+ HangoutsChannelPrivate *priv;
};
struct _HangoutsChannelClass
@@ -27,5 +31,15 @@ struct _HangoutsChannelClass
GType
hangouts_channel_get_type (void);
+void
+hangouts_channel_set_access_token (HangoutsChannel *channel,
+ gchar *access_token);
+
+HangoutsChannel *
+hangouts_channel_new (PurpleConnection *gc);
+
+void
+hangouts_channel_get_gsid (HangoutsChannel *channel);
+
#endif /* _HANGOUTS_CHANNEL_H_ */
More information about the Commits
mailing list