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