示例#1
0
文件: feed.c 项目: ctubio/claws
static void _free_items(gpointer item, gpointer nada)
{
	feed_item_free(item);
}
示例#2
0
void rssyl_update_comments(RFolderItem *ritem)
{
	FolderItem *item = &ritem->item;
	FeedItem *fi = NULL;
	RFetchCtx *ctx = NULL;
	GDir *dp;
	const gchar *d;
	GError *error = NULL;
	gint num;
	gchar *path, *msg, *fname;
	MainWindow *mainwin = mainwindow_get_mainwindow();

	g_return_if_fail(ritem != NULL);

	if( ritem->fetch_comments == FALSE )
		return;

	path = folder_item_get_path(item);
	g_return_if_fail(path != NULL);

	debug_print("RSSyl: starting to parse comments, path is '%s'\n", path);

	if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
		debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n",
				path, error->code, error->message);
		g_error_free(error);
		g_free(path);
		return;
	}

	ritem->fetching_comments = TRUE;

	while( (d = g_dir_read_name(dp)) != NULL ) {
		if (claws_is_exiting()) {
			g_dir_close(dp);
			g_free(path);
			debug_print("RSSyl: bailing out, app is exiting\n");
			return;
		}

		if( (num = to_number(d)) > 0) {
			fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d);
			if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR))
				continue;

			debug_print("RSSyl: starting to parse '%s'\n", d);

			if( (fi = rssyl_parse_folder_item_file(fname)) != NULL ) {
				if( feed_item_get_comments_url(fi) && feed_item_get_id(fi) &&
						(ritem->fetch_comments_max_age == -1 ||
						 time(NULL) - feed_item_get_date_modified(fi) <= ritem->fetch_comments_max_age*86400)) {
					msg = g_strdup_printf(_("Updating comments for '%s'..."),
							feed_item_get_title(fi));
					debug_print("RSSyl: updating comments for '%s' (%s)\n",
							feed_item_get_title(fi), feed_item_get_comments_url(fi));
					STATUSBAR_PUSH(mainwin, msg);

					ctx = rssyl_prep_fetchctx_from_url(feed_item_get_comments_url(fi));
					g_return_if_fail(ctx != NULL);
					feed_set_ssl_verify_peer(ctx->feed, ritem->ssl_verify_peer);

					rssyl_fetch_feed(ctx, FALSE);
					
					if( ctx->success && feed_n_items(ctx->feed) > 0 ) {
						g_free(ctx->feed->title);
						ctx->feed->title = g_strdup(ritem->official_title);

						feed_foreach_item(ctx->feed, rssyl_update_reference_func,
								feed_item_get_id(fi));

						if( !rssyl_parse_feed(ritem, ctx->feed) ) {
							debug_print("RSSyl: Error processing comments feed\n");
							log_error(LOG_PROTOCOL, RSSYL_LOG_ERROR_PROC, ctx->feed->url);
						}
					}
				}

				STATUSBAR_POP(mainwin);

				feed_item_free(fi);
			}

			g_free(fname);
		}
	}

	g_dir_close(dp);
	g_free(path);

	ritem->fetching_comments = FALSE;

	debug_print("RSSyl: rssyl_update_comments() is done\n");
}
示例#3
0
void feed_parser_atom10_start(void *data, const gchar *el, const gchar **attr)
{
	FeedParserCtx *ctx = (FeedParserCtx *)data;
	gchar *a = NULL;

	if( ctx->depth == 1 ) {

		if( !strcmp(el, "entry") ) {
			/* Start of new feed item found.
			 * Create a new FeedItem, freeing the one we already have, if any. */
			if( ctx->curitem != NULL )
				feed_item_free(ctx->curitem);
			ctx->curitem = feed_item_new(ctx->feed);
			ctx->location = FEED_LOC_ATOM10_ENTRY;
		} else if( !strcmp(el, "author") ) {
			/* Start of author info for the feed found.
			 * Set correct location. */
			ctx->location = FEED_LOC_ATOM10_AUTHOR;
		} else if( !strcmp(el, "link") ) {
			if (!feed_parser_get_attribute_value(attr, "rel")) {
				/* Link tag for the feed */
				g_free(ctx->feed->link);
				ctx->feed->link =
					g_strdup(feed_parser_get_attribute_value(attr, "href"));
			}
		} else ctx->location = FEED_LOC_ATOM10_NONE;

	} else if( ctx->depth == 2 ) {

		/* Make sure we are in one of known locations within the XML structure.
		 * This condition should never be true on a valid Atom feed. */
		if (ctx->location != FEED_LOC_ATOM10_AUTHOR &&
				ctx->location != FEED_LOC_ATOM10_ENTRY) {
			ctx->depth++;
			return;
		}

		if( !strcmp(el, "author") ) {
			/* Start of author info for current feed item.
			 * Set correct location. */
			ctx->location = FEED_LOC_ATOM10_AUTHOR;
		} else if( !strcmp(el, "link") ) {
			/* Capture item URL, from the "url" XML attribute. */
			if (ctx->curitem && ctx->location == FEED_LOC_ATOM10_ENTRY)
				ctx->curitem->url = g_strdup(feed_parser_get_attribute_value(attr, "href"));
		} else if( !strcmp(el, "source") ) {
			ctx->location = FEED_LOC_ATOM10_SOURCE;
		} else ctx->location = FEED_LOC_ATOM10_ENTRY;

		if( !strcmp(el, "title") && ctx->curitem != NULL) {
			a = feed_parser_get_attribute_value(attr, "type");
			if( !a || !strcmp(a, "text") )
				ctx->curitem->title_format = FEED_ITEM_TITLE_TEXT;
			else if( !strcmp(a, "html") )
				ctx->curitem->title_format = FEED_ITEM_TITLE_HTML;
			else if( !strcmp(a, "xhtml") )
				ctx->curitem->title_format = FEED_ITEM_TITLE_XHTML;
			else
				ctx->curitem->title_format = FEED_ITEM_TITLE_UNKNOWN;
		} else if (!strcmp(el, "content") && ctx->curitem != NULL) {
			ctx->location = FEED_LOC_ATOM10_CONTENT;
			a = feed_parser_get_attribute_value(attr, "type");
			if (a && !strcmp(a, "xhtml")) {
				ctx->curitem->xhtml_content = TRUE;
				ctx->xhtml_str = g_string_new(NULL);
			}
		}
	} else if (ctx->depth >= 3) {
		if (ctx->location == FEED_LOC_ATOM10_CONTENT
				&& ctx->curitem != NULL
				&& ctx->curitem->xhtml_content) {
			guint i;
			GString *txt = ctx->xhtml_str;
			g_string_append_c(txt, '<');
			g_string_append(txt, el);

			for (i = 0; attr[i] != NULL && attr[i+1] != NULL; i += 2) {
				g_string_append_printf(txt, " %s='%s'", attr[i], attr[i+1]);
			}
			g_string_append_c(txt, '>');
		}
	}


	ctx->depth++;
}