Mercurial > hg > nginx
comparison src/http/modules/ngx_http_index_handler.c @ 293:ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 19 Mar 2004 05:25:53 +0000 |
parents | a472bfb778b3 |
children | 2e3cbc1bbe3c |
comparison
equal
deleted
inserted
replaced
292:a472bfb778b3 | 293:ec3c049681fd |
---|---|
19 ngx_http_cache_t *cache; | 19 ngx_http_cache_t *cache; |
20 unsigned tested:1; | 20 unsigned tested:1; |
21 } ngx_http_index_ctx_t; | 21 } ngx_http_index_ctx_t; |
22 | 22 |
23 | 23 |
24 #define NGX_HTTP_DEFAULT_INDEX (u_char *) "index.html" | 24 #define NGX_HTTP_DEFAULT_INDEX "index.html" |
25 | 25 |
26 | 26 |
27 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, | 27 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, |
28 ngx_http_index_ctx_t *ctx); | 28 ngx_http_index_ctx_t *ctx); |
29 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, | 29 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, |
96 */ | 96 */ |
97 | 97 |
98 int ngx_http_index_handler(ngx_http_request_t *r) | 98 int ngx_http_index_handler(ngx_http_request_t *r) |
99 { | 99 { |
100 u_char *name; | 100 u_char *name; |
101 size_t len; | |
102 ngx_fd_t fd; | 101 ngx_fd_t fd; |
103 ngx_int_t rc; | 102 ngx_int_t rc; |
104 ngx_str_t *index; | 103 ngx_str_t *index; |
105 ngx_err_t err; | 104 ngx_err_t err; |
106 ngx_log_t *log; | 105 ngx_log_t *log; |
159 } | 158 } |
160 } | 159 } |
161 | 160 |
162 #endif | 161 #endif |
163 | 162 |
164 len = clcf->root.len + r->uri.len + ilcf->max_index_len; | 163 ctx->path.data = ngx_palloc(r->pool, clcf->root.len + r->uri.len |
165 if (!(ctx->path.data = ngx_palloc(r->pool, len))) { | 164 + ilcf->max_index_len |
165 - clcf->alias * clcf->name.len); | |
166 if (ctx->path.data == NULL) { | |
166 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 167 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
167 } | 168 } |
168 | 169 |
169 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, | 170 ctx->redirect.data = ngx_cpymem(ctx->path.data, clcf->root.data, |
170 clcf->root.len); | 171 clcf->root.len); |
171 ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data, | 172 |
172 r->uri.len + 1); | 173 if (clcf->alias) { |
173 ctx->path.len = ctx->last - ctx->path.data; | 174 ctx->last = ngx_cpystrn(ctx->redirect.data, |
174 } | 175 r->uri.data + clcf->name.len, |
176 r->uri.len + 1 - clcf->name.len); | |
177 | |
178 /* | |
179 * aliases usually have trailling "/", | |
180 * set it in the start of the possible redirect | |
181 */ | |
182 | |
183 if (*ctx->redirect.data != '/') { | |
184 ctx->redirect.data--; | |
185 } | |
186 | |
187 } else { | |
188 ctx->last = ngx_cpystrn(ctx->redirect.data, r->uri.data, | |
189 r->uri.len + 1); | |
190 } | |
191 } | |
192 | |
193 ctx->path.len = ctx->last - ctx->path.data; | |
175 | 194 |
176 index = ilcf->indices.elts; | 195 index = ilcf->indices.elts; |
177 for (/* void */; ctx->index < ilcf->indices.nelts; ctx->index++) { | 196 for (/* void */; ctx->index < ilcf->indices.nelts; ctx->index++) { |
178 | 197 |
179 if (index[ctx->index].data[0] == '/') { | 198 if (index[ctx->index].data[0] == '/') { |
396 return NGX_CONF_OK; | 415 return NGX_CONF_OK; |
397 } | 416 } |
398 | 417 |
399 ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR); | 418 ngx_test_null(index, ngx_push_array(&conf->indices), NGX_CONF_ERROR); |
400 index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1; | 419 index->len = sizeof(NGX_HTTP_DEFAULT_INDEX) - 1; |
401 index->data = NGX_HTTP_DEFAULT_INDEX; | 420 index->data = (u_char *) NGX_HTTP_DEFAULT_INDEX; |
402 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); | 421 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); |
403 | 422 |
404 return NGX_CONF_OK; | 423 return NGX_CONF_OK; |
405 } | 424 } |
406 | 425 |