- curl grabs longs, so pass longs to curl_easy_setopt()
authorMichael Wallner <mike@php.net>
Thu, 25 May 2006 08:47:21 +0000 (08:47 +0000)
committerMichael Wallner <mike@php.net>
Thu, 25 May 2006 08:47:21 +0000 (08:47 +0000)
- add possibility to reset session cookies only, patch to libcurl has been accepted (7.15.4)

docs/functions.html
http_request_api.c
http_request_object.c
php_http_request_api.h

index d1725a19ff9e28e7b9e8319fe45b14c32a701e9b..b27ed0799bae4709bf67515230a4092a77b61f5e 100644 (file)
@@ -707,9 +707,13 @@ pairs to add.</p>
 <h3 id="HttpRequest_enableCookies">bool HttpRequest::enableCookies()</h3>
 <p>Enable automatic sending of received cookies.<br />
 Note that cuutomly set cookies will be sent anyway.</p>
-<h3 id="HttpRequest_resetCookies">bool HttpRequest::resetCookies()</h3>
+<h3 id="HttpRequest_resetCookies">bool HttpRequest::resetCookies([bool session_only = FALSE])</h3>
 <p>Reset all automatically received/sent cookies.<br />
 Note that customly set cookies are not affected.</p>
+<p>Accepts an optional bool parameter specifying<br />
+whether only session cookies should be reset<br />
+(needs libcurl >= v7.15.4, else libcurl >= v7.14.1).</p>
+<p>Returns TRUE on success, or FALSE on failure.</p>
 <h3 id="HttpRequest_setUrl">bool HttpRequest::setUrl(string url)</h3>
 <p>Set the request URL.</p>
 <p>Expects a string as parameter specifying the request url.</p>
@@ -1430,7 +1434,7 @@ http.cache_log is set.</p>
 </li>
 </ul>
 </div>
-    <p><b>Generated at: Mon, 22 May 2006 11:19:25 +0200</b></p>
+    <p><b>Generated at: Thu, 25 May 2006 10:46:03 +0200</b></p>
 </body>
 </html>
 
index d6a370481dbe2da6cb0c90cbb9e276f7f8f50d6d..b59d943e736853f43eb23df6db80c8fcc0dd784e 100644 (file)
@@ -300,12 +300,12 @@ PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, http_request *request)
 {
        if (ch || (ch = curl_easy_init())) {
 #if defined(ZTS)
-               HTTP_CURL_OPT_EX(ch, CURLOPT_NOSIGNAL, 1);
+               HTTP_CURL_OPT_EX(ch, CURLOPT_NOSIGNAL, 1L);
 #endif
-               HTTP_CURL_OPT_EX(ch, CURLOPT_HEADER, 0);
-               HTTP_CURL_OPT_EX(ch, CURLOPT_FILETIME, 1);
-               HTTP_CURL_OPT_EX(ch, CURLOPT_AUTOREFERER, 1);
-               HTTP_CURL_OPT_EX(ch, CURLOPT_VERBOSE, 1);
+               HTTP_CURL_OPT_EX(ch, CURLOPT_HEADER, 0L);
+               HTTP_CURL_OPT_EX(ch, CURLOPT_FILETIME, 1L);
+               HTTP_CURL_OPT_EX(ch, CURLOPT_AUTOREFERER, 1L);
+               HTTP_CURL_OPT_EX(ch, CURLOPT_VERBOSE, 1L);
                HTTP_CURL_OPT_EX(ch, CURLOPT_HEADERFUNCTION, NULL);
                HTTP_CURL_OPT_EX(ch, CURLOPT_DEBUGFUNCTION, http_curl_raw_callback);
                HTTP_CURL_OPT_EX(ch, CURLOPT_READFUNCTION, http_curl_read_callback);
@@ -334,9 +334,9 @@ PHP_HTTP_API void _http_curl_free(CURL **ch)
 {
        if (*ch) {
                /* avoid nasty segfaults with already cleaned up callbacks */
-               HTTP_CURL_OPT_EX(*ch, CURLOPT_NOPROGRESS, 1);
+               HTTP_CURL_OPT_EX(*ch, CURLOPT_NOPROGRESS, 1L);
                HTTP_CURL_OPT_EX(*ch, CURLOPT_PROGRESSFUNCTION, NULL);
-               HTTP_CURL_OPT_EX(*ch, CURLOPT_VERBOSE, 0);
+               HTTP_CURL_OPT_EX(*ch, CURLOPT_VERBOSE, 0L);
                HTTP_CURL_OPT_EX(*ch, CURLOPT_DEBUGFUNCTION, NULL);
                curl_easy_cleanup(*ch);
                *ch = NULL;
@@ -432,16 +432,26 @@ PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request)
 }
 /* }}} */
 
-/* {{{ STATUS http_request_reset_cookies(http_request *) */
-PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request)
+/* {{{ STATUS http_request_reset_cookies(http_request *, int) */
+PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only)
 {
        TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
+       
+       if (session_only) {
+#if HTTP_CURL_VERSION(7,15,4)
+               curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "SESS");
+               return SUCCESS;
+#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 (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL")) {
+               curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL");
                return SUCCESS;
-       }
+#else
+               http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies (need libcurl >= v7.14.1)");
 #endif
-       http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies");
+       }
        return FAILURE;
 }
 /* }}} */
@@ -452,23 +462,23 @@ PHP_HTTP_API void _http_request_defaults(http_request *request)
        if (request->ch) {
                HTTP_CURL_OPT(CURLOPT_PROGRESSFUNCTION, NULL);
                HTTP_CURL_OPT(CURLOPT_URL, NULL);
-               HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 1);
+               HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 1L);
                HTTP_CURL_OPT(CURLOPT_PROXY, NULL);
-               HTTP_CURL_OPT(CURLOPT_PROXYPORT, 0);
-               HTTP_CURL_OPT(CURLOPT_PROXYTYPE, 0);
+               HTTP_CURL_OPT(CURLOPT_PROXYPORT, 0L);
+               HTTP_CURL_OPT(CURLOPT_PROXYTYPE, 0L);
                HTTP_CURL_OPT(CURLOPT_PROXYUSERPWD, NULL);
-               HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0);
+               HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0L);
                HTTP_CURL_OPT(CURLOPT_INTERFACE, NULL);
-               HTTP_CURL_OPT(CURLOPT_PORT, 0);
+               HTTP_CURL_OPT(CURLOPT_PORT, 0L);
 #if HTTP_CURL_VERSION(7,15,2)
-               HTTP_CURL_OPT(CURLOPT_LOCALPORT, 0);
-               HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, 0);
+               HTTP_CURL_OPT(CURLOPT_LOCALPORT, 0L);
+               HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, 0L);
 #endif
                HTTP_CURL_OPT(CURLOPT_USERPWD, NULL);
-               HTTP_CURL_OPT(CURLOPT_HTTPAUTH, 0);
+               HTTP_CURL_OPT(CURLOPT_HTTPAUTH, 0L);
                HTTP_CURL_OPT(CURLOPT_ENCODING, NULL);
-               HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, 0);
-               HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, 0);
+               HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, 0L);
+               HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, 0L);
                HTTP_CURL_OPT(CURLOPT_REFERER, NULL);
                HTTP_CURL_OPT(CURLOPT_USERAGENT, "PECL::HTTP/" PHP_EXT_HTTP_VERSION " (PHP/" PHP_VERSION ")");
                HTTP_CURL_OPT(CURLOPT_HTTPHEADER, NULL);
@@ -477,11 +487,11 @@ PHP_HTTP_API void _http_request_defaults(http_request *request)
                HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL);
 #endif
                HTTP_CURL_OPT(CURLOPT_RANGE, NULL);
-               HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0);
-               HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0);
-               HTTP_CURL_OPT(CURLOPT_TIMECONDITION, 0);
-               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, 0);
-               HTTP_CURL_OPT(CURLOPT_TIMEOUT, 0);
+               HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0L);
+               HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0L);
+               HTTP_CURL_OPT(CURLOPT_TIMECONDITION, 0L);
+               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, 0L);
+               HTTP_CURL_OPT(CURLOPT_TIMEOUT, 0L);
                HTTP_CURL_OPT(CURLOPT_CONNECTTIMEOUT, 3);
                HTTP_CURL_OPT(CURLOPT_SSLCERT, NULL);
                HTTP_CURL_OPT(CURLOPT_SSLCERTTYPE, NULL);
@@ -490,26 +500,26 @@ PHP_HTTP_API void _http_request_defaults(http_request *request)
                HTTP_CURL_OPT(CURLOPT_SSLKEYTYPE, NULL);
                HTTP_CURL_OPT(CURLOPT_SSLKEYPASSWD, NULL);
                HTTP_CURL_OPT(CURLOPT_SSLENGINE, NULL);
-               HTTP_CURL_OPT(CURLOPT_SSLVERSION, 0);
-               HTTP_CURL_OPT(CURLOPT_SSL_VERIFYPEER, 0);
-               HTTP_CURL_OPT(CURLOPT_SSL_VERIFYHOST, 0);
+               HTTP_CURL_OPT(CURLOPT_SSLVERSION, 0L);
+               HTTP_CURL_OPT(CURLOPT_SSL_VERIFYPEER, 0L);
+               HTTP_CURL_OPT(CURLOPT_SSL_VERIFYHOST, 0L);
                HTTP_CURL_OPT(CURLOPT_SSL_CIPHER_LIST, NULL);
                HTTP_CURL_OPT(CURLOPT_CAINFO, NULL);
                HTTP_CURL_OPT(CURLOPT_CAPATH, NULL);
                HTTP_CURL_OPT(CURLOPT_RANDOM_FILE, NULL);
                HTTP_CURL_OPT(CURLOPT_EGDSOCKET, NULL);
                HTTP_CURL_OPT(CURLOPT_POSTFIELDS, NULL);
-               HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, 0);
+               HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, 0L);
                HTTP_CURL_OPT(CURLOPT_HTTPPOST, NULL);
                HTTP_CURL_OPT(CURLOPT_IOCTLDATA, NULL);
                HTTP_CURL_OPT(CURLOPT_READDATA, NULL);
-               HTTP_CURL_OPT(CURLOPT_INFILESIZE, 0);
+               HTTP_CURL_OPT(CURLOPT_INFILESIZE, 0L);
                HTTP_CURL_OPT(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
                HTTP_CURL_OPT(CURLOPT_CUSTOMREQUEST, NULL);
-               HTTP_CURL_OPT(CURLOPT_NOBODY, 0);
-               HTTP_CURL_OPT(CURLOPT_POST, 0);
-               HTTP_CURL_OPT(CURLOPT_UPLOAD, 0);
-               HTTP_CURL_OPT(CURLOPT_HTTPGET, 1);
+               HTTP_CURL_OPT(CURLOPT_NOBODY, 0L);
+               HTTP_CURL_OPT(CURLOPT_POST, 0L);
+               HTTP_CURL_OPT(CURLOPT_UPLOAD, 0L);
+               HTTP_CURL_OPT(CURLOPT_HTTPGET, 1L);
        }
 }
 /* }}} */
@@ -613,7 +623,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 
        /* redirects, defaults to 0 */
        if ((zoption = http_request_option(request, options, "redirect", IS_LONG))) {
-               HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
+               HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1L : 0L);
                HTTP_CURL_OPT(CURLOPT_MAXREDIRS, Z_LVAL_P(zoption));
                if ((zoption = http_request_option(request, options, "unrestrictedauth", IS_BOOL))) {
                        HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
@@ -636,7 +646,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        }
 
        /* resume */
-       if ((zoption = http_request_option(request, options, "resume", IS_LONG)) && (Z_LVAL_P(zoption) != 0)) {
+       if ((zoption = http_request_option(request, options, "resume", IS_LONG)) && (Z_LVAL_P(zoption) > 0)) {
                range_req = 1;
                HTTP_CURL_OPT(CURLOPT_RESUME_FROM, Z_LVAL_P(zoption));
        }
@@ -735,9 +745,9 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
                        if (Z_LVAL_P(zoption) > 0) {
                                HTTP_CURL_OPT(CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
                        } else {
-                               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption));
+                               HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption));
                        }
-                       HTTP_CURL_OPT(CURLOPT_TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE);
+                       HTTP_CURL_OPT(CURLOPT_TIMECONDITION, (long) (range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE));
                } else {
                        HTTP_CURL_OPT(CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
                }
@@ -783,7 +793,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
 
        /* don't load session cookies from cookiestore */
        if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL)) && Z_BVAL_P(zoption)) {
-               HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1);
+               HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1L);
        }
 
        /* cookiestore, read initial cookies from that file and store cookies back into that file */
@@ -853,19 +863,19 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti
        /* request method */
        switch (request->meth) {
                case HTTP_GET:
-                       HTTP_CURL_OPT(CURLOPT_HTTPGET, 1);
+                       HTTP_CURL_OPT(CURLOPT_HTTPGET, 1L);
                        break;
 
                case HTTP_HEAD:
-                       HTTP_CURL_OPT(CURLOPT_NOBODY, 1);
+                       HTTP_CURL_OPT(CURLOPT_NOBODY, 1L);
                        break;
 
                case HTTP_POST:
-                       HTTP_CURL_OPT(CURLOPT_POST, 1);
+                       HTTP_CURL_OPT(CURLOPT_POST, 1L);
                        break;
 
                case HTTP_PUT:
-                       HTTP_CURL_OPT(CURLOPT_UPLOAD, 1);
+                       HTTP_CURL_OPT(CURLOPT_UPLOAD, 1L);
                        break;
 
                default:
index 45625f0f777ab4dbf1fa0be4d5e229ed5818e591..d90803db8ce87cdda5b273dd53d68b4b5202075f 100644 (file)
@@ -74,7 +74,9 @@ HTTP_END_ARGS;
 
 HTTP_EMPTY_ARGS(enableCookies);
 #if HTTP_CURL_VERSION(7,14,1)
-HTTP_EMPTY_ARGS(resetCookies);
+HTTP_BEGIN_ARGS(resetCookies, 0)
+       HTTP_ARG_VAL(session_only, 0)
+HTTP_END_ARGS;
 #endif
 
 HTTP_EMPTY_ARGS(getUrl);
@@ -881,8 +883,13 @@ PHP_METHOD(HttpRequest, setOptions)
 #if HTTP_CURL_VERSION(7,14,1)
                        } else if (!strcmp(key, "resetcookies")) {
                                getObject(http_request_object, obj);
-                               http_request_reset_cookies(obj->request);
+                               http_request_reset_cookies(obj->request, 0);
 #endif
+                       } else if (!strcmp(key, "enablecookies")) {
+                               getObject(http_request_object, obj);
+                               http_request_enable_cookies(obj->request);
+                       } else if (!strcasecmp(key, "recordHistory")) {
+                               UPD_PROP(bool, recordHistory, 1);
                        } else {
                                ZVAL_ADDREF(*opt);
                                add_assoc_zval(add_opts, key, *opt);
@@ -1060,17 +1067,26 @@ PHP_METHOD(HttpRequest, enableCookies)
 }
 /* }}} */
 
-/* {{{ proto bool HttpRequest::resetCookies()
+/* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
  *
  * Reset all automatically received/sent cookies.
  * Note that customly set cookies are not affected.
+ *
+ * Accepts an optional bool parameter specifying
+ * whether only session cookies should be reset
+ * (needs libcurl >= v7.15.4, else libcurl >= v7.14.1).
+ *
+ * Returns TRUE on success, or FALSE on failure.
  */
 PHP_METHOD(HttpRequest, resetCookies)
 {
-       NO_ARGS {
-               getObject(http_request_object, obj);
-               RETURN_SUCCESS(http_request_reset_cookies(obj->request));
+       zend_bool session_only = 0;
+       getObject(http_request_object, obj);
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &session_only)) {
+               RETURN_FALSE;
        }
+       RETURN_SUCCESS(http_request_reset_cookies(obj->request, session_only));
 }
 /* }}} */
 
index 5666fecbdc09fa181a176799ca6d3200644deebe..286792dae8a563c1ecfdcd5feebe16572d3bc4f7 100644 (file)
@@ -74,8 +74,8 @@ PHP_HTTP_API void _http_request_reset(http_request *r);
 #define http_request_enable_cookies(r) _http_request_enable_cookies(r)
 PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request);
 
-#define http_request_reset_cookies(r) _http_request_reset_cookies(r)
-PHP_HTTP_API STATUS _http_request_reset_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_defaults(r) _http_request_defaults(r)
 PHP_HTTP_API void _http_request_defaults(http_request *request);