From: Michael Wallner Date: Thu, 4 Apr 2013 16:20:24 +0000 (+0000) Subject: allow retrieval of response by request X-Git-Tag: RELEASE_2_1_0_RC3~10^2^2~32 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ee95d238f4ffa07e8c5f146848cd1e73ac2447d1;p=m6w6%2Fext-http allow retrieval of response by request --- diff --git a/package.xml b/package.xml index d345f10..ca92778 100644 --- a/package.xml +++ b/package.xml @@ -36,7 +36,7 @@ Extended HTTP support. Again. Keep in mind that it's got the major version 2, be beta BSD, revised - diff --git a/php_http_client.c b/php_http_client.c index c307221..0826bbf 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -661,19 +661,38 @@ static PHP_METHOD(HttpClient, requeue) } ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getResponse, 0, 0, 0) + ZEND_ARG_OBJ_INFO(0, request, http\\Client\\Request, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, getResponse) { - if (SUCCESS == zend_parse_parameters_none()) { + zval *zrequest = NULL; + + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_get_class_entry())) { php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - if (obj->client->responses.tail) { - php_http_message_object_t *response_obj = *(php_http_message_object_t **) obj->client->responses.tail->data; + if (!zrequest) { + /* pop off the last respone */ + if (obj->client->responses.tail) { + php_http_message_object_t *response_obj = *(php_http_message_object_t **) obj->client->responses.tail->data; + + /* pop off and go */ + if (response_obj) { + RETVAL_OBJVAL(response_obj->zv, 1); + zend_llist_remove_tail(&obj->client->responses); + } + } + } else { + /* lookup the response with the request */ + zend_llist_element *el = NULL; + php_http_message_object_t *req_obj = zend_object_store_get_object(zrequest TSRMLS_CC); - /* pop off and go */ - if (response_obj) { - RETVAL_OBJVAL(response_obj->zv, 1); - zend_llist_remove_tail(&obj->client->responses); + for (el = obj->client->responses.head; el; el = el->next) { + php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data; + + if (response_obj->message->parent == req_obj->message) { + RETVAL_OBJVAL(response_obj->zv, 1); + break; + } } } }