2 * Copyright (C) 2006 Andrej Kacian <andrej@kacian.sk>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
27 #include "parser_rdf.h"
29 void feed_parser_rdf_start(void *data, const gchar *el, const gchar **attr)
31 FeedParserCtx *ctx = (FeedParserCtx *)data;
33 if( ctx->depth == 1 ) {
34 if( !strcmp(el, "channel") ) {
35 ctx->location = FEED_LOC_RDF_CHANNEL;
36 } else if( !strcmp(el, "item") ) {
38 if( ctx->curitem != NULL )
39 feed_item_free(ctx->curitem);
41 ctx->curitem = feed_item_new(ctx->feed);
42 ctx->location = FEED_LOC_RDF_ITEM;
44 } else ctx->location = 0;
51 void feed_parser_rdf_end(void *data, const gchar *el)
53 FeedParserCtx *ctx = (FeedParserCtx *)data;
54 Feed *feed = ctx->feed;
57 if( ctx->str != NULL )
64 switch( ctx->depth ) {
68 if( !strcmp(el, "rdf") ) {
69 /* we finished parsing the feed */
70 ctx->feed->items = g_slist_reverse(ctx->feed->items);
77 /* <item></item> block just ended, so ... */
78 if( !strcmp(el, "item") ) {
80 /* add the complete feed item to our feed struct */
82 g_slist_prepend(ctx->feed->items, (gpointer)ctx->curitem);
84 /* since it's in the linked list, lose this pointer */
92 switch(ctx->location) {
94 /* We're inside introductory <channel></channel> */
95 case FEED_LOC_RDF_CHANNEL:
96 if( !strcmp(el, "title") ) {
98 } else if( !strcmp(el, "description" ) ) {
99 FILL(feed->description)
100 } else if( !strcmp(el, "dc:language") ) {
102 } else if( !strcmp(el, "dc:creator") ) {
104 } else if( !strcmp(el, "dc:date") ) {
105 feed->date = parseISO8601Date(text);
106 } else if( !strcmp(el, "pubDate") ) {
107 feed->date = parseRFC822Date(text);
112 /* We're inside an <item></item> */
113 case FEED_LOC_RDF_ITEM:
114 if( ctx->curitem == NULL ) {
118 /* decide which field did we just get */
119 if( !strcmp(el, "title") ) {
120 FILL(ctx->curitem->title)
121 } else if( !strcmp(el, "dc:creator") ) {
122 FILL(ctx->curitem->author)
123 } else if( !strcmp(el, "description") ) {
124 FILL(ctx->curitem->summary)
125 } else if( !strcmp(el, "content:encoded") ) {
126 FILL(ctx->curitem->text)
127 } else if( !strcmp(el, "link") ) {
128 FILL(ctx->curitem->url)
129 } else if( !strcmp(el, "dc:date") ) {
130 ctx->curitem->date_modified = parseISO8601Date(text);
131 } else if( !strcmp(el, "pubDate") ) {
132 ctx->curitem->date_modified = parseRFC822Date(text);
142 if( ctx->str != NULL ) {
143 g_string_free(ctx->str, TRUE);