Esempio n. 1
0
static void _opml_parser_start(void *data, const gchar *el, const gchar **attr)
{
	OPMLProcessCtx *ctx = (OPMLProcessCtx *)data;
	gchar *title = NULL, *type = NULL, *url = NULL, *tmp = NULL;

	if( ctx->body_reached ) {
		if( ctx->depth >= 2 && !strcmp(el, "outline") ) {
			title = feed_parser_get_attribute_value(attr, "title");
			type = feed_parser_get_attribute_value(attr, "type");
			if( type != NULL && strcmp(type, "folder") ) {
				url = feed_parser_get_attribute_value(attr, "xmlUrl");

				if( url != NULL ) {
					if( !strncmp(url, "feed://", 7) )
						tmp = g_strdup(url+7);
					else if( !strncmp(url, "feed:", 5) )
						tmp = g_strdup(url+5);
				
					if( tmp != NULL ) {
						g_free(url);
						url = tmp;
					}
				}
			}

			if( ctx->user_function != NULL ) {
				ctx->user_function(title, url, ctx->depth, ctx->user_data);
			}
		}
	}

	if( ctx->depth == 1 ) {
		if( !strcmp(el, "body") ) {
			ctx->body_reached = TRUE;
		}
	}

	ctx->depth++;
}
Esempio n. 2
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++;
}