]>
git.ipfire.org Git - thirdparty/squid.git/blob - lib/rfc1123.c
3 * $Id: rfc1123.c,v 1.18 1998/07/17 00:16:29 wessels Exp $
6 * AUTHOR: Harvest Derived
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * --------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by
14 * the National Science Foundation.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 * Copyright (c) 1994, 1995. All rights reserved.
35 * The Harvest software was developed by the Internet Research Task
36 * Force Research Group on Resource Discovery (IRTF-RD):
38 * Mic Bowman of Transarc Corporation.
39 * Peter Danzig of the University of Southern California.
40 * Darren R. Hardy of the University of Colorado at Boulder.
41 * Udi Manber of the University of Arizona.
42 * Michael F. Schwartz of the University of Colorado at Boulder.
43 * Duane Wessels of the University of Colorado at Boulder.
45 * This copyright notice applies to software in the Harvest
46 * ``src/'' directory only. Users should consult the individual
47 * copyright notices in the ``components/'' subdirectories for
48 * copyright information about other software bundled with the
49 * Harvest source code distribution.
53 * The Harvest software may be used and re-distributed without
54 * charge, provided that the software origin and research team are
55 * cited in any use of the system. Most commonly this is
56 * accomplished by including a link to the Harvest Home Page
57 * (http://harvest.cs.colorado.edu/) from the query page of any
58 * Broker you deploy, as well as in the query result pages. These
59 * links are generated automatically by the standard Broker
60 * software distribution.
62 * The Harvest software is provided ``as is'', without express or
63 * implied warranty, and with no support nor obligation to assist
64 * in its use, correction, modification or enhancement. We assume
65 * no liability with respect to the infringement of copyrights,
66 * trade secrets, or any patents, and are not responsible for
67 * consequential damages. Proper use of the Harvest software is
68 * entirely the responsibility of the user.
72 * Users may make derivative works from the Harvest software, subject
73 * to the following constraints:
75 * - You must include the above copyright notice and these
76 * accompanying paragraphs in all forms of derivative works,
77 * and any documentation and other materials related to such
78 * distribution and use acknowledge that the software was
79 * developed at the above institutions.
81 * - You must notify IRTF-RD regarding your distribution of
82 * the derivative work.
84 * - You must clearly notify users that your are distributing
85 * a modified version and not the original Harvest software.
87 * - Any derivative product is also subject to these copyright
88 * and use restrictions.
90 * Note that the Harvest software is NOT in the public domain. We
91 * retain copyright, as specified above.
93 * HISTORY OF FREE SOFTWARE STATUS
95 * Originally we required sites to license the software in cases
96 * where they were going to build commercial products/services
97 * around Harvest. In June 1995 we changed this policy. We now
98 * allow people to use the core Harvest software (the code found in
99 * the Harvest ``src/'' directory) for free. We made this change
100 * in the interest of encouraging the widest possible deployment of
101 * the technology. The Harvest software is really a reference
102 * implementation of a set of protocols and formats, some of which
103 * we intend to standardize. We encourage commercial
104 * re-implementations of code complying to this set of standards.
111 * Adapted from HTSUtils.c in CERN httpd 3.0 (http://info.cern.ch/httpd/)
112 * by Darren Hardy <hardy@cs.colorado.edu>, November 1994.
124 #include <sys/types.h>
130 #include <sys/time.h>
134 #include "snprintf.h"
136 #define RFC850_STRFTIME "%A, %d-%b-%y %H:%M:%S GMT"
137 #define RFC1123_STRFTIME "%a, %d %b %Y %H:%M:%S GMT"
139 static int make_month(const char *s
);
140 static int make_num(const char *s
);
142 static char *month_names
[12] =
144 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
145 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
150 make_num(const char *s
)
152 if (*s
>= '0' && *s
<= '9')
153 return 10 * (*s
- '0') + *(s
+ 1) - '0';
155 return *(s
+ 1) - '0';
159 make_month(const char *s
)
164 month
[0] = toupper(*s
);
165 month
[1] = tolower(*(s
+ 1));
166 month
[2] = tolower(*(s
+ 2));
168 for (i
= 0; i
< 12; i
++)
169 if (!strncmp(month_names
[i
], month
, 3))
176 parse_rfc1123(const char *str
)
185 memset(&tm
, '\0', sizeof(struct tm
));
186 if ((s
= strchr(str
, ','))) { /* Thursday, 10-Jun-93 01:29:59 GMT */
187 s
++; /* or: Thu, 10 Jan 1993 01:29:59 GMT */
190 if (isdigit(*s
) && !isdigit(*(s
+1))) /* backoff if only one digit */
192 if (strchr(s
, '-')) { /* First format */
193 if ((int) strlen(s
) < 18)
195 tm
.tm_mday
= make_num(s
);
196 tm
.tm_mon
= make_month(s
+ 3);
197 tm
.tm_year
= make_num(s
+ 7);
199 * Y2K: Arjan de Vet <Arjan.deVet@adv.IAEhv.nl>
200 * if tm.tm_year < 70, assume it's after the year 2000.
204 tm
.tm_hour
= make_num(s
+ 10);
205 tm
.tm_min
= make_num(s
+ 13);
206 tm
.tm_sec
= make_num(s
+ 16);
207 } else { /* Second format */
208 if ((int) strlen(s
) < 20)
210 tm
.tm_mday
= make_num(s
);
211 tm
.tm_mon
= make_month(s
+ 3);
212 tm
.tm_year
= (100 * make_num(s
+ 7) - 1900) + make_num(s
+ 9);
213 tm
.tm_hour
= make_num(s
+ 12);
214 tm
.tm_min
= make_num(s
+ 15);
215 tm
.tm_sec
= make_num(s
+ 18);
218 } else { /* Try the other format: */
219 s
= str
; /* Wed Jun 9 01:29:59 1993 GMT */
220 while (*s
&& *s
== ' ')
222 if ((int) strlen(s
) < 24)
224 tm
.tm_mday
= make_num(s
+ 8);
225 tm
.tm_mon
= make_month(s
+ 4);
226 tm
.tm_year
= make_num(s
+ 22);
227 tm
.tm_hour
= make_num(s
+ 11);
228 tm
.tm_min
= make_num(s
+ 14);
229 tm
.tm_sec
= make_num(s
+ 17);
231 if (tm
.tm_sec
< 0 || tm
.tm_sec
> 59 ||
232 tm
.tm_min
< 0 || tm
.tm_min
> 59 ||
233 tm
.tm_hour
< 0 || tm
.tm_hour
> 23 ||
234 tm
.tm_mday
< 1 || tm
.tm_mday
> 31 ||
235 tm
.tm_mon
< 0 || tm
.tm_mon
> 11 ||
236 tm
.tm_year
< 70 || tm
.tm_year
> 120) {
246 struct tm
*local
= localtime(&t
);
247 t
+= local
->tm_gmtoff
;
250 /* some systems do not have tm_gmtoff so we fake it */
254 #if defined (_TIMEZONE)
255 #elif defined (_timezone)
256 #elif defined(_SQUID_AIX_)
258 extern time_t timezone
;
261 * The following assumes a fixed DST offset of 1 hour,
262 * which is probably wrong.
267 t
-= (_timezone
+ dst
);
269 t
-= (timezone
+ dst
);
279 static char buf
[128];
281 struct tm
*gmt
= gmtime(&t
);
284 strftime(buf
, 127, RFC1123_STRFTIME
, gmt
);
289 mkhttpdlogtime(const time_t * t
)
291 static char buf
[128];
293 struct tm
*gmt
= gmtime(t
);
296 int gmt_min
, gmt_hour
, gmt_yday
, day_offset
;
301 /* localtime & gmtime may use the same static data */
302 gmt_min
= gmt
->tm_min
;
303 gmt_hour
= gmt
->tm_hour
;
304 gmt_yday
= gmt
->tm_yday
;
307 day_offset
= lt
->tm_yday
- gmt_yday
;
308 min_offset
= day_offset
* 1440 + (lt
->tm_hour
- gmt_hour
) * 60
309 + (lt
->tm_min
- gmt_min
);
311 /* wrap round on end of year */
314 else if (day_offset
< -1)
317 len
= strftime(buf
, 127 - 5, "%d/%b/%Y:%H:%M:%S ", lt
);
318 snprintf(buf
+ len
, 128 - len
, "%+03d%02d",
319 (min_offset
/ 60) % 24,
323 strftime(buf
, 127, "%d/%b/%Y:%H:%M:%S -000", gmt
);
338 printf("HTTP Time: %s\n", x
);
340 pt
= parse_rfc1123(x
);
341 printf("Parsed: %d vs. %d\n", pt
, t
);