- fix build on Debian systems where access to Curl_* functions is prohibited
[m6w6/ext-http] / http_request_object.c
index 60935420a651332df6c027089e3512c694b26459..40e36bc61586bdd986fe959e6bc16944958688e6 100644 (file)
@@ -72,8 +72,11 @@ HTTP_BEGIN_ARGS(addCookies, 1)
        HTTP_ARG_VAL(cookies, 0)
 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);
@@ -231,10 +234,12 @@ HTTP_BEGIN_ARGS(methodExists, 1)
        HTTP_ARG_VAL(method, 0)
 HTTP_END_ARGS;
 
+#ifdef HAVE_CURL_GETFORMDATA
 HTTP_BEGIN_ARGS(encodeBody, 2)
        HTTP_ARG_VAL(fields, 0)
        HTTP_ARG_VAL(files, 0)
 HTTP_END_ARGS;
+#endif
 
 #define OBJ_PROP_CE http_request_object_ce
 zend_class_entry *http_request_object_ce;
@@ -254,6 +259,8 @@ zend_function_entry http_request_object_fe[] = {
        HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC)
        HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC)
        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
@@ -318,9 +325,9 @@ 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 HAVE_CURL_GETFORMDATA
        HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode)
-
+#endif
        EMPTY_FUNCTION_ENTRY
 };
 static zend_object_handlers http_request_object_handlers;
@@ -472,15 +479,6 @@ void _http_request_object_free(zend_object *object TSRMLS_DC)
        efree(o);
 }
 
-#if HTTP_CURL_VERSION(7,14,1)
-#define http_request_object_resetcookies(o) _http_request_object_resetcookies((o) TSRMLS_CC)
-static inline STATUS _http_request_object_resetcookies(zval *this_ptr TSRMLS_DC)
-{
-       getObject(http_request_object, obj);
-       return curl_easy_setopt(obj->request->ch, CURLOPT_COOKIELIST, "ALL");
-}
-#endif
-
 #define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
 static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
 {
@@ -886,8 +884,14 @@ PHP_METHOD(HttpRequest, setOptions)
                                zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt);
 #if HTTP_CURL_VERSION(7,14,1)
                        } else if (!strcmp(key, "resetcookies")) {
-                               http_request_object_resetcookies(getThis());
+                               getObject(http_request_object, obj);
+                               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);
@@ -1050,18 +1054,43 @@ PHP_METHOD(HttpRequest, getCookies)
 }
 /* }}} */
 
-#if HTTP_CURL_VERSION(7,14,1)
-/* {{{ proto bool HttpRequest::resetCookies()
+/* {{{ proto bool HttpRequest::enableCookies()
+ *
+ * Enable automatic sending of received cookies.
+ * Note that cuutomly set cookies will be sent anyway.
+ */
+PHP_METHOD(HttpRequest, enableCookies)
+{
+       NO_ARGS {
+               getObject(http_request_object, obj);
+               RETURN_SUCCESS(http_request_enable_cookies(obj->request));
+       }
+       
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
+ *
+ * Reset all automatically received/sent cookies.
+ * Note that customly set cookies are not affected.
  *
- * Reset all 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;
-       RETURN_SUCCESS(http_request_object_resetcookies(getThis()));
+       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));
 }
 /* }}} */
-#endif
 
 /* {{{ proto bool HttpRequest::setUrl(string url)
  *