/[james]/sargasso2/feed.c
ViewVC logotype

Diff of /sargasso2/feed.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 77 by james, Tue Sep 26 21:31:28 2006 UTC revision 78 by james, Sat Sep 30 21:34:24 2006 UTC
# Line 21  bool feed_work_needed = false; Line 21  bool feed_work_needed = false;
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);
# Line 236  bool feed_work(void) Line 238  bool feed_work(void)
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)
# Line 254  void feed_work_feed(struct feed *feed) Line 259  void feed_work_feed(struct feed *feed)
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);
# Line 282  void feed_create_fetch(struct feed *feed Line 288  void feed_create_fetch(struct feed *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";
# Line 295  void feed_create_fetch(struct feed *feed Line 302  void feed_create_fetch(struct feed *feed
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";
# Line 352  void feed_start_fetch(struct feed *feed) Line 360  void feed_start_fetch(struct feed *feed)
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    
# Line 436  void feed_fetched(struct feed *feed, CUR Line 445  void feed_fetched(struct feed *feed, CUR
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);
# Line 514  void feed_parse(struct feed *feed) Line 525  void feed_parse(struct feed *feed)
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;

Legend:
Removed from v.77  
changed lines
  Added in v.78

  ViewVC Help
Powered by ViewVC 1.1.26