[Commits] [SCM] claws branch, master, updated. 3.11.1-111-g545ff0c
ticho at claws-mail.org
ticho at claws-mail.org
Sat May 30 19:47:16 CEST 2015
The branch, master has been updated
via 545ff0cc02a37ebcef0514afb42dd273a69ab3bf (commit)
via 3b6cfef6e32f0eca7255c971a63233b25bee1ada (commit)
from 87adea61fd673b7820a5ee5726403577439b8e0e (commit)
Summary of changes:
src/plugins/rssyl/libfeed/date.c | 76 ++---------------------------
src/plugins/rssyl/libfeed/parser_atom10.c | 10 ++--
src/plugins/rssyl/libfeed/parser_rdf.c | 4 +-
src/plugins/rssyl/libfeed/parser_rss20.c | 4 +-
src/procheader.c | 43 +++++++++++-----
5 files changed, 45 insertions(+), 92 deletions(-)
- Log -----------------------------------------------------------------
commit 545ff0cc02a37ebcef0514afb42dd273a69ab3bf
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Sat May 30 19:45:32 2015 +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.
diff --git a/src/plugins/rssyl/libfeed/date.c b/src/plugins/rssyl/libfeed/date.c
index b00555a..cb7c6d2 100644
--- 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
index 8f9f4d6..eda6064 100644
--- 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
index 77e1df5..361c5a8 100644
--- 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
index 1ce30ab..df9c08e 100644
--- 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")) {
commit 3b6cfef6e32f0eca7255c971a63233b25bee1ada
Author: Andrej Kacian <ticho at claws-mail.org>
Date: Sat May 30 19:40:51 2015 +0200
Rewrote parsing of RFC3339 datetime strings.
This rewrite supports all allowed separators between date
and time: both uppercase and lowercase 'T', as well as space.
Only thing not yet supported is 'Z' instead of time zone offset,
I will hopefully add that later.
diff --git a/src/procheader.c b/src/procheader.c
index bfa31f1..36298be 100644
--- a/src/procheader.c
+++ b/src/procheader.c
@@ -790,8 +790,10 @@ static gint procheader_scan_date_string(const gchar *str,
{
gint result;
gint month_n;
- gchar zone1[3];
- gchar zone2[3];
+ gint secfract;
+ gint zone1, zone2;
+ gchar offset_sign;
+ gchar sep1;
if (str == NULL)
return -1;
@@ -836,23 +838,40 @@ static gint procheader_scan_date_string(const gchar *str,
day, month, year, hh, mm);
if (result == 5) return 0;
- /* RFC3339 subset */
*weekday = '\0';
- result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d+%2s:%2s",
- year, &month_n, day, hh, mm, ss, zone1, zone2);
- if (result == 8) {
- if (1 <= month_n && month_n <= 12) {
+
+ /* RFC3339 subset, with fraction of second */
+ /* TODO: Allow "Z" instead of time zone offset, since RFC allows
+ * that too. */
+ result = sscanf(str, "%4d-%2d-%2d%c%2d:%2d:%2d.%1d%c%2d:%2d",
+ year, &month_n, day, &sep1, hh, mm, ss, &secfract,
+ &offset_sign, &zone1, &zone2);
+ if (result == 11
+ && (sep1 == 'T' || sep1 == 't' || sep1 == ' ')) {
+ if (month_n >= 1 && month_n <= 12) {
strncpy2(month, monthstr+((month_n-1)*3), 4);
- *zone = '+';
- strncpy2(zone+1, zone1, 3);
- strncpy2(zone+3, zone2, 3);
+ sprintf(zone, "%c%2d%2d", offset_sign, zone1, zone2);
+ return 0;
+ }
+ }
+
+ /* RFC3339 subset, no fraction of second */
+ result = sscanf(str, "%4d-%2d-%2d%c%2d:%2d:%2d%c%2d:%2d",
+ year, &month_n, day, &sep1, hh, mm, ss,
+ &offset_sign, &zone1, &zone2);
+ if (result == 10
+ && (sep1 == 'T' || sep1 == 't' || sep1 == ' ')) {
+ if (month_n >= 1 && month_n <= 12) {
+ strncpy2(month, monthstr+((month_n-1)*3), 4);
+ sprintf(zone, "%c%2d%2d", offset_sign, zone1, zone2);
return 0;
}
}
- /* RFC3339 subset */
*zone = '\0';
- *weekday = '\0';
+
+ /* RFC3339 subset */
+ /* This particular "subset" is invalid, RFC requires the time offset */
result = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d",
year, &month_n, day, hh, mm, ss);
if (result == 6) {
-----------------------------------------------------------------------
hooks/post-receive
--
Claws Mail
More information about the Commits
mailing list