make the pool functional again
authorMichael Wallner <mike@php.net>
Tue, 27 Mar 2012 10:12:11 +0000 (10:12 +0000)
committerMichael Wallner <mike@php.net>
Tue, 27 Mar 2012 10:12:11 +0000 (10:12 +0000)
php_http_client.c
php_http_client.h
php_http_client_curl.c
php_http_client_curl.h
php_http_client_pool.c
php_http_client_pool.h
php_http_client_pool_curl.c
reflection2php.php

index 7b8d85967ecd3e629da3b3c6c47835e1bbb8663d..e0f7bc8516963b39524c031e200933b9315c7a92 100644 (file)
@@ -165,8 +165,8 @@ PHP_HTTP_BEGIN_ARGS(resetCookies, 0)
 PHP_HTTP_END_ARGS;
 PHP_HTTP_EMPTY_ARGS(flushCookies);
 
-PHP_HTTP_EMPTY_ARGS(getMessageClass);
-PHP_HTTP_BEGIN_ARGS(setMessageClass, 1)
+PHP_HTTP_EMPTY_ARGS(getResponseMessageClass);
+PHP_HTTP_BEGIN_ARGS(setResponseMessageClass, 1)
        PHP_HTTP_ARG_VAL(message_class_name, 0)
 PHP_HTTP_END_ARGS;
 
@@ -174,6 +174,12 @@ PHP_HTTP_EMPTY_ARGS(getResponseMessage);
 PHP_HTTP_EMPTY_ARGS(getRequestMessage);
 PHP_HTTP_EMPTY_ARGS(getHistory);
 PHP_HTTP_EMPTY_ARGS(clearHistory);
+
+PHP_HTTP_BEGIN_ARGS(setRequest, 1)
+       PHP_HTTP_ARG_OBJ(http\\Client\\Request, request, 1)
+PHP_HTTP_END_ARGS;
+PHP_HTTP_EMPTY_ARGS(getRequest);
+
 PHP_HTTP_BEGIN_ARGS(send, 1)
        PHP_HTTP_ARG_VAL(request, 0)
 PHP_HTTP_END_ARGS;
@@ -216,6 +222,8 @@ zend_function_entry php_http_client_method_entry[] = {
        PHP_HTTP_CLIENT_ME(resetCookies, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(flushCookies, ZEND_ACC_PUBLIC)
 
+       PHP_HTTP_CLIENT_ME(setRequest, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_ME(getRequest, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(send, ZEND_ACC_PUBLIC)
 
        PHP_HTTP_CLIENT_ME(getResponseMessage, ZEND_ACC_PUBLIC)
@@ -223,8 +231,8 @@ zend_function_entry php_http_client_method_entry[] = {
        PHP_HTTP_CLIENT_ME(getHistory, ZEND_ACC_PUBLIC)
        PHP_HTTP_CLIENT_ME(clearHistory, ZEND_ACC_PUBLIC)
 
-       PHP_HTTP_CLIENT_ME(getMessageClass, ZEND_ACC_PUBLIC)
-       PHP_HTTP_CLIENT_ME(setMessageClass, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_ME(getResponseMessageClass, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_ME(setResponseMessageClass, ZEND_ACC_PUBLIC)
 
        EMPTY_FUNCTION_ENTRY
 };
@@ -332,7 +340,7 @@ static inline void php_http_client_object_check_request_content_type(zval *this_
 static inline zend_object_value php_http_client_object_message(zval *this_ptr, php_http_message_t *msg TSRMLS_DC)
 {
        zend_object_value ov;
-       zval *zcn = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("messageClass"), 0 TSRMLS_CC);
+       zval *zcn = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("responseMessageClass"), 0 TSRMLS_CC);
        zend_class_entry *class_entry;
 
        if (Z_STRLEN_P(zcn)
@@ -344,18 +352,29 @@ static inline zend_object_value php_http_client_object_message(zval *this_ptr, p
        }
 }
 
-STATUS php_http_client_object_handle_request(zval *zclient, zval *zreq TSRMLS_DC)
+STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_DC)
 {
        php_http_client_object_t *obj = zend_object_store_get_object(zclient TSRMLS_CC);
        php_http_client_progress_t *progress;
        zval *zoptions;
 
+       /* do we have a valid request? */
+       if (*zreq) {
+               /* remember the request */
+               zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("request"), *zreq TSRMLS_CC);
+       } else {
+               /* maybe a request is already set */
+               *zreq = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("request"), 0 TSRMLS_CC);
+
+               if (Z_TYPE_PP(zreq) != IS_OBJECT || !instanceof_function(Z_OBJCE_PP(zreq), php_http_client_request_class_entry TSRMLS_CC)) {
+                       php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "The client does not have a valid request set");
+                       return FAILURE;
+               }
+       }
+
        /* reset request handle */
        php_http_client_reset(obj->client);
 
-       /* remember the request */
-       zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("request"), zreq TSRMLS_CC);
-
        /* reset transfer info */
        zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("info") TSRMLS_CC);
 
@@ -642,7 +661,7 @@ static void php_http_client_object_set_options(INTERNAL_FUNCTION_PARAMETERS)
                                        zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addcookies", NULL, *opt);
                                } else if (KEYMATCH(key, "recordHistory")) {
                                        zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("recordHistory"), *opt TSRMLS_CC);
-                               } else if (KEYMATCH(key, "messageClass")) {
+                               } else if (KEYMATCH(key, "responseMessageClass")) {
                                        zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmessageclass", NULL, *opt);
                                } else if (Z_TYPE_PP(opt) == IS_NULL) {
                                        old_opts = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
@@ -986,34 +1005,51 @@ PHP_METHOD(HttpClient, clearHistory)
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
-PHP_METHOD(HttpClient, getMessageClass)
+PHP_METHOD(HttpClient, getResponseMessageClass)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
-               RETURN_PROP(php_http_client_class_entry, "messageClass");
+               RETURN_PROP(php_http_client_class_entry, "responseMessageClass");
        }
        RETURN_FALSE;
 }
 
-PHP_METHOD(HttpClient, setMessageClass)
+PHP_METHOD(HttpClient, setResponseMessageClass)
 {
        char *cn;
        int cl;
 
        if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cn, &cl)) {
-               zend_update_property_stringl(php_http_client_class_entry, getThis(), ZEND_STRL("messageClass"), cn, cl TSRMLS_CC);
+               zend_update_property_stringl(php_http_client_class_entry, getThis(), ZEND_STRL("responseMessageClass"), cn, cl TSRMLS_CC);
        }
        RETVAL_ZVAL(getThis(), 1, 0);
 }
 
+PHP_METHOD(HttpClient, setRequest)
+{
+       zval *zreq = NULL;
+
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zreq, php_http_client_request_class_entry)) {
+               zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("request"), zreq TSRMLS_CC);
+       }
+       RETURN_ZVAL(getThis(), 1, 0);
+}
+
+PHP_METHOD(HttpClient, getRequest)
+{
+       if (SUCCESS == zend_parse_parameters_none()) {
+               RETURN_PROP(php_http_client_class_entry, "request");
+       }
+}
+
 PHP_METHOD(HttpClient, send)
 {
-       zval *zreq;
+       zval *zreq = NULL;
 
        RETVAL_FALSE;
 
        with_error_handling(EH_THROW, php_http_exception_class_entry) {
-               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zreq, php_http_client_request_class_entry)) {
-                       if (SUCCESS == php_http_client_object_handle_request(getThis(), zreq TSRMLS_CC)) {
+               if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!", &zreq, php_http_client_request_class_entry)) {
+                       if (SUCCESS == php_http_client_object_handle_request(getThis(), &zreq TSRMLS_CC)) {
                                php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
                                php_http_message_object_t *req = zend_object_store_get_object(zreq TSRMLS_CC);
 
@@ -1040,7 +1076,7 @@ PHP_MINIT_FUNCTION(http_client)
 
        zend_class_implements(php_http_client_class_entry TSRMLS_CC, 2, spl_ce_SplSubject, php_http_client_interface_class_entry);
 
-       zend_declare_property_string(php_http_client_class_entry, ZEND_STRL("messageClass"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
+       zend_declare_property_string(php_http_client_class_entry, ZEND_STRL("responseMessageClass"), "", ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PRIVATE TSRMLS_CC);
        zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PRIVATE TSRMLS_CC);
index 9599fae2d58b164cfe4d425be99e4cf3cd3720fc..4fdef597404f2190ec97f4518f9a50e2cc0e2791 100644 (file)
@@ -174,6 +174,9 @@ extern void php_http_client_object_free(void *object TSRMLS_DC);
 
 extern zend_object_handlers *php_http_client_get_object_handlers(void);
 
+extern STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_DC);
+extern STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC);
+
 extern STATUS php_http_client_object_requesthandler(php_http_client_object_t *obj, zval *this_ptr, char **meth, char **url, php_http_message_body_t **body TSRMLS_DC);
 extern STATUS php_http_client_object_responsehandler(php_http_client_object_t *obj, zval *this_ptr TSRMLS_DC);
 
@@ -195,15 +198,15 @@ PHP_METHOD(HttpClient, setCookies);
 PHP_METHOD(HttpClient, enableCookies);
 PHP_METHOD(HttpClient, resetCookies);
 PHP_METHOD(HttpClient, flushCookies);
+PHP_METHOD(HttpClient, setRequest);
+PHP_METHOD(HttpClient, getRequest);
 PHP_METHOD(HttpClient, send);
 PHP_METHOD(HttpClient, getResponseMessage);
-PHP_METHOD(HttpClient, getRawResponseMessage);
 PHP_METHOD(HttpClient, getRequestMessage);
-PHP_METHOD(HttpClient, getRawRequestMessage);
 PHP_METHOD(HttpClient, getHistory);
 PHP_METHOD(HttpClient, clearHistory);
-PHP_METHOD(HttpClient, getMessageClass);
-PHP_METHOD(HttpClient, setMessageClass);
+PHP_METHOD(HttpClient, getResponseMessageClass);
+PHP_METHOD(HttpClient, setResponseMessageClass);
 
 extern PHP_MINIT_FUNCTION(http_client);
 
index f16349e2f0472320875d300657f55b9a57f59ad0..a89a807235ae4248dd5cf4d1963a64fc9a9c1691 100644 (file)
@@ -1022,10 +1022,8 @@ static STATUS php_http_client_curl_reset(php_http_client_t *h)
        return SUCCESS;
 }
 
-static STATUS php_http_client_curl_exec(php_http_client_t *h, php_http_message_t *msg)
+STATUS php_http_client_curl_prepare(php_http_client_t *h, php_http_message_t *msg)
 {
-       uint tries = 0;
-       CURLcode result;
        php_http_client_curl_t *curl = h->ctx;
        php_http_client_curl_storage_t *storage = get_storage(curl->handle);
        TSRMLS_FETCH_FROM_CTX(h->ts);
@@ -1033,6 +1031,7 @@ static STATUS php_http_client_curl_exec(php_http_client_t *h, php_http_message_t
        /* request url */
        if (!PHP_HTTP_INFO(msg).request.url) {
                php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot request empty URL");
+               return FAILURE;
        }
        storage->errorbuffer[0] = '\0';
        if (storage->url) {
@@ -1110,6 +1109,21 @@ static STATUS php_http_client_curl_exec(php_http_client_t *h, php_http_message_t
                curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
        }
 
+       return SUCCESS;
+}
+
+static STATUS php_http_client_curl_exec(php_http_client_t *h, php_http_message_t *msg)
+{
+       uint tries = 0;
+       CURLcode result;
+       php_http_client_curl_t *curl = h->ctx;
+       php_http_client_curl_storage_t *storage = get_storage(curl->handle);
+       TSRMLS_FETCH_FROM_CTX(h->ts);
+
+       if (SUCCESS != php_http_client_curl_prepare(h, msg)) {
+               return FAILURE;
+       }
+
 retry:
        if (CURLE_OK != (result = curl_easy_perform(curl->handle))) {
                php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "%s; %s (%s)", curl_easy_strerror(result), storage->errorbuffer, storage->url);
index 059ab93753255d5b304a2b1b6f9c46ab1aed4009..1b1f24b6ea3e5bcd5b32354b2f42f68a476b661f 100644 (file)
@@ -60,12 +60,15 @@ static inline php_http_client_curl_storage_t *get_storage(CURL *ch) {
        return st;
 }
 
+extern STATUS php_http_client_curl_prepare(php_http_client_t *h, php_http_message_t *msg);
+
 extern zend_class_entry *php_http_client_curl_class_entry;
 extern zend_function_entry php_http_client_curl_method_entry[];
 
-zend_object_value php_http_client_curl_object_new(zend_class_entry *ce TSRMLS_DC);
-zend_object_value php_http_client_curl_object_new_ex(zend_class_entry *ce, php_http_client_t *r, php_http_client_object_t **ptr TSRMLS_DC);
+extern zend_object_value php_http_client_curl_object_new(zend_class_entry *ce TSRMLS_DC);
+extern zend_object_value php_http_client_curl_object_new_ex(zend_class_entry *ce, php_http_client_t *r, php_http_client_object_t **ptr TSRMLS_DC);
 
+PHP_MINIT_FUNCTION(http_client_curl);
 
 #endif /* PHP_HTTP_HAVE_CURL */
 #endif /* PHP_HTTP_CLIENT_CURL_H */
index f0b6ca623a6b6f47a648208b64dfcce01d628379..9c86e12c1ff4b556b50e48232cd9b80a2fc7c6c3 100644 (file)
@@ -73,21 +73,22 @@ PHP_HTTP_API STATUS php_http_client_pool_attach(php_http_client_pool_t *h, zval
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
        if (h->ops->attach) {
-               char *url = NULL;
-               char *m = NULL;
-               php_http_message_body_t *body = NULL;
-               php_http_client_object_t *obj = zend_object_store_get_object(client TSRMLS_CC);
+               zval *zreq = NULL;
+               php_http_client_object_t *obj;
+               php_http_message_object_t *msg_obj;
 
-               if (SUCCESS != php_http_client_object_requesthandler(obj, client, &m, &url, &body TSRMLS_CC)) {
+               if (SUCCESS != php_http_client_object_handle_request(client, &zreq TSRMLS_CC)) {
                        return FAILURE;
                }
-               if (SUCCESS == h->ops->attach(h, obj->client, m, url, body)) {
-                       STR_FREE(url);
+
+               obj = zend_object_store_get_object(client TSRMLS_CC);
+               msg_obj = zend_object_store_get_object(zreq TSRMLS_CC);
+
+               if (SUCCESS == h->ops->attach(h, obj->client, msg_obj->message)) {
                        Z_ADDREF_P(client);
                        zend_llist_add_element(&h->clients.attached, &client);
                        return SUCCESS;
                }
-               STR_FREE(url);
        }
 
        return FAILURE;
@@ -207,17 +208,17 @@ PHP_HTTP_API void php_http_client_pool_requests(php_http_client_pool_t *h, zval
 
 #define PHP_HTTP_BEGIN_ARGS(method, req_args)  PHP_HTTP_BEGIN_ARGS_EX(HttpClientPool, method, 0, req_args)
 #define PHP_HTTP_EMPTY_ARGS(method)                            PHP_HTTP_EMPTY_ARGS_EX(HttpClientPool, method, 0)
-#define PHP_HTTP_REQPOOL_ME(method, visibility)        PHP_ME(HttpClientPool, method, PHP_HTTP_ARGS(HttpClientPool, method), visibility)
+#define PHP_HTTP_CLIENT_POOL_ME(method, visibility)    PHP_ME(HttpClientPool, method, PHP_HTTP_ARGS(HttpClientPool, method), visibility)
 
 PHP_HTTP_EMPTY_ARGS(__destruct);
 PHP_HTTP_EMPTY_ARGS(reset);
 
 PHP_HTTP_BEGIN_ARGS(attach, 1)
-       PHP_HTTP_ARG_OBJ(http\\Client, client, 0)
+       PHP_HTTP_ARG_OBJ(http\\Client\\AbstractClient, request, 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_BEGIN_ARGS(detach, 1)
-       PHP_HTTP_ARG_OBJ(http\\Client, client, 0)
+       PHP_HTTP_ARG_OBJ(http\\Client\\AbstractClient, request, 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_EMPTY_ARGS(send);
@@ -234,8 +235,8 @@ PHP_HTTP_EMPTY_ARGS(rewind);
 
 PHP_HTTP_EMPTY_ARGS(count);
 
-PHP_HTTP_EMPTY_ARGS(getAttachedRequests);
-PHP_HTTP_EMPTY_ARGS(getFinishedRequests);
+PHP_HTTP_EMPTY_ARGS(getAttached);
+PHP_HTTP_EMPTY_ARGS(getFinished);
 
 PHP_HTTP_BEGIN_ARGS(enablePipelining, 0)
        PHP_HTTP_ARG_VAL(enable, 0)
@@ -247,30 +248,30 @@ PHP_HTTP_END_ARGS;
 
 zend_class_entry *php_http_client_pool_class_entry;
 zend_function_entry php_http_client_pool_method_entry[] = {
-       PHP_HTTP_REQPOOL_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
-       PHP_HTTP_REQPOOL_ME(attach, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(detach, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(send, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(reset, ZEND_ACC_PUBLIC)
+       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)
+       PHP_HTTP_CLIENT_POOL_ME(send, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(reset, ZEND_ACC_PUBLIC)
 
-       PHP_HTTP_REQPOOL_ME(once, ZEND_ACC_PROTECTED)
-       PHP_HTTP_REQPOOL_ME(wait, ZEND_ACC_PROTECTED)
+       PHP_HTTP_CLIENT_POOL_ME(once, ZEND_ACC_PROTECTED)
+       PHP_HTTP_CLIENT_POOL_ME(wait, ZEND_ACC_PROTECTED)
 
        /* implements Iterator */
-       PHP_HTTP_REQPOOL_ME(valid, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(current, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(key, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(next, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(rewind, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(valid, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(current, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(key, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(next, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(rewind, ZEND_ACC_PUBLIC)
 
        /* implmenents Countable */
-       PHP_HTTP_REQPOOL_ME(count, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(count, ZEND_ACC_PUBLIC)
 
-       PHP_HTTP_REQPOOL_ME(getAttachedRequests, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(getFinishedRequests, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(getAttached, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(getFinished, ZEND_ACC_PUBLIC)
 
-       PHP_HTTP_REQPOOL_ME(enablePipelining, ZEND_ACC_PUBLIC)
-       PHP_HTTP_REQPOOL_ME(enableEvents, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(enablePipelining, ZEND_ACC_PUBLIC)
+       PHP_HTTP_CLIENT_POOL_ME(enableEvents, ZEND_ACC_PUBLIC)
 
        EMPTY_FUNCTION_ENTRY
 };
@@ -501,7 +502,7 @@ PHP_METHOD(HttpClientPool, count)
        }
 }
 
-PHP_METHOD(HttpClientPool, getAttachedRequests)
+PHP_METHOD(HttpClientPool, getAttached)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -515,7 +516,7 @@ PHP_METHOD(HttpClientPool, getAttachedRequests)
        RETURN_FALSE;
 }
 
-PHP_METHOD(HttpClientPool, getFinishedRequests)
+PHP_METHOD(HttpClientPool, getFinished)
 {
        if (SUCCESS == zend_parse_parameters_none()) {
                php_http_client_pool_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -560,6 +561,7 @@ PHP_MINIT_FUNCTION(http_client_pool)
        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;
index 937bacf8933aaf4c61adcc1d99d04932fc58572a..50b5856a36fc03481ddb297f0b214b90c5eb8aaa 100644 (file)
@@ -25,7 +25,7 @@ typedef void (*php_http_client_pool_reset_func_t)(struct php_http_client_pool *p
 typedef STATUS (*php_http_client_pool_exec_func_t)(struct php_http_client_pool *p);
 typedef STATUS (*php_http_client_pool_wait_func_t)(struct php_http_client_pool *p, struct timeval *custom_timeout);
 typedef int (*php_http_client_pool_once_func_t)(struct php_http_client_pool *p);
-typedef STATUS (*php_http_client_pool_attach_func_t)(struct php_http_client_pool *p, php_http_client_t *r, const char *m, const char *url, php_http_message_body_t *body);
+typedef STATUS (*php_http_client_pool_attach_func_t)(struct php_http_client_pool *p, php_http_client_t *r, php_http_message_t *msg);
 typedef STATUS (*php_http_client_pool_detach_func_t)(struct php_http_client_pool *p, php_http_client_t *r);
 typedef STATUS (*php_http_client_pool_setopt_func_t)(struct php_http_client_pool *p, php_http_client_pool_setopt_opt_t opt, void *arg);
 
@@ -49,6 +49,7 @@ typedef struct php_http_client_pool {
        php_http_client_pool_ops_t *ops;
 
        struct {
+               php_http_client_t *master;
                zend_llist attached;
                zend_llist finished;
        } clients;
@@ -74,7 +75,7 @@ PHP_HTTP_API void php_http_client_pool_requests(php_http_client_pool_t *h, zval
 typedef struct php_http_client_pool_object {
        zend_object zo;
        php_http_client_pool_t *pool;
-       zend_object_value factory;
+       zend_object_value client;
        struct {
                long pos;
        } iterator;
@@ -102,8 +103,8 @@ PHP_METHOD(HttpClientPool, key);
 PHP_METHOD(HttpClientPool, next);
 PHP_METHOD(HttpClientPool, rewind);
 PHP_METHOD(HttpClientPool, count);
-PHP_METHOD(HttpClientPool, getAttachedRequests);
-PHP_METHOD(HttpClientPool, getFinishedRequests);
+PHP_METHOD(HttpClientPool, getAttached);
+PHP_METHOD(HttpClientPool, getFinished);
 PHP_METHOD(HttpClientPool, enablePipelining);
 PHP_METHOD(HttpClientPool, enableEvents);
 
index 26e416768a7b37aecad46069156f0ec5497fab1e..055079b360bf714b2f36aa9ed2ee30039a8d7ac4 100644 (file)
@@ -66,7 +66,7 @@ static void php_http_client_pool_curl_responsehandler(php_http_client_pool_t *po
                                if (msg->easy_handle == ((php_http_client_curl_t *) (obj->client->ctx))->handle) {
                                        Z_ADDREF_PP(request);
                                        zend_llist_add_element(&pool->clients.finished, request);
-                                       php_http_client_object_responsehandler(obj, *request TSRMLS_CC);
+                                       php_http_client_object_handle_response(*request TSRMLS_CC);
                                }
 
                                zval_ptr_dtor(request);
@@ -274,14 +274,14 @@ static void php_http_client_pool_curl_dtor(php_http_client_pool_t *h)
        h->ctx = NULL;
 }
 
-static STATUS php_http_client_pool_curl_attach(php_http_client_pool_t *h, php_http_client_t *r, const char *m, const char *url, php_http_message_body_t *body)
+static STATUS php_http_client_pool_curl_attach(php_http_client_pool_t *h, php_http_client_t *r, php_http_message_t *m)
 {
        php_http_client_pool_curl_t *curl = h->ctx;
        php_http_client_curl_t *recurl = r->ctx;
        CURLMcode rs;
        TSRMLS_FETCH_FROM_CTX(h->ts);
 
-       if (SUCCESS != php_http_curl_request_prepare(r, m, url, body)) {
+       if (SUCCESS != php_http_client_curl_prepare(r, m)) {
                return FAILURE;
        }
 
index c55eb65290bb0c2a19656ca967ff9abf8ba7d31b..e319bd4074cfbd3fb18bc73f026e7044f99d0ca3 100755 (executable)
@@ -57,36 +57,46 @@ foreach ($ext->getFunctions() as $f) {
 }
 printf("\n");
 
-foreach ($ext->getClasses() as $class) {
+$classes = $ext->getClasses();
+usort($classes, function($a,$b) {
+        $cmp = strcmp($a->getNamespaceName(), $b->getNamespaceName());
+        if (!$cmp) {
+            $cmp = strcmp($a->getShortName(), $b->getShortName());
+        }
+        return $cmp;
+    }
+);
+
+foreach ($classes as $class) {
 
     if ($class->inNamespace()) {
-        printf("namespace %s {\n", $class->getNamespaceName());
+        printf("namespace %s\n{\n", $class->getNamespaceName());
     }
-       printf("%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getShortName());
+       printf("\t%s%s %s ", m($class->getModifiers()), $class->isInterface() ? "interface":"class" ,$class->getShortName());
        if ($p = $class->getParentClass()) {
                printf("extends \\%s ", $p->getName());
        }
        if ($i = $class->getInterfaceNames()) {
                printf("implements \\%s ", implode(", \\", array_filter($i,function($v){return$v!="Traversable";})));
        }
-       printf("\n{\n");
+       printf("\n\t{\n");
 
        $_=0;
        foreach ($class->getConstants() as $n => $v) {
-               c($n, $class) and $_+=printf("\tconst %s = %s;\n", $n, var_export($v, true));
+               c($n, $class) and $_+=printf("\t\tconst %s = %s;\n", $n, var_export($v, true));
        }
        $_ and printf("\n");
        $_=0;
        foreach ($class->getProperties() as $p) {
                if ($p->getDeclaringClass()->getName() == $class->getName()) {
-                       $_+=printf("\t%s\$%s;\n", m($p->getModifiers()), $p->getName());
+                       $_+=printf("\t\t%s\$%s;\n", m($p->getModifiers()), $p->getName());
                }
        }
        $_ and printf("\n");
 
        foreach ($class->getMethods() as $m) {
                if ($m->getDeclaringClass()->getName() == $class->getName()) {
-                       printf("\t%sfunction %s(", m($m->getModifiers()), $m->getName());
+                       printf("\t\t%sfunction %s(", m($m->getModifiers()), $m->getName());
                        $ps = array();
                        foreach ($m->getParameters() as $p) {
                                $p1 = sprintf("%s%s\$%s", t($p), $p->isPassedByReference()?"&":"", $p->getName());
@@ -101,11 +111,11 @@ foreach ($ext->getClasses() as $class) {
                 }
                                $ps[] = $p1;
                        }
-                       printf("%s) {\n\t}\n", implode(", ", $ps));
+                       printf("%s) {\n\t\t}\n", implode(", ", $ps));
                }
        }
 
-    printf("}\n");
+    printf("\t}\n");
     if ($class->inNamespace()) {
         printf("}\n");
     }