#endif
PHP_INI_BEGIN()
PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode)
- PHP_HTTP_INI_ENTRY("http.request_datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.cookie)
- PHP_HTTP_INI_ENTRY("http.request_datashare.dns", "1", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.dns)
- PHP_HTTP_INI_ENTRY("http.request_datashare.ssl", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.ssl)
- PHP_HTTP_INI_ENTRY("http.request_datashare.connect", "0", PHP_INI_SYSTEM, OnUpdateBool, request_datashare.connect)
PHP_HTTP_INI_ENTRY("http.persistent_handle.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent_handle.limit)
PHP_INI_END()
#if PHP_HTTP_HAVE_CURL
|| SUCCESS != PHP_MSHUTDOWN_CALL(http_curl)
#endif
- || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)
|| SUCCESS != PHP_MSHUTDOWN_CALL(http_request_factory)
|| SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle)
) {
{
if (0
|| SUCCESS != PHP_RINIT_CALL(http_env)
- || SUCCESS != PHP_RINIT_CALL(http_request_datashare)
#if PHP_HTTP_HAVE_CURL
|| SUCCESS != PHP_RINIT_CALL(http_curl)
#endif
{
if (0
|| SUCCESS != PHP_RSHUTDOWN_CALL(http_env)
- || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare)
) {
return FAILURE;
}
ZEND_BEGIN_MODULE_GLOBALS(php_http)
struct php_http_env_globals env;
struct php_http_persistent_handle_globals persistent_handle;
- struct php_http_request_datashare_globals request_datashare;
#if PHP_HTTP_HAVE_CURL && PHP_HTTP_HAVE_EVENT
struct php_http_curl_globals curl;
#endif
#endif
} php_http_curl_request_pool_t;
-#ifdef ZTS
-typedef struct php_http_curl_request_datashare_lock {
- CURL *ch;
- MUTEX_T mx;
-} php_http_curl_request_datashare_lock_t;
-#endif
-
typedef struct php_http_curl_request_datashare {
CURLSH *handle;
-
-#ifdef ZTS
- php_http_curl_request_datashare_lock_t *locks;
-#endif
} php_http_curl_request_datashare_t;
#define PHP_HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \
}
-#ifdef ZTS
-static void *php_http_curl_request_datashare_locks_init(void)
-{
- int i;
- php_http_curl_request_datashare_lock_t *locks = pecalloc(CURL_LOCK_DATA_LAST, sizeof(*locks), 1);
-
- if (locks) {
- for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
- locks[i].mx = tsrm_mutex_alloc();
- }
- }
-
- return locks;
-}
-
-static void php_http_curl_request_datashare_locks_dtor(void *l)
-{
- int i;
- php_http_curl_request_datashare_lock_t *locks = l;
-
- for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
- tsrm_mutex_free(locks[i].mx);
- }
- pefree(locks, 1);
-}
-
-static void php_http_curl_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr)
-{
- php_http_curl_request_datashare_lock_t *locks = userptr;
-
- /* TSRM can't distinguish shared/exclusive locks */
- tsrm_mutex_lock(locks[data].mx);
- locks[data].ch = handle;
-}
-
-static void php_http_curl_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr)
-{
- php_http_curl_request_datashare_lock_t *locks = userptr;
-
- if (locks[data].ch == handle) {
- tsrm_mutex_unlock(locks[data].mx);
- }
-}
-#endif
-
-
-
/* request datashare handler ops */
static php_http_request_datashare_t *php_http_curl_request_datashare_init(php_http_request_datashare_t *h, void *handle)
return NULL;
}
- curl = pecalloc(1, sizeof(*curl), h->persistent);
+ curl = ecalloc(1, sizeof(*curl));
curl->handle = handle;
-#ifdef ZTS
- if (h->persistent) {
- curl->locks = php_http_curl_request_datashare_locks_init();
- if (curl->locks) {
- curl_share_setopt(curl->handle, CURLSHOPT_LOCKFUNC, php_http_curl_request_datashare_lock_func);
- curl_share_setopt(curl->handle, CURLSHOPT_UNLOCKFUNC, php_http_curl_request_datashare_unlock_func);
- curl_share_setopt(curl->handle, CURLSHOPT_USERDATA, curl->locks);
- }
- }
-#endif
h->ctx = curl;
return h;
php_http_resource_factory_handle_dtor(h->rf, curl->handle TSRMLS_CC);
-#ifdef ZTS
- if (h->persistent) {
- php_http_curl_request_datashare_locks_dtor(curl->locks);
- }
-#endif
-
- pefree(curl, h->persistent);
+ efree(curl);
h->ctx = NULL;
}
break;
case PHP_HTTP_REQUEST_DATASHARE_OPT_RESOLVER:
- if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_COOKIE))) {
+ if (CURLSHE_OK != (rc = curl_share_setopt(curl->handle, *((zend_bool *) arg) ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, CURL_LOCK_DATA_DNS))) {
TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_DATASHARE, "Could not %s sharing of resolver data: %s", *((zend_bool *) arg) ? "enable" : "disable", curl_share_strerror(rc));
php_http_resource_factory_free(&h->rf);
- if (h->persistent_handle_id) {
- zval_ptr_dtor(&h->persistent_handle_id);
- }
-
php_http_message_parser_free(&h->parser);
php_http_message_free(&h->message);
php_http_buffer_free(&h->buffer);
php_http_message_parser_t *parser;
php_http_message_t *message;
php_http_buffer_t *buffer;
- zval *persistent_handle_id;
#ifdef ZTS
void ***ts;
#endif
static int php_http_request_datashare_compare_handles(void *h1, void *h2);
-#ifdef ZTS
-static void *php_http_request_datashare_locks_init(void);
-static void php_http_request_datashare_locks_dtor(void *l);
-static void php_http_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr);
-static void php_http_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr);
-static MUTEX_T php_http_request_datashare_global_shares_lock;
-#endif
-static HashTable php_http_request_datashare_global_shares;
-php_http_request_datashare_t *php_http_request_datashare_global_get(const char *driver_str, size_t driver_len TSRMLS_DC)
-{
- php_http_request_datashare_t *s = NULL, **s_ptr;
- char *lower_str = php_strtolower(estrndup(driver_str, driver_len), driver_len);
-
-#ifdef ZTS
- tsrm_mutex_lock(php_http_request_datashare_global_shares_lock);
-#endif
- if (zend_hash_find(&php_http_request_datashare_global_shares, lower_str, driver_len + 1, (void *) &s_ptr)) {
- s = *s_ptr;
- } else {
- php_http_request_factory_driver_t driver;
-
- if ((SUCCESS == php_http_request_factory_get_driver(driver_str, driver_len, &driver)) && driver.request_datashare_ops) {
- s = php_http_request_datashare_init(NULL, driver.request_datashare_ops, NULL, NULL, 1 TSRMLS_CC);
- zend_hash_add(&php_http_request_datashare_global_shares, lower_str, driver_len + 1, &s, sizeof(php_http_request_datashare_t *), NULL);
- }
- }
-#ifdef ZTS
- tsrm_mutex_unlock(php_http_request_datashare_global_shares_lock);
-#endif
-
- efree(lower_str);
- return s;
-}
-
-PHP_HTTP_API php_http_request_datashare_t *php_http_request_datashare_init(php_http_request_datashare_t *h, php_http_request_datashare_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg, zend_bool persistent TSRMLS_DC)
+PHP_HTTP_API php_http_request_datashare_t *php_http_request_datashare_init(php_http_request_datashare_t *h, php_http_request_datashare_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC)
{
php_http_request_datashare_t *free_h = NULL;
if (!h) {
- free_h = h = pemalloc(sizeof(*h), persistent);
+ free_h = h = emalloc(sizeof(*h));
}
memset(h, sizeof(*h), 0);
- if (!(h->persistent = persistent)) {
- h->requests = emalloc(sizeof(*h->requests));
- zend_llist_init(h->requests, sizeof(zval *), ZVAL_PTR_DTOR, 0);
- TSRMLS_SET_CTX(h->ts);
- }
+ zend_llist_init(&h->requests, sizeof(zval *), ZVAL_PTR_DTOR, 0);
h->ops = ops;
h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
+ TSRMLS_SET_CTX(h->ts);
if (h->ops->init) {
if (!(h = h->ops->init(h, init_arg))) {
if (free_h) {
- pefree(free_h, persistent);
+ efree(free_h);
}
}
}
if (h->ops->dtor) {
h->ops->dtor(h);
}
- if (h->requests) {
- zend_llist_destroy(h->requests);
- pefree(h->requests, h->persistent);
- h->requests = NULL;
- }
-
- if (h->persistent_handle_id) {
- zval_ptr_dtor(&h->persistent_handle_id);
- }
+ zend_llist_destroy(&h->requests);
+ php_http_resource_factory_free(&h->rf);
}
PHP_HTTP_API void php_http_request_datashare_free(php_http_request_datashare_t **h)
{
php_http_request_datashare_dtor(*h);
- pefree(*h, (*h)->persistent);
+ efree(*h);
*h = NULL;
}
if (SUCCESS == h->ops->attach(h, obj->request)) {
Z_ADDREF_P(request);
- zend_llist_add_element(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(h), &request);
+ zend_llist_add_element(&h->requests, &request);
return SUCCESS;
}
}
php_http_request_object_t *obj = zend_object_store_get_object(request TSRMLS_CC);
if (SUCCESS == h->ops->detach(h, obj->request)) {
- zend_llist_del_element(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(h), request, php_http_request_datashare_compare_handles);
+ zend_llist_del_element(&h->requests, request, php_http_request_datashare_compare_handles);
return SUCCESS;
}
}
if (h->ops->reset) {
h->ops->reset(h);
} else if (h->ops->detach) {
- zend_llist_apply_with_argument(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(h), detach, h TSRMLS_CC);
+ zend_llist_apply_with_argument(&h->requests, detach, h TSRMLS_CC);
}
- zend_llist_clean(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(h));
-}
-
-static void php_http_request_datashare_global_requests_dtor(void *el)
-{
- //php_http_request_datashare_detach(php_http_request_datashare_global_get(), *((zval **) el));
- zval_ptr_dtor(el);
+ zend_llist_clean(&h->requests);
}
#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpRequestDataShare, method, 0, req_args)
if (share) {
o->share = share;
} else {
- o->share = php_http_request_datashare_init(NULL, NULL, NULL, NULL, 0 TSRMLS_CC);
+ o->share = php_http_request_datashare_init(NULL, NULL, NULL, NULL TSRMLS_CC);
}
if (ptr) {
{
php_http_request_datashare_object_t *o = (php_http_request_datashare_object_t *) object;
- if (!o->share->persistent) {
- php_http_request_datashare_free(&o->share);
- }
+ php_http_request_datashare_free(&o->share);
zend_object_std_dtor((zend_object *) o TSRMLS_CC);
efree(o);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_request_datashare_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- RETURN_LONG(zend_llist_count(PHP_HTTP_REQUEST_DATASHARE_REQUESTS(obj->share)));
+ RETURN_LONG(zend_llist_count(&obj->share->requests));
}
RETURN_FALSE;
}
zend_class_implements(php_http_request_datashare_class_entry TSRMLS_CC, 1, spl_ce_Countable);
- zend_declare_property_null(php_http_request_datashare_class_entry, ZEND_STRL("instance"), (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
zend_declare_property_bool(php_http_request_datashare_class_entry, ZEND_STRL("cookie"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_bool(php_http_request_datashare_class_entry, ZEND_STRL("dns"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
-#ifdef ZTS
- php_http_request_datashare_global_shares_lock = tsrm_mutex_alloc();
-#endif
- zend_hash_init(&php_http_request_datashare_global_shares, 0, NULL, (dtor_func_t) php_http_request_datashare_free, 1);
-
return SUCCESS;
}
-PHP_MSHUTDOWN_FUNCTION(http_request_datashare)
-{
- zend_hash_destroy(&php_http_request_datashare_global_shares);
-#ifdef ZTS
- tsrm_mutex_free(php_http_request_datashare_global_shares_lock);
-#endif
-
- return SUCCESS;
-}
-
-PHP_RINIT_FUNCTION(http_request_datashare)
-{
- zend_llist_init(&PHP_HTTP_G->request_datashare.requests, sizeof(zval *), php_http_request_datashare_global_requests_dtor, 0);
-
- return SUCCESS;
-}
-
-PHP_RSHUTDOWN_FUNCTION(http_request_datashare)
-{
- zend_llist_destroy(&PHP_HTTP_G->request_datashare.requests);
-
- return SUCCESS;
-}
-
-
/*
* Local variables:
* tab-width: 4
php_http_request_datashare_setopt_func_t setopt;
} php_http_request_datashare_ops_t;
-#define PHP_HTTP_REQUEST_DATASHARE_REQUESTS(s) ((s)->persistent ? &PHP_HTTP_G->request_datashare.requests : (s)->requests)
struct php_http_request_datashare {
void *ctx;
php_http_resource_factory_t *rf;
php_http_request_datashare_ops_t *ops;
- zend_llist *requests; /* NULL if persistent, use PHP_HTTP_REQUEST_DATASHARE_REQUESTS */
- unsigned persistent:1;
- zval *persistent_handle_id;
+ zend_llist requests;
#ifdef ZTS
void ***ts;
#endif
};
-struct php_http_request_datashare_globals {
- zend_llist requests;
- zend_bool cookie;
- zend_bool dns;
- zend_bool ssl;
- zend_bool connect;
-};
-
-extern php_http_request_datashare_t *php_http_request_datashare_global_get(const char *driver_str, size_t driver_len TSRMLS_DC);
-
extern PHP_MINIT_FUNCTION(http_request_datashare);
extern PHP_MSHUTDOWN_FUNCTION(http_request_datashare);
extern PHP_RINIT_FUNCTION(http_request_datashare);
extern PHP_RSHUTDOWN_FUNCTION(http_request_datashare);
-PHP_HTTP_API php_http_request_datashare_t *php_http_request_datashare_init(php_http_request_datashare_t *h, php_http_request_datashare_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg, zend_bool persistent TSRMLS_DC);
+PHP_HTTP_API php_http_request_datashare_t *php_http_request_datashare_init(php_http_request_datashare_t *h, php_http_request_datashare_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC);
PHP_HTTP_API php_http_request_datashare_t *php_http_request_datashare_copy(php_http_request_datashare_t *from, php_http_request_datashare_t *to);
PHP_HTTP_API void php_http_request_datashare_dtor(php_http_request_datashare_t *h);
PHP_HTTP_API void php_http_request_datashare_free(php_http_request_datashare_t **h);
PHP_HTTP_ARG_OBJ(http\\Request, request2, 1)
PHP_HTTP_ARG_OBJ(http\\Request, requestN, 1)
PHP_HTTP_END_ARGS;
-PHP_HTTP_EMPTY_ARGS(getGlobalDataShareInstance);
PHP_HTTP_EMPTY_ARGS(getDriver);
PHP_HTTP_EMPTY_ARGS(getAvailableDrivers);
PHP_HTTP_REQUEST_FACTORY_ME(createRequest, ZEND_ACC_PUBLIC)
PHP_HTTP_REQUEST_FACTORY_ME(createPool, ZEND_ACC_PUBLIC)
PHP_HTTP_REQUEST_FACTORY_ME(createDataShare, ZEND_ACC_PUBLIC)
- PHP_HTTP_REQUEST_FACTORY_ME(getGlobalDataShareInstance, ZEND_ACC_PUBLIC)
PHP_HTTP_REQUEST_FACTORY_ME(getDriver, ZEND_ACC_PUBLIC)
PHP_HTTP_REQUEST_FACTORY_ME(getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
efree(name_str);
}
- share = php_http_request_datashare_init(NULL, driver.request_datashare_ops, rf, NULL, 0 TSRMLS_CC);
+ share = php_http_request_datashare_init(NULL, driver.request_datashare_ops, rf, NULL TSRMLS_CC);
if (share) {
if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_datashare_object_new_ex, php_http_request_datashare_class_entry, share, NULL TSRMLS_CC)) {
ZVAL_OBJVAL(return_value, ov, 0);
} end_error_handling();
}
-PHP_METHOD(HttpRequestFactory, getGlobalDataShareInstance)
-{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *instance = *zend_std_get_static_property(php_http_request_datashare_class_entry, ZEND_STRL("instance"), 0, NULL TSRMLS_CC);
-
- if (Z_TYPE_P(instance) != IS_OBJECT) {
- zval *zdriver;
- zend_object_value ov;
- zend_class_entry *class_entry;
- php_http_request_datashare_t *share;
-
- if (!(class_entry = php_http_request_factory_get_class_entry(getThis(), ZEND_STRL("requestDataShareClass") TSRMLS_CC))) {
- class_entry = php_http_request_datashare_class_entry;
- }
-
- if ((zdriver = zend_read_property(php_http_request_factory_class_entry, getThis(), ZEND_STRL("driver"), 0 TSRMLS_CC))
- && (IS_STRING == Z_TYPE_P(zdriver))
- && (share = php_http_request_datashare_global_get(Z_STRVAL_P(zdriver), Z_STRLEN_P(zdriver) TSRMLS_CC))
- && (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_request_datashare_object_new_ex, php_http_request_datashare_class_entry, share, NULL TSRMLS_CC))
- ) {
- MAKE_STD_ZVAL(instance);
- ZVAL_OBJVAL(instance, ov, 0);
- zend_update_static_property(php_http_request_datashare_class_entry, ZEND_STRL("instance"), instance TSRMLS_CC);
-
- if (PHP_HTTP_G->request_datashare.cookie) {
- zend_update_property_bool(php_http_request_datashare_class_entry, instance, ZEND_STRL("cookie"), PHP_HTTP_G->request_datashare.cookie TSRMLS_CC);
- }
- if (PHP_HTTP_G->request_datashare.dns) {
- zend_update_property_bool(php_http_request_datashare_class_entry, instance, ZEND_STRL("dns"), PHP_HTTP_G->request_datashare.dns TSRMLS_CC);
- }
- }
- }
-
- RETVAL_ZVAL(instance, 1, 0);
- } end_error_handling();
- }
- } end_error_handling();
-}
-
-
PHP_METHOD(HttpRequestFactory, getDriver)
{
if (SUCCESS == zend_parse_parameters_none()) {
zend_llist_clean(&h->requests.finished);
zend_llist_clean(&h->requests.attached);
- if (h->persistent_handle_id) {
- zval_ptr_dtor(&h->persistent_handle_id);
- }
-
php_http_resource_factory_free(&h->rf);
}
zend_llist finished;
} requests;
- zval *persistent_handle_id;
-
#ifdef ZTS
void ***ts;
#endif
--SKIPIF--
<?php
include "skipif.inc";
-in_array("curl", http\request\Factory::getAvailableDrivers()) or die ("skip CURL support missing");
+in_array("curl", http\Request\Factory::getAvailableDrivers()) or die ("skip CURL support missing");
?>
--FILE--
<?php
echo "Test\n";
class MyRequest extends http\Request {}
-class MyPool extends http\request\Pool {}
-class MyShare extends http\request\DataShare {}
+class MyPool extends http\Request\Pool {}
+class MyShare extends http\Request\DataShare {}
-class MyFactory extends http\request\Factory {
+class MyFactory extends http\Request\Factory {
protected $driver = "curl";
protected $persistentHandleId = "My";
protected $requestClass = "MyRequest";
$p = $f->createPool();
$s = $f->createDataShare();
-var_dump(array_map("get_class", array($f,$r,$p,$s)));
+var_dump(
+ array_map("get_class", array($f,$r,$p,$s)),
+ $f->getDriver()
+);
+
+foreach (array("Request", "Pool", "DataShare") as $type) {
+ try {
+ var_dump((new http\Request\Factory(array("driver" => "nonexistant")))->{"create$type"}());
+ } catch (Exception $e) {
+ echo $e->getMessage(), "\n";
+ }
+}
echo "Done\n";
?>
[3]=>
string(7) "MyShare"
}
+string(4) "curl"
+requests are not supported by this driver
+pools are not supported by this driver
+datashares are not supported by this driver
Done