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 )
62 switch( ctx->depth ) {
66 if( !strcmp(el, "rdf") ) {
67 /* we finished parsing the feed */
68 ctx->feed->items = g_slist_reverse(ctx->feed->items);
75 /* <item></item> block just ended, so ... */
76 if( !strcmp(el, "item") ) {
78 /* add the complete feed item to our feed struct */
80 g_slist_prepend(ctx->feed->items, (gpointer)ctx->curitem);
82 /* since it's in the linked list, lose this pointer */
90 switch(ctx->location) {
92 /* We're inside introductory <channel></channel> */
93 case FEED_LOC_RDF_CHANNEL:
94 if( !strcmp(el, "title") ) {
96 } else if( !strcmp(el, "description" ) ) {
97 FILL(feed->description)
98 } else if( !strcmp(el, "dc:language") ) {
100 } else if( !strcmp(el, "dc:creator") ) {
102 } else if( !strcmp(el, "dc:date") ) {
103 feed->date = parseISO8601Date(text);
104 } else if( !strcmp(el, "pubDate") ) {
105 feed->date = parseRFC822Date(text);
110 /* We're inside an <item></item> */
111 case FEED_LOC_RDF_ITEM:
112 if( ctx->curitem == NULL ) {
116 /* decide which field did we just get */
117 if( !strcmp(el, "title") ) {
118 FILL(ctx->curitem->title)
119 } else if( !strcmp(el, "dc:creator") ) {
120 FILL(ctx->curitem->author)
121 } else if( !strcmp(el, "description") ) {
122 FILL(ctx->curitem->summary)
123 } else if( !strcmp(el, "content:encoded") ) {
124 FILL(ctx->curitem->text)
125 } else if( !strcmp(el, "link") ) {
126 FILL(ctx->curitem->url)
127 } else if( !strcmp(el, "dc:date") ) {
128 ctx->curitem->date_modified = parseISO8601Date(text);
129 } else if( !strcmp(el, "pubDate") ) {
130 ctx->curitem->date_modified = parseRFC822Date(text);
140 if( ctx->str != NULL ) {
141 g_string_free(ctx->str, TRUE);