--- a/libpurple/protocols/gg/oauth/oauth-purple.c Fri Oct 11 20:23:42 2019 -0400
+++ b/libpurple/protocols/gg/oauth/oauth-purple.c Fri Oct 11 21:47:21 2019 -0400
@@ -49,17 +49,6 @@
gchar *sign_method, *sign_url;
-static void ggp_oauth_data_free(ggp_oauth_data *data);
-static void ggp_oauth_request_token_got(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data);
-static void ggp_oauth_authorization_done(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data);
-static void ggp_oauth_access_token_got(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data);
static void ggp_oauth_data_free(ggp_oauth_data *data)
@@ -69,34 +58,97 @@
-void ggp_oauth_request(PurpleConnection *gc, ggp_oauth_request_cb callback,
- gpointer user_data, const gchar *sign_method, const gchar *sign_url)
+ggp_oauth_access_token_got(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer user_data) - PurpleAccount *account = purple_connection_get_account(gc);
+ ggp_oauth_data *data = user_data; + gchar *token, *token_secret; + xml_raw = purple_http_response_get_data(response, NULL); + xml = purple_xmlnode_from_str(xml_raw, -1); + purple_debug_error("gg", "ggp_oauth_access_token_got: invalid xml"); + ggp_oauth_data_free(data); + succ &= ggp_xml_get_string(xml, "oauth_token", &token); + succ &= ggp_xml_get_string(xml, "oauth_token_secret", &token_secret); + purple_xmlnode_free(xml); + if (!succ || strlen(token) < 10) { + purple_debug_error("gg", "ggp_oauth_access_token_got: invalid xml - " + "token is not present"); + ggp_oauth_data_free(data); + PurpleAccount *account; + purple_debug_misc("gg", "ggp_oauth_access_token_got: got access token, " + "returning signed url"); + account = purple_connection_get_account(data->gc); + auth = gg_oauth_generate_header( + data->sign_method, data->sign_url, + purple_account_get_username(account), + purple_connection_get_password(data->gc), token, token_secret); + data->callback(data->gc, auth, data->user_data); + "ggp_oauth_access_token_got: got access token, returning it"); + data->callback(data->gc, token, data->user_data); + ggp_oauth_data_free(data); +ggp_oauth_authorization_done(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer user_data) + ggp_oauth_data *data = user_data; + PurpleAccount *account; const char *method = "POST";
- const char *url = "http://api.gadu-gadu.pl/request_token";
+ const char *url = "http://api.gadu-gadu.pl/access_token"; + PURPLE_ASSERT_CONNECTION_IS_VALID(data->gc); + account = purple_connection_get_account(data->gc); - purple_debug_misc("gg", "ggp_oauth_request: requesting token...\n");
+ response_code = purple_http_response_get_code(response); + if (response_code != 302) { + purple_debug_error("gg", + "ggp_oauth_authorization_done: failed (code = %d)", + ggp_oauth_data_free(data); + purple_debug_misc("gg", "ggp_oauth_authorization_done: authorization done, " + "requesting access token..."); auth = gg_oauth_generate_header(method, url,
- purple_account_get_username(account),
- purple_connection_get_password(gc), NULL, NULL);
- data = g_new0(ggp_oauth_data, 1);
- data->callback = callback;
- data->user_data = user_data;
- data->sign_method = g_strdup(sign_method);
- data->sign_url = g_strdup(sign_url);
+ purple_account_get_username(account), + purple_connection_get_password(data->gc), + data->token, data->token_secret); req = purple_http_request_new(url);
purple_http_request_set_max_len(req, GGP_OAUTH_RESPONSE_MAX);
purple_http_request_set_method(req, method);
purple_http_request_header_set(req, "Authorization", auth);
- purple_http_request(gc, req, ggp_oauth_request_token_got, data);
+ purple_http_request(data->gc, req, ggp_oauth_access_token_got, data); purple_http_request_unref(req);
@@ -166,97 +218,37 @@
-static void ggp_oauth_authorization_done(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data)
+ggp_oauth_request(PurpleConnection *gc, ggp_oauth_request_cb callback, + gpointer user_data, const gchar *sign_method, - ggp_oauth_data *data = user_data;
- PurpleAccount *account;
+ PurpleAccount *account = purple_connection_get_account(gc); const char *method = "POST";
- const char *url = "http://api.gadu-gadu.pl/access_token";
+ const char *url = "http://api.gadu-gadu.pl/request_token"; - PURPLE_ASSERT_CONNECTION_IS_VALID(data->gc);
- account = purple_connection_get_account(data->gc);
+ purple_debug_misc("gg", "ggp_oauth_request: requesting token...\n"); - response_code = purple_http_response_get_code(response);
- if (response_code != 302) {
- purple_debug_error("gg", "ggp_oauth_authorization_done: "
- "failed (code = %d)", response_code);
- ggp_oauth_data_free(data);
+ auth = gg_oauth_generate_header( + method, url, purple_account_get_username(account), + purple_connection_get_password(gc), NULL, NULL); - purple_debug_misc("gg", "ggp_oauth_authorization_done: "
- "authorization done, requesting access token...\n");
- auth = gg_oauth_generate_header(method, url,
- purple_account_get_username(account),
- purple_connection_get_password(data->gc),
- data->token, data->token_secret);
+ data = g_new0(ggp_oauth_data, 1); + data->callback = callback; + data->user_data = user_data; + data->sign_method = g_strdup(sign_method); + data->sign_url = g_strdup(sign_url); req = purple_http_request_new(url);
purple_http_request_set_max_len(req, GGP_OAUTH_RESPONSE_MAX);
purple_http_request_set_method(req, method);
purple_http_request_header_set(req, "Authorization", auth);
- purple_http_request(data->gc, req, ggp_oauth_access_token_got, data);
+ purple_http_request(gc, req, ggp_oauth_request_token_got, data); purple_http_request_unref(req);
-static void ggp_oauth_access_token_got(PurpleHttpConnection *http_conn,
- PurpleHttpResponse *response, gpointer user_data)
- ggp_oauth_data *data = user_data;
- gchar *token, *token_secret;
- xml_raw = purple_http_response_get_data(response, NULL);
- xml = purple_xmlnode_from_str(xml_raw, -1);
- purple_debug_error("gg", "ggp_oauth_access_token_got: "
- ggp_oauth_data_free(data);
- succ &= ggp_xml_get_string(xml, "oauth_token", &token);
- succ &= ggp_xml_get_string(xml, "oauth_token_secret",
- purple_xmlnode_free(xml);
- if (!succ || strlen(token) < 10) {
- purple_debug_error("gg", "ggp_oauth_access_token_got: "
- "invalid xml - token is not present\n");
- ggp_oauth_data_free(data);
- PurpleAccount *account;
- purple_debug_misc("gg", "ggp_oauth_access_token_got: "
- "got access token, returning signed url\n");
- account = purple_connection_get_account(data->gc);
- auth = gg_oauth_generate_header(
- data->sign_method, data->sign_url,
- purple_account_get_username(account),
- purple_connection_get_password(data->gc),
- data->callback(data->gc, auth, data->user_data);
- purple_debug_misc("gg", "ggp_oauth_access_token_got: "
- "got access token, returning it\n");
- data->callback(data->gc, token, data->user_data);
- ggp_oauth_data_free(data);