X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=src%2Fphp_http_client.c;h=4e4a0cf7889783522ebdf3b62e84f9a6647487a4;hp=5de1eac6dd2311a22bb5b175292f2186839220cf;hb=28d7c572181c8c3c335edd3df539f75c3bbde0fd;hpb=ab1eba311be2f8aab98eed7a6164e79d69b402b2 diff --git a/src/php_http_client.c b/src/php_http_client.c index 5de1eac..4e4a0cf 100644 --- a/src/php_http_client.c +++ b/src/php_http_client.c @@ -13,7 +13,7 @@ #include "php_http_api.h" #include "php_http_client.h" -#include +#include "ext/spl/spl_observer.h" /* * array of name => php_http_client_driver_t* @@ -330,6 +330,8 @@ void php_http_client_object_free(zend_object *object) { php_http_client_object_t *o = PHP_HTTP_OBJ(object, NULL); + PTR_FREE(o->gc); + php_http_client_free(&o->client); php_http_object_method_dtor(&o->notify); php_http_object_method_free(&o->update); @@ -356,6 +358,49 @@ zend_object *php_http_client_object_new(zend_class_entry *ce) return &php_http_client_object_new_ex(ce, NULL)->zo; } +static HashTable *php_http_client_object_get_gc(zval *object, zval **table, int *n) +{ + php_http_client_object_t *obj = PHP_HTTP_OBJ(NULL, object); + zend_llist_element *el = NULL; + HashTable *props = Z_OBJPROP_P(object); + uint32_t count = zend_hash_num_elements(props) + zend_llist_count(&obj->client->responses) + zend_llist_count(&obj->client->requests) + 1; + zval *val; + + *n = 0; + *table = obj->gc = erealloc(obj->gc, sizeof(zval) * count); + +#if PHP_HTTP_HAVE_CURL + if (obj->client->ops == php_http_client_curl_get_ops()) { + php_http_client_curl_t *curl = obj->client->ctx; + + if (curl->ev_ops == php_http_client_curl_user_ops_get()) { + php_http_client_curl_user_context_t *ctx = curl->ev_ctx; + + ZVAL_COPY_VALUE(&obj->gc[(*n)++], &ctx->user); + } + } +#endif + + for (el = obj->client->responses.head; el; el = el->next) { + php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data; + ZVAL_OBJ(&obj->gc[(*n)++], &response_obj->zo); + } + + for (el = obj->client->requests.head; el; el = el->next) { + php_http_client_enqueue_t *q = (php_http_client_enqueue_t *) el->data; + php_http_message_object_t *request_obj = q->opaque; /* FIXME */ + ZVAL_OBJ(&obj->gc[(*n)++], &request_obj->zo); + } + + ZEND_HASH_FOREACH_VAL(props, val) + { + ZVAL_COPY_VALUE(&obj->gc[(*n)++], val); + } + ZEND_HASH_FOREACH_END(); + + return NULL; +} + static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response) { zval new_hist, old_hist_tmp, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0, &old_hist_tmp); @@ -400,7 +445,7 @@ static ZEND_RESULT_CODE handle_response(void *arg, php_http_client_t *client, ph *response = NULL; msg_obj = php_http_message_object_new_ex(php_http_get_client_response_class_entry(), msg); - ZVAL_OBJ(&zresponse, &msg_obj->zo); + ZVAL_OBJECT(&zresponse, &msg_obj->zo, 1); ZVAL_OBJECT(&zrequest, &((php_http_message_object_t *) e->opaque)->zo, 1); php_http_message_object_prepend(&zresponse, &zrequest, 1); @@ -411,7 +456,6 @@ static ZEND_RESULT_CODE handle_response(void *arg, php_http_client_t *client, ph zend_update_property(php_http_get_client_response_class_entry(), &zresponse, ZEND_STRL("transferInfo"), &info); zval_ptr_dtor(&info); - Z_ADDREF(zresponse); zend_llist_add_element(&client->responses, &msg_obj); if (e->closure.fci.size) { @@ -478,7 +522,7 @@ static void response_dtor(void *data) { php_http_message_object_t *msg_obj = *(php_http_message_object_t **) data; - zend_objects_store_del(&msg_obj->zo); + zend_object_release(&msg_obj->zo); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0) @@ -579,14 +623,14 @@ static void msg_queue_dtor(php_http_client_enqueue_t *e) { php_http_message_object_t *msg_obj = e->opaque; - zend_objects_store_del(&msg_obj->zo); + zend_object_release(&msg_obj->zo); zend_hash_destroy(e->options); FREE_HASHTABLE(e->options); if (e->closure.fci.size) { zval_ptr_dtor(&e->closure.fci.function_name); if (e->closure.fci.object) { - zend_objects_store_del(e->closure.fci.object); + zend_object_release(e->closure.fci.object); } } } @@ -1231,6 +1275,7 @@ PHP_MINIT_FUNCTION(http_client) php_http_client_object_handlers.offset = XtOffsetOf(php_http_client_object_t, zo); php_http_client_object_handlers.free_obj = php_http_client_object_free; php_http_client_object_handlers.clone_obj = NULL; + php_http_client_object_handlers.get_gc = php_http_client_object_get_gc; zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("observers"), ZEND_ACC_PRIVATE); zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED); zend_declare_property_null(php_http_client_class_entry, ZEND_STRL("history"), ZEND_ACC_PROTECTED);