Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 357 lines (277 sloc) 10.302 kb
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b Alvaro Lopez Ortega Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-97f1...
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
23 */
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
24
25 #include "common-internal.h"
26 #include "handler_common.h"
27
28 #ifdef HAVE_SYS_TYPES_H
29 # include <sys/types.h>
30 #endif
31
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <errno.h>
35
36 #ifdef HAVE_STRINGS_H
37 # include <strings.h>
38 #endif
39
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
40 #include "util.h"
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
41 #include "connection.h"
42 #include "connection-protected.h"
43 #include "server.h"
44 #include "server-protected.h"
45 #include "module.h"
46 #include "connection.h"
47
48 #define ENTRIES "handler,common"
b0e3bfe Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2169 5dc97367-97f1...
alobbs authored
49 #define DEFAULT_ALLOW_PATHINFO false
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
50 #define DEFAULT_ALLOW_DIRLIST true
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
51
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
52 ret_t
53 cherokee_handler_common_props_free (cherokee_handler_common_props_t *props)
54 {
55 if (props->props_file != NULL) {
56 cherokee_handler_file_props_free (props->props_file);
57 props->props_file = NULL;
58 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
59
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
60 if (props->props_dirlist != NULL) {
61 cherokee_handler_dirlist_props_free (props->props_dirlist);
62 props->props_dirlist = NULL;
63 }
64
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
65 return cherokee_handler_props_free_base (HANDLER_PROPS(props));
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
66 }
67
68
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
69 ret_t
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
70 cherokee_handler_common_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props)
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
71 {
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
72 ret_t ret;
73 cherokee_config_node_t *subconf;
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
74 cherokee_handler_common_props_t *props;
75
76 if (*_props == NULL) {
77 CHEROKEE_NEW_STRUCT (n, handler_common_props);
78
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
79 cherokee_handler_props_init_base (HANDLER_PROPS(n),
81679d0 handler_*.c, space / code style cleanups
ADF authored
80 MODULE_PROPS_FREE(cherokee_handler_common_props_free));
be04810 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@283 5dc97367-97f1-...
alobbs authored
81
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
82 n->props_file = NULL;
83 n->props_dirlist = NULL;
84 n->allow_pathinfo = DEFAULT_ALLOW_PATHINFO;
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
85 n->allow_dirlist = DEFAULT_ALLOW_DIRLIST;
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
86
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
87 *_props = MODULE_PROPS(n);
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
88 }
89
90 props = PROP_COMMON(*_props);
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
91
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
92 /* Parse 'common' parameters
93 */
94 ret = cherokee_config_node_get (conf, "allow_pathinfo", &subconf);
95 if (ret == ret_ok) {
2459250 Alvaro Lopez Ortega Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
96 ret = cherokee_atob (subconf->val.buf, &props->allow_pathinfo);
97 if (ret != ret_ok) return ret;
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
98 }
99
100 ret = cherokee_config_node_get (conf, "allow_dirlist", &subconf);
101 if (ret == ret_ok) {
2459250 Alvaro Lopez Ortega Replace atoi() calls by either cherokee_atoi() or cherokee_atob().
alobbs authored
102 ret = cherokee_atob (subconf->val.buf, &props->allow_dirlist);
103 if (ret != ret_ok) return ret;
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
104 }
105
106 /* Parse 'file' parameters
107 */
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
108 ret = cherokee_handler_file_configure (conf, srv, (cherokee_module_props_t **)&props->props_file);
6df50ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@461 5dc97367-97f1-...
alobbs authored
109 if ((ret != ret_ok) && (ret != ret_deny)) return ret;
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
110
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
111 /* Parse 'dirlist' parameters
112 */
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
113 return cherokee_handler_dirlist_configure (conf, srv, (cherokee_module_props_t **)&props->props_dirlist);
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
114 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
115
116
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
117
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
118 ret_t
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
119 cherokee_handler_common_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props)
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
120 {
121 ret_t ret;
122 int exists;
123 struct stat nocache_info;
124 struct stat *info;
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
125 cherokee_iocache_entry_t *io_entry = NULL;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
126 cherokee_iocache_t *iocache = NULL;
127 cherokee_boolean_t use_iocache = true;
128 cherokee_connection_t *conn = CONN(cnt);
129
7a3e417 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1611 5dc97367-97f1...
alobbs authored
130 TRACE_CONN(conn);
131
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
132 /* Check some properties
133 */
3509796 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@282 5dc97367-97f1-...
alobbs authored
134 if (PROP_COMMON(props)->props_file != NULL) {
135 use_iocache = PROP_COMMON(props)->props_file->use_cache;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
136 }
137
d5fa8c3 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2192 5dc97367-97f1...
alobbs authored
138 use_iocache &= (CONN_SRV(cnt)->iocache != NULL);
139
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
140 /* Check the request
141 */
142 cherokee_buffer_add_buffer (&conn->local_directory, &conn->request);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
143
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
144 if (use_iocache)
a957ffd Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2119 5dc97367-97f1...
alobbs authored
145 iocache = CONN_SRV(conn)->iocache;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
146
b39795e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2238 5dc97367-97f1...
alobbs authored
147 ret = cherokee_io_stat (iocache, &conn->local_directory, use_iocache, &nocache_info, &io_entry, &info);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
148 exists = (ret == ret_ok);
149
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
150 TRACE (ENTRIES, "request: '%s', local: '%s', exists %d\n",
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
151 conn->request.buf, conn->local_directory.buf, exists);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
152
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
153 if (!exists) {
154 ret_t ret;
155 char *pathinfo;
156 int pathinfo_len;
157 int begin;
158
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
159 /* If PathInfo is not allowed just return 'Not Found'
160 */
161 if (! PROP_COMMON(props)->allow_pathinfo) {
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
162 TRACE(ENTRIES, "Returns conn->error_code: %s\n", "http_not_found");
163 cherokee_iocache_entry_unref (&io_entry);
164
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
165 conn->error_code = http_not_found;
8cbb62f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@945 5dc97367-97f1-...
alobbs authored
166 return ret_error;
167 }
168
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
169 /* Maybe it could stat() the file because the request contains
170 * a PathInfo string at the end..
171 */
172 begin = conn->local_directory.len - conn->request.len;
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
173
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
174 ret = cherokee_split_pathinfo (&conn->local_directory, begin, true, &pathinfo, &pathinfo_len);
175 if ((ret == ret_not_found) || (pathinfo_len <= 0)) {
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
176 TRACE(ENTRIES, "Returns conn->error_code: %s\n", "http_not_found");
177 cherokee_iocache_entry_unref (&io_entry);
178
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
179 conn->error_code = http_not_found;
180 return ret_error;
181 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
182
183 /* Copy the PathInfo and clean the request
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
184 */
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
185 if (cherokee_buffer_is_empty (&conn->request_original)) {
186 cherokee_buffer_add_buffer (&conn->request_original, &conn->request);
a82df4d Antonio Pérez Original query string is now saved, like original request, and added to ...
skarcha authored
187 cherokee_buffer_add_buffer (&conn->query_string_original, &conn->query_string);
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
188 }
189
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
190 cherokee_buffer_add (&conn->pathinfo, pathinfo, pathinfo_len);
51ed095 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1614 5dc97367-97f1...
alobbs authored
191 cherokee_buffer_drop_ending (&conn->request, pathinfo_len);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
192
193 /* Clean the local_directory, this connection is going
194 * to restart the connection setup phase
195 */
196 cherokee_buffer_clean (&conn->local_directory);
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
197 cherokee_iocache_entry_unref (&io_entry);
7a3e417 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1611 5dc97367-97f1...
alobbs authored
198
199 TRACE_CONN(conn);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
200 return ret_eagain;
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
201 }
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
202
51ed095 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1614 5dc97367-97f1...
alobbs authored
203 cherokee_buffer_drop_ending (&conn->local_directory, conn->request.len);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
204
205 /* Is it a file?
206 */
207 if (S_ISREG(info->st_mode)) {
208 TRACE (ENTRIES, "going for %s\n", "handler_file");
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
209 cherokee_iocache_entry_unref (&io_entry);
210
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
211 return cherokee_handler_file_new (hdl, cnt, MODULE_PROPS(PROP_COMMON(props)->props_file));
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
212 }
213
214 /* Is it a directory
215 */
216 if (S_ISDIR(info->st_mode)) {
e0f5eff Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1286 5dc97367-97f1...
alobbs authored
217 cherokee_thread_t *thread = CONN_THREAD(conn);
218 cherokee_list_t *i;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
219
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
220 cherokee_iocache_entry_unref (&io_entry);
b7f7d10 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97f1-...
alobbs authored
221
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
222 /* Maybe it has to be redirected
223 */
f60e724 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@661 5dc97367-97f1-...
alobbs authored
224 if (cherokee_buffer_end_char (&conn->request) != '/') {
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
225 TRACE (ENTRIES, "going for %s\n", "handler_dir");
7b0e48a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@387 5dc97367-97f1-...
alobbs authored
226 return cherokee_handler_dirlist_new (hdl, cnt, MODULE_PROPS(PROP_COMMON(props)->props_dirlist));
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
227 }
228
229 /* Add the request
230 */
231 cherokee_buffer_add_buffer (&conn->local_directory, &conn->request);
232
233 /* Have an index file inside?
234 */
235 list_for_each (i, &CONN_VSRV(conn)->index_list) {
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
236 int is_dir;
237 cherokee_buffer_t *index = BUF(LIST_ITEM_INFO(i));
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
238
239 /* Check if the index is fullpath
240 */
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
241 if (index->buf[0] == '/') {
3c2b494 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97f1-...
alobbs authored
242 cherokee_buffer_t *new_local_dir = THREAD_TMP_BUF1(thread);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
243
244 /* This means there is a configuration entry like:
245 * 'DirectoryIndex index.php, /index_default.php'
246 * and it's proceesing '/index_default.php'.
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
247 */
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
248
249 /* Build the secondary path
250 */
251 cherokee_buffer_add_buffer (&conn->effective_directory, &conn->local_directory);
252
253 /* Lets reconstruct the local directory
254 */
3c2b494 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97f1-...
alobbs authored
255 cherokee_buffer_clean (new_local_dir);
256 cherokee_buffer_add_buffer (new_local_dir, &CONN_VSRV(conn)->root);
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
257 cherokee_buffer_add_buffer (new_local_dir, index);
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
258
b39795e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2238 5dc97367-97f1...
alobbs authored
259 ret = cherokee_io_stat (iocache, new_local_dir, use_iocache, &nocache_info, &io_entry, &info);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
260 exists = (ret == ret_ok);
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
261 cherokee_iocache_entry_unref (&io_entry);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
262
3c2b494 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97f1-...
alobbs authored
263 if (!exists)
264 continue;
b7f7d10 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97f1-...
alobbs authored
265
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
266 /* Build the new request before respin
267 */
268 cherokee_buffer_clean (&conn->local_directory);
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
269 if (cherokee_buffer_is_empty (&conn->request_original)) {
270 cherokee_buffer_add_buffer (&conn->request_original, &conn->request);
a82df4d Antonio Pérez Original query string is now saved, like original request, and added to ...
skarcha authored
271 cherokee_buffer_add_buffer (&conn->query_string_original, &conn->query_string);
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
272 }
c69896a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@639 5dc97367-97f1-...
alobbs authored
273
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
274 cherokee_buffer_clean (&conn->request);
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
275 cherokee_buffer_add_buffer (&conn->request, index);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
276
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
277 TRACE (ENTRIES, "top level index matched %s\n", index->buf);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
278
c69896a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@639 5dc97367-97f1-...
alobbs authored
279 BIT_SET (conn->options, conn_op_root_index);
7a3e417 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1611 5dc97367-97f1...
alobbs authored
280
281 TRACE_CONN(conn);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
282 return ret_eagain;
283 }
284
c69896a Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@639 5dc97367-97f1-...
alobbs authored
285 /* stat() the possible new path
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
286 */
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
287 cherokee_buffer_add_buffer (&conn->local_directory, index);
b39795e Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2238 5dc97367-97f1...
alobbs authored
288 ret = cherokee_io_stat (iocache, &conn->local_directory, use_iocache, &nocache_info, &io_entry, &info);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
289
06858f5 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@770 5dc97367-97f1-...
alobbs authored
290 exists = (ret == ret_ok);
291 is_dir = ((ret == ret_ok) && S_ISDIR(info->st_mode));
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
292
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
293 cherokee_iocache_entry_unref (&io_entry);
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
294 cherokee_buffer_drop_ending (&conn->local_directory, index->len);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
295
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
296 TRACE (ENTRIES, "trying index '%s', exists %d\n", index->buf, exists);
b7f7d10 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97f1-...
alobbs authored
297
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
298 /* If the file doesn't exist or it is a directory, try with the next one
299 */
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
300 if ((!exists) || (is_dir))
b7f7d10 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@313 5dc97367-97f1-...
alobbs authored
301 continue;
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
302
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
303 /* Add the index file to the request and clean up
304 */
51ed095 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1614 5dc97367-97f1...
alobbs authored
305 cherokee_buffer_drop_ending (&conn->local_directory, conn->request.len);
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
306
307 if (cherokee_buffer_is_empty (&conn->request_original)) {
308 cherokee_buffer_add_buffer (&conn->request_original, &conn->request);
a82df4d Antonio Pérez Original query string is now saved, like original request, and added to ...
skarcha authored
309 cherokee_buffer_add_buffer (&conn->query_string_original, &conn->query_string);
2bb4da7 Antonio Pérez git-svn-id: svn://cherokee-project.com/cherokee/trunk@2220 5dc97367-97f1...
skarcha authored
310 }
311
749f862 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@3336 5dc97367-97f1...
alobbs authored
312 cherokee_buffer_add_buffer (&conn->request, index);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
313
7a3e417 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1611 5dc97367-97f1...
alobbs authored
314 TRACE_CONN(conn);
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
315 return ret_eagain;
316 }
317
318 /* If the dir hasn't a index file, it uses dirlist
319 */
51ed095 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1614 5dc97367-97f1...
alobbs authored
320 cherokee_buffer_drop_ending (&conn->local_directory, conn->request.len);
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
321 if (PROP_COMMON(props)->allow_dirlist) {
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
322 return cherokee_handler_dirlist_new (hdl, cnt,
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
323 MODULE_PROPS(PROP_COMMON(props)->props_dirlist));
324 }
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
325
ca8859b Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2280 5dc97367-97f1...
alobbs authored
326 conn->error_code = http_access_denied;
327 return ret_error;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
328 }
329
330 /* Unknown request type
331 */
e52151f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2053 5dc97367-97f1...
alobbs authored
332 TRACE(ENTRIES, "Returns conn->error_code: %s\n", "http_unsupported_media_type");
9a294ab Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@1673 5dc97367-97f1...
alobbs authored
333
e52151f Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@2053 5dc97367-97f1...
alobbs authored
334 conn->error_code = http_unsupported_media_type;
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
335 return ret_error;
336 }
337
338
339
340 /* Library init function
341 */
342 static cherokee_boolean_t _common_is_init = false;
343
72f6444 Alvaro Lopez Ortega Clean up: Trims trailing spaces.
alobbs authored
344 void
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
345 PLUGIN_INIT_NAME(common) (cherokee_plugin_loader_t *loader)
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
346 {
347 if (_common_is_init) return;
348 _common_is_init = true;
349
350 /* Load the dependences
351 */
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
352 cherokee_plugin_loader_load (loader, "file");
353 cherokee_plugin_loader_load (loader, "dirlist");
ae9d971 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97f1-...
alobbs authored
354 }
b6c69ad Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@269 5dc97367-97f1-...
alobbs authored
355
b69d2e0 Alvaro Lopez Ortega git-svn-id: svn://cherokee-project.com/cherokee/trunk@476 5dc97367-97f1-...
alobbs authored
356 PLUGIN_INFO_HANDLER_EASY_INIT (common, http_all_methods);
Something went wrong with that request. Please try again.