/soc/2015/nakulgulati/main: 48868c941511: hangouts: api, cookie ...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Thu Jul 30 15:47:20 EDT 2015
Changeset: 48868c941511c2f309a4d63cf5746cb05f930bc8
Author: Nakul Gulati
Date: 2015-07-31 03:46 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/48868c941511
Description:
hangouts: api, cookie parser and other fixes
diffstat:
libpurple/protocols/hangouts/api.c | 74 ++++++++++++++++++++++++++++++++----
libpurple/protocols/hangouts/api.h | 6 +++
libpurple/protocols/hangouts/util.c | 30 +--------------
libpurple/protocols/hangouts/util.h | 3 -
4 files changed, 72 insertions(+), 41 deletions(-)
diffs (229 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
@@ -19,12 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
+#include <string.h>
#include <glib.h>
#include "http.h"
#include "api.h"
-#include "util.h"
//TODO api call backs
G_DEFINE_TYPE(HangoutsApi, hangouts_api, G_TYPE_OBJECT);
@@ -34,11 +34,21 @@ enum _HangoutsConversationOffTheRecordSt
HANGOUTS_OFF_THE_RECORD = 1, HANGOUTS_ON_THE_RECORD = 2
};
+struct _HangoutsApiCookies{
+ gchar *APISID;
+ gchar *HSID;
+ gchar *NID;
+ gchar *SAPISID;
+ gchar *SID;
+ gchar *SSID;
+ gchar *test;
+};
+
struct _HangoutsApiPrivate
{
PurpleConnection *gc;
PurpleHttpCookieJar *cookie_jar;
- GHashTable *cookies_tab;
+ HangoutsApiCookies *cookies;
gchar *galx;
gchar *api_key;
@@ -66,9 +76,9 @@ hangouts_api_dispose (GObject *obj)
purple_http_conn_cancel_all (priv->gc);
}
- g_hash_table_destroy (priv->cookies_tab);
purple_http_cookie_jar_unref(priv->cookie_jar);
+ g_free(priv->cookies);
g_free (priv->galx);
g_free (priv->access_token);
g_free (priv->api_key);
@@ -103,31 +113,78 @@ hangouts_api_new (PurpleConnection *gc)
{
HangoutsApi *api;
HangoutsApiPrivate *priv;
+ HangoutsApiCookies *cookies;
api = g_object_new (HANGOUTS_TYPE_API, NULL);
priv = api->priv;
+ cookies = malloc(sizeof(HangoutsApiCookies));
+ priv->cookies = cookies;
priv->gc = gc;
- priv->cookies_tab = g_hash_table_new (g_str_hash, g_str_equal);
return api;
}
+void
+hangouts_api_parse_header (HangoutsApiCookies *cookies, GList *headers)
+{
+ GList *l;
+
+ for(l = headers; l!=NULL; l=l->next)
+ {
+ const gchar *cookie = l->data;
+ const gchar *eqsign, *semicolon;
+ gchar *name, *value;
+
+ eqsign = strchr (cookie, '=');
+ semicolon = strchr (cookie, ';');
+
+ name = g_strndup (cookie, eqsign - cookie);
+ eqsign++;
+ if (semicolon != NULL)
+ value = g_strndup (eqsign, semicolon - eqsign);
+ else
+ value = g_strdup (eqsign);
+
+ if(g_str_equal(name, "APISID")){
+ cookies->APISID = value;
+ }
+ else if(g_str_equal(name, "HSID")){
+ cookies->HSID = value;
+ }
+ else if(g_str_equal(name, "NID")){
+ cookies->NID = value;
+ }
+ else if(g_str_equal(name, "SAPISID")){
+ cookies->SAPISID = value;
+ }
+ else if(g_str_equal(name, "SID")){
+ cookies->SID = value;
+ }
+ else if(g_str_equal(name, "SSID")){
+ cookies->SSID = value;
+ }
+ g_free(name);
+ g_free(value);
+
+ }
+}
+
static void
hangouts_api_fetch_cookies_cb (PurpleHttpConnection *http_conn,
PurpleHttpResponse *response, gpointer user_data)
{
- purple_debug_misc ("hangouts-prpl", "second call back");
HangoutsApi *api;
+ HangoutsApiPrivate *priv;
api = user_data;
+ priv = api->priv;
PurpleHttpCookieJar *cj = purple_http_conn_get_cookie_jar (http_conn);
GList *headers = purple_http_response_get_headers_by_name (response,
"Set-Cookie");
-
- hangouts_util_parse_header (api->priv->cookies_tab, headers);
+ hangouts_api_parse_header (priv->cookies, headers);
}
void
@@ -151,8 +208,7 @@ hangouts_api_fetch_login_cookies (Hangou
"&Passwd=%s"
"&PersistentCookie=yes"
"&GALX=%s"
- "&continue=https:\/\/talkgadget.google.com\/talkgadget\/gauth?verify=true"
- "&skipvpage=true",
+ "&Page=PasswordSeparationSignIn",
username, password, priv->galx);
request = purple_http_request_new (url);
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 "connection.h"
+
#define HANGOUTS_ORIGIN_URL "https://talkgadget.google.com"
#define HANGOUTS_IMAGE_UPLOAD_URL "http://docs.google.com/upload/photos/resumable"
#define HANGOUTS_PVT_TOKEN_URL "https://talkgadget.google.com/talkgadget/_/extension-start"
@@ -48,6 +50,7 @@ typedef struct _HangoutsApi HangoutsApi;
typedef struct _HangoutsApiClass HangoutsApiClass;
typedef struct _HangoutsApiPrivate HangoutsApiPrivate;
typedef struct _HangoutsApiHttpInfo HangoutsApiHttpInfo;
+typedef struct _HangoutsApiCookies HangoutsApiCookies;
struct _HangoutsApi
{
@@ -67,6 +70,9 @@ HangoutsApi *
hangouts_api_new (PurpleConnection *gc);
void
+hangouts_api_parse_header (HangoutsApiCookies *cookies, GList *headers);
+
+void
hangouts_api_get_galx_cookie (HangoutsApi *api);
void
diff --git a/libpurple/protocols/hangouts/util.c b/libpurple/protocols/hangouts/util.c
--- a/libpurple/protocols/hangouts/util.c
+++ b/libpurple/protocols/hangouts/util.c
@@ -25,6 +25,7 @@
#include "debug.h"
#include "util.h"
+#include "api.h"
gchar *
hangouts_util_escape_string (gchar *string)
@@ -69,32 +70,3 @@ hangouts_util_parse (gchar *raw_data)
return chat_init_data;
}
-
-void
-hangouts_util_parse_header (GHashTable *cookies_tab, GList *headers)
-{
- headers = g_list_first (headers);
- while (headers)
- {
- const gchar *cookie = headers->data;
- const gchar *eqsign, *semicolon;
- gchar *name, *value;
- headers = g_list_next(headers);
-
- eqsign = strchr (cookie, '=');
- semicolon = strchr (cookie, ';');
-
- name = g_strndup (cookie, eqsign - cookie);
- eqsign++;
- if (semicolon != NULL)
- value = g_strndup (eqsign, semicolon - eqsign);
- else
- value = g_strdup (eqsign);
-
- purple_debug_misc("hangouts-prpl", "name: %s, value: %s", name, value);
-
- g_free(name);
- g_free(value);
-
- }
-}
diff --git a/libpurple/protocols/hangouts/util.h b/libpurple/protocols/hangouts/util.h
--- a/libpurple/protocols/hangouts/util.h
+++ b/libpurple/protocols/hangouts/util.h
@@ -33,7 +33,4 @@ hangouts_util_escape_string (gchar *stri
GHashTable *
hangouts_util_parse (gchar *raw_data);
-void
-hangouts_util_parse_header (GHashTable *cookies_tab, GList *headers);
-
#endif _UTIL_H
More information about the Commits
mailing list