From ef227f4f7f697c954eef0adb9f9f897148a771ca Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 14 Dec 2005 16:52:12 +0000 Subject: [PATCH] - export http_parse_cookie() --- docs/functions.html | 35 +++++++++++++++-------------------- http.c | 1 + http_functions.c | 39 +++++++++++++++++++++++++++++++++++++++ http_request_api.c | 6 +++++- http_util_object.c | 5 +++++ package2.xml | 1 + php_http.h | 1 + php_http_util_object.h | 1 + 8 files changed, 68 insertions(+), 21 deletions(-) diff --git a/docs/functions.html b/docs/functions.html index fa3d1c5..0e53c61 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -253,7 +253,15 @@ several consecutive HTTP messages.

Expects a string parameter containing HTTP headers.

Returns an array on success, or FALSE on failure.

Example:


-<?php
$headers 
"content-type: text/html; charset=UTF-8\r\n".
           
"Server: Funky/1.0\r\n".
           
"Set-Cookie: foo=bar\r\n".
           
"Set-Cookie: baz=quux\r\n".
           
"Folded: works\r\n\ttoo\r\n";
print_r(http_parse_headers($headers));

Array
(
    [
Content-Type] => text/htmlchatset=UTF-8
    
[Server] => Funky/1.0
    
[Set-Cookie] => Array
        (
            [
0] => foo=bar
            
[1] => baz=quux
        
)
    [
Folded] => works
        too 
?>

+<?php
$headers 
"content-type: text/html; charset=UTF-8\r\n".
           
"Server: Funky/1.0\r\n".
           
"Set-Cookie: foo=bar\r\n".
           
"Set-Cookie: baz=quux\r\n".
           
"Folded: works\r\n\ttoo\r\n";
print_r(http_parse_headers($headers));

Array
(
    [
Content-Type] => text/htmlchatset=UTF-8
    
[Server] => Funky/1.0
    
[Set-Cookie] => Array
        (
            [
0] => foo=bar
            
[1] => baz=quux
        
)
    [
Folded] => works
        too 

?>
+

+

+ +

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:


+<?php
print_r
(http_parse_cookie("foo=bar; path=/"));

stdClass Object
(
    [
name] => foo
    
[value] => bar
    
[path] => /
)
?>

array http_get_request_headers(void)

@@ -350,7 +358,7 @@ See http_get() for a full list of available options.

Returns the request method name as string on success, or FALSE on failure.

string http_build_query(mixed formdata [, string prefix[, string arg_separator]])

Generates a form-encoded query string from an associative array or object.

-

string http_gzencode(string data[, int level = -1])

+

string http_gzencode(string data[, int level = -1[, int mtime = 0]])

Compress data with the HTTP compatible GZIP encoding.

Expects the first parameter to be a string which contains the data that
should be encoded. Additionally accepts an optional in paramter specifying
@@ -361,7 +369,7 @@ best compression ratio.

Uncompress data compressed with the HTTP compatible GZIP encoding.

Expects a string as parameter containing the compressed data.

Returns the decoded string on success, or NULL on failure.

-

string http_deflate(string data[, int level = -1])

+

string http_deflate(string data[, int level = -1[, bool zlib_header = false]])

Compress data with the HTTP compatible DEFLATE encoding.

Expects the first parameter to be a string containing the data that should
be encoded. Additionally accepts an optional int parameter specifying the
@@ -372,17 +380,6 @@ compression ratio.

Uncompress data compressed with the HTTP compatible DEFLATE encoding.

Expects a string as parameter containing the compressed data.

Returns the decoded string on success, or NULL on failure.

-

string http_compress(string data[, int level = -1])

-

Compress data with the HTTP compatible COMPRESS encoding.

-

Expects the first parameter to be a string containing the data which should
-be encoded. Additionally accepts an optional int parameter specifying the
-compression level, where -1 is default, 0 is no compression and 9 is best
-compression ratio.

-

Returns the encoded string on success, or NULL on failure.

-

string http_uncompress(string data)

-

Uncompress data compressed with the HTTP compatible COMPRESS encoding.

-

Expects a string as parameter containing the compressed data.

-

Returns the decoded string on success, or NULL on failure.

int http_support([int feature = 0])

Check for feature that require external libraries.

Accpepts an optional in parameter specifying which feature to probe for.
@@ -759,7 +756,7 @@ HttpMalformedHeaderException, HttpEncodingException.

Instantiate a new HttpRequestPool object. An HttpRequestPool is
able to send several HttpRequests in parallel.

WARNING: Don't attach/detach HttpRequest objects to the HttpRequestPool
-object while you're using the implemented Interator interface.

+object while you're using the implemented Iterator interface.

Accepts virtual infinite optional parameters each referencing an
HttpRequest object.

Throws HttpRequestPoolException (HttpRequestException, HttpInvalidParamException).

@@ -1022,6 +1019,8 @@ http.cache_log is set.

  • http_parse_headers
  • +
  • http_parse_cookie +
  • http_get_request_headers
  • http_get_request_body @@ -1058,10 +1057,6 @@ http.cache_log is set.

  • http_inflate
  • -
  • http_compress -
  • -
  • http_uncompress -
  • http_support
  • @@ -1200,7 +1195,7 @@ http.cache_log is set.

    -

    Generated at: Fri, 09 Dec 2005 13:56:42 +0100

    +

    Generated at: Wed, 14 Dec 2005 16:25:48 +0100

    diff --git a/http.c b/http.c index 6fc1af9..eb8f5e9 100644 --- a/http.c +++ b/http.c @@ -83,6 +83,7 @@ zend_function_entry http_functions[] = { PHP_FE(http_chunked_decode, NULL) PHP_FE(http_parse_message, NULL) PHP_FE(http_parse_headers, NULL) + PHP_FE(http_parse_cookie, NULL) PHP_FE(http_get_request_headers, NULL) PHP_FE(http_get_request_body, NULL) PHP_FE(http_match_request_header, NULL) 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. diff --git a/http_request_api.c b/http_request_api.c index bc1fdbb..3408812 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -304,7 +304,7 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback); HTTP_CURL_OPT(IOCTLFUNCTION, http_curl_ioctl_callback); HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback); - HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); + HTTP_CURL_OPT(PROGRESSFUNCTION, NULL); HTTP_CURL_OPT(URL, NULL); HTTP_CURL_OPT(NOPROGRESS, 1); HTTP_CURL_OPT(PROXY, NULL); @@ -351,6 +351,9 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(IOCTLDATA, NULL); HTTP_CURL_OPT(READDATA, NULL); HTTP_CURL_OPT(INFILESIZE, 0); +#if 0 + HTTP_CURL_OPT(IGNORE_CONTENT_ENCODING, 1); +#endif } } /* }}} */ @@ -388,6 +391,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti if ((zoption = http_request_option(request, options, "onprogress", 0))) { HTTP_CURL_OPT(NOPROGRESS, 0); HTTP_CURL_OPT(PROGRESSDATA, request); + HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback); http_request_set_progress_callback(request, zoption); } diff --git a/http_util_object.c b/http_util_object.c index b1ad7c7..03429f4 100644 --- a/http_util_object.c +++ b/http_util_object.c @@ -78,6 +78,10 @@ HTTP_BEGIN_ARGS(parseHeaders, 1) HTTP_ARG_VAL(headers_string, 0) HTTP_END_ARGS; +HTTP_BEGIN_ARGS(parseCookie, 1) + HTTP_ARG_VAL(cookie_string, 0) +HTTP_END_ARGS; + HTTP_BEGIN_ARGS(chunkedDecode, 1) HTTP_ARG_VAL(encoded_string, 0) HTTP_END_ARGS; @@ -118,6 +122,7 @@ zend_function_entry http_util_object_fe[] = { HTTP_UTIL_ALIAS(matchRequestHeader, http_match_request_header) HTTP_UTIL_ALIAS(parseMessage, http_parse_message) HTTP_UTIL_ALIAS(parseHeaders, http_parse_headers) + HTTP_UTIL_ALIAS(parseCookie, http_parse_cookie) HTTP_UTIL_ALIAS(chunkedDecode, http_chunked_decode) #ifdef HTTP_HAVE_ZLIB HTTP_UTIL_ALIAS(gzEncode, http_gzencode) diff --git a/package2.xml b/package2.xml index 2cd49b7..69306af 100644 --- a/package2.xml +++ b/package2.xml @@ -47,6 +47,7 @@ HttpUtil, HttpMessage, HttpRequest, HttpRequestPool; HttpResponse (PHP-5.1) + Added 'bodyonly' request option + Added IOCTL callback for cURL + Added ssl_engines array and cookies array to the request info array ++ Added http_parse_cookie() to parse Set-Cookie headers - Renamed http_connectcode to connect_code in the request info array - Enable "original headers" previously stripped off by the message parser: diff --git a/php_http.h b/php_http.h index 22d97e1..f738a3f 100644 --- a/php_http.h +++ b/php_http.h @@ -127,6 +127,7 @@ PHP_FUNCTION(http_send_stream); PHP_FUNCTION(http_chunked_decode); PHP_FUNCTION(http_parse_message); PHP_FUNCTION(http_parse_headers); +PHP_FUNCTION(http_parse_cookie); PHP_FUNCTION(http_get_request_headers); PHP_FUNCTION(http_get_request_body); PHP_FUNCTION(http_match_request_header); diff --git a/php_http_util_object.h b/php_http_util_object.h index 2c085fa..6225ae8 100644 --- a/php_http_util_object.h +++ b/php_http_util_object.h @@ -30,6 +30,7 @@ PHP_METHOD(HttpUtil, matchModified); PHP_METHOD(HttpUtil, matchEtag); PHP_METHOD(HttpUtil, parseHeaders); PHP_METHOD(HttpUtil, parseMessage); +PHP_METHOD(HttpUtil, parseCookie); PHP_METHOD(HttpUtil, chunkedDecode); PHP_METHOD(HttpUtil, gzEncode); PHP_METHOD(HttpUtil, gzDecode); -- 2.30.2