Mercurial > hg > nginx-quic
comparison src/core/ngx_parse.c @ 4241:6afb20bf2ad5 stable-1.0
Merging r4009, r4133, r4184, r4201, r4202, r4203, r4204, r4205:
Miscellaneous fixes:
*) Fix of names of the referer hash size directives introduced in r3940.
*) Cosmetics: replaced NGX_CONF_TAKE1 to NGX_CONF_FLAG for "sendfile"
and "chunked_transfer_encoding" directives, to be in line with all
directives taking a boolean argument. Both flags will ensure that
a directive takes one argument.
*) Improved ngx_parse_time() code readability.
*) Preallocating exact number of default MIME types entries.
*) Stylistic change in checking the boolean expression.
*) Replaced magic constants representing default values of some directives
with appropriate #define's.
*) Fixed grammar in a comment.
*) Fixed two minor bugs in "types" parsing code.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 01 Nov 2011 11:19:58 +0000 |
parents | 9d2bdbda4ee3 |
children | d620f497c50f |
comparison
equal
deleted
inserted
replaced
4240:17ab1927f80f | 4241:6afb20bf2ad5 |
---|---|
91 return offset; | 91 return offset; |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 ngx_int_t | 95 ngx_int_t |
96 ngx_parse_time(ngx_str_t *line, ngx_uint_t sec) | 96 ngx_parse_time(ngx_str_t *line, ngx_uint_t is_sec) |
97 { | 97 { |
98 u_char *p, *last; | 98 u_char *p, *last; |
99 ngx_int_t value, total, scale; | 99 ngx_int_t value, total, scale; |
100 ngx_uint_t max, valid; | 100 ngx_uint_t max, valid; |
101 enum { | 101 enum { |
112 } step; | 112 } step; |
113 | 113 |
114 valid = 0; | 114 valid = 0; |
115 value = 0; | 115 value = 0; |
116 total = 0; | 116 total = 0; |
117 step = sec ? st_start : st_month; | 117 step = is_sec ? st_start : st_month; |
118 scale = sec ? 1 : 1000; | 118 scale = is_sec ? 1 : 1000; |
119 | 119 |
120 p = line->data; | 120 p = line->data; |
121 last = p + line->len; | 121 last = p + line->len; |
122 | 122 |
123 while (p < last) { | 123 while (p < last) { |
133 case 'y': | 133 case 'y': |
134 if (step > st_start) { | 134 if (step > st_start) { |
135 return NGX_ERROR; | 135 return NGX_ERROR; |
136 } | 136 } |
137 step = st_year; | 137 step = st_year; |
138 max = 68; | 138 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 365); |
139 scale = 60 * 60 * 24 * 365; | 139 scale = 60 * 60 * 24 * 365; |
140 break; | 140 break; |
141 | 141 |
142 case 'M': | 142 case 'M': |
143 if (step > st_year) { | 143 if (step >= st_month) { |
144 return NGX_ERROR; | 144 return NGX_ERROR; |
145 } | 145 } |
146 step = st_month; | 146 step = st_month; |
147 max = 828; | 147 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 30); |
148 scale = 60 * 60 * 24 * 30; | 148 scale = 60 * 60 * 24 * 30; |
149 break; | 149 break; |
150 | 150 |
151 case 'w': | 151 case 'w': |
152 if (step > st_month) { | 152 if (step >= st_week) { |
153 return NGX_ERROR; | 153 return NGX_ERROR; |
154 } | 154 } |
155 step = st_week; | 155 step = st_week; |
156 max = 3550; | 156 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24 * 7); |
157 scale = 60 * 60 * 24 * 7; | 157 scale = 60 * 60 * 24 * 7; |
158 break; | 158 break; |
159 | 159 |
160 case 'd': | 160 case 'd': |
161 if (step > st_week) { | 161 if (step >= st_day) { |
162 return NGX_ERROR; | 162 return NGX_ERROR; |
163 } | 163 } |
164 step = st_day; | 164 step = st_day; |
165 max = 24855; | 165 max = NGX_MAX_INT32_VALUE / (60 * 60 * 24); |
166 scale = 60 * 60 * 24; | 166 scale = 60 * 60 * 24; |
167 break; | 167 break; |
168 | 168 |
169 case 'h': | 169 case 'h': |
170 if (step > st_day) { | 170 if (step >= st_hour) { |
171 return NGX_ERROR; | 171 return NGX_ERROR; |
172 } | 172 } |
173 step = st_hour; | 173 step = st_hour; |
174 max = 596523; | 174 max = NGX_MAX_INT32_VALUE / (60 * 60); |
175 scale = 60 * 60; | 175 scale = 60 * 60; |
176 break; | 176 break; |
177 | 177 |
178 case 'm': | 178 case 'm': |
179 if (*p == 's') { | 179 if (*p == 's') { |
180 if (sec || step > st_sec) { | 180 if (is_sec || step >= st_msec) { |
181 return NGX_ERROR; | 181 return NGX_ERROR; |
182 } | 182 } |
183 p++; | 183 p++; |
184 step = st_msec; | 184 step = st_msec; |
185 max = 2147483647; | 185 max = NGX_MAX_INT32_VALUE; |
186 scale = 1; | 186 scale = 1; |
187 break; | 187 break; |
188 } | 188 } |
189 | 189 |
190 if (step > st_hour) { | 190 if (step >= st_min) { |
191 return NGX_ERROR; | 191 return NGX_ERROR; |
192 } | 192 } |
193 step = st_min; | 193 step = st_min; |
194 max = 35791394; | 194 max = NGX_MAX_INT32_VALUE / 60; |
195 scale = 60; | 195 scale = 60; |
196 break; | 196 break; |
197 | 197 |
198 case 's': | 198 case 's': |
199 if (step > st_min) { | 199 if (step >= st_sec) { |
200 return NGX_ERROR; | 200 return NGX_ERROR; |
201 } | 201 } |
202 step = st_sec; | 202 step = st_sec; |
203 max = 2147483647; | 203 max = NGX_MAX_INT32_VALUE; |
204 scale = 1; | 204 scale = 1; |
205 break; | 205 break; |
206 | 206 |
207 case ' ': | 207 case ' ': |
208 if (step > st_min) { | 208 if (step >= st_sec) { |
209 return NGX_ERROR; | 209 return NGX_ERROR; |
210 } | 210 } |
211 step = st_last; | 211 step = st_last; |
212 max = 2147483647; | 212 max = NGX_MAX_INT32_VALUE; |
213 scale = 1; | 213 scale = 1; |
214 break; | 214 break; |
215 | 215 |
216 default: | 216 default: |
217 return NGX_ERROR; | 217 return NGX_ERROR; |
218 } | 218 } |
219 | 219 |
220 if (step != st_msec && !sec) { | 220 if (step != st_msec && !is_sec) { |
221 scale *= 1000; | 221 scale *= 1000; |
222 max /= 1000; | 222 max /= 1000; |
223 } | 223 } |
224 | 224 |
225 if ((ngx_uint_t) value > max) { | 225 if ((ngx_uint_t) value > max) { |
226 return NGX_ERROR; | 226 return NGX_ERROR; |
227 } | 227 } |
228 | 228 |
229 total += value * scale; | 229 total += value * scale; |
230 | 230 |
231 if ((ngx_uint_t) total > 2147483647) { | 231 if ((ngx_uint_t) total > NGX_MAX_INT32_VALUE) { |
232 return NGX_ERROR; | 232 return NGX_ERROR; |
233 } | 233 } |
234 | 234 |
235 value = 0; | 235 value = 0; |
236 scale = sec ? 1 : 1000; | 236 scale = is_sec ? 1 : 1000; |
237 | 237 |
238 while (p < last && *p == ' ') { | 238 while (p < last && *p == ' ') { |
239 p++; | 239 p++; |
240 } | 240 } |
241 } | 241 } |