/cpw/tomkiewicz/http: b69cd2bfe289: Migrate relnot plugin to new...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Oct 16 06:40:14 EDT 2012


Changeset: b69cd2bfe289cfa2a53382e410464c4f339d628f
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2012-10-16 12:40 +0200
Branch:	 default
URL: http://hg.pidgin.im/cpw/tomkiewicz/http/rev/b69cd2bfe289

Description:

Migrate relnot plugin to new HTTP API

diffstat:

 pidgin/plugins/relnot.c |  49 +++++++++----------------------------------------
 1 files changed, 9 insertions(+), 40 deletions(-)

diffs (97 lines):

diff --git a/pidgin/plugins/relnot.c b/pidgin/plugins/relnot.c
--- a/pidgin/plugins/relnot.c
+++ b/pidgin/plugins/relnot.c
@@ -28,7 +28,7 @@
 #endif
 
 #include "internal.h"
-#include "obsolete.h"
+//#include "obsolete.h"
 
 #include <string.h>
 
@@ -37,6 +37,7 @@
 #include "debug.h"
 #include "gtkblist.h"
 #include "gtkutils.h"
+#include "http.h"
 #include "notify.h"
 #include "pidginstock.h"
 #include "prefs.h"
@@ -61,42 +62,20 @@ release_show()
 	purple_notify_uri(NULL, PURPLE_WEBSITE);
 }
 
-static void
-version_fetch_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data,
-		const gchar *response, size_t len, const gchar *error_message)
+static void version_fetch_cb(PurpleHttpConnection *hc,
+	PurpleHttpResponse *response, gpointer user_data)
 {
 	gchar *cur_ver;
-	const char *tmp, *changelog;
-	char response_code[4];
+	const char *changelog;
 	GtkWidget *release_dialog;
 
 	GString *message;
 	int i = 0;
 
-	if(error_message || !response || !len)
+	if(!purple_http_response_is_successfull(response))
 		return;
 
-	memset(response_code, '\0', sizeof(response_code));
-	/* Parse the status code - the response should be in the form of "HTTP/?.? 200 ..." */
-	if ((tmp = strstr(response, " ")) != NULL) {
-		tmp++;
-		/* Read the 3 digit status code */
-		if (len - (tmp - response) > 3) {
-			memcpy(response_code, tmp, 3);
-		}
-	}
-
-	if (strcmp(response_code, "200") != 0) {
-		purple_debug_error("relnot", "Didn't recieve a HTTP status code of 200.\n");
-		return;
-	}
-
-	/* Go to the start of the data */
-	if((changelog = strstr(response, "\r\n\r\n")) == NULL) {
-		purple_debug_error("relnot", "Unable to find start of HTTP response data.\n");
-		return;
-	}
-	changelog += 4;
+	changelog = purple_http_response_get_data(response);
 
 	while(changelog[i] && changelog[i] != '\n') i++;
 
@@ -132,7 +111,7 @@ do_check(void)
 {
 	int last_check = purple_prefs_get_int("/plugins/gtk/relnot/last_check");
 	if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) {
-		gchar *url, *request;
+		gchar *url;
 		const char *host = "pidgin.im";
 
 		url = g_strdup_printf("http://%s/version.php?version=%s&build=%s",
@@ -145,18 +124,8 @@ do_check(void)
 #endif
 		);
 
-		request = g_strdup_printf(
-				"GET %s HTTP/1.0\r\n"
-				"Connection: close\r\n"
-				"Accept: */*\r\n"
-				"Host: %s\r\n\r\n",
-				url,
-				host);
+		purple_http_get(NULL, url, version_fetch_cb, NULL);
 
-		purple_util_fetch_url_request(NULL, url, TRUE, NULL, FALSE,
-			request, TRUE, -1, version_fetch_cb, NULL);
-
-		g_free(request);
 		g_free(url);
 
 		purple_prefs_set_int("/plugins/gtk/relnot/last_check", time(NULL));



More information about the Commits mailing list