From: Michael Wallner Date: Tue, 27 Mar 2012 10:12:11 +0000 (+0000) Subject: make the pool functional again X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~145^2~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=c52a84fd06e87bf72eb98e83abfff29779b0681c;p=m6w6%2Fext-http make the pool functional again --- diff --git a/php_http_client.c b/php_http_client.c index 7b8d859..e0f7bc8 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -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); diff --git a/php_http_client.h b/php_http_client.h index 9599fae..4fdef59 100644 --- a/php_http_client.h +++ b/php_http_client.h @@ -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); diff --git a/php_http_client_curl.c b/php_http_client_curl.c index f16349e..a89a807 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -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); diff --git a/php_http_client_curl.h b/php_http_client_curl.h index 059ab93..1b1f24b 100644 --- a/php_http_client_curl.h +++ b/php_http_client_curl.h @@ -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 */ diff --git a/php_http_client_pool.c b/php_http_client_pool.c index f0b6ca6..9c86e12 100644 --- a/php_http_client_pool.c +++ b/php_http_client_pool.c @@ -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; diff --git a/php_http_client_pool.h b/php_http_client_pool.h index 937bacf..50b5856 100644 --- a/php_http_client_pool.h +++ b/php_http_client_pool.h @@ -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); diff --git a/php_http_client_pool_curl.c b/php_http_client_pool_curl.c index 26e4167..055079b 100644 --- a/php_http_client_pool_curl.c +++ b/php_http_client_pool_curl.c @@ -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; } diff --git a/reflection2php.php b/reflection2php.php index c55eb65..e319bd4 100755 --- a/reflection2php.php +++ b/reflection2php.php @@ -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"); }