Mercurial > hg > nginx
annotate src/http/modules/ngx_http_index_module.c @ 3440:88741ec7731a stable-0.7
merge r3294, r3305:
Fix a bug introduced in r2032: After a child process has read a terminate
message from a channel, the process tries to read the channel again.
The kernel (at least FreeBSD) may preempt the process and sends a SIGIO
signal to a master process. The master process sends a new terminate message,
the kernel switches again to the the child process, and the child process
reads the messages instead of an EAGAIN error. And this may repeat over
and over. Being that the child process can not exit the cycle and test
the termination flag set by the message handler.
The fix disallow the master process to send a new terminate message on
SIGIO signal reception. It may send the message only on SIGALARM signal.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 01 Feb 2010 15:49:36 +0000 |
parents | 9ecd253fcc90 |
children | 975f0558aab3 8152369f7037 |
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 |
489 | 119 if (r->zero_in_uri) { |
120 return NGX_DECLINED; | |
121 } | |
122 | |
1454 | 123 ilcf = ngx_http_get_module_loc_conf(r, ngx_http_index_module); |
124 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
125 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
126 allocated = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
127 root = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
128 dir_tested = 0; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
129 name = NULL; |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
130 /* suppress MSVC warning */ |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
131 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
|
132 |
509 | 133 index = ilcf->indices->elts; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
134 for (i = 0; i < ilcf->indices->nelts; i++) { |
509 | 135 |
136 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
|
137 |
509 | 138 if (index[i].name.data[0] == '/') { |
139 return ngx_http_internal_redirect(r, &index[i].name, &r->args); | |
140 } | |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
141 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
142 reserve = ilcf->max_index_len; |
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
143 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
|
144 |
509 | 145 } else { |
146 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
|
147 |
509 | 148 e.ip = index[i].lengths->elts; |
149 e.request = r; | |
573 | 150 e.flushed = 1; |
509 | 151 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
152 /* 1 is for terminating '\0' as in static names */ |
563 | 153 len = 1; |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
154 |
509 | 155 while (*(uintptr_t *) e.ip) { |
156 lcode = *(ngx_http_script_len_code_pt *) e.ip; | |
157 len += lcode(&e); | |
158 } | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
159 |
563 | 160 /* 16 bytes are preallocation */ |
161 | |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
162 reserve = len + 16; |
509 | 163 } |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
164 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
165 if (reserve > allocated) { |
557 | 166 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
167 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
|
168 if (name == NULL) { |
557 | 169 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
|
170 } |
557 | 171 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
172 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
|
173 } |
201
267ea1d98683
nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
200
diff
changeset
|
174 |
509 | 175 if (index[i].values == NULL) { |
557 | 176 |
177 /* index[i].name.len includes the terminating '\0' */ | |
178 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
179 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
|
180 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
181 path.len = (name + index[i].name.len - 1) - path.data; |
1454 | 182 |
509 | 183 } else { |
184 e.ip = index[i].values->elts; | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
185 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
|
186 |
509 | 187 while (*(uintptr_t *) e.ip) { |
188 code = *(ngx_http_script_code_pt *) e.ip; | |
189 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
|
190 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
191 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
192 if (*name == '/') { |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
193 uri.len = len - 1; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
194 uri.data = name; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
195 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
|
196 } |
6f3b20c1ac50
nginx-0.0.7-2004-07-18-23:11:20 import
Igor Sysoev <igor@sysoev.ru>
parents:
356
diff
changeset
|
197 |
1454 | 198 path.len = e.pos - path.data; |
199 | |
2564 | 200 *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
|
201 } |
ec3c049681fd
nginx-0.0.3-2004-03-19-08:25:53 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
202 |
2405 | 203 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
204 "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
|
205 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
206 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
|
207 |
2129 | 208 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
209 of.valid = clcf->open_file_cache_valid; |
1772 | 210 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
|
211 of.test_only = 1; |
1454 | 212 of.errors = clcf->open_file_cache_errors; |
1457 | 213 of.events = clcf->open_file_cache_events; |
563 | 214 |
1799 | 215 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
216 != NGX_OK) | |
217 { | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
218 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
|
219 "%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
|
220 |
1454 | 221 if (of.err == 0) { |
222 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
223 } | |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
224 |
3429 | 225 if (of.err == NGX_ENOTDIR |
226 || of.err == NGX_ENAMETOOLONG | |
227 || of.err == NGX_EACCES) | |
228 { | |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
229 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
|
230 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
231 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
232 if (!dir_tested) { |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
233 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
|
234 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
235 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
|
236 return rc; |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
237 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
238 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
239 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
|
240 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
241 |
1454 | 242 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
|
243 continue; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
244 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
246 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
|
247 "%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
|
248 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
249 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
|
250 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
251 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
252 uri.len = r->uri.len + len - 1; |
557 | 253 |
254 if (!clcf->alias) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
255 uri.data = path.data + root; |
557 | 256 |
257 } else { | |
2049 | 258 uri.data = ngx_pnalloc(r->pool, uri.len); |
557 | 259 if (uri.data == NULL) { |
260 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
261 } | |
262 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
263 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
|
264 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
|
265 } |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
266 |
557 | 267 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
|
268 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
269 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
270 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
271 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 |
24
77c7629a2627
nginx-0.0.1-2002-12-10-21:05:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
11
diff
changeset
|
273 |
509 | 274 static ngx_int_t |
1454 | 275 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
|
276 u_char *path, u_char *last) |
509 | 277 { |
1454 | 278 u_char c; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
279 ngx_str_t dir; |
1454 | 280 ngx_open_file_info_t of; |
509 | 281 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
282 c = *last; |
1627 | 283 if (c != '/' || path == last) { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
284 /* "alias" without trailing slash */ |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
285 c = *(++last); |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
286 } |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
287 *last = '\0'; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
288 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
289 dir.len = last - path; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
290 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
|
291 |
1454 | 292 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
|
293 "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
|
294 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
295 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
|
296 |
1454 | 297 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
|
298 of.test_only = 1; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
299 of.valid = clcf->open_file_cache_valid; |
1454 | 300 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
|
301 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
302 if (ngx_open_cached_file(clcf->open_file_cache, &dir, &of, r->pool) |
1454 | 303 != NGX_OK) |
304 { | |
305 if (of.err) { | |
306 | |
307 if (of.err == NGX_ENOENT) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
308 *last = c; |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
309 return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT); |
1454 | 310 } |
311 | |
2181
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
312 if (of.err == NGX_EACCES) { |
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 *last = c; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
315 |
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 * 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
|
318 * 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
|
319 * This means that directory searching is allowed. |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
320 */ |
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 return NGX_OK; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
323 } |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
324 |
1454 | 325 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
|
326 "%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
|
327 } |
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 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
|
330 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
331 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
332 *last = c; |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
333 |
1454 | 334 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
|
335 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
|
336 } |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
337 |
509 | 338 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
|
339 "\"%s\" is not a directory", dir.data); |
509 | 340 |
341 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
|
342 } |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
343 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
344 |
509 | 345 static ngx_int_t |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
346 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
|
347 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
|
348 { |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
349 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
|
350 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
|
351 "\"%s\" is forbidden", file); |
577 | 352 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
353 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
|
354 } |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
355 |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
356 if (clcf->log_not_found) { |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
357 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
|
358 "\"%s\" is not found", file); |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
359 } |
509 | 360 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
361 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
|
362 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
363 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
364 |
509 | 365 static void * |
366 ngx_http_index_create_loc_conf(ngx_conf_t *cf) | |
367 { | |
368 ngx_http_index_loc_conf_t *conf; | |
369 | |
370 conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)); | |
371 if (conf == NULL) { | |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
372 return NULL; |
509 | 373 } |
374 | |
375 conf->indices = NULL; | |
681 | 376 conf->max_index_len = 0; |
509 | 377 |
378 return conf; | |
379 } | |
380 | |
381 | |
382 static char * | |
383 ngx_http_index_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
384 { | |
385 ngx_http_index_loc_conf_t *prev = parent; | |
386 ngx_http_index_loc_conf_t *conf = child; | |
387 | |
388 ngx_http_index_t *index; | |
389 | |
390 if (conf->indices == NULL) { | |
391 conf->indices = prev->indices; | |
392 conf->max_index_len = prev->max_index_len; | |
393 } | |
394 | |
395 if (conf->indices == NULL) { | |
396 conf->indices = ngx_array_create(cf->pool, 1, sizeof(ngx_http_index_t)); | |
397 if (conf->indices == NULL) { | |
398 return NGX_CONF_ERROR; | |
399 } | |
400 | |
401 index = ngx_array_push(conf->indices); | |
402 if (index == NULL) { | |
403 return NGX_CONF_ERROR; | |
404 } | |
405 | |
406 index->name.len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
407 index->name.data = (u_char *) NGX_HTTP_DEFAULT_INDEX; | |
408 index->lengths = NULL; | |
409 index->values = NULL; | |
410 | |
411 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
412 | |
413 return NGX_CONF_OK; | |
414 } | |
415 | |
416 return NGX_CONF_OK; | |
417 } | |
418 | |
419 | |
681 | 420 static ngx_int_t |
421 ngx_http_index_init(ngx_conf_t *cf) | |
422 { | |
423 ngx_http_handler_pt *h; | |
424 ngx_http_core_main_conf_t *cmcf; | |
425 | |
426 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
427 | |
428 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); | |
429 if (h == NULL) { | |
430 return NGX_ERROR; | |
431 } | |
432 | |
433 *h = ngx_http_index_handler; | |
434 | |
435 return NGX_OK; | |
436 } | |
437 | |
438 | |
509 | 439 /* TODO: warn about duplicate indices */ |
440 | |
441 static char * | |
442 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
443 { | |
444 ngx_http_index_loc_conf_t *ilcf = conf; | |
445 | |
681 | 446 ngx_str_t *value; |
509 | 447 ngx_uint_t i, n; |
448 ngx_http_index_t *index; | |
449 ngx_http_script_compile_t sc; | |
450 | |
451 if (ilcf->indices == NULL) { | |
452 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t)); | |
453 if (ilcf->indices == NULL) { | |
454 return NGX_CONF_ERROR; | |
455 } | |
456 } | |
457 | |
458 value = cf->args->elts; | |
459 | |
460 for (i = 1; i < cf->args->nelts; i++) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
461 |
509 | 462 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
|
463 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
509 | 464 "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
|
465 "should be absolute"); |
509 | 466 } |
467 | |
468 if (value[i].len == 0) { | |
469 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
470 "index \"%V\" in \"index\" directive is invalid", | |
471 &value[1]); | |
472 return NGX_CONF_ERROR; | |
473 } | |
474 | |
475 index = ngx_array_push(ilcf->indices); | |
476 if (index == NULL) { | |
477 return NGX_CONF_ERROR; | |
478 } | |
479 | |
480 index->name.len = value[i].len; | |
481 index->name.data = value[i].data; | |
482 index->lengths = NULL; | |
483 index->values = NULL; | |
484 | |
485 n = ngx_http_script_variables_count(&value[i]); | |
486 | |
487 if (n == 0) { | |
681 | 488 if (ilcf->max_index_len < index->name.len) { |
509 | 489 ilcf->max_index_len = index->name.len; |
490 } | |
491 | |
1600
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
492 if (index->name.data[0] == '/') { |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
493 continue; |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
494 } |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
495 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
496 /* include the terminating '\0' to the length to use ngx_memcpy() */ |
557 | 497 index->name.len++; |
498 | |
509 | 499 continue; |
500 } | |
501 | |
502 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
503 | |
504 sc.cf = cf; | |
505 sc.source = &value[i]; | |
506 sc.lengths = &index->lengths; | |
507 sc.values = &index->values; | |
508 sc.variables = n; | |
509 sc.complete_lengths = 1; | |
510 sc.complete_values = 1; | |
511 | |
512 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
513 return NGX_CONF_ERROR; | |
514 } | |
515 } | |
516 | |
517 return NGX_CONF_OK; | |
518 } |