diff options
Diffstat (limited to 'src/http.c')
-rw-r--r-- | src/http.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -6,6 +6,7 @@ #include <curl/curl.h> #include "string-util.h" #include "auth.h" +#include "config.h" #include "log.h" #define BUFFER_SIZE (256 * 1024) @@ -13,7 +14,11 @@ int http_init() { - return curl_global_init(CURL_GLOBAL_ALL); + if (curl_global_init(CURL_GLOBAL_ALL)) { + log_msg(LOG_WARNING, "http_init", "failed to init curl"); + return -1; + } + return 0; } void http_cleanup() @@ -44,7 +49,6 @@ static size_t write_response(void *ptr, size_t size, size_t nmemb, void *stream) char *get_request(const char *url) { - CURL *curl = NULL; CURLcode status; struct curl_slist *headers = NULL; @@ -61,6 +65,8 @@ char *get_request(const char *url) struct write_result write_result = {.data = data, .pos = 0}; + log_msg(LOG_INFO, "get_request", "loggedid: %d, token: %s", is_logged_in(), get_access_token()); + if (is_logged_in()) { const char *token = get_access_token(); size_t s = strlen(AUTH_HEADER_STR_PREFIX) + strlen(token) + 1; @@ -76,7 +82,7 @@ char *get_request(const char *url) curl_easy_setopt(curl, CURLOPT_WRITEDATA, &write_result); status = curl_easy_perform(curl); - if (status != 0) { + if (status) { log_msg(LOG_WARNING, "get_request", "unable to request data from %s: %s", url, curl_easy_strerror(status)); @@ -145,7 +151,7 @@ char *post_request(const char *url, char *post_data) curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_data); status = curl_easy_perform(curl); - if (status != 0) { + if (status) { log_msg(LOG_WARNING, "post_request", "unable to request data from %s: %s", url, curl_easy_strerror(status)); goto error; |