comparison src/core/ngx_parse.c @ 644:6f21ae02fb01 NGINX_1_1_6

nginx 1.1.6 *) Change in internal API: now module context data are cleared while internal redirect to named location. Requested by Yichun Zhang. *) Change: if a server in an upstream failed, only one request will be sent to it after fail_timeout; the server will be considered alive if it will successfully respond to the request. *) Change: now the 0x7F-0x1F characters are escaped as \xXX in an access_log. *) Feature: "proxy/fastcgi/scgi/uwsgi_ignore_headers" directives support the following additional values: X-Accel-Limit-Rate, X-Accel-Buffering, X-Accel-Charset. *) Feature: decrease of memory consumption if SSL is used. *) Bugfix: some UTF-8 characters were processed incorrectly. Thanks to Alexey Kuts. *) Bugfix: the ngx_http_rewrite_module directives specified at "server" level were executed twice if no matching locations were defined. *) Bugfix: a socket leak might occurred if "aio sendfile" was used. *) Bugfix: connections with fast clients might be closed after send_timeout if file AIO was used. *) Bugfix: in the ngx_http_autoindex_module. *) Bugfix: the module ngx_http_mp4_module did not support seeking on 32-bit platforms.
author Igor Sysoev <http://sysoev.ru>
date Mon, 17 Oct 2011 00:00:00 +0400
parents 6639b93e81b2
children d0f7a625f27c
comparison
equal deleted inserted replaced
643:a4bb0b481f6c 644:6f21ae02fb01
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 }