From: Michael Wallner Date: Wed, 28 Dec 2005 14:16:27 +0000 (+0000) Subject: - return zvals directly and don'T assume a type X-Git-Tag: RELEASE_0_21_0~20 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=43923eca4429ed3ce5fb85407345d7030a1879f1;p=m6w6%2Fext-http - return zvals directly and don'T assume a type - fix crash with http_request_body_fill(NULL,NULL,NULL) - add test --- diff --git a/http_request_body_api.c b/http_request_body_api.c index 8476b63..401e0ac 100644 --- a/http_request_body_api.c +++ b/http_request_body_api.c @@ -52,31 +52,33 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, struct curl_httppost *http_post_data[2] = {NULL, NULL}; /* normal data */ - FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) { - if (key) { - CURLcode err; - zval *orig = *data; - - convert_to_string_ex(data); - err = curl_formadd(&http_post_data[0], &http_post_data[1], - CURLFORM_COPYNAME, key, - CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data), - CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data), - CURLFORM_END - ); - - if (orig != *data) { - zval_ptr_dtor(data); - } - - if (CURLE_OK != err) { - http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err)); - curl_formfree(http_post_data[0]); - return NULL; + if (fields) { + FOREACH_HASH_KEYVAL(pos, fields, key, idx, data) { + if (key) { + CURLcode err; + zval *orig = *data; + + convert_to_string_ex(data); + err = curl_formadd(&http_post_data[0], &http_post_data[1], + CURLFORM_COPYNAME, key, + CURLFORM_COPYCONTENTS, Z_STRVAL_PP(data), + CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_PP(data), + CURLFORM_END + ); + + if (orig != *data) { + zval_ptr_dtor(data); + } + + if (CURLE_OK != err) { + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err)); + curl_formfree(http_post_data[0]); + return NULL; + } + + /* reset */ + key = NULL; } - - /* reset */ - key = NULL; } } @@ -129,7 +131,7 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1); - } else { + } else if (fields) { char *encoded; size_t encoded_len; @@ -139,6 +141,8 @@ PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, } return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1); + } else { + return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, estrndup("", 0), 0, 1); } } diff --git a/http_request_object.c b/http_request_object.c index 4b85676..f763b48 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -643,7 +643,8 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, array_init(return_value); - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options)) { + if ( (Z_TYPE_P(opts) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void **) &options))) { convert_to_array(*options); array_copy(*options, return_value); } @@ -715,6 +716,7 @@ PHP_METHOD(HttpRequest, setOptions) if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) { SET_PROP(obj, options, new_opts); + zval_ptr_dtor(&new_opts); RETURN_TRUE; } @@ -1369,6 +1371,7 @@ PHP_METHOD(HttpRequest, setPostFiles) array_copy(files, post); } SET_PROP(obj, postFiles, post); + zval_ptr_dtor(&post); RETURN_TRUE; } @@ -1386,9 +1389,9 @@ PHP_METHOD(HttpRequest, getPostFiles) IF_RETVAL_USED { getObject(http_request_object, obj); - - array_init(return_value); - array_copy(GET_PROP(obj, postFiles), return_value); + zval *files = GET_PROP(obj, postFiles); + + RETURN_ZVAL(files, 1, 0); } } /* }}} */ @@ -1453,9 +1456,9 @@ PHP_METHOD(HttpRequest, getResponseData) IF_RETVAL_USED { getObject(http_request_object, obj); + zval *data = GET_PROP(obj, responseData); - array_init(return_value); - array_copy(GET_PROP(obj, responseData), return_value); + RETURN_ZVAL(data, 1, 0); } } /* }}} */ diff --git a/tests/HttpRequest_005.phpt b/tests/HttpRequest_005.phpt new file mode 100644 index 0000000..7fc0dc5 --- /dev/null +++ b/tests/HttpRequest_005.phpt @@ -0,0 +1,26 @@ +--TEST-- +HttpRequest accessors +--SKIPIF-- + +--FILE-- + 3 && substr($method, 0, 3) == 'get') + $x = $r->$method(); + else + $x = $r->$method(null, null); + } catch (HttpException $e) { + } +} +echo "Done\n"; +?> +--EXPECTF-- +%sTEST +Done