- deprecate HttpRequest::*RawPostData() in favour of ::*Body()
[m6w6/ext-http] / http_request_datashare_api.c
index 2bf05632daa71b2d9312eda6831b657765c56b20..6c70f3f7f88fe8f47f288f239cbbfcf2f9d9df6f 100644 (file)
 #include "php_http_request_datashare_api.h"
 #include "php_http_request_api.h"
 #include "php_http_request_object.h"
-
-#ifndef HAVE_CURL_SHARE_STRERROR
-#      define curl_share_strerror(dummy) "unknown error"
+#ifdef HTTP_HAVE_PERSISTENT_HANDLES
+#      include "php_http_persistent_handle_api.h"
 #endif
-#ifndef HAVE_CURL_EASY_STRERROR
-#      define curl_easy_strerror(dummy) "unknown error"
+
+#ifdef HTTP_HAVE_PERSISTENT_HANDLES
+#      define HTTP_CURL_SHARE_CTOR(ch) (SUCCESS == http_persistent_handle_acquire("http_request_datashare", &(ch)))
+#      define HTTP_CURL_SHARE_DTOR(chp) http_persistent_handle_release("http_request_datashare", (chp))
+#else
+#      define HTTP_CURL_SHARE_CTOR(ch) ((ch) = curl_share_init())
+#      define HTTP_CURL_SHARE_DTOR(chp) curl_share_cleanup(*(chp)); *(chp) = NULL
 #endif
 
 static HashTable http_request_datashare_options;
@@ -47,6 +51,16 @@ PHP_MINIT_FUNCTION(http_request_datashare)
 {
        curl_lock_data val;
        
+#ifdef HTTP_HAVE_PERSISTENT_HANDLES
+       if (SUCCESS != http_persistent_handle_provide("http_request_datashare", curl_share_init, (http_persistent_handle_dtor) curl_share_cleanup)) {
+               return FAILURE;
+       }
+#endif
+       
+       if (!http_request_datashare_init_ex(&http_request_datashare_global, 1)) {
+               return FAILURE;
+       }
+       
        zend_hash_init(&http_request_datashare_options, 4, NULL, NULL, 1);
 #define ADD_DATASHARE_OPT(name, opt) \
        val = opt; \
@@ -56,8 +70,6 @@ PHP_MINIT_FUNCTION(http_request_datashare)
        ADD_DATASHARE_OPT("ssl", CURL_LOCK_DATA_SSL_SESSION);
        ADD_DATASHARE_OPT("connect", CURL_LOCK_DATA_CONNECT);
        
-       http_request_datashare_init_ex(&http_request_datashare_global, 1);
-       
        return SUCCESS;
 }
 
@@ -92,8 +104,7 @@ PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_reques
        }
        memset(share, 0, sizeof(http_request_datashare));
        
-       HTTP_CHECK_CURL_INIT(share->ch, curl_share_init(), ;);
-       if (!share->ch) {
+       if (!HTTP_CURL_SHARE_CTOR(share->ch)) {
                if (free_share) {
                        pefree(share, persistent);
                }
@@ -180,7 +191,7 @@ PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSR
                zend_llist_destroy(share->handles);
                efree(share->handles);
        }
-       curl_share_cleanup(share->ch);
+       HTTP_CURL_SHARE_DTOR(&share->ch);
 #ifdef ZTS
        if (share->persistent) {
                int i;
@@ -223,10 +234,13 @@ static void http_request_datashare_destroy_handles(void *el)
 {
        zval **r = (zval **) el;
        TSRMLS_FETCH();
-       getObjectEx(http_request_object, obj, *r);
        
-       curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL);
-       zval_ptr_dtor(r);
+       { /* gcc 2.95 needs these braces */
+               getObjectEx(http_request_object, obj, *r);
+               
+               curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL);
+               zval_ptr_dtor(r);
+       }
 }
 
 #ifdef ZTS