/pidgin/main: 8bdcc4f84a5e: HTTP: introduce purple_http_get_prin...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Wed Jul 3 21:24:19 EDT 2013


Changeset: 8bdcc4f84a5e94fd904a05ed3427cd8042828a5e
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-07-04 03:24 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/8bdcc4f84a5e

Description:

HTTP: introduce purple_http_get_printf, make purple_http_get consistent with it

diffstat:

 finch/plugins/gnttinyurl.c                |   4 ++--
 libpurple/http.c                          |  24 ++++++++++++++++++++++--
 libpurple/http.h                          |  28 +++++++++++++++++++++-------
 libpurple/protocols/msn/msn.c             |   8 ++------
 libpurple/protocols/mxit/formcmds.c       |   2 +-
 libpurple/protocols/mxit/markup.c         |   7 +++----
 libpurple/protocols/myspace/user.c        |   2 +-
 libpurple/protocols/yahoo/yahoo_picture.c |   2 +-
 libpurple/protocols/yahoo/yahoo_profile.c |  12 ++++--------
 pidgin/gtksmiley.c                        |   2 +-
 pidgin/plugins/relnot.c                   |   2 +-
 11 files changed, 59 insertions(+), 34 deletions(-)

diffs (242 lines):

diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -329,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_http_get(NULL, url, url_fetched, cbdata);
+		purple_http_get(NULL, url_fetched, cbdata, url);
 		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);
@@ -401,7 +401,7 @@ tinyurl_notify_uri(const char *uri)
 	 * 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);
+	hc = purple_http_get(NULL, tinyurl_notify_fetch_cb, win, fullurl);
 	g_free(fullurl);
 	g_signal_connect_swapped(G_OBJECT(win), "destroy",
 			G_CALLBACK(purple_http_conn_cancel), hc);
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -1243,8 +1243,8 @@ static gboolean purple_http_request_time
 	return FALSE;
 }
 
-PurpleHttpConnection * purple_http_get(PurpleConnection *gc, const gchar *url,
-	PurpleHttpCallback callback, gpointer user_data)
+PurpleHttpConnection * purple_http_get(PurpleConnection *gc,
+	PurpleHttpCallback callback, gpointer user_data, const gchar *url)
 {
 	PurpleHttpRequest *request;
 	PurpleHttpConnection *hc;
@@ -1258,6 +1258,26 @@ PurpleHttpConnection * purple_http_get(P
 	return hc;
 }
 
+PurpleHttpConnection * purple_http_get_printf(PurpleConnection *gc,
+	PurpleHttpCallback callback, gpointer user_data,
+	const gchar *format, ...)
+{
+	va_list args;
+	gchar *value;
+	PurpleHttpConnection *ret;
+
+	g_return_val_if_fail(format != NULL, NULL);
+
+	va_start(args, format);
+	value = g_strdup_vprintf(format, args);
+	va_end(args);
+
+	ret = purple_http_get(gc, callback, user_data, value);
+	g_free(value);
+
+	return ret;
+}
+
 PurpleHttpConnection * purple_http_request(PurpleConnection *gc,
 	PurpleHttpRequest *request, PurpleHttpCallback callback,
 	gpointer user_data)
diff --git a/libpurple/http.h b/libpurple/http.h
--- a/libpurple/http.h
+++ b/libpurple/http.h
@@ -125,14 +125,28 @@ G_BEGIN_DECLS
  * Fetches the data from a URL with GET request, and passes it to a callback
  * function.
  *
- * @param gc       The connection for which the request is needed, or NULL.
- * @param url      The URL.
- * @param callback The callback function.
- * @param data     The user data to pass to the callback function.
- * @return         The HTTP connection struct.
+ * @param gc        The connection for which the request is needed, or NULL.
+ * @param callback  The callback function.
+ * @param user_data The user data to pass to the callback function.
+ * @param url       The URL.
+ * @return          The HTTP connection struct.
  */
-PurpleHttpConnection * purple_http_get(PurpleConnection *gc, const gchar *url,
-	PurpleHttpCallback callback, gpointer user_data);
+PurpleHttpConnection * purple_http_get(PurpleConnection *gc,
+	PurpleHttpCallback callback, gpointer user_data, const gchar *url);
+
+/**
+ * Constructs an URL and fetches the data from it with GET request, then passes
+ * it to a callback function.
+ *
+ * @param gc        The connection for which the request is needed, or NULL.
+ * @param callback  The callback function.
+ * @param user_data The user data to pass to the callback function.
+ * @param format    The format string.
+ * @return          The HTTP connection struct.
+ */
+PurpleHttpConnection * purple_http_get_printf(PurpleConnection *gc,
+	PurpleHttpCallback callback, gpointer user_data,
+	const gchar *format, ...) G_GNUC_PRINTF(4, 5);
 
 /**
  * Fetches a HTTP request and passes the response to a callback function.
diff --git a/libpurple/protocols/msn/msn.c b/libpurple/protocols/msn/msn.c
--- a/libpurple/protocols/msn/msn.c
+++ b/libpurple/protocols/msn/msn.c
@@ -2800,18 +2800,14 @@ msn_get_info(PurpleConnection *gc, const
 	PurpleHttpConnection *hc;
 	MsnSession *session = purple_connection_get_protocol_data(gc);
 	MsnGetInfoData *data;
-	char *url;
 
 	data       = g_new0(MsnGetInfoData, 1);
 	data->gc   = gc;
 	data->name = g_strdup(name);
 
-	url = g_strdup_printf("%s%s", PROFILE_URL, name);
-
-	hc = purple_http_get(gc, url, msn_got_info, data);
+	hc = purple_http_get_printf(gc, msn_got_info, data,
+		"%s%s", PROFILE_URL, name);
 	session->http_reqs = g_slist_prepend(session->http_reqs, hc);
-
-	g_free(url);
 }
 
 static gboolean msn_load(PurplePlugin *plugin)
diff --git a/libpurple/protocols/mxit/formcmds.c b/libpurple/protocols/mxit/formcmds.c
--- a/libpurple/protocols/mxit/formcmds.c
+++ b/libpurple/protocols/mxit/formcmds.c
@@ -359,7 +359,7 @@ static void command_image(struct RXMsgDa
 				/* send the request for the inline image */
 				purple_debug_info(MXIT_PLUGIN_ID, "sending request for inline image '%s'\n", iireq->url);
 
-				purple_http_get(mx->session->con, iireq->url, mxit_cb_ii_returned, iireq);
+				purple_http_get(mx->session->con, mxit_cb_ii_returned, iireq, iireq->url);
 				mx->img_count++;
 			}
 		}
diff --git a/libpurple/protocols/mxit/markup.c b/libpurple/protocols/mxit/markup.c
--- a/libpurple/protocols/mxit/markup.c
+++ b/libpurple/protocols/mxit/markup.c
@@ -627,16 +627,15 @@ static void emoticon_request( struct RXM
 {
 	PurpleHttpConnection *hc;
 	const char*				wapserver;
-	char*					url;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "sending request for emoticon '%s'\n", id );
 
 	wapserver = purple_account_get_string( mx->session->acc, MXIT_CONFIG_WAPSERVER, DEFAULT_WAPSITE );
 
-	url = g_strdup_printf( "%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver, MXIT_EMOTICON_SIZE, id, time( NULL ) );
-	hc = purple_http_get(mx->session->con, url, emoticon_returned, mx);
+	hc = purple_http_get_printf(mx->session->con, emoticon_returned, mx,
+		"%s/res/?type=emo&mlh=%i&sc=%s&ts=%li", wapserver,
+		MXIT_EMOTICON_SIZE, id, time( NULL ) );
 	mx->session->async_http_reqs = g_slist_prepend(mx->session->async_http_reqs, hc);
-	g_free( url );
 }
 
 
diff --git a/libpurple/protocols/myspace/user.c b/libpurple/protocols/myspace/user.c
--- a/libpurple/protocols/myspace/user.c
+++ b/libpurple/protocols/myspace/user.c
@@ -383,7 +383,7 @@ msim_store_user_info_each(const gchar *k
 		/* Only download if URL changed */
 		if (!previous_url || !g_str_equal(previous_url, user->image_url)) {
 			purple_http_conn_cancel(user->http_conn);
-			user->http_conn = purple_http_get(NULL, user->image_url, msim_downloaded_buddy_icon, user);
+			user->http_conn = purple_http_get(NULL, msim_downloaded_buddy_icon, user, user->image_url);
 		}
 	} else if (g_str_equal(key_str, "LastImageUpdated")) {
 		/* TODO: use somewhere */
diff --git a/libpurple/protocols/yahoo/yahoo_picture.c b/libpurple/protocols/yahoo/yahoo_picture.c
--- a/libpurple/protocols/yahoo/yahoo_picture.c
+++ b/libpurple/protocols/yahoo/yahoo_picture.c
@@ -134,7 +134,7 @@ void yahoo_process_picture(PurpleConnect
 		data->gc = gc;
 		data->who = g_strdup(who);
 		data->checksum = checksum;
-		hc = purple_http_get(gc, url, yahoo_fetch_picture_cb, data);
+		hc = purple_http_get(gc, yahoo_fetch_picture_cb, data, url);
 		yd = purple_connection_get_protocol_data(gc);
 		yd->http_reqs = g_slist_prepend(yd->http_reqs, hc);
 	} else if (who && send_icon_info) {
diff --git a/libpurple/protocols/yahoo/yahoo_profile.c b/libpurple/protocols/yahoo/yahoo_profile.c
--- a/libpurple/protocols/yahoo/yahoo_profile.c
+++ b/libpurple/protocols/yahoo/yahoo_profile.c
@@ -937,7 +937,7 @@ yahoo_got_info(PurpleHttpConnection *htt
 	/* Try to put the photo in there too, if there's one */
 	if (photo_url_text) {
 		PurpleHttpConnection *hc;
-		hc = purple_http_get(info_data->gc, photo_url_text, yahoo_got_photo, info2_data);
+		hc = purple_http_get(info_data->gc, yahoo_got_photo, info2_data, photo_url_text);
 		yd->http_reqs = g_slist_prepend(yd->http_reqs, hc);
 	} else {
 		/* Emulate a callback */
@@ -1260,18 +1260,14 @@ void yahoo_get_info(PurpleConnection *gc
 {
 	YahooData *yd = purple_connection_get_protocol_data(gc);
 	YahooGetInfoData *data;
-	char *url;
 	PurpleHttpConnection *hc;
 
 	data       = g_new0(YahooGetInfoData, 1);
 	data->gc   = gc;
 	data->name = g_strdup(name);
 
-	url = g_strdup_printf("%s%s",
-			(yd->jp ? YAHOOJP_PROFILE_URL : YAHOO_PROFILE_URL), name);
-
-	hc = purple_http_get(gc, url, yahoo_got_info, data);
+	hc = purple_http_get_printf(gc, yahoo_got_info, data,
+		"%s%s", (yd->jp ? YAHOOJP_PROFILE_URL : YAHOO_PROFILE_URL),
+		name);
 	yd->http_reqs = g_slist_prepend(yd->http_reqs, hc);
-
-	g_free(url);
 }
diff --git a/pidgin/gtksmiley.c b/pidgin/gtksmiley.c
--- a/pidgin/gtksmiley.c
+++ b/pidgin/gtksmiley.c
@@ -786,7 +786,7 @@ smiley_dnd_recv(GtkWidget *widget, GdkDr
 			purple_http_conn_cancel(smiley_manager->
 				running_request);
 			smiley_manager->running_request = purple_http_get(NULL,
-				name, smiley_got_url, dialog);
+				smiley_got_url, dialog, name);
 		}
 
 		gtk_drag_finish(dc, TRUE, FALSE, t);
diff --git a/pidgin/plugins/relnot.c b/pidgin/plugins/relnot.c
--- a/pidgin/plugins/relnot.c
+++ b/pidgin/plugins/relnot.c
@@ -123,7 +123,7 @@ do_check(void)
 #endif
 		);
 
-		purple_http_get(NULL, url, version_fetch_cb, NULL);
+		purple_http_get(NULL, version_fetch_cb, NULL, url);
 
 		g_free(url);
 



More information about the Commits mailing list