comparison src/http/ngx_http_parse_time.c @ 538:1dcf6adad484 NGINX_0_8_21

nginx 0.8.21 *) Feature: now the "-V" switch shows TLS SNI support. *) Feature: the "listen" directive of the HTTP module supports unix domain sockets. Thanks to Hongli Lai. *) Feature: the "default_server" parameter of the "listen" directive. *) Feature: now a "default" parameter is not required to set listen socket options. *) Bugfix: nginx did not support dates in 2038 year on 32-bit platforms; *) Bugfix: socket leak; the bug had appeared in 0.8.11.
author Igor Sysoev <http://sysoev.ru>
date Mon, 26 Oct 2009 00:00:00 +0300
parents 79c5df00501e
children d0f7a625f27c
comparison
equal deleted inserted replaced
537:3ca2e495d9de 538:1dcf6adad484
6 6
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 9
10 10
11 static int mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; 11 static ngx_uint_t mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
12 12
13 time_t 13 time_t
14 ngx_http_parse_time(u_char *value, size_t len) 14 ngx_http_parse_time(u_char *value, size_t len)
15 { 15 {
16 u_char *p, *end; 16 u_char *p, *end;
17 int day, month, year, hour, min, sec; 17 ngx_int_t month;
18 ngx_uint_t day, year, hour, min, sec;
19 uint64_t time;
18 enum { 20 enum {
19 no = 0, 21 no = 0,
20 rfc822, /* Tue, 10 Nov 2002 23:50:13 */ 22 rfc822, /* Tue, 10 Nov 2002 23:50:13 */
21 rfc850, /* Tuesday, 10-Dec-02 23:50:13 */ 23 rfc850, /* Tuesday, 10-Dec-02 23:50:13 */
22 isoc /* Tue Dec 10 23:50:13 2002 */ 24 isoc /* Tue Dec 10 23:50:13 2002 */
227 229
228 } else if (day > mday[month]) { 230 } else if (day > mday[month]) {
229 return NGX_ERROR; 231 return NGX_ERROR;
230 } 232 }
231 233
232 #if (NGX_TIME_T_SIZE <= 4)
233
234 if (year >= 2038) {
235 return NGX_ERROR;
236 }
237
238 #endif
239
240 /* 234 /*
241 * shift new year to March 1 and start months from 1 (not 0), 235 * shift new year to March 1 and start months from 1 (not 0),
242 * it is needed for Gauss' formula 236 * it is needed for Gauss' formula
243 */ 237 */
244 238
247 year -= 1; 241 year -= 1;
248 } 242 }
249 243
250 /* Gauss' formula for Grigorian days since March 1, 1 BC */ 244 /* Gauss' formula for Grigorian days since March 1, 1 BC */
251 245
252 return ( 246 time = (uint64_t) (
253 /* days in years including leap years since March 1, 1 BC */ 247 /* days in years including leap years since March 1, 1 BC */
254 248
255 365 * year + year / 4 - year / 100 + year / 400 249 365 * year + year / 4 - year / 100 + year / 400
256 250
257 /* days before the month */ 251 /* days before the month */
266 * 719527 days were between March 1, 1 BC and March 1, 1970, 260 * 719527 days were between March 1, 1 BC and March 1, 1970,
267 * 31 and 28 days were in January and February 1970 261 * 31 and 28 days were in January and February 1970
268 */ 262 */
269 263
270 - 719527 + 31 + 28) * 86400 + hour * 3600 + min * 60 + sec; 264 - 719527 + 31 + 28) * 86400 + hour * 3600 + min * 60 + sec;
265
266 #if (NGX_TIME_T_SIZE <= 4)
267
268 if (time > 0x7fffffff) {
269 return NGX_ERROR;
270 }
271
272 #endif
273
274 return (time_t) time;
271 } 275 }