Skip to content
Newer
Older
100644 519 lines (422 sloc) 11.1 KB
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
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 @alobbs Happy new year!
alobbs authored Jan 14, 2011
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
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 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored Jan 2, 2009
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
23 */
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
24
25 #include "common-internal.h"
26 #include "handler_ssi.h"
27
28 #include <sys/stat.h>
29
30 #include "util.h"
31 #include "server-protected.h"
32 #include "connection-protected.h"
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
33 #include "virtual_server.h"
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
34
35 #define ENTRIES "handler,ssi"
36
37 /* Plug-in initialization
38 */
39 PLUGIN_INFO_HANDLER_EASIEST_INIT (ssi, http_get | http_head);
40
41
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
42 typedef enum {
43 op_none,
44 op_include,
45 op_size,
46 op_lastmod
47 } operations_t;
48
49 typedef enum {
50 path_none,
51 path_file,
52 path_virtual
53 } path_type_t;
54
55
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
56 ret_t
57 cherokee_handler_ssi_new (cherokee_handler_t **hdl,
58 cherokee_connection_t *cnt,
59 cherokee_module_props_t *props)
60 {
61 CHEROKEE_NEW_STRUCT (n, handler_ssi);
62
63 /* Init the base class object
64 */
65 cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(ssi));
66
67 MODULE(n)->free = (module_func_free_t) cherokee_handler_ssi_free;
68 MODULE(n)->init = (handler_func_init_t) cherokee_handler_ssi_init;
69 HANDLER(n)->step = (handler_func_step_t) cherokee_handler_ssi_step;
70 HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_ssi_add_headers;
71
72 /* Supported features
c6dc1b3 @skarcha git-svn-id: svn://cherokee-project.com/cherokee/trunk@2647 5dc97367-9…
skarcha authored Dec 25, 2008
73 */
74 HANDLER(n)->support = hsupport_nothing;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
75
76 /* Init
77 */
78 n->mime = NULL;
79 cherokee_buffer_init (&n->dir);
80 cherokee_buffer_init (&n->source);
81 cherokee_buffer_init (&n->render);
82
83 /* Return the object
84 */
85 *hdl = HANDLER(n);
86 return ret_ok;
87 }
88
89
3bde750 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2293 5dc97367-9…
alobbs authored Nov 2, 2008
90 static ret_t
91 props_free (cherokee_handler_ssi_props_t *props)
92 {
93 return cherokee_handler_props_free_base (HANDLER_PROPS(props));
94 }
95
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
96 ret_t
97 cherokee_handler_ssi_configure (cherokee_config_node_t *conf,
98 cherokee_server_t *srv,
99 cherokee_module_props_t **_props)
100 {
3bde750 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2293 5dc97367-9…
alobbs authored Nov 2, 2008
101 cherokee_handler_ssi_props_t *props;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
102
3bde750 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2293 5dc97367-9…
alobbs authored Nov 2, 2008
103 UNUSED(srv);
1e47304 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-9…
alobbs authored Jan 14, 2009
104 UNUSED(conf);
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
105 UNUSED(props);
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
106
3bde750 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2293 5dc97367-9…
alobbs authored Nov 2, 2008
107 if (*_props == NULL) {
108 CHEROKEE_NEW_STRUCT (n, handler_ssi_props);
109
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
110 cherokee_module_props_init_base (MODULE_PROPS(n),
3bde750 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2293 5dc97367-9…
alobbs authored Nov 2, 2008
111 MODULE_PROPS_FREE(props_free));
112 n->foo = 1;
113 *_props = MODULE_PROPS(n);
114 }
115
116 props = PROP_SSI(*_props);
117 return ret_ok;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
118 }
119
120
121 static ret_t
122 get_pair (cherokee_buffer_t *key,
123 cherokee_buffer_t *pair)
124 {
125 char *i = key->buf;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
126
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
127 while ((*i != ' ') && *i)
128 i++;
129
130 cherokee_buffer_add (pair, key->buf, i - key->buf);
131 return ret_ok;
132 }
133
134 static ret_t
135 get_val (char *begin,
136 cherokee_buffer_t *val)
137 {
138 char *j;
139 char *i = begin;
140
141 /* Skip whites
142 */
143 while (*i == ' ')
144 i++;
145
146 /* Read value
147 */
148 if (*i == '"') {
149 /* The value is quoted */
150 i++;
151 j = i;
152 while ((*j != '"') && *j)
153 j++;
154 } else {
155 /* The value is not quoted */
156 j = i;
157 while ((*j != ' ') && *j)
158 j++;
159 }
160
161 cherokee_buffer_add (val, i, j-i);
162 return ret_ok;
163 }
164
165
166 static ret_t
167 parse (cherokee_handler_ssi_t *hdl,
168 cherokee_buffer_t *in,
169 cherokee_buffer_t *out)
170 {
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
171 ret_t ret;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
172 char *p, *q;
173 char *begin;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
174 int re;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
175 cuint_t len;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
176 operations_t op;
177 path_type_t path;
178 struct stat info;
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
179 cherokee_boolean_t ignore;
180 cherokee_buffer_t key = CHEROKEE_BUF_INIT;
181 cherokee_buffer_t val = CHEROKEE_BUF_INIT;
182 cherokee_buffer_t pair = CHEROKEE_BUF_INIT;
183 cherokee_buffer_t fpath = CHEROKEE_BUF_INIT;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
184
185 q = in->buf;
186
187 while (true) {
188 begin = q;
189
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
190 /* Check the end
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
191 */
192 if (q >= in->buf + in->len)
193 break;
194
195 /* Find next SSI tag
196 */
197 p = strstr (q, "<!--#");
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
198 if (p == NULL) {
199 cherokee_buffer_add (out, begin, (in->buf + in->len) - begin);
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
200 ret = ret_ok;
201 goto out;
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
202 }
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
203
204 q = strstr (p + 5, "-->");
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
205 if (q == NULL) {
206 ret = ret_error;
207 goto out;
208 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
209
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
210 len = q - p;
211 len -= 5;
212
213 cherokee_buffer_clean (&key);
214 cherokee_buffer_add (&key, p+5, len);
215 cherokee_buffer_trim (&key);
216
217 q += 3;
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
218 TRACE(ENTRIES, "Found key '%s'\n", key.buf);
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
219
220 /* Add the previous chunk
221 */
222 cherokee_buffer_add (out, begin, p - begin);
223
224 /* Check element
225 */
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
226 op = op_none;
227 ignore = false;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
228
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
229 if (strncmp (key.buf, "include", 7) == 0) {
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
230 op = op_include;
231 len = 7;
232 } else if (strncmp (key.buf, "fsize", 5) == 0) {
233 op = op_size;
234 len = 5;
235 } else if (strncmp (key.buf, "flastmod", 8) == 0) {
236 op = op_lastmod;
237 len = 8;
238 } else {
3272909 @alobbs More PRINT_* calls converted to LOG_*
alobbs authored Nov 16, 2009
239 LOG_ERROR (CHEROKEE_ERROR_HANDLER_SSI_PROPERTY, key.buf);
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
240 }
241
242 /* Deeper parsing
243 */
244 path = path_none;
245
246 switch (op) {
247 case op_size:
248 case op_include:
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
249 case op_lastmod:
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
250 /* Read a property key
251 */
252 cherokee_buffer_move_to_begin (&key, len);
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
253 cherokee_buffer_trim (&key);
254
255 cherokee_buffer_clean (&pair);
256 get_pair (&key, &pair);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
257
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
258 cherokee_buffer_drop_ending (&key, pair.len);
259 cherokee_buffer_trim (&key);
260
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
261 /* Parse the property
262 */
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
263 if (strncmp (pair.buf, "file=", 5) == 0) {
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
264 path = path_file;
265 len = 5;
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
266 } else if (strncmp (pair.buf, "virtual=", 8) == 0) {
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
267 path = path_virtual;
268 len = 8;
269 }
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
270
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
271 cherokee_buffer_clean (&val);
272 get_val (pair.buf + len, &val);
273
274 cherokee_buffer_clean (&fpath);
275
276 switch (path) {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
277 case path_file:
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
278 cherokee_buffer_add_buffer (&fpath, &hdl->dir);
279 cherokee_buffer_add_char (&fpath, '/');
280 cherokee_buffer_add_buffer (&fpath, &val);
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
281
282 TRACE(ENTRIES, "Path: file '%s'\n", fpath.buf);
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
283 break;
284 case path_virtual:
285 cherokee_buffer_add_buffer (&fpath, &HANDLER_VSRV(hdl)->root);
286 cherokee_buffer_add_char (&fpath, '/');
287 cherokee_buffer_add_buffer (&fpath, &val);
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
288
289 TRACE(ENTRIES, "Path: virtual '%s'\n", fpath.buf);
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
290 break;
291 default:
d088203 @alobbs "Null pointer 'fpath.buf' that comes from line 182 may be dereferenced
alobbs authored May 22, 2011
292 ignore = true;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
293 SHOULDNT_HAPPEN;
294 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
295
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
296 /* Path security check: ensure that the file
297 * to include is inside the document root.
298 */
299 if (! cherokee_buffer_is_empty (&fpath)) {
300 cherokee_path_short (&fpath);
301
302 if (fpath.len < HANDLER_VSRV(hdl)->root.len) {
303 ignore = true;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
304
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
305 } else {
306 re = strncmp (fpath.buf,
307 HANDLER_VSRV(hdl)->root.buf,
308 HANDLER_VSRV(hdl)->root.len);
309 if (re != 0) {
310 ignore = true;
311 }
312 }
313 }
0621616 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2291 5dc97367-9…
alobbs authored Nov 2, 2008
314
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
315 /* Perform the operation
316 */
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
317 if (! ignore) {
318 switch (op) {
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
319 case op_include: {
320 cherokee_buffer_t file_content = CHEROKEE_BUF_INIT;
321
322 ret = cherokee_buffer_read_file (&file_content, fpath.buf);
323 if (unlikely (ret != ret_ok)) {
6b479aa @skinkie Memory leak. Dynamic memory stored in 'file_content.buf' allocated th…
skinkie authored May 21, 2011
324 cherokee_buffer_mrproper (&file_content);
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
325 ret = ret_error;
326 goto out;
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
327 }
328
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
329 TRACE(ENTRIES, "Including file '%s'\n", fpath.buf);
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
330
331 ret = parse (hdl, &file_content, out);
332 if (unlikely (ret != ret_ok)) {
344c186 @alobbs "Memory leak. Dynamic memory stored in 'file_content.buf' allocated
alobbs authored May 22, 2011
333 cherokee_buffer_mrproper (&file_content);
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
334 ret = ret_error;
335 goto out;
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
336 }
337
338 cherokee_buffer_mrproper (&file_content);
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
339 break;
93f52e1 @alobbs Implements recursive file inclusions in the SSI handler.
alobbs authored May 12, 2011
340 }
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
341
342 case op_size:
343 TRACE(ENTRIES, "Including file size '%s'\n", fpath.buf);
344 re = cherokee_stat (fpath.buf, &info);
345 if (re >=0) {
346 cherokee_buffer_add_ullong10 (out, info.st_size);
347 }
348 break;
349
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
350 case op_lastmod:
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
351 TRACE(ENTRIES, "Including file modification date '%s'\n", fpath.buf);
352 re = cherokee_stat (fpath.buf, &info);
353 if (re >= 0) {
748a4dc @alobbs Replace a couple of calls to localtime() by cherokee_localtime() and
alobbs authored May 21, 2011
354 struct tm *ltime;
355 struct tm ltime_buf;
356 char tmp[50];
357
358 ltime = cherokee_localtime (&info.st_mtime, &ltime_buf);
359 if (ltime != NULL) {
360 strftime (tmp, sizeof(tmp), "%d-%b-%Y %H:%M", ltime);
6b8a513 @alobbs "'tmp' array elements might be used uninitialized in this function."
alobbs authored May 27, 2011
361 cherokee_buffer_add (out, tmp, strlen(tmp));
748a4dc @alobbs Replace a couple of calls to localtime() by cherokee_localtime() and
alobbs authored May 21, 2011
362 }
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
363 }
364 break;
365 default:
366 SHOULDNT_HAPPEN;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
367 }
08d7e6d @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2307 5dc97367-9…
alobbs authored Nov 3, 2008
368 } /* !ignore */
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
369
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
370 break;
55a35be @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2292 5dc97367-9…
alobbs authored Nov 2, 2008
371 default:
372 SHOULDNT_HAPPEN;
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
373 } /* switch(op) */
374 } /* while */
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
375
f6c226e @alobbs Fixes a few (minor) memory leaks in the SSI handler.
alobbs authored Oct 7, 2011
376 ret = ret_ok;
377
378 out:
379 cherokee_buffer_mrproper (&key);
380 cherokee_buffer_mrproper (&val);
381 cherokee_buffer_mrproper (&pair);
382 cherokee_buffer_mrproper (&fpath);
383
384 return ret;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
385 }
386
387
388 static ret_t
389 init (cherokee_handler_ssi_t *hdl,
390 cherokee_buffer_t *local_path)
391 {
392 int re;
393 ret_t ret;
394 cherokee_connection_t *conn = HANDLER_CONN(hdl);
395
396 /* Stat the file
397 */
147fcf8 @alobbs {l,f,}stat() related fix. Ensure the EINTR signal is handler
alobbs authored Sep 22, 2010
398 re = cherokee_stat (local_path->buf, &hdl->cache_info);
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
399 if (re < 0) {
400 switch (errno) {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
401 case ENOENT:
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
402 conn->error_code = http_not_found;
403 break;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
404 case EACCES:
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
405 conn->error_code = http_access_denied;
406 break;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
407 default:
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
408 conn->error_code = http_internal_error;
409 }
410 return ret_error;
411 }
412
413 /* Read the file
414 */
415 ret = cherokee_buffer_read_file (&hdl->source, local_path->buf);
416 if (ret != ret_ok)
417 return ret_error;
418
419 /* Render
420 */
421 ret = parse (hdl, &hdl->source, &hdl->render);
422 if (ret != ret_ok)
423 return ret;
424
425 return ret_ok;
426 }
427
428
429 ret_t
430 cherokee_handler_ssi_init (cherokee_handler_ssi_t *hdl)
431 {
432 ret_t ret;
433 cherokee_connection_t *conn = HANDLER_CONN(hdl);
434
435 /* Build the local directory
436 */
437 cherokee_buffer_add_buffer (&hdl->dir, &conn->local_directory);
761a7c3 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2296 5dc97367-9…
alobbs authored Nov 3, 2008
438 cherokee_buffer_add_buffer (&hdl->dir, &conn->request);
439
440 while (true) {
441 if (cherokee_buffer_is_empty (&hdl->dir))
442 return ret_error;
443
444 if (cherokee_buffer_is_ending (&hdl->dir, '/'))
445 break;
446
447 cherokee_buffer_drop_ending (&hdl->dir, 1);
448 }
449
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
450
451 /* Real init function
452 */
453 cherokee_buffer_add_buffer (&conn->local_directory, &conn->request);
454 ret = init (hdl, &conn->local_directory);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
455 cherokee_buffer_drop_ending (&conn->local_directory, conn->request.len);
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
456
457 return ret;
458 }
459
460
461 ret_t
462 cherokee_handler_ssi_free (cherokee_handler_ssi_t *hdl)
463 {
464 cherokee_buffer_mrproper (&hdl->dir);
465 cherokee_buffer_mrproper (&hdl->source);
466 cherokee_buffer_mrproper (&hdl->render);
467 return ret_ok;
468 }
469
470
471 ret_t
472 cherokee_handler_ssi_step (cherokee_handler_ssi_t *hdl,
473 cherokee_buffer_t *buffer)
474 {
475 cherokee_buffer_add_buffer (buffer, &hdl->render);
476 return ret_eof_have_data;
477 }
478
479
480 ret_t
481 cherokee_handler_ssi_add_headers (cherokee_handler_ssi_t *hdl,
482 cherokee_buffer_t *buffer)
483 {
0b6e52e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2309 5dc97367-9…
alobbs authored Nov 3, 2008
484 ret_t ret;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
485 char *ext;
486 cherokee_buffer_t *mime = NULL;
487 cherokee_server_t *srv = HANDLER_SRV(hdl);
1e47304 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2701 5dc97367-9…
alobbs authored Jan 14, 2009
488 cherokee_connection_t *conn = HANDLER_CONN(hdl);;
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
489
490 /* MIME type
491 */
492 if (srv->mime != NULL) {
493 ext = strrchr (conn->request.buf, '.');
494 if (ext == NULL)
495 return ret_ok;
496
0b6e52e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2309 5dc97367-9…
alobbs authored Nov 3, 2008
497 ret = cherokee_mime_get_by_suffix (srv->mime, ext+1, &hdl->mime);
498 if (ret == ret_ok) {
499 cherokee_mime_entry_get_type (hdl->mime, &mime);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
500
0b6e52e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2309 5dc97367-9…
alobbs authored Nov 3, 2008
501 cherokee_buffer_add_str (buffer, "Content-Type: ");
502 cherokee_buffer_add_buffer (buffer, mime);
503 cherokee_buffer_add_str (buffer, CRLF);
504 }
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
505 }
506
507 /* Length
508 */
4d96114 @skarcha git-svn-id: svn://cherokee-project.com/cherokee/trunk@2646 5dc97367-9…
skarcha authored Dec 23, 2008
509 if (cherokee_connection_should_include_length(conn)) {
c6dc1b3 @skarcha git-svn-id: svn://cherokee-project.com/cherokee/trunk@2647 5dc97367-9…
skarcha authored Dec 25, 2008
510 HANDLER(hdl)->support = hsupport_length;
511
4d96114 @skarcha git-svn-id: svn://cherokee-project.com/cherokee/trunk@2646 5dc97367-9…
skarcha authored Dec 23, 2008
512 cherokee_buffer_add_str (buffer, "Content-Length: ");
513 cherokee_buffer_add_ullong10(buffer, (cullong_t) hdl->render.len);
514 cherokee_buffer_add_str (buffer, CRLF);
515 }
352fd27 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2289 5dc97367-9…
alobbs authored Nov 2, 2008
516
517 return ret_ok;
518 }
Something went wrong with that request. Please try again.