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 php_http_array_hashkey_t key
= php_http_array_hashkey_init(0);
34 char **allowed_extras
= NULL
;
35 zval
**header
= NULL
, **entry
= NULL
;
36 HashPosition pos
, pos1
, pos2
;
37 php_http_message_object_t
*msg
= zend_object_store_get_object(getThis() TSRMLS_CC
);
40 array_init(return_value
);
42 if (allowed_extras_array
) {
43 allowed_extras
= ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array
)) + 1, sizeof(char *));
44 FOREACH_VAL(pos
, allowed_extras_array
, entry
) {
45 zval
*data
= php_http_ztyp(IS_STRING
, *entry
);
46 allowed_extras
[i
++] = estrndup(Z_STRVAL_P(data
), Z_STRLEN_P(data
));
51 FOREACH_HASH_KEYVAL(pos1
, &msg
->message
->hdrs
, key
, header
) {
52 if (key
.type
== HASH_KEY_IS_STRING
&& !strcasecmp(key
.str
, "Set-Cookie")) {
53 php_http_cookie_list_t
*list
;
55 if (Z_TYPE_PP(header
) == IS_ARRAY
) {
58 FOREACH_VAL(pos2
, *header
, single_header
) {
59 zval
*data
= php_http_ztyp(IS_STRING
, *single_header
);
61 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
64 MAKE_STD_ZVAL(cookie
);
65 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list
, NULL TSRMLS_CC
), 0);
66 add_next_index_zval(return_value
, cookie
);
71 zval
*data
= php_http_ztyp(IS_STRING
, *header
);
72 if ((list
= php_http_cookie_list_parse(NULL
, Z_STRVAL_P(data
), Z_STRLEN_P(data
), flags
, allowed_extras TSRMLS_CC
))) {
75 MAKE_STD_ZVAL(cookie
);
76 ZVAL_OBJVAL(cookie
, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list
, NULL TSRMLS_CC
), 0);
77 add_next_index_zval(return_value
, cookie
);
85 for (i
= 0; allowed_extras
[i
]; ++i
) {
86 efree(allowed_extras
[i
]);
88 efree(allowed_extras
);
97 static zend_class_entry
*php_http_client_response_class_entry
;
99 zend_class_entry
*php_http_client_response_get_class_entry(void)
101 return php_http_client_response_class_entry
;
104 static zend_function_entry php_http_client_response_method_entry
[] = {
105 PHP_HTTP_CLIENT_RESPONSE_ME(getCookies
, ZEND_ACC_PUBLIC
)
109 PHP_MINIT_FUNCTION(http_client_response
)
111 PHP_HTTP_REGISTER_CLASS(http
\\Client
, Response
, http_client_response
, php_http_message_get_class_entry(), 0);
121 * vim600: noet sw=4 ts=4 fdm=marker
122 * vim<600: noet sw=4 ts=4