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
;
26 php_http_message_object_t
*msg
;
28 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS(), "|la!/", &flags
, &allowed_extras_array
)) {
32 msg
= PHP_HTTP_OBJ(NULL
, getThis());
33 array_init(return_value
);
35 if (allowed_extras_array
) {
36 /* FIXME: use zend_string** instead of char** */
37 allowed_extras
= ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array
)) + 1, sizeof(char *));
38 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(allowed_extras_array
), entry
)
40 zend_string
*zs
= zval_get_string(entry
);
41 allowed_extras
[i
++] = estrndup(zs
->val
, zs
->len
);
42 zend_string_release(zs
);
44 ZEND_HASH_FOREACH_END();
47 if ((header
= php_http_message_header(msg
->message
, ZEND_STRL("Set-Cookie")))) {
48 php_http_cookie_list_t
*list
;
50 if (Z_TYPE_P(header
) == IS_ARRAY
) {
53 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(header
), single_header
)
55 zend_string
*zs
= zval_get_string(single_header
);
57 if ((list
= php_http_cookie_list_parse(NULL
, zs
->val
, zs
->len
, flags
, allowed_extras
))) {
60 ZVAL_OBJ(&cookie
, &php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
)->zo
);
61 add_next_index_zval(return_value
, &cookie
);
63 zend_string_release(zs
);
65 ZEND_HASH_FOREACH_END();
67 zend_string
*zs
= zval_get_string(header
);
69 if ((list
= php_http_cookie_list_parse(NULL
, zs
->val
, zs
->len
, flags
, allowed_extras
))) {
72 ZVAL_OBJ(&cookie
, &php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
)->zo
);
73 add_next_index_zval(return_value
, &cookie
);
75 zend_string_release(zs
);
80 for (i
= 0; allowed_extras
[i
]; ++i
) {
81 efree(allowed_extras
[i
]);
83 efree(allowed_extras
);
87 ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientResponse_getTransferInfo
, 0, 0, 0)
88 ZEND_ARG_INFO(0, element
)
90 static PHP_METHOD(HttpClientResponse
, getTransferInfo
)
92 char *info_name
= NULL
;
94 zval info_tmp
, info_name_tmp
, *info
;
96 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &info_name
, &info_len
), invalid_arg
, return);
98 info
= zend_read_property(php_http_client_response_class_entry
, getThis(), ZEND_STRL("transferInfo"), 0, &info_tmp
);
100 /* request completed? */
101 if (Z_TYPE_P(info
) != IS_OBJECT
) {
102 php_http_throw(bad_method_call
, "Incomplete state", NULL
);
106 if (info_len
&& info_name
) {
107 info
= zend_read_property(NULL
, info
, php_http_pretty_key(info_name
, info_len
, 0, 0), info_len
, 0, &info_name_tmp
);
110 php_http_throw(unexpected_val
, "Could not find transfer info with name '%s'", info_name
);
115 RETURN_ZVAL_FAST(info
);
118 static zend_function_entry php_http_client_response_methods
[] = {
119 PHP_ME(HttpClientResponse
, getCookies
, ai_HttpClientResponse_getCookies
, ZEND_ACC_PUBLIC
)
120 PHP_ME(HttpClientResponse
, getTransferInfo
, ai_HttpClientResponse_getTransferInfo
, ZEND_ACC_PUBLIC
)
124 zend_class_entry
*php_http_client_response_class_entry
;
126 PHP_MINIT_FUNCTION(http_client_response
)
128 zend_class_entry ce
= {0};
130 INIT_NS_CLASS_ENTRY(ce
, "http\\Client", "Response", php_http_client_response_methods
);
131 php_http_client_response_class_entry
= zend_register_internal_class_ex(&ce
, php_http_message_class_entry
);
133 zend_declare_property_null(php_http_client_response_class_entry
, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED
);
143 * vim600: noet sw=4 ts=4 fdm=marker
144 * vim<600: noet sw=4 ts=4