X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_client.c;h=4d109bd0e313de840f262e72a6b7fc759180ecc6;hp=0de62c9bdbd33bbcc9610459efb25dc1f1ed90e2;hb=0ee6755121a35b2e7bcca536f19c8d34d2b9ba6b;hpb=628bdcb6edd65cb683b43af16cd0ce619b56d58a diff --git a/php_http_client.c b/php_http_client.c index 0de62c9..4d109bd 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -13,8 +13,9 @@ #include "php_http_api.h" #include +#include -PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_http_resource_factory_t *rf, void *init_arg TSRMLS_DC) +PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC) { php_http_client_t *free_h = NULL; @@ -27,15 +28,15 @@ PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_h if (rf) { h->rf = rf; } else if (ops->rsrc) { - h->rf = php_http_resource_factory_init(NULL, h->ops->rsrc, h, NULL); + h->rf = php_resource_factory_init(NULL, h->ops->rsrc, h, NULL); } h->request.buffer = php_http_buffer_init(NULL); h->request.parser = php_http_message_parser_init(NULL TSRMLS_CC); - h->request.message = php_http_message_init(NULL, 0 TSRMLS_CC); + h->request.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); h->response.buffer = php_http_buffer_init(NULL); h->response.parser = php_http_message_parser_init(NULL TSRMLS_CC); - h->response.message = php_http_message_init(NULL, 0 TSRMLS_CC); + h->response.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); TSRMLS_SET_CTX(h->ts); @@ -58,7 +59,7 @@ PHP_HTTP_API void php_http_client_dtor(php_http_client_t *h) h->ops->dtor(h); } - php_http_resource_factory_free(&h->rf); + php_resource_factory_free(&h->rf); php_http_message_parser_free(&h->request.parser); php_http_message_free(&h->request.message); @@ -91,19 +92,19 @@ PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, ph to->ops = from->ops; if (from->rf) { - php_http_resource_factory_addref(from->rf); + php_resource_factory_addref(from->rf); to->rf = from->rf; } else if (to->ops->rsrc){ - to->rf = php_http_resource_factory_init(NULL, to->ops->rsrc, to, NULL); + to->rf = php_resource_factory_init(NULL, to->ops->rsrc, to, NULL); } to->request.buffer = php_http_buffer_init(NULL); to->request.parser = php_http_message_parser_init(NULL TSRMLS_CC); - to->request.message = php_http_message_init(NULL, 0 TSRMLS_CC); + to->request.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); to->response.buffer = php_http_buffer_init(NULL); to->response.parser = php_http_message_parser_init(NULL TSRMLS_CC); - to->response.message = php_http_message_init(NULL, 0 TSRMLS_CC); + to->response.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); TSRMLS_SET_CTX(to->ts); @@ -352,6 +353,7 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D php_http_client_object_t *obj = zend_object_store_get_object(zclient TSRMLS_CC); php_http_client_progress_t *progress; zval *zoptions; + HashTable options; /* do we have a valid request? */ if (*zreq) { @@ -373,12 +375,19 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D /* reset transfer info */ zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("transferInfo") TSRMLS_CC); + /* set client options */ + zend_hash_init(&options, 0, NULL, ZVAL_PTR_DTOR, 0); zoptions = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("options"), 0 TSRMLS_CC); - php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions)); - /* set request options */ + if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) { + php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC); + } zoptions = zend_read_property(php_http_client_request_get_class_entry(), *zreq, ZEND_STRL("options"), 0 TSRMLS_CC); - php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, Z_ARRVAL_P(zoptions)); + if (Z_TYPE_P(zoptions) == IS_ARRAY && zend_hash_num_elements(Z_ARRVAL_P(zoptions))) { + php_array_merge(&options, Z_ARRVAL_P(zoptions), 1 TSRMLS_CC); + } + php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_SETTINGS, &options); + zend_hash_destroy(&options); /* set progress callback */ if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, &progress)) { @@ -386,7 +395,6 @@ STATUS php_http_client_object_handle_request(zval *zclient, zval **zreq TSRMLS_D php_http_client_progress_callback_t *callback = emalloc(sizeof(*callback)); callback->type = PHP_HTTP_CLIENT_PROGRESS_CALLBACK_USER; - callback->pass_state = 0; MAKE_STD_ZVAL(callback->func.user); array_init(callback->func.user); Z_ADDREF_P(zclient); @@ -444,7 +452,7 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC) zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("responseMessage"), message TSRMLS_CC); zval_ptr_dtor(&message); - obj->client->response.message = php_http_message_init(NULL, 0 TSRMLS_CC); + obj->client->response.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); } else { zend_update_property_null(php_http_client_class_entry, zclient, ZEND_STRL("responseMessage") TSRMLS_CC); } @@ -461,7 +469,7 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC) ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), msg, NULL TSRMLS_CC), 0); zend_update_property(php_http_client_class_entry, zclient, ZEND_STRL("requestMessage"), message TSRMLS_CC); zval_ptr_dtor(&message); - obj->client->request.message = php_http_message_init(NULL, 0 TSRMLS_CC); + obj->client->request.message = php_http_message_init(NULL, 0, NULL TSRMLS_CC); } } @@ -924,7 +932,7 @@ PHP_METHOD(HttpClient, request) MAKE_STD_ZVAL(req); ZVAL_OBJVAL(req, ov, 0); - msg_obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST TSRMLS_CC); + msg_obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC); PHP_HTTP_INFO(msg_obj->message).request.url = estrndup(url_str, url_len); PHP_HTTP_INFO(msg_obj->message).request.method = estrndup(meth_str, meth_len); @@ -975,7 +983,7 @@ PHP_METHOD(HttpClient, send) PHP_MINIT_FUNCTION(http_client) { - PHP_HTTP_REGISTER_CLASS(http\\Client, AbstractClient, http_client, php_http_object_get_class_entry(), ZEND_ACC_ABSTRACT); + PHP_HTTP_REGISTER_CLASS(http\\Client, AbstractClient, http_client, php_http_object_get_class_entry(), ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); php_http_client_class_entry->create_object = php_http_client_object_new; memcpy(&php_http_client_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); php_http_client_object_handlers.clone_obj = php_http_client_object_clone;