Mercurial > hg > nginx
comparison src/http/modules/ngx_http_index_handler.c @ 396:6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sun, 18 Jul 2004 19:11:20 +0000 |
parents | 2e3cbc1bbe3c |
children | 69e851f83522 |
comparison
equal
deleted
inserted
replaced
395:f8f0f1834266 | 396:6f3b20c1ac50 |
---|---|
96 */ | 96 */ |
97 | 97 |
98 ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) | 98 ngx_int_t ngx_http_index_handler(ngx_http_request_t *r) |
99 { | 99 { |
100 u_char *name; | 100 u_char *name; |
101 size_t len; | |
101 ngx_fd_t fd; | 102 ngx_fd_t fd; |
102 ngx_int_t rc; | 103 ngx_int_t rc; |
103 ngx_str_t *index; | 104 ngx_str_t *index; |
104 ngx_err_t err; | 105 ngx_err_t err; |
105 ngx_log_t *log; | 106 ngx_log_t *log; |
158 } | 159 } |
159 } | 160 } |
160 | 161 |
161 #endif | 162 #endif |
162 | 163 |
164 #if 0 | |
163 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len | 165 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len |
164 + ilcf->max_index_len | 166 + ilcf->max_index_len |
165 - clcf->alias * clcf->name.len); | 167 - clcf->alias * clcf->name.len); |
166 if (ctx->path.data == NULL) { | 168 if (ctx->path.data == NULL) { |
167 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 169 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
168 } | 170 } |
169 | 171 |
170 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, | 172 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, |
171 clcf->root.len); | 173 clcf->root.len); |
174 #endif | |
172 | 175 |
173 if (clcf->alias) { | 176 if (clcf->alias) { |
174 ctx->last = ngx_cpystrn(ctx->redirect.data, | 177 if (clcf->root.len > clcf->name.len) { |
178 ctx->path.data = ngx_palloc(r->pool, clcf->root.len | |
179 + r->uri.len | |
180 - clcf->name.len | |
181 + ilcf->max_index_len); | |
182 if (ctx->path.data == NULL) { | |
183 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
184 } | |
185 | |
186 ctx->redirect.data = ctx->path.data + clcf->root.len + 1 | |
187 - clcf->name.len; | |
188 | |
189 } else { | |
190 ctx->redirect.data = ngx_palloc(r->pool, r->uri.len | |
191 + ilcf->max_index_len); | |
192 if (ctx->redirect.data == NULL) { | |
193 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
194 } | |
195 | |
196 ctx->path.data = ctx->redirect.data + clcf->name.len | |
197 - clcf->root.len; | |
198 } | |
199 | |
200 ngx_memcpy(ctx->path.data, clcf->root.data, clcf->root.len); | |
201 | |
202 ctx->last = ngx_cpystrn(ctx->path.data + clcf->root.len, | |
175 r->uri.data + clcf->name.len, | 203 r->uri.data + clcf->name.len, |
176 r->uri.len + 1 - clcf->name.len); | 204 r->uri.len + 1 - clcf->name.len); |
177 | 205 |
178 /* | 206 /* |
179 * aliases usually have trailling "/", | 207 * aliases usually have trailling "/", |
183 if (*ctx->redirect.data != '/') { | 211 if (*ctx->redirect.data != '/') { |
184 ctx->redirect.data--; | 212 ctx->redirect.data--; |
185 } | 213 } |
186 | 214 |
187 } else { | 215 } else { |
216 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len | |
217 + ilcf->max_index_len); | |
218 if (ctx->path.data == NULL) { | |
219 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
220 } | |
221 | |
222 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, | |
223 clcf->root.len); | |
224 | |
188 ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data, | 225 ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data, |
189 r->uri.len + 1); | 226 r->uri.len + 1); |
190 } | 227 } |
191 } | 228 } |
192 | 229 |
253 r->file.name.len = index[ctx->index].len; | 290 r->file.name.len = index[ctx->index].len; |
254 ctx->redirect.len = index[ctx->index].len; | 291 ctx->redirect.len = index[ctx->index].len; |
255 ctx->redirect.data = index[ctx->index].data; | 292 ctx->redirect.data = index[ctx->index].data; |
256 | 293 |
257 } else { | 294 } else { |
258 ctx->redirect.len = r->uri.len + index[ctx->index].len; | 295 if (clcf->alias) { |
296 ngx_memcpy(ctx->redirect.data, clcf->name.data, clcf->name.len); | |
297 } | |
298 | |
299 ctx->redirect.len = r->uri.len + index[ctx->index].len | |
300 - clcf->alias * clcf->name.len; | |
259 r->file.name.len = clcf->root.len + r->uri.len | 301 r->file.name.len = clcf->root.len + r->uri.len |
302 - clcf->alias * clcf->name.len | |
260 + index[ctx->index].len; | 303 + index[ctx->index].len; |
261 } | 304 } |
262 | 305 |
263 /**/ | 306 /**/ |
264 | 307 |
362 | 405 |
363 | 406 |
364 static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle) | 407 static ngx_int_t ngx_http_index_init(ngx_cycle_t *cycle) |
365 { | 408 { |
366 ngx_http_handler_pt *h; | 409 ngx_http_handler_pt *h; |
367 ngx_http_conf_ctx_t *ctx; | |
368 ngx_http_core_main_conf_t *cmcf; | 410 ngx_http_core_main_conf_t *cmcf; |
369 | 411 |
370 ctx = (ngx_http_conf_ctx_t *) cycle->conf_ctx[ngx_http_module.index]; | 412 cmcf = ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module); |
371 cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; | |
372 | 413 |
373 h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); | 414 h = ngx_push_array(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); |
374 if (h == NULL) { | 415 if (h == NULL) { |
375 return NGX_ERROR; | 416 return NGX_ERROR; |
376 } | 417 } |