From c7b95b4b19bbde93d3f142c5653ad5b68229cfcd Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 3 Mar 2006 20:18:44 +0000 Subject: [PATCH] - unroll http_message_dup() --- http_message_api.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/http_message_api.c b/http_message_api.c index 9154692..402d3dd 100644 --- a/http_message_api.c +++ b/http_message_api.c @@ -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) -- 2.30.2