Esempio n. 1
0
/**
 * Add "broadcast-friends" to the list of subscriptions if required 
 */
static void
google_source_add_broadcast_subscription (GoogleSourcePtr gsource)
{
	const gchar* title = "Friend's Shared Items"; 
	GSList * iter = NULL; 
	nodePtr node; 

	iter = gsource->root->children; 
	while (iter) { 
		node = (nodePtr) iter->data ; 
		if (!node->subscription || !node->subscription->source) 
			continue;
		if (g_str_equal (node->subscription->source, GOOGLE_READER_BROADCAST_FRIENDS_URL)) {
			return;
		}
		iter = g_slist_next (iter);
	}

	/* aha! add it! */

	node = node_new (feed_get_node_type ());
	node_set_title (node, title);
	node_set_data (node, feed_new ());

	node_set_subscription (node, subscription_new (GOOGLE_READER_BROADCAST_FRIENDS_URL, NULL, NULL));
	node->subscription->type = &googleSourceFeedSubscriptionType;
	node_set_parent (node, gsource->root, -1);
	feedlist_node_imported (node);
	
	subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
	subscription_update_favicon (node->subscription);
}
static void
theoldreader_source_merge_feed (TheOldReaderSourcePtr source, const gchar *url, const gchar *title, const gchar *id, nodePtr folder)
{
	nodePtr	node;

	node = feedlist_find_node (source->root, NODE_BY_URL, url);
	if (!node) {
		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = source->root->source->type->feedSubscriptionType;
	
		/* Save TheOldReader feed id which we need to fetch items... */
		node->subscription->metadata = metadata_list_append (node->subscription->metadata, "theoldreader-feed-id", id);

		db_subscription_update (node->subscription);
	
		node_set_parent (node, folder?folder:source->root, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);

	} else {
		node_source_update_folder (node, folder);
	}
}
Esempio n. 3
0
PRIVATE int parseFeed(rss_feeds *feeds, const char* feedstr) {
  rss_feed* feed = NULL;
  int32_t result = SUCCESS; /* be optimistic */
  simple_list option_list = NULL;
  NODE * current = NULL;
  suboption_t *opt_item = NULL;

  option_list = parseMultiOption(feedstr);
  current = option_list;

  while (current != NULL) {
    opt_item = (suboption_t*)current->data;

    if(opt_item != NULL) {
      if(!feed) {
        feed = feed_new();
        assert(feed && "feed_new() failed!");
      }

      if(!strncmp(opt_item->option, "url_pattern", 11)) {
        feed->url_pattern = trim(opt_item->value);
      } else if(!strncmp(opt_item->option, "url_replace", 11)) {
        feed->url_replace = trim(opt_item->value);
      } else if(!strncmp(opt_item->option, "url", 3)) {
        feed->url = trim(opt_item->value);
      } else if(!strncmp(opt_item->option, "cookies", 6)) {
        feed->cookies = trim(opt_item->value);
      } else if(!strncmp(opt_item->option, "id", 2)) {
        feed->id = trim(opt_item->value);
      } else {
        dbg_printf(P_ERROR, "Unknown suboption '%s'!", opt_item->option);
      }
    } else {
      assert(0 && "opt_item == NULL");
    }

    current = current->next;
  }

  if(feed && feed->url) {
    /* Maybe the cookies are encoded within the URL */
    if(feed->cookies == NULL) {
      parseCookiesFromURL(feed);
    }

    feed_add(feed, feeds);
  } else {
    dbg_printf(P_ERROR, "Invalid feed: '%s'", feedstr);
    feed_free(feed);
    result = FAILURE;
  }

  if(option_list != NULL) {
    freeList(&option_list, freeOptionItem);
  }

  return result;
}
Esempio n. 4
0
static nodePtr
default_source_add_subscription (nodePtr node, subscriptionPtr subscription)
{
	/* For the local feed list source subscriptions are always
	   feed subscriptions implemented by the feed node and 
	   subscription type... */
	nodePtr child = node_new (feed_get_node_type ());
	node_set_title (child, _("New Subscription"));
	node_set_data (child, feed_new ());
	node_set_subscription (child, subscription);	/* feed subscription type is implicit */
	feedlist_node_added (child);
	
	subscription_update (subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
	return child;
}
Esempio n. 5
0
PRIVATE int parseFeed(rss_feeds *feeds, const char* feedstr) {
  char *line = NULL, *option = NULL, *param = NULL;
  char *saveptr;
  char *str = NULL;
  rss_feed* feed = NULL;
  int result = SUCCESS; /* be optimistic */

  str = shorten(feedstr);

  line = strtok_r(str, AM_DELIMITER, &saveptr);
  while (line) {
    if(!feed) {
      feed = feed_new();
      assert(feed && "feed_new() failed!");
    }
    if(parseSubOption(line, &option, &param) == 0) {
      if(!strncmp(option, "url", 3)) {
        feed->url = shorten(param);
      } else if(!strncmp(option, "cookies", 6)) {
        feed->cookies = shorten(param);
      } else {
        dbg_printf(P_ERROR, "Unknown suboption '%s'!", option);
      }
      am_free(option);
      am_free(param);
    } else {
      dbg_printf(P_ERROR, "Invalid suboption string: '%s'!", line);
    }
    line = strtok_r(NULL, AM_DELIMITER, &saveptr);
  }


  if(feed && feed->url) {
    /* Maybe the cookies are encoded within the URL */
    if(feed->cookies == NULL) {
      parseCookiesFromURL(feed);
    }
    feed->id = listCount(*feeds);
    feed_add(feed, feeds);
  } else {
    dbg_printf(P_ERROR, "Invalid feed: '%s'", str);
    result = FAILURE;
  }

  am_free(str);
  return result;
}
Esempio n. 6
0
PRIVATE int getFeeds(NODE **head, const char* strlist) {
  char *p = NULL;
  char *str;
  str = shorten(strlist);
  assert(head != NULL);
  p = strtok(str, AM_DELIMITER);
  while (p) {
    rss_feed* feed = feed_new();
    assert(feed && "feed_new() failed!");
    feed->url = strdup(p);
    feed->id  = listCount(*head);
    /* Maybe the cookies are encoded within the URL */
    parseCookiesFromURL(feed);
    feed_add(feed, head);
    p = strtok(NULL, AM_DELIMITER);
  }
  am_free(str);
  return 0;
}
Esempio n. 7
0
static void
ttrss_source_merge_feed (ttrssSourcePtr source, const gchar *url, const gchar *title, gint64 id)
{
	nodePtr		node;
	gchar		*tmp;

	/* check if node to be merged already exists */
	node = feedlist_find_node (source->root, NODE_BY_URL, url);
	
	if (!node) {
		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = &ttrssSourceFeedSubscriptionType;
	
		/* Save tt-rss feed id which we need to fetch items... */
		tmp = g_strdup_printf ("%" G_GINT64_FORMAT, id);
		metadata_list_set (&node->subscription->metadata, "ttrss-feed-id", tmp);
		g_free (tmp);
	
		node_set_parent (node, source->root, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);
	
		/* Important: we must not loose the feed id! */
		db_subscription_update (node->subscription);
	}
	
	debug2 (DEBUG_UPDATE, "updating folder for %s (%s)", title, url);
	ttrss_source_update_folder (source, node);
}
static void
inoreader_source_merge_feed (InoreaderSourcePtr source, const gchar *url, const gchar *title, const gchar *id)
{
	nodePtr	node;
	GSList	*iter;

	/* check if node to be merged already exists */
	iter = source->root->children;
	while (iter) {
		node = (nodePtr)iter->data;
		if (g_str_equal (node->subscription->source, url))
			return;
		iter = g_slist_next (iter);
	}

	debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
	node = node_new (feed_get_node_type ());
	node_set_title (node, title);
	node_set_data (node, feed_new ());
		
	node_set_subscription (node, subscription_new (url, NULL, NULL));
	node->subscription->type = &inoreaderSourceFeedSubscriptionType;

	/* Save Inoreader feed id which we need to fetch items... */
	node->subscription->metadata = metadata_list_append (node->subscription->metadata, "inoreader-feed-id", id);
	db_subscription_update (node->subscription);

	node_set_parent (node, source->root, -1);
	feedlist_node_imported (node);
		
	/**
	 * @todo mark the ones as read immediately after this is done
	 * the feed as retrieved by this has the read and unread
	 * status inherently.
	 */
	subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
	subscription_update_favicon (node->subscription);
}
Esempio n. 9
0
static void
google_source_merge_feed (xmlNodePtr match, gpointer user_data)
{
	GoogleSourcePtr	gsource = (GoogleSourcePtr)user_data;
	nodePtr		node;
	GSList		*iter;
	xmlNodePtr	xml;
	xmlChar		*title = NULL, *id = NULL;
	gchar           *url = NULL;

	xml = xpath_find (match, "./string[@name='title']");
	if (xml)
		title = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		
	xml = xpath_find (match, "./string[@name='id']");
	if (xml) {
		id = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		url = g_strdup(id + strlen ("feed/"));
	}

	/* Note: ids look like "feed/http://rss.slashdot.org" */
	if (id && title) {	

		/* check if node to be merged already exists */
		iter = gsource->root->children;
		while (iter) {
			node = (nodePtr)iter->data;
			if (g_str_equal (node->subscription->source, url)) {
				node->subscription->type = &googleSourceFeedSubscriptionType;
				goto cleanup ;
			}
			iter = g_slist_next (iter);
		}
	
		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = &googleSourceFeedSubscriptionType;
		node_set_parent (node, gsource->root, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);
	} else 
		g_warning("Unable to parse subscription information from Google");

cleanup:
	if (id)
		xmlFree (id);
	if (title)
		xmlFree (title);
	g_free (url) ;
}
Esempio n. 10
0
static void
aol_source_merge_feed (xmlNodePtr match, gpointer user_data)
{
	AolSourcePtr	gsource = (AolSourcePtr)user_data;
	nodePtr		node, parent = NULL, subnode = NULL;
	GSList		*iter, *iter_sub;
	xmlNodePtr	xml;
	xmlChar		*title = NULL, *id = NULL, *label = NULL;
	gchar		*url = NULL;

	xml = xpath_find (match, "./string[@name='title']");
	if (xml)
		title = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		
	xml = xpath_find (match, "./string[@name='id']");
	if (xml) {
		id = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
		url = g_strdup (id + strlen ("feed/"));
	}

	/* Note: ids look like "feed/http://rss.slashdot.org" */
	if (id && title) {

		/* check if node to be merged already exists */
		iter = gsource->root->children;
		while (iter) {
			node = (nodePtr)iter->data;
			if (node->subscription != NULL
			    && g_str_equal (node->subscription->source, url)) {
				node->subscription->type = &aolSourceFeedSubscriptionType;
				aol_source_update_folder (match, gsource, node);
				goto cleanup;
			} else if (node->type->capabilities
				 & NODE_CAPABILITY_SUBFOLDERS) {
				iter_sub = node->children;
				while (iter_sub) {
					subnode = (nodePtr)iter_sub->data;
					if (subnode->subscription != NULL
					    && g_str_equal (subnode->subscription->source, url)) {
						subnode->subscription->type = &aolSourceFeedSubscriptionType;
						aol_source_update_folder (match, gsource, subnode);
						goto cleanup;
					}
					iter_sub = g_slist_next (iter_sub);
				}
			}
			iter = g_slist_next (iter);
		}

		/* if a new feed contains label, put its node under a folder with the same name */
		xml = xpath_find (match, "./list[@name='categories']/object/string[@name='label']");
		if (xml) {
			label = xmlNodeListGetString (xml->doc, xml->xmlChildrenNode, 1);
			parent = aol_source_find_or_create_folder ((gchar*)label, gsource->root);
			xmlFree (label);
		} else {
			parent = gsource->root;
		}
		
		g_assert (NULL != parent);

		debug2 (DEBUG_UPDATE, "adding %s (%s)", title, url);
		node = node_new (feed_get_node_type ());
		node_set_title (node, title);
		node_set_data (node, feed_new ());
		
		node_set_subscription (node, subscription_new (url, NULL, NULL));
		node->subscription->type = &aolSourceFeedSubscriptionType;
		node_set_parent (node, parent, -1);
		feedlist_node_imported (node);
		
		/**
		 * @todo mark the ones as read immediately after this is done
		 * the feed as retrieved by this has the read and unread
		 * status inherently.
		 */
		subscription_update (node->subscription, FEED_REQ_RESET_TITLE | FEED_REQ_PRIORITY_HIGH);
		subscription_update_favicon (node->subscription);
	} else {
		g_warning("Unable to parse subscription information from Google");
	}

cleanup:
	xmlFree (id);
	xmlFree (title);
	g_free (url) ;
}