Return-Path: Delivered-To: apmail-apr-commits-archive@www.apache.org Received: (qmail 315 invoked from network); 19 Aug 2005 04:03:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Aug 2005 04:03:09 -0000 Received: (qmail 27410 invoked by uid 500); 19 Aug 2005 04:03:09 -0000 Delivered-To: apmail-apr-commits-archive@apr.apache.org Received: (qmail 27373 invoked by uid 500); 19 Aug 2005 04:03:08 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 27360 invoked by uid 99); 19 Aug 2005 04:03:08 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 18 Aug 2005 21:03:08 -0700 Received: (qmail 295 invoked by uid 65534); 19 Aug 2005 04:03:07 -0000 Message-ID: <20050819040307.294.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r233425 - in /apr/apr-util/trunk: CHANGES misc/apr_date.c test/Makefile.in test/abts_tests.h test/testdaterfc.c test/testutil.h Date: Fri, 19 Aug 2005 04:03:06 -0000 To: commits@apr.apache.org From: rooneg@apache.org X-Mailer: svnmailer-1.0.3 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: rooneg Date: Thu Aug 18 21:03:03 2005 New Revision: 233425 URL: http://svn.apache.org/viewcvs?rev=233425&view=rev Log: Fix the parsing of several types of RFC style dates and add a new one. * misc/apr_date.c (apr_date_parse_rfc): correct the gmt offset for two formats, tweak some comments, add a new date format, simplify gmtstr parsing. * test/Makefile.in (testall_OBJECTS): add testdaterfc.lo. * test/testdaterfc.c: new file. * test/abts_tests.h (alltests): add testdaterfc. * test/testutil.h (testdaterfc): new function prototype. * CHANGES: document change. Submitted By: Maxime Petazzoni Tweaked By: Garrett Rooney Added: apr/apr-util/trunk/test/testdaterfc.c Modified: apr/apr-util/trunk/CHANGES apr/apr-util/trunk/misc/apr_date.c apr/apr-util/trunk/test/Makefile.in apr/apr-util/trunk/test/abts_tests.h apr/apr-util/trunk/test/testutil.h Modified: apr/apr-util/trunk/CHANGES URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/CHANGES?rev=233425&r1=233424&r2=233425&view=diff ============================================================================== --- apr/apr-util/trunk/CHANGES (original) +++ apr/apr-util/trunk/CHANGES Thu Aug 18 21:03:03 2005 @@ -1,3 +1,8 @@ +Changes with APR-util 1.2.2 + + *) Fix GMT offset for several date formats and add a new format. + [Maxime Petazzoni ] + Changes with APR-util 1.2.0 *) Fix apr_rmm_realloc() offset calculation bug. [Keith Kelleman Modified: apr/apr-util/trunk/misc/apr_date.c URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/misc/apr_date.c?rev=233425&r1=233424&r2=233425&view=diff ============================================================================== --- apr/apr-util/trunk/misc/apr_date.c (original) +++ apr/apr-util/trunk/misc/apr_date.c Thu Aug 18 21:03:03 2005 @@ -361,7 +361,7 @@ monstr = date + 3; timstr = date + 12; - gmtstr = date + 20; + gmtstr = date + 21; TIMEPARSE_STD(ds, timstr); } @@ -418,7 +418,9 @@ } else if (apr_date_checkmask(date, "## @$$ ## ##:##:## *")) { /* This is the old RFC 1123 date format - many many years ago, people - * used two-digit years. Oh, how foolish. */ + * used two-digit years. Oh, how foolish. + * + * Two-digit day, two-digit year version. */ ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0'); if (ds.tm_year < 70) @@ -432,9 +434,29 @@ TIMEPARSE_STD(ds, timstr); } + else if (apr_date_checkmask(date, " # @$$ ## ##:##:## *")) { + /* This is the old RFC 1123 date format - many many years ago, people + * used two-digit years. Oh, how foolish. + * + * Space + one-digit day, two-digit year version.*/ + ds.tm_year = ((date[7] - '0') * 10) + (date[8] - '0'); + + if (ds.tm_year < 70) + ds.tm_year += 100; + + ds.tm_mday = (date[1] - '0'); + + monstr = date + 3; + timstr = date + 10; + gmtstr = date + 19; + + TIMEPARSE_STD(ds, timstr); + } else if (apr_date_checkmask(date, "# @$$ ## ##:##:## *")) { /* This is the old RFC 1123 date format - many many years ago, people - * used two-digit years. Oh, how foolish. */ + * used two-digit years. Oh, how foolish. + * + * One-digit day, two-digit year version. */ ds.tm_year = ((date[6] - '0') * 10) + (date[7] - '0'); if (ds.tm_year < 70) @@ -521,7 +543,7 @@ monstr = date + 3; timstr = date + 12; - gmtstr = date + 20; + gmtstr = date + 21; TIMEPARSE_STD(ds, timstr); } @@ -583,22 +605,21 @@ * If there is any confusion, tm_gmtoff will remain 0. */ ds.tm_gmtoff = 0; - if (gmtstr && *gmtstr != '\0') { - /* Do we have a GMT? */ - if (*(++gmtstr) != '\0') { - int offset; - switch (*(gmtstr++)) { - case '-': - offset = atoi(gmtstr); - ds.tm_gmtoff -= (offset / 100) * 60 * 60; - ds.tm_gmtoff -= (offset % 100) * 60; - break; - case '+': - offset = atoi(gmtstr); - ds.tm_gmtoff += (offset / 100) * 60 * 60; - ds.tm_gmtoff += (offset % 100) * 60; - break; - } + + /* Do we have a timezone ? */ + if (gmtstr) { + int offset; + switch (*gmtstr) { + case '-': + offset = atoi(gmtstr+1); + ds.tm_gmtoff -= (offset / 100) * 60 * 60; + ds.tm_gmtoff -= (offset % 100) * 60; + break; + case '+': + offset = atoi(gmtstr+1); + ds.tm_gmtoff += (offset / 100) * 60 * 60; + ds.tm_gmtoff += (offset % 100) * 60; + break; } } Modified: apr/apr-util/trunk/test/Makefile.in URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/Makefile.in?rev=233425&r1=233424&r2=233425&view=diff ============================================================================== --- apr/apr-util/trunk/test/Makefile.in (original) +++ apr/apr-util/trunk/test/Makefile.in Thu Aug 18 21:03:03 2005 @@ -74,7 +74,8 @@ $(LINK) $(APRUTIL_LDFLAGS) $(testxlate_OBJECTS) $(testxlate_LDADD) $(PROGRAM_DEPENDENCIES) testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \ - testbuckets.lo testpass.lo testmd4.lo testmd5.lo testldap.lo testdbd.lo + testbuckets.lo testpass.lo testmd4.lo testmd5.lo testldap.lo \ + testdaterfc.lo testdbd.lo testall_LDADD = $(TARGET_LIB_PATH) testall: $(testall_OBJECTS) $(testall_LDADD) $(LINK) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD) $(PROGRAM_DEPENDENCIES) Modified: apr/apr-util/trunk/test/abts_tests.h URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/abts_tests.h?rev=233425&r1=233424&r2=233425&view=diff ============================================================================== --- apr/apr-util/trunk/test/abts_tests.h (original) +++ apr/apr-util/trunk/test/abts_tests.h Thu Aug 18 21:03:03 2005 @@ -31,7 +31,8 @@ {testmd4}, {testmd5}, {testldap}, - {testdbd} + {testdbd}, + {testdaterfc} }; #endif /* APR_TEST_INCLUDES */ Added: apr/apr-util/trunk/test/testdaterfc.c URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testdaterfc.c?rev=233425&view=auto ============================================================================== --- apr/apr-util/trunk/test/testdaterfc.c (added) +++ apr/apr-util/trunk/test/testdaterfc.c Thu Aug 18 21:03:03 2005 @@ -0,0 +1,61 @@ +/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as + * applicable. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "testutil.h" +#include "apr_date.h" + +struct datetest { + const char *input; + const char *output; +} tests[] = { + { "Mon, 27 Feb 1995 20:49:44 -0800", "Tue, 28 Feb 1995 04:49:44 GMT" }, + { "Fri, 1 Jul 2005 11:34:25 -0400", "Fri, 01 Jul 2005 15:34:25 GMT" }, + { "Monday, 27-Feb-95 20:49:44 -0800", "Tue, 28 Feb 1995 04:49:44 GMT" }, + { "Tue, 4 Mar 1997 12:43:52 +0200", "Tue, 04 Mar 1997 10:43:52 GMT" }, + { "Mon, 27 Feb 95 20:49:44 -0800", "Tue, 28 Feb 1995 04:49:44 GMT" }, + { "Tue, 4 Mar 97 12:43:52 +0200", "Tue, 04 Mar 1997 10:43:52 GMT" }, + { "Tue, 4 Mar 97 12:43:52 +0200", "Tue, 04 Mar 1997 10:43:52 GMT" }, + { "Mon, 27 Feb 95 20:49 GMT", "Mon, 27 Feb 1995 20:49:00 GMT" }, + { "Tue, 4 Mar 97 12:43 GMT", "Tue, 04 Mar 1997 12:43:00 GMT" }, + { NULL, NULL } +}; + +static void test_date_rfc(abts_case *tc, void *data) +{ + apr_time_t date; + int i = 0; + + while (tests[i].input) { + char str_date[APR_RFC822_DATE_LEN] = { 0 }; + + date = apr_date_parse_rfc(tests[i].input); + + apr_rfc822_date(str_date, date); + + ABTS_STR_EQUAL(tc, str_date, tests[i].output); + + i++; + } +} + +abts_suite *testdaterfc(abts_suite *suite) +{ + suite = ADD_SUITE(suite); + + abts_run_test(suite, test_date_rfc, NULL); + + return suite; +} Modified: apr/apr-util/trunk/test/testutil.h URL: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testutil.h?rev=233425&r1=233424&r2=233425&view=diff ============================================================================== --- apr/apr-util/trunk/test/testutil.h (original) +++ apr/apr-util/trunk/test/testutil.h Thu Aug 18 21:03:03 2005 @@ -52,5 +52,6 @@ abts_suite *testmd5(abts_suite *suite); abts_suite *testldap(abts_suite *suite); abts_suite *testdbd(abts_suite *suite); +abts_suite *testdaterfc(abts_suite *suite); #endif /* APR_TEST_INCLUDES */