/soc/2015/nakulgulati/main: f8e963ad210e: hangouts: alternate au...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Tue Jul 28 16:35:24 EDT 2015
Changeset: f8e963ad210eb7eedb8873149d03b97e477e3ff9
Author: Nakul Gulati
Date: 2015-07-29 04:34 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/f8e963ad210e
Description:
hangouts: alternate auth approach, refactor
diffstat:
libpurple/protocols/hangouts/api.c | 52 +++--
libpurple/protocols/hangouts/api.h | 2 +-
libpurple/protocols/hangouts/auth.c | 293 ++++++++-----------------------
libpurple/protocols/hangouts/auth.h | 23 +-
libpurple/protocols/hangouts/hangouts.c | 155 +++++++--------
5 files changed, 186 insertions(+), 339 deletions(-)
diffs (truncated from 773 to 300 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
@@ -34,8 +34,10 @@ enum _HangoutsConversationOffTheRecordSt
struct _HangoutsApiPrivate
{
PurpleConnection *gc;
- HangoutsAuthCookies *cookies;
+ //HangoutsAuthCookies *cookies
+ PurpleHttpCookieJar *cookie_jar;
+ gchar *galx;
gchar *api_key;
gchar *access_token;
gchar *header_date;
@@ -61,8 +63,11 @@ hangouts_api_dispose (GObject *obj)
purple_http_conn_cancel_all (priv->gc);
}
- hangouts_auth_cookies_free (priv->cookies);
+ //hangouts_auth_cookies_free (priv->cookies);
+ purple_http_cookie_free (priv->cookie_jar);
+
+ g_free (priv->galx);
g_free (priv->access_token);
g_free (priv->api_key);
g_free (priv->client_id);
@@ -76,6 +81,7 @@ hangouts_api_dispose (GObject *obj)
static void
hangouts_api_class_init (HangoutsApiClass *klass)
{
+ purple_debug_misc ("hangouts-prpl", "new class init");
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof(HangoutsApiPrivate));
gobject_class->dispose = hangouts_api_dispose;
@@ -84,6 +90,7 @@ hangouts_api_class_init (HangoutsApiClas
static void
hangouts_api_init (HangoutsApi *api)
{
+ purple_debug_misc ("hangouts-prpl", "api init");
HangoutsApiPrivate *priv;
priv = G_TYPE_INSTANCE_GET_PRIVATE (api, HANGOUTS_TYPE_API,
@@ -94,6 +101,7 @@ hangouts_api_init (HangoutsApi *api)
HangoutsApi *
hangouts_api_new (PurpleConnection *gc)
{
+ purple_debug_misc ("hangouts-prpl", "new api obj");
HangoutsApi *api;
HangoutsApiPrivate *priv;
@@ -144,21 +152,21 @@ hangouts_api_request (HangoutsApi *api,
}
purple_http_request_header_add (request, "content-type", content_type);
- purple_http_request_header_add (
- request, "Authorization",
- hangouts_auth_get_authorization_header (priv->access_token));
+ /*purple_http_request_header_add (
+ request, "Authorization",
+ hangouts_auth_get_authorization_header (priv->access_token));*/
purple_http_request_set_method (request, "POST");
- purple_http_request_set_contents (request, request_body);
+ purple_http_request_set_contents (request, request_body, -1);
purple_http_request (priv->gc, request, info->callback, api);
}
void
hangouts_api_getselfinfo (HangoutsApi *api)
{
- static const HangoutsApiHttpInfo *info =
- {
+ /*static const HangoutsApiHttpInfo *info =
+ {
- };
+ };*/
gchar *url_endpoint, *header, *body;
@@ -166,16 +174,16 @@ hangouts_api_getselfinfo (HangoutsApi *a
header = hangouts_api_get_request_header (api);
body = g_strdup_printf ("[%s,[], []]", header);
- hangouts_api_request (api, info, url_endpoint, TRUE, body);
+ //hangouts_api_request (api, info, url_endpoint, TRUE, body);
}
void
hangouts_api_syncallevents (HangoutsApi *api)
{
- static const HangoutsApiHttpInfo *info =
- {
+ /* static const HangoutsApiHttpInfo *info =
+ {
- };
+ };*/
gchar *url_endpoint, *header, *body;
GTimeVal *time_stamp;
@@ -195,7 +203,7 @@ hangouts_api_syncallevents (HangoutsApi
"]",
header, g_time_val_to_iso8601 (time_stamp));
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ //hangouts_api_request (api, info, url_endpoint, FALSE, body);
}
void
@@ -204,10 +212,10 @@ hangouts_api_sendchatmessage (HangoutsAp
HangoutsOffTheRecordStatus otr_status)
{
//TODO: segments should be in the protojson format
- static const HangoutsApiHttpInfo *info =
- {
+ /*static const HangoutsApiHttpInfo *info =
+ {
- };
+ };*/
guint32 client_generated_id;
gchar *url_endpoint, *image_info, *body, *header;
@@ -235,17 +243,17 @@ hangouts_api_sendchatmessage (HangoutsAp
header, segments, image_info, conversation_id,
client_generated_id, otr_status);
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ //hangouts_api_request (api, info, url_endpoint, FALSE, body);
}
void
hangouts_api_setactiveclient (HangoutsApi *api, gboolean is_active,
gchar *timeout_sec)
{
- static const HangoutsApiHttpInfo *info =
- {
+ /*static const HangoutsApiHttpInfo *info =
+ {
- };
+ };*/
gchar *url_endpoint, *is_active_flag, *body, *header;
HangoutsApiPrivate *priv;
@@ -268,6 +276,6 @@ hangouts_api_setactiveclient (HangoutsAp
header, is_active_flag, priv->email, priv->client_id,
timeout_sec);
- hangouts_api_request (api, info, url_endpoint, FALSE, body);
+ //hangouts_api_request (api, info, url_endpoint, FALSE, body);
}
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
@@ -57,7 +57,7 @@ struct _HangoutsApi
struct _HangoutsApiClass
{
- GObject parent;
+ GObjectClass parent;
};
GType
diff --git a/libpurple/protocols/hangouts/auth.c b/libpurple/protocols/hangouts/auth.c
--- a/libpurple/protocols/hangouts/auth.c
+++ b/libpurple/protocols/hangouts/auth.c
@@ -22,246 +22,103 @@
#include "http.h"
#include "http.c"
#include "auth.h"
+#include "api.c"
#include <json-glib/json-glib.h>
-typedef struct
+struct _HangoutsAuthCookies
{
- PurpleConnection *gc;
- gpointer user_data;
- gchar *token;
- gchar *token_secret;
- gchar *sign_method;
- gchar *sign_url;
-} _hangouts_oauth_data;
+ GHashTable *cookies_tab;
+};
-typedef struct
+static void
+hangouts_auth_fetch_cookies_cb (PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response,
+ gpointer user_data)
{
- PurpleConnection *gc;
- gpointer user_data;
- gchar *client_id;
- gchar *client_secret;
- gchar *authorization_code;
- gchar *redirect_uri;
-} _hangouts_oauth_token_request_data;
+ purple_debug_misc ("hangouts-prpl", "second call back");
-typedef struct
-{
- gchar *APISID;
- gchar *HSID;
- gchar *NID;
- gchar *SAPISID;
- gchar *SID;
- gchar *SSID;
-} _hangouts_oauth_cookies;
+ PurpleHttpCookieJar *cj = purple_http_conn_get_cookie_jar (http_conn);
-gchar *
-hangouts_auth_get_authorization_header(gchar *access_token)
-{
- gchar *header = g_strdup_printf("Bearer %s",access_token);
- return header;
+ GList *headers = purple_http_response_get_headers_by_name (response,
+ "Set-Cookie");
+ /*TODO: parse headers and store cookies*/
+ GList *l;
+
+ for (l = headers; l != NULL; l = l->next)
+ {
+ purple_debug_misc ("hangouts-prpl", "\nheader: %s", l->data);
+ }
}
void
-hangouts_auth_with_authentication_code_cb(PurpleHttpConnection *gc,
- PurpleHttpResponse *response, gpointer user_data){
- purple_debug_misc("hangouts-prpl", "http req call back");
+hangouts_auth_fetch_login_cookies (HangoutsApi *api)
+{
+ PurpleConnection *gc;
+ PurpleAccount *acct;
+ PurpleHttpRequest *request;
+ HangoutsApiPrivate *priv;
+ gchar *username, *password, *url, *request_body;
- JsonParser *parser;
- JsonObject *result;
- gchar *error, *access_token, *refresh_token;
+ priv = api->priv;
+ gc = priv->gc;
+ acct = purple_connection_get_account (gc);
+ username = purple_account_get_username (acct);
+ password = purple_connection_get_password (gc);
- gchar *raw_res = purple_http_response_get_data(response,NULL);
+ url = "https://accounts.google.com/ServiceLoginAuth";
+ request_body = g_strdup_printf (
+ "Email=%s"
+ "&Passwd=%s"
+ "&PersistentCookie=yes"
+ "&GALX=%s"
+ "&continue=https:\/\/talkgadget.google.com\/talkgadget\/gauth?verify=true"
+ "&skipvpage=true",
+ username, password, priv->galx);
+ request = purple_http_request_new (url);
- parser = json_parser_new();
- json_parser_load_from_data(parser, raw_res, -1, NULL);
- result = json_node_get_object(json_parser_get_root(parser));
-
- if (json_object_has_member(result, "error"))
- /*TODO Throw error*/
- error = json_object_get_string_member(result, "error");
-
- if (json_object_has_member(result, "access_token"))
- /*TODO store token for api_access*/
- access_token = json_object_get_string_member(result, "access_token");
-
- if (json_object_has_member(result, "refresh_token"))
- /*TODO store token for refresh request*/
- refresh_token = json_object_get_string_member(result, "refresh_token");
-
-
- purple_debug_misc("hangouts-prpl", "response data: %s \n error: %s, token: %s",raw_res, error, access_token);
- hangouts_auth_get_session_cookies(gc,access_token);
-
+ purple_http_request_set_method (request, "POST");
+ purple_http_request_set_max_len (request, -1);
+ purple_http_request_header_add (request, "Content-Type",
+ "application/x-www-form-urlencoded");
+ purple_http_request_set_contents (request, request_body, -1);
+ purple_http_request_set_cookie_jar (request, priv->cookie_jar);
+ purple_http_request_set_max_redirects (request, 0);
+ purple_http_request (gc, request, hangouts_auth_fetch_cookies_cb, NULL);
}
+static void
+hangouts_auth_get_galx_cookie_cb (PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response,
+ gpointer user_data)
More information about the Commits
mailing list