X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_client_factory.c;h=318c63b1676c76d6843a1b42092704aae53548e5;hb=921522e44830f4f04cfbaeeffb52c6b1fb9dceaa;hp=d1586f19754ea5f9083cb7e2f199fc200046f2d6;hpb=5c2aacdbafcaad2ddae8ce80db86b59bd00208ec;p=m6w6%2Fext-http diff --git a/php_http_client_factory.c b/php_http_client_factory.c index d1586f1..318c63b 100644 --- a/php_http_client_factory.c +++ b/php_http_client_factory.c @@ -35,13 +35,11 @@ PHP_HTTP_API STATUS php_http_client_factory_get_driver(const char *name_str, siz return FAILURE; } -static zend_class_entry *php_http_client_factory_get_class_entry(zval *this_ptr, const char *for_str, size_t for_len TSRMLS_DC) +static zend_class_entry *php_http_client_factory_find_class_entry(zval *this_ptr, const char *for_str, size_t for_len TSRMLS_DC) { /* stupid non-const api */ - char *sc = estrndup(for_str, for_len); - zval *cn = zend_read_property(Z_OBJCE_P(getThis()), getThis(), sc, for_len, 0 TSRMLS_CC); + zval *cn = zend_read_property(Z_OBJCE_P(getThis()), getThis(), for_str, for_len, 0 TSRMLS_CC); - efree(sc); if (Z_TYPE_P(cn) == IS_STRING && Z_STRLEN_P(cn)) { return zend_fetch_class(Z_STRVAL_P(cn), Z_STRLEN_P(cn), 0 TSRMLS_CC); } @@ -74,8 +72,14 @@ PHP_HTTP_END_ARGS; PHP_HTTP_EMPTY_ARGS(getDriver); PHP_HTTP_EMPTY_ARGS(getAvailableDrivers); -zend_class_entry *php_http_client_factory_class_entry; -zend_function_entry php_http_client_factory_method_entry[] = { +static zend_class_entry *php_http_client_factory_class_entry; + +zend_class_entry *php_http_client_factory_get_class_entry(void) +{ + return php_http_client_factory_class_entry; +} + +static zend_function_entry php_http_client_factory_method_entry[] = { PHP_HTTP_REQUEST_FACTORY_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) PHP_HTTP_REQUEST_FACTORY_ME(createClient, ZEND_ACC_PUBLIC) PHP_HTTP_REQUEST_FACTORY_ME(createPool, ZEND_ACC_PUBLIC) @@ -88,7 +92,7 @@ zend_function_entry php_http_client_factory_method_entry[] = { PHP_METHOD(HttpClientFactory, __construct) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { HashTable *options = NULL; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &options)) { @@ -113,10 +117,10 @@ PHP_METHOD(HttpClientFactory, createClient) { zval *options = NULL; - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!", &options)) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { - zval *zdriver, *os; + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + zval *zdriver; zend_object_value ov; zend_class_entry *class_entry = NULL; php_http_client_t *req = NULL; @@ -126,17 +130,17 @@ PHP_METHOD(HttpClientFactory, createClient) if ((IS_STRING == Z_TYPE_P(zdriver)) && (SUCCESS == php_http_client_factory_get_driver(Z_STRVAL_P(zdriver), Z_STRLEN_P(zdriver), &driver)) && driver.client_ops) { zval *phi = php_http_zsep(1, IS_STRING, zend_read_property(php_http_client_factory_class_entry, getThis(), ZEND_STRL("persistentHandleId"), 0 TSRMLS_CC)); - php_http_resource_factory_t *rf = NULL; + php_resource_factory_t *rf = NULL; if (Z_STRLEN_P(phi)) { char *name_str; size_t name_len; - php_http_persistent_handle_factory_t *pf; + php_persistent_handle_factory_t *pf; name_len = spprintf(&name_str, 0, "http_client.%s", Z_STRVAL_P(zdriver)); - if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) { - rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon); + if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi), NULL, NULL TSRMLS_CC))) { + rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon); } efree(name_str); @@ -144,7 +148,7 @@ PHP_METHOD(HttpClientFactory, createClient) req = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC); if (req) { - if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientClass") TSRMLS_CC))) { + if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientClass") TSRMLS_CC))) { class_entry = driver.client_ops->class_entry(); } @@ -168,11 +172,11 @@ PHP_METHOD(HttpClientFactory, createClient) PHP_METHOD(HttpClientFactory, createPool) { int argc = 0; - zval ***argv; + zval ***argv = NULL; - with_error_handling(EH_THROW, php_http_exception_class_entry) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|*", &argv, &argc)) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &argv, &argc)) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { int i; zval *zdriver; zend_object_value ov; @@ -183,17 +187,17 @@ PHP_METHOD(HttpClientFactory, createPool) zdriver = zend_read_property(php_http_client_factory_class_entry, getThis(), ZEND_STRL("driver"), 0 TSRMLS_CC); if ((IS_STRING == Z_TYPE_P(zdriver)) && (SUCCESS == php_http_client_factory_get_driver(Z_STRVAL_P(zdriver), Z_STRLEN_P(zdriver), &driver)) && driver.client_pool_ops) { zval *phi = php_http_zsep(1, IS_STRING, zend_read_property(php_http_client_factory_class_entry, getThis(), ZEND_STRL("persistentHandleId"), 0 TSRMLS_CC)); - php_http_resource_factory_t *rf = NULL; + php_resource_factory_t *rf = NULL; if (Z_STRLEN_P(phi)) { char *name_str; size_t name_len; - php_http_persistent_handle_factory_t *pf; + php_persistent_handle_factory_t *pf; name_len = spprintf(&name_str, 0, "http_client_pool.%s", Z_STRVAL_P(zdriver)); - if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) { - rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon); + if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi), NULL, NULL TSRMLS_CC))) { + rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon); } efree(name_str); @@ -201,14 +205,14 @@ PHP_METHOD(HttpClientFactory, createPool) pool = php_http_client_pool_init(NULL, driver.client_pool_ops, rf, NULL TSRMLS_CC); if (pool) { - if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientPoolClass") TSRMLS_CC))) { + if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientPoolClass") TSRMLS_CC))) { class_entry = driver.client_pool_ops->class_entry(); } if (SUCCESS == php_http_new(&ov, class_entry, driver.client_pool_ops->create_object, driver.client_pool_ops->class_entry(), pool, NULL TSRMLS_CC)) { ZVAL_OBJVAL(return_value, ov, 0); for (i = 0; i < argc; ++i) { - if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) { + if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) { php_http_client_pool_attach(pool, *(argv[i])); } } @@ -222,6 +226,10 @@ PHP_METHOD(HttpClientFactory, createPool) php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_FACTORY, "pools are not supported by this driver"); } } end_error_handling(); + + if (argv) { + efree(argv); + } } } end_error_handling(); } @@ -229,11 +237,11 @@ PHP_METHOD(HttpClientFactory, createPool) PHP_METHOD(HttpClientFactory, createDataShare) { int argc = 0; - zval ***argv; + zval ***argv = NULL; - with_error_handling(EH_THROW, php_http_exception_class_entry) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|*", &argv, &argc)) { - with_error_handling(EH_THROW, php_http_exception_class_entry) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", &argv, &argc)) { + with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { int i; zval *zdriver; zend_object_value ov; @@ -244,17 +252,17 @@ PHP_METHOD(HttpClientFactory, createDataShare) zdriver = zend_read_property(php_http_client_factory_class_entry, getThis(), ZEND_STRL("driver"), 0 TSRMLS_CC); if ((IS_STRING == Z_TYPE_P(zdriver)) && (SUCCESS == php_http_client_factory_get_driver(Z_STRVAL_P(zdriver), Z_STRLEN_P(zdriver), &driver)) && driver.client_datashare_ops) { zval *phi = php_http_zsep(1, IS_STRING, zend_read_property(php_http_client_factory_class_entry, getThis(), ZEND_STRL("persistentHandleId"), 0 TSRMLS_CC)); - php_http_resource_factory_t *rf = NULL; + php_resource_factory_t *rf = NULL; if (Z_STRLEN_P(phi)) { char *name_str; size_t name_len; - php_http_persistent_handle_factory_t *pf; + php_persistent_handle_factory_t *pf; name_len = spprintf(&name_str, 0, "http_client_datashare.%s", Z_STRVAL_P(zdriver)); - if ((pf = php_http_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi) TSRMLS_CC))) { - rf = php_http_resource_factory_init(NULL, php_http_persistent_handle_resource_factory_ops(), pf, (void (*)(void *)) php_http_persistent_handle_abandon); + if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, Z_STRVAL_P(phi), Z_STRLEN_P(phi), NULL, NULL TSRMLS_CC))) { + rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon); } efree(name_str); @@ -262,14 +270,14 @@ PHP_METHOD(HttpClientFactory, createDataShare) share = php_http_client_datashare_init(NULL, driver.client_datashare_ops, rf, NULL TSRMLS_CC); if (share) { - if (!(class_entry = php_http_client_factory_get_class_entry(getThis(), ZEND_STRL("clientDataShareClass") TSRMLS_CC))) { + if (!(class_entry = php_http_client_factory_find_class_entry(getThis(), ZEND_STRL("clientDataShareClass") TSRMLS_CC))) { class_entry = driver.client_datashare_ops->class_entry(); } if (SUCCESS == php_http_new(&ov, class_entry, driver.client_datashare_ops->create_object, driver.client_datashare_ops->class_entry(), share, NULL TSRMLS_CC)) { ZVAL_OBJVAL(return_value, ov, 0); for (i = 0; i < argc; ++i) { - if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_class_entry TSRMLS_CC)) { + if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), php_http_client_get_class_entry() TSRMLS_CC)) { php_http_client_datashare_attach(share, *(argv[i])); } } @@ -283,6 +291,9 @@ PHP_METHOD(HttpClientFactory, createDataShare) php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_FACTORY, "datashares are not supported by this driver"); } } end_error_handling(); + if (argv) { + efree(argv); + } } } end_error_handling(); } @@ -314,7 +325,7 @@ PHP_MINIT_FUNCTION(http_client_factory) { zend_hash_init(&php_http_client_factory_drivers, 0, NULL, NULL, 1); - PHP_HTTP_REGISTER_CLASS(http\\Client, Factory, http_client_factory, php_http_object_class_entry, 0); + PHP_HTTP_REGISTER_CLASS(http\\Client, Factory, http_client_factory, php_http_object_get_class_entry(), 0); php_http_client_factory_class_entry->create_object = php_http_client_factory_new; zend_declare_property_stringl(php_http_client_factory_class_entry, ZEND_STRL("driver"), ZEND_STRL("curl"), ZEND_ACC_PROTECTED TSRMLS_CC);