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-2011, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 #define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpClientResponse, method, 0, req_args)
16 #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpClientResponse, method, 0)
17 #define PHP_HTTP_CLIENT_RESPONSE_ME(method, visibility) PHP_ME(HttpClientResponse, method, PHP_HTTP_ARGS(HttpClientResponse, method), visibility)
18 #define PHP_HTTP_CLIENT_RESPONSE_ALIAS(method, func) PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpClientResponse, method))
19 #define PHP_HTTP_CLIENT_RESPONSE_MALIAS(me, al, vis) ZEND_FENTRY(me, ZEND_MN(HttpClientResponse_##al), PHP_HTTP_ARGS(HttpClientResponse, al), vis)
21 PHP_HTTP_BEGIN_ARGS(getCookies
, 0)
22 PHP_HTTP_ARG_VAL(flags
, 0)
23 PHP_HTTP_ARG_VAL(allowed_extras
, 0)
26 PHP_METHOD(HttpClientResponse
, getCookies
)
29 zval
*allowed_extras_array
= NULL
;
31 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|la!", &flags
, &allowed_extras_array
)) {
33 char **allowed_extras
= NULL
;
34 zval
*header
= NULL
, **entry
= NULL
;
36 php_http_message_object_t
*msg
= zend_object_store_get_object(getThis() TSRMLS_CC
);
39 array_init(return_value
);
41 if (allowed_extras_array
) {
42 allowed_extras
= ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array
)) + 1, sizeof(char *));
43 FOREACH_VAL(pos
, allowed_extras_array
, entry
) {
44 zval
*data
= php_http_ztyp(IS_STRING
, *entry
);
45 allowed_extras
[i
++] = estrndup(Z_STRVAL_P(data
), Z_STRLEN_P(data
));
50 if ((header
= php_http_message_header(msg
->message
, ZEND_STRL("Set-Cookie"), 0))) {
51 php_http_cookie_list_t
*list
;
53 if (Z_TYPE_P(header
) == IS_ARRAY
) {
56 FOREACH_VAL(pos
, header
, single_header
) {
57 zval
*data
= php_http_ztyp(IS_STRING
, *single_header
);
59 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
62 MAKE_STD_ZVAL(cookie
);
63 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list
, NULL TSRMLS_CC
), 0);
64 add_next_index_zval(return_value
, cookie
);
69 zval
*data
= php_http_ztyp(IS_STRING
, header
);
70 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
73 MAKE_STD_ZVAL(cookie
);
74 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list
, NULL TSRMLS_CC
), 0);
75 add_next_index_zval(return_value
, cookie
);
79 zval_ptr_dtor(&header
);
83 for (i
= 0; allowed_extras
[i
]; ++i
) {
84 efree(allowed_extras
[i
]);
86 efree(allowed_extras
);
95 static zend_class_entry
*php_http_client_response_class_entry
;
97 zend_class_entry
*php_http_client_response_get_class_entry(void)
99 return php_http_client_response_class_entry
;
102 static zend_function_entry php_http_client_response_method_entry
[] = {
103 PHP_HTTP_CLIENT_RESPONSE_ME(getCookies
, ZEND_ACC_PUBLIC
)
107 PHP_MINIT_FUNCTION(http_client_response
)
109 PHP_HTTP_REGISTER_CLASS(http
\\Client
, Response
, http_client_response
, php_http_message_get_class_entry(), 0);
119 * vim600: noet sw=4 ts=4 fdm=marker
120 * vim<600: noet sw=4 ts=4