/pidgin/main: bb56b6121733: HTTP: migrate purple_util_fetch_url_...
Tomasz Wasilczyk
tomkiewicz at cpw.pidgin.im
Thu Jul 4 10:22:10 EDT 2013
Changeset: bb56b612173339d71c7a8df4b208c8a5cf9f3dd1
Author: Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date: 2013-07-04 16:22 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/bb56b6121733
Description:
HTTP: migrate purple_util_fetch_url_request to new API for yahoo prpl (login process)
diffstat:
libpurple/http.c | 18 +-
libpurple/protocols/yahoo/libyahoo.c | 2 +-
libpurple/protocols/yahoo/libyahoojp.c | 2 +-
libpurple/protocols/yahoo/libymsg.c | 325 ++++++++++++++------------------
libpurple/protocols/yahoo/util.c | 2 +-
5 files changed, 165 insertions(+), 184 deletions(-)
diffs (truncated from 515 to 300 lines):
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -2058,7 +2058,23 @@ const gchar * purple_http_response_get_e
{
g_return_val_if_fail(response != NULL, NULL);
- return response->error;
+ if (response->error != NULL)
+ return response->error;
+
+ if (!purple_http_response_is_successfull(response)) {
+ static gchar errmsg[200];
+ if (response->code <= 0) {
+ g_snprintf(errmsg, sizeof(errmsg),
+ _("Unknown HTTP error"));
+ } else {
+ g_snprintf(errmsg, sizeof(errmsg),
+ _("Invalid HTTP response code (%d)"),
+ response->code);
+ }
+ return errmsg;
+ }
+
+ return NULL;
}
gsize purple_http_response_get_data_len(PurpleHttpResponse *response)
diff --git a/libpurple/protocols/yahoo/libyahoo.c b/libpurple/protocols/yahoo/libyahoo.c
--- a/libpurple/protocols/yahoo/libyahoo.c
+++ b/libpurple/protocols/yahoo/libyahoo.c
@@ -324,10 +324,10 @@ init_plugin(PurplePlugin *plugin)
option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
+#if 0
option = purple_account_option_bool_new(_("Use account proxy for HTTP and HTTPS connections"), "proxy_ssl", FALSE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
-#if 0
option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
#endif
diff --git a/libpurple/protocols/yahoo/libyahoojp.c b/libpurple/protocols/yahoo/libyahoojp.c
--- a/libpurple/protocols/yahoo/libyahoojp.c
+++ b/libpurple/protocols/yahoo/libyahoojp.c
@@ -222,10 +222,10 @@ init_plugin(PurplePlugin *plugin)
option = purple_account_option_bool_new(_("Ignore conference and chatroom invitations"), "ignore_invites", FALSE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
+#if 0
option = purple_account_option_bool_new(_("Use account proxy for HTTP and HTTPS connections"), "proxy_ssl", FALSE);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
-#if 0
option = purple_account_option_string_new(_("Chat room list URL"), "room_list", YAHOO_ROOMLIST_URL);
prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
#endif
diff --git a/libpurple/protocols/yahoo/libymsg.c b/libpurple/protocols/yahoo/libymsg.c
--- a/libpurple/protocols/yahoo/libymsg.c
+++ b/libpurple/protocols/yahoo/libymsg.c
@@ -1702,6 +1702,8 @@ static void yahoo_auth16_stage3(PurpleCo
purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage3\n");
+ g_return_if_fail(crypt != NULL);
+
md5_cipher = purple_ciphers_find_cipher("md5");
md5_ctx = purple_cipher_context_new(md5_cipher, NULL);
purple_cipher_context_append(md5_ctx, (guchar *)crypt, strlen(crypt));
@@ -1746,170 +1748,134 @@ static void yahoo_auth16_stage3(PurpleCo
purple_cipher_context_destroy(md5_ctx);
}
-static gchar *yahoo_auth16_get_cookie_b(gchar *headers)
+static void yahoo_auth16_stage2(PurpleHttpConnection *http_conn,
+ PurpleHttpResponse *response, gpointer _auth_data)
{
- gchar **splits = g_strsplit(headers, "\r\n", -1);
- gchar *tmp = NULL, *tmp2 = NULL, *sem = NULL;
- int elements = g_strv_length(splits), i;
-
- if(elements > 1) {
- for(i = 0; i < elements; i++) {
- if(g_ascii_strncasecmp(splits[i], "Set-Cookie: B=", 14) == 0) {
- tmp = &splits[i][14];
- sem = strchr(tmp, ';');
-
- if (sem != NULL) {
- tmp2 = g_strndup(tmp, sem - tmp);
- purple_debug_info("yahoo", "Got needed part of B cookie: %s\n",
- tmp2 ? tmp2 : "(null)");
- break;
- }
- }
- }
- }
-
- g_strfreev(splits);
- return tmp2;
-}
-
-static void yahoo_auth16_stage2(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *ret_data, size_t len, const gchar *error_message)
-{
- struct yahoo_auth_data *auth_data = user_data;
+ struct yahoo_auth_data *auth_data = _auth_data;
PurpleConnection *gc = auth_data->gc;
YahooData *yd = purple_connection_get_protocol_data(gc);
+ int i;
+ gchar **splits;
+ int response_no = -1;
+ char *crumb = NULL;
+ char *crypt = NULL;
+ PurpleHttpCookieJar *cookiejar;
+
purple_debug_info("yahoo","Authentication: In yahoo_auth16_stage2\n");
- yd->url_datas = g_slist_remove(yd->url_datas, url_data);
-
- if (error_message != NULL) {
+ yd->http_reqs = g_slist_remove(yd->http_reqs, http_conn);
+
+ if (!purple_http_response_is_successfull(response)) {
+ const gchar *error_message = purple_http_response_get_error(response);
purple_debug_error("yahoo", "Login Failed, unable to retrieve stage 2 url: %s\n", error_message);
purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message);
g_free(auth_data->seed);
g_free(auth_data);
return;
}
- else if (len > 0 && ret_data && *ret_data) {
- gchar **splits = g_strsplit(ret_data, "\r\n\r\n", -1), **split_data = NULL;
- int totalelements = 0;
- int response_no = -1;
- char *crumb = NULL;
- char *crypt = NULL;
-
- if(g_strv_length(splits) > 1) {
- yd->cookie_b = yahoo_auth16_get_cookie_b(splits[0]);
- split_data = g_strsplit(splits[1], "\r\n", -1);
- totalelements = g_strv_length(split_data);
+
+ splits = g_strsplit(purple_http_response_get_data(response, NULL),
+ "\r\n", -1);
+
+ cookiejar = purple_http_conn_get_cookie_jar(http_conn);
+ yd->cookie_b = g_strdup(purple_http_cookie_jar_get(cookiejar, "B"));
+ yd->cookie_t = g_strdup(purple_http_cookie_jar_get(cookiejar, "T"));
+ yd->cookie_y = g_strdup(purple_http_cookie_jar_get(cookiejar, "Y"));
+
+ i = 0;
+ while (splits[i]) {
+ /* I'm not exactly a fan of the magic numbers, but it's obvious,
+ * so no sense in wasting a bajillion vars or calls to strlen */
+
+ if (i == 0 && g_ascii_isdigit(splits[i][0])) {
+ response_no = strtol(splits[i], NULL, 10);
+ purple_debug_info("yahoo", "Got auth16 stage 2 response code: %d\n",
+ response_no);
+ } else if (strncmp(splits[i], "crumb=", 6) == 0) {
+ crumb = g_strdup(&splits[i][6]);
+
+ if (purple_debug_is_unsafe())
+ purple_debug_info("yahoo", "Got crumb: %s\n", crumb);
}
-
- if (totalelements >= 4) {
- int i;
-
- for(i = 0; i < totalelements; i++) {
- /* I'm not exactly a fan of the magic numbers, but it's obvious,
- * so no sense in wasting a bajillion vars or calls to strlen */
-
- if(g_ascii_isdigit(split_data[i][0])) {
- /* if the current line and the next line both start with numbers,
- * the current line is the length of the body, so skip. If not,
- * then the current line is the response code from the login process. */
- if(!g_ascii_isdigit(split_data[i + 1][0])) {
- response_no = strtol(split_data[i], NULL, 10);
- purple_debug_info("yahoo", "Got auth16 stage 2 response code: %d\n",
- response_no);
- }
- } else if(strncmp(split_data[i], "crumb=", 6) == 0) {
- crumb = g_strdup(&split_data[i][6]);
-
- if(purple_debug_is_unsafe())
- purple_debug_info("yahoo", "Got crumb: %s\n", crumb);
-
- } else if(strncmp(split_data[i], "Y=", 2) == 0) {
- yd->cookie_y = g_strdup(&split_data[i][2]);
-
- if(purple_debug_is_unsafe())
- purple_debug_info("yahoo", "Got Y cookie: %s\n", yd->cookie_y);
-
- } else if(strncmp(split_data[i], "T=", 2) == 0) {
- yd->cookie_t = g_strdup(&split_data[i][2]);
-
- if(purple_debug_is_unsafe())
- purple_debug_info("yahoo", "Got T cookie: %s\n", yd->cookie_t);
+ i++;
+ }
+
+ g_strfreev(splits);
+
+ if (crumb == NULL)
+ response_no = -1;
+
+ if(response_no != 0) {
+ /* Some error in the login process */
+ PurpleConnectionError error;
+ char *error_reason = NULL;
+
+ switch (response_no) {
+ case -1:
+ /* Some error in the received stream */
+ error_reason = g_strdup(_("Received invalid data"));
+ error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
+ break;
+ case 100:
+ /* Unknown error */
+ error_reason = g_strdup(_("Unknown error"));
+ error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
+ break;
+ default:
+ /* if we have everything we need, why not try to login irrespective of response */
+ if ((crumb != NULL) && (yd->cookie_y != NULL) && (yd->cookie_t != NULL)) {
+#if 0
+ try_login_on_error = TRUE;
+#endif
+ break;
}
- }
+ error_reason = g_strdup(_("Unknown error"));
+ error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
+ break;
}
-
- g_strfreev(splits);
- g_strfreev(split_data);
-
- if(response_no != 0) {
- /* Some error in the login process */
- PurpleConnectionError error;
- char *error_reason = NULL;
-
- switch(response_no) {
- case -1:
- /* Some error in the received stream */
- error_reason = g_strdup(_("Received invalid data"));
- error = PURPLE_CONNECTION_ERROR_NETWORK_ERROR;
- break;
- case 100:
- /* Unknown error */
- error_reason = g_strdup(_("Unknown error"));
- error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
- break;
- default:
- /* if we have everything we need, why not try to login irrespective of response */
- if((crumb != NULL) && (yd->cookie_y != NULL) && (yd->cookie_t != NULL)) {
-#if 0
- try_login_on_error = TRUE;
-#endif
- break;
- }
- error_reason = g_strdup(_("Unknown error"));
- error = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
- break;
- }
- if(error_reason) {
- purple_debug_error("yahoo", "Authentication error: %s. "
- "Code %d\n", error_reason, response_no);
- purple_connection_error(gc, error, error_reason);
- g_free(error_reason);
- g_free(auth_data->seed);
- g_free(auth_data);
- return;
- }
+ if (error_reason) {
+ purple_debug_error("yahoo", "Authentication error: %s. "
+ "Code %d\n", error_reason, response_no);
+ purple_connection_error(gc, error, error_reason);
+ g_free(error_reason);
+ g_free(crumb);
+ g_free(auth_data->seed);
+ g_free(auth_data);
+ return;
}
-
- crypt = g_strconcat(crumb, auth_data->seed, NULL);
- yahoo_auth16_stage3(gc, crypt);
- g_free(crypt);
- g_free(crumb);
}
+
+ crypt = g_strconcat(crumb, auth_data->seed, NULL);
+ yahoo_auth16_stage3(gc, crypt);
+ g_free(crypt);
+ g_free(crumb);
g_free(auth_data->seed);
More information about the Commits
mailing list