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