From ef504c97eb98ff93e63d32452aca0684ed3c514a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 5 Oct 2007 07:36:08 +0000 Subject: [PATCH] - add HttpRequest::flushCookies() (libcurl>=7.17.1) - fix HttpRequest's resetCookies() and enableCookies() to only trigger the error if libcurl version is insufficient - don't use zval_is_true, which converts the zval to boolean - remove all refs to HAVE_CURL_GETFORMDATA --- http_functions.c | 2 +- http_request_api.c | 27 ++++++++++++++++++++++-- http_request_body_api.c | 2 +- http_request_object.c | 38 ++++++++++++++++++++++------------ http_requestdatashare_object.c | 2 +- http_response_object.c | 6 +++--- package2.xml | 19 ++++++++++++----- php_http_request_api.h | 3 +++ php_http_request_object.h | 1 + 9 files changed, 74 insertions(+), 26 deletions(-) diff --git a/http_functions.c b/http_functions.c index 4527c25..f7f73f7 100644 --- a/http_functions.c +++ b/http_functions.c @@ -856,7 +856,7 @@ PHP_FUNCTION(http_persistent_handles_ident) zval **bodyonly; \ \ /* check if only the body should be returned */ \ - if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void *) &bodyonly)) && zval_is_true(*bodyonly)) { \ + if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void *) &bodyonly)) && i_zend_is_true(*bodyonly)) { \ http_message *msg = http_message_parse(PHPSTR_VAL(&request.conv.response), PHPSTR_LEN(&request.conv.response)); \ \ if (msg) { \ diff --git a/http_request_api.c b/http_request_api.c index 33450a3..728fe3f 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -401,20 +401,38 @@ PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int sessi if (initialized && CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "SESS")) { return SUCCESS; } -#endif +#else http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset session cookies (need libcurl >= v7.15.4)"); +#endif } else { #if HTTP_CURL_VERSION(7,14,1) if (initialized && CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL")) { return SUCCESS; } -#endif +#else http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies (need libcurl >= v7.14.1)"); +#endif } return FAILURE; } /* }}} */ +PHP_HTTP_API STATUS _http_request_flush_cookies(http_request *request) +{ + int initialized = 1; + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls); + + HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0); +#if HTTP_CURL_VERSION(7,17,1) + if (initialized && CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "FLUSH")) { + return SUCCESS; + } +#else + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not flush cookies (need libcurl >= v7.17.1)"); +#endif + return FAILURE; +} + /* {{{ void http_request_defaults(http_request *) */ PHP_HTTP_API void _http_request_defaults(http_request *request) { @@ -450,6 +468,11 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(CURLOPT_USERPWD, NULL); HTTP_CURL_OPT(CURLOPT_HTTPAUTH, 0L); HTTP_CURL_OPT(CURLOPT_ENCODING, NULL); +#if HTTP_CURL_VERSION(7,16,2) + /* we do this ourself anyway */ + HTTP_CURL_OPT(CURLOPT_HTTP_CONTENT_DECODING, 0L); + HTTP_CURL_OPT(CURLOPT_HTTP_TRANSFER_DECODING, 0L); +#endif HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, 0L); HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, 0L); HTTP_CURL_OPT(CURLOPT_REFERER, NULL); diff --git a/http_request_body_api.c b/http_request_body_api.c index 39cba65..f2d5f56 100644 --- a/http_request_body_api.c +++ b/http_request_body_api.c @@ -145,7 +145,7 @@ PHP_HTTP_API STATUS _http_request_body_encode(http_request_body *body, char **bu switch (body->type) { case HTTP_REQUEST_BODY_CURLPOST: { -#if defined(HAVE_CURL_FORMGET) +#ifdef HAVE_CURL_FORMGET phpstr str; phpstr_init_ex(&str, 0x8000, 0); diff --git a/http_request_object.c b/http_request_object.c index 7f427b8..f9bbf5e 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -81,11 +81,10 @@ HTTP_BEGIN_ARGS(addCookies, 1) HTTP_END_ARGS; HTTP_EMPTY_ARGS(enableCookies); -#if HTTP_CURL_VERSION(7,14,1) HTTP_BEGIN_ARGS(resetCookies, 0) HTTP_ARG_VAL(session_only, 0) HTTP_END_ARGS; -#endif +HTTP_EMPTY_ARGS(flushCookies); HTTP_EMPTY_ARGS(getUrl); HTTP_BEGIN_ARGS(setUrl, 1) @@ -242,7 +241,7 @@ HTTP_BEGIN_ARGS(methodExists, 1) HTTP_ARG_VAL(method, 0) HTTP_END_ARGS; -#if defined(HAVE_CURL_GETFORMDATA) || defined(HAVE_CURL_FORMGET) +#ifdef HAVE_CURL_FORMGET HTTP_BEGIN_ARGS(encodeBody, 2) HTTP_ARG_VAL(fields, 0) HTTP_ARG_VAL(files, 0) @@ -269,9 +268,8 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(enableCookies, ZEND_ACC_PUBLIC) -#if HTTP_CURL_VERSION(7,14,1) HTTP_REQUEST_ME(resetCookies, ZEND_ACC_PUBLIC) -#endif + HTTP_REQUEST_ME(flushCookies, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC) @@ -338,7 +336,7 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister) HTTP_REQUEST_ALIAS(methodName, http_request_method_name) HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists) -#if defined(HAVE_CURL_GETFORMDATA) || defined(HAVE_CURL_FORMGET) +#ifdef HAVE_CURL_FORMGET HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode) #endif EMPTY_FUNCTION_ENTRY @@ -635,7 +633,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ if ( (Z_TYPE_P(options) != IS_ARRAY) || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void *) &entry) - || (!zval_is_true(*entry)))) { + || (!zend_is_callable(*entry, 0, NULL)))) { MAKE_STD_ZVAL(pcb); array_init(pcb); ZVAL_ADDREF(getThis()); @@ -670,7 +668,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)))) { zval *message; - if (zval_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) { + if (i_zend_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) { zval *hist, *history = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC); http_message *response = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)); http_message *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)); @@ -706,7 +704,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("responseStatus")-1, "" TSRMLS_CC); /* append request message to history */ - if (zval_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) { + if (i_zend_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) { http_message *request; if ((request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) { @@ -904,16 +902,19 @@ PHP_METHOD(HttpRequest, setOptions) zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt); } else if (KEYMATCH(key, "method")) { zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt); -#if HTTP_CURL_VERSION(7,14,1) + } else if (KEYMATCH(key, "flushcookies")) { + getObject(http_request_object, obj); + if (i_zend_is_true(*opt)) { + http_request_flush_cookies(obj->request); + } } else if (KEYMATCH(key, "resetcookies")) { getObject(http_request_object, obj); - http_request_reset_cookies(obj->request, 0); -#endif + http_request_reset_cookies(obj->request, (zend_bool) i_zend_is_true(*opt)); } else if (KEYMATCH(key, "enablecookies")) { getObject(http_request_object, obj); http_request_enable_cookies(obj->request); } else if (KEYMATCH(key, "recordHistory")) { - zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 1 TSRMLS_CC); + zend_update_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, *opt TSRMLS_CC); } else if (Z_TYPE_PP(opt) == IS_NULL) { old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC); if (Z_TYPE_P(old_opts) == IS_ARRAY) { @@ -1048,6 +1049,17 @@ PHP_METHOD(HttpRequest, resetCookies) } /* }}} */ +/* {{{ proto bool HttpRequest::flushCookies() + Flush internal cookies to the cookiestore file */ +PHP_METHOD(HttpRequest, flushCookies) +{ + NO_ARGS { + getObject(http_request_object, obj); + RETURN_SUCCESS(http_request_flush_cookies(obj->request)); + } +} +/* }}} */ + /* {{{ proto bool HttpRequest::setUrl(string url) Set the request URL. */ PHP_METHOD(HttpRequest, setUrl) diff --git a/http_requestdatashare_object.c b/http_requestdatashare_object.c index 8b4a51d..91a2fa6 100644 --- a/http_requestdatashare_object.c +++ b/http_requestdatashare_object.c @@ -163,7 +163,7 @@ static void _http_requestdatashare_object_write_prop(zval *object, zval *member, getObjectEx(http_requestdatashare_object, obj, object); SEPARATE_ZVAL_IF_NOT_REF(&value); - status = http_request_datashare_set(obj->share, Z_STRVAL_P(member), Z_STRLEN_P(member), (zend_bool) zval_is_true(value)); + status = http_request_datashare_set(obj->share, Z_STRVAL_P(member), Z_STRLEN_P(member), (zend_bool) i_zend_is_true(value)); if (orig != value) { zval_ptr_dtor(&value); value = orig; diff --git a/http_response_object.c b/http_response_object.c index 2360d68..ed634af 100644 --- a/http_response_object.c +++ b/http_response_object.c @@ -795,7 +795,7 @@ PHP_METHOD(HttpResponse, send) } /* capture mode */ - if (zval_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("catch")-1, 0 TSRMLS_CC))) { + if (i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("catch")-1, 0 TSRMLS_CC))) { zval *etag_p, *the_data; MAKE_STD_ZVAL(the_data); @@ -827,7 +827,7 @@ PHP_METHOD(HttpResponse, send) } /* caching */ - if (zval_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("cache")-1, 0 TSRMLS_CC))) { + if (i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("cache")-1, 0 TSRMLS_CC))) { zval *cctl, *cctl_p, *etag, *etag_p, *lmod, *lmod_p; etag = convert_to_type_ex(IS_STRING, *zend_std_get_static_property(THIS_CE, ZEND_STRS("eTag")-1, 0 TSRMLS_CC), &etag_p); @@ -895,7 +895,7 @@ PHP_METHOD(HttpResponse, send) } /* gzip */ - HTTP_G->send.deflate.response = zval_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("gzip")-1, 0 TSRMLS_CC)); + HTTP_G->send.deflate.response = i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("gzip")-1, 0 TSRMLS_CC)); /* send */ switch (Z_LVAL_P(*zend_std_get_static_property(THIS_CE, ZEND_STRS("mode")-1, 0 TSRMLS_CC))) { diff --git a/package2.xml b/package2.xml index 1576885..25f698c 100644 --- a/package2.xml +++ b/package2.xml @@ -30,7 +30,7 @@ support. Parallel requests are available for PHP 5 and greater. 2007-09-26 - 1.6.0b2 + 1.6.0RC1 1.6.0 @@ -39,16 +39,25 @@ support. Parallel requests are available for PHP 5 and greater. BSD, revised = 7.17.1) +* Fixed problems with cookiestore request option introduced with persistent handles +* Fixed crash on prematurely called HttpMessage::next() +* Fixed possible shutdown crash with http_parse_params() and PHP4 + +1.6.0b2: + Added constant HTTP_URL_FROM_ENV -+ Added 'retrycount' and 'retrydelay' request options -+ Added libevent support for libcurl (>= 7.16.0): - o added --with-http-curl-libevent configure option - o added HttpRequestPool::enableEvents() * Fixed a possible crash at module shutdown in the persistent handle API (probably fixing bug #11509) * Fixed test suite for PHP4 * Fixed missing PHP_LIBDIR definition in config.m4 for PHP4 * Fixed non-standard shell support in config.m4 + +1.6.0b1: ++ Added 'retrycount' and 'retrydelay' request options ++ Added libevent support for libcurl (>= 7.16.0): + o added --with-http-curl-libevent configure option + o added HttpRequestPool::enableEvents() ]]> diff --git a/php_http_request_api.h b/php_http_request_api.h index dfb2e32..f0b6858 100644 --- a/php_http_request_api.h +++ b/php_http_request_api.h @@ -112,6 +112,9 @@ PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request); #define http_request_reset_cookies(r, s) _http_request_reset_cookies((r), (s)) PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only); +#define http_request_flush_cookies(r) _http_request_flush_cookies(r) +PHP_HTTP_API STATUS _http_request_flush_cookies(http_request *request); + #define http_request_defaults(r) _http_request_defaults(r) PHP_HTTP_API void _http_request_defaults(http_request *request); diff --git a/php_http_request_object.h b/php_http_request_object.h index ad7e9c5..93c6b36 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -61,6 +61,7 @@ PHP_METHOD(HttpRequest, getCookies); PHP_METHOD(HttpRequest, setCookies); PHP_METHOD(HttpRequest, enableCookies); PHP_METHOD(HttpRequest, resetCookies); +PHP_METHOD(HttpRequest, flushCookies); PHP_METHOD(HttpRequest, setMethod); PHP_METHOD(HttpRequest, getMethod); PHP_METHOD(HttpRequest, setUrl); -- 2.30.2