/soc/2015/nakulgulati/main: 145cc0fe5a3c: hangouts: JSON support...
Nakul at rock.pidgin.im
Nakul at rock.pidgin.im
Tue Jun 23 02:53:40 EDT 2015
Changeset: 145cc0fe5a3ce5d05e85128f5a6d4227548b6646
Author: Nakul Gulati
Date: 2015-06-22 18:56 +0800
Branch: hangouts
URL: https://hg.pidgin.im/soc/2015/nakulgulati/main/rev/145cc0fe5a3c
Description:
hangouts: JSON support, Auth refactor
diffstat:
libpurple/protocols/hangouts/Makefile.am | 3 +-
libpurple/protocols/hangouts/auth.c | 53 ++++++++++++++++++++++++++++++++
libpurple/protocols/hangouts/auth.h | 1 +
libpurple/protocols/hangouts/hangouts.c | 40 +-----------------------
4 files changed, 57 insertions(+), 40 deletions(-)
diffs (161 lines):
diff --git a/libpurple/protocols/hangouts/Makefile.am b/libpurple/protocols/hangouts/Makefile.am
--- a/libpurple/protocols/hangouts/Makefile.am
+++ b/libpurple/protocols/hangouts/Makefile.am
@@ -25,7 +25,7 @@ else
st =
pkg_LTLIBRARIES = libhangouts.la
libhangouts_la_SOURCES = $(HANGOUTSSOURCES)
-libhangouts_la_LIBADD = @PURPLE_LIBS@
+libhangouts_la_LIBADD = @PURPLE_LIBS@ $(JSON_LIBS)
endif
@@ -33,5 +33,6 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/libpurple \
-I$(top_builddir)/libpurple \
$(GLIB_CFLAGS) \
+ $(JSON_CFLAGS) \
$(GPLUGIN_CFLAGS) \
$(DEBUG_CFLAGS)
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,6 +22,8 @@
#include "http.h"
#include "auth.h"
+#include <json-glib/json-glib.h>
+
typedef struct
{
PurpleConnection *gc;
@@ -42,10 +44,61 @@ typedef struct
gchar *redirect_uri;
} _hangouts_oauth_token_request_data;
+static void
+hangouts_got_token_cb(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer user_data){
+ purple_debug_misc("hangouts-prpl", "http req call back");
+
+ JsonParser *parser;
+ JsonObject *result;
+ gchar *error;
+
+ gchar *raw_res = purple_http_response_get_data(response,NULL);
+
+ 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"))
+ //throw error
+ error = json_object_get_string_member(result, "error");
+
+ purple_debug_misc("hangouts-prpl", "response data: %s \n error: %s",raw_res, error);
+
+
+}
+
void
hangouts_request_auth(PurpleConnection *gc)
{
+ gchar *request_data;
+ gchar *auth_code;
+ PurpleAccount *account = purple_connection_get_account(gc);
+
+ auth_code = purple_connection_get_password(gc);
+
+ request_data = g_strdup_printf(
+ "client_id=%s&"
+ "client_secret=%s&"
+ "code=%s&"
+ "grant_type=%s&"
+ "redirect_uri=%s",
+ OAUTH2_CLIENT_ID,
+ OAUTH2_CLIENT_SECRET,
+ auth_code,
+ OAUTH2_GRANT_TYPE,
+ OAUTH2_REDIRECT_URI);
+
+ PurpleHttpRequest *request;
+ const char *method = "POST";
+
+ request = purple_http_request_new(OAUTH2_TOKEN_REQUEST_URL);
+ purple_http_request_set_method(request,method);
+ purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
+ purple_http_request_set_contents(request, request_data, -1);
+
+ purple_http_request(gc,request,hangouts_got_token_cb,NULL);
}
diff --git a/libpurple/protocols/hangouts/auth.h b/libpurple/protocols/hangouts/auth.h
--- a/libpurple/protocols/hangouts/auth.h
+++ b/libpurple/protocols/hangouts/auth.h
@@ -42,5 +42,6 @@ typedef struct _hangouts_oauth_token_req
void hangouts_oauth_data_free(hangouts_oauth_data *data);
+void hangouts_request_auth(PurpleConnection *gc);
#endif /* _AUTH_H_ */
diff --git a/libpurple/protocols/hangouts/hangouts.c b/libpurple/protocols/hangouts/hangouts.c
--- a/libpurple/protocols/hangouts/hangouts.c
+++ b/libpurple/protocols/hangouts/hangouts.c
@@ -35,15 +35,6 @@
static PurpleProtocol *_hangouts_protocol = NULL;
-static void hangouts_http_req_cb(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data){
- purple_debug_misc("hangouts-prpl", "http req call back");
-
- gchar *raw_res = purple_http_response_get_data(response,NULL);
- purple_debug_misc("hangouts-prpl", "response data: %s",raw_res);
-
-}
-
static void
hangouts_login(PurpleAccount *acct)
{
@@ -56,37 +47,8 @@ hangouts_login(PurpleAccount *acct)
username = purple_account_get_username(acct);
purple_debug_misc("hangouts-prpl", "login; account username: %s;",username);
- /*purple_signal_connect(purple_accounts_get_handle(), "account-connecting",
- plugin, PURPLE_CALLBACK(account_connecting_cb), NULL);
-*/
- //http login request
-
- gchar *request_data;
-
- request_data = g_strdup_printf(
- "client_id=%s&"
- "client_secret=%s&"
- "code=%s&"
- "grant_type=%s&"
- "redirect_uri=%s",
- OAUTH2_CLIENT_ID,
- OAUTH2_CLIENT_SECRET,
- "4/NfxMyTwRc0cVmSOZ0W-6hwOISSoQIvgGQgOHTzZBYdM",
- OAUTH2_GRANT_TYPE,
- OAUTH2_REDIRECT_URI);
-
- /*PurpleHttpURL *login_url = purple_http_url_parse(OAUTH2_LOGIN_URL);*/
- PurpleHttpRequest *request;
- const char *method = "POST";
-
- request = purple_http_request_new(OAUTH2_TOKEN_REQUEST_URL);
- purple_http_request_set_method(request,method);
- purple_http_request_header_set(request, "Content-Type", "application/x-www-form-urlencoded");
- purple_http_request_set_contents(request, request_data, -1);
-
- purple_http_request(gc,request,hangouts_http_req_cb,NULL);
-
+ hangouts_request_auth(gc);
}
More information about the Commits
mailing list