summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-02-14 19:34:56 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-02-14 19:34:56 +0000
commit3f7785e670e09cfd75a77ccca8031fabc0d432ab (patch)
tree41ff9eadd2b1eb537568f87a0bfcc3941a4df36a /src/util.c
parent009ef4d4a37ca136c6bd1071fc980c4f164badd9 (diff)
statistics!
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index e0b07c8..bd6bb9e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -24,11 +24,39 @@
#include <string.h>
#include <glib-object.h>
+#include <curl/curl.h>
+#include <json-glib/json-glib.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>
#include "util.h"
+#include "dispatch.h"
+
+const gchar *make_error_message(JsonObject * response, int status)
+{
+ if (status == FAIL_JSON_DECODE) {
+ return g_strdup("JSON decoding error.");
+ } else if (status == FAIL_RESPONSE_UNSUCCESSFUL) {
+ const gchar *resultStr =
+ json_object_get_string_member(response, "result");
+ if (resultStr == NULL)
+ return g_strdup("Server responded, but with no result.");
+ else
+ return g_strdup(resultStr);
+ } else if (status <= -100) {
+ return g_strdup_printf("Request failed with HTTP code %d",
+ -(status + 100));
+ } else {
+ return g_strdup(curl_easy_strerror(status));
+ }
+}
+
+void response_unref(JsonObject * response)
+{
+ if (response != NULL)
+ json_object_unref(response);
+}
char *tr_strlpercent(char *buf, double x, size_t buflen)
{