/soc/2012/sanket/statscollector-2.x.y: 6928c68b3ce8: Check for r...
Sanket Agarwal
sanket at soc.pidgin.im
Tue Jul 10 00:36:27 EDT 2012
Changeset: 6928c68b3ce8ac70ddb17b6ff3d4a8f68286ca77
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2012-07-09 16:54 +0530
Branch: soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/6928c68b3ce8
Description:
Check for return headers before setting resend timer
If the request to send fails, due to reasons such as
DNS faliure or bad request we should not set the last-sent
counter.
TODO: It's probably a good idea to implement something like
an exponential backoff.
diffstat:
libpurple/plugins/statscollector.c | 56 ++++++++++++++++++++++++++++++-------
1 files changed, 45 insertions(+), 11 deletions(-)
diffs (115 lines):
diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -31,7 +31,7 @@
#define RESEND_SEC (24*3600)
/* Sending URL */
-#define SEND_URL "http://pidgin-stats.alwaysdata.net/collectstats/collect/"
+#define SEND_URL "http://localhost:8000/collectstats/collect/"
/* Version of XML this plugin supports writing */
@@ -618,7 +618,7 @@
int len;
PurplePlugin *prpl_plugin;
PurplePluginProtocolInfo *prpl_info;
- GList *user_splits, *l, *l2;
+ GList *user_splits, *l;
username = purple_account_get_username(account);
protocol = purple_account_get_protocol_id(account);
@@ -653,7 +653,6 @@
/* We can also send ``username-splits'' as they will be helpful
* in general
*/
- l2 = NULL;
username_dup = g_strdup(username);
if(user_splits != NULL){
@@ -790,11 +789,48 @@
}
+static int
+elem(gchar **s){
+
+ /* Returns the lenght of a NULL terminated string array */
+
+ int len;
+
+ len = 0;
+ while(s[len]) len++;
+ return len;
+
+}
+
static void
url_callback(PurpleUtilFetchUrlData *url_data, gpointer user_data, \
const gchar *url_text, gsize len, const gchar *error_message){
- purple_debug_info("STATS WWW", "%s", url_text);
+ /* Check if the header has HTTP/1.1 200 ... */
+
+ char **lines, **parts;
+ int code;
+ gboolean success;
+
+ success = FALSE;
+
+ lines = g_strsplit(url_text, "\n", 3);
+ if(elem(lines) >= 1){
+ purple_debug_info("STATS", "%s", lines[0]);
+ parts = g_strsplit(lines[0]," ",3);
+ if(elem(parts) >= 2){
+ purple_debug_info("STATS", "%s", parts[1]);
+ code = atoi(parts[1]);
+ if(code==200) success = TRUE;
+ }
+ }
+
+ if(success){
+ purple_prefs_set_int("/plugins/core/statscollector/last-sent",\
+ get_time_sec());
+ }
+
+ schedule_send();
}
@@ -808,6 +844,7 @@
gchar *host, *path, *request, *filename, *url= SEND_URL;
gchar *pd_xml, *postdata;
const char *pd_id;
+ gboolean *send_success;
GError *error;
int port;
gsize length;
@@ -823,6 +860,8 @@
purple_url_parse(url, &host, &port, &path, NULL, NULL);
+ send_success = g_new0(gboolean, 1);
+
request = g_strdup_printf(\
"POST /%s HTTP/1.0\r\n"
"Connection: keep-alive\r\n"
@@ -832,16 +871,11 @@
path, host, port, strlen(postdata), postdata);
#if PURPLE_VERSION_CHECK(3,0,0)
- urldata = purple_util_fetch_url_request(NULL, url, TRUE, NULL, FALSE, request, FALSE, -1, url_callback, (gpointer)postdata);
+ urldata = purple_util_fetch_url_request(NULL, url, TRUE, NULL, FALSE, request, FALSE, -1, url_callback, send_success);
#else
- urldata = purple_util_fetch_url_request(url, TRUE, NULL, FALSE, request, FALSE, url_callback, (gpointer)postdata);
+ urldata = purple_util_fetch_url_request(url, TRUE, NULL, FALSE, request, TRUE, url_callback, send_success);
#endif
-
- purple_prefs_set_int("/plugins/core/statscollector/last-sent",\
- get_time_sec());
- schedule_send();
-
g_free(host);
g_free(path);
g_free(request);
More information about the Commits
mailing list