21 |
const char *feed_error = 0; |
const char *feed_error = 0; |
22 |
static const char *feed_status_name[] = { "NEW", "FETCHING", "OK", "ERROR" }; |
static const char *feed_status_name[] = { "NEW", "FETCHING", "OK", "ERROR" }; |
23 |
static CURLM *curl_multi_handle; |
static CURLM *curl_multi_handle; |
24 |
|
static unsigned int fetching = 0; |
25 |
|
#define MAX_FETCHES 3 |
26 |
|
|
27 |
|
|
28 |
static void feed_set_status(struct feed *feed, feed_status status); |
static void feed_set_status(struct feed *feed, feed_status status); |
238 |
} |
} |
239 |
} |
} |
240 |
|
|
241 |
if (running || queue) |
for (i = 0; i != feed_count; i++) |
242 |
feed_work_needed = true; |
if (feeds[i].status == FEED_NEW || |
243 |
|
feeds[i].status == FEED_FETCHING || |
244 |
|
feeds[i].status == FEED_UPDATE) |
245 |
|
feed_work_needed = true; |
246 |
|
|
247 |
for (i = 0; i != feed_count; i++) |
for (i = 0; i != feed_count; i++) |
248 |
if (feeds[i].updated) |
if (feeds[i].updated) |
259 |
{ |
{ |
260 |
assert(feed); |
assert(feed); |
261 |
|
|
262 |
if (feed->status == FEED_NEW || feed->status == FEED_UPDATE) { |
if ((feed->status == FEED_NEW || feed->status == FEED_UPDATE) && |
263 |
|
fetching < MAX_FETCHES) { |
264 |
feed_create_fetch(feed); |
feed_create_fetch(feed); |
265 |
if (feed->status != FEED_ERROR) |
if (feed->status != FEED_ERROR) |
266 |
feed_start_fetch(feed); |
feed_start_fetch(feed); |
288 |
headers2 = curl_slist_append(headers, "Accept: " |
headers2 = curl_slist_append(headers, "Accept: " |
289 |
"application/rss+xml, application/xml, text/xml"); |
"application/rss+xml, application/xml, text/xml"); |
290 |
if (!headers2) { |
if (!headers2) { |
291 |
|
curl_easy_cleanup(feed); |
292 |
curl_slist_free_all(headers); |
curl_slist_free_all(headers); |
293 |
feed_set_status(feed, FEED_ERROR); |
feed_set_status(feed, FEED_ERROR); |
294 |
feed->error = "Out of memory"; |
feed->error = "Out of memory"; |
302 |
snprintf(if_none_match, n, "If-None-Match: %s", feed->etag); |
snprintf(if_none_match, n, "If-None-Match: %s", feed->etag); |
303 |
headers2 = curl_slist_append(headers, if_none_match); |
headers2 = curl_slist_append(headers, if_none_match); |
304 |
if (!headers2) { |
if (!headers2) { |
305 |
|
curl_easy_cleanup(curl); |
306 |
curl_slist_free_all(headers); |
curl_slist_free_all(headers); |
307 |
feed_set_status(feed, FEED_ERROR); |
feed_set_status(feed, FEED_ERROR); |
308 |
feed->error = "Out of memory"; |
feed->error = "Out of memory"; |
360 |
|
|
361 |
printf("fetching feed %s\n", feed->url); |
printf("fetching feed %s\n", feed->url); |
362 |
|
|
363 |
|
fetching++; |
364 |
feed_work_needed = true; |
feed_work_needed = true; |
365 |
} |
} |
366 |
|
|
445 |
printf("finished %s with result %i %s\n", |
printf("finished %s with result %i %s\n", |
446 |
feed->url, result, curl_easy_strerror(result)); |
feed->url, result, curl_easy_strerror(result)); |
447 |
|
|
448 |
|
fetching--; |
449 |
|
|
450 |
if (result == CURLE_OK) { |
if (result == CURLE_OK) { |
451 |
curl_easy_getinfo(feed->curl, CURLINFO_RESPONSE_CODE, |
curl_easy_getinfo(feed->curl, CURLINFO_RESPONSE_CODE, |
452 |
&http_code); |
&http_code); |
525 |
} |
} |
526 |
//xmlDebugDumpDocument(stdout, doc); |
//xmlDebugDumpDocument(stdout, doc); |
527 |
|
|
528 |
|
free(feed->data); |
529 |
|
feed->data = 0; |
530 |
|
|
531 |
for (rss = doc->children; rss; rss = rss->next) |
for (rss = doc->children; rss; rss = rss->next) |
532 |
if (rss->type == XML_ELEMENT_NODE && !strcmp(rss->name, "rss")) |
if (rss->type == XML_ELEMENT_NODE && !strcmp(rss->name, "rss")) |
533 |
break; |
break; |