split off raphf
[m6w6/ext-http] / php_http_client_pool.c
index 9c86e12c1ff4b556b50e48232cd9b80a2fc7c6c3..3e6b6f98b88354f976c5c7f566a46fc7a92d820e 100644 (file)
@@ -12,7 +12,7 @@
 
 #include "php_http_api.h"
 
-PHP_HTTP_API php_http_client_pool_t *php_http_client_pool_init(php_http_client_pool_t *h, php_http_client_pool_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC)
+PHP_HTTP_API php_http_client_pool_t *php_http_client_pool_init(php_http_client_pool_t *h, php_http_client_pool_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC)
 {
        php_http_client_pool_t *free_h = NULL;
 
@@ -22,7 +22,11 @@ PHP_HTTP_API php_http_client_pool_t *php_http_client_pool_init(php_http_client_p
        memset(h, 0, sizeof(*h));
 
        h->ops = ops;
-       h->rf = rf ? rf : php_http_resource_factory_init(NULL, h->ops->rsrc, NULL, NULL);
+       if (rf) {
+               h->rf = rf;
+       } else if (ops->rsrc) {
+               h->rf = php_resource_factory_init(NULL, h->ops->rsrc, h, NULL);
+       }
        zend_llist_init(&h->clients.attached, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
        zend_llist_init(&h->clients.finished, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
        TSRMLS_SET_CTX(h->ts);
@@ -57,7 +61,7 @@ PHP_HTTP_API void php_http_client_pool_dtor(php_http_client_pool_t *h)
        zend_llist_clean(&h->clients.finished);
        zend_llist_clean(&h->clients.attached);
 
-       php_http_resource_factory_free(&h->rf);
+       php_resource_factory_free(&h->rf);
 }
 
 PHP_HTTP_API void php_http_client_pool_free(php_http_client_pool_t **h) {
@@ -246,8 +250,14 @@ PHP_HTTP_BEGIN_ARGS(enableEvents, 0)
        PHP_HTTP_ARG_VAL(enable, 0)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_client_pool_class_entry;
-zend_function_entry php_http_client_pool_method_entry[] = {
+static zend_class_entry *php_http_client_pool_class_entry;
+
+zend_class_entry *php_http_client_pool_get_class_entry(void)
+{
+       return php_http_client_pool_class_entry;
+}
+
+static zend_function_entry php_http_client_pool_method_entry[] = {
        PHP_HTTP_CLIENT_POOL_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
        PHP_HTTP_CLIENT_POOL_ME(attach, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_POOL_ME(detach, ZEND_ACC_PUBLIC)
@@ -283,6 +293,22 @@ extern zend_object_handlers *php_http_client_pool_get_object_handlers(void)
        return &php_http_client_pool_object_handlers;
 }
 
+static php_http_client_pool_ops_t php_http_client_pool_user_ops = {
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       (php_http_new_t) php_http_client_pool_object_new_ex,
+       php_http_client_pool_get_class_entry
+};
+
 zend_object_value php_http_client_pool_object_new(zend_class_entry *ce TSRMLS_DC)
 {
        return php_http_client_pool_object_new_ex(ce, NULL, NULL TSRMLS_CC);
@@ -298,7 +324,7 @@ zend_object_value php_http_client_pool_object_new_ex(zend_class_entry *ce, php_h
        object_properties_init((zend_object *) o, ce);
 
        if (!(o->pool = p)) {
-               o->pool = php_http_client_pool_init(NULL, NULL, NULL, NULL TSRMLS_CC);
+               o->pool = php_http_client_pool_init(NULL, &php_http_client_pool_user_ops, NULL, NULL TSRMLS_CC);
        }
 
        if (ptr) {
@@ -350,11 +376,11 @@ PHP_METHOD(HttpClientPool, reset)
 
 PHP_METHOD(HttpClientPool, attach)
 {
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                zval *request;
 
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_class_entry)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_get_class_entry())) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                                if (obj->iterator.pos > 0 && obj->iterator.pos < zend_llist_count(&obj->pool->clients.attached)) {
@@ -373,11 +399,11 @@ PHP_METHOD(HttpClientPool, detach)
 {
        RETVAL_FALSE;
 
-       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                zval *request;
 
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_class_entry)) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_get_class_entry())) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                                obj->iterator.pos = -1;
@@ -393,9 +419,9 @@ PHP_METHOD(HttpClientPool, send)
 {
        RETVAL_FALSE;
 
-       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_none()) {
-                       with_error_handling(EH_THROW, php_http_exception_class_entry) {
+                       with_error_handling(EH_THROW, php_http_exception_get_class_entry()) {
                                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
 
                                php_http_client_pool_exec(obj->pool);
@@ -556,12 +582,11 @@ PHP_METHOD(HttpClientPool, enableEvents)
 
 PHP_MINIT_FUNCTION(http_client_pool)
 {
-       PHP_HTTP_REGISTER_CLASS(http\\Client\\Pool, AbstractPool, http_client_pool, php_http_object_class_entry, 0);
-       php_http_client_pool_class_entry->create_object = php_http_object_new; //php_http_client_pool_object_new;
+       PHP_HTTP_REGISTER_CLASS(http\\Client\\Pool, AbstractPool, http_client_pool, php_http_object_get_class_entry(), ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
+       php_http_client_pool_class_entry->create_object = php_http_client_pool_object_new;
        memcpy(&php_http_client_pool_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
        php_http_client_pool_object_handlers.clone_obj = NULL;
 
-       zend_declare_property_null(php_http_client_pool_class_entry, ZEND_STRL("client"), ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_class_implements(php_http_client_pool_class_entry TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);
 
        return SUCCESS;