2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getCookies
, 0, 0, 0)
16 ZEND_ARG_INFO(0, flags
)
17 ZEND_ARG_INFO(0, allowed_extras
)
19 static PHP_METHOD(HttpClientResponse
, getCookies
)
22 zval
*allowed_extras_array
= NULL
;
24 char **allowed_extras
= NULL
;
25 zval
*header
= NULL
, **entry
= NULL
;
27 php_http_message_object_t
*msg
;
29 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|la!", &flags
, &allowed_extras_array
)) {
33 msg
= zend_object_store_get_object(getThis() TSRMLS_CC
);
34 array_init(return_value
);
36 if (allowed_extras_array
) {
37 allowed_extras
= ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array
)) + 1, sizeof(char *));
38 FOREACH_VAL(pos
, allowed_extras_array
, entry
) {
39 zval
*data
= php_http_ztyp(IS_STRING
, *entry
);
40 allowed_extras
[i
++] = estrndup(Z_STRVAL_P(data
), Z_STRLEN_P(data
));
45 if ((header
= php_http_message_header(msg
->message
, ZEND_STRL("Set-Cookie"), 0))) {
46 php_http_cookie_list_t
*list
;
48 if (Z_TYPE_P(header
) == IS_ARRAY
) {
51 FOREACH_VAL(pos
, header
, single_header
) {
52 zval
*data
= php_http_ztyp(IS_STRING
, *single_header
);
54 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
57 MAKE_STD_ZVAL(cookie
);
58 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
, NULL TSRMLS_CC
), 0);
59 add_next_index_zval(return_value
, cookie
);
64 zval
*data
= php_http_ztyp(IS_STRING
, header
);
65 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
68 MAKE_STD_ZVAL(cookie
);
69 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
, NULL TSRMLS_CC
), 0);
70 add_next_index_zval(return_value
, cookie
);
74 zval_ptr_dtor(&header
);
78 for (i
= 0; allowed_extras
[i
]; ++i
) {
79 efree(allowed_extras
[i
]);
81 efree(allowed_extras
);
85 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo
, 0, 0, 0)
86 ZEND_ARG_INFO(0, element
)
88 static PHP_METHOD(HttpClientResponse
, getTransferInfo
)
90 char *info_name
= NULL
;
94 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &info_name
, &info_len
), invalid_arg
, return);
96 info
= zend_read_property(php_http_client_response_class_entry
, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC
);
98 /* request completed? */
99 if (Z_TYPE_P(info
) != IS_OBJECT
) {
100 php_http_throw(bad_method_call
, "Incomplete state", NULL
);
104 if (info_len
&& info_name
) {
105 info
= zend_read_property(NULL
, info
, php_http_pretty_key(info_name
, info_len
, 0, 0), info_len
, 0 TSRMLS_CC
);
108 php_http_throw(unexpected_val
, "Could not find transfer info with name '%s'", info_name
);
113 RETURN_ZVAL(info
, 1, 0);
116 static zend_function_entry php_http_client_response_methods
[] = {
117 PHP_ME(HttpClientResponse
, getCookies
, ai_HttpClientResponse_getCookies
, ZEND_ACC_PUBLIC
)
118 PHP_ME(HttpClientResponse
, getTransferInfo
, ai_HttpClientResponse_getTransferInfo
, ZEND_ACC_PUBLIC
)
122 zend_class_entry
*php_http_client_response_class_entry
;
124 PHP_MINIT_FUNCTION(http_client_response
)
126 zend_class_entry ce
= {0};
128 INIT_NS_CLASS_ENTRY(ce
, "http\\Client", "Response", php_http_client_response_methods
);
129 php_http_client_response_class_entry
= zend_register_internal_class_ex(&ce
, php_http_message_class_entry
, NULL TSRMLS_CC
);
130 zend_declare_property_null(php_http_client_response_class_entry
, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED TSRMLS_CC
);
140 * vim600: noet sw=4 ts=4 fdm=marker
141 * vim<600: noet sw=4 ts=4