X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_functions.c;h=b16cef17e43c59725be76cfd2add8d5ad0a2c594;hp=225019dc52f26924d85e94be508e59ab51d372ad;hb=e6b35fbe072a13b0e792952852fcd1499bd8e610;hpb=424eec077256edbed079988cfa4dccab5b979536 diff --git a/http_functions.c b/http_functions.c index 225019d..b16cef1 100644 --- a/http_functions.c +++ b/http_functions.c @@ -27,6 +27,7 @@ #include "php_http_api.h" #include "php_http_cache_api.h" +#include "php_http_cookie_api.h" #include "php_http_date_api.h" #include "php_http_encoding_api.h" #include "php_http_headers_api.h" @@ -1038,41 +1039,76 @@ PHP_FUNCTION(http_parse_headers) } /* }}}*/ -/* {{{ proto object http_parse_cookie(string cookie) +/* {{{ proto object http_parse_cookie(string cookie[, int flags[, array allowed_extras]]) * * Parses HTTP cookies like sent in a response into a struct. * * Expects a string as parameter containing the value of a Set-Cookie response header. * - * Returns an stdClass object with the cookie params as properties on success or FALSE on failure. + * Returns an stdClass olike shown in the example on success or FALSE on failure. * * Example: *
  *  foo
- *     [value] => bar
+ *     [cookies] => Array
+ *         (
+ *             [foo] => bar
+ *             [bar] => baz
+ *         )
+ * 
+ *     [extras] => Array
+ *         (
+ *             [comment] =>
+ *         )
+ * 
+ *     [flags] => 16
+ *     [expires] => 0
  *     [path] => /
+ *     [domain] => example.com
  * )
  * ?>
  * 
*/ PHP_FUNCTION(http_parse_cookie) { - char *cookie; - int cookie_len; + char *cookie, **allowed_extras = NULL; + int i = 0, cookie_len; + long flags = 0; + zval *allowed_extras_array = NULL, **entry = NULL; + HashPosition pos; + http_cookie_list list; - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cookie, &cookie_len)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la", &cookie, &cookie_len, &flags, &allowed_extras_array)) { RETURN_FALSE; } - object_init(return_value); - if (SUCCESS != http_parse_cookie(cookie, HASH_OF(return_value))) { - zval_dtor(return_value); - RETURN_FALSE; + if (allowed_extras_array) { + allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *)); + FOREACH_VAL(pos, allowed_extras_array, entry) { + ZVAL_ADDREF(*entry); + convert_to_string_ex(entry); + allowed_extras[i] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); + zval_ptr_dtor(entry); + } + } + + if (http_parse_cookie_ex(&list, cookie, flags, allowed_extras)) { + object_init(return_value); + http_cookie_list_tostruct(&list, return_value); + http_cookie_list_dtor(&list); + } else { + RETVAL_FALSE; + } + + if (allowed_extras) { + for (i = 0; allowed_extras[i]; ++i) { + efree(allowed_extras[i]); + } + efree(allowed_extras); } }