rbb 99/12/20 08:10:19
Modified: src/lib/apr/include apr.h.in apr_errno.h apr_time.h src/lib/apr/time/unix Makefile.in access.c atime.h time.c Added: src/lib/apr/time/unix timestr.c Log: A bunch more time functions for use in Apache. This is really the first cut at making the time library usable in an actual program. Revision Changes Path 1.7 +1 -0 apache-2.0/src/lib/apr/include/apr.h.in Index: apr.h.in =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr.h.in,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- apr.h.in 1999/12/06 18:19:33 1.6 +++ apr.h.in 1999/12/20 16:10:10 1.7 @@ -70,6 +70,7 @@ #define API_EXPORT(type) type #define API_EXPORT_NONSTD(type) type #define API_VAR_IMPORT extern +#define API_VAR_EXPORT #endif /* APR_H */ 1.12 +3 -0 apache-2.0/src/lib/apr/include/apr_errno.h Index: apr_errno.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_errno.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- apr_errno.h 1999/12/09 21:00:20 1.11 +++ apr_errno.h 1999/12/20 16:10:11 1.12 @@ -124,6 +124,9 @@ #define APR_BADARG (APR_OS_START_STATUS + 13) #define APR_EOF (APR_OS_START_STATUS + 14) #define APR_NOTFOUND (APR_OS_START_STATUS + 15) +#define APR_LESS (APR_OS_START_STATUS + 16) +#define APR_EQUAL (APR_OS_START_STATUS + 17) +#define APR_MORE (APR_OS_START_STATUS + 18) /* A simple value to be used to initialze a status variable. */ #define APR_EINIT (APR_OS_START_STATUS + 16) 1.4 +8 -0 apache-2.0/src/lib/apr/include/apr_time.h Index: apr_time.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_time.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- apr_time.h 1999/10/04 16:36:55 1.3 +++ apr_time.h 1999/12/20 16:10:11 1.4 @@ -67,12 +67,18 @@ typedef struct atime_t ap_time_t; +API_VAR_IMPORT const char ap_month_snames[12][4]; +API_VAR_IMPORT const char ap_day_snames[7][4]; + /* Function Definitions */ ap_status_t ap_make_time(ap_time_t **, ap_context_t *); ap_status_t ap_current_time(ap_time_t *); ap_status_t ap_explode_time(ap_time_t *, ap_timetype_e); ap_status_t ap_implode_time(ap_time_t *); +ap_status_t ap_gm_timestr_822(char **date_str, struct atime_t *t, ap_context_t *p); +ap_status_t ap_strftime(char *s, ap_size_t max, const char *format, ap_time_t *tm); + /* accessor functions */ ap_status_t ap_get_curtime(ap_time_t *, ap_int64_t *); ap_status_t ap_timediff(ap_time_t *, ap_time_t *, ap_int32_t *); @@ -85,6 +91,7 @@ ap_status_t ap_get_year(ap_time_t *, ap_int32_t *); ap_status_t ap_get_wday(ap_time_t *, ap_int32_t *); +ap_status_t ap_set_curtime(ap_time_t *, ap_int64_t); ap_status_t ap_set_sec(ap_time_t *, ap_int32_t); ap_status_t ap_set_min(ap_time_t *, ap_int32_t); ap_status_t ap_set_hour(ap_time_t *, ap_int32_t); @@ -92,6 +99,7 @@ ap_status_t ap_set_mon(ap_time_t *, ap_int32_t); ap_status_t ap_set_year(ap_time_t *, ap_int32_t); ap_status_t ap_set_wday(ap_time_t *, ap_int32_t); +ap_status_t ap_timecmp(ap_time_t *a, ap_time_t *b); ap_status_t ap_get_timedata(ap_time_t *, char *, void *); ap_status_t ap_set_timedata(ap_time_t *, void *, char *, 1.8 +11 -4 apache-2.0/src/lib/apr/time/unix/Makefile.in Index: Makefile.in =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/time/unix/Makefile.in,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- Makefile.in 1999/12/19 18:10:05 1.7 +++ Makefile.in 1999/12/20 16:10:15 1.8 @@ -15,7 +15,8 @@ LIB=libtime.a OBJS=time.o \ - access.o + access.o \ + timestr.o .c.o: $(CC) $(CFLAGS) -c $(INCLUDES) $< @@ -53,10 +54,16 @@ access.o: access.c atime.h ../../include/apr_config.h \ ../../include/apr_time.h ../../include/apr_general.h \ ../../include/apr.h ../../include/apr_errno.h ../../include/apr_lib.h \ - ../../include/apr_file_io.h + ../../include/apr_file_io.h ../../include/apr_thread_proc.h time.o: time.c atime.h ../../include/apr_config.h \ ../../include/apr_time.h ../../include/apr_general.h \ ../../include/apr.h ../../include/apr_errno.h ../../include/apr_lib.h \ - ../../include/apr_file_io.h ../../include/apr_portable.h \ - ../../include/apr_thread_proc.h ../../include/apr_network_io.h \ + ../../include/apr_file_io.h ../../include/apr_thread_proc.h \ + ../../include/apr_portable.h ../../include/apr_network_io.h \ + ../../include/apr_lock.h +timestr.o: timestr.c atime.h ../../include/apr_config.h \ + ../../include/apr_time.h ../../include/apr_general.h \ + ../../include/apr.h ../../include/apr_errno.h ../../include/apr_lib.h \ + ../../include/apr_file_io.h ../../include/apr_thread_proc.h \ + ../../include/apr_portable.h ../../include/apr_network_io.h \ ../../include/apr_lock.h 1.8 +18 -0 apache-2.0/src/lib/apr/time/unix/access.c Index: access.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/time/unix/access.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- access.c 1999/12/03 15:18:48 1.7 +++ access.c 1999/12/20 16:10:15 1.8 @@ -176,6 +176,24 @@ } /* ***APRDOC******************************************************** + * ap_status_t ap_set_curtime(ap_time_t *, ap_int64_t) + * Set the current time in seconds since Jan 1, 1970. + * arg 1) The time value we care about. + * arg 2) Integer to store time value in + */ +ap_status_t ap_set_curtime(struct atime_t *atime, ap_int64_t sec) +{ + if (atime) { + if (!atime->currtime) { + atime->currtime = ap_pcalloc(atime->cntxt, sizeof(struct timeval)); + } + atime->currtime->tv_sec = sec; + return APR_SUCCESS; + } + return APR_ENOTIME; +} + +/* ***APRDOC******************************************************** * ap_status_t ap_set_sec(ap_time_t *, ap_int64_t) * Set the number of sec since the top of the minute * arg 1) The time value we care about. 1.4 +1 -0 apache-2.0/src/lib/apr/time/unix/atime.h Index: atime.h =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/time/unix/atime.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- atime.h 1999/12/06 18:19:48 1.3 +++ atime.h 1999/12/20 16:10:16 1.4 @@ -73,6 +73,7 @@ ap_context_t *cntxt; struct timeval *currtime; struct tm *explodedtime; + int time_ex; /* have we already exploded the time? */ }; 1.13 +40 -0 apache-2.0/src/lib/apr/time/unix/time.c Index: time.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/time/unix/time.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- time.c 1999/12/03 15:18:49 1.12 +++ time.c 1999/12/20 16:10:16 1.13 @@ -72,6 +72,7 @@ (*new)->cntxt = cont; (*new)->explodedtime = ap_palloc(cont, sizeof(struct tm)); + (*new)->time_ex = 0; (*new)->currtime = NULL; return APR_SUCCESS; } @@ -85,6 +86,7 @@ { new->currtime = ap_palloc(new->cntxt, sizeof(struct timeval)); gettimeofday(new->currtime, NULL); + new->time_ex = 0; return APR_SUCCESS; } @@ -117,6 +119,7 @@ break; } } + atime->time_ex = 1; return APR_SUCCESS; } @@ -160,6 +163,7 @@ atime->currtime = ap_palloc(atime->cntxt, sizeof(struct timeval)); atime->currtime->tv_sec = days; /* must be a valid time */ atime->currtime->tv_usec = 0; + atime->time_ex = 1; return APR_SUCCESS; } @@ -199,6 +203,7 @@ (*thetime)->cntxt = cont; } (*thetime)->currtime = atime; + (*thetime)->time_ex = 0; return APR_SUCCESS; } @@ -220,4 +225,39 @@ *rv = s + us; return APR_SUCCESS; } + +/* ***APRDOC******************************************************** + * ap_status_t ap_timecmp(ap_time_t **, ap_time_t *, ap_time_t *) + * Compare two time values. + * arg 1) The first time value + * arg 2) The second time value. + * return) APR_LESS -- arg 1 < arg 2 + * APR_MORE -- arg 1 > arg 2 + * APR_EQUAL -- arg 1 = arg 2 + */ +ap_status_t ap_timecmp(struct atime_t *a, struct atime_t *b) +{ + if (a == NULL) { + return APR_LESS; + } + else if (b == NULL) { + return APR_MORE; + } + + if (a->currtime->tv_sec > b->currtime->tv_sec) { + return APR_MORE; + } + else if (a->currtime->tv_sec < b->currtime->tv_sec) { + return APR_LESS; + } + else { + if (a->currtime->tv_usec > b->currtime->tv_sec) { + return APR_MORE; + } + else { + return APR_LESS; + } + } + return APR_EQUAL; +} 1.1 apache-2.0/src/lib/apr/time/unix/timestr.c Index: timestr.c =================================================================== /* ==================================================================== * Copyright (c) 1999 The Apache Group. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * 4. The names "Apache Server" and "Apache Group" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the Apache Group * for use in the Apache HTTP server project (http://www.apache.org/)." * * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Group. * For more information on the Apache Group and the Apache HTTP server * project, please see <http://www.apache.org/>. * */ #include "atime.h" #include "apr_portable.h" API_VAR_EXPORT const char ap_month_snames[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; API_VAR_EXPORT const char ap_day_snames[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; ap_status_t ap_gm_timestr_822(char **date_str, struct atime_t *t, ap_context_t *p) { struct tm *tms; char *date_str_ptr; int real_year; (*date_str) = ap_palloc(p, 48 * sizeof(char)); date_str_ptr = (*date_str); if (t->time_ex == 0) { ap_explode_time(t, APR_UTCTIME); } /* Assumption: this is always 3 */ /* i = strlen(ap_day_snames[tms->tm_wday]); */ memcpy(date_str_ptr, ap_day_snames[t->explodedtime->tm_wday], 3); date_str_ptr += 3; *date_str_ptr++ = ','; *date_str_ptr++ = ' '; *date_str_ptr++ = t->explodedtime->tm_mday / 10 + '0'; *date_str_ptr++ = t->explodedtime->tm_mday % 10 + '0'; *date_str_ptr++ = ' '; /* Assumption: this is also always 3 */ /* i = strlen(ap_month_snames[tms->tm_mon]); */ memcpy(date_str_ptr, ap_month_snames[t->explodedtime->tm_mon], 3); date_str_ptr += 3; *date_str_ptr++ = ' '; real_year = 1900 + t->explodedtime->tm_year; /* This routine isn't y10k ready. */ *date_str_ptr++ = real_year / 1000 + '0'; *date_str_ptr++ = real_year % 1000 / 100 + '0'; *date_str_ptr++ = real_year % 100 / 10 + '0'; *date_str_ptr++ = real_year % 10 + '0'; *date_str_ptr++ = ' '; *date_str_ptr++ = t->explodedtime->tm_hour / 10 + '0'; *date_str_ptr++ = t->explodedtime->tm_hour % 10 + '0'; *date_str_ptr++ = ':'; *date_str_ptr++ = t->explodedtime->tm_min / 10 + '0'; *date_str_ptr++ = t->explodedtime->tm_min % 10 + '0'; *date_str_ptr++ = ':'; *date_str_ptr++ = t->explodedtime->tm_sec / 10 + '0'; *date_str_ptr++ = t->explodedtime->tm_sec % 10 + '0'; *date_str_ptr++ = ' '; *date_str_ptr++ = 'G'; *date_str_ptr++ = 'M'; *date_str_ptr++ = 'T'; *date_str_ptr = '\0'; return APR_SUCCESS; /* RFC date format; as strftime '%a, %d %b %Y %T GMT' */ /* The equivalent using sprintf. Use this for more legible but slower code return ap_psprintf(p, "%s, %.2d %s %d %.2d:%.2d:%.2d GMT", ap_day_snames[t->explodedtime->tm_wday], t->explodedtime->tm_mday, ap_month_snames[t->explodedtime->tm_mon], t->explodedtime->tm_year + 1900, t->explodedtime->tm_hour, t->explodedtime->tm_min, t->explodedtime->tm_sec); */ } ap_status_t ap_strftime(char *s, ap_size_t max, const char *format, struct atime_t *tm) { strftime(s, max, format, tm->explodedtime); }