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