X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_client_response.c;h=de27904de0160a22e0f20d39dd4f3a5def1a5aee;hp=663ce8bba34adceff09af13e0d00ecbe311b2c62;hb=76f74c9bfd2e97c89e7184d85ea7a0c5322a5219;hpb=eebe0f3e8947ecb407451d20aef0611cfcedfdac diff --git a/php_http_client_response.c b/php_http_client_response.c index 663ce8b..de27904 100644 --- a/php_http_client_response.c +++ b/php_http_client_response.c @@ -6,34 +6,26 @@ | 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 | +--------------------------------------------------------------------+ */ #include "php_http_api.h" -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpClientResponse, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpClientResponse, method, 0) -#define PHP_HTTP_CLIENT_RESPONSE_ME(method, visibility) PHP_ME(HttpClientResponse, method, PHP_HTTP_ARGS(HttpClientResponse, method), visibility) -#define PHP_HTTP_CLIENT_RESPONSE_ALIAS(method, func) PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpClientResponse, method)) -#define PHP_HTTP_CLIENT_RESPONSE_MALIAS(me, al, vis) ZEND_FENTRY(me, ZEND_MN(HttpClientResponse_##al), PHP_HTTP_ARGS(HttpClientResponse, al), vis) - -PHP_HTTP_BEGIN_ARGS(getCookies, 0) - PHP_HTTP_ARG_VAL(flags, 0) - PHP_HTTP_ARG_VAL(allowed_extras, 0) -PHP_HTTP_END_ARGS; - -PHP_METHOD(HttpClientResponse, getCookies) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getCookies, 0, 0, 0) + ZEND_ARG_INFO(0, flags) + ZEND_ARG_INFO(0, allowed_extras) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientResponse, getCookies) { long flags = 0; zval *allowed_extras_array = NULL; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) { int i = 0; - php_http_array_hashkey_t key = php_http_array_hashkey_init(0); char **allowed_extras = NULL; - zval **header = NULL, **entry = NULL; - HashPosition pos, pos1, pos2; + zval *header = NULL, **entry = NULL; + HashPosition pos; php_http_message_object_t *msg = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -48,27 +40,15 @@ PHP_METHOD(HttpClientResponse, getCookies) } } - FOREACH_HASH_KEYVAL(pos1, &msg->message->hdrs, key, header) { - if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "Set-Cookie")) { - php_http_cookie_list_t *list; - - if (Z_TYPE_PP(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(pos2, *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_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; @@ -78,7 +58,18 @@ PHP_METHOD(HttpClientResponse, getCookies) } 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_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) { @@ -93,16 +84,47 @@ PHP_METHOD(HttpClientResponse, getCookies) RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo, 0, 0, 0) + ZEND_ARG_INFO(0, element) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientResponse, getTransferInfo) +{ + char *info_name = NULL; + int info_len = 0; -zend_class_entry *php_http_client_response_class_entry; -zend_function_entry php_http_client_response_method_entry[] = { - PHP_HTTP_CLIENT_RESPONSE_ME(getCookies, ZEND_ACC_PUBLIC) + 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_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC); + + /* 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); + } + } else { + RETURN_ZVAL(info, 1, 0); + } + } + } + RETURN_FALSE; +} + +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_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; }