X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=php_http_client.c;h=66afb7cd7957fc6ca0ec9f760da1f9e7bd6eb9f1;hb=e22fc5f78e8cfc1101c4548de0568add46a8694a;hp=3ee3ff523d62509d9f88bd1f40f9047da92649c7;hpb=d8beb35c8d7194ef1688cfd8dd6ed40ec8e31464;p=m6w6%2Fext-http diff --git a/php_http_client.c b/php_http_client.c index 3ee3ff5..66afb7c 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -22,21 +22,21 @@ static HashTable php_http_client_drivers; static void php_http_client_driver_hash_dtor(zval *pData) { - efree(Z_PTR_P(pData)); + pefree(Z_PTR_P(pData), 1); } ZEND_RESULT_CODE php_http_client_driver_add(php_http_client_driver_t *driver) { - return zend_hash_str_add_mem(&php_http_client_drivers, driver->name_str, driver->name_len, (void *) driver, sizeof(php_http_client_driver_t)) + return zend_hash_add_mem(&php_http_client_drivers, driver->driver_name, (void *) driver, sizeof(php_http_client_driver_t)) ? SUCCESS : FAILURE; } -php_http_client_driver_t *php_http_client_driver_get(const char *name_str, size_t name_len) +php_http_client_driver_t *php_http_client_driver_get(zend_string *name) { zval *ztmp; php_http_client_driver_t *tmp; - if (name_str && (tmp = zend_hash_str_find_ptr(&php_http_client_drivers, name_str, name_len))) { + if (name && (tmp = zend_hash_find_ptr(&php_http_client_drivers, name))) { return tmp; } if ((ztmp = zend_hash_get_current_data(&php_http_client_drivers))) { @@ -50,7 +50,7 @@ static int apply_driver_list(zval *p, void *arg) php_http_client_driver_t *d = Z_PTR_P(p); zval zname; - ZVAL_STRINGL(&zname, d->name_str, d->name_len); + ZVAL_STR(&zname, d->driver_name); zend_hash_next_index_insert(arg, &zname); return ZEND_HASH_APPLY_KEEP; @@ -65,10 +65,10 @@ void php_http_client_options_set_subr(zval *instance, char *key, size_t len, zva { if (overwrite || (opts && zend_hash_num_elements(Z_ARRVAL_P(opts)))) { zend_class_entry *this_ce = Z_OBJCE_P(instance); - zval *old_opts, new_opts, *entry = NULL; + zval old_opts_tmp, *old_opts, new_opts, *entry = NULL; array_init(&new_opts); - old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0); + old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp); if (Z_TYPE_P(old_opts) == IS_ARRAY) { array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL(new_opts)); } @@ -107,7 +107,7 @@ void php_http_client_options_set(zval *instance, zval *opts) zend_update_property(this_ce, instance, ZEND_STRL("options"), &new_opts); zval_ptr_dtor(&new_opts); } else { - zval *old_opts, add_opts, *opt; + zval old_opts_tmp, *old_opts, add_opts, *opt; array_init(&add_opts); /* some options need extra attention -- thus cannot use array_merge() directly */ @@ -119,7 +119,7 @@ void php_http_client_options_set(zval *instance, zval *opts) } else if (is_client && (zend_string_equals_literal(key.key, "recordHistory") || zend_string_equals_literal(key.key, "responseMessageClass"))) { zend_update_property(this_ce, instance, key.key->val, key.key->len, opt); } else if (Z_TYPE_P(opt) == IS_NULL) { - old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0); + old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp); if (Z_TYPE_P(old_opts) == IS_ARRAY) { zend_symtable_del(Z_ARRVAL_P(old_opts), key.key); } @@ -131,7 +131,7 @@ void php_http_client_options_set(zval *instance, zval *opts) } ZEND_HASH_FOREACH_END(); - old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0); + old_opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &old_opts_tmp); if (Z_TYPE_P(old_opts) == IS_ARRAY) { array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL(new_opts)); } @@ -145,7 +145,7 @@ void php_http_client_options_set(zval *instance, zval *opts) void php_http_client_options_get_subr(zval *instance, char *key, size_t len, zval *return_value) { zend_class_entry *this_ce = Z_OBJCE_P(instance); - zval *options, *opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0); + zval *options, opts_tmp, *opts = zend_read_property(this_ce, instance, ZEND_STRL("options"), 0, &opts_tmp); if ((Z_TYPE_P(opts) == IS_ARRAY) && (options = zend_symtable_str_find(Z_ARRVAL_P(opts), key, len))) { RETVAL_ZVAL_FAST(options); @@ -351,7 +351,7 @@ zend_object *php_http_client_object_new(zend_class_entry *ce) static void handle_history(zval *zclient, php_http_message_t *request, php_http_message_t *response) { - zval new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0); + zval new_hist, old_hist_tmp, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0, &old_hist_tmp); php_http_message_t *req_copy = php_http_message_copy(request, NULL); php_http_message_t *res_copy = php_http_message_copy(response, NULL); php_http_message_t *zipped = php_http_message_zip(res_copy, req_copy); @@ -378,13 +378,13 @@ static ZEND_RESULT_CODE handle_response(void *arg, php_http_client_t *client, ph if ((msg = *response)) { php_http_message_object_t *msg_obj; - zval info, zresponse, zrequest; + zval info, zresponse, zrequest, rec_hist_tmp; HashTable *info_ht; /* ensure the message is of type response (could be uninitialized in case of early error, like DNS) */ php_http_message_set_type(msg, PHP_HTTP_RESPONSE); - if (zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0))) { + if (zend_is_true(zend_read_property(php_http_client_class_entry, &zclient, ZEND_STRL("recordHistory"), 0, &rec_hist_tmp))) { handle_history(&zclient, *request, *response); } @@ -479,21 +479,20 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, __construct) { - char *driver_str = NULL, *persistent_handle_str = NULL; - size_t driver_len = 0, persistent_handle_len = 0; + zend_string *driver_name = NULL, *persistent_handle_name = NULL; php_http_client_driver_t *driver; php_resource_factory_t *rf = NULL; php_http_client_object_t *obj; zval os; - php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len), invalid_arg, return); + php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|S!S!", &driver_name, &persistent_handle_name), invalid_arg, return); if (!zend_hash_num_elements(&php_http_client_drivers)) { php_http_throw(unexpected_val, "No http\\Client drivers available", NULL); return; } - if (!(driver = php_http_client_driver_get(driver_str, driver_len))) { - php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_len ? driver_str : "default"); + if (!(driver = php_http_client_driver_get(driver_name))) { + php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_name ? driver_name->val : "default"); return; } @@ -501,19 +500,12 @@ static PHP_METHOD(HttpClient, __construct) zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), &os); zval_ptr_dtor(&os); - if (persistent_handle_len) { - char *name_str; - size_t name_len; + if (persistent_handle_name) { php_persistent_handle_factory_t *pf; - name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver->name_str); - php_http_pretty_key(name_str + lenof("http\\Client\\"), driver->name_len, 1, 1); - - if ((pf = php_persistent_handle_concede(NULL, name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL))) { + if ((pf = php_persistent_handle_concede(NULL, driver->client_name, persistent_handle_name, NULL, NULL))) { rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon); } - - efree(name_str); } obj = PHP_HTTP_OBJ(NULL, getThis()); @@ -547,7 +539,7 @@ static HashTable *combined_options(zval *client, zval *request) { HashTable *options; unsigned num_options = 0; - zval z_roptions, *z_coptions = zend_read_property(php_http_client_class_entry, client, ZEND_STRL("options"), 0); + zval z_roptions, z_options_tmp, *z_coptions = zend_read_property(php_http_client_class_entry, client, ZEND_STRL("options"), 0, &z_options_tmp); if (Z_TYPE_P(z_coptions) == IS_ARRAY) { num_options = zend_hash_num_elements(Z_ARRVAL_P(z_coptions)); @@ -765,11 +757,11 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getHistory, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, getHistory) { - zval *zhistory; + zval zhistory_tmp, *zhistory; php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0); + zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0, &zhistory_tmp); RETVAL_ZVAL_FAST(zhistory); } @@ -867,11 +859,11 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_notify, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, notify) { - zval *request = NULL, *zprogress = NULL, *observers, args[3]; + zval *request = NULL, *zprogress = NULL, observers_tmp, *observers, args[3]; php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O!o!", &request, php_http_client_request_class_entry, &zprogress), invalid_arg, return); - observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0); + observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp); if (Z_TYPE_P(observers) != IS_OBJECT) { php_http_throw(unexpected_val, "Observer storage is corrupted", NULL); @@ -908,11 +900,11 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_attach, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, attach) { - zval *observers, *observer, retval; + zval observers_tmp, *observers, *observer, retval; php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &observer, spl_ce_SplObserver), invalid_arg, return); - observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0); + observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp); if (Z_TYPE_P(observers) != IS_OBJECT) { php_http_throw(unexpected_val, "Observer storage is corrupted", NULL); @@ -931,11 +923,11 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_detach, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, detach) { - zval *observers, *observer, retval; + zval observers_tmp, *observers, *observer, retval; php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O", &observer, spl_ce_SplObserver), invalid_arg, return); - observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0); + observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp); if (Z_TYPE_P(observers) != IS_OBJECT) { php_http_throw(unexpected_val, "Observer storage is corrupted", NULL); @@ -953,11 +945,11 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getObservers, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, getObservers) { - zval *observers; + zval observers_tmp, *observers; php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return); - observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0); + observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0, &observers_tmp); if (Z_TYPE_P(observers) != IS_OBJECT) { php_http_throw(unexpected_val, "Observer storage is corrupted", NULL); @@ -1033,7 +1025,7 @@ ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, getOptions) { if (SUCCESS == zend_parse_parameters_none()) { - zval *options = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0); + zval options_tmp, *options = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("options"), 0, &options_tmp); RETVAL_ZVAL_FAST(options); } }