X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_functions.c;h=80030ce0469279b2ba76545b7c2471a5b5598aea;hp=424a6bde66ad7a41b4857507d09bf3e555ef9d6a;hb=ef227f4f7f697c954eef0adb9f9f897148a771ca;hpb=eabc03de1d511ce49640322859c6175f27a413e5 diff --git a/http_functions.c b/http_functions.c index 424a6bd..80030ce 100644 --- a/http_functions.c +++ b/http_functions.c @@ -894,6 +894,7 @@ PHP_FUNCTION(http_parse_message) * ) * [Folded] => works * too + * ) * ?> * */ @@ -914,6 +915,44 @@ PHP_FUNCTION(http_parse_headers) } /* }}}*/ +/* {{{ proto object http_parse_cookie(string cookie) + * + * 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. + * + * Example: + *
+ *  foo
+ *     [value] => bar
+ *     [path] => /
+ * )
+ * ?>
+ * 
+ */ +PHP_FUNCTION(http_parse_cookie) +{ + char *cookie; + int cookie_len; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cookie, &cookie_len)) { + RETURN_FALSE; + } + + object_init(return_value); + if (SUCCESS != http_parse_cookie(cookie, HASH_OF(return_value))) { + zval_dtor(return_value); + RETURN_FALSE; + } +} + /* {{{ proto array http_get_request_headers(void) * * Get a list of incoming HTTP headers.