+ ret = SUCCESS;
+ } else {
+ /* update properties with empty values*/
+ zval *resp = GET_PROP(responseData), *znull;
+
+ MAKE_STD_ZVAL(znull);
+ ZVAL_NULL(znull);
+ SET_PROP(responseMessage, znull);
+ zval_ptr_dtor(&znull);
+
+ if (Z_TYPE_P(resp) == IS_ARRAY) {
+ zend_hash_clean(Z_ARRVAL_P(resp));
+ }
+
+ UPD_PROP(long, responseCode, 0);
+ UPD_PROP(string, responseStatus, "");
+
+ /* append request message to history */
+ if (zval_is_true(GET_PROP(recordHistory))) {
+ http_message *request;
+
+ if ((request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
+ zval *hist, *history = GET_PROP(history);
+
+ MAKE_STD_ZVAL(hist);
+ ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, request, NULL), 0);
+ if (Z_TYPE_P(history) == IS_OBJECT) {
+ http_message_object_prepend(hist, history);
+ }
+ SET_PROP(history, hist);
+ zval_ptr_dtor(&hist);
+ }
+ }
+
+ ret = FAILURE;
+ }
+
+ if (!EG(exception) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
+ zval *param;
+
+ MAKE_STD_ZVAL(param);
+ ZVAL_BOOL(param, ret == SUCCESS);
+ with_error_handling(EH_NORMAL, NULL) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
+ } end_error_handling();
+ zval_ptr_dtor(¶m);
+ }
+
+ return ret;
+}
+
+static int apply_pretty_key(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
+{
+ if (hash_key->nKeyLength > 1) {
+ hash_key->h = zend_get_hash_value(pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
+ }
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+#define http_request_object_set_options_subr(key, ow, pk) \
+ _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow), (pk))
+static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite, int prettify_keys)
+{
+ zval *old_opts, *new_opts, *opts = NULL, **entry = NULL;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(new_opts);
+ array_init(new_opts);
+ old_opts = GET_PROP(options);
+ if (Z_TYPE_P(old_opts) == IS_ARRAY) {
+ array_copy(old_opts, new_opts);
+ }
+
+ if (prettify_keys && opts) {
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(opts), apply_pretty_key, 0);
+ }
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
+ if (overwrite) {
+ zend_hash_clean(Z_ARRVAL_PP(entry));
+ }
+ if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
+ if (overwrite) {
+ array_copy(opts, *entry);
+ } else {
+ array_merge(opts, *entry);
+ }
+ }
+ } else if (opts) {
+ ZVAL_ADDREF(opts);
+ add_assoc_zval(new_opts, key, opts);
+ }
+ SET_PROP(options, new_opts);
+ zval_ptr_dtor(&new_opts);
+
+ RETURN_TRUE;
+}
+
+#define http_request_object_get_options_subr(key) \
+ _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
+static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ zval *opts, **options;
+
+ opts = GET_PROP(options);
+ array_init(return_value);