From: Jean-Philippe Orsini Date: Fri, 26 Apr 2013 06:44:23 +0000 (+0000) Subject: (no commit message) X-Git-Url: https://git.wpitchoune.net/gitweb/?p=prss.git;a=commitdiff_plain;h=e55e4740384c307e2634e886546983bac3a24543 --- diff --git a/src/http.c b/src/http.c index 52238ec..4438423 100644 --- a/src/http.c +++ b/src/http.c @@ -20,6 +20,7 @@ #include #define _(str) gettext(str) +#include #include #include #include @@ -35,6 +36,7 @@ struct ucontent { }; static CURL *curl; +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; static size_t cbk_curl(void *buffer, size_t size, size_t nmemb, void *userp) { @@ -67,10 +69,13 @@ void http_cleanup() char *http_get(const char *url, const char *content) { struct ucontent chunk; + int result; chunk.data = malloc(1); chunk.len = 0; + pthread_mutex_lock(&lock); + curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); if (content) { @@ -82,7 +87,11 @@ char *http_get(const char *url, const char *content) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cbk_curl); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); - if (curl_easy_perform(curl) == CURLE_OK) + result = curl_easy_perform(curl); + + pthread_mutex_unlock(&lock); + + if (result == CURLE_OK) return chunk.data; free(chunk.data);