diff --git a/src/module/module_repo.c b/src/module/module_repo.c index 4d2cbc290b3fe6e33c66dbc0f29657bfc0728628..fffc8ff6ba8f76607876c20354b76f23beb7021c 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -136,13 +136,19 @@ __json_sync(struct module_repo_internal *repo, struct json_object **json) RETURN_UNLESS(json, "Invalid argument", 1); CURL *curl_handle; CURLcode res; + struct curl_slist *headers = NULL; int ret = 1; struct __memory file = { .mem = NULL, .size = 0. }; + /* Only accept json file */ + headers = curl_slist_append(headers, "Accept: application/json"); + headers = curl_slist_append(headers, "Content-Type: application/json"); + curl_handle = curl_easy_init(); + curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle, CURLOPT_URL, repo->get_all_json); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, __write_mem); curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &file); @@ -155,11 +161,18 @@ __json_sync(struct module_repo_internal *repo, struct json_object **json) goto err; } + /* Check if recieved json is not empty */ + if (file.size == 0) { + LOG_ERROR("CURL", "Gottent file is empty"); + goto err; + } + *json = json_tokener_parse(file.mem); ret = 0; err: __clean_memory(&file); curl_easy_cleanup(curl_handle); + curl_slist_free_all(headers); return ret; }