- add HttpRequest::flushCookies() (libcurl>=7.17.1)
authorMichael Wallner <mike@php.net>
Fri, 5 Oct 2007 07:36:08 +0000 (07:36 +0000)
committerMichael Wallner <mike@php.net>
Fri, 5 Oct 2007 07:36:08 +0000 (07:36 +0000)
- 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
http_request_api.c
http_request_body_api.c
http_request_object.c
http_requestdatashare_object.c
http_response_object.c
package2.xml
php_http_request_api.h
php_http_request_object.h

index 4527c25388f0f8b16a0d215513e7d52649a76a14..f7f73f75afd5b957368ee8951a6df83e96c1f386 100644 (file)
@@ -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) { \
index 33450a3f53a043398da23cffe194b72505f31722..728fe3f2357a65cfb008e720b16d4a75ffc0f9f2 100644 (file)
@@ -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);
index 39cba652c70cf7e14390fbaa564b1236f36e45c7..f2d5f5684569e8294b8e5aac3e3bdd2830d8671c 100644 (file)
@@ -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);
index 7f427b8c0eda5e3a915dfa0e6543ef42ee6da730..f9bbf5e018451225b350145b4cf89796a965bd7b 100644 (file)
@@ -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)
index 8b4a51df89e0ba9468eba95606501a4464275d46..91a2fa6f0af650c8edf6368ebe8167c045d57204 100644 (file)
@@ -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;
index 2360d68765b7b387e2830a62d44742ff85c5e5b0..ed634afa869cb7be0d4ad0eff339c1fda1c1b917 100644 (file)
@@ -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))) {
index 1576885d35b0b2a45d7b6fdd489b7d710b41424f..25f698cadb464df956c32bfe13dadd50b73f234e 100644 (file)
@@ -30,7 +30,7 @@ support. Parallel requests are available for PHP 5 and greater.
  </lead>
  <date>2007-09-26</date>
  <version>
-  <release>1.6.0b2</release>
+  <release>1.6.0RC1</release>
   <api>1.6.0</api>
  </version>
  <stability>
@@ -39,16 +39,25 @@ support. Parallel requests are available for PHP 5 and greater.
  </stability>
  <license>BSD, revised</license>
  <notes><![CDATA[
+1.6.0RC1:
++ Added HttpRequest::flushCookies() (libcurl >= 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()
 ]]></notes>
  <contents>
   <dir name="/">
index dfb2e32c8860f158e86adb1f2c261fd22d1d01c1..f0b68589d551eb34a458042a70776e46123eb7c1 100644 (file)
@@ -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);
 
index ad7e9c52dc45a29939356f0f20d012f00b384975..93c6b3627d7b1a66437fe7c513e9eff63c911ca6 100644 (file)
@@ -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);