From: Michael Wallner Date: Fri, 21 Oct 2005 14:09:08 +0000 (+0000) Subject: - start thinking about cloning X-Git-Tag: RELEASE_0_17_0~24 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=b0c335e3addb18b3b2c09a8a2cbd2bce95152703;p=m6w6%2Fext-http - start thinking about cloning --- diff --git a/http_request_object.c b/http_request_object.c index 3244161..459536a 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -222,6 +222,8 @@ HTTP_END_ARGS; #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C) static inline void _http_request_object_declare_default_properties(TSRMLS_D); +#define http_request_object_clone_obj _http_request_object_clone_obj +static inline zend_object_value _http_request_object_clone_obj(zval *object TSRMLS_DC); zend_class_entry *http_request_object_ce; zend_function_entry http_request_object_fe[] = { @@ -301,17 +303,28 @@ static zend_object_handlers http_request_object_handlers; PHP_MINIT_FUNCTION(http_request_object) { HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0); + http_request_object_handlers.clone_obj = NULL; /* http_request_object_clone_obj; */ return SUCCESS; } zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) +{ + return http_request_object_new_ex(ce, NULL); +} + +zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL* ch TSRMLS_DC) { zend_object_value ov; http_request_object *o; o = ecalloc(1, sizeof(http_request_object)); o->zo.ce = ce; - o->ch = curl_easy_init(); + + if (ch) { + o->ch = ch; + } else { + o->ch = curl_easy_init(); + } phpstr_init(&o->history); phpstr_init(&o->request); @@ -327,6 +340,39 @@ zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) return ov; } +zend_object_value _http_request_object_clone(zval *object TSRMLS_DC) +{ + return http_request_object_clone_obj(object TSRMLS_CC); +} + +static inline zend_object_value _http_request_object_clone_obj(zval *object TSRMLS_DC) +{ + zval clone; + getObjectEx(http_request_object, obj, object); + + INIT_PZVAL(&clone); + clone.value.obj = http_request_object_new_ex(Z_OBJCE_P(object), curl_easy_duphandle(obj->ch)); + { + getObjectEx(http_request_object, cobj, &clone); + + /* copy history */ + phpstr_append(&cobj->history, PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history)); + /* + phpstr_append(&cobj->request, PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request)); + phpstr_append(&obj->response, PHPSTR_VAL(&obj->response), PHPSTR_ÖEN(&obj->response)); + */ + /* copy properties */ + zend_hash_copy(OBJ_PROP(cobj), OBJ_PROP(obj), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); + + /* attach to pool */ + if (obj->pool) { + http_request_pool_attach(obj->pool, &clone); + } + } + + return clone.value.obj; +} + static inline void _http_request_object_declare_default_properties(TSRMLS_D) { zend_class_entry *ce = http_request_object_ce; diff --git a/php_http_request_object.h b/php_http_request_object.h index 5959dbd..7cbc2a3 100644 --- a/php_http_request_object.h +++ b/php_http_request_object.h @@ -46,8 +46,13 @@ extern PHP_MINIT_FUNCTION(http_request_object); #define http_request_object_new _http_request_object_new extern zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC); +#define http_request_object_new_ex(ce, ch) _http_request_object_new_ex((ce), (ch) TSRMLS_CC) +#define http_request_object_from_curl(ch) _http_request_object_new_ex(http_request_object_ce, (ch) TSRMLS_CC) +extern zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch TSRMLS_DC); #define http_request_object_free _http_request_object_free extern void _http_request_object_free(zend_object *object TSRMLS_DC); +#define http_request_object_clone(o) _http_request_object_clone((o) TSRMLS_CC) +extern zend_object_value _http_request_object_clone(zval *object TSRMLS_DC); #define http_request_object_requesthandler(req, this, body) _http_request_object_requesthandler((req), (this), (body) TSRMLS_CC) extern STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr, http_request_body *body TSRMLS_DC);