(no commit message)
[prss.git] / src / http.c
index 55eab0f..52238ec 100644 (file)
@@ -27,8 +27,7 @@
 #include <curl/curl.h>
 
 #include "http.h"
-
-static int debug = 1;
+#include "log.h"
 
 struct ucontent {
        char *data;
@@ -77,7 +76,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);
@@ -87,7 +86,7 @@ char *http_get(const char *url, const char *content)
                return chunk.data;
 
        free(chunk.data);
-       fprintf(stderr, _("HTTP request fail url=%s"), url);
+       log_err(_("HTTP request fail url=%s"), url);
 
        return NULL;
 }
@@ -98,20 +97,22 @@ json_object *http_json_get(const char *url, struct json_object *j)
        char *out;
        struct json_object *result;
 
+       if (log_level >= LOG_DEBUG)
+               log_debug("HTTP request= %s",
+                      json_object_to_json_string(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);
+
+               if (log_level >= LOG_DEBUG)
+                       log_debug("HTTP reply= %s", out);
+
                free(out);
                return result;
-       } 
+       }
 
        return NULL;
 }