Mercurial > pidgin
changeset 24050:13e520aeb956
Parse the HTTP status code in the release notification plugin and only display
the output when we receive a code of "200". This will prevent bogus messages
when a proxy blocks the retrieval or it fails for any other reason.
References #6930.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Wed, 03 Sep 2008 15:38:31 +0000 |
parents | 48153b64d7d3 |
children | 11d6c66ad001 |
files | pidgin/plugins/relnot.c |
diffstat | 1 files changed, 52 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin/plugins/relnot.c Tue Sep 02 09:41:15 2008 +0000 +++ b/pidgin/plugins/relnot.c Wed Sep 03 15:38:31 2008 +0000 @@ -33,6 +33,7 @@ #include "connection.h" #include "core.h" +#include "debug.h" #include "notify.h" #include "prefs.h" #include "util.h" @@ -45,14 +46,39 @@ static void version_fetch_cb(PurpleUtilFetchUrlData *url_data, gpointer user_data, - const gchar *changelog, size_t len, const gchar *error_message) + const gchar *response, size_t len, const gchar *error_message) { - char *cur_ver, *formatted; + gchar *cur_ver, *formatted; + const char *tmp, *changelog; + char response_code[4]; + GString *message; - int i=0; + int i = 0; + + if(error_message || !response || !len) + return; - if(error_message || !changelog || !len) + 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; while(changelog[i] && changelog[i] != '\n') i++; @@ -94,16 +120,35 @@ { int last_check = purple_prefs_get_int("/plugins/gtk/relnot/last_check"); if(!last_check || time(NULL) - last_check > MIN_CHECK_INTERVAL) { - char *url = g_strdup_printf("http://pidgin.im/version.php?version=%s&build=%s", purple_core_get_version(), + gchar *url, *request; + const char *host = "pidgin.im"; + + url = g_strdup_printf("http://%s/version.php?version=%s&build=%s", + host, + purple_core_get_version(), #ifdef _WIN32 "purple-win32" #else "purple" #endif ); - purple_util_fetch_url(url, TRUE, NULL, FALSE, version_fetch_cb, NULL); + + 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_util_fetch_url_request_len(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)); - g_free(url); + } }