- unroll http_message_dup()
authorMichael Wallner <mike@php.net>
Fri, 3 Mar 2006 20:18:44 +0000 (20:18 +0000)
committerMichael Wallner <mike@php.net>
Fri, 3 Mar 2006 20:18:44 +0000 (20:18 +0000)
http_message_api.c

index 915469248187e0119070235d60d6956883545bea..402d3dd4ea8e782eebe526ce121defcd42b80994 100644 (file)
@@ -579,19 +579,35 @@ PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC)
        return rs;
 }
 
-PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC)
+PHP_HTTP_API http_message *_http_message_dup(http_message *orig TSRMLS_DC)
 {
-       /*
-        * TODO: unroll
-        */
-       http_message *new;
-       char *serialized_data;
-       size_t serialized_length;
-
-       http_message_serialize(msg, &serialized_data, &serialized_length);
-       new = http_message_parse(serialized_data, serialized_length);
-       efree(serialized_data);
-       return new;
+       http_message *temp, *copy = NULL;
+       http_info info;
+       
+       if (orig) {
+               info.type = orig->type;
+               info.http = orig->http;
+               
+               copy = temp = http_message_new();
+               http_message_set_info(temp, &info);
+               zend_hash_copy(&temp->hdrs, &orig->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+               phpstr_append(&temp->body, orig->body.data, orig->body.used);
+       
+               while (orig->parent) {
+                       info.type = orig->parent->type;
+                       info.http = orig->parent->http;
+               
+                       temp->parent = http_message_new();
+                       http_message_set_info(temp->parent, &info);
+                       zend_hash_copy(&temp->parent->hdrs, &orig->parent->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
+                       phpstr_append(&temp->parent->body, orig->parent->body.data, orig->parent->body.used);
+               
+                       temp = temp->parent;
+                       orig = orig->parent;
+               }
+       }
+       
+       return copy;
 }
 
 PHP_HTTP_API void _http_message_dtor(http_message *message)