- reverse request history
authorMichael Wallner <mike@php.net>
Tue, 14 Feb 2006 17:18:54 +0000 (17:18 +0000)
committerMichael Wallner <mike@php.net>
Tue, 14 Feb 2006 17:18:54 +0000 (17:18 +0000)
http_message_object.c
http_request_object.c
php_http_message_object.h
tests/HttpRequest_002.phpt
tests/HttpRequest_007.phpt

index ad4d8277ef02d829f0c9878288ebee4937689efa..c642754c73641b81bf4182bee3a71d25ebc7f658 100644 (file)
@@ -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);
        }
 }
 /* }}} */
index 2ab84c0c3fe0300efbe271254a58be09e62d6b3f..45ef05053cc6b07ccff0e56bb1e3d8a2cde3a0df 100644 (file)
@@ -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? */
index 4c084703fce5b4b171a4c2f0947c31e8c2fb21a0..b3a836e342ceed34252191298083ee1b73d7a86c 100644 (file)
@@ -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)
index eca6d021d49c4506532c4682f098c952fcb2edf9..a5569773a6b10571cb03a7db423160243db6115f 100644 (file)
@@ -57,6 +57,8 @@ Array
     [proxyauth_avail] => %s
     [num_connects] => %d
     [cookies] => Array%s
+    [os_errno] => 0
+    [error] => 
 )
 Array
 (
index 74ce5276744e5b081b7622e04fd7bd01720f4e9c..96160af3db1cb89d2cf16c5754b08f4b41094274 100644 (file)
@@ -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