Mercurial > hg > nginx
comparison src/http/modules/ngx_http_index_handler.c @ 44:0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 09 Jan 2003 05:36:00 +0000 |
parents | 53cd05892261 |
children | f1ee46c036a4 |
comparison
equal
deleted
inserted
replaced
43:53cd05892261 | 44:0e81ac0bb3e2 |
---|---|
7 #include <ngx_files.h> | 7 #include <ngx_files.h> |
8 #include <ngx_conf_file.h> | 8 #include <ngx_conf_file.h> |
9 | 9 |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 #include <ngx_http_config.h> | 11 #include <ngx_http_config.h> |
12 #include <ngx_http_core_module.h> | |
12 #include <ngx_http_index_handler.h> | 13 #include <ngx_http_index_handler.h> |
13 | 14 |
14 | 15 |
15 static void *ngx_http_index_create_conf(ngx_pool_t *pool); | 16 static void *ngx_http_index_create_conf(ngx_pool_t *pool); |
16 static void *ngx_http_index_merge_conf(ngx_pool_t *p, | 17 static char *ngx_http_index_merge_conf(ngx_pool_t *p, |
17 void *parent, void *child); | 18 void *parent, void *child); |
18 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, | 19 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, |
19 char *conf); | 20 char *conf); |
20 | 21 |
21 | 22 |
48 | 49 |
49 }; | 50 }; |
50 | 51 |
51 | 52 |
52 ngx_module_t ngx_http_index_module = { | 53 ngx_module_t ngx_http_index_module = { |
54 0, /* module index */ | |
53 &ngx_http_index_module_ctx, /* module context */ | 55 &ngx_http_index_module_ctx, /* module context */ |
54 ngx_http_index_commands, /* module directives */ | 56 ngx_http_index_commands, /* module directives */ |
55 NGX_HTTP_MODULE_TYPE, /* module type */ | 57 NGX_HTTP_MODULE_TYPE, /* module type */ |
56 NULL /* init module */ | 58 NULL /* init module */ |
57 }; | 59 }; |
63 char *name, *file; | 65 char *name, *file; |
64 ngx_str_t loc, *index; | 66 ngx_str_t loc, *index; |
65 ngx_err_t err; | 67 ngx_err_t err; |
66 ngx_fd_t fd; | 68 ngx_fd_t fd; |
67 | 69 |
68 ngx_http_index_conf_t *cf; | 70 ngx_http_index_conf_t *cf; |
71 ngx_http_core_loc_conf_t *core_cf; | |
69 | 72 |
70 cf = (ngx_http_index_conf_t *) | 73 cf = (ngx_http_index_conf_t *) |
71 ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx); | 74 ngx_http_get_module_loc_conf(r, ngx_http_index_module_ctx); |
72 | 75 |
76 core_cf = (ngx_http_core_loc_conf_t *) | |
77 ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx); | |
78 | |
73 ngx_test_null(name, | 79 ngx_test_null(name, |
74 ngx_palloc(r->pool, | 80 ngx_palloc(r->pool, |
75 r->server->doc_root_len + r->uri.len | 81 core_cf->doc_root.len + r->uri.len |
76 + cf->max_index_len), | 82 + cf->max_index_len), |
77 NGX_HTTP_INTERNAL_SERVER_ERROR); | 83 NGX_HTTP_INTERNAL_SERVER_ERROR); |
78 | 84 |
79 loc.data = ngx_cpystrn(name, r->server->doc_root, r->server->doc_root_len); | 85 loc.data = ngx_cpystrn(name, core_cf->doc_root.data, |
86 core_cf->doc_root.len + 1); | |
80 file = ngx_cpystrn(loc.data, r->uri.data, r->uri.len + 1); | 87 file = ngx_cpystrn(loc.data, r->uri.data, r->uri.len + 1); |
81 | 88 |
82 index = (ngx_str_t *) cf->indices->elts; | 89 index = (ngx_str_t *) cf->indices->elts; |
83 for (i = 0; i < cf->indices->nelts; i++) { | 90 for (i = 0; i < cf->indices->nelts; i++) { |
84 ngx_memcpy(file, index[i].data, index[i].len + 1); | 91 ngx_memcpy(file, index[i].data, index[i].len + 1); |
99 ngx_open_file_n " %s failed", name); | 106 ngx_open_file_n " %s failed", name); |
100 | 107 |
101 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 108 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
102 } | 109 } |
103 | 110 |
104 r->file.name.len = r->server->doc_root_len + r->uri.len + index[i].len; | 111 r->file.name.len = core_cf->doc_root.len + r->uri.len + index[i].len; |
105 r->file.name.data = name; | 112 r->file.name.data = name; |
106 r->file.fd = fd; | 113 r->file.fd = fd; |
107 | 114 |
108 loc.len = r->uri.len + index[i].len; | 115 loc.len = r->uri.len + index[i].len; |
109 return ngx_http_internal_redirect(r, loc); | 116 return ngx_http_internal_redirect(r, loc); |
115 | 122 |
116 static void *ngx_http_index_create_conf(ngx_pool_t *pool) | 123 static void *ngx_http_index_create_conf(ngx_pool_t *pool) |
117 { | 124 { |
118 ngx_http_index_conf_t *conf; | 125 ngx_http_index_conf_t *conf; |
119 | 126 |
120 ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)), NULL); | 127 ngx_test_null(conf, ngx_pcalloc(pool, sizeof(ngx_http_index_conf_t)), |
128 NGX_CONF_ERROR); | |
121 | 129 |
122 ngx_test_null(conf->indices, | 130 ngx_test_null(conf->indices, |
123 ngx_create_array(pool, sizeof(ngx_str_t), 3), | 131 ngx_create_array(pool, sizeof(ngx_str_t), 3), |
124 NULL); | 132 NGX_CONF_ERROR); |
125 | 133 |
126 return conf; | 134 return conf; |
127 } | 135 } |
128 | 136 |
129 | 137 |
130 static void *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child) | 138 static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child) |
139 { | |
140 ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent; | |
141 ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child; | |
142 ngx_str_t *index; | |
143 | |
144 ngx_test_null(index, ngx_push_array(conf->indices), NGX_CONF_ERROR); | |
145 index->len = sizeof(NGX_HTTP_INDEX) - 1; | |
146 index->data = NGX_HTTP_INDEX; | |
147 conf->max_index_len = sizeof(NGX_HTTP_INDEX); | |
148 | |
149 return NULL; | |
150 } | |
151 | |
152 | |
153 #if 0 | |
154 static char *ngx_http_index_merge_conf(ngx_pool_t *p, void *parent, void *child) | |
131 { | 155 { |
132 ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent; | 156 ngx_http_index_conf_t *prev = (ngx_http_index_conf_t *) parent; |
133 ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child; | 157 ngx_http_index_conf_t *conf = (ngx_http_index_conf_t *) child; |
134 ngx_str_t *index; | 158 ngx_str_t *index; |
135 | 159 |
144 conf->max_index_len = sizeof(NGX_HTTP_INDEX); | 168 conf->max_index_len = sizeof(NGX_HTTP_INDEX); |
145 } | 169 } |
146 | 170 |
147 return conf; | 171 return conf; |
148 } | 172 } |
149 | 173 #endif |
150 | 174 |
151 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, | 175 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, |
152 char *conf) | 176 char *conf) |
153 { | 177 { |
154 ngx_http_index_conf_t *icf = (ngx_http_index_conf_t *) conf; | 178 ngx_http_index_conf_t *icf = (ngx_http_index_conf_t *) conf; |