X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_client.c;h=5aca3bce113917231e7be63815f9975a92e0b521;hp=f131136a1d0222021cd137e85d21f91f7b7b0fca;hb=7566d9549758b56d37b86473feb16248378744e0;hpb=5913db177b07398233cb00d2357aba595eab8371 diff --git a/php_http_client.c b/php_http_client.c index f131136..5aca3bc 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -13,6 +13,7 @@ #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) { @@ -297,7 +298,7 @@ zend_object_value php_http_client_object_new_ex(zend_class_entry *ce, php_http_c o = ecalloc(1, sizeof(*o)); zend_object_std_init((zend_object *) o, ce TSRMLS_CC); object_properties_init((zend_object *) o, ce); - + ov.handle = zend_objects_store_put(o, NULL, php_http_client_object_free, NULL TSRMLS_CC); ov.handlers = &php_http_client_object_handlers; @@ -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); @@ -419,10 +427,10 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC) zval_ptr_dtor(&info); if ((msg = obj->client->response.message)) { - /* FIXME: update history */ if (i_zend_is_true(zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("recordHistory"), 0 TSRMLS_CC))) { zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC); - zend_object_value ov = php_http_client_object_message(zclient, php_http_message_copy(msg, NULL) TSRMLS_CC); + php_http_message_t *zipped = php_http_message_zip(obj->client->response.message, obj->client->request.message); + zend_object_value ov = php_http_client_object_message(zclient, zipped TSRMLS_CC); MAKE_STD_ZVAL(new_hist); ZVAL_OBJVAL(new_hist, ov, 0); @@ -458,7 +466,7 @@ STATUS php_http_client_object_handle_response(zval *zclient TSRMLS_DC) /* update the actual request message */ MAKE_STD_ZVAL(message); - ZVAL_OBJVAL(message, php_http_message_object_new_ex(php_http_message_get_class_entry(), php_http_message_copy_ex(msg, NULL, 0), NULL TSRMLS_CC), 0); + 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); @@ -771,7 +779,7 @@ PHP_METHOD(HttpClient, addCookies) zval *opts = NULL; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) { - php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC); + php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC); RETVAL_ZVAL(getThis(), 1, 0); } @@ -916,7 +924,6 @@ PHP_METHOD(HttpClient, request) with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a!z!a!/", &meth_str, &meth_len, &url_str, &url_len, &zheader, &zbody, &zoptions)) { - php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); php_http_message_object_t *msg_obj; zend_object_value ov; zval *req, *res = NULL; @@ -955,7 +962,7 @@ PHP_METHOD(HttpClient, send) RETVAL_FALSE; with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O!", &zreq, php_http_client_request_get_class_entry())) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!", &zreq, php_http_client_request_get_class_entry())) { if (SUCCESS == php_http_client_object_handle_request(getThis(), &zreq TSRMLS_CC)) { php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); php_http_message_object_t *req = zend_object_store_get_object(zreq TSRMLS_CC); @@ -976,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;