comparison src/http/modules/ngx_http_index_handler.c @ 97:70d2345a903f

nginx-0.0.1-2003-05-29-17:02:09 import
author Igor Sysoev <igor@sysoev.ru>
date Thu, 29 May 2003 13:02:09 +0000
parents a23d010f356d
children c9b243802a17
comparison
equal deleted inserted replaced
96:a23d010f356d 97:70d2345a903f
57 57
58 int ngx_http_index_handler(ngx_http_request_t *r) 58 int ngx_http_index_handler(ngx_http_request_t *r)
59 { 59 {
60 int i, rc, test_dir; 60 int i, rc, test_dir;
61 char *name, *file; 61 char *name, *file;
62 ngx_str_t loc, *index; 62 ngx_str_t redirect, *index;
63 ngx_err_t err; 63 ngx_err_t err;
64 ngx_fd_t fd; 64 ngx_fd_t fd;
65 ngx_http_index_conf_t *icf; 65 ngx_http_index_conf_t *icf;
66 ngx_http_core_loc_conf_t *clcf; 66 ngx_http_core_loc_conf_t *clcf;
67 67
72 ngx_palloc(r->pool, 72 ngx_palloc(r->pool,
73 clcf->doc_root.len + r->uri.len 73 clcf->doc_root.len + r->uri.len
74 + icf->max_index_len), 74 + icf->max_index_len),
75 NGX_HTTP_INTERNAL_SERVER_ERROR); 75 NGX_HTTP_INTERNAL_SERVER_ERROR);
76 76
77 loc.data = ngx_cpystrn(r->path.data, clcf->doc_root.data, 77 redirect.data = ngx_cpymem(r->path.data, clcf->doc_root.data,
78 clcf->doc_root.len + 1); 78 clcf->doc_root.len);
79 file = ngx_cpystrn(loc.data, r->uri.data, r->uri.len + 1); 79 file = ngx_cpystrn(redirect.data, r->uri.data, r->uri.len + 1);
80 r->path.len = file - r->path.data; 80 r->path.len = file - r->path.data;
81 81
82 test_dir = 1; 82 test_dir = 1;
83 83
84 index = (ngx_str_t *) icf->indices.elts; 84 index = icf->indices.elts;
85 for (i = 0; i < icf->indices.nelts; i++) { 85 for (i = 0; i < icf->indices.nelts; i++) {
86 86
87 if (index[i].data[0] != '/') { 87 if (index[i].data[0] != '/') {
88 ngx_memcpy(file, index[i].data, index[i].len + 1); 88 ngx_memcpy(file, index[i].data, index[i].len + 1);
89 name = r->path.data; 89 name = r->path.data;
134 r->file.name.data = name; 134 r->file.name.data = name;
135 r->file.fd = fd; 135 r->file.fd = fd;
136 136
137 if (index[i].data[0] == '/') { 137 if (index[i].data[0] == '/') {
138 r->file.name.len = index[i].len; 138 r->file.name.len = index[i].len;
139 loc.len = index[i].len; 139 redirect.len = index[i].len;
140 loc.data = index[i].data; 140 redirect.data = index[i].data;
141 141
142 } else { 142 } else {
143 loc.len = r->uri.len + index[i].len; 143 redirect.len = r->uri.len + index[i].len;
144 r->file.name.len = clcf->doc_root.len + r->uri.len 144 r->file.name.len = clcf->doc_root.len + r->uri.len + index[i].len;
145 + index[i].len; 145 }
146 } 146
147 147 return ngx_http_internal_redirect(r, &redirect, NULL);
148 /* STUB */ r->exten.len = 4; r->exten.data = "html";
149
150 return ngx_http_internal_redirect(r, loc);
151 } 148 }
152 149
153 return NGX_DECLINED; 150 return NGX_DECLINED;
154 } 151 }
155 152
175 r->path.data[r->path.len - 1] = '/'; 172 r->path.data[r->path.len - 1] = '/';
176 return NGX_HTTP_NOT_FOUND; 173 return NGX_HTTP_NOT_FOUND;
177 } 174 }
178 175
179 ngx_log_error(NGX_LOG_CRIT, r->connection->log, r->path_err, 176 ngx_log_error(NGX_LOG_CRIT, r->connection->log, r->path_err,
180 "ngx_http_index_test_dir: "
181 ngx_file_type_n " %s failed", r->path.data); 177 ngx_file_type_n " %s failed", r->path.data);
182 178
183 return NGX_HTTP_INTERNAL_SERVER_ERROR; 179 return NGX_HTTP_INTERNAL_SERVER_ERROR;
184 } 180 }
185 181
261 257
262 return NGX_CONF_OK; 258 return NGX_CONF_OK;
263 } 259 }
264 260
265 261
266 /* TODO: check duplicate indices */ 262 /* TODO: warn about duplicate indices */
267 263
268 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, 264 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
269 void *conf) 265 void *conf)
270 { 266 {
271 ngx_http_index_conf_t *icf = conf; 267 ngx_http_index_conf_t *icf = conf;
281 return ngx_conf_errstr; 277 return ngx_conf_errstr;
282 } 278 }
283 279
284 for (i = 1; i < cf->args->nelts; i++) { 280 for (i = 1; i < cf->args->nelts; i++) {
285 if (value[i].len == 0) { 281 if (value[i].len == 0) {
286 return "is invalid"; 282 ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1,
283 "index \"%s\" is invalid", value[1].data);
284 return ngx_conf_errstr;
287 } 285 }
288 286
289 ngx_test_null(index, ngx_push_array(&icf->indices), NGX_CONF_ERROR); 287 ngx_test_null(index, ngx_push_array(&icf->indices), NGX_CONF_ERROR);
290 index->len = value[i].len; 288 index->len = value[i].len;
291 index->data = value[i].data; 289 index->data = value[i].data;
293 if (icf->max_index_len < index->len + 1) { 291 if (icf->max_index_len < index->len + 1) {
294 icf->max_index_len = index->len + 1; 292 icf->max_index_len = index->len + 1;
295 } 293 }
296 } 294 }
297 295
298 return NULL; 296 return NGX_CONF_OK;
299 } 297 }