X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_response_object.c;h=e255989e7fbcc21c4fb84b139cf0d0a4c7b4d218;hp=0e1eb29abd7455fdb3a26c9756722cc1498a3a30;hb=656d8e1b62f2fd578b2b0943e6a09ac13bab4f70;hpb=b63e146a77c6512cae1574c0bb520b3a7bbec1e7 diff --git a/http_response_object.c b/http_response_object.c index 0e1eb29..e255989 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -1,16 +1,13 @@ /* - +----------------------------------------------------------------------+ - | PECL :: http | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, that | - | is bundled with this package in the file LICENSE, and is available | - | through the world-wide-web at http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Copyright (c) 2004-2005 Michael Wallner | - +----------------------------------------------------------------------+ + +--------------------------------------------------------------------+ + | PECL :: http | + +--------------------------------------------------------------------+ + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the conditions mentioned | + | in the accompanying LICENSE file are met. | + +--------------------------------------------------------------------+ + | Copyright (c) 2004-2005, Michael Wallner | + +--------------------------------------------------------------------+ */ /* $Id$ */ @@ -214,10 +211,11 @@ zend_function_entry http_response_object_fe[] = { EMPTY_FUNCTION_ENTRY }; -void _http_response_object_init(INIT_FUNC_ARGS) +PHP_MINIT_FUNCTION(http_response_object) { HTTP_REGISTER_CLASS(HttpResponse, http_response_object, NULL, 0); http_response_object_declare_default_properties(); + return SUCCESS; } static inline void _http_response_object_declare_default_properties(TSRMLS_D) @@ -533,11 +531,7 @@ PHP_METHOD(HttpResponse, setContentType) RETURN_FALSE; } - if (!strchr(ctype, '/')) { - http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype); - RETURN_FALSE; - } - + HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE); RETURN_SUCCESS(UPD_STATIC_STRL(contentType, ctype, ctype_len)); } /* }}} */ @@ -843,6 +837,7 @@ PHP_METHOD(HttpResponse, getBufferSize) */ PHP_METHOD(HttpResponse, setData) { + char *etag; zval *the_data; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &the_data)) { @@ -857,15 +852,10 @@ PHP_METHOD(HttpResponse, setData) RETURN_FALSE; } - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_data, SEND_DATA)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } + UPD_STATIC_PROP(long, lastModified, http_last_modified(the_data, SEND_DATA)); + if (etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA)) { + UPD_STATIC_PROP(string, eTag, etag); + efree(etag); } RETURN_TRUE; @@ -901,6 +891,7 @@ PHP_METHOD(HttpResponse, getData) */ PHP_METHOD(HttpResponse, setStream) { + char *etag; zval *the_stream; php_stream *the_real_stream; php_stream_statbuf ssb; @@ -920,15 +911,10 @@ PHP_METHOD(HttpResponse, setStream) } zend_list_addref(Z_LVAL_P(the_stream)); - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_real_stream, SEND_RSRC)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(the_real_stream, 0, SEND_RSRC); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } + UPD_STATIC_PROP(long, lastModified, http_last_modified(the_real_stream, SEND_RSRC)); + if (etag = http_etag(the_real_stream, 0, SEND_RSRC)) { + UPD_STATIC_PROP(string, eTag, etag); + efree(etag); } RETURN_TRUE; @@ -961,7 +947,7 @@ PHP_METHOD(HttpResponse, getStream) */ PHP_METHOD(HttpResponse, setFile) { - char *the_file; + char *the_file, *etag; int file_len; php_stream_statbuf ssb; @@ -978,15 +964,10 @@ PHP_METHOD(HttpResponse, setFile) RETURN_FALSE; } - if (!(Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(lastModified))) > 0)) { - UPD_STATIC_PROP(long, lastModified, http_last_modified(the_file, -1)); - } - if (!Z_STRLEN_P(convert_to_type_ex(IS_STRING, GET_STATIC_PROP(eTag)))) { - char *etag = http_etag(the_file, 0, -1); - if (etag) { - UPD_STATIC_PROP(string, eTag, etag); - efree(etag); - } + UPD_STATIC_PROP(long, lastModified, http_last_modified(the_file, -1)); + if (etag = http_etag(the_file, 0, -1)) { + UPD_STATIC_PROP(string, eTag, etag); + efree(etag); } RETURN_TRUE; @@ -1122,17 +1103,14 @@ PHP_METHOD(HttpResponse, send) } /* throttling */ - { - HTTP_G(send).buffer_size = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize))); - HTTP_G(send).throttle_delay = Z_DVAL_P(convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay))); - } + HTTP_G(send).buffer_size = Z_LVAL_P(convert_to_type_ex(IS_LONG, GET_STATIC_PROP(bufferSize))); + HTTP_G(send).throttle_delay = Z_DVAL_P(convert_to_type_ex(IS_DOUBLE, GET_STATIC_PROP(throttleDelay))); /* gzip */ - if (zval_is_true(GET_STATIC_PROP(gzip))) { - php_start_ob_buffer_named("ob_gzhandler", HTTP_G(send).buffer_size, 0 TSRMLS_CC); - } else { - php_start_ob_buffer(NULL, HTTP_G(send).buffer_size, 0 TSRMLS_CC); - } + HTTP_G(send).gzip_encoding = zval_is_true(GET_STATIC_PROP(gzip)); + + /* start ob */ + php_start_ob_buffer(NULL, HTTP_G(send).buffer_size, 0 TSRMLS_CC); /* send */ switch (Z_LVAL_P(GET_STATIC_PROP(mode)))