Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_index_module.c @ 451:670af56a1158 NGINX_0_7_33
nginx 0.7.33
*) Bugfix: a double response might be returned if the epoll or rtsig
methods are used and a redirect was returned to a request with
body.
Thanks to Eden Li.
*) Bugfix: the $sent_http_location variable was empty for some
redirects types.
*) Bugfix: a segmentation fault might occur in worker process if
"resolver" directive was used in SMTP proxy.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 02 Feb 2009 00:00:00 +0300 |
parents | dac47e9ef0d5 |
children | bb941a2996a6 |
comparison
equal
deleted
inserted
replaced
450:52bbf0e6dfad | 451:670af56a1158 |
---|---|
94 | 94 |
95 static ngx_int_t | 95 static ngx_int_t |
96 ngx_http_index_handler(ngx_http_request_t *r) | 96 ngx_http_index_handler(ngx_http_request_t *r) |
97 { | 97 { |
98 u_char *p, *name; | 98 u_char *p, *name; |
99 size_t len, nlen, root, allocated; | 99 size_t len, root, reserve, allocated; |
100 ngx_int_t rc; | 100 ngx_int_t rc; |
101 ngx_str_t path, uri; | 101 ngx_str_t path, uri; |
102 ngx_uint_t i, dir_tested; | 102 ngx_uint_t i, dir_tested; |
103 ngx_http_index_t *index; | 103 ngx_http_index_t *index; |
104 ngx_open_file_info_t of; | 104 ngx_open_file_info_t of; |
126 | 126 |
127 allocated = 0; | 127 allocated = 0; |
128 root = 0; | 128 root = 0; |
129 dir_tested = 0; | 129 dir_tested = 0; |
130 name = NULL; | 130 name = NULL; |
131 /* suppress MSVC warning */ | |
131 path.data = NULL; | 132 path.data = NULL; |
132 | 133 |
133 index = ilcf->indices->elts; | 134 index = ilcf->indices->elts; |
134 for (i = 0; i < ilcf->indices->nelts; i++) { | 135 for (i = 0; i < ilcf->indices->nelts; i++) { |
135 | 136 |
137 | 138 |
138 if (index[i].name.data[0] == '/') { | 139 if (index[i].name.data[0] == '/') { |
139 return ngx_http_internal_redirect(r, &index[i].name, &r->args); | 140 return ngx_http_internal_redirect(r, &index[i].name, &r->args); |
140 } | 141 } |
141 | 142 |
142 len = ilcf->max_index_len; | 143 reserve = ilcf->max_index_len; |
143 nlen = index[i].name.len; | 144 len = index[i].name.len; |
144 | 145 |
145 } else { | 146 } else { |
146 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 147 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
147 | 148 |
148 e.ip = index[i].lengths->elts; | 149 e.ip = index[i].lengths->elts; |
149 e.request = r; | 150 e.request = r; |
150 e.flushed = 1; | 151 e.flushed = 1; |
151 | 152 |
152 /* 1 byte for terminating '\0' */ | 153 /* 1 is for terminating '\0' as in static names */ |
153 | |
154 len = 1; | 154 len = 1; |
155 | 155 |
156 while (*(uintptr_t *) e.ip) { | 156 while (*(uintptr_t *) e.ip) { |
157 lcode = *(ngx_http_script_len_code_pt *) e.ip; | 157 lcode = *(ngx_http_script_len_code_pt *) e.ip; |
158 len += lcode(&e); | 158 len += lcode(&e); |
159 } | 159 } |
160 | 160 |
161 nlen = len; | |
162 | |
163 /* 16 bytes are preallocation */ | 161 /* 16 bytes are preallocation */ |
164 | 162 |
165 len += 16; | 163 reserve = len + 16; |
166 } | 164 } |
167 | 165 |
168 if (len > (size_t) (path.data + allocated - name)) { | 166 if (reserve > allocated) { |
169 | 167 |
170 name = ngx_http_map_uri_to_path(r, &path, &root, len); | 168 name = ngx_http_map_uri_to_path(r, &path, &root, reserve); |
171 if (name == NULL) { | 169 if (name == NULL) { |
172 return NGX_ERROR; | 170 return NGX_ERROR; |
173 } | 171 } |
174 | 172 |
175 allocated = path.len; | 173 allocated = path.data + path.len - name; |
176 } | 174 } |
177 | 175 |
178 if (index[i].values == NULL) { | 176 if (index[i].values == NULL) { |
179 | 177 |
180 /* index[i].name.len includes the terminating '\0' */ | 178 /* index[i].name.len includes the terminating '\0' */ |
191 code = *(ngx_http_script_code_pt *) e.ip; | 189 code = *(ngx_http_script_code_pt *) e.ip; |
192 code((ngx_http_script_engine_t *) &e); | 190 code((ngx_http_script_engine_t *) &e); |
193 } | 191 } |
194 | 192 |
195 if (*name == '/') { | 193 if (*name == '/') { |
196 uri.len = nlen - 1; | 194 uri.len = len - 1; |
197 uri.data = name; | 195 uri.data = name; |
198 return ngx_http_internal_redirect(r, &uri, &r->args); | 196 return ngx_http_internal_redirect(r, &uri, &r->args); |
199 } | 197 } |
200 | 198 |
201 path.len = e.pos - path.data; | 199 path.len = e.pos - path.data; |
246 ngx_open_file_n " \"%s\" failed", path.data); | 244 ngx_open_file_n " \"%s\" failed", path.data); |
247 | 245 |
248 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 246 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
249 } | 247 } |
250 | 248 |
251 uri.len = r->uri.len + nlen - 1; | 249 uri.len = r->uri.len + len - 1; |
252 | 250 |
253 if (!clcf->alias) { | 251 if (!clcf->alias) { |
254 uri.data = path.data + root; | 252 uri.data = path.data + root; |
255 | 253 |
256 } else { | 254 } else { |
258 if (uri.data == NULL) { | 256 if (uri.data == NULL) { |
259 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 257 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
260 } | 258 } |
261 | 259 |
262 p = ngx_copy(uri.data, r->uri.data, r->uri.len); | 260 p = ngx_copy(uri.data, r->uri.data, r->uri.len); |
263 ngx_memcpy(p, name, nlen - 1); | 261 ngx_memcpy(p, name, len - 1); |
264 } | 262 } |
265 | 263 |
266 return ngx_http_internal_redirect(r, &uri, &r->args); | 264 return ngx_http_internal_redirect(r, &uri, &r->args); |
267 } | 265 } |
268 | 266 |
489 | 487 |
490 if (index->name.data[0] == '/') { | 488 if (index->name.data[0] == '/') { |
491 continue; | 489 continue; |
492 } | 490 } |
493 | 491 |
494 /* include the terminating '\0' to the length to use ngx_copy() */ | 492 /* include the terminating '\0' to the length to use ngx_memcpy() */ |
495 index->name.len++; | 493 index->name.len++; |
496 | 494 |
497 continue; | 495 continue; |
498 } | 496 } |
499 | 497 |