Mercurial > hg > nginx
comparison src/http/modules/ngx_http_index_handler.c @ 41:59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 26 Dec 2002 16:26:23 +0000 |
parents | d45effe5854c |
children | cd035a94e0b6 |
comparison
equal
deleted
inserted
replaced
40:d5d4f3bba6f0 | 41:59e7c7f30d49 |
---|---|
11 | 11 |
12 | 12 |
13 static void *ngx_http_index_create_conf(ngx_pool_t *pool); | 13 static void *ngx_http_index_create_conf(ngx_pool_t *pool); |
14 static void *ngx_http_index_merge_conf(ngx_pool_t *p, | 14 static void *ngx_http_index_merge_conf(ngx_pool_t *p, |
15 void *parent, void *child); | 15 void *parent, void *child); |
16 static char *ngx_http_index_set_index(ngx_pool_t *p, void *conf, | 16 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, |
17 ngx_str_t *value); | 17 char *conf); |
18 | 18 |
19 | 19 |
20 static ngx_command_t ngx_http_index_commands[] = { | 20 static ngx_command_t ngx_http_index_commands[] = { |
21 | 21 |
22 {"index", ngx_http_index_set_index, 0, | 22 {ngx_string("index"), |
23 NGX_HTTP_LOC_CONF, NGX_CONF_ITERATE, | 23 NGX_CONF_ANY, |
24 "set index files"}, | 24 ngx_http_index_set_index, |
25 NGX_HTTP_LOC_CONF, | |
26 0}, | |
25 | 27 |
26 {NULL} | 28 {ngx_string(""), 0, NULL, 0, 0} |
29 }; | |
30 | |
31 | |
32 ngx_http_module_t ngx_http_index_module_ctx = { | |
33 NGX_HTTP_MODULE, | |
34 | |
35 NULL, /* create server config */ | |
36 ngx_http_index_create_conf, /* create location config */ | |
37 | |
38 NULL, /* translate handler */ | |
39 | |
40 NULL, /* output header filter */ | |
41 NULL, /* next output header filter */ | |
42 NULL, /* output body filter */ | |
43 NULL, /* next output body filter */ | |
27 | 44 |
28 }; | 45 }; |
29 | 46 |
30 | 47 |
31 ngx_http_module_t ngx_http_index_module = { | 48 ngx_module_t ngx_http_index_module = { |
32 NGX_HTTP_MODULE, | 49 &ngx_http_index_module_ctx, /* module context */ |
33 | |
34 NULL, /* create server config */ | |
35 ngx_http_index_create_conf, /* create location config */ | |
36 ngx_http_index_commands, /* module directives */ | 50 ngx_http_index_commands, /* module directives */ |
37 | 51 NGX_HTTP_MODULE_TYPE, /* module type */ |
38 NULL, /* init module */ | 52 NULL /* init module */ |
39 NULL, /* translate handler */ | |
40 | |
41 NULL, /* init output body filter */ | |
42 }; | 53 }; |
43 | 54 |
44 | 55 |
45 int ngx_http_index_handler(ngx_http_request_t *r) | 56 int ngx_http_index_handler(ngx_http_request_t *r) |
46 { | 57 { |
51 ngx_fd_t fd; | 62 ngx_fd_t fd; |
52 | 63 |
53 ngx_http_index_conf_t *cf; | 64 ngx_http_index_conf_t *cf; |
54 | 65 |
55 cf = (ngx_http_index_conf_t *) | 66 cf = (ngx_http_index_conf_t *) |
56 ngx_get_module_loc_conf(r, ngx_http_index_module); | 67 ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx); |
57 | 68 |
58 ngx_test_null(name, | 69 ngx_test_null(name, |
59 ngx_palloc(r->pool, | 70 ngx_palloc(r->pool, |
60 r->server->doc_root_len + r->uri.len | 71 r->server->doc_root_len + r->uri.len |
61 + cf->max_index_len), | 72 + cf->max_index_len), |
69 ngx_memcpy(file, index[i].data, index[i].len + 1); | 80 ngx_memcpy(file, index[i].data, index[i].len + 1); |
70 | 81 |
71 fd = ngx_open_file(name, NGX_FILE_RDONLY); | 82 fd = ngx_open_file(name, NGX_FILE_RDONLY); |
72 if (fd == NGX_INVALID_FILE) { | 83 if (fd == NGX_INVALID_FILE) { |
73 err = ngx_errno; | 84 err = ngx_errno; |
74 if (err == NGX_ENOENT) | 85 if (err == NGX_ENOENT) { |
75 continue; | 86 continue; |
87 } | |
76 #if (WIN32) | 88 #if (WIN32) |
77 if (err == ERROR_PATH_NOT_FOUND) | 89 if (err == ERROR_PATH_NOT_FOUND) { |
78 continue; | 90 continue; |
91 } | |
79 #endif | 92 #endif |
80 | 93 |
81 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, | 94 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
82 ngx_open_file_n " %s failed", name); | 95 ngx_open_file_n " %s failed", name); |
83 | 96 |
115 ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent; | 128 ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent; |
116 ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child; | 129 ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child; |
117 ngx_str_t *index; | 130 ngx_str_t *index; |
118 | 131 |
119 if (conf->max_index_len == 0) { | 132 if (conf->max_index_len == 0) { |
120 if (prev->max_index_len != 0) | 133 if (prev->max_index_len != 0) { |
121 return prev; | 134 return prev; |
135 } | |
122 | 136 |
123 ngx_test_null(index, ngx_push_array(conf->indices), NULL); | 137 ngx_test_null(index, ngx_push_array(conf->indices), NULL); |
124 index->len = sizeof(NGX_HTTP_INDEX) - 1; | 138 index->len = sizeof(NGX_HTTP_INDEX) - 1; |
125 index->data = NGX_HTTP_INDEX; | 139 index->data = NGX_HTTP_INDEX; |
126 conf->max_index_len = sizeof(NGX_HTTP_INDEX); | 140 conf->max_index_len = sizeof(NGX_HTTP_INDEX); |
128 | 142 |
129 return conf; | 143 return conf; |
130 } | 144 } |
131 | 145 |
132 | 146 |
133 static char *ngx_http_index_set_index(ngx_pool_t *p, void *conf, | 147 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, |
134 ngx_str_t *value) | 148 char *conf) |
135 { | 149 { |
136 ngx_http_index_conf_t *cf = (ngx_http_index_conf_t *) conf; | 150 ngx_http_index_conf_t *icf = (ngx_http_index_conf_t *) conf; |
137 ngx_str_t *index; | 151 int i; |
152 ngx_str_t *index, *value; | |
138 | 153 |
139 ngx_test_null(index, ngx_push_array(cf->indices), NULL); | 154 value = (ngx_str_t *) cf->args->elts; |
140 index->len = value->len; | 155 for (i = 1; i < cf->args->nelts; i++) { |
141 index->data = value->data; | 156 ngx_test_null(index, ngx_push_array(icf->indices), NULL); |
157 index->len = value[i].len; | |
158 index->data = value[i].data; | |
142 | 159 |
143 if (cf->max_index_len < index->len) | 160 if (icf->max_index_len < index->len) { |
144 cf->max_index_len = index->len; | 161 icf->max_index_len = index->len; |
162 } | |
163 } | |
145 | 164 |
146 return NULL; | 165 return NULL; |
147 } | 166 } |