You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Dmitri Tikhonov <dm...@netilla.com> on 2003/07/31 21:51:56 UTC
[apr-util] New (evil) date format for apr_date_parse_rfc()
Enclosed is a patch against APR 0.9.4 that would parse a date string I saw
produced by Netscape-Enterprise/4.1 server (it could be the web
application, however). This might not be the best solution, because I had
to copy and lower-case the month string for the date to parse. I couldn't
find this format in any RFC, so maybe this function is even a wrong place
for it.
- Dmitri.
--- apr_date.c 2003/04/10 19:16:14 1.5
+++ apr_date.c 2003/07/31 19:42:28
@@ -342,6 +342,8 @@
* Sun, 6 Nov 94 8:49:37 GMT ; Unknown [Elm 70.85]
* Mon, 7 Jan 2002 07:21:22 GMT ; Unknown [Postfix]
* Sun, 06-Nov-1994 08:49:37 GMT ; RFC 850 with four digit years
+ * THU 7-AUG-2003 16:16:19 GMT ; Upper-case month
+ * THU 17-AUG-2003 16:16:19 GMT ; Upper-case month
*
*/
@@ -362,7 +364,9 @@
{
apr_time_exp_t ds;
apr_time_t result;
- int mint, mon;
+ int mint, mon, i;
+ /* Buffer in case we need to lower-case month */
+ char mbuf[3];
const char *monstr, *timstr, *gmtstr;
static const int months[12] =
{
@@ -390,7 +394,7 @@
++date; /* Now pointing to first char after space, which should be */ }
- /* start of the actual date information for all 11 formats. */
+ /* start of the actual date information for all 14 formats. */
if (apr_date_checkmask(date, "## @$$ #### ##:##:## *")) { /* RFC 1123 format */
ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
@@ -580,6 +584,50 @@
ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
monstr = date + 3;
+ timstr = date + 12;
+ gmtstr = date + 21;
+
+ TIMEPARSE_STD(ds, timstr);
+ }
+ else if (apr_date_checkmask(date, "#-@@@-#### ##:##:## *")) {
+ /* Seen on the web: THU 7-AUG-2003 16:16:19 GMT */
+ ds.tm_year = ((date[6] - '0') * 10 + (date[7] - '0') - 19) * 100;
+ if (ds.tm_year < 0)
+ return APR_DATE_BAD;
+
+ ds.tm_year += ((date[8] - '0') * 10) + (date[9] - '0');
+
+ ds.tm_mday = date[0] - '0';
+
+ for (i = 0; i < 3; ++i) {
+ mbuf[i] = date[2 + i];
+ if (i)
+ mbuf[i] = apr_tolower(mbuf[i]);
+ }
+
+ monstr = mbuf;
+ timstr = date + 11;
+ gmtstr = date + 20;
+
+ TIMEPARSE_STD(ds, timstr);
+ }
+ else if (apr_date_checkmask(date, "##-@@@-#### ##:##:## *")) {
+ /* Seen on the web: THU 7-AUG-2003 16:16:19 GMT */
+ ds.tm_year = ((date[7] - '0') * 10 + (date[8] - '0') - 19) * 100;
+ if (ds.tm_year < 0)
+ return APR_DATE_BAD;
+
+ ds.tm_year += ((date[9] - '0') * 10) + (date[10] - '0');
+
+ ds.tm_mday = ((date[0] - '0') * 10) + (date[1] - '0');
+
+ for (i = 0; i < 3; ++i) {
+ mbuf[i] = date[3 + i];
+ if (i)
+ mbuf[i] = apr_tolower(mbuf[i]);
+ }
+
+ monstr = mbuf;
timstr = date + 12;
gmtstr = date + 21;