From: Michael Wallner Date: Tue, 14 Feb 2006 17:18:54 +0000 (+0000) Subject: - reverse request history X-Git-Tag: RELEASE_0_23_0~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d650022122969644c33bd03a552af1a631429e16;p=m6w6%2Fext-http - reverse request history --- diff --git a/http_message_object.c b/http_message_object.c index ad4d827..c642754 100644 --- a/http_message_object.c +++ b/http_message_object.c @@ -209,6 +209,56 @@ PHP_MINIT_FUNCTION(http_message_object) return SUCCESS; } +void _http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC) +{ + int i; + getObject(http_message_object, obj); + + /* count */ + http_message_count(i, obj->message); + + if (i > 1) { + zval o; + zend_object_value *ovalues = NULL; + http_message_object **objects = NULL; + int last = i - 1; + + objects = ecalloc(i, sizeof(http_message_object *)); + ovalues = ecalloc(i, sizeof(zend_object_value)); + + /* we are the first message */ + objects[0] = obj; + ovalues[0] = getThis()->value.obj; + + /* fetch parents */ + INIT_PZVAL(&o); + o.type = IS_OBJECT; + for (i = 1; obj->parent.handle; ++i) { + o.value.obj = obj->parent; + ovalues[i] = o.value.obj; + objects[i] = obj = zend_object_store_get_object(&o TSRMLS_CC); + } + + /* reorder parents */ + for (last = --i; i; --i) { + objects[i]->message->parent = objects[i-1]->message; + objects[i]->parent = ovalues[i-1]; + } + objects[0]->message->parent = NULL; + objects[0]->parent.handle = 0; + objects[0]->parent.handlers = NULL; + + /* add ref (why?) */ + Z_OBJ_ADDREF_P(getThis()); + RETVAL_OBJVAL(ovalues[last], 1); + + efree(objects); + efree(ovalues); + } else { + RETURN_ZVAL(getThis(), 1, 0); + } +} + void _http_message_object_prepend_ex(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC) { zval m; @@ -1382,53 +1432,8 @@ PHP_METHOD(HttpMessage, prepend) */ PHP_METHOD(HttpMessage, reverse) { - int i; - getObject(http_message_object, obj); - - NO_ARGS; - - /* count */ - http_message_count(i, obj->message); - - if (i > 1) { - zval o; - zend_object_value *ovalues = NULL; - http_message_object **objects = NULL; - int last = i - 1; - - objects = ecalloc(i, sizeof(http_message_object *)); - ovalues = ecalloc(i, sizeof(zend_object_value)); - - /* we are the first message */ - objects[0] = obj; - ovalues[0] = getThis()->value.obj; - - /* fetch parents */ - INIT_PZVAL(&o); - o.type = IS_OBJECT; - for (i = 1; obj->parent.handle; ++i) { - o.value.obj = obj->parent; - ovalues[i] = o.value.obj; - objects[i] = obj = zend_object_store_get_object(&o TSRMLS_CC); - } - - /* reorder parents */ - for (last = --i; i; --i) { - objects[i]->message->parent = objects[i-1]->message; - objects[i]->parent = ovalues[i-1]; - } - objects[0]->message->parent = NULL; - objects[0]->parent.handle = 0; - objects[0]->parent.handlers = NULL; - - /* add ref (why?) */ - Z_OBJ_ADDREF_P(getThis()); - RETVAL_OBJVAL(ovalues[last], 1); - - efree(objects); - efree(ovalues); - } else { - RETURN_ZVAL(getThis(), 1, 0); + NO_ARGS { + http_message_object_reverse(getThis(), return_value); } } /* }}} */ diff --git a/http_request_object.c b/http_request_object.c index 2ab84c0..45ef050 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -587,7 +587,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this /* stuck request messages in between response messages - + response request v v response request @@ -595,16 +595,22 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this response request ================== response > request - ,---' + ,---' response > request - ,---' + ,---' response > request + + if there are more responses than requests (PUT etc), + begin add $diff response's parent message */ - if (num_req == num_resp) { + if (num_req <= num_resp) { int i; - zval *hist, *history = GET_PROP(history); + zval *prep, *hist, *history = GET_PROP(history); http_message *res_tmp = response, *req_tmp = request, *req_par, *res_par; + for (i = 0; i < (num_resp - num_req); ++i) { + res_tmp = res_tmp->parent; + } for (i = 0; i < num_req; ++i) { res_par = res_tmp->parent; req_par = req_tmp->parent; @@ -616,10 +622,13 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this MAKE_STD_ZVAL(hist); ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, response, NULL), 0); + MAKE_STD_ZVAL(prep); + http_message_object_reverse(hist, prep); if (Z_TYPE_P(history) == IS_OBJECT) { - http_message_object_prepend(hist, history); + http_message_object_prepend(prep, history); } - SET_PROP(history, hist); + SET_PROP(history, prep); + zval_ptr_dtor(&prep); zval_ptr_dtor(&hist); } /* TODO: error? */ diff --git a/php_http_message_object.h b/php_http_message_object.h index 4c08470..b3a836e 100644 --- a/php_http_message_object.h +++ b/php_http_message_object.h @@ -32,6 +32,9 @@ extern PHP_MINIT_FUNCTION(http_message_object); #define http_message_object_prepend_ex(o, p, t) _http_message_object_prepend_ex((o), (p), (t) TSRMLS_CC) extern void _http_message_object_prepend_ex(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC); +#define http_message_object_reverse(t, r) _http_message_object_reverse((t), (r) TSRMLS_CC) +extern void _http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC); + #define http_message_object_new(ce) _http_message_object_new((ce) TSRMLS_CC) extern zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC); #define http_message_object_new_ex(ce, msg, ptr) _http_message_object_new_ex((ce), (msg), (ptr) TSRMLS_CC) diff --git a/tests/HttpRequest_002.phpt b/tests/HttpRequest_002.phpt index eca6d02..a556977 100644 --- a/tests/HttpRequest_002.phpt +++ b/tests/HttpRequest_002.phpt @@ -57,6 +57,8 @@ Array [proxyauth_avail] => %s [num_connects] => %d [cookies] => Array%s + [os_errno] => 0 + [error] => ) Array ( diff --git a/tests/HttpRequest_007.phpt b/tests/HttpRequest_007.phpt index 74ce527..96160af 100644 --- a/tests/HttpRequest_007.phpt +++ b/tests/HttpRequest_007.phpt @@ -40,6 +40,7 @@ var_dump($r->getHistory()->toString(true)); echo "Done\n"; ?> +HTTP/1.1 100 Continue PUT /.print_put.php5 HTTP/1.1 User-Agent: PECL::HTTP/%s Host: dev.iworks.at