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.
25 #include <procheader.h>
29 #include "parser_rdf.h"
31 void feed_parser_rdf_start(void *data, const gchar *el, const gchar **attr)
33 FeedParserCtx *ctx = (FeedParserCtx *)data;
35 if( ctx->depth == 1 ) {
36 if( !strcmp(el, "channel") ) {
37 ctx->location = FEED_LOC_RDF_CHANNEL;
38 } else if( !strcmp(el, "item") ) {
40 if( ctx->curitem != NULL )
41 feed_item_free(ctx->curitem);
43 ctx->curitem = feed_item_new(ctx->feed);
44 ctx->location = FEED_LOC_RDF_ITEM;
46 } else ctx->location = 0;
53 void feed_parser_rdf_end(void *data, const gchar *el)
55 FeedParserCtx *ctx = (FeedParserCtx *)data;
56 Feed *feed = ctx->feed;
59 if( ctx->str != NULL )
60 text = g_strstrip(g_strdup(ctx->str->str));
66 switch( ctx->depth ) {
70 if( !strcmp(el, "rdf") ) {
71 /* we finished parsing the feed */
72 ctx->feed->items = g_slist_reverse(ctx->feed->items);
79 /* <item></item> block just ended, so ... */
80 if( !strcmp(el, "item") ) {
82 /* add the complete feed item to our feed struct */
84 g_slist_prepend(ctx->feed->items, (gpointer)ctx->curitem);
86 /* since it's in the linked list, lose this pointer */
94 switch(ctx->location) {
96 /* We're inside introductory <channel></channel> */
97 case FEED_LOC_RDF_CHANNEL:
98 if( !strcmp(el, "title") ) {
100 } else if( !strcmp(el, "description" ) ) {
101 FILL(feed->description)
102 } else if( !strcmp(el, "dc:language") ) {
104 } else if( !strcmp(el, "dc:creator") ) {
106 } else if( !strcmp(el, "dc:date") ) {
107 feed->date = parseISO8601Date(text);
108 } else if( !strcmp(el, "pubDate") ) {
109 feed->date = procheader_date_parse(NULL, text, 0);
114 /* We're inside an <item></item> */
115 case FEED_LOC_RDF_ITEM:
116 if( ctx->curitem == NULL ) {
120 /* decide which field did we just get */
121 if( !strcmp(el, "title") ) {
122 FILL(ctx->curitem->title)
123 } else if( !strcmp(el, "dc:creator") ) {
124 FILL(ctx->curitem->author)
125 } else if( !strcmp(el, "description") ) {
126 FILL(ctx->curitem->summary)
127 } else if( !strcmp(el, "content:encoded") ) {
128 FILL(ctx->curitem->text)
129 } else if( !strcmp(el, "link") ) {
130 FILL(ctx->curitem->url)
131 } else if( !strcmp(el, "dc:date") ) {
132 ctx->curitem->date_modified = parseISO8601Date(text);
133 } else if( !strcmp(el, "pubDate") ) {
134 ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0);
144 if( ctx->str != NULL ) {
146 g_string_free(ctx->str, TRUE);