/soc/2013/ankitkv/gobjectification: af4e269e4aa9: Merged default...

Ankit Vani a at nevitus.org
Thu Jul 4 09:22:04 EDT 2013


Changeset: af4e269e4aa9e7eb97773c3f50d441aee4aff33c
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-07-04 18:51 +0530
Branch:	 soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/af4e269e4aa9

Description:

Merged default branch

diffstat:

 finch/plugins/gnttinyurl.c                     |    4 +-
 libpurple/http.c                               |   75 ++++++++++++-
 libpurple/http.h                               |   52 +++++++-
 libpurple/protocols/gg/avatar.c                |  115 +++++++++++----------
 libpurple/protocols/gg/oauth/oauth-parameter.c |    4 +-
 libpurple/protocols/gg/oauth/oauth-purple.c    |  129 +++++++++++------------
 libpurple/protocols/gg/pubdir-prpl.c           |  132 +++++++++++-------------
 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 +-
 pidgin/themes/Contents/Resources/main.css      |    7 +-
 16 files changed, 316 insertions(+), 239 deletions(-)

diffs (truncated from 1124 to 300 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
@@ -155,6 +155,9 @@ struct _PurpleHttpCookieJar
 
 static time_t purple_http_rfc1123_to_time(const gchar *str);
 
+static gboolean purple_http_request_is_method(PurpleHttpRequest *request,
+	const gchar *method);
+
 static PurpleHttpConnection * purple_http_connection_new(
 	PurpleHttpRequest *request, PurpleConnection *gc);
 static void purple_http_connection_terminate(PurpleHttpConnection *hc);
@@ -513,10 +516,13 @@ static void _purple_http_gen_headers(Pur
 	if (!purple_http_headers_get(hdrs, "accept"))
 		g_string_append(h, "Accept: */*\r\n");
 
-	if (req->contents_length > 0 && !purple_http_headers_get(hdrs,
-		"content-length"))
+	if (!purple_http_headers_get(hdrs, "content-length") && (
+		req->contents_length > 0 ||
+		purple_http_request_is_method(req, "post")))
+	{
 		g_string_append_printf(h, "Content-Length: %u\r\n",
 			req->contents_length);
+	}
 
 	if (proxy_http)
 		g_string_append(h, "Proxy-Connection: close\r\n");
@@ -1237,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;
@@ -1252,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)
@@ -1260,6 +1286,12 @@ PurpleHttpConnection * purple_http_reque
 
 	g_return_val_if_fail(request != NULL, NULL);
 
+	if (request->url == NULL) {
+		purple_debug_error("http", "Cannot perform new request - "
+			"URL is not set\n");
+		return NULL;
+	}
+
 	hc = purple_http_connection_new(request, gc);
 	hc->callback = callback;
 	hc->user_data = user_data;
@@ -1703,8 +1735,6 @@ PurpleHttpRequest * purple_http_request_
 {
 	PurpleHttpRequest *request;
 
-	g_return_val_if_fail(url != NULL, NULL);
-
 	request = g_new0(PurpleHttpRequest, 1);
 
 	request->ref_count = 1;
@@ -1759,6 +1789,23 @@ void purple_http_request_set_url(PurpleH
 	request->url = g_strdup(url);
 }
 
+void purple_http_request_set_url_printf(PurpleHttpRequest *request,
+	const gchar *format, ...)
+{
+	va_list args;
+	gchar *value;
+
+	g_return_if_fail(request != NULL);
+	g_return_if_fail(format != NULL);
+
+	va_start(args, format);
+	value = g_strdup_vprintf(format, args);
+	va_end(args);
+
+	purple_http_request_set_url(request, value);
+	g_free(value);
+}
+
 const gchar * purple_http_request_get_url(PurpleHttpRequest *request)
 {
 	g_return_val_if_fail(request != NULL, NULL);
@@ -1781,6 +1828,20 @@ const gchar * purple_http_request_get_me
 	return request->method;
 }
 
+static gboolean purple_http_request_is_method(PurpleHttpRequest *request,
+	const gchar *method)
+{
+	const gchar *rmethod;
+
+	g_return_val_if_fail(request != NULL, FALSE);
+	g_return_val_if_fail(method != NULL, FALSE);
+
+	rmethod = purple_http_request_get_method(request);
+	if (rmethod == NULL)
+		return (g_ascii_strcasecmp(method, "get") == 0);
+	return (g_ascii_strcasecmp(method, rmethod) == 0);
+}
+
 void purple_http_request_set_contents(PurpleHttpRequest *request,
 	const gchar *contents, int length)
 {
@@ -2014,7 +2075,7 @@ const gchar * purple_http_response_get_d
 {
 	const gchar *ret = "";
 
-	g_return_val_if_fail(response != NULL, NULL);
+	g_return_val_if_fail(response != NULL, "");
 
 	if (response->contents != NULL) {
 		ret = response->contents->str;
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.
@@ -403,7 +417,8 @@ gboolean purple_http_cookie_jar_is_empty
 /**
  * Creates the new instance of HTTP request configuration.
  *
- * @param url The URL to request for.
+ * @param url The URL to request for, or NULL to leave empty (to be set with
+ *            purple_http_request_set_url).
  * @return The new instance of HTTP request struct.
  */
 PurpleHttpRequest * purple_http_request_new(const gchar *url);
@@ -434,6 +449,15 @@ PurpleHttpRequest * purple_http_request_
 void purple_http_request_set_url(PurpleHttpRequest *request, const gchar *url);
 
 /**
+ * Constructs and sets an URL for HTTP request.
+ *
+ * @param request The request.
+ * @param format  The format string.
+ */
+void purple_http_request_set_url_printf(PurpleHttpRequest *request,
+	const gchar *format, ...) G_GNUC_PRINTF(2, 3);
+
+/**
  * Gets URL set for the HTTP request.
  *
  * @param request The request.
@@ -580,14 +604,22 @@ int purple_http_request_get_max_len(Purp
 /**
  * Sets (replaces, if exists) specified HTTP request header with provided value.
  *
- * @param key   A header to be set.
- * @param value A value to set, or NULL to remove specified header from request.
+ * @param request The request.
+ * @param key     A header to be set.
+ * @param value   A value to set, or NULL to remove specified header.
  *
  * @see purple_http_request_header_add
  */
 void purple_http_request_header_set(PurpleHttpRequest *request,
 	const gchar *key, const gchar *value);
 
+/**
+ * Constructs and sets (replaces, if exists) specified HTTP request header.
+ *
+ * @param request The request.
+ * @param key     A header to be set.
+ * @param format  The format string.
+ */
 void purple_http_request_header_set_printf(PurpleHttpRequest *request,
 	const gchar *key, const gchar *format, ...) G_GNUC_PRINTF(3, 4);
 
diff --git a/libpurple/protocols/gg/avatar.c b/libpurple/protocols/gg/avatar.c
--- a/libpurple/protocols/gg/avatar.c
+++ b/libpurple/protocols/gg/avatar.c
@@ -31,7 +31,7 @@
 
 #include <debug.h>
 #include <glibcompat.h>
-#include <obsolete.h>
+#include <http.h>
 
 #include "gg.h"
 #include "utils.h"
@@ -55,13 +55,12 @@ typedef struct
 	time_t timestamp;
 	
 	PurpleConnection *gc;
-	PurpleUtilFetchUrlData *request;
+	PurpleHttpConnection *request;
 } ggp_avatar_buddy_update_req;
 
 static gboolean ggp_avatar_buddy_update_next(PurpleConnection *gc);
-static void ggp_avatar_buddy_update_received(PurpleUtilFetchUrlData *url_data,
-	gpointer _pending_update, const gchar *url_text, gsize len,
-	const gchar *error_message);
+static void ggp_avatar_buddy_update_received(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer user_data);
 
 #define GGP_AVATAR_BUDDY_URL "http://avatars.gg.pl/%u/s,big"
 
@@ -74,9 +73,8 @@ typedef struct
 
 static void ggp_avatar_own_got_token(PurpleConnection *gc, const gchar *token,
 	gpointer img);
-static void ggp_avatar_own_sent(PurpleUtilFetchUrlData *url_data,
-	gpointer user_data, const gchar *url_text, gsize len,
-	const gchar *error_message);
+static void ggp_avatar_own_sent(PurpleHttpConnection *http_conn,
+	PurpleHttpResponse *response, gpointer user_data);
 
 #define GGP_AVATAR_RESPONSE_MAX 10240
 
@@ -106,7 +104,7 @@ void ggp_avatar_cleanup(PurpleConnection
 		ggp_avatar_buddy_update_req *current_update =
 			avdata->current_update;
 		
-		purple_util_fetch_url_cancel(current_update->request);



More information about the Commits mailing list