/pidgin/main: b04c63c278f3: HTTP: migrate purple_util_fetch_url ...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Sun Jun 23 07:19:33 EDT 2013


Changeset: b04c63c278f390b7c81391a112a1e2657b871de7
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-06-23 13:19 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/b04c63c278f3

Description:

HTTP: migrate purple_util_fetch_url to new API for finch tinyurl plugin

diffstat:

 finch/plugins/gnttinyurl.c |  51 ++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 17 deletions(-)

diffs (121 lines):

diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -21,7 +21,6 @@
 
 #include "internal.h"
 #include <glib.h>
-#include "obsolete.h"
 
 #define PLUGIN_STATIC_NAME	TinyURL
 #define PREFS_BASE          "/plugins/gnt/tinyurl"
@@ -30,6 +29,7 @@
 
 
 #include <conversation.h>
+#include <http.h>
 #include <signals.h>
 
 #include <glib.h>
@@ -203,17 +203,26 @@ static GList *extract_urls(const char *t
 	return ret;
 }
 
-static void url_fetched(PurpleUtilFetchUrlData *url_data, gpointer cb_data,
-				const gchar *url_text, gsize len, const gchar *error_message)
+
+
+static void url_fetched(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer _data)
 {
-	CbInfo *data = (CbInfo *)cb_data;
+	CbInfo *data = (CbInfo *)_data;
 	PurpleConversation *conv = data->conv;
 	GList *convs = purple_get_conversations();
+	const gchar *url;
+
+	if (purple_http_response_is_successfull(response))
+		url = purple_http_response_get_data(response, NULL);
+	else
+		url = _("Error while querying TinyURL");
+
 	/* ensure the conversation still exists */
 	for (; convs; convs = convs->next) {
 		if ((PurpleConversation *)(convs->data) == conv) {
 			FinchConv *fconv = FINCH_CONV(conv);
-			gchar *str = g_strdup_printf("[%d] %s", data->num, url_text);
+			gchar *str = g_strdup_printf("[%d] %s", data->num, url);
 			GntTextView *tv = GNT_TEXT_VIEW(fconv->tv);
 			gnt_text_view_tag_change(tv, data->tag, str, FALSE);
 			g_free(str);
@@ -320,7 +329,7 @@ process_urls(PurpleConversation *conv, G
 			url = g_strdup_printf("%s%s", purple_prefs_get_string(PREF_URL), purple_url_encode(tmp));
 		}
 		g_free(tmp);
-		purple_util_fetch_url(url, TRUE, "finch", FALSE, -1, url_fetched, cbdata);
+		purple_http_get(NULL, url, url_fetched, cbdata);
 		i = gnt_text_view_get_lines_below(tv);
 		str = g_strdup_printf(_("\nFetching TinyURL..."));
 		gnt_text_view_append_text_with_tag((tv), str, GNT_TEXT_FLAG_DIM, cbdata->tag);
@@ -342,20 +351,27 @@ free_conv_urls(PurpleConversation *conv)
 	g_list_free(urls);
 }
 
-static void tinyurl_notify_fetch_cb(PurpleUtilFetchUrlData *urldata, gpointer cbdata,
-		const gchar *urltext, gsize len, const gchar *error)
+static void
+tinyurl_notify_fetch_cb(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer _win)
 {
-	GntWidget *win = cbdata;
+	GntWidget *win = _win;
 	GntWidget *label = g_object_get_data(G_OBJECT(win), "info-widget");
 	char *message;
+	const gchar *url;
 
-	message = g_strdup_printf(_("TinyURL for above: %s"), urltext);
+	if (!purple_http_response_is_successfull(response))
+		return;
+
+	url = purple_http_response_get_data(response, NULL);
+
+	message = g_strdup_printf(_("TinyURL for above: %s"), url);
 	gnt_label_set_text(GNT_LABEL(label), message);
 	g_free(message);
 
 	g_signal_handlers_disconnect_matched(G_OBJECT(win), G_SIGNAL_MATCH_FUNC,
 			0, 0, NULL,
-			G_CALLBACK(purple_util_fetch_url_cancel), NULL);
+			G_CALLBACK(purple_http_conn_cancel), NULL);
 }
 
 static void *
@@ -363,7 +379,7 @@ tinyurl_notify_uri(const char *uri)
 {
 	char *fullurl = NULL;
 	GntWidget *win;
-	PurpleUtilFetchUrlData *urlcb;
+	PurpleHttpConnection *hc;
 
 	/* XXX: The following expects that finch_notify_message gets called. This
 	 * may not always happen, e.g. when another plugin sets its own
@@ -381,13 +397,14 @@ tinyurl_notify_uri(const char *uri)
 				purple_url_encode(uri));
 	}
 
-	/* Store the return value of _fetch_url and destroy that when win is
-	   destroyed, so that the callback for _fetch_url does not try to molest a
-	   non-existent window */
-	urlcb = purple_util_fetch_url(fullurl, TRUE, "finch", FALSE, -1, tinyurl_notify_fetch_cb, win);
+	/* Store the return value of purple_http_get and destroy that when win
+	 * is destroyed, so that the callback for purple_http_get does not try
+	 * to molest a non-existent window
+	 */
+	hc = purple_http_get(NULL, fullurl, tinyurl_notify_fetch_cb, win);
 	g_free(fullurl);
 	g_signal_connect_swapped(G_OBJECT(win), "destroy",
-			G_CALLBACK(purple_util_fetch_url_cancel), urlcb);
+			G_CALLBACK(purple_http_conn_cancel), hc);
 
 	return win;
 }



More information about the Commits mailing list