Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_index_module.c @ 3275:b344b68da8c5
optimize some cycles:
*) delete surplus variable;
*) on i386/amd64 "while (n) / n--" is smaller than "while (n--)",
because the platforms have no postfix operations
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 02 Nov 2009 17:12:09 +0000 |
parents | 975f0558aab3 |
children | 84905c7b2aa7 |
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 |
3178 | 208 of.read_ahead = clcf->read_ahead; |
2129 | 209 of.directio = clcf->directio; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
210 of.valid = clcf->open_file_cache_valid; |
1772 | 211 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
|
212 of.test_only = 1; |
1454 | 213 of.errors = clcf->open_file_cache_errors; |
1457 | 214 of.events = clcf->open_file_cache_events; |
563 | 215 |
1799 | 216 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
217 != NGX_OK) | |
218 { | |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
219 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
|
220 "%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
|
221 |
1454 | 222 if (of.err == 0) { |
223 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
224 } | |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
225 |
3160
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
226 if (of.err == NGX_ENOTDIR |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
227 || of.err == NGX_ENAMETOOLONG |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
228 || of.err == NGX_EACCES) |
a7637c2c1157
low ENAMETOOLONG logging level
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
229 { |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
230 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
|
231 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
232 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
233 if (!dir_tested) { |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
234 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
|
235 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
236 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
|
237 return rc; |
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 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
240 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
|
241 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
242 |
1454 | 243 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
|
244 continue; |
41
59e7c7f30d49
nginx-0.0.1-2002-12-26-19:26:23 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
245 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2721
diff
changeset
|
247 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
|
248 "%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
|
249 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
250 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
|
251 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
252 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
253 uri.len = r->uri.len + len - 1; |
557 | 254 |
255 if (!clcf->alias) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
256 uri.data = path.data + root; |
557 | 257 |
258 } else { | |
2049 | 259 uri.data = ngx_pnalloc(r->pool, uri.len); |
557 | 260 if (uri.data == NULL) { |
261 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
262 } | |
263 | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
264 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
|
265 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
|
266 } |
a65b630b3a66
nginx-0.0.1-2003-11-28-11:40:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
267 |
557 | 268 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
|
269 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
270 |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
1
diff
changeset
|
271 return NGX_DECLINED; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
273 |
24
77c7629a2627
nginx-0.0.1-2002-12-10-21:05:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
11
diff
changeset
|
274 |
509 | 275 static ngx_int_t |
1454 | 276 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
|
277 u_char *path, u_char *last) |
509 | 278 { |
1454 | 279 u_char c; |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
280 ngx_str_t dir; |
1454 | 281 ngx_open_file_info_t of; |
509 | 282 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
283 c = *last; |
1627 | 284 if (c != '/' || path == last) { |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
285 /* "alias" without trailing slash */ |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
286 c = *(++last); |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
287 } |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
288 *last = '\0'; |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
289 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
290 dir.len = last - path; |
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
291 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
|
292 |
1454 | 293 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
|
294 "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
|
295 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
296 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
|
297 |
1454 | 298 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
|
299 of.test_only = 1; |
1767
c42431762903
open_file_cache_retest > open_file_cache_valid
Igor Sysoev <igor@sysoev.ru>
parents:
1627
diff
changeset
|
300 of.valid = clcf->open_file_cache_valid; |
1454 | 301 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
|
302 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
303 if (ngx_open_cached_file(clcf->open_file_cache, &dir, &of, r->pool) |
1454 | 304 != NGX_OK) |
305 { | |
306 if (of.err) { | |
307 | |
308 if (of.err == NGX_ENOENT) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
309 *last = c; |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
310 return ngx_http_index_error(r, clcf, dir.data, NGX_ENOENT); |
1454 | 311 } |
312 | |
2181
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
313 if (of.err == NGX_EACCES) { |
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 *last = c; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
316 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
317 /* |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
318 * 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
|
319 * 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
|
320 * This means that directory searching is allowed. |
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 |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
323 return NGX_OK; |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
324 } |
774bef502c78
ignore NGX_EACCES error while directory test
Igor Sysoev <igor@sysoev.ru>
parents:
2160
diff
changeset
|
325 |
1454 | 326 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
|
327 "%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
|
328 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
329 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
330 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
|
331 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
332 |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
333 *last = c; |
47
d81326c3b21b
nginx-0.0.1-2003-01-15-10:02:27 import
Igor Sysoev <igor@sysoev.ru>
parents:
46
diff
changeset
|
334 |
1454 | 335 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
|
336 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
|
337 } |
46
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
338 |
509 | 339 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
|
340 "\"%s\" is not a directory", dir.data); |
509 | 341 |
342 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
|
343 } |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
344 |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
345 |
509 | 346 static ngx_int_t |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
347 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
|
348 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
|
349 { |
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
350 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
|
351 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
|
352 "\"%s\" is forbidden", file); |
577 | 353 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
354 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
|
355 } |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
356 |
2160
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
357 if (clcf->log_not_found) { |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
358 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
|
359 "\"%s\" is not found", file); |
e21f3b073843
consider log_not_found while testing index files
Igor Sysoev <igor@sysoev.ru>
parents:
2129
diff
changeset
|
360 } |
509 | 361 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
119
diff
changeset
|
362 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
|
363 } |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
364 |
f84a648211f4
nginx-0.0.1-2003-01-10-20:45:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
45
diff
changeset
|
365 |
509 | 366 static void * |
367 ngx_http_index_create_loc_conf(ngx_conf_t *cf) | |
368 { | |
369 ngx_http_index_loc_conf_t *conf; | |
370 | |
371 conf = ngx_palloc(cf->pool, sizeof(ngx_http_index_loc_conf_t)); | |
372 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
|
373 return NULL; |
509 | 374 } |
375 | |
376 conf->indices = NULL; | |
681 | 377 conf->max_index_len = 0; |
509 | 378 |
379 return conf; | |
380 } | |
381 | |
382 | |
383 static char * | |
384 ngx_http_index_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
385 { | |
386 ngx_http_index_loc_conf_t *prev = parent; | |
387 ngx_http_index_loc_conf_t *conf = child; | |
388 | |
389 ngx_http_index_t *index; | |
390 | |
391 if (conf->indices == NULL) { | |
392 conf->indices = prev->indices; | |
393 conf->max_index_len = prev->max_index_len; | |
394 } | |
395 | |
396 if (conf->indices == NULL) { | |
397 conf->indices = ngx_array_create(cf->pool, 1, sizeof(ngx_http_index_t)); | |
398 if (conf->indices == NULL) { | |
399 return NGX_CONF_ERROR; | |
400 } | |
401 | |
402 index = ngx_array_push(conf->indices); | |
403 if (index == NULL) { | |
404 return NGX_CONF_ERROR; | |
405 } | |
406 | |
407 index->name.len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
408 index->name.data = (u_char *) NGX_HTTP_DEFAULT_INDEX; | |
409 index->lengths = NULL; | |
410 index->values = NULL; | |
411 | |
412 conf->max_index_len = sizeof(NGX_HTTP_DEFAULT_INDEX); | |
413 | |
414 return NGX_CONF_OK; | |
415 } | |
416 | |
417 return NGX_CONF_OK; | |
418 } | |
419 | |
420 | |
681 | 421 static ngx_int_t |
422 ngx_http_index_init(ngx_conf_t *cf) | |
423 { | |
424 ngx_http_handler_pt *h; | |
425 ngx_http_core_main_conf_t *cmcf; | |
426 | |
427 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
428 | |
429 h = ngx_array_push(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers); | |
430 if (h == NULL) { | |
431 return NGX_ERROR; | |
432 } | |
433 | |
434 *h = ngx_http_index_handler; | |
435 | |
436 return NGX_OK; | |
437 } | |
438 | |
439 | |
509 | 440 /* TODO: warn about duplicate indices */ |
441 | |
442 static char * | |
443 ngx_http_index_set_index(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
444 { | |
445 ngx_http_index_loc_conf_t *ilcf = conf; | |
446 | |
681 | 447 ngx_str_t *value; |
509 | 448 ngx_uint_t i, n; |
449 ngx_http_index_t *index; | |
450 ngx_http_script_compile_t sc; | |
451 | |
452 if (ilcf->indices == NULL) { | |
453 ilcf->indices = ngx_array_create(cf->pool, 2, sizeof(ngx_http_index_t)); | |
454 if (ilcf->indices == NULL) { | |
455 return NGX_CONF_ERROR; | |
456 } | |
457 } | |
458 | |
459 value = cf->args->elts; | |
460 | |
461 for (i = 1; i < cf->args->nelts; i++) { | |
1602
55c8aede41f5
refactor index module: remove context
Igor Sysoev <igor@sysoev.ru>
parents:
1601
diff
changeset
|
462 |
509 | 463 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
|
464 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
509 | 465 "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
|
466 "should be absolute"); |
509 | 467 } |
468 | |
469 if (value[i].len == 0) { | |
470 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
471 "index \"%V\" in \"index\" directive is invalid", | |
472 &value[1]); | |
473 return NGX_CONF_ERROR; | |
474 } | |
475 | |
476 index = ngx_array_push(ilcf->indices); | |
477 if (index == NULL) { | |
478 return NGX_CONF_ERROR; | |
479 } | |
480 | |
481 index->name.len = value[i].len; | |
482 index->name.data = value[i].data; | |
483 index->lengths = NULL; | |
484 index->values = NULL; | |
485 | |
486 n = ngx_http_script_variables_count(&value[i]); | |
487 | |
488 if (n == 0) { | |
681 | 489 if (ilcf->max_index_len < index->name.len) { |
509 | 490 ilcf->max_index_len = index->name.len; |
491 } | |
492 | |
1600
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
493 if (index->name.data[0] == '/') { |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
494 continue; |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
495 } |
1d659775325a
fix mime type for absolute index
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
496 |
2480
a9abdddaa92d
test allocated space as in try_files
Igor Sysoev <igor@sysoev.ru>
parents:
2405
diff
changeset
|
497 /* include the terminating '\0' to the length to use ngx_memcpy() */ |
557 | 498 index->name.len++; |
499 | |
509 | 500 continue; |
501 } | |
502 | |
503 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
504 | |
505 sc.cf = cf; | |
506 sc.source = &value[i]; | |
507 sc.lengths = &index->lengths; | |
508 sc.values = &index->values; | |
509 sc.variables = n; | |
510 sc.complete_lengths = 1; | |
511 sc.complete_values = 1; | |
512 | |
513 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
514 return NGX_CONF_ERROR; | |
515 } | |
516 } | |
517 | |
518 return NGX_CONF_OK; | |
519 } |