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;
*/
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);
}
}
/* }}} */
/*
stuck request messages in between response messages
-
+
response request
v v
response request
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;
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? */
#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)