X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_client_response.c;h=26e85178012452e4b9825d5805ca1e6a7d343a79;hb=975cb208a4711c01261dd76630ef793efd1294fa;hp=506885691b29621c912e3376c4235d07130c5419;hpb=f753226f1f45e10ef3916256ec1bc0416c8644a8;p=m6w6%2Fext-http diff --git a/php_http_client_response.c b/php_http_client_response.c index 5068856..26e8517 100644 --- a/php_http_client_response.c +++ b/php_http_client_response.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -20,68 +20,66 @@ static PHP_METHOD(HttpClientResponse, getCookies) { long flags = 0; zval *allowed_extras_array = NULL; + int i = 0; + char **allowed_extras = NULL; + zval *header = NULL, **entry = NULL; + HashPosition pos; + php_http_message_object_t *msg; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) { - int i = 0; - char **allowed_extras = NULL; - zval *header = NULL, **entry = NULL; - HashPosition pos; - php_http_message_object_t *msg = zend_object_store_get_object(getThis() TSRMLS_CC); - + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) { + return; + } - array_init(return_value); + msg = zend_object_store_get_object(getThis() TSRMLS_CC); + array_init(return_value); - if (allowed_extras_array) { - allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *)); - FOREACH_VAL(pos, allowed_extras_array, entry) { - zval *data = php_http_ztyp(IS_STRING, *entry); - allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data)); - zval_ptr_dtor(&data); - } + if (allowed_extras_array) { + allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *)); + FOREACH_VAL(pos, allowed_extras_array, entry) { + zval *data = php_http_ztyp(IS_STRING, *entry); + allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data)); + zval_ptr_dtor(&data); } + } - if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) { - php_http_cookie_list_t *list; - - if (Z_TYPE_P(header) == IS_ARRAY) { - zval **single_header; + if ((header = php_http_message_header(msg->message, ZEND_STRL("Set-Cookie"), 0))) { + php_http_cookie_list_t *list; - FOREACH_VAL(pos, header, single_header) { - zval *data = php_http_ztyp(IS_STRING, *single_header); + if (Z_TYPE_P(header) == IS_ARRAY) { + zval **single_header; - if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) { - zval *cookie; + FOREACH_VAL(pos, header, single_header) { + zval *data = php_http_ztyp(IS_STRING, *single_header); - MAKE_STD_ZVAL(cookie); - ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list, NULL TSRMLS_CC), 0); - add_next_index_zval(return_value, cookie); - } - zval_ptr_dtor(&data); - } - } else { - zval *data = php_http_ztyp(IS_STRING, header); if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) { zval *cookie; MAKE_STD_ZVAL(cookie); - ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list, NULL TSRMLS_CC), 0); + ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); add_next_index_zval(return_value, cookie); } zval_ptr_dtor(&data); } - zval_ptr_dtor(&header); - } - - if (allowed_extras) { - for (i = 0; allowed_extras[i]; ++i) { - efree(allowed_extras[i]); + } else { + zval *data = php_http_ztyp(IS_STRING, header); + if ((list = php_http_cookie_list_parse(NULL, Z_STRVAL_P(data), Z_STRLEN_P(data), flags, allowed_extras TSRMLS_CC))) { + zval *cookie; + + MAKE_STD_ZVAL(cookie); + ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); + add_next_index_zval(return_value, cookie); } - efree(allowed_extras); + zval_ptr_dtor(&data); } + zval_ptr_dtor(&header); + } - return; + if (allowed_extras) { + for (i = 0; allowed_extras[i]; ++i) { + efree(allowed_extras[i]); + } + efree(allowed_extras); } - RETURN_FALSE; } ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo, 0, 0, 0) @@ -91,42 +89,45 @@ static PHP_METHOD(HttpClientResponse, getTransferInfo) { char *info_name = NULL; int info_len = 0; + zval *infop, *info; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) { - zval **infop, *info = zend_read_property(php_http_client_response_get_class_entry(), getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC); + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) { + return; + } - /* request completed? */ - if (Z_TYPE_P(info) == IS_ARRAY) { - if (info_len && info_name) { - if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(info), php_http_pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) { - RETURN_ZVAL(*infop, 1, 0); - } else { - php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name); - } + info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC); + + /* request completed? */ + if (Z_TYPE_P(info) == IS_OBJECT) { + if (info_len && info_name) { + infop = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC); + + if (infop) { + RETURN_ZVAL(infop, 1, 0); } else { - RETURN_ZVAL(info, 1, 0); + php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name); } + } else { + RETURN_ZVAL(info, 1, 0); } } RETURN_FALSE; } -static zend_class_entry *php_http_client_response_class_entry; - -zend_class_entry *php_http_client_response_get_class_entry(void) -{ - return php_http_client_response_class_entry; -} - -static zend_function_entry php_http_client_response_method_entry[] = { - PHP_ME(HttpClientResponse, getCookies, ai_HttpClientResponse_getCookies, ZEND_ACC_PUBLIC) +static zend_function_entry php_http_client_response_methods[] = { + PHP_ME(HttpClientResponse, getCookies, ai_HttpClientResponse_getCookies, ZEND_ACC_PUBLIC) PHP_ME(HttpClientResponse, getTransferInfo, ai_HttpClientResponse_getTransferInfo, ZEND_ACC_PUBLIC) EMPTY_FUNCTION_ENTRY }; +zend_class_entry *php_http_client_response_class_entry; + PHP_MINIT_FUNCTION(http_client_response) { - PHP_HTTP_REGISTER_CLASS(http\\Client, Response, http_client_response, php_http_message_get_class_entry(), 0); + zend_class_entry ce = {0}; + + INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Response", php_http_client_response_methods); + php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC); return SUCCESS; }