PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
+ if $HTTP_HAVE_A_REQUEST_LIB; then
+ AC_DEFINE([PHP_HTTP_HAVE_CLIENT], [1], [Have HTTP client support])
+ fi
fi
ZEND_BEGIN_MODULE_GLOBALS(php_http)
struct php_http_env_globals env;
+#ifdef PHP_HTTP_HAVE_CLIENT
+ struct {
+#ifdef PHP_HTTP_HAVE_CURL
+ struct php_http_client_curl_globals curl;
+#endif
+ } client;
+#endif
ZEND_END_MODULE_GLOBALS(php_http)
ZEND_EXTERN_MODULE_GLOBALS(php_http);
ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver)
{
- return zend_hash_str_add_mem(&php_http_client_drivers, driver->name_str, driver->name_len, (void *) driver, sizeof(php_http_client_driver_t))
+ return zend_hash_add_mem(&php_http_client_drivers, driver->driver_name, (void *) driver, sizeof(php_http_client_driver_t))
? SUCCESS : FAILURE;
}
-php_http_client_driver_t *php_http_client_driver_get(const char *name_str, size_t name_len)
+php_http_client_driver_t *php_http_client_driver_get(zend_string *name)
{
zval *ztmp;
php_http_client_driver_t *tmp;
- if (name_str && (tmp = zend_hash_str_find_ptr(&php_http_client_drivers, name_str, name_len))) {
+ if (name && (tmp = zend_hash_find_ptr(&php_http_client_drivers, name))) {
return tmp;
}
if ((ztmp = zend_hash_get_current_data(&php_http_client_drivers))) {
php_http_client_driver_t *d = Z_PTR_P(p);
zval zname;
- ZVAL_STRINGL(&zname, d->name_str, d->name_len);
+ ZVAL_STR(&zname, d->driver_name);
zend_hash_next_index_insert(arg, &zname);
return ZEND_HASH_APPLY_KEEP;
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, __construct)
{
- char *driver_str = NULL, *persistent_handle_str = NULL;
- size_t driver_len = 0, persistent_handle_len = 0;
+ zend_string *driver_name = NULL, *persistent_handle_name = NULL;
php_http_client_driver_t *driver;
php_resource_factory_t *rf = NULL;
php_http_client_object_t *obj;
zval os;
- php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len), invalid_arg, return);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|S!S!", &driver_name, &persistent_handle_name), invalid_arg, return);
if (!zend_hash_num_elements(&php_http_client_drivers)) {
php_http_throw(unexpected_val, "No http\\Client drivers available", NULL);
return;
}
- if (!(driver = php_http_client_driver_get(driver_str, driver_len))) {
- php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_len ? driver_str : "default");
+ if (!(driver = php_http_client_driver_get(driver_name))) {
+ php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_name ? driver_name->val : "default");
return;
}
zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), &os);
zval_ptr_dtor(&os);
- if (persistent_handle_len) {
- char *name_str;
- size_t name_len;
+ if (persistent_handle_name) {
php_persistent_handle_factory_t *pf;
- name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver->name_str);
- php_http_pretty_key(name_str + lenof("http\\Client\\"), driver->name_len, 1, 1);
-
- if ((pf = php_persistent_handle_concede(NULL, name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL))) {
+ if ((pf = php_persistent_handle_concede(NULL, driver->client_name, persistent_handle_name, NULL, NULL))) {
rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon);
}
-
- efree(name_str);
}
obj = PHP_HTTP_OBJ(NULL, getThis());
} php_http_client_ops_t;
typedef struct php_http_client_driver {
- const char *name_str;
- size_t name_len;
+ zend_string *driver_name;
+ zend_string *client_name;
+ zend_string *request_name;
php_http_client_ops_t *client_ops;
} php_http_client_driver_t;
PHP_HTTP_API ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver);
-PHP_HTTP_API php_http_client_driver_t *php_http_client_driver_get(const char *name_str, size_t name_len);
+PHP_HTTP_API php_http_client_driver_t *php_http_client_driver_get(zend_string *name);
typedef struct php_http_client_progress_state {
struct {
{
php_persistent_handle_factory_t *pf;
php_resource_factory_t *rf = NULL;
+ zend_string *id;
char *id_str = NULL;
size_t id_len;
}
id_len = spprintf(&id_str, 0, "%s:%d", STR_PTR(url->host), url->port ? url->port : 80);
+ id = php_http_cs2zs(id_str, id_len);
+
+ pf = php_persistent_handle_concede(NULL, PHP_HTTP_G->client.curl.driver.request_name, id, NULL, NULL);
+ zend_string_release(id);
- pf = php_persistent_handle_concede(NULL, ZEND_STRL("http\\Client\\Curl\\Request"), id_str, id_len, NULL, NULL);
if (pf) {
rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void*)) php_persistent_handle_abandon);
} else {
rf = php_resource_factory_init(NULL, &php_http_curle_resource_factory_ops, NULL, NULL);
}
- efree(id_str);
+ zend_string_release(id);
return rf;
}
PHP_MINIT_FUNCTION(http_client_curl)
{
php_http_options_t *options;
- php_http_client_driver_t driver = {
- ZEND_STRL("curl"),
- &php_http_client_curl_ops
- };
+ php_http_client_driver_t driver;
- if (SUCCESS != php_http_client_driver_add(&driver)) {
- return FAILURE;
- }
+ PHP_HTTP_G->client.curl.driver.driver_name = zend_string_init(ZEND_STRL("curl"), 1);
+ PHP_HTTP_G->client.curl.driver.client_name = zend_string_init(ZEND_STRL("http\\Client\\Curl"), 1);
+ PHP_HTTP_G->client.curl.driver.request_name = zend_string_init(ZEND_STRL("http\\Client\\Curl\\Request"), 1);
+ PHP_HTTP_G->client.curl.driver.client_ops = &php_http_client_curl_ops;
+
+ if (SUCCESS != php_http_client_driver_add(&PHP_HTTP_G->client.curl.driver)) {
+ return FAILURE;
+ }
- if (SUCCESS != php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl"), &php_http_curlm_resource_factory_ops, NULL, NULL)) {
+ if (SUCCESS != php_persistent_handle_provide(PHP_HTTP_G->client.curl.driver.client_name, &php_http_curlm_resource_factory_ops, NULL, NULL)) {
return FAILURE;
}
- if (SUCCESS != php_persistent_handle_provide(ZEND_STRL("http\\Client\\Curl\\Request"), &php_http_curle_resource_factory_ops, NULL, NULL)) {
+ if (SUCCESS != php_persistent_handle_provide(PHP_HTTP_G->client.curl.driver.request_name, &php_http_curle_resource_factory_ops, NULL, NULL)) {
return FAILURE;
}
PHP_MSHUTDOWN_FUNCTION(http_client_curl)
{
- php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl"), NULL, 0);
- php_persistent_handle_cleanup(ZEND_STRL("http\\Client\\Curl\\Request"), NULL, 0);
+ php_persistent_handle_cleanup(PHP_HTTP_G->client.curl.driver.client_name, NULL);
+ php_persistent_handle_cleanup(PHP_HTTP_G->client.curl.driver.request_name, NULL);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.client_name);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.request_name);
+ zend_string_release(PHP_HTTP_G->client.curl.driver.driver_name);
php_http_options_dtor(&php_http_curle_options);
#if PHP_HTTP_HAVE_CURL
+struct php_http_client_curl_globals {
+ php_http_client_driver_t driver;
+};
+
PHP_MINIT_FUNCTION(http_client_curl);
PHP_MSHUTDOWN_FUNCTION(http_client_curl);
#endif /* PHP_HTTP_HAVE_CURL */