talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 545ff0cc02a37ebcef0514afb42dd273a69ab3bf
parent 3b6cfef6e32f0eca7255c971a63233b25bee1ada
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Sat, 30 May 2015 19:45:32 +0200

RSSyl: Use procheader_date_parse() for RFC3339 date strings.

This allows us to remove the parseISO8601Date() function, and
therefore use of strptime(), which does not exist on all platforms.

Diffstat:
Msrc/plugins/rssyl/libfeed/date.c | 76++++------------------------------------------------------------------------
Msrc/plugins/rssyl/libfeed/parser_atom10.c | 10++++++----
Msrc/plugins/rssyl/libfeed/parser_rdf.c | 4++--
Msrc/plugins/rssyl/libfeed/parser_rss20.c | 4++--
4 files changed, 14 insertions(+), 80 deletions(-)

diff --git a/src/plugins/rssyl/libfeed/date.c b/src/plugins/rssyl/libfeed/date.c @@ -37,78 +37,10 @@ #include <time.h> #include <glib.h> -#include <locale.h> -#include <string.h> -#include <ctype.h> -#include <stdlib.h> - -/* converts a ISO 8601 time string to a time_t value */ -time_t parseISO8601Date(gchar *date) { - struct tm tm; - time_t t, t2, offset = 0; - gboolean success = FALSE; - gchar *pos; - - if (date == NULL) - return -1; - - memset(&tm, 0, sizeof(struct tm)); - - /* we expect at least something like "2003-08-07T15:28:19" and - don't require the second fractions and the timezone info - - the most specific format: YYYY-MM-DDThh:mm:ss.sTZD - */ - - /* full specified variant */ - if(NULL != (pos = strptime((const char *)date, "%Y-%m-%dT%H:%M:%SZ", &tm))) { - /* Parse seconds */ - if (*pos == ':') - pos++; - if (isdigit(pos[0]) && !isdigit(pos[1])) { - tm.tm_sec = pos[0] - '0'; - pos++; - } else if (isdigit(pos[0]) && isdigit(pos[1])) { - tm.tm_sec = 10*(pos[0]-'0') + pos[1] - '0'; - pos +=2; - } - /* Parse timezone */ - if (*pos == 'Z') - offset = 0; - else if ((*pos == '+' || *pos == '-') && isdigit(pos[1]) && isdigit(pos[2]) && strlen(pos) >= 3) { - offset = (10*(pos[1] - '0') + (pos[2] - '0')) * 60 * 60; - - if (pos[3] == ':' && isdigit(pos[4]) && isdigit(pos[5])) - offset += (10*(pos[4] - '0') + (pos[5] - '0')) * 60; - else if (isdigit(pos[3]) && isdigit(pos[4])) - offset += (10*(pos[3] - '0') + (pos[4] - '0')) * 60; - - offset *= (pos[0] == '+') ? 1 : -1; - - } - success = TRUE; - /* only date */ - } else if(NULL != strptime((const char *)date, "%t%Y-%m-%d", &tm)) - success = TRUE; - /* there were others combinations too... */ - - if(TRUE == success) { - if((time_t)(-1) != (t = mktime(&tm))) { - /* Correct for the local timezone*/ - t = t - offset; - t2 = mktime(gmtime(&t)); - t = t - (t2 - t); - - return t; - } else { - g_warning("internal error! time conversion error! mktime failed!\n"); - } - } else { - g_warning("Invalid ISO8601 date format! Ignoring <dc:date> information!\n"); - } - - return 0; -} +//#include <locale.h> +//#include <string.h> +//#include <ctype.h> +//#include <stdlib.h> gchar *dayofweek[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; gchar *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; diff --git a/src/plugins/rssyl/libfeed/parser_atom10.c b/src/plugins/rssyl/libfeed/parser_atom10.c @@ -23,6 +23,8 @@ #include <string.h> #include <stdio.h> +#include <procheader.h> + #include "feed.h" #include "feeditem.h" #include "date.h" @@ -167,7 +169,7 @@ void feed_parser_atom10_end(void *data, const gchar *el) } else if( !strcmp(el, "summary" ) ) { FILL(feed->description) } else if( !strcmp(el, "updated" ) ) { - feed->date = parseISO8601Date(text); + feed->date = procheader_date_parse(NULL, text, 0); } /* FIXME: add more later */ @@ -193,9 +195,9 @@ void feed_parser_atom10_end(void *data, const gchar *el) FILL(ctx->curitem->id) feed_item_set_id_permalink(ctx->curitem, TRUE); } else if( !strcmp(el, "published") ) { - ctx->curitem->date_published = parseISO8601Date(text); + ctx->curitem->date_published = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "updated") ) { - ctx->curitem->date_modified = parseISO8601Date(text); + ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } break; @@ -244,7 +246,7 @@ void feed_parser_atom10_end(void *data, const gchar *el) } else if( !strcmp(el, "id" ) ) { FILL(ctx->curitem->sourceid) } else if( !strcmp(el, "updated" ) ) { - ctx->curitem->sourcedate = parseISO8601Date(text); + ctx->curitem->sourcedate = procheader_date_parse(NULL, text, 0); } break; diff --git a/src/plugins/rssyl/libfeed/parser_rdf.c b/src/plugins/rssyl/libfeed/parser_rdf.c @@ -110,7 +110,7 @@ void feed_parser_rdf_end(void *data, const gchar *el) } else if( !strcmp(el, "dc:creator") ) { FILL(feed->author) } else if( !strcmp(el, "dc:date") ) { - feed->date = parseISO8601Date(text); + feed->date = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "pubDate") ) { feed->date = procheader_date_parse(NULL, text, 0); } @@ -135,7 +135,7 @@ void feed_parser_rdf_end(void *data, const gchar *el) } else if( !strcmp(el, "link") ) { FILL(ctx->curitem->url) } else if( !strcmp(el, "dc:date") ) { - ctx->curitem->date_modified = parseISO8601Date(text); + ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "pubDate") ) { ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } diff --git a/src/plugins/rssyl/libfeed/parser_rss20.c b/src/plugins/rssyl/libfeed/parser_rss20.c @@ -132,7 +132,7 @@ void feed_parser_rss20_end(void *data, const gchar *el) } else if( !strcmp(el, "admin:generatorAgent") ) { FILL(feed->generator) } else if( !strcmp(el, "dc:date") ) { - feed->date = parseISO8601Date(text); + feed->date = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "pubDate") ) { feed->date = procheader_date_parse(NULL, text, 0); } @@ -162,7 +162,7 @@ void feed_parser_rss20_end(void *data, const gchar *el) } else if( !strcmp(el, "wfw:commentRSS") || !strcmp(el, "wfw:commentRss") ) { FILL(ctx->curitem->comments_url) } else if( !strcmp(el, "dc:date") ) { - ctx->curitem->date_modified = parseISO8601Date(text); + ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "pubDate") ) { ctx->curitem->date_modified = procheader_date_parse(NULL, text, 0); } else if( !strcmp(el, "dc:creator")) {