RSSyl: Use procheader_date_parse() for RFC3339 date strings.
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 30 May 2015 17:45:32 +0000 (19:45 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 30 May 2015 17:46:48 +0000 (19:46 +0200)
This allows us to remove the parseISO8601Date() function, and
therefore use of strptime(), which does not exist on all platforms.

src/plugins/rssyl/libfeed/date.c
src/plugins/rssyl/libfeed/parser_atom10.c
src/plugins/rssyl/libfeed/parser_rdf.c
src/plugins/rssyl/libfeed/parser_rss20.c

index b00555a..cb7c6d2 100644 (file)
 
 #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"};
index 8f9f4d6..eda6064 100644 (file)
@@ -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;
index 77e1df5..361c5a8 100644 (file)
@@ -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);
                                        }
index 1ce30ab..df9c08e 100644 (file)
@@ -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")) {