X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_object.c;h=e6ed74ae0aaafd0dd2e876e746296e8322bdc08e;hb=c64365b84429b86b4af55b283de3758af38d9369;hp=7eb00d493809e176c1bce075413d84f364113529;hpb=32e91737086db53bb1fd9ed9f79d693c43ec459f;p=m6w6%2Fext-http diff --git a/http_request_object.c b/http_request_object.c index 7eb00d4..e6ed74a 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -12,10 +12,6 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" @@ -302,7 +298,7 @@ PHP_MINIT_FUNCTION(http_request_object) zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC) { - return http_request_object_new_ex(ce, curl_easy_init(), NULL); + return http_request_object_new_ex(ce, NULL, NULL); } zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC) @@ -337,7 +333,10 @@ zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC) getObject(http_request_object, old_obj); old_zo = zend_objects_get_address(this_ptr TSRMLS_CC); - new_ov = http_request_object_new_ex(old_zo->ce, curl_easy_duphandle(old_obj->request->ch), &new_obj); + new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj); + if (old_obj->request->ch) { + http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request); + } zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC); phpstr_append(&new_obj->history, old_obj->history.data, old_obj->history.used); @@ -403,6 +402,11 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) /* WebDAV Access Control - RFC 3744 */ DCL_CONST(long, "METH_ACL", HTTP_ACL); + /* cURL HTTP protocol versions */ + DCL_CONST(long, "VERSION_1_0", CURL_HTTP_VERSION_1_0); + DCL_CONST(long, "VERSION_1_1", CURL_HTTP_VERSION_1_1); + DCL_CONST(long, "VERSION_NONE", CURL_HTTP_VERSION_NONE); + /* * Auth Constants */ @@ -431,7 +435,7 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ STATUS status = SUCCESS; http_request_reset(obj->request); - HTTP_CHECK_CURL_INIT(obj->request->ch, curl_easy_init(), return FAILURE); + HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init(obj->request), return FAILURE); obj->request->url = http_absolute_url(Z_STRVAL_P(GET_PROP(url))); @@ -497,8 +501,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ fields = (Z_TYPE_P(zfields) == IS_ARRAY) ? Z_ARRVAL_P(zfields) : NULL; files = (Z_TYPE_P(zfiles) == IS_ARRAY) ? Z_ARRVAL_P(zfiles) : NULL; - if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) { - status = FAILURE; + if ((fields && zend_hash_num_elements(fields)) || (files && zend_hash_num_elements(files))) { + if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) { + status = FAILURE; + } } } } @@ -597,7 +603,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this zval_ptr_dtor(&resp); MAKE_STD_ZVAL(message); - ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL)); + ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL), 0); SET_PROP(responseMessage, message); zval_ptr_dtor(&message); @@ -619,8 +625,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow)) static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite) { - zval *old_opts, *new_opts, *opts, **entry; - getObject(http_request_object, obj); + zval *old_opts, *new_opts, *opts = NULL, **entry; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) { RETURN_FALSE; @@ -662,10 +667,8 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, IF_RETVAL_USED { zval *opts, **options; - getObject(http_request_object, obj); opts = GET_PROP(options); - array_init(return_value); if ( (Z_TYPE_P(opts) == IS_ARRAY) && @@ -696,7 +699,6 @@ PHP_METHOD(HttpRequest, __construct) int URL_len; long meth = -1; zval *options = NULL; - getObject(http_request_object, obj); SET_EH_THROW_HTTP(); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla", &URL, &URL_len, &meth, &options)) { @@ -730,7 +732,6 @@ PHP_METHOD(HttpRequest, setOptions) ulong idx = 0; HashPosition pos; zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) { RETURN_FALSE; @@ -934,7 +935,6 @@ PHP_METHOD(HttpRequest, setUrl) { char *URL = NULL; int URL_len; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) { RETURN_FALSE; @@ -973,7 +973,6 @@ PHP_METHOD(HttpRequest, getUrl) PHP_METHOD(HttpRequest, setMethod) { long meth; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) { RETURN_FALSE; @@ -1116,7 +1115,6 @@ PHP_METHOD(HttpRequest, addQueryData) zval *qdata, *old_qdata; char *query_data = NULL; size_t query_data_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) { RETURN_FALSE; @@ -1148,7 +1146,6 @@ PHP_METHOD(HttpRequest, addQueryData) PHP_METHOD(HttpRequest, addPostFields) { zval *post_data, *old_post, *new_post; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &post_data)) { RETURN_FALSE; @@ -1183,7 +1180,6 @@ PHP_METHOD(HttpRequest, addPostFields) PHP_METHOD(HttpRequest, setPostFields) { zval *post, *post_data = NULL; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &post_data)) { RETURN_FALSE; @@ -1233,7 +1229,6 @@ PHP_METHOD(HttpRequest, setRawPostData) { char *raw_data = NULL; int data_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) { RETURN_FALSE; @@ -1261,7 +1256,6 @@ PHP_METHOD(HttpRequest, addRawPostData) { char *raw_data; int data_len; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) { RETURN_FALSE; @@ -1315,7 +1309,6 @@ PHP_METHOD(HttpRequest, addPostFile) zval *entry, *old_post, *new_post; char *name, *file, *type = NULL; int name_len, file_len, type_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) { RETURN_FALSE; @@ -1363,7 +1356,6 @@ PHP_METHOD(HttpRequest, addPostFile) PHP_METHOD(HttpRequest, setPostFiles) { zval *files = NULL, *post; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!/", &files)) { RETURN_FALSE; @@ -1410,7 +1402,6 @@ PHP_METHOD(HttpRequest, setPutFile) { char *file = ""; int file_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) { RETURN_FALSE; @@ -1477,7 +1468,6 @@ PHP_METHOD(HttpRequest, getResponseHeader) zval *data, **headers, **header; char *header_name = NULL; int header_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) { RETURN_FALSE; @@ -1522,7 +1512,6 @@ PHP_METHOD(HttpRequest, getResponseCookie) zval *data, **headers; char *cookie_name = NULL; int cookie_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) { RETURN_FALSE; @@ -1623,7 +1612,6 @@ PHP_METHOD(HttpRequest, getResponseBody) IF_RETVAL_USED { zval **body; - getObject(http_request_object, obj); zval *data = GET_PROP(responseData); if ( (Z_TYPE_P(data) == IS_ARRAY) && @@ -1677,7 +1665,6 @@ PHP_METHOD(HttpRequest, getResponseInfo) zval *info, **infop; char *info_name = NULL; int info_len = 0; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) { RETURN_FALSE; @@ -1722,12 +1709,11 @@ PHP_METHOD(HttpRequest, getResponseMessage) IF_RETVAL_USED { zval *message; - getObject(http_request_object, obj); SET_EH_THROW_HTTP(); message = GET_PROP(responseMessage); if (Z_TYPE_P(message) == IS_OBJECT) { - RETVAL_OBJECT(message); + RETVAL_OBJECT(message, 1); } else { RETVAL_NULL(); } @@ -1764,7 +1750,7 @@ PHP_METHOD(HttpRequest, getRequestMessage) SET_EH_THROW_HTTP(); if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) { - ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL)); + RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL), 0); } SET_EH_NORMAL(); } @@ -1838,7 +1824,7 @@ PHP_METHOD(HttpRequest, getHistory) SET_EH_THROW_HTTP(); if ((msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history)))) { - ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL)); + RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL), 0); } SET_EH_NORMAL(); } @@ -1918,7 +1904,7 @@ PHP_METHOD(HttpRequest, send) } else if (SUCCESS == http_request_object_requesthandler(obj, getThis())) { http_request_exec(obj->request); if (SUCCESS == http_request_object_responsehandler(obj, getThis())) { - RETVAL_OBJECT(GET_PROP(responseMessage)); + RETVAL_OBJECT(GET_PROP(responseMessage), 1); } }