Mercurial > hg > nginx
annotate src/http/modules/ngx_http_index_module.c @ 8518:f9b1a4e52597 quic
QUIC: changed c->quic->pto_count type to ngx_uint_t.
This field is served as a simple counter for PTO backoff.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 19 Aug 2020 15:58:03 +0300 |
parents | e55e28e6998f |
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 |
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 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
65 ngx_http_index_create_loc_conf, /* create location configuration */ |
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4494
diff
changeset
|
66 ngx_http_index_merge_loc_conf /* merge location configuration */ |
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 |
5126
3d50d86f3572
Fixed language in a comment preceding ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
88 * existence because valid requests should prevail over invalid ones. |
3d50d86f3572
Fixed language in a comment preceding ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
89 * If open()/stat() of a file will fail then stat() of a directory |
3d50d86f3572
Fixed language in a comment preceding ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
90 * should be faster because kernel may have already cached some data. |
2756
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. |
5126
3d50d86f3572
Fixed language in a comment preceding ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
92 * Unix has ENOTDIR error; however, it's less helpful than Win32's one: |
3d50d86f3572
Fixed language in a comment preceding ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
4499
diff
changeset
|
93 * it only indicates that path points to a regular file, not a 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) { |
7603
e55e28e6998f
Fixed request finalization in ngx_http_index_handler().
Ruslan Ermilov <ru@nginx.com>
parents:
6948
diff
changeset
|
166 return NGX_HTTP_INTERNAL_SERVER_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; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
212 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
213 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
214 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
215 } |
563 | 216 |
1799 | 217 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
218 != NGX_OK) | |
219 { | |
1454 | 220 if (of.err == 0) { |
221 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
222 } | |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
223 |
6948
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5126
diff
changeset
|
224 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, of.err, |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5126
diff
changeset
|
225 "%s \"%s\" failed", of.failed, path.data); |
3fb9b5eb75c0
Fixed ngx_open_cached_file() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5126
diff
changeset
|
226 |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
227 #if (NGX_HAVE_OPENAT) |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
228 if (of.err == NGX_EMLINK |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
229 || of.err == NGX_ELOOP) |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
230 { |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
231 return NGX_HTTP_FORBIDDEN; |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
232 } |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
233 #endif |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
234 |
3160
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
235 if (of.err == NGX_ENOTDIR |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
236 || of.err == NGX_ENAMETOOLONG |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
237 || of.err == NGX_EACCES) |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
238 { |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
239 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
|
240 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
241 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
242 if (!dir_tested) { |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
243 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
|
244 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
245 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
|
246 return rc; |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
247 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
248 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
249 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
|
250 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
251 |
1454 | 252 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
|
253 continue; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
254 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
256 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
|
257 "%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
|
258 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
259 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
|
260 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
261 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
262 uri.len = r->uri.len + len - 1; |
557 | 263 |
264 if (!clcf->alias) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
265 uri.data = path.data + root; |
557 | 266 |
267 } else { | |
2049 | 268 uri.data = ngx_pnalloc(r->pool, uri.len); |
557 | 269 if (uri.data == NULL) { |
270 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
271 } | |
272 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
273 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
|
274 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
|
275 } |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
276 |
557 | 277 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
|
278 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
279 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
280 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
281 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
282 |
24
77c7629a2627
nginx-0.0.1-2002-12-10-21:05:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
11
diff
changeset
|
283 |
509 | 284 static ngx_int_t |
1454 | 285 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
|
286 u_char *path, u_char *last) |
509 | 287 { |
1454 | 288 u_char c; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
289 ngx_str_t dir; |
1454 | 290 ngx_open_file_info_t of; |
509 | 291 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
292 c = *last; |
1627 | 293 if (c != '/' || path == last) { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
294 /* "alias" without trailing slash */ |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
295 c = *(++last); |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
296 } |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
297 *last = '\0'; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
298 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
299 dir.len = last - path; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
300 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
|
301 |
1454 | 302 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
|
303 "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
|
304 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
305 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
|
306 |
1454 | 307 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
|
308 of.test_only = 1; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
309 of.valid = clcf->open_file_cache_valid; |
1454 | 310 of.errors = clcf->open_file_cache_errors; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
311 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
312 if (ngx_http_set_disable_symlinks(r, clcf, &dir, &of) != NGX_OK) { |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
313 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
314 } |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
315 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
316 if (ngx_open_cached_file(clcf->open_file_cache, &dir, &of, r->pool) |
1454 | 317 != NGX_OK) |
318 { | |
319 if (of.err) { | |
320 | |
4478
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
321 #if (NGX_HAVE_OPENAT) |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
322 if (of.err == NGX_EMLINK |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
323 || of.err == NGX_ELOOP) |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
324 { |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
325 return NGX_HTTP_FORBIDDEN; |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
326 } |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
327 #endif |
08713bac87fc
Support for disable_symlinks in various modules.
Andrey Belov <defan@nginx.com>
parents:
4412
diff
changeset
|
328 |
1454 | 329 if (of.err == NGX_ENOENT) { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
330 *last = c; |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
331 return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT); |
1454 | 332 } |
333 | |
2181
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
334 if (of.err == NGX_EACCES) { |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
335 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
336 *last = c; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
337 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
338 /* |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
339 * 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
|
340 * 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
|
341 * This means that directory searching is allowed. |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
342 */ |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
343 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
344 return NGX_OK; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
345 } |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
346 |
1454 | 347 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
|
348 "%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
|
349 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
350 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
351 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
|
352 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
353 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
354 *last = c; |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
355 |
1454 | 356 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
|
357 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
|
358 } |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
359 |
509 | 360 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
|
361 "\"%s\" is not a directory", dir.data); |
509 | 362 |
363 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
|
364 } |
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 |
509 | 367 static ngx_int_t |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
368 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
|
369 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
|
370 { |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
371 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
|
372 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
|
373 "\"%s\" is forbidden", file); |
577 | 374 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
375 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
|
376 } |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
377 |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
378 if (clcf->log_not_found) { |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
379 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
|
380 "\"%s\" is not found", file); |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
381 } |
509 | 382 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
383 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
|
384 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
385 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
386 |
509 | 387 static void * |
388 ngx_http_index_create_loc_conf(ngx_conf_t *cf) | |
389 { | |
390 ngx_http_index_loc_conf_t *conf; | |
391 | |
392 conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)); | |
393 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
|
394 return NULL; |
509 | 395 } |
396 | |
397 conf->indices = NULL; | |
681 | 398 conf->max_index_len = 0; |
509 | 399 |
400 return conf; | |
401 } | |
402 | |
403 | |
404 static char * | |
405 ngx_http_index_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
406 { | |
407 ngx_http_index_loc_conf_t *prev = parent; | |
408 ngx_http_index_loc_conf_t *conf = child; | |
409 | |
410 ngx_http_index_t *index; | |
411 | |
412 if (conf->indices == NULL) { | |
413 conf->indices = prev->indices; | |
414 conf->max_index_len = prev->max_index_len; | |
415 } | |
416 | |
417 if (conf->indices == NULL) { | |
418 conf->indices = ngx_array_create(cf->pool, 1, sizeof(ngx_http_index_t)); | |
419 if (conf->indices == NULL) { | |
420 return NGX_CONF_ERROR; | |
421 } | |
422 | |
423 index = ngx_array_push(conf->indices); | |
424 if (index == NULL) { | |
425 return NGX_CONF_ERROR; | |
426 } | |
427 | |
428 index->name.len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
429 index->name.data = (u_char *) NGX_HTTP_DEFAULT_INDEX; | |
430 index->lengths = NULL; | |
431 index->values = NULL; | |
432 | |
433 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
434 | |
435 return NGX_CONF_OK; | |
436 } | |
437 | |
438 return NGX_CONF_OK; | |
439 } | |
440 | |
441 | |
681 | 442 static ngx_int_t |
443 ngx_http_index_init(ngx_conf_t *cf) | |
444 { | |
445 ngx_http_handler_pt *h; | |
446 ngx_http_core_main_conf_t *cmcf; | |
447 | |
448 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
449 | |
450 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); | |
451 if (h == NULL) { | |
452 return NGX_ERROR; | |
453 } | |
454 | |
455 *h = ngx_http_index_handler; | |
456 | |
457 return NGX_OK; | |
458 } | |
459 | |
460 | |
509 | 461 /* TODO: warn about duplicate indices */ |
462 | |
463 static char * | |
464 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
465 { | |
466 ngx_http_index_loc_conf_t *ilcf = conf; | |
467 | |
681 | 468 ngx_str_t *value; |
509 | 469 ngx_uint_t i, n; |
470 ngx_http_index_t *index; | |
471 ngx_http_script_compile_t sc; | |
472 | |
473 if (ilcf->indices == NULL) { | |
474 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t)); | |
475 if (ilcf->indices == NULL) { | |
476 return NGX_CONF_ERROR; | |
477 } | |
478 } | |
479 | |
480 value = cf->args->elts; | |
481 | |
482 for (i = 1; i < cf->args->nelts; i++) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
483 |
509 | 484 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
|
485 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
509 | 486 "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
|
487 "should be absolute"); |
509 | 488 } |
489 | |
490 if (value[i].len == 0) { | |
491 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
492 "index \"%V\" in \"index\" directive is invalid", | |
493 &value[1]); | |
494 return NGX_CONF_ERROR; | |
495 } | |
496 | |
497 index = ngx_array_push(ilcf->indices); | |
498 if (index == NULL) { | |
499 return NGX_CONF_ERROR; | |
500 } | |
501 | |
502 index->name.len = value[i].len; | |
503 index->name.data = value[i].data; | |
504 index->lengths = NULL; | |
505 index->values = NULL; | |
506 | |
507 n = ngx_http_script_variables_count(&value[i]); | |
508 | |
509 if (n == 0) { | |
681 | 510 if (ilcf->max_index_len < index->name.len) { |
509 | 511 ilcf->max_index_len = index->name.len; |
512 } | |
513 | |
1600
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
514 if (index->name.data[0] == '/') { |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
515 continue; |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
516 } |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
517 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
518 /* include the terminating '\0' to the length to use ngx_memcpy() */ |
557 | 519 index->name.len++; |
520 | |
509 | 521 continue; |
522 } | |
523 | |
524 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
525 | |
526 sc.cf = cf; | |
527 sc.source = &value[i]; | |
528 sc.lengths = &index->lengths; | |
529 sc.values = &index->values; | |
530 sc.variables = n; | |
531 sc.complete_lengths = 1; | |
532 sc.complete_values = 1; | |
533 | |
534 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
535 return NGX_CONF_ERROR; | |
536 } | |
537 } | |
538 | |
539 return NGX_CONF_OK; | |
540 } |