Return-Path: Delivered-To: apmail-apr-dev-archive@apr.apache.org Received: (qmail 69921 invoked by uid 500); 31 Jul 2003 19:54:44 -0000 Mailing-List: contact dev-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Delivered-To: mailing list dev@apr.apache.org Received: (qmail 69909 invoked from network); 31 Jul 2003 19:54:43 -0000 Date: Thu, 31 Jul 2003 15:51:56 -0400 (Eastern Daylight Time) From: Dmitri Tikhonov To: dev@apr.apache.org Subject: [apr-util] New (evil) date format for apr_date_parse_rfc() Message-ID: X-X-Sender: dmitri@mail.netilla.com MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-OriginalArrivalTime: 31 Jul 2003 19:52:12.0726 (UTC) FILETIME=[3C284560:01C3579D] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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;