cvs: pecl /http http.c http_methods.c php_http.h

From: Date: Thu, 24 Mar 2005 16:32:47 +0000
Subject: cvs: pecl /http http.c http_methods.c php_http.h
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2899@lists.php.net to get a copy of this message
mike Thu Mar 24 11:32:47 2005 EDT Modified files: /pecl/http http.c http_methods.c php_http.h Log: * renamed HttpRequest::addHeader() to ::addHeaders() and addCookie() to ::addCookies() * added ::(set|get|unset)SslOptions() * added ::(get|unstet)(Headers|Cookies)()

http://cvs.php.net/diff.php/pecl/http/http.c?r1=1.56&r2=1.57&ty=u Index: pecl/http/http.c diff -u pecl/http/http.c:1.56 pecl/http/http.c:1.57 --- pecl/http/http.c:1.56 Mon Mar 21 14:33:37 2005 +++ pecl/http/http.c Thu Mar 24 11:32:47 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http.c,v 1.56 2005/03/21 19:33:37 mike Exp $ */ +/* $Id: http.c,v 1.57 2005/03/24 16:32:47 mike Exp $ */ #ifdef HAVE_CONFIG_H @@ -308,9 +308,16 @@ PHP_ME(HttpRequest, setOptions, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getOptions, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, unsetOptions, NULL, ZEND_ACC_PUBLIC) - - PHP_ME(HttpRequest, addHeader, NULL, ZEND_ACC_PUBLIC) - PHP_ME(HttpRequest, addCookie, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, setSslOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getSslOptions, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetSslOptions, NULL, ZEND_ACC_PUBLIC) + + PHP_ME(HttpRequest, addHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetHeaders, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, addCookies, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getCookies, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, unsetCookies, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, setMethod, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getMethod, NULL, ZEND_ACC_PUBLIC) @@ -339,6 +346,7 @@ PHP_ME(HttpRequest, getResponseData, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getResponseHeader, NULL, ZEND_ACC_PUBLIC) + PHP_ME(HttpRequest, getResponseCookie, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getResponseCode, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getResponseBody, NULL, ZEND_ACC_PUBLIC) PHP_ME(HttpRequest, getResponseInfo, NULL, ZEND_ACC_PUBLIC) http://cvs.php.net/diff.php/pecl/http/http_methods.c?r1=1.15&r2=1.16&ty=u Index: pecl/http/http_methods.c diff -u pecl/http/http_methods.c:1.15 pecl/http/http_methods.c:1.16 --- pecl/http/http_methods.c:1.15 Mon Mar 21 14:33:37 2005 +++ pecl/http/http_methods.c Thu Mar 24 11:32:47 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: http_methods.c,v 1.15 2005/03/21 19:33:37 mike Exp $ */ +/* $Id: http_methods.c,v 1.16 2005/03/24 16:32:47 mike Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -641,11 +641,74 @@ } /* }}} */ -/* {{{ proto bool HttpRequest::addHeader(array header) +/* {{{ proto bool HttpRequest::setSslOptions(array options) * - * Add (a) request header name/value pair(s). + * Set additional SSL options. */ -PHP_METHOD(HttpRequest, addHeader) +PHP_METHOD(HttpRequest, setSslOptions) +{ + zval *opts, *old_opts, **ssl_options; + getObject(http_request_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &opts)) { + RETURN_FALSE; + } + + old_opts = GET_PROP(obj, options); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(old_opts), "ssl", sizeof("ssl"), (void **) &ssl_options)) { + array_merge(opts, *ssl_options); + } else { + zval_add_ref(&opts); + add_assoc_zval(old_opts, "ssl", opts); + } + + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto array HttpRequest::getSslOtpions() + * + * Get previously set SSL options. + */ +PHP_METHOD(HttpRequest, getSslOptions) +{ + zval *opts, **ssl_options; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + + array_init(return_value); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "ssl", sizeof("ssl"), (void **) &ssl_options)) { + array_copy(*ssl_options, return_value); + } +} +/* }}} */ + +/* {{{ proto void HttpRequest::unsetSslOptions() + * + * Unset previously set SSL options. + */ +PHP_METHOD(HttpRequest, unsetSslOptions) +{ + zval *opts; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + zend_hash_del(Z_ARRVAL_P(opts), "ssl", sizeof("ssl")); +} +/* }}} */ + +/* {{{ proto bool HttpRequest::addHeaders(array headers) + * + * Add request header name/value pairs. + */ +PHP_METHOD(HttpRequest, addHeaders) { zval *opts, **headers, *new_headers; getObject(http_request_object, obj); @@ -667,11 +730,48 @@ } /* }}} */ -/* {{{ proto bool HttpRequest::addCookie(array cookie) +/* {{{ proto array HttpRequest::getHeaders() + * + * Get previously set request headers. + */ +PHP_METHOD(HttpRequest, getHeaders) +{ + zval *opts, **headers; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + + array_init(return_value); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) { + array_copy(*headers, return_value); + } +} +/* }}} */ + +/* {{{ proto void HttpRequest::unsetHeaders() * - * Add (a) cookie(s). + * Unset previously set request headers. */ -PHP_METHOD(HttpRequest, addCookie) +PHP_METHOD(HttpRequest, unsetHeaders) +{ + zval *opts; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + zend_hash_del(Z_ARRVAL_P(opts), "headers", sizeof("headers")); +} +/* }}} */ + +/* {{{ proto bool HttpRequest::addCookies(array cookies) + * + * Add cookies. + */ +PHP_METHOD(HttpRequest, addCookies) { zval *opts, **cookies, *new_cookies; getObject(http_request_object, obj); @@ -693,6 +793,42 @@ } /* }}} */ +/* {{{ proto array HttpRequest::getCookies() + * + * Get previously set cookies. + */ +PHP_METHOD(HttpRequest, getCookies) +{ + zval *opts, **cookies; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + + array_init(return_value); + + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "cookies", sizeof("cookies"), (void **) &cookies)) { + array_copy(*cookies, return_value); + } +} +/* }}} */ + +/* {{{ proto void HttpRequest::unsetCookies() + * + */ +PHP_METHOD(HttpRequest, unsetCookies) +{ + zval *opts; + getObject(http_request_object, obj); + + NO_ARGS; + + opts = GET_PROP(obj, options); + zend_hash_del(Z_ARRVAL_P(opts), "cookies", sizeof("cookies")); +} +/* }}} */ + /* {{{ proto bool HttpRequest::setURL(string url) * * Set the request URL. @@ -1066,7 +1202,7 @@ } /* }}} */ -/* {{{ proto string HttpRequest::getResponseHeader([string name]) +/* {{{ proto mixed HttpRequest::getResponseHeader([string name]) * * Get response header(s) after the request has been sent. */ @@ -1095,6 +1231,94 @@ RETURN_FALSE; } } +/* }}} */ + +/* {{{ proto array HttpRequest::getResponseCookie([string name]) + * + * Get response cookie(s) after the request has been sent. + */ +PHP_METHOD(HttpRequest, getResponseCookie) +{ + zval *data, **headers; + char *cookie_name = NULL; + int cookie_len = 0; + getObject(http_request_object, obj); + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) { + RETURN_FALSE; + } + + array_init(return_value); + + data = GET_PROP(obj, responseData); + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) { + ulong idx = 0; + char *key = NULL; + zval **header = NULL; + + FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers), key, idx, header) { + if (key && !strcasecmp(key, "Set-Cookie")) { + /* several cookies? */ + if (Z_TYPE_PP(header) == IS_ARRAY) { + zval **cookie; + + FOREACH_HASH_VAL(Z_ARRVAL_PP(header), cookie) { + zval *cookie_hash; + MAKE_STD_ZVAL(cookie_hash); + array_init(cookie_hash); + + if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(cookie), Z_ARRVAL_P(cookie_hash))) { + if (!cookie_len) { + add_next_index_zval(return_value, cookie_hash); + } else { + zval **name; + + if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) && + (!strcmp(Z_STRVAL_PP(name), cookie_name))) { + add_next_index_zval(return_value, cookie_hash); + return; /* <<< FOUND >>> */ + } else { + zval_dtor(cookie_hash); + efree(cookie_hash); + } + } + } else { + zval_dtor(cookie_hash); + efree(cookie_hash); + } + } + } else { + zval *cookie_hash; + MAKE_STD_ZVAL(cookie_hash); + array_init(cookie_hash); + + if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(header), Z_ARRVAL_P(cookie_hash))) { + if (!cookie_len) { + add_next_index_zval(return_value, cookie_hash); + } else { + zval **name; + + if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) && + (!strcmp(Z_STRVAL_PP(name), cookie_name))) { + add_next_index_zval(return_value, cookie_hash); + } else { + zval_dtor(cookie_hash); + efree(cookie_hash); + } + } + } else { + zval_dtor(cookie_hash); + efree(cookie_hash); + } + } + break; + } + /* reset key */ + key = NULL; + } + } +} +/* }}} */ /* {{{ proto string HttpRequest::getResponseBody() * http://cvs.php.net/diff.php/pecl/http/php_http.h?r1=1.36&r2=1.37&ty=u Index: pecl/http/php_http.h diff -u pecl/http/php_http.h:1.36 pecl/http/php_http.h:1.37 --- pecl/http/php_http.h:1.36 Tue Mar 22 06:45:24 2005 +++ pecl/http/php_http.h Thu Mar 24 11:32:47 2005 @@ -13,7 +13,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_http.h,v 1.36 2005/03/22 11:45:24 mike Exp $ */ +/* $Id: php_http.h,v 1.37 2005/03/24 16:32:47 mike Exp $ */ #ifndef PHP_EXT_HTTP_H #define PHP_EXT_HTTP_H @@ -118,8 +118,15 @@ PHP_METHOD(HttpRequest, setOptions); PHP_METHOD(HttpRequest, getOptions); PHP_METHOD(HttpRequest, unsetOptions); -PHP_METHOD(HttpRequest, addHeader); -PHP_METHOD(HttpRequest, addCookie); +PHP_METHOD(HttpRequest, setSslOptions); +PHP_METHOD(HttpRequest, getSslOptions); +PHP_METHOD(HttpRequest, unsetSslOptions); +PHP_METHOD(HttpRequest, addHeaders); +PHP_METHOD(HttpRequest, getHeaders); +PHP_METHOD(HttpRequest, unsetHeaders); +PHP_METHOD(HttpRequest, addCookies); +PHP_METHOD(HttpRequest, getCookies); +PHP_METHOD(HttpRequest, unsetCookies); PHP_METHOD(HttpRequest, setMethod); PHP_METHOD(HttpRequest, getMethod); PHP_METHOD(HttpRequest, setURL); @@ -140,6 +147,7 @@ PHP_METHOD(HttpRequest, send); PHP_METHOD(HttpRequest, getResponseData); PHP_METHOD(HttpRequest, getResponseHeader); +PHP_METHOD(HttpRequest, getResponseCookie); PHP_METHOD(HttpRequest, getResponseCode); PHP_METHOD(HttpRequest, getResponseBody); PHP_METHOD(HttpRequest, getResponseInfo);
« previous php.pecl.cvs (#2899) next »