#include <curl/curl.h>
#include "http.h"
+#include "log.h"
struct ucontent {
char *data;
void http_init()
{
- curl = curl_easy_init();
+ if (!curl)
+ curl = curl_easy_init();
}
void http_cleanup()
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);
return chunk.data;
free(chunk.data);
- fprintf(stderr, _("HTTP request fail url=%s"), url);
+ log_err(_("HTTP request fail url=%s"), url);
return NULL;
}
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 (out) {
result = json_tokener_parse(out);
+
+ if (log_level >= LOG_DEBUG)
+ log_debug("HTTP reply= %s", out);
+
free(out);
return result;
}