Mercurial > hg > nginx-quic
annotate src/core/ngx_parse.c @ 5669:cac82b9b3499
SSL: explicit handling of empty names.
X509_check_host() can't handle non null-terminated names with zero length,
so make sure to fail before calling it.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 23 Apr 2014 20:31:31 +0400 |
parents | d620f497c50f |
children | 15a15f6ae3a2 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
6 |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
563 | 12 ssize_t |
13 ngx_parse_size(ngx_str_t *line) | |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 { |
1971 | 15 u_char unit; |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
194
diff
changeset
|
16 size_t len; |
563 | 17 ssize_t size; |
18 ngx_int_t scale; | |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 len = line->len; |
1971 | 21 unit = line->data[len - 1]; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 |
1971 | 23 switch (unit) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 case 'K': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 case 'k': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 len--; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 scale = 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
30 case 'M': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 case 'm': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 len--; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 scale = 1024 * 1024; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 default: |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 |
563 | 40 size = ngx_atosz(line->data, len); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 if (size == NGX_ERROR) { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 size *= scale; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 return size; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
663 | 51 off_t |
52 ngx_parse_offset(ngx_str_t *line) | |
53 { | |
1971 | 54 u_char unit; |
663 | 55 off_t offset; |
56 size_t len; | |
57 ngx_int_t scale; | |
58 | |
59 len = line->len; | |
1971 | 60 unit = line->data[len - 1]; |
663 | 61 |
1971 | 62 switch (unit) { |
663 | 63 case 'K': |
64 case 'k': | |
65 len--; | |
66 scale = 1024; | |
67 break; | |
68 | |
69 case 'M': | |
70 case 'm': | |
71 len--; | |
72 scale = 1024 * 1024; | |
73 break; | |
74 | |
75 case 'G': | |
76 case 'g': | |
77 len--; | |
78 scale = 1024 * 1024 * 1024; | |
79 break; | |
80 | |
81 default: | |
82 scale = 1; | |
83 } | |
84 | |
85 offset = ngx_atoof(line->data, len); | |
86 if (offset == NGX_ERROR) { | |
87 return NGX_ERROR; | |
88 } | |
89 | |
90 offset *= scale; | |
91 | |
92 return offset; | |
93 } | |
94 | |
95 | |
563 | 96 ngx_int_t |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
97 ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec) |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
99 u_char *p, *last; |
651 | 100 ngx_int_t value, total, scale; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
101 ngx_uint_t max, valid; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 enum { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
103 st_start = 0, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
104 st_year, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 st_month, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 st_week, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 st_day, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 st_hour, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 st_min, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 st_sec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 st_msec, |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 st_last |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 } step; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
115 valid = 0; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
116 value = 0; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 total = 0; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
118 step = is_sec ? st_start : st_month; |
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
119 scale = is_sec ? 1 : 1000; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
121 p = line->data; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
122 last = p + line->len; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
124 while (p < last) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
126 if (*p >= '0' && *p <= '9') { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
127 value = value * 10 + (*p++ - '0'); |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
128 valid = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
129 continue; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
132 switch (*p++) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 case 'y': |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 if (step > st_start) { |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 step = st_year; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
139 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 365); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 scale = 60 * 60 * 24 * 365; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 case 'M': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
144 if (step >= st_month) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 step = st_month; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
148 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 30); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 scale = 60 * 60 * 24 * 30; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
150 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 case 'w': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
153 if (step >= st_week) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
155 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 step = st_week; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
157 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 7); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 scale = 60 * 60 * 24 * 7; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 case 'd': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
162 if (step >= st_day) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 step = st_day; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
166 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 scale = 60 * 60 * 24; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
170 case 'h': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
171 if (step >= st_hour) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 step = st_hour; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
175 max = NGX_MAX_INT32_VALUE / (60 * 60); |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
176 scale = 60 * 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 case 'm': |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
180 if (*p == 's') { |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
181 if (is_sec || step >= st_msec) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
182 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
183 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
184 p++; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
185 step = st_msec; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
186 max = NGX_MAX_INT32_VALUE; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
187 scale = 1; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
188 break; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
189 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
190 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
191 if (step >= st_min) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 step = st_min; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
195 max = NGX_MAX_INT32_VALUE / 60; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
196 scale = 60; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
198 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 case 's': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
200 if (step >= st_sec) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 step = st_sec; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
204 max = NGX_MAX_INT32_VALUE; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 scale = 1; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
206 break; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
207 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
208 case ' ': |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
209 if (step >= st_sec) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
210 return NGX_ERROR; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
211 } |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
212 step = st_last; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
213 max = NGX_MAX_INT32_VALUE; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 scale = 1; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
215 break; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
216 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
217 default: |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 return NGX_ERROR; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
219 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
220 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
221 if (step != st_msec && !is_sec) { |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
222 scale *= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
223 max /= 1000; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
224 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
226 if ((ngx_uint_t) value > max) { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
227 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
229 |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
230 total += value * scale; |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
232 if ((ngx_uint_t) total > NGX_MAX_INT32_VALUE) { |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
233 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
234 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
235 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
236 value = 0; |
4183
c352c483263c
Improved ngx_parse_time() code readability.
Ruslan Ermilov <ru@nginx.com>
parents:
1972
diff
changeset
|
237 scale = is_sec ? 1 : 1000; |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
238 |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
239 while (p < last && *p == ' ') { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
240 p++; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
242 } |
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 |
1972
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
244 if (valid) { |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
245 return total + value * scale; |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
246 } |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
247 |
9d2bdbda4ee3
allow time without spaces in ngx_parse_time()
Igor Sysoev <igor@sysoev.ru>
parents:
1971
diff
changeset
|
248 return NGX_ERROR; |
157
70b36c805682
nginx-0.0.1-2003-10-23-19:54:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 } |