we need libcurl 7.21.5 for UNKNOWN_OPTION and 7.23 for ssl session
[m6w6/ext-http] / src / php_http_client_curl.c
index 5dab9e210037a95b7fe055759f4fadaf68029ec6..d4f051755a207db062c26565c37206a58450aadc 100644 (file)
@@ -1760,6 +1760,48 @@ static ZEND_RESULT_CODE php_http_curlm_option_set_use_eventloop(php_http_option_
 }
 #endif
 
+static ZEND_RESULT_CODE php_http_curlm_option_set_share_cookies(php_http_option_t *opt, zval *value, void *userdata)
+{
+       php_http_client_t *client = userdata;
+       php_http_client_curl_t *curl = client->ctx;
+       CURLSHcode rc;
+
+       if (Z_BVAL_P(value)) {
+               rc = curl_share_setopt(curl->handle->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
+       } else {
+               rc = curl_share_setopt(curl->handle->share, CURLSHOPT_UNSHARE, CURL_LOCK_DATA_COOKIE);
+       }
+
+       if (CURLSHE_OK != rc) {
+               TSRMLS_FETCH_FROM_CTX(client->ts);
+               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_share_strerror(rc));
+               return FAILURE;
+       }
+       return SUCCESS;
+}
+
+#if PHP_HTTP_CURL_VERSION(7,23,0)
+static ZEND_RESULT_CODE php_http_curlm_option_set_share_ssl(php_http_option_t *opt, zval *value, void *userdata)
+{
+       php_http_client_t *client = userdata;
+       php_http_client_curl_t *curl = client->ctx;
+       CURLSHcode rc;
+
+       if (Z_BVAL_P(value)) {
+               rc = curl_share_setopt(curl->handle->share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
+       } else {
+               rc = curl_share_setopt(curl->handle->share, CURLSHOPT_UNSHARE, CURL_LOCK_DATA_SSL_SESSION);
+       }
+
+       if (CURLSHE_OK != rc) {
+               TSRMLS_FETCH_FROM_CTX(client->ts);
+               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_share_strerror(rc));
+               return FAILURE;
+       }
+       return SUCCESS;
+}
+#endif
+
 static void php_http_curlm_options_init(php_http_options_t *registry TSRMLS_DC)
 {
        php_http_option_t *opt;
@@ -1810,6 +1852,17 @@ static void php_http_curlm_options_init(php_http_options_t *registry TSRMLS_DC)
        if ((opt = php_http_option_register(registry, ZEND_STRL("use_eventloop"), 0, IS_BOOL))) {
                opt->setter = php_http_curlm_option_set_use_eventloop;
        }
+#endif
+       /* share */
+       if ((opt = php_http_option_register(registry, ZEND_STRL("share_cookies"), 0, IS_BOOL))) {
+               opt->setter = php_http_curlm_option_set_share_cookies;
+               ZVAL_BOOL(&opt->defval, 1);
+       }
+#if PHP_HTTP_CURL_VERSION(7,23,0)
+       if ((opt = php_http_option_register(registry, ZEND_STRL("share_ssl"), 0, IS_BOOL))) {
+               opt->setter = php_http_curlm_option_set_share_ssl;
+               ZVAL_BOOL(&opt->defval, 1);
+       }
 #endif
 }
 
@@ -1836,15 +1889,18 @@ static ZEND_RESULT_CODE php_http_curlm_set_option(php_http_option_t *opt, zval *
                case IS_BOOL:
                        if (CURLM_OK != (rc = curl_multi_setopt(ch, opt->option, (long) Z_BVAL_P(val)))) {
                                rv = FAILURE;
+                               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_multi_strerror(rc));
                        }
                        break;
                case IS_LONG:
                        if (CURLM_OK != (rc = curl_multi_setopt(ch, opt->option, Z_LVAL_P(val)))) {
                                rv = FAILURE;
+                               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_multi_strerror(rc));
                        }
                        break;
                default:
                        rv = FAILURE;
+                       php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s", opt->name.s);
                        break;
                }
        }
@@ -1853,9 +1909,6 @@ static ZEND_RESULT_CODE php_http_curlm_set_option(php_http_option_t *opt, zval *
                zval_ptr_dtor(&val);
        }
 
-       if (rv != SUCCESS) {
-               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s (%s)", opt->name.s, curl_easy_strerror(rc));
-       }
        return rv;
 }