(no commit message)
[prss.git] / src / http.c
index e663b86..99afa01 100644 (file)
@@ -28,6 +28,8 @@
 
 #include "http.h"
 
+static int debug = 0;
+
 struct ucontent {
        char *data;
        size_t len;
@@ -54,7 +56,8 @@ static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp)
 
 void http_init()
 {
-       curl = curl_easy_init();
+       if (!curl)
+               curl = curl_easy_init();
 }
 
 void http_cleanup()
@@ -74,7 +77,7 @@ char *http_get(const char *url, const char *content)
        if (content) {
                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, content);
                curl_easy_setopt(curl,
-                                CURLOPT_POSTFIELDSIZE, 
+                                CURLOPT_POSTFIELDSIZE,
                                 (long)strlen(content));
        }
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl);
@@ -97,9 +100,15 @@ json_object *http_json_get(const char *url, struct json_object *j)
 
        in = json_object_to_json_string(j);
        out = http_get(url, in);
-       
+
+       if (debug)
+               printf("HTTP request= %s\n",
+                      json_object_to_json_string(j));
+
        if (out) {
                result = json_tokener_parse(out);
+               if (debug)
+                       printf("HTTP reply= %s\n", out);
                free(out);
                return result;
        }