X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_curl_client_datashare.c;h=1957c2bdba92308aad65b7c071a13e37cc7420e6;hb=bfa5d473bdfb59fd39f04c2b8fb77ea4a7e9421b;hp=1b47eb56e786163debe707816a8269bbaac3638b;hpb=2769c041b77a0aaba7acbee4ae469571eaeb2b0a;p=m6w6%2Fext-http diff --git a/php_http_curl_client_datashare.c b/php_http_curl_client_datashare.c index 1b47eb5..1957c2b 100644 --- a/php_http_curl_client_datashare.c +++ b/php_http_curl_client_datashare.c @@ -19,7 +19,7 @@ typedef struct php_http_curl_client_datashare { } php_http_curl_client_datashare_t; -static void *php_http_curlsh_ctor(void *opaque TSRMLS_DC) +static void *php_http_curlsh_ctor(void *opaque, void *init_arg TSRMLS_DC) { return curl_share_init(); } @@ -37,7 +37,7 @@ static php_http_client_datashare_t *php_http_curl_client_datashare_init(php_http php_http_curl_client_datashare_t *curl; TSRMLS_FETCH_FROM_CTX(h->ts); - if (!handle && !(handle = php_http_resource_factory_handle_ctor(h->rf TSRMLS_CC))) { + if (!handle && !(handle = php_resource_factory_handle_ctor(h->rf, NULL TSRMLS_CC))) { php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_DATASHARE, "could not initialize curl share handle"); return NULL; } @@ -54,7 +54,7 @@ static void php_http_curl_client_datashare_dtor(php_http_client_datashare_t *h) php_http_curl_client_datashare_t *curl = h->ctx; TSRMLS_FETCH_FROM_CTX(h->ts); - php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC); + php_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC); efree(curl); h->ctx = NULL; @@ -67,6 +67,11 @@ static STATUS php_http_curl_client_datashare_attach(php_http_client_datashare_t php_http_curl_client_t *recurl = r->ctx; TSRMLS_FETCH_FROM_CTX(h->ts); + if (r->ops != php_http_curl_client_get_ops()) { + php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_DATASHARE, "Cannot attach a non-curl client to this datashare"); + return FAILURE; + } + if (CURLE_OK != (rc = curl_easy_setopt(recurl->handle, CURLOPT_SHARE, curl->handle))) { php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_DATASHARE, "Could not attach request to the datashare: %s", curl_easy_strerror(rc)); return FAILURE; @@ -81,6 +86,11 @@ static STATUS php_http_curl_client_datashare_detach(php_http_client_datashare_t TSRMLS_FETCH_FROM_CTX(h->ts); + if (r->ops != php_http_curl_client_get_ops()) { + php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_DATASHARE, "Cannot attach a non-curl client to this datashare"); + return FAILURE; + } + if (CURLE_OK != (rc = curl_easy_setopt(recurl->handle, CURLOPT_SHARE, NULL))) { php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_DATASHARE, "Could not detach request from the datashare: %s", curl_share_strerror(rc)); return FAILURE; @@ -130,17 +140,12 @@ static STATUS php_http_curl_client_datashare_setopt(php_http_client_datashare_t return SUCCESS; } -static php_http_resource_factory_ops_t php_http_curlsh_resource_factory_ops = { +static php_resource_factory_ops_t php_http_curlsh_resource_factory_ops = { php_http_curlsh_ctor, NULL, php_http_curlsh_dtor }; -static zend_class_entry *get_class_entry(void) -{ - return php_http_curl_client_datashare_class_entry; -} - static php_http_client_datashare_ops_t php_http_curl_client_datashare_ops = { &php_http_curlsh_resource_factory_ops, php_http_curl_client_datashare_init, @@ -151,7 +156,7 @@ static php_http_client_datashare_ops_t php_http_curl_client_datashare_ops = { php_http_curl_client_datashare_detach, php_http_curl_client_datashare_setopt, (php_http_new_t) php_http_curl_client_datashare_object_new_ex, - get_class_entry + php_http_curl_client_datashare_get_class_entry }; PHP_HTTP_API php_http_client_datashare_ops_t *php_http_curl_client_datashare_get_ops(void) @@ -163,8 +168,14 @@ PHP_HTTP_API php_http_client_datashare_ops_t *php_http_curl_client_datashare_get #define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpClientDataShare, method, 0) #define PHP_HTTP_RSHARE_ME(method, visibility) PHP_ME(HttpClientDataShare, method, PHP_HTTP_ARGS(HttpClientDataShare, method), visibility) -zend_class_entry *php_http_curl_client_datashare_class_entry; -zend_function_entry php_http_curl_client_datashare_method_entry[] = { +static zend_class_entry *php_http_curl_client_datashare_class_entry; + +zend_class_entry *php_http_curl_client_datashare_get_class_entry(void) +{ + return php_http_curl_client_datashare_class_entry; +} + +static zend_function_entry php_http_curl_client_datashare_method_entry[] = { EMPTY_FUNCTION_ENTRY }; @@ -201,7 +212,7 @@ zend_object_value php_http_curl_client_datashare_object_new_ex(zend_class_entry PHP_MINIT_FUNCTION(http_curl_client_datashare) { - if (SUCCESS != php_http_persistent_handle_provide(ZEND_STRL("http_client_datashare.curl"), &php_http_curlsh_resource_factory_ops, NULL, NULL)) { + if (SUCCESS != php_persistent_handle_provide(ZEND_STRL("http_client_datashare.curl"), &php_http_curlsh_resource_factory_ops, NULL, NULL)) { return FAILURE; }