Sun, 23 Jun 2013 21:35:31 +0200
HTTP: migrate purple_util_fetch_url to new API for prpls
--- a/libpurple/obsolete.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/obsolete.c Sun Jun 23 21:35:31 2013 +0200 @@ -23,8 +23,11 @@ #include "internal.h" #include "debug.h" +#include "ntlm.h" + +#if 0 #include "http.h" -#include "ntlm.h" +#endif struct _PurpleUtilFetchUrlData { @@ -65,17 +68,12 @@ gboolean chunked; PurpleAccount *account; +#if 0 PurpleHttpConnection *wrapped_request; +#endif gboolean cancelled; }; -typedef struct -{ - PurpleUtilFetchUrlData *url_data; - PurpleUtilFetchUrlCallback cb; - gpointer user_data; -} PurpleUtilLegacyWrapData; - /** * Parses a URL, returning its host, port, file path, username and password. * @@ -91,6 +89,14 @@ static gboolean purple_url_parse(const char *url, char **ret_host, int *ret_port, char **ret_path, char **ret_user, char **ret_passwd); +#if 0 + +typedef struct +{ + PurpleUtilFetchUrlData *url_data; + PurpleUtilFetchUrlCallback cb; + gpointer user_data; +} PurpleUtilLegacyWrapData; static void purple_util_fetch_url_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer _wrap_data) @@ -144,6 +150,8 @@ return url_data; } +#endif + /** * The arguments to this function are similar to printf. */ @@ -761,11 +769,13 @@ void purple_util_fetch_url_cancel(PurpleUtilFetchUrlData *gfud) { +#if 0 if (gfud->wrapped_request != NULL) { gfud->cancelled = TRUE; purple_http_conn_cancel(gfud->wrapped_request); return; } +#endif if (gfud->ssl_connection != NULL) purple_ssl_close(gfud->ssl_connection);
--- a/libpurple/obsolete.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/obsolete.h Sun Jun 23 21:35:31 2013 +0200 @@ -57,6 +57,7 @@ */ typedef void (*PurpleUtilFetchUrlCallback)(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message); +#if 0 /** * Fetches the data from a URL, and passes it to a callback function. * @@ -72,6 +73,7 @@ PurpleUtilFetchUrlData * purple_util_fetch_url(const gchar *url, gboolean full, const gchar *user_agent, gboolean http11, gssize max_len, PurpleUtilFetchUrlCallback cb, gpointer data); +#endif /** * Fetches the data from a URL, and passes it to a callback function.
--- a/libpurple/protocols/jabber/jabber.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/jabber/jabber.c Sun Jun 23 21:35:31 2013 +0200 @@ -31,6 +31,7 @@ #include "conversation.h" #include "debug.h" #include "dnssrv.h" +#include "http.h" #include "imgstore.h" #include "message.h" #include "notify.h" @@ -1640,9 +1641,9 @@ js->bs_proxies = g_list_delete_link(js->bs_proxies, js->bs_proxies); } - while(js->url_datas) { - purple_util_fetch_url_cancel(js->url_datas->data); - js->url_datas = g_slist_delete_link(js->url_datas, js->url_datas); + while(js->http_conns) { + purple_http_conn_cancel(js->http_conns->data); + js->http_conns = g_slist_delete_link(js->http_conns, js->http_conns); } g_free(js->stream_id);
--- a/libpurple/protocols/jabber/jabber.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/jabber/jabber.h Sun Jun 23 21:35:31 2013 +0200 @@ -265,10 +265,10 @@ PurpleBOSHConnection *bosh; /** - * This linked list contains PurpleUtilFetchUrlData structs + * This linked list contains PurpleHttpConnection structs * for when we lookup buddy icons from a url */ - GSList *url_datas; + GSList *http_conns; /* keep a hash table of JingleSessions */ GHashTable *sessions;
--- a/libpurple/protocols/jabber/useravatar.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/jabber/useravatar.c Sun Jun 23 21:35:31 2013 +0200 @@ -22,8 +22,8 @@ */ #include "internal.h" -#include "obsolete.h" +#include "http.h" #include "useravatar.h" #include "pep.h" #include "debug.h" @@ -260,22 +260,24 @@ } JabberBuddyAvatarUpdateURLInfo; static void -do_buddy_avatar_update_fromurl(PurpleUtilFetchUrlData *url_data, - gpointer user_data, const gchar *url_text, - gsize len, const gchar *error_message) +do_buddy_avatar_update_fromurl(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer _info) { - JabberBuddyAvatarUpdateURLInfo *info = user_data; + JabberBuddyAvatarUpdateURLInfo *info = _info; gpointer icon_data; + const gchar *got_data; + size_t got_len; - if(!url_text) { - purple_debug_error("jabber", - "do_buddy_avatar_update_fromurl got error \"%s\"", - error_message); + if (!purple_http_response_is_successfull(response)) { + purple_debug_error("jabber", "do_buddy_avatar_update_fromurl " + "got error \"%s\"", + purple_http_response_get_error(response)); goto out; } - icon_data = g_memdup(url_text, len); - purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, len, info->id); + got_data = purple_http_response_get_data(response, &got_len); + icon_data = g_memdup(got_data, got_len); + purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, got_len, info->id); out: g_free(info->from); @@ -378,20 +380,19 @@ jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id, do_buddy_avatar_update_data); } else { - PurpleUtilFetchUrlData *url_data; + PurpleHttpRequest *req; + PurpleHttpConnection *http_conn; JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1); info->js = js; - url_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, - MAX_HTTP_BUDDYICON_BYTES, - do_buddy_avatar_update_fromurl, info); - if (url_data) { - info->from = g_strdup(from); - info->id = g_strdup(id); - js->url_datas = g_slist_prepend(js->url_datas, url_data); - } else - g_free(info); + req = purple_http_request_new(url); + purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES); + http_conn = purple_http_request(js->gc, req, do_buddy_avatar_update_fromurl, info); + purple_http_request_unref(req); + info->from = g_strdup(from); + info->id = g_strdup(id); + js->http_conns = g_slist_prepend(js->http_conns, http_conn); } } }
--- a/libpurple/protocols/msn/msn.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/msn/msn.c Sun Jun 23 21:35:31 2013 +0200 @@ -26,8 +26,8 @@ #include "internal.h" #include "debug.h" +#include "http.h" #include "request.h" -#include "obsolete.h" #include "accountopt.h" #include "contact.h" @@ -2277,8 +2277,8 @@ return NULL; } -static void msn_got_photo(PurpleUtilFetchUrlData *url_data, gpointer data, - const gchar *url_text, gsize len, const gchar *error_message); +static void msn_got_photo(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _info2_data); #endif @@ -2315,10 +2315,10 @@ } static void -msn_got_info(PurpleUtilFetchUrlData *url_data, gpointer data, - const gchar *url_text, size_t len, const gchar *error_message) +msn_got_info(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer _info_data) { - MsnGetInfoData *info_data = (MsnGetInfoData *)data; + MsnGetInfoData *info_data = _info_data; MsnSession *session; PurpleNotifyUserInfo *user_info; char *stripped, *p, *q, *tmp; @@ -2330,20 +2330,20 @@ gboolean has_contact_info = FALSE; char *url_buffer; int stripped_len; + const gchar *got_data; + size_t got_len; #if PHOTO_SUPPORT char *photo_url_text = NULL; MsnGetInfoStepTwoData *info2_data = NULL; #endif - purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n",url_text); - session = purple_connection_get_protocol_data(info_data->gc); - session->url_datas = g_slist_remove(session->url_datas, url_data); + session->http_reqs = g_slist_remove(session->http_reqs, http_conn); user_info = purple_notify_user_info_new(); has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data); - if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) + if (!purple_http_response_is_successfull(response)) { purple_notify_user_info_add_pair_html(user_info, _("Error retrieving profile"), NULL); @@ -2356,12 +2356,16 @@ return; } - url_buffer = g_strdup(url_text); + got_data = purple_http_response_get_data(response, &got_len); + + purple_debug_info("msn", "In msn_got_info,url_text:{%s}\n", got_data); + + url_buffer = g_strdup(got_data); /* If they have a homepage link, MSN masks it such that we need to * fetch the url out before purple_markup_strip_html() nukes it */ /* I don't think this works with the new spaces profiles - Stu 3/2/06 */ - if ((p = strstr(url_text, + if ((p = strstr(url_buffer, "Take a look at my </font><A class=viewDesc title=\"")) != NULL) { p += 50; @@ -2709,7 +2713,7 @@ #if PHOTO_SUPPORT /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ - photo_url_text = msn_get_photo_url(url_text); + photo_url_text = msn_get_photo_url(got_data); purple_debug_info("msn", "photo url:{%s}\n", photo_url_text ? photo_url_text : "(null)"); /* Marshall the existing state */ @@ -2723,23 +2727,28 @@ /* Try to put the photo in there too, if there's one */ if (photo_url_text) { - url_data = purple_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, - MAX_HTTP_BUDDYICON_BYTES, - msn_got_photo, info2_data); - session->url_datas = g_slist_prepend(session->url_datas, url_data); + PurpleHttpRequest *req; + PurpleHttpConnection *hc; + + req = purple_http_request_new(photo_url_text); + purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES); + hc = purple_http_request(info_data->gc, req, msn_got_photo, info2_data); + purple_http_request_unref(req); + + session->http_reqs = g_slist_prepend(session->http_reqs, hc); } else { /* Finish the Get Info and show the user something */ - msn_got_photo(NULL, info2_data, NULL, 0, NULL); + msn_got_photo(NULL, NULL, info2_data); } } static void -msn_got_photo(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *url_text, gsize len, const gchar *error_message) +msn_got_photo(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _info2_data) { - MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)user_data; + MsnGetInfoStepTwoData *info2_data = _info2_data; int id = -1; /* Unmarshall the saved state */ @@ -2749,44 +2758,23 @@ PurpleNotifyUserInfo *user_info = info2_data->user_info; char *photo_url_text = info2_data->photo_url_text; - if (url_data) { + if (http_conn) { MsnSession *session = purple_connection_get_protocol_data(info_data->gc); - session->url_datas = g_slist_remove(session->url_datas, url_data); - } - - if (url_text && error_message) - { - purple_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); - g_free(stripped); - g_free(url_buffer); - purple_notify_user_info_destroy(user_info); - g_free(info_data->name); - g_free(info_data); - g_free(photo_url_text); - g_free(info2_data); - - return; + session->http_reqs = g_slist_remove(session->http_reqs, http_conn); } /* Try to put the photo in there too, if there's one and is readable */ - if (url_text && len != 0) + if (response && purple_http_response_is_successfull(response)) { - if (strstr(url_text, "400 Bad Request") - || strstr(url_text, "403 Forbidden") - || strstr(url_text, "404 Not Found")) - { - - purple_debug_info("msn", "Error getting %s: %s\n", - photo_url_text, url_text); - } - else - { - char buf[1024]; - purple_debug_info("msn", "%s is %" G_GSIZE_FORMAT " bytes\n", photo_url_text, len); - id = purple_imgstore_new_with_id(g_memdup(url_text, len), len, NULL); - g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); - purple_notify_user_info_prepend_pair_html(user_info, NULL, buf); - } + char buf[1024]; + const gchar *photo_data; + size_t len; + + photo_data = purple_http_response_get_data(response, &len); + purple_debug_info("msn", "%s is %" G_GSIZE_FORMAT " bytes\n", photo_url_text, len); + id = purple_imgstore_new_with_id(g_memdup(photo_data, len), len, NULL); + g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); + purple_notify_user_info_prepend_pair_html(user_info, NULL, buf); } /* We continue here from msn_got_info, as if nothing has happened */ @@ -2809,10 +2797,10 @@ static void msn_get_info(PurpleConnection *gc, const char *name) { + PurpleHttpConnection *hc; MsnSession *session = purple_connection_get_protocol_data(gc); MsnGetInfoData *data; char *url; - PurpleUtilFetchUrlData *url_data; data = g_new0(MsnGetInfoData, 1); data->gc = gc; @@ -2820,10 +2808,8 @@ url = g_strdup_printf("%s%s", PROFILE_URL, name); - url_data = purple_util_fetch_url(url, FALSE, - "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", - TRUE, -1, msn_got_info, data); - session->url_datas = g_slist_prepend(session->url_datas, url_data); + hc = purple_http_get(gc, url, msn_got_info, data); + session->http_reqs = g_slist_prepend(session->http_reqs, hc); g_free(url); }
--- a/libpurple/protocols/msn/session.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/msn/session.c Sun Jun 23 21:35:31 2013 +0200 @@ -24,7 +24,7 @@ #include "internal.h" #include "debug.h" -#include "obsolete.h" +#include "http.h" #include "error.h" #include "msnutils.h" @@ -65,9 +65,9 @@ session->destroying = TRUE; - while (session->url_datas) { - purple_util_fetch_url_cancel(session->url_datas->data); - session->url_datas = g_slist_delete_link(session->url_datas, session->url_datas); + while (session->http_reqs) { + purple_http_conn_cancel(session->http_reqs->data); + session->http_reqs = g_slist_delete_link(session->http_reqs, session->http_reqs); } if (session->connected)
--- a/libpurple/protocols/msn/session.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/msn/session.h Sun Jun 23 21:35:31 2013 +0200 @@ -120,7 +120,7 @@ guint soap_cleanup_handle; char *guid; - GSList *url_datas; /**< PurpleUtilFetchUrlData to be cancelled on exit */ + GSList *http_reqs; /**< PurpleHttpConnection to be cancelled on exit */ }; /**
--- a/libpurple/protocols/msn/slp.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/msn/slp.c Sun Jun 23 21:35:31 2013 +0200 @@ -24,7 +24,7 @@ #include "internal.h" #include "debug.h" -#include "obsolete.h" +#include "http.h" #include "slp.h" #include "slpcall.h" @@ -171,23 +171,27 @@ } static void -fetched_user_display(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *url_text, gsize len, const gchar *error_message) +fetched_user_display(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer _data) { - MsnFetchUserDisplayData *data = user_data; + MsnFetchUserDisplayData *data = _data; MsnSession *session = data->session; - session->url_datas = g_slist_remove(session->url_datas, url_data); + session->http_reqs = g_slist_remove(session->http_reqs, http_conn); - if (url_text) { - purple_buddy_icons_set_for_user(session->account, data->remote_user, - g_memdup(url_text, len), len, - data->sha1); + if (purple_http_response_is_successfull(response)) { + size_t len; + const gchar *icon_data; + + icon_data = purple_http_response_get_data(response, &len); + purple_buddy_icons_set_for_user(session->account, + data->remote_user, g_memdup(icon_data, len), len, + data->sha1); } end_user_display(NULL, session); - g_free(user_data); + g_free(data); } static void @@ -249,14 +253,18 @@ { const char *url = msn_object_get_url1(obj); if (url) { + PurpleHttpRequest *req; + PurpleHttpConnection *hc; MsnFetchUserDisplayData *data = g_new0(MsnFetchUserDisplayData, 1); - PurpleUtilFetchUrlData *url_data; data->session = session; data->remote_user = user->passport; data->sha1 = info; - url_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, 200*1024, - fetched_user_display, data); - session->url_datas = g_slist_prepend(session->url_datas, url_data); + + req = purple_http_request_new(url); + purple_http_request_set_max_len(req, 200*1024); + hc = purple_http_request(NULL, req, fetched_user_display, data); + purple_http_request_unref(req); + session->http_reqs = g_slist_prepend(session->http_reqs, hc); } else { msn_slplink_request_object(slplink, info, got_user_display, end_user_display, obj);
--- a/libpurple/protocols/mxit/formcmds.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/mxit/formcmds.c Sun Jun 23 21:35:31 2013 +0200 @@ -26,7 +26,7 @@ #include "internal.h" #include "debug.h" -#include "obsolete.h" +#include "libpurple/http.h" #include "protocol.h" #include "mxit.h" @@ -75,24 +75,22 @@ /*------------------------------------------------------------------------ * Callback function invoked when an inline image request to a web site completes. - * - * @param url_data - * @param user_data The Markup message object - * @param url_text The data returned from the WAP site - * @param len The length of the data returned - * @param error_message Descriptive error message */ -static void mxit_cb_ii_returned(PurpleUtilFetchUrlData* url_data, gpointer user_data, const gchar* url_text, gsize len, const gchar* error_message) +static void +mxit_cb_ii_returned(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _iireq) { - struct ii_url_request* iireq = (struct ii_url_request*) user_data; + struct ii_url_request* iireq = _iireq; int* intptr = NULL; int id; + const gchar* data; + size_t len; #ifdef MXIT_DEBUG_COMMANDS purple_debug_info(MXIT_PLUGIN_ID, "Inline Image returned from %s\n", iireq->url); #endif - if (!url_text) { + if (!purple_http_response_is_successfull(response)) { /* no reply from the WAP site */ purple_debug_error(MXIT_PLUGIN_ID, "Error downloading Inline Image from %s.\n", iireq->url); goto done; @@ -105,7 +103,8 @@ } /* we now have the inline image, store a copy in the imagestore */ - id = purple_imgstore_new_with_id(g_memdup(url_text, len), len, NULL); + data = purple_http_response_get_data(response, &len); + id = purple_imgstore_new_with_id(g_memdup(data, len), len, NULL); /* map the inline image id to purple image id */ intptr = g_malloc(sizeof(int)); @@ -360,8 +359,7 @@ /* send the request for the inline image */ purple_debug_info(MXIT_PLUGIN_ID, "sending request for inline image '%s'\n", iireq->url); - /* request the image (reference: "libpurple/util.h") */ - purple_util_fetch_url(iireq->url, TRUE, NULL, TRUE, -1, mxit_cb_ii_returned, iireq); + purple_http_get(mx->session->con, iireq->url, mxit_cb_ii_returned, iireq); mx->img_count++; } }
--- a/libpurple/protocols/mxit/markup.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/mxit/markup.c Sun Jun 23 21:35:31 2013 +0200 @@ -25,6 +25,7 @@ #include "internal.h" #include "debug.h" +#include "libpurple/http.h" #include "obsolete.h" #include "protocol.h" @@ -464,17 +465,13 @@ /*------------------------------------------------------------------------ * Callback function invoked when a custom emoticon request to the WAP site completes. - * - * @param url_data - * @param user_data The Markup message object - * @param url_text The data returned from the WAP site - * @param len The length of the data returned - * @param error_message Descriptive error message */ -static void emoticon_returned( PurpleUtilFetchUrlData* url_data, gpointer user_data, const gchar* url_text, gsize len, const gchar* error_message ) +static void emoticon_returned(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer user_data) { struct RXMsgData* mx = (struct RXMsgData*) user_data; - const char* data = url_text; + const gchar* data; + size_t len; unsigned int pos = 0; char emo[16]; int id; @@ -490,14 +487,16 @@ #endif /* remove request from the async outstanding calls list */ - mx->session->async_calls = g_slist_remove( mx->session->async_calls, url_data ); + mx->session->async_http_reqs = g_slist_remove(mx->session->async_http_reqs, http_conn); - if ( !url_text ) { + if (!purple_http_response_is_successfull(response)) { /* no reply from the WAP site */ purple_debug_error( MXIT_PLUGIN_ID, "Error contacting the MXit WAP site. Please try again later (emoticon).\n" ); goto done; } + data = purple_http_response_get_data(response, &len); + #ifdef MXIT_DEBUG_EMO hex_dump( data, len ); #endif @@ -626,7 +625,7 @@ */ static void emoticon_request( struct RXMsgData* mx, const char* id ) { - PurpleUtilFetchUrlData* url_data; + PurpleHttpConnection *hc; const char* wapserver; char* url; @@ -634,12 +633,9 @@ wapserver = purple_account_get_string( mx->session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE ); - /* reference: "libpurple/util.h" */ url = g_strdup_printf( "%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver, MXIT_EMOTICON_SIZE, id, time( NULL ) ); - url_data = purple_util_fetch_url( url, TRUE, NULL, TRUE, -1, emoticon_returned, mx ); - if ( url_data ) - mx->session->async_calls = g_slist_prepend( mx->session->async_calls, url_data ); - + hc = purple_http_get(mx->session->con, url, emoticon_returned, mx); + mx->session->async_http_reqs = g_slist_prepend(mx->session->async_http_reqs, hc); g_free( url ); }
--- a/libpurple/protocols/mxit/mxit.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/mxit/mxit.h Sun Jun 23 21:35:31 2013 +0200 @@ -169,6 +169,7 @@ guint q_slow_timer_id; /* timer handle for slow tx queue */ guint q_fast_timer_id; /* timer handle for fast tx queue */ GSList* async_calls; /* list of current outstanding async calls */ + GSList* async_http_reqs; /* list of current outstanding async http requests */ /* receive */ char rx_lbuf[16]; /* receive byte buffer (socket packet length) */
--- a/libpurple/protocols/mxit/protocol.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/mxit/protocol.c Sun Jun 23 21:35:31 2013 +0200 @@ -2911,6 +2911,10 @@ purple_util_fetch_url_cancel( session->async_calls->data ); session->async_calls = g_slist_delete_link( session->async_calls, session->async_calls ); } + while (session->async_http_reqs) { + purple_http_conn_cancel(session->async_http_reqs->data); + session->async_http_reqs = g_slist_delete_link(session->async_http_reqs, session->async_http_reqs); + } /* remove the input cb function */ if ( session->inpa ) {
--- a/libpurple/protocols/myspace/myspace.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/myspace/myspace.c Sun Jun 23 21:35:31 2013 +0200 @@ -3367,93 +3367,6 @@ } #endif -#ifdef MSIM_CHECK_NEWER_VERSION -/** - * Callback for when a currentversion.txt has been downloaded. - */ -static void -msim_check_newer_version_cb(PurpleUtilFetchUrlData *url_data, - gpointer user_data, - const gchar *url_text, - gsize len, - const gchar *error_message) -{ - GKeyFile *keyfile; - GError *error; - GString *data; - gchar *newest_filever; - - if (!url_text) { - purple_debug_info("msim_check_newer_version_cb", - "got error: %s\n", error_message); - return; - } - - purple_debug_info("msim_check_newer_version_cb", - "url_text=%s\n", url_text ? url_text : "(NULL)"); - - /* Prepend [group] so that GKeyFile can parse it (requires a group). */ - data = g_string_new(url_text); - purple_debug_info("msim", "data=%s\n", data->str - ? data->str : "(NULL)"); - data = g_string_prepend(data, "[group]\n"); - - purple_debug_info("msim", "data=%s\n", data->str - ? data->str : "(NULL)"); - - /* url_text is variable=data\n...†*/ - - /* Check FILEVER, 1.0.716.0. 716 is build, MSIM_CLIENT_VERSION */ - /* New (english) version can be downloaded from SETUPURL+SETUPFILE */ - - error = NULL; - keyfile = g_key_file_new(); - - /* Default list seperator is ;, but currentversion.txt doesn't have - * these, so set to an unused character to avoid parsing problems. */ - g_key_file_set_list_separator(keyfile, '\0'); - - g_key_file_load_from_data(keyfile, data->str, data->len, - G_KEY_FILE_NONE, &error); - g_string_free(data, TRUE); - - if (error != NULL) { - purple_debug_info("msim_check_newer_version_cb", - "couldn't parse, error: %d %d %s\n", - error->domain, error->code, error->message); - g_error_free(error); - return; - } - - gchar **ks; - guint n; - ks = g_key_file_get_keys(keyfile, "group", &n, NULL); - purple_debug_info("msim", "n=%d\n", n); - guint i; - for (i = 0; ks[i] != NULL; ++i) - { - purple_debug_info("msim", "%d=%s\n", i, ks[i]); - } - - newest_filever = g_key_file_get_string(keyfile, "group", - "FILEVER", &error); - - purple_debug_info("msim_check_newer_version_cb", - "newest filever: %s\n", newest_filever ? - newest_filever : "(NULL)"); - if (error != NULL) { - purple_debug_info("msim_check_newer_version_cb", - "error: %d %d %s\n", - error->domain, error->code, error->message); - g_error_free(error); - } - - g_key_file_free(keyfile); - - exit(0); -} -#endif - /** Handle a myim:addContact command, after username has been looked up. */ @@ -3615,17 +3528,6 @@ PurpleAccountOption *option; static gboolean initialized = FALSE; -#ifdef MSIM_CHECK_NEWER_VERSION - /* PROBLEM: MySpace's servers always return Content-Location, and - * libpurple redirects to it, infinitely, even though it is the same - * location we requested! */ - purple_util_fetch_url("http://im.myspace.com/nsis/currentversion.txt", - FALSE, /* not full URL */ - "MSIMAutoUpdateAgent", /* user agent */ - TRUE, /* use HTTP/1.1 */ - msim_check_newer_version_cb, NULL); -#endif - /* TODO: default to automatically try different ports. Make the user be * able to set the first port to try (like LastConnectedPort in Windows client). */ option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
--- a/libpurple/protocols/myspace/myspace.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/myspace/myspace.h Sun Jun 23 21:35:31 2013 +0200 @@ -95,10 +95,6 @@ /* Build version of MySpaceIM to report to servers (1.0.xxx.0) */ #define MSIM_CLIENT_VERSION 697 -/* Check for a newer official MySpaceIM client on startup? - * (Mostly useful for developers) */ -/*#define MSIM_CHECK_NEWER_VERSION*/ - /* Language codes from http://www.microsoft.com/globaldev/reference/oslocversion.mspx */ #define MSIM_LANGUAGE_ID_ENGLISH 1033 #define MSIM_LANGUAGE_NAME_ENGLISH "ENGLISH"
--- a/libpurple/protocols/myspace/user.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/myspace/user.c Sun Jun 23 21:35:31 2013 +0200 @@ -72,9 +72,7 @@ if (!user) return; - if (user->url_data != NULL) - purple_util_fetch_url_cancel(user->url_data); - + purple_http_conn_cancel(user->http_conn); g_free(user->client_info); g_free(user->gender); g_free(user->location); @@ -215,31 +213,33 @@ * Callback for when a buddy icon finished being downloaded. */ static void -msim_downloaded_buddy_icon(PurpleUtilFetchUrlData *url_data, - gpointer user_data, - const gchar *url_text, - gsize len, - const gchar *error_message) +msim_downloaded_buddy_icon(PurpleHttpConnection *http_conn, + PurpleHttpResponse *response, gpointer _user) { - MsimUser *user = (MsimUser *)user_data; + MsimUser *user = _user; const char *name = purple_buddy_get_name(user->buddy); PurpleAccount *account; - - user->url_data = NULL; + const gchar *data; + size_t len; - purple_debug_info("msim_downloaded_buddy_icon", - "Downloaded %" G_GSIZE_FORMAT " bytes\n", len); + g_assert(user->http_conn == http_conn); + user->http_conn = NULL; - if (!url_text) { + if (!purple_http_response_is_successfull(response)) { purple_debug_info("msim_downloaded_buddy_icon", "failed to download icon for %s", name); return; } + data = purple_http_response_get_data(response, &len); + + purple_debug_info("msim_downloaded_buddy_icon", + "Downloaded %" G_GSIZE_FORMAT " bytes\n", len); + account = purple_buddy_get_account(user->buddy); purple_buddy_icons_set_for_user(account, name, - g_memdup((gchar *)url_text, len), len, + g_memdup(data, len), len, /* Use URL itself as buddy icon "checksum" (TODO: ETag) */ user->image_url); /* checksum */ } @@ -382,9 +382,8 @@ /* Only download if URL changed */ if (!previous_url || !g_str_equal(previous_url, user->image_url)) { - if (user->url_data != NULL) - purple_util_fetch_url_cancel(user->url_data); - user->url_data = purple_util_fetch_url(user->image_url, TRUE, NULL, TRUE, -1, msim_downloaded_buddy_icon, (gpointer)user); + purple_http_conn_cancel(user->http_conn); + user->http_conn = purple_http_get(NULL, user->image_url, msim_downloaded_buddy_icon, user); } } else if (g_str_equal(key_str, "LastImageUpdated")) { /* TODO: use somewhere */
--- a/libpurple/protocols/myspace/user.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/myspace/user.h Sun Jun 23 21:35:31 2013 +0200 @@ -20,7 +20,7 @@ #ifndef _MYSPACE_USER_H #define _MYSPACE_USER_H -#include "obsolete.h" +#include "http.h" /* Hold ephemeral information about buddies, for proto_data of PurpleBuddy. */ /* GHashTable? */ @@ -42,7 +42,7 @@ gchar *image_url; guint last_image_updated; gboolean temporary_user; - PurpleUtilFetchUrlData *url_data; + PurpleHttpConnection *http_conn; } MsimUser; /* Callback function pointer type for when a user's information is received,
--- a/libpurple/protocols/yahoo/libymsg.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/yahoo/libymsg.c Sun Jun 23 21:35:31 2013 +0200 @@ -31,6 +31,7 @@ #include "cmds.h" #include "core.h" #include "debug.h" +#include "http.h" #include "network.h" #include "notify.h" #include "privacy.h" @@ -54,6 +55,7 @@ /* #define YAHOO_DEBUG */ +/* Not tested with new HTTP API, because it doesn't compile at the moment. */ /* #define TRY_WEBMESSENGER_LOGIN 0 */ /* One hour */ @@ -2216,7 +2218,8 @@ case 13: #ifdef TRY_WEBMESSENGER_LOGIN if (!yd->wm) { - PurpleUtilFetchUrlData *url_data; + PurpleHttpRequest *req; + PurpleHttpConnection *hc; yd->wm = TRUE; if (yd->fd >= 0) close(yd->fd); @@ -2224,10 +2227,11 @@ purple_input_remove(yd->inpa); yd->inpa = 0; } - url_data = purple_util_fetch_url(WEBMESSENGER_URL, TRUE, - "Purple/" VERSION, FALSE, -1, yahoo_login_page_cb, gc); - if (url_data != NULL) - yd->url_datas = g_slist_prepend(yd->url_datas, url_data); + req = purple_http_request_new(WEBMESSENGER_URL); + purple_http_request_header_set(req, "User-Agent", "Purple/" VERSION); + hc = purple_http_request(gc, req, yahoo_login_page_cb, NULL); + purple_http_request_unref(req); + yd->http_reqs = g_slist_prepend(yd->http_reqs, hc); return; } #endif /* TRY_WEBMESSENGER_LOGIN */ @@ -3447,15 +3451,17 @@ } static void -yahoo_login_page_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *url_text, size_t len, const gchar *error_message) +yahoo_login_page_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _unused) { - PurpleConnection *gc = (PurpleConnection *)user_data; + PurpleConnection *gc = purple_http_conn_get_purple_connection(http_conn); PurpleAccount *account = purple_connection_get_account(gc); YahooData *yd = purple_connection_get_protocol_data(gc); const char *sn = purple_account_get_username(account); const char *pass = purple_connection_get_password(gc); - GHashTable *hash = yahoo_login_page_hash(url_text, len); + size_t len; + const gchar *got_data; + GHashTable *hash; GString *url = g_string_new("GET http://login.yahoo.com/config/login?login="); char md5[33], *hashp = md5, *chal; int i; @@ -3463,15 +3469,18 @@ PurpleCipherContext *context; guchar digest[16]; - 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)) { purple_connection_error(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, - error_message); + purple_http_response_get_error(response)); return; } + got_data = purple_http_response_get_data(response, &len); + hash = yahoo_login_page_hash(got_data, len); + url = g_string_append(url, sn); url = g_string_append(url, "&passwd="); @@ -3712,6 +3721,10 @@ purple_util_fetch_url_cancel(yd->url_datas->data); yd->url_datas = g_slist_delete_link(yd->url_datas, yd->url_datas); } + while (yd->http_reqs) { + purple_http_conn_cancel(yd->http_reqs->data); + yd->http_reqs = g_slist_delete_link(yd->http_reqs, yd->http_reqs); + } for (l = yd->confs; l; l = l->next) { PurpleConversation *conv = l->data;
--- a/libpurple/protocols/yahoo/libymsg.h Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/yahoo/libymsg.h Sun Jun 23 21:35:31 2013 +0200 @@ -240,10 +240,14 @@ struct _YchtConn *ycht; /** - * This linked list contains PurpleUtilFetchUrlData structs + * This linked list contains PurpleHttpConnection structs * for when we lookup people profile or photo information. */ + GSList *http_reqs; + + /* TODO: remove it */ GSList *url_datas; + GHashTable *xfer_peer_idstring_map;/* Hey, i dont know, but putting this HashTable next to friends gives a run time fault... */ GSList *cookies;/* contains all cookies, including _y and _t */ PurpleNetworkListenData *listen_data;
--- a/libpurple/protocols/yahoo/yahoo_picture.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/yahoo/yahoo_picture.c Sun Jun 23 21:35:31 2013 +0200 @@ -28,6 +28,7 @@ #include "accountopt.h" #include "blist.h" #include "debug.h" +#include "http.h" #include "privacy.h" #include "prpl.h" #include "proxy.h" @@ -46,23 +47,28 @@ }; static void -yahoo_fetch_picture_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *pic_data, size_t len, const gchar *error_message) +yahoo_fetch_picture_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _data) { - struct yahoo_fetch_picture_data *d; + struct yahoo_fetch_picture_data *d = _data; YahooData *yd; - d = user_data; yd = purple_connection_get_protocol_data(d->gc); - yd->url_datas = g_slist_remove(yd->url_datas, url_data); + yd->http_reqs = g_slist_remove(yd->http_reqs, http_conn); - if (error_message != NULL) { - purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", error_message); - } else if (len == 0) { - purple_debug_error("yahoo", "Fetched an icon with length 0. Strange.\n"); + if (!purple_http_response_is_successfull(response)) { + purple_debug_error("yahoo", "Fetching buddy icon failed: %s\n", + purple_http_response_get_error(response)); } else { char *checksum = g_strdup_printf("%i", d->checksum); - purple_buddy_icons_set_for_user(purple_connection_get_account(d->gc), d->who, g_memdup(pic_data, len), len, checksum); + const gchar *pic_data; + size_t pic_len; + + pic_data = purple_http_response_get_data(response, &pic_len); + + purple_buddy_icons_set_for_user( + purple_connection_get_account(d->gc), d->who, + g_memdup(pic_data, pic_len), pic_len, checksum); g_free(checksum); } @@ -121,23 +127,16 @@ /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ if (who && got_icon_info && url && !g_ascii_strncasecmp(url, "http://", 7)) { /* TODO: make this work p2p, try p2p before the url */ - PurpleUtilFetchUrlData *url_data; + PurpleHttpConnection *hc; struct yahoo_fetch_picture_data *data; - /* use whole URL if using HTTP Proxy */ - gboolean use_whole_url = yahoo_account_use_http_proxy(gc); data = g_new0(struct yahoo_fetch_picture_data, 1); data->gc = gc; data->who = g_strdup(who); data->checksum = checksum; - /* TODO: Does this need to be MSIE 5.0? */ - url_data = purple_util_fetch_url(url, use_whole_url, - "Mozilla/4.0 (compatible; MSIE 5.5)", FALSE, -1, - yahoo_fetch_picture_cb, data); - if (url_data != NULL) { - yd = purple_connection_get_protocol_data(gc); - yd->url_datas = g_slist_prepend(yd->url_datas, url_data); - } + hc = purple_http_get(gc, url, yahoo_fetch_picture_cb, data); + yd = purple_connection_get_protocol_data(gc); + yd->http_reqs = g_slist_prepend(yd->http_reqs, hc); } else if (who && send_icon_info) { yahoo_send_picture_info(gc, who); }
--- a/libpurple/protocols/yahoo/yahoo_profile.c Sun Jun 23 13:19:25 2013 +0200 +++ b/libpurple/protocols/yahoo/yahoo_profile.c Sun Jun 23 21:35:31 2013 +0200 @@ -24,8 +24,8 @@ #define PHOTO_SUPPORT 1 #include "internal.h" -#include "obsolete.h" #include "debug.h" +#include "http.h" #include "notify.h" #include "util.h" #if PHOTO_SUPPORT @@ -757,15 +757,16 @@ } static void -yahoo_got_photo(PurpleUtilFetchUrlData *url_data, gpointer data, - const gchar *url_text, size_t len, const gchar *error_message); +yahoo_got_photo(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _info2_data); #endif /* PHOTO_SUPPORT */ -static void yahoo_got_info(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *url_text, size_t len, const gchar *error_message) +static void +yahoo_got_info(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _info_data) { - YahooGetInfoData *info_data = (YahooGetInfoData *)user_data; + YahooGetInfoData *info_data = _info_data; PurpleNotifyUserInfo *user_info; char *p; #if PHOTO_SUPPORT @@ -787,11 +788,12 @@ const profile_strings_node_t *strings = NULL; const char *title; profile_state_t profile_state = PROFILE_STATE_DEFAULT; + const gchar *url_text; purple_debug_info("yahoo", "In yahoo_got_info\n"); yd = purple_connection_get_protocol_data(info_data->gc); - yd->url_datas = g_slist_remove(yd->url_datas, url_data); + yd->http_reqs = g_slist_remove(yd->http_reqs, http_conn); user_info = purple_notify_user_info_new(); @@ -805,7 +807,7 @@ * happen except under unusual error conditions, as Yahoo is observed * to send back HTML, with a 200 status code. */ - if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) { + if (!purple_http_response_is_successfull(response)) { purple_notify_user_info_add_pair_html(user_info, _("Error retrieving profile"), NULL); purple_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL); @@ -816,6 +818,8 @@ return; } + url_text = purple_http_response_get_data(response, NULL); + /* Construct the correct profile URL */ s = g_string_sized_new(80); /* wild guess */ g_string_printf(s, "%s%s", (yd->jp? YAHOOJP_PROFILE_URL: YAHOO_PROFILE_URL), @@ -932,29 +936,20 @@ /* Try to put the photo in there too, if there's one */ if (photo_url_text) { - PurpleUtilFetchUrlData *url_data; - /* use whole URL if using HTTP Proxy */ - gboolean use_whole_url = yahoo_account_use_http_proxy(info_data->gc); - - /* User-uploaded photos use a different server that requires the Host - * header, but Yahoo Japan will use the "chunked" content encoding if - * we specify HTTP 1.1. So we have to specify 1.0 & fix purple_util_fetch_url - */ - url_data = purple_util_fetch_url(photo_url_text, use_whole_url, NULL, - FALSE, -1, yahoo_got_photo, info2_data); - if (url_data != NULL) - yd->url_datas = g_slist_prepend(yd->url_datas, url_data); + PurpleHttpConnection *hc; + hc = purple_http_get(info_data->gc, photo_url_text, yahoo_got_photo, info2_data); + yd->http_reqs = g_slist_prepend(yd->http_reqs, hc); } else { /* Emulate a callback */ - yahoo_got_photo(NULL, info2_data, NULL, 0, NULL); + yahoo_got_photo(NULL, NULL, info2_data); } } static void -yahoo_got_photo(PurpleUtilFetchUrlData *url_data, gpointer data, - const gchar *url_text, size_t len, const gchar *error_message) +yahoo_got_photo(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, + gpointer _info2_data) { - YahooGetInfoStepTwoData *info2_data = (YahooGetInfoStepTwoData *)data; + YahooGetInfoStepTwoData *info2_data = _info2_data; YahooData *yd; gboolean found = FALSE; int id = -1; @@ -985,7 +980,8 @@ char *fudged_buffer; yd = purple_connection_get_protocol_data(info_data->gc); - yd->url_datas = g_slist_remove(yd->url_datas, url_data); + if (http_conn) + yd->http_reqs = g_slist_remove(yd->http_reqs, http_conn); fudged_buffer = purple_strcasereplace(url_buffer, "</dd>", "</dd><br>"); /* nuke the html, it's easier than trying to parse the horrid stuff */ @@ -1036,23 +1032,21 @@ #if PHOTO_SUPPORT /* Try to put the photo in there too, if there's one and is readable */ - if (url_text && len != 0) { - if (strstr(url_text, "400 Bad Request") - || strstr(url_text, "403 Forbidden") - || strstr(url_text, "404 Not Found")) { + if (purple_http_response_is_successfull(response)) { + const gchar *data; + size_t len; + + data = purple_http_response_get_data(response, &len); - purple_debug_info("yahoo", "Error getting %s: %s\n", - photo_url_text, url_text); - } else { - purple_debug_info("yahoo", "%s is %" G_GSIZE_FORMAT - " bytes\n", photo_url_text, len); - id = purple_imgstore_new_with_id(g_memdup(url_text, len), len, NULL); + purple_debug_info("yahoo", "%s is %" G_GSIZE_FORMAT " bytes\n", + photo_url_text, len); + id = purple_imgstore_new_with_id(g_memdup(data, len), len, + NULL); - tmp = g_strdup_printf("<img id=\"" PURPLE_STORED_IMAGE_PROTOCOL "%d\"><br>", - id); - purple_notify_user_info_add_pair_html(user_info, NULL, tmp); - g_free(tmp); - } + tmp = g_strdup_printf("<img id=\"" PURPLE_STORED_IMAGE_PROTOCOL + "%d\"><br>", id); + purple_notify_user_info_add_pair_html(user_info, NULL, tmp); + g_free(tmp); } #endif /* PHOTO_SUPPORT */ @@ -1267,7 +1261,7 @@ YahooData *yd = purple_connection_get_protocol_data(gc); YahooGetInfoData *data; char *url; - PurpleUtilFetchUrlData *url_data; + PurpleHttpConnection *hc; data = g_new0(YahooGetInfoData, 1); data->gc = gc; @@ -1276,9 +1270,8 @@ url = g_strdup_printf("%s%s", (yd->jp ? YAHOOJP_PROFILE_URL : YAHOO_PROFILE_URL), name); - url_data = purple_util_fetch_url(url, TRUE, NULL, FALSE, -1, yahoo_got_info, data); - if (url_data != NULL) - yd->url_datas = g_slist_prepend(yd->url_datas, url_data); + hc = purple_http_get(gc, url, yahoo_got_info, data); + yd->http_reqs = g_slist_prepend(yd->http_reqs, hc); g_free(url); }