- fix output buffering, default mime type
[m6w6/ext-http] / http_response_object.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
22 #include "php.h"
23
24 #ifdef ZEND_ENGINE_2
25
26 #include "SAPI.h"
27 #include "php_ini.h"
28
29 #include "php_http.h"
30 #include "php_http_api.h"
31 #include "php_http_std_defs.h"
32 #include "php_http_response_object.h"
33 #include "php_http_exception_object.h"
34 #include "php_http_send_api.h"
35 #include "php_http_cache_api.h"
36
37 #include "missing.h"
38
39 ZEND_EXTERN_MODULE_GLOBALS(http);
40
41 #define USE_STATIC_PROP() USE_STATIC_PROP_EX(http_response_object_ce)
42 #define GET_STATIC_PROP(n) *GET_STATIC_PROP_EX(http_response_object_ce, n)
43 #define SET_STATIC_PROP(n, v) SET_STATIC_PROP_EX(http_response_object_ce, n, v)
44 #define SET_STATIC_PROP_STRING(n, s, d) SET_STATIC_PROP_STRING_EX(http_response_object_ce, n, s, d)
45 #define SET_STATIC_PROP_STRINGL(n, s, l, d) SET_STATIC_PROP_STRINGL_EX(http_response_object_ce, n, s, l, d)
46
47 #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args)
48 #define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpResponse, method, ret_ref)
49 #define HTTP_RESPONSE_ME(method, visibility) PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC)
50
51 HTTP_EMPTY_ARGS(getETag, 0);
52 HTTP_BEGIN_ARGS(setETag, 1)
53 HTTP_ARG_VAL(etag, 0)
54 HTTP_END_ARGS;
55
56 HTTP_EMPTY_ARGS(getCache, 0);
57 HTTP_BEGIN_ARGS(setCache, 1)
58 HTTP_ARG_VAL(cache, 0)
59 HTTP_END_ARGS;
60
61 HTTP_EMPTY_ARGS(getGzip, 0);
62 HTTP_BEGIN_ARGS(setGzip, 1)
63 HTTP_ARG_VAL(gzip, 0)
64 HTTP_END_ARGS;
65
66 HTTP_EMPTY_ARGS(getCacheControl, 0);
67 HTTP_BEGIN_ARGS(setCacheControl, 1)
68 HTTP_ARG_VAL(cache_control, 0)
69 HTTP_ARG_VAL(max_age, 0)
70 HTTP_END_ARGS;
71
72 HTTP_EMPTY_ARGS(getContentType, 0);
73 HTTP_BEGIN_ARGS(setContentType, 1)
74 HTTP_ARG_VAL(content_type, 0)
75 HTTP_END_ARGS;
76
77 HTTP_EMPTY_ARGS(getContentDisposition, 0);
78 HTTP_BEGIN_ARGS(setContentDisposition, 1)
79 HTTP_ARG_VAL(filename, 0)
80 HTTP_ARG_VAL(send_inline, 0)
81 HTTP_END_ARGS;
82
83 HTTP_EMPTY_ARGS(getThrottleDelay, 0);
84 HTTP_BEGIN_ARGS(setThrottleDelay, 1)
85 HTTP_ARG_VAL(seconds, 0)
86 HTTP_END_ARGS;
87
88 HTTP_EMPTY_ARGS(getBufferSize, 0);
89 HTTP_BEGIN_ARGS(setBufferSize, 1)
90 HTTP_ARG_VAL(bytes, 0)
91 HTTP_END_ARGS;
92
93 HTTP_EMPTY_ARGS(getData, 0);
94 HTTP_BEGIN_ARGS(setData, 1)
95 HTTP_ARG_VAL(data, 0)
96 HTTP_END_ARGS;
97
98 HTTP_EMPTY_ARGS(getStream, 0);
99 HTTP_BEGIN_ARGS(setStream, 1)
100 HTTP_ARG_VAL(stream, 0)
101 HTTP_END_ARGS;
102
103 HTTP_EMPTY_ARGS(getFile, 0);
104 HTTP_BEGIN_ARGS(setFile, 1)
105 HTTP_ARG_VAL(filepath, 0)
106 HTTP_END_ARGS;
107
108 HTTP_BEGIN_ARGS(send, 0)
109 HTTP_ARG_VAL(clean_ob, 0)
110 HTTP_END_ARGS;
111
112 #define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C)
113 static inline void _http_response_object_declare_default_properties(TSRMLS_D);
114
115 zend_class_entry *http_response_object_ce;
116 zend_function_entry http_response_object_fe[] = {
117
118 HTTP_RESPONSE_ME(setETag, ZEND_ACC_PUBLIC)
119 HTTP_RESPONSE_ME(getETag, ZEND_ACC_PUBLIC)
120
121 HTTP_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC)
122 HTTP_RESPONSE_ME(getContentDisposition, ZEND_ACC_PUBLIC)
123
124 HTTP_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC)
125 HTTP_RESPONSE_ME(getContentType, ZEND_ACC_PUBLIC)
126
127 HTTP_RESPONSE_ME(setCache, ZEND_ACC_PUBLIC)
128 HTTP_RESPONSE_ME(getCache, ZEND_ACC_PUBLIC)
129
130 HTTP_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC)
131 HTTP_RESPONSE_ME(getCacheControl, ZEND_ACC_PUBLIC)
132
133 HTTP_RESPONSE_ME(setGzip, ZEND_ACC_PUBLIC)
134 HTTP_RESPONSE_ME(getGzip, ZEND_ACC_PUBLIC)
135
136 HTTP_RESPONSE_ME(setThrottleDelay, ZEND_ACC_PUBLIC)
137 HTTP_RESPONSE_ME(getThrottleDelay, ZEND_ACC_PUBLIC)
138
139 HTTP_RESPONSE_ME(setBufferSize, ZEND_ACC_PUBLIC)
140 HTTP_RESPONSE_ME(getBufferSize, ZEND_ACC_PUBLIC)
141
142 HTTP_RESPONSE_ME(setData, ZEND_ACC_PUBLIC)
143 HTTP_RESPONSE_ME(getData, ZEND_ACC_PUBLIC)
144
145 HTTP_RESPONSE_ME(setFile, ZEND_ACC_PUBLIC)
146 HTTP_RESPONSE_ME(getFile, ZEND_ACC_PUBLIC)
147
148 HTTP_RESPONSE_ME(setStream, ZEND_ACC_PUBLIC)
149 HTTP_RESPONSE_ME(getStream, ZEND_ACC_PUBLIC)
150
151 HTTP_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
152
153 {NULL, NULL, NULL}
154 };
155 static zend_object_handlers http_response_object_handlers;
156
157 void _http_response_object_init(INIT_FUNC_ARGS)
158 {
159 HTTP_REGISTER_CLASS(HttpResponse, http_response_object, NULL, 0);
160 http_response_object_declare_default_properties();
161 }
162
163 static inline void _http_response_object_declare_default_properties(TSRMLS_D)
164 {
165 zend_class_entry *ce = http_response_object_ce;
166
167 DCL_STATIC_PROP(PRIVATE, bool, sent, 0);
168 DCL_STATIC_PROP(PRIVATE, bool, catch, 0);
169 DCL_STATIC_PROP(PRIVATE, long, mode, -1);
170 DCL_STATIC_PROP(PROTECTED, bool, cache, 0);
171 DCL_STATIC_PROP(PROTECTED, bool, gzip, 0);
172 DCL_STATIC_PROP(PROTECTED, long, stream, 0);
173 DCL_STATIC_PROP_N(PROTECTED, file);
174 DCL_STATIC_PROP_N(PROTECTED, data);
175 DCL_STATIC_PROP_N(PROTECTED, eTag);
176 DCL_STATIC_PROP(PROTECTED, long, lastModified, 0);
177 DCL_STATIC_PROP_N(PROTECTED, cacheControl);
178 DCL_STATIC_PROP_N(PROTECTED, contentType);
179 DCL_STATIC_PROP_N(PROTECTED, contentDisposition);
180 DCL_STATIC_PROP(PROTECTED, long, bufferSize, HTTP_SENDBUF_SIZE);
181 DCL_STATIC_PROP(PROTECTED, double, throttleDelay, 0.0);
182 }
183
184 /* ### USERLAND ### */
185
186 /* {{{ proto bool HttpResponse::setCache(bool cache)
187 *
188 * Whether it sould be attempted to cache the entitity.
189 * This will result in necessary caching headers and checks of clients
190 * "If-Modified-Since" and "If-None-Match" headers. If one of those headers
191 * matches a "304 Not Modified" status code will be issued.
192 *
193 * NOTE: If you're using sessions, be shure that you set session.cache_limiter
194 * to something more appropriate than "no-cache"!
195 */
196 PHP_METHOD(HttpResponse, setCache)
197 {
198 zend_bool do_cache = 0;
199
200 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_cache)) {
201 RETURN_FALSE;
202 }
203
204 ZVAL_BOOL(GET_STATIC_PROP(cache), do_cache);
205 RETURN_TRUE;
206 }
207 /* }}} */
208
209 /* {{{ proto bool HttpResponse::getCache()
210 *
211 * Get current caching setting.
212 */
213 PHP_METHOD(HttpResponse, getCache)
214 {
215 NO_ARGS;
216
217 IF_RETVAL_USED {
218 RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(cache)));
219 }
220 }
221 /* }}}*/
222
223 /* {{{ proto bool HttpResponse::setGzip(bool gzip)
224 *
225 * Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.
226 */
227 PHP_METHOD(HttpResponse, setGzip)
228 {
229 zend_bool do_gzip = 0;
230
231 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_gzip)) {
232 RETURN_FALSE;
233 }
234
235 ZVAL_BOOL(GET_STATIC_PROP(gzip), do_gzip);
236 RETURN_TRUE;
237 }
238 /* }}} */
239
240 /* {{{ proto bool HttpResponse::getGzip()
241 *
242 * Get current gzipping setting.
243 */
244 PHP_METHOD(HttpResponse, getGzip)
245 {
246 NO_ARGS;
247
248 IF_RETVAL_USED {
249 RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(gzip)));
250 }
251 }
252 /* }}} */
253
254 /* {{{ proto bool HttpResponse::setCacheControl(string control[, long max_age = 0])
255 *
256 * Set a custom cache-control header, usually being "private" or "public";
257 * The max_age parameter controls how long the cache entry is valid on the client side.
258 */
259 PHP_METHOD(HttpResponse, setCacheControl)
260 {
261 char *ccontrol, *cctl;
262 int cc_len;
263 long max_age = 0;
264
265 #define HTTP_CACHECONTROL_TEMPLATE "%s, must-revalidate, max_age=%ld"
266
267 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &ccontrol, &cc_len, &max_age)) {
268 RETURN_FALSE;
269 }
270
271 if (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache")) {
272 http_error_ex(E_WARNING, HTTP_E_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
273 RETURN_FALSE;
274 } else {
275 USE_STATIC_PROP();
276 spprintf(&cctl, 0, HTTP_CACHECONTROL_TEMPLATE, ccontrol, max_age);
277 SET_STATIC_PROP_STRING(cacheControl, cctl, 0);
278 RETURN_TRUE;
279 }
280 }
281 /* }}} */
282
283 /* {{{ proto string HttpResponse::getCacheControl()
284 *
285 * Get current Cache-Control header setting.
286 */
287 PHP_METHOD(HttpResponse, getCacheControl)
288 {
289 NO_ARGS;
290
291 IF_RETVAL_USED {
292 zval *ccontrol = GET_STATIC_PROP(cacheControl);
293 RETURN_STRINGL(Z_STRVAL_P(ccontrol), Z_STRLEN_P(ccontrol), 1);
294 }
295 }
296 /* }}} */
297
298 /* {{{ proto bool HttpResponse::setContentType(string content_type)
299 *
300 * Set the content-type of the sent entity.
301 */
302 PHP_METHOD(HttpResponse, setContentType)
303 {
304 char *ctype;
305 int ctype_len;
306
307 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ctype_len)) {
308 RETURN_FALSE;
309 }
310
311 if (!strchr(ctype, '/')) {
312 http_error_ex(E_WARNING, HTTP_E_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype);
313 RETURN_FALSE;
314 }
315
316 USE_STATIC_PROP();
317 SET_STATIC_PROP_STRINGL(contentType, ctype, ctype_len, 1);
318 RETURN_TRUE;
319 }
320 /* }}} */
321
322 /* {{{ proto string HttpResponse::getContentType()
323 *
324 * Get current Content-Type header setting.
325 */
326 PHP_METHOD(HttpResponse, getContentType)
327 {
328 NO_ARGS;
329
330 IF_RETVAL_USED {
331 zval *ctype = GET_STATIC_PROP(contentType);
332 RETURN_STRINGL(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
333 }
334 }
335 /* }}} */
336
337 /* {{{ proto bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
338 *
339 * Set the Content-Disposition of the sent entity. This setting aims to suggest
340 * the receiveing user agent how to handle the sent entity; usually the client
341 * will show the user a "Save As..." popup.
342 */
343 PHP_METHOD(HttpResponse, setContentDisposition)
344 {
345 char *file, *cd;
346 int file_len;
347 zend_bool send_inline = 0;
348
349 #define HTTP_CONTENTDISPOSITION_TEMPLATE "%s; filename=\"%s\""
350
351 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &send_inline)) {
352 RETURN_FALSE;
353 }
354
355 spprintf(&cd, 0, HTTP_CONTENTDISPOSITION_TEMPLATE, send_inline ? "inline" : "attachment", file);
356 SET_STATIC_PROP_STRING(contentDisposition, cd, 0);
357 RETURN_TRUE;
358 }
359 /* }}} */
360
361 /* {{{ proto string HttpResponse::getContentDisposition()
362 *
363 * Get current Content-Disposition setting.
364 */
365 PHP_METHOD(HttpResponse, getContentDisposition)
366 {
367 NO_ARGS;
368
369 IF_RETVAL_USED {
370 zval *cd = GET_STATIC_PROP(contentDisposition);
371 RETURN_STRINGL(Z_STRVAL_P(cd), Z_STRLEN_P(cd), 1);
372 }
373 }
374 /* }}} */
375
376 /* {{{ proto bool HttpResponse::setETag(string etag)
377 *
378 * Set a custom ETag. Use this only if you know what you're doing.
379 */
380 PHP_METHOD(HttpResponse, setETag)
381 {
382 char *etag;
383 int etag_len;
384
385 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len)) {
386 RETURN_FALSE;
387 }
388
389 USE_STATIC_PROP();
390 SET_STATIC_PROP_STRINGL(eTag, etag, etag_len, 1);
391 RETURN_TRUE;
392 }
393 /* }}} */
394
395 /* {{{ proto string HttpResponse::getETag()
396 *
397 * Get the previously set custom ETag.
398 */
399 PHP_METHOD(HttpResponse, getETag)
400 {
401 NO_ARGS;
402
403 IF_RETVAL_USED {
404 zval *etag = GET_STATIC_PROP(eTag);
405 RETURN_STRINGL(Z_STRVAL_P(etag), Z_STRLEN_P(etag), 1);
406 }
407 }
408 /* }}} */
409
410 /* {{{ proto void HttpResponse::setThrottleDelay(double seconds)
411 *
412 */
413 PHP_METHOD(HttpResponse, setThrottleDelay)
414 {
415 double seconds;
416
417 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &seconds)) {
418 ZVAL_DOUBLE(GET_STATIC_PROP(throttleDelay), seconds);
419 }
420 }
421 /* }}} */
422
423 /* {{{ proto double HttpResponse::getThrottleDelay()
424 *
425 */
426 PHP_METHOD(HttpResponse, getThrottleDelay)
427 {
428 NO_ARGS;
429
430 IF_RETVAL_USED {
431 RETURN_DOUBLE(Z_DVAL_P(GET_STATIC_PROP(throttleDelay)));
432 }
433 }
434 /* }}} */
435
436 /* {{{ proto void HttpResponse::setBufferSize(long bytes)
437 *
438 */
439 PHP_METHOD(HttpResponse, setBufferSize)
440 {
441 long bytes;
442
443 if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &bytes)) {
444 ZVAL_LONG(GET_STATIC_PROP(bufferSize), bytes);
445 }
446 }
447 /* }}} */
448
449 /* {{{ proto long HttpResponse::getBufferSize()
450 *
451 */
452 PHP_METHOD(HttpResponse, getBufferSize)
453 {
454 NO_ARGS;
455
456 IF_RETVAL_USED {
457 RETURN_LONG(Z_LVAL_P(GET_STATIC_PROP(bufferSize)));
458 }
459 }
460 /* }}} */
461
462 /* {{{ proto bool HttpResponse::setData(string data)
463 *
464 * Set the data to be sent.
465 */
466 PHP_METHOD(HttpResponse, setData)
467 {
468 zval *the_data, **data;
469
470 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_data)) {
471 RETURN_FALSE;
472 }
473 convert_to_string_ex(&the_data);
474
475 USE_STATIC_PROP();
476 SET_STATIC_PROP(data, the_data);
477 ZVAL_LONG(GET_STATIC_PROP(lastModified), http_last_modified(the_data, SEND_DATA));
478 ZVAL_LONG(GET_STATIC_PROP(mode), SEND_DATA);
479 RETURN_TRUE;
480 }
481 /* }}} */
482
483 /* {{{ proto string HttpResponse::getData()
484 *
485 * Get the previously set data to be sent.
486 */
487 PHP_METHOD(HttpResponse, getData)
488 {
489 NO_ARGS;
490
491 IF_RETVAL_USED {
492 zval *the_data = GET_STATIC_PROP(data);
493 RETURN_STRINGL(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), 1);
494 }
495 }
496 /* }}} */
497
498 /* {{{ proto bool HttpResponse::setStream(resource stream)
499 *
500 * Set the resource to be sent.
501 */
502 PHP_METHOD(HttpResponse, setStream)
503 {
504 zval *the_stream;
505 php_stream *the_real_stream;
506
507 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &the_stream)) {
508 RETURN_FALSE;
509 }
510
511 USE_STATIC_PROP();
512 php_stream_from_zval(the_real_stream, &the_stream);
513 ZVAL_LONG(GET_STATIC_PROP(stream), Z_LVAL_P(the_stream));
514 ZVAL_LONG(GET_STATIC_PROP(lastModified), http_last_modified(the_real_stream, SEND_RSRC));
515 ZVAL_LONG(GET_STATIC_PROP(mode), SEND_RSRC);
516 RETURN_TRUE;
517 }
518 /* }}} */
519
520 /* {{{ proto resource HttpResponse::getStream()
521 *
522 * Get the previously set resource to be sent.
523 */
524 PHP_METHOD(HttpResponse, getStream)
525 {
526 NO_ARGS;
527
528 IF_RETVAL_USED {
529 RETURN_RESOURCE(Z_LVAL_P(GET_STATIC_PROP(stream)));
530 }
531 }
532 /* }}} */
533
534 /* {{{ proto bool HttpResponse::setFile(string file)
535 *
536 * Set the file to be sent.
537 */
538 PHP_METHOD(HttpResponse, setFile)
539 {
540 zval *the_file;
541
542 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_file)) {
543 RETURN_FALSE;
544 }
545
546 convert_to_string_ex(&the_file);
547 USE_STATIC_PROP();
548 SET_STATIC_PROP(file, the_file);
549 ZVAL_LONG(GET_STATIC_PROP(lastModified), http_last_modified(the_file, -1));
550 ZVAL_LONG(GET_STATIC_PROP(mode), -1);
551
552 RETURN_TRUE;
553 }
554 /* }}} */
555
556 /* {{{ proto string HttpResponse::getFile()
557 *
558 * Get the previously set file to be sent.
559 */
560 PHP_METHOD(HttpResponse, getFile)
561 {
562 NO_ARGS;
563
564 IF_RETVAL_USED {
565 zval *the_file = GET_STATIC_PROP(file);
566 RETURN_STRINGL(Z_STRVAL_P(the_file), Z_STRLEN_P(the_file), 1);
567 }
568 }
569 /* }}} */
570
571 /* {{{ proto bool HttpResponse::send([bool clean_ob = true])
572 *
573 * Finally send the entity.
574 */
575 PHP_METHOD(HttpResponse, send)
576 {
577 zval *do_cache, *do_gzip;
578 zend_bool clean_ob = 1;
579
580 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) {
581 RETURN_FALSE;
582 }
583
584 if (clean_ob) {
585 /* interrupt on-the-fly etag generation */
586 HTTP_G(etag).started = 0;
587 /* discard previous output buffers */
588 php_end_ob_buffers(0 TSRMLS_CC);
589 }
590
591 /* gzip */
592 if (Z_LVAL_P(GET_STATIC_PROP(gzip))) {
593 php_start_ob_buffer_named("ob_gzhandler", 0, 1 TSRMLS_CC);
594 } else {
595 php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC);
596 }
597
598 /* caching */
599 if (Z_LVAL_P(GET_STATIC_PROP(cache))) {
600 char *cc_hdr;
601 int cc_len;
602 zval *cctl, *etag, *lmod;
603
604 etag = GET_STATIC_PROP(eTag);
605 lmod = GET_STATIC_PROP(lastModified);
606 cctl = GET_STATIC_PROP(cacheControl);
607
608 http_cache_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
609 http_cache_last_modified(Z_LVAL_P(lmod), Z_LVAL_P(lmod) ? Z_LVAL_P(lmod) : time(NULL), Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
610 }
611
612 /* content type */
613 {
614 zval *ctype = GET_STATIC_PROP(contentType);
615 if (Z_STRLEN_P(ctype)) {
616 http_send_content_type(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype));
617 } else {
618 char *ctypes = INI_STR("default_mimetype");
619 size_t ctlen = ctypes ? strlen(ctypes) : 0;
620
621 if (ctlen) {
622 http_send_content_type(ctypes, ctlen);
623 } else {
624 http_send_content_type("application/x-octetstream", lenof("application/x-octetstream"));
625 }
626 }
627 }
628
629 /* content disposition */
630 {
631 zval *cd = GET_STATIC_PROP(contentDisposition);
632 if (Z_STRLEN_P(cd)) {
633 char *cds;
634
635 spprintf(&cds, 0, "Content-Disposition: %s", Z_STRVAL_P(cd));
636 http_send_header(cds);
637 efree(cds);
638 }
639 }
640
641 /* throttling */
642 {
643 HTTP_G(send).buffer_size = Z_LVAL_P(GET_STATIC_PROP(bufferSize));
644 HTTP_G(send).throttle_delay = Z_DVAL_P(GET_STATIC_PROP(throttleDelay));
645 }
646
647 /* send */
648 {
649 switch (Z_LVAL_P(GET_STATIC_PROP(mode)))
650 {
651 case SEND_DATA:
652 {
653 zval *zdata = GET_STATIC_PROP(data);
654 RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
655 }
656
657 case SEND_RSRC:
658 {
659 php_stream *the_real_stream;
660 zval *the_stream = GET_STATIC_PROP(stream);
661 php_stream_from_zval(the_real_stream, &the_stream);
662 RETURN_SUCCESS(http_send_stream(the_real_stream));
663 }
664
665 default:
666 {
667 RETURN_SUCCESS(http_send_file(Z_STRVAL_P(GET_STATIC_PROP(file))));
668 }
669 }
670 }
671 }
672 /* }}} */
673
674 #endif /* ZEND_ENGINE_2 */
675
676 /*
677 * Local variables:
678 * tab-width: 4
679 * c-basic-offset: 4
680 * End:
681 * vim600: noet sw=4 ts=4 fdm=marker
682 * vim<600: noet sw=4 ts=4
683 */
684