/soc/2015/nakulgulati/main: 247b33e26b20: hangouts: channel ssl ...

Nakul at rock.pidgin.im Nakul at rock.pidgin.im
Wed Aug 26 23:37:24 EDT 2015


Changeset: 247b33e26b2039de9a12877437f9dbba12763105
Author:	 Nakul Gulati
Date:	 2015-08-27 09:06 +0530
Branch:	 hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/247b33e26b20

Description:

hangouts: channel ssl socket test

diffstat:

 libpurple/protocols/hangouts/channel.c |  89 ++++++++++++++++++++++++++-------
 1 files changed, 69 insertions(+), 20 deletions(-)

diffs (138 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
@@ -13,6 +13,7 @@ struct _HangoutsChannelPrivate
 {
   PurpleConnection *gc;
   PurpleHttpCookieJar *cj;
+  PurpleSslConnection *sgc;
 
   gboolean connected;
   gboolean subscribed;
@@ -45,21 +46,17 @@ hangouts_channel_class_init (HangoutsCha
   g_class->dispose = hangouts_channel_dispose;
   g_type_class_add_private (g_class, sizeof(HangoutsChannelPrivate));
 
-  g_signal_new ("connect",
-		  G_TYPE_FROM_CLASS(klass),
-		  G_SIGNAL_ACTION, 0,
-		  NULL, NULL,
-		  g_cclosure_marshal_VOID__VOID,
-		  G_TYPE_NONE,
-		  NULL);
+  g_signal_new ("connect", G_TYPE_FROM_CLASS(klass), G_SIGNAL_ACTION, 0,
+  NULL,
+		NULL, g_cclosure_marshal_VOID__VOID,
+		G_TYPE_NONE,
+		NULL);
 
-  g_signal_new ("subscribe",
-  		  G_TYPE_FROM_CLASS(klass),
-  		  G_SIGNAL_ACTION, 0,
-  		  NULL, NULL,
-  		  g_cclosure_marshal_VOID__VOID,
-  		  G_TYPE_NONE,
-  		  NULL);
+  g_signal_new ("subscribe", G_TYPE_FROM_CLASS(klass), G_SIGNAL_ACTION, 0,
+  NULL,
+		NULL, g_cclosure_marshal_VOID__VOID,
+		G_TYPE_NONE,
+		NULL);
 }
 
 static void
@@ -193,7 +190,7 @@ hangouts_channel_long_poll_cb (PurpleHtt
 			       PurpleHttpResponse *response, gpointer user_data)
 {
   HangoutsChannel *channel;
-  const gchar *raw = purple_http_response_get_data(response,NULL);
+  const gchar *raw = purple_http_response_get_data (response, NULL);
 
   channel = user_data;
 
@@ -223,13 +220,14 @@ hangouts_channel_long_poll_watcher (Purp
     {
       priv->connected = TRUE;
       //g_signal_emit_by_name (channel, "connect");
-      hangouts_channel_subscribe(channel);
+      hangouts_channel_subscribe (channel);
     }
   //TODO: parse chunk
 
-  if(strstr(chunk, "lcsw")){
-      hangouts_api_set_client_id(priv->gc, chunk);
-  }
+  if (strstr (chunk, "lcsw"))
+    {
+      hangouts_api_set_client_id (priv->gc, chunk);
+    }
 
 }
 
@@ -270,6 +268,56 @@ hangouts_channel_long_poll (HangoutsChan
 }
 
 static void
+hangouts_channel_ssl_got_data (gpointer userdata, PurpleSslConnection *conn,
+			       PurpleInputCondition cond)
+{
+  gchar buf;
+  HangoutsChannel *channel;
+
+  channel = userdata;
+
+  purple_debug_misc ("hangouts-channel", "got data cb");
+
+  while(purple_ssl_read(channel->priv->sgc, &buf, 1) == 1){
+      purple_debug_misc("hangouts-channel", "buf: %c", buf);
+  }
+
+}
+
+static void
+hangouts_channel_ssl_connect_cb (gpointer userdata, PurpleSslConnection *conn,
+				 PurpleInputCondition cond)
+{
+  const gchar *data;
+  HangoutsChannel *channel = userdata;
+
+  purple_debug_misc ("hangouts-channel", "ssl cb");
+  purple_ssl_input_add (channel->priv->sgc, hangouts_channel_ssl_got_data,
+			channel);
+  data = g_strdup_printf ("GET /client-channel/channel/bind HTTP/1.1\r\n"
+			  "Host: 0.client-channel.google.com\r\n"
+			  "\r\n");
+
+  purple_ssl_write (channel->priv->sgc, data, strlen (data));
+}
+
+static void
+hangouts_channel_longpoll_ssl (HangoutsChannel *channel)
+{
+  HangoutsChannelPrivate *priv;
+  PurpleAccount *acct;
+
+  priv = channel->priv;
+
+  acct = purple_connection_get_account (priv->gc);
+
+  priv->sgc = purple_ssl_connect (acct, "0.client-channel.google.com", 443,
+				  hangouts_channel_ssl_connect_cb, NULL,
+				  channel);
+
+}
+
+static void
 hangouts_channel_get_gsid_cb (PurpleHttpConnection *http_conn,
 			      PurpleHttpResponse *response, gpointer user_data)
 {
@@ -298,7 +346,8 @@ hangouts_channel_get_gsid_cb (PurpleHttp
   priv->gession_id = g_strdup (gsid);
 
   json_node_free (node);
-  hangouts_channel_long_poll (channel);
+  //hangouts_channel_long_poll (channel);
+  hangouts_channel_longpoll_ssl (channel);
 }
 
 void



More information about the Commits mailing list