Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_index_module.c @ 3952:4d61547bbc2a stable-0.7
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 19 Jul 2011 14:11:18 +0000 |
parents | 8152369f7037 |
children |
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 |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
25 #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
|
26 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
27 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
28 static ngx_int_t ngx_http_index_test_dir(ngx_http_request_t *r, |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
29 ngx_http_core_loc_conf_t *clcf, u_char *path, u_char *last); |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
30 static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
31 ngx_http_core_loc_conf_t *clcf, u_char *file, 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
|
32 |
681 | 33 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
|
34 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
|
35 static char *ngx_http_index_merge_loc_conf(ngx_conf_t *cf, |
509 | 36 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
|
37 static char *ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, |
509 | 38 void *conf); |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
39 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
40 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
41 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
|
42 |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
43 { ngx_string("index"), |
509 | 44 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
|
45 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
|
46 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
|
47 0, |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
48 NULL }, |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
49 |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
50 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
|
51 }; |
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
52 |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
53 |
667 | 54 static ngx_http_module_t ngx_http_index_module_ctx = { |
509 | 55 NULL, /* preconfiguration */ |
681 | 56 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
|
57 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
58 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
|
59 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
|
60 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
61 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
|
62 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
|
63 |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
64 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
|
65 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
|
66 }; |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
67 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
69 ngx_module_t ngx_http_index_module = { |
509 | 70 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
|
71 &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
|
72 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
|
73 NGX_HTTP_MODULE, /* module type */ |
541 | 74 NULL, /* init master */ |
681 | 75 NULL, /* init module */ |
541 | 76 NULL, /* init process */ |
77 NULL, /* init thread */ | |
78 NULL, /* exit thread */ | |
79 NULL, /* exit process */ | |
80 NULL, /* exit master */ | |
81 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
|
82 }; |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
83 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
84 |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
85 /* |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
86 * Try to open/test the first index file before the test of directory |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
87 * existence because valid requests should be much more than invalid ones. |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
88 * If the file open()/stat() would fail, then the directory stat() should |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
89 * be more quickly because some data is already cached in the kernel. |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
90 * Besides, Win32 may return ERROR_PATH_NOT_FOUND (NGX_ENOTDIR) at once. |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
91 * Unix has ENOTDIR error, however, it's less helpful than Win32's one: |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
92 * it only indicates that path contains an usual file in place of directory. |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
93 */ |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
94 |
509 | 95 static ngx_int_t |
96 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
|
97 { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
98 u_char *p, *name; |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
99 size_t len, root, reserve, allocated; |
509 | 100 ngx_int_t rc; |
1454 | 101 ngx_str_t path, uri; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
102 ngx_uint_t i, dir_tested; |
509 | 103 ngx_http_index_t *index; |
1454 | 104 ngx_open_file_info_t of; |
509 | 105 ngx_http_script_code_pt code; |
106 ngx_http_script_engine_t e; | |
107 ngx_http_core_loc_conf_t *clcf; | |
108 ngx_http_index_loc_conf_t *ilcf; | |
109 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
|
110 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
111 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
|
112 return NGX_DECLINED; |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
113 } |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
114 |
955
ff762576da78
limit the ngx_http_index_module methods to GET, HEAD and POST
Igor Sysoev <igor@sysoev.ru>
parents:
813
diff
changeset
|
115 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
|
116 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
|
117 } |
ff762576da78
limit the ngx_http_index_module methods to GET, HEAD and POST
Igor Sysoev <igor@sysoev.ru>
parents:
813
diff
changeset
|
118 |
1454 | 119 ilcf = ngx_http_get_module_loc_conf(r, ngx_http_index_module); |
120 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
121 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
122 allocated = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
123 root = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
124 dir_tested = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
125 name = NULL; |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
126 /* suppress MSVC warning */ |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
127 path.data = NULL; |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
128 |
509 | 129 index = ilcf->indices->elts; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
130 for (i = 0; i < ilcf->indices->nelts; i++) { |
509 | 131 |
132 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
|
133 |
509 | 134 if (index[i].name.data[0] == '/') { |
135 return ngx_http_internal_redirect(r, &index[i].name, &r->args); | |
136 } | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
137 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
138 reserve = ilcf->max_index_len; |
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
139 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
|
140 |
509 | 141 } else { |
142 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
|
143 |
509 | 144 e.ip = index[i].lengths->elts; |
145 e.request = r; | |
573 | 146 e.flushed = 1; |
509 | 147 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
148 /* 1 is for terminating '\0' as in static names */ |
563 | 149 len = 1; |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
150 |
509 | 151 while (*(uintptr_t *) e.ip) { |
152 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
153 len += lcode(&e); | |
154 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
155 |
563 | 156 /* 16 bytes are preallocation */ |
157 | |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
158 reserve = len + 16; |
509 | 159 } |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
160 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
161 if (reserve > allocated) { |
557 | 162 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
163 name = ngx_http_map_uri_to_path(r, &path, &root, reserve); |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
164 if (name == NULL) { |
557 | 165 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
|
166 } |
557 | 167 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
168 allocated = path.data + path.len - name; |
287
35a6a9df2d25
nginx-0.0.2-2004-03-12-19:57:08 import
Igor Sysoev <igor@sysoev.ru>
parents:
257
diff
changeset
|
169 } |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
170 |
509 | 171 if (index[i].values == NULL) { |
557 | 172 |
173 /* index[i].name.len includes the terminating '\0' */ | |
174 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
175 ngx_memcpy(name, 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
|
176 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
177 path.len = (name + index[i].name.len - 1) - path.data; |
1454 | 178 |
509 | 179 } else { |
180 e.ip = index[i].values->elts; | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
181 e.pos = name; |
293
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
182 |
509 | 183 while (*(uintptr_t *) e.ip) { |
184 code = *(ngx_http_script_code_pt *) e.ip; | |
185 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
|
186 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
187 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
188 if (*name == '/') { |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
189 uri.len = len - 1; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
190 uri.data = name; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
191 return ngx_http_internal_redirect(r, &uri, &r->args); |
396
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
192 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
193 |
1454 | 194 path.len = e.pos - path.data; |
195 | |
2564 | 196 *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
|
197 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
198 |
2405 | 199 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
200 "open index \"%V\"", &path); | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
201 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
202 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
203 |
2129 | 204 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
205 of.valid = clcf->open_file_cache_valid; |
1772 | 206 of.min_uses = clcf->open_file_cache_min_uses; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
207 of.test_only = 1; |
1454 | 208 of.errors = clcf->open_file_cache_errors; |
1457 | 209 of.events = clcf->open_file_cache_events; |
563 | 210 |
1799 | 211 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
212 != NGX_OK) | |
213 { | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
214 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err, |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
215 "%s \"%s\" failed", of.failed, path.data); |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
216 |
1454 | 217 if (of.err == 0) { |
218 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
219 } | |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
220 |
3429 | 221 if (of.err == NGX_ENOTDIR |
222 || of.err == NGX_ENAMETOOLONG | |
223 || of.err == NGX_EACCES) | |
224 { | |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
225 return ngx_http_index_error(r, clcf, path.data, of.err); |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
226 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
227 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
228 if (!dir_tested) { |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
229 rc = ngx_http_index_test_dir(r, clcf, path.data, name - 1); |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
230 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
231 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
|
232 return rc; |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
233 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
234 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
235 dir_tested = 1; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
236 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
237 |
1454 | 238 if (of.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
|
239 continue; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
240 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
241 |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
242 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
243 "%s \"%s\" failed", of.failed, path.data); |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
244 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
245 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
|
246 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
248 uri.len = r->uri.len + len - 1; |
557 | 249 |
250 if (!clcf->alias) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
251 uri.data = path.data + root; |
557 | 252 |
253 } else { | |
2049 | 254 uri.data = ngx_pnalloc(r->pool, uri.len); |
557 | 255 if (uri.data == NULL) { |
256 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
257 } | |
258 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
259 p = ngx_copy(uri.data, r->uri.data, r->uri.len); |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
260 ngx_memcpy(p, name, len - 1); |
199
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
261 } |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
262 |
557 | 263 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
|
264 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
265 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
266 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
267 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
268 |
24
77c7629a2627
nginx-0.0.1-2002-12-10-21:05:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
11
diff
changeset
|
269 |
509 | 270 static ngx_int_t |
1454 | 271 ngx_http_index_test_dir(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf, |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
272 u_char *path, u_char *last) |
509 | 273 { |
1454 | 274 u_char c; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
275 ngx_str_t dir; |
1454 | 276 ngx_open_file_info_t of; |
509 | 277 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
278 c = *last; |
1627 | 279 if (c != '/' || path == last) { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
280 /* "alias" without trailing slash */ |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
281 c = *(++last); |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
282 } |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
283 *last = '\0'; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
284 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
285 dir.len = last - path; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
286 dir.data = path; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
287 |
1454 | 288 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
289 "http index check dir: \"%V\"", &dir); |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
290 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
291 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
292 |
1454 | 293 of.test_dir = 1; |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
294 of.test_only = 1; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
295 of.valid = clcf->open_file_cache_valid; |
1454 | 296 of.errors = clcf->open_file_cache_errors; |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
297 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
298 if (ngx_open_cached_file(clcf->open_file_cache, &dir, &of, r->pool) |
1454 | 299 != NGX_OK) |
300 { | |
301 if (of.err) { | |
302 | |
303 if (of.err == NGX_ENOENT) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
304 *last = c; |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
305 return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT); |
1454 | 306 } |
307 | |
2181
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
308 if (of.err == NGX_EACCES) { |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
309 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
310 *last = c; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
311 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
312 /* |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
313 * ngx_http_index_test_dir() is called after the first index |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
314 * file testing has returned an error distinct from NGX_EACCES. |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
315 * This means that directory searching is allowed. |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
316 */ |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
317 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
318 return NGX_OK; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
319 } |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
320 |
1454 | 321 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
322 "%s \"%s\" failed", of.failed, dir.data); |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
323 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
324 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
325 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
|
326 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
327 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
328 *last = c; |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
329 |
1454 | 330 if (of.is_dir) { |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
331 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
|
332 } |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
333 |
509 | 334 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
335 "\"%s\" is not a directory", dir.data); |
509 | 336 |
337 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
|
338 } |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
339 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
340 |
509 | 341 static ngx_int_t |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
342 ngx_http_index_error(ngx_http_request_t *r, ngx_http_core_loc_conf_t *clcf, |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
343 u_char *file, 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
|
344 { |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
345 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
|
346 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
347 "\"%s\" is forbidden", file); |
577 | 348 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
349 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
|
350 } |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
351 |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
352 if (clcf->log_not_found) { |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
353 ngx_log_error(NGX_LOG_ERR, r->connection->log, err, |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
354 "\"%s\" is not found", file); |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
355 } |
509 | 356 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
357 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
|
358 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
359 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
360 |
509 | 361 static void * |
362 ngx_http_index_create_loc_conf(ngx_conf_t *cf) | |
363 { | |
364 ngx_http_index_loc_conf_t *conf; | |
365 | |
366 conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)); | |
367 if (conf == NULL) { | |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
368 return NULL; |
509 | 369 } |
370 | |
371 conf->indices = NULL; | |
681 | 372 conf->max_index_len = 0; |
509 | 373 |
374 return conf; | |
375 } | |
376 | |
377 | |
378 static char * | |
379 ngx_http_index_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
380 { | |
381 ngx_http_index_loc_conf_t *prev = parent; | |
382 ngx_http_index_loc_conf_t *conf = child; | |
383 | |
384 ngx_http_index_t *index; | |
385 | |
386 if (conf->indices == NULL) { | |
387 conf->indices = prev->indices; | |
388 conf->max_index_len = prev->max_index_len; | |
389 } | |
390 | |
391 if (conf->indices == NULL) { | |
392 conf->indices = ngx_array_create(cf->pool, 1, sizeof(ngx_http_index_t)); | |
393 if (conf->indices == NULL) { | |
394 return NGX_CONF_ERROR; | |
395 } | |
396 | |
397 index = ngx_array_push(conf->indices); | |
398 if (index == NULL) { | |
399 return NGX_CONF_ERROR; | |
400 } | |
401 | |
402 index->name.len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
403 index->name.data = (u_char *) NGX_HTTP_DEFAULT_INDEX; | |
404 index->lengths = NULL; | |
405 index->values = NULL; | |
406 | |
407 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
408 | |
409 return NGX_CONF_OK; | |
410 } | |
411 | |
412 return NGX_CONF_OK; | |
413 } | |
414 | |
415 | |
681 | 416 static ngx_int_t |
417 ngx_http_index_init(ngx_conf_t *cf) | |
418 { | |
419 ngx_http_handler_pt *h; | |
420 ngx_http_core_main_conf_t *cmcf; | |
421 | |
422 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
423 | |
424 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); | |
425 if (h == NULL) { | |
426 return NGX_ERROR; | |
427 } | |
428 | |
429 *h = ngx_http_index_handler; | |
430 | |
431 return NGX_OK; | |
432 } | |
433 | |
434 | |
509 | 435 /* TODO: warn about duplicate indices */ |
436 | |
437 static char * | |
438 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
439 { | |
440 ngx_http_index_loc_conf_t *ilcf = conf; | |
441 | |
681 | 442 ngx_str_t *value; |
509 | 443 ngx_uint_t i, n; |
444 ngx_http_index_t *index; | |
445 ngx_http_script_compile_t sc; | |
446 | |
447 if (ilcf->indices == NULL) { | |
448 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t)); | |
449 if (ilcf->indices == NULL) { | |
450 return NGX_CONF_ERROR; | |
451 } | |
452 } | |
453 | |
454 value = cf->args->elts; | |
455 | |
456 for (i = 1; i < cf->args->nelts; i++) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
457 |
509 | 458 if (value[i].data[0] == '/' && i != cf->args->nelts - 1) { |
1601
cba2bb1796e4
change emerg to a warn for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1600
diff
changeset
|
459 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
509 | 460 "only the last index in \"index\" directive " |
1601
cba2bb1796e4
change emerg to a warn for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1600
diff
changeset
|
461 "should be absolute"); |
509 | 462 } |
463 | |
464 if (value[i].len == 0) { | |
465 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
466 "index \"%V\" in \"index\" directive is invalid", | |
467 &value[1]); | |
468 return NGX_CONF_ERROR; | |
469 } | |
470 | |
471 index = ngx_array_push(ilcf->indices); | |
472 if (index == NULL) { | |
473 return NGX_CONF_ERROR; | |
474 } | |
475 | |
476 index->name.len = value[i].len; | |
477 index->name.data = value[i].data; | |
478 index->lengths = NULL; | |
479 index->values = NULL; | |
480 | |
481 n = ngx_http_script_variables_count(&value[i]); | |
482 | |
483 if (n == 0) { | |
681 | 484 if (ilcf->max_index_len < index->name.len) { |
509 | 485 ilcf->max_index_len = index->name.len; |
486 } | |
487 | |
1600
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
488 if (index->name.data[0] == '/') { |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
489 continue; |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
490 } |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
491 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
492 /* include the terminating '\0' to the length to use ngx_memcpy() */ |
557 | 493 index->name.len++; |
494 | |
509 | 495 continue; |
496 } | |
497 | |
498 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
499 | |
500 sc.cf = cf; | |
501 sc.source = &value[i]; | |
502 sc.lengths = &index->lengths; | |
503 sc.values = &index->values; | |
504 sc.variables = n; | |
505 sc.complete_lengths = 1; | |
506 sc.complete_values = 1; | |
507 | |
508 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
509 return NGX_CONF_ERROR; | |
510 } | |
511 } | |
512 | |
513 return NGX_CONF_OK; | |
514 } |