1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-17 18:45:10 +00:00

Improve curl code.

This commit is contained in:
Brenden Matthews 2010-10-05 11:53:55 -07:00
parent c9cf08d9e9
commit 5b0dee741c

View File

@ -113,16 +113,30 @@ void ccurl_fetch_data(thread_handle &handle, const ccurl_location_ptr &curloc)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ccurl_write_memory_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &chunk);
curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "conky-curl/1.0");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res == CURLE_OK && chunk.size) { if (res == CURLE_OK && chunk.size) {
long http_status_code; long http_status_code;
if(curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_status_code) == CURLE_OK && http_status_code == 200) { if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE,
std::lock_guard<std::mutex> lock(handle.mutex()); &http_status_code) == CURLE_OK) {
curloc->process_function(curloc->result, chunk.memory); switch (http_status_code) {
case 200:
{
std::lock_guard<std::mutex> lock(handle.mutex());
curloc->process_function(curloc->result, chunk.memory);
}
break;
case 304:
break;
default:
NORM_ERR("curl: no data from server, got HTTP status %d %s",
http_status_code);
break;
}
} else { } else {
NORM_ERR("curl: no data from server"); NORM_ERR("curl: no HTTP status from server");
} }
free(chunk.memory); free(chunk.memory);
} else { } else {