annotate src/http/modules/ngx_http_index_module.c @ 252:644510700914 NGINX_0_4_11

nginx 0.4.11 *) Feature: the POP3 proxy supports the AUTH LOGIN PLAIN and CRAM-MD5. *) Feature: the ngx_http_perl_module supports the $r->allow_ranges method. *) Bugfix: if the APOP was enabled in the POP3 proxy, then the USER/PASS commands might not work; bug appeared in 0.4.10.
author Igor Sysoev <http://sysoev.ru>
date Wed, 25 Oct 2006 00:00:00 +0400
parents acd2ec3541cb
children 29a6403156b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 typedef struct {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
13 ngx_str_t name;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
14 ngx_array_t *lengths;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
15 ngx_array_t *values;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
16 } ngx_http_index_t;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
17
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
18
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
19 typedef struct {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
20 ngx_array_t *indices; /* array of ngx_http_index_t */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 size_t max_index_len;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 } ngx_http_index_loc_conf_t;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 typedef struct {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
26 ngx_uint_t current;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
27
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
28 ngx_str_t path;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
29 ngx_str_t index;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
30
248
acd2ec3541cb nginx 0.4.9
Igor Sysoev <http://sysoev.ru>
parents: 234
diff changeset
31 size_t root;
acd2ec3541cb nginx 0.4.9
Igor Sysoev <http://sysoev.ru>
parents: 234
diff changeset
32
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
33 ngx_uint_t tested; /* unsigned tested:1 */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 } ngx_http_index_ctx_t;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 #define NGX_HTTP_DEFAULT_INDEX "index.html"
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r,
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
41 ngx_http_index_ctx_t *ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r,
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
43 ngx_http_index_ctx_t *ctx, ngx_err_t err);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
45 static ngx_int_t ngx_http_index_init(ngx_conf_t *cf);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 static void *ngx_http_index_create_loc_conf(ngx_conf_t *cf);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf,
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
48 void *parent, void *child);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd,
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
50 void *conf);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53 static ngx_command_t ngx_http_index_commands[] = {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 { ngx_string("index"),
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
56 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 ngx_http_index_set_index,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59 0,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 #if (NGX_HTTP_CACHE)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 { ngx_string("index_cache"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE3,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 ngx_http_set_cache_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 offsetof(ngx_http_index_loc_conf_t, index_cache),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 #endif
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 ngx_null_command
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76
216
fa32d59d9a15 nginx 0.3.55
Igor Sysoev <http://sysoev.ru>
parents: 210
diff changeset
77 static ngx_http_module_t ngx_http_index_module_ctx = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
78 NULL, /* preconfiguration */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
79 ngx_http_index_init, /* postconfiguration */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 NULL, /* create main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 NULL, /* init main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 NULL, /* create server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 NULL, /* merge server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 ngx_http_index_create_loc_conf, /* create location configration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 ngx_http_index_merge_loc_conf /* merge location configration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 ngx_module_t ngx_http_index_module = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
93 NGX_MODULE_V1,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94 &ngx_http_index_module_ctx, /* module context */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 ngx_http_index_commands, /* module directives */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 NGX_HTTP_MODULE, /* module type */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
97 NULL, /* init master */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
98 NULL, /* init module */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
99 NULL, /* init process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
100 NULL, /* init thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
101 NULL, /* exit thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
102 NULL, /* exit process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
103 NULL, /* exit master */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
104 NGX_MODULE_V1_PADDING
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 * Try to open the first index file before the test of the directory existence
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 * because the valid requests should be many more than invalid ones.
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 * If open() would fail, then stat() should be more quickly because some data
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 * is already cached in the kernel.
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 * Besides, Win32 has ERROR_PATH_NOT_FOUND (NGX_ENOTDIR).
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114 * Unix has ENOTDIR error, although it less helpfull - it points only
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 * that path contains the usual file in place of the directory.
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
118 static ngx_int_t
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
119 ngx_http_index_handler(ngx_http_request_t *r)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 {
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
121 u_char *last;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
122 size_t len;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
123 ngx_fd_t fd;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
124 ngx_int_t rc;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
125 ngx_err_t err;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
126 ngx_str_t uri;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
127 ngx_log_t *log;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
128 ngx_uint_t i;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
129 ngx_http_index_t *index;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
130 ngx_http_index_ctx_t *ctx;
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
131 ngx_pool_cleanup_t *cln;
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
132 ngx_pool_cleanup_file_t *clnf;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
133 ngx_http_script_code_pt code;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
134 ngx_http_script_engine_t e;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
135 ngx_http_core_loc_conf_t *clcf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
136 ngx_http_index_loc_conf_t *ilcf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
137 ngx_http_script_len_code_pt lcode;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 if (r->uri.data[r->uri.len - 1] != '/') {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 return NGX_DECLINED;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 /* TODO: Win32 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 if (r->zero_in_uri) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 return NGX_DECLINED;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 log = r->connection->log;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 /*
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
151 * we use context because the handler supports an async file opening,
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
152 * and may be called several times
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 ilcf = ngx_http_get_module_loc_conf(r, ngx_http_index_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 ctx = ngx_http_get_module_ctx(r, ngx_http_index_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 if (ctx == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_index_ctx_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 if (ctx == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 return NGX_HTTP_INTERNAL_SERVER_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 ngx_http_set_ctx(r, ctx, ngx_http_index_module);
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
166 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
168 index = ilcf->indices->elts;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
169 for (i = ctx->current; i < ilcf->indices->nelts; i++) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
170
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
171 if (index[i].lengths == NULL) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
173 if (index[i].name.data[0] == '/') {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
174 return ngx_http_internal_redirect(r, &index[i].name, &r->args);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
175 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
177 len = ilcf->max_index_len;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
178 ctx->index.len = index[i].name.len;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
180 } else {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
181 ngx_memzero(&e, sizeof(ngx_http_script_engine_t));
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
183 e.ip = index[i].lengths->elts;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
184 e.request = r;
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 112
diff changeset
185 e.flushed = 1;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
186
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
187 /* 1 byte for terminating '\0' */
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
188
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
189 len = 1;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
191 while (*(uintptr_t *) e.ip) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
192 lcode = *(ngx_http_script_len_code_pt *) e.ip;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
193 len += lcode(&e);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
194 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
196 ctx->index.len = len;
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
197
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
198 /* 16 bytes are preallocation */
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
199
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
200 len += 16;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
201 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
203 if (len > (size_t) (ctx->path.data + ctx->path.len - ctx->index.data)) {
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
204
248
acd2ec3541cb nginx 0.4.9
Igor Sysoev <http://sysoev.ru>
parents: 234
diff changeset
205 last = ngx_http_map_uri_to_path(r, &ctx->path, &ctx->root, len);
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
206 if (last == NULL) {
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
207 return NGX_ERROR;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 }
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
209
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
210 ctx->index.data = last;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
213 if (index[i].values == NULL) {
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
214
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
215 /* index[i].name.len includes the terminating '\0' */
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
216
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
217 ngx_memcpy(ctx->index.data, index[i].name.data, index[i].name.len);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
219 } else {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
220 e.ip = index[i].values->elts;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
221 e.pos = ctx->index.data;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
223 while (*(uintptr_t *) e.ip) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
224 code = *(ngx_http_script_code_pt *) e.ip;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
225 code((ngx_http_script_engine_t *) &e);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
228 if (*ctx->index.data == '/') {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
229 ctx->index.len--;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
230 return ngx_http_internal_redirect(r, &ctx->index, &r->args);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
233 *e.pos++ = '\0';
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
236 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
237 "open index \"%s\"", ctx->path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
239 cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t));
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
240 if (cln == NULL) {
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
241 return NGX_HTTP_INTERNAL_SERVER_ERROR;
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
242 }
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
243
234
c16038b14e68 nginx 0.4.2
Igor Sysoev <http://sysoev.ru>
parents: 232
diff changeset
244 fd = ngx_open_file(ctx->path.data, NGX_FILE_RDONLY, NGX_FILE_OPEN);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246 if (fd == (ngx_fd_t) NGX_AGAIN) {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
247 ctx->current = i;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 return NGX_AGAIN;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 if (fd == NGX_INVALID_FILE) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 err = ngx_errno;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
254 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, err,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
255 ngx_open_file_n " \"%s\" failed", ctx->path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 if (err == NGX_ENOTDIR) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 return ngx_http_index_error(r, ctx, err);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
260 } else if (err == NGX_EACCES) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
261 return ngx_http_index_error(r, ctx, err);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
262 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
263
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
264 if (!ctx->tested) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
265 rc = ngx_http_index_test_dir(r, ctx);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
266
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
267 if (rc != NGX_OK) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
268 return rc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
269 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
270
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
271 ctx->tested = 1;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
272 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
273
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
274 if (err == NGX_ENOENT) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
275 continue;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
276 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
277
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
278 ngx_log_error(NGX_LOG_ERR, log, err,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
279 ngx_open_file_n " \"%s\" failed", ctx->path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
280
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
281 return NGX_HTTP_INTERNAL_SERVER_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
282 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
284 cln->handler = ngx_pool_cleanup_file;
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
285 clnf = cln->data;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286
112
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
287 clnf->fd = fd;
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
288 clnf->name = ctx->path.data;
408f195b3482 nginx 0.3.3
Igor Sysoev <http://sysoev.ru>
parents: 106
diff changeset
289 clnf->log = r->pool->log;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
291 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
292
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
293 uri.len = r->uri.len + ctx->index.len - 1;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
294
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
295 if (!clcf->alias) {
248
acd2ec3541cb nginx 0.4.9
Igor Sysoev <http://sysoev.ru>
parents: 234
diff changeset
296 uri.data = ctx->path.data + ctx->root;
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
297
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
298 } else {
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
299 uri.data = ngx_palloc(r->pool, uri.len);
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
300 if (uri.data == NULL) {
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
301 return NGX_HTTP_INTERNAL_SERVER_ERROR;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
302 }
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
303
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 112
diff changeset
304 last = ngx_copy(uri.data, r->uri.data, r->uri.len);
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
305 ngx_memcpy(last, ctx->index.data, ctx->index.len - 1);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
307
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
308 return ngx_http_internal_redirect(r, &uri, &r->args);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
309 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
310
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 return NGX_DECLINED;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
315 static ngx_int_t
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
316 ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_index_ctx_t *ctx)
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
317 {
252
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
318 u_char c;
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
319 ngx_uint_t i;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
320 ngx_err_t err;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
321 ngx_file_info_t fi;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
322
252
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
323 c = *(ctx->index.data - 1);
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
324 i = (c == '/') ? 1 : 0;
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
325 *(ctx->index.data - i) = '\0';
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
328 "http index check dir: \"%s\"", ctx->path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
329
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
330 if (ngx_file_info(ctx->path.data, &fi) == -1) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
331
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
332 err = ngx_errno;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
333
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
334 if (err == NGX_ENOENT) {
252
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
335 *(ctx->index.data - i) = c;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
336 return ngx_http_index_error(r, ctx, err);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
337 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
338
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
339 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
340 ngx_file_info_n " \"%s\" failed", ctx->path.data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
341
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
342 return NGX_HTTP_INTERNAL_SERVER_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
343 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
344
252
644510700914 nginx 0.4.11
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
345 *(ctx->index.data - i) = c;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
346
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
347 if (ngx_is_dir(&fi)) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
348 return NGX_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
349 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
350
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
351 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
352 "\"%s\" is not a directory", ctx->path.data);
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
353
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
354 return NGX_HTTP_INTERNAL_SERVER_ERROR;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
355 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
356
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
357
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
358 static ngx_int_t
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
359 ngx_http_index_error(ngx_http_request_t *r, ngx_http_index_ctx_t *ctx,
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
360 ngx_err_t err)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
362 if (err == NGX_EACCES) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
363 ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
364 "\"%s\" is forbidden", ctx->path.data);
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
365
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366 return NGX_HTTP_FORBIDDEN;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
368
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
369 ngx_log_error(NGX_LOG_ERR, r->connection->log, err,
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
370 "\"%s\" is not found", ctx->path.data);
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
371
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372 return NGX_HTTP_NOT_FOUND;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
373 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
374
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
375
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
376 static void *
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
377 ngx_http_index_create_loc_conf(ngx_conf_t *cf)
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
378 {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
379 ngx_http_index_loc_conf_t *conf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
380
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
381 conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t));
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
382 if (conf == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
383 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
384 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
385
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
386 conf->indices = NULL;
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
387 conf->max_index_len = 0;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
388
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
389 return conf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
390 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
391
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
392
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
393 static char *
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
394 ngx_http_index_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
395 {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
396 ngx_http_index_loc_conf_t *prev = parent;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
397 ngx_http_index_loc_conf_t *conf = child;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
398
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
399 ngx_http_index_t *index;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
400
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
401 if (conf->indices == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
402 conf->indices = prev->indices;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
403 conf->max_index_len = prev->max_index_len;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
404 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
405
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
406 if (conf->indices == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
407 conf->indices = ngx_array_create(cf->pool, 1, sizeof(ngx_http_index_t));
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
408 if (conf->indices == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
409 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
410 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
411
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
412 index = ngx_array_push(conf->indices);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
413 if (index == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
414 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
415 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
416
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
417 index->name.len = sizeof(NGX_HTTP_DEFAULT_INDEX);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
418 index->name.data = (u_char *) NGX_HTTP_DEFAULT_INDEX;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
419 index->lengths = NULL;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
420 index->values = NULL;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
421
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
422 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
423
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
424 return NGX_CONF_OK;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
425 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
426
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
427 return NGX_CONF_OK;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
428 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
429
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
430
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
431 static ngx_int_t
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
432 ngx_http_index_init(ngx_conf_t *cf)
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
433 {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
434 ngx_http_handler_pt *h;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
435 ngx_http_core_main_conf_t *cmcf;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
436
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
437 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
438
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
439 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers);
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
440 if (h == NULL) {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
441 return NGX_ERROR;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
442 }
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
443
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
444 *h = ngx_http_index_handler;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
445
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
446 return NGX_OK;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
447 }
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
448
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
449
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
450 /* TODO: warn about duplicate indices */
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
451
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
452 static char *
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
453 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
454 {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
455 ngx_http_index_loc_conf_t *ilcf = conf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
456
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
457 ngx_str_t *value;
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
458 ngx_uint_t i, n;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
459 ngx_http_index_t *index;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
460 ngx_http_script_compile_t sc;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
461
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
462 if (ilcf->indices == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
463 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t));
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
464 if (ilcf->indices == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
465 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
466 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
467 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
468
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
469 value = cf->args->elts;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
470
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
471 for (i = 1; i < cf->args->nelts; i++) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
472 if (value[i].data[0] == '/' && i != cf->args->nelts - 1) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
473 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
474 "only the last index in \"index\" directive "
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
475 "may be absolute");
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
476 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
477 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
478
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
479 if (value[i].len == 0) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
480 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
481 "index \"%V\" in \"index\" directive is invalid",
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
482 &value[1]);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
483 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
484 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
485
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
486 index = ngx_array_push(ilcf->indices);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
487 if (index == NULL) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
488 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
489 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
490
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
491 index->name.len = value[i].len;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
492 index->name.data = value[i].data;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
493 index->lengths = NULL;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
494 index->values = NULL;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
495
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
496 n = ngx_http_script_variables_count(&value[i]);
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
497
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
498 if (n == 0) {
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
499 if (ilcf->max_index_len < index->name.len) {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
500 ilcf->max_index_len = index->name.len;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
501 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
502
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 112
diff changeset
503 /* include the terminating '\0' to the length to use ngx_copy() */
106
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
504 index->name.len++;
45f7329b4bd0 nginx 0.3.0
Igor Sysoev <http://sysoev.ru>
parents: 90
diff changeset
505
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
506 continue;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
507 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
508
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
509 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
510
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
511 sc.cf = cf;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
512 sc.source = &value[i];
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
513 sc.lengths = &index->lengths;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
514 sc.values = &index->values;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
515 sc.variables = n;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
516 sc.complete_lengths = 1;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
517 sc.complete_values = 1;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
518
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
519 if (ngx_http_script_compile(&sc) != NGX_OK) {
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
520 return NGX_CONF_ERROR;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
521 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
522 }
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
523
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
524 return NGX_CONF_OK;
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
525 }