RSSyl: fix crash introduced by previous commit
[claws.git] / src / plugins / rssyl / libfeed / parser_atom10.c
index 2285477caa0a9485757d0e28d775aaa84d2a8c21..f1ba9b39168cf25cab6e926934a8a0d84b376e7a 100644 (file)
@@ -47,10 +47,22 @@ void feed_parser_atom10_start(void *data, const gchar *el, const gchar **attr)
                        /* Start of author info for the feed found.
                         * Set correct location. */
                        ctx->location = FEED_LOC_ATOM10_AUTHOR;
+               } else if( !strcmp(el, "link") ) {
+                       /* 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. */
@@ -89,18 +101,20 @@ void feed_parser_atom10_end(void *data, const gchar *el)
 {
        FeedParserCtx *ctx = (FeedParserCtx *)data;
        Feed *feed = ctx->feed;
-       gchar *text = NULL;
+       gchar *text = NULL, *tmp;
 
        if( ctx->str != NULL )
                text = ctx->str->str;
        else
                text = "";
 
-       ctx->depth--;
-
        switch( ctx->depth ) {
 
                case 0:
+                       /* Just in case. */
+                       break;
+
+               case 1:
 
                        if( !strcmp(el, "feed") ) {
                                /* We have finished parsing the feed, reverse the list
@@ -110,12 +124,23 @@ void feed_parser_atom10_end(void *data, const gchar *el)
 
                        break;
 
-               case 1:
+               case 2:
 
                        /* decide if we just received </entry>, so we can
                         * add a complete item to feed */
                        if( !strcmp(el, "entry") ) {
 
+                               /* Fix up URL, if it is relative */
+                               if (ctx->curitem->url != NULL &&
+                                               !strstr("://", ctx->curitem->url) &&
+                                               ctx->feed->link != NULL) {
+                                       tmp = g_strconcat(ctx->feed->link,
+                                                       (ctx->curitem->url[0] == '/' ? "" : "/"),
+                                                       ctx->curitem->url, NULL);
+                                       feed_item_set_url(ctx->curitem, tmp);
+                                       g_free(tmp);
+                               }
+
                                /* append the complete feed item */
                                if( ctx->curitem->id && ctx->curitem->title
                                                && ctx->curitem->date_modified ) {
@@ -137,7 +162,7 @@ void feed_parser_atom10_end(void *data, const gchar *el)
 
                        break;
 
-               case 2:
+               case 3:
 
                        if( ctx->curitem == NULL )
                                break;
@@ -152,9 +177,9 @@ void feed_parser_atom10_end(void *data, const gchar *el)
                                                FILL(ctx->curitem->summary)
                                        } else if( !strcmp(el, "content") ) {
                                                if (!ctx->curitem->xhtml_content)
-                                                       FILL(ctx->curitem->text);
+                                                       FILL(ctx->curitem->text)
                                        } else if( !strcmp(el, "id") ) {
-                                               FILL(ctx->curitem->id);
+                                               FILL(ctx->curitem->id)
                                                feed_item_set_id_permalink(ctx->curitem, TRUE);
                                        } else if( !strcmp(el, "published") ) {
                                                ctx->curitem->date_published = parseISO8601Date(text);
@@ -176,7 +201,7 @@ void feed_parser_atom10_end(void *data, const gchar *el)
                                                                !ctx->name && !ctx->mail ? "N/A" : "");
                                                ctx->location = FEED_LOC_ATOM10_ENTRY;
                                        } else if( !strcmp(el, "name") ) {
-                                               FILL(feed->author);
+                                               FILL(feed->author)
                                        }
 
                                        break;
@@ -184,7 +209,7 @@ void feed_parser_atom10_end(void *data, const gchar *el)
 
                        break;
 
-               case 3:
+               case 4:
 
                        if( ctx->curitem == NULL )
                                break;
@@ -194,9 +219,9 @@ void feed_parser_atom10_end(void *data, const gchar *el)
                                /* We're in feed/entry/author */
                                case FEED_LOC_ATOM10_AUTHOR:
                                        if( !strcmp(el, "name") ) {
-                                               FILL(ctx->name);
+                                               FILL(ctx->name)
                                        } else if( !strcmp(el, "email") ) {
-                                               FILL(ctx->mail);
+                                               FILL(ctx->mail)
                                        }
 
                                        break;
@@ -204,9 +229,9 @@ void feed_parser_atom10_end(void *data, const gchar *el)
                                /* We're in feed/entry/source */
                                case FEED_LOC_ATOM10_SOURCE:
                                        if( !strcmp(el, "title" ) ) {
-                                               FILL(ctx->curitem->sourcetitle);
+                                               FILL(ctx->curitem->sourcetitle)
                                        } else if( !strcmp(el, "id" ) ) {
-                                               FILL(ctx->curitem->sourceid);
+                                               FILL(ctx->curitem->sourceid)
                                        } else if( !strcmp(el, "updated" ) ) {
                                                ctx->curitem->sourcedate = parseISO8601Date(text);
                                        }
@@ -215,7 +240,7 @@ void feed_parser_atom10_end(void *data, const gchar *el)
 
                                case FEED_LOC_ATOM10_CONTENT:
                                        if (!strcmp(el, "div") && ctx->curitem->xhtml_content)
-                                               FILL(ctx->curitem->text);
+                                               FILL(ctx->curitem->text)
                                        break;
 
                                }
@@ -229,4 +254,6 @@ void feed_parser_atom10_end(void *data, const gchar *el)
                ctx->str = NULL;
        }
        ctx->str = NULL;
+
+       ctx->depth--;
 }