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"
37 void feed_parser_rdf_start(void *data, const gchar *el, const gchar **attr)
39 FeedParserCtx *ctx = (FeedParserCtx *)data;
41 if( ctx->depth == 1 ) {
42 if( !strcmp(el, "channel") ) {
43 ctx->location = FEED_LOC_RDF_CHANNEL;
44 } else if( !strcmp(el, "item") ) {
46 if( ctx->curitem != NULL )
47 feed_item_free(ctx->curitem);
49 ctx->curitem = feed_item_new(ctx->feed);
50 ctx->location = FEED_LOC_RDF_ITEM;
52 } else ctx->location = 0;
59 void feed_parser_rdf_end(void *data, const gchar *el)
61 FeedParserCtx *ctx = (FeedParserCtx *)data;
62 Feed *feed = ctx->feed;
65 if( ctx->str != NULL )
66 text = g_strstrip(g_strdup(ctx->str->str));
72 switch( ctx->depth ) {
76 if( !strcmp(el, "rdf") ) {
77 /* we finished parsing the feed */
78 ctx->feed->items = g_slist_reverse(ctx->feed->items);
85 /* <item></item> block just ended, so ... */
86 if( !strcmp(el, "item") ) {
88 /* add the complete feed item to our feed struct */
90 g_slist_prepend(ctx->feed->items, (gpointer)ctx->curitem);
92 /* since it's in the linked list, lose this pointer */
100 switch(ctx->location) {
102 /* We're inside introductory <channel></channel> */
103 case FEED_LOC_RDF_CHANNEL:
104 if( !strcmp(el, "title") ) {
106 } else if( !strcmp(el, "description" ) ) {
107 FILL(feed->description)
108 } else if( !strcmp(el, "dc:language") ) {
110 } else if( !strcmp(el, "dc:creator") ) {
112 } else if( !strcmp(el, "dc:date") ) {
113 feed->date = procheader_date_parse(NULL, text, 0);
114 } else if( !strcmp(el, "pubDate") ) {
115 feed->date = procheader_date_parse(NULL, text, 0);
120 /* We're inside an <item></item> */
121 case FEED_LOC_RDF_ITEM:
122 if( ctx->curitem == NULL ) {
126 /* decide which field did we just get */
127 if( !strcmp(el, "title") ) {
128 FILL(ctx->curitem->title)
129 } else if( !strcmp(el, "dc:creator") ) {
130 FILL(ctx->curitem->author)
131 } else if( !strcmp(el, "description") ) {
132 FILL(ctx->curitem->summary)
133 } else if( !strcmp(el, "content:encoded") ) {
134 FILL(ctx->curitem->text)
135 } else if( !strcmp(el, "link") ) {
136 FILL(ctx->curitem->url)
137 } else if( !strcmp(el, "dc:date") ) {
138 ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0);
139 } else if( !strcmp(el, "pubDate") ) {
140 ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0);
150 if( ctx->str != NULL ) {
152 g_string_free(ctx->str, TRUE);