Ejemplo n.º 1
0
rss_file *rss_open_file(const char *filename)
{
  xmlParserCtxtPtr ctxt;
  xmlDocPtr doc;
  rss_file *f;
  xmlNode *root_element = NULL;
  gchar *fetched_time;

  ctxt = xmlNewParserCtxt();
  ctxt->sax->getEntity = _get_entity;
  doc = xmlSAXParseFile(ctxt->sax, filename, 0);

  if (!doc) {
    fprintf(stderr, "Error parsing RSS file %s.\n", filename);
    xmlFreeParserCtxt(ctxt);

    return NULL;
  }

  root_element = xmlDocGetRootElement(doc);

  if (!root_element)  {
    xmlFreeDoc(doc);
    xmlFreeParserCtxt(ctxt);

    fprintf(stderr, "Error parsing RSS file %s.\n", filename);
    return NULL;
  }

  /* Establish the time the RSS file was 'fetched'. */
  fetched_time = get_rfc822_time();

  if (!fetched_time) {
    xmlFreeDoc(doc);
    xmlFreeParserCtxt(ctxt);

    g_fprintf(stderr, "Error retrieving current time.\n");
    return NULL;
  }

  f = rss_parse(filename, root_element, fetched_time);

  xmlFreeDoc(doc);
  xmlFreeParserCtxt(ctxt);
  g_free(fetched_time);

  return f;
}
Ejemplo n.º 2
0
static void _enclosure_iterator(const void *user_data, int i, const xmlNode *node)
{
  const char *downloadtime;

  channel *c = (channel *)user_data;

  downloadtime = libxmlutil_attr_as_string(node, "downloadtime");

  if (downloadtime)
    downloadtime = g_strdup(downloadtime);
  else
    downloadtime = get_rfc822_time();

  g_hash_table_insert(c->downloaded_enclosures,
                      (gpointer)libxmlutil_attr_as_string(node, "url"),
                      (gpointer)downloadtime);
}
Ejemplo n.º 3
0
int channel_update(channel *c, void *user_data, channel_callback cb,
                   int no_download, int no_mark_read, int first_only,
                   int resume, enclosure_filter *filter, int debug,
                   int show_progress_bar)
{
  int i, download_failed;
  rss_file *f;

  /* Retrieve the RSS file. */
  f = _get_rss(c, user_data, cb, debug);

  if (!f)
    return 1;

  /* Check enclosures in RSS file. */
  for (i = 0; i < f->num_items; i++)
    if (f->items[i]->enclosure) {
      if (!g_hash_table_lookup_extended(c->downloaded_enclosures, f->items[i]->enclosure->url, NULL, NULL)) {
        rss_item *item;

        item = f->items[i];

        if (!filter || _enclosure_pattern_match(filter, item->enclosure)) {
          if (no_download)
            download_failed = _do_catchup(c, &(f->channel_info), item, user_data, cb);
          else
            download_failed = _do_download(c, &(f->channel_info), item, user_data, cb, resume, debug, show_progress_bar);

          if (download_failed)
            break;

          if (!no_mark_read) {
            /* Mark enclosure as downloaded and immediately save channel
               file to ensure that it reflects the change. */
            g_hash_table_insert(c->downloaded_enclosures, f->items[i]->enclosure->url,
                                (gpointer)get_rfc822_time());

            _cast_channel_save(c, debug);
          }

          /* If we have been instructed to deal only with the first
             available enclosure, it is time to break out of the loop. */
          if (first_only)
            break;
        }
      }
    }

  if (!no_mark_read) {
    /* Update the RSS last fetched time and save the channel file again. */

    if (c->rss_last_fetched)
      g_free(c->rss_last_fetched);

    c->rss_last_fetched = g_strdup(f->fetched_time);

    _cast_channel_save(c, debug);
  }

  rss_close(f);

  return 0;
}