X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_object.c;h=bb3ebf46527e02a498cba94567e907bdb9209e24;hp=a3b132eeaaae4b4b60d50de558feb1777ad58101;hb=1a0dbb96fbe46a2edec1c813798cef7b0898eebe;hpb=34b27dcfad5431b1c585a79733b4786b28dbd482 diff --git a/http_request_object.c b/http_request_object.c index a3b132e..bb3ebf4 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -6,16 +6,12 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2005, Michael Wallner | + | Copyright (c) 2004-2006, Michael Wallner | +--------------------------------------------------------------------+ */ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_CURL #include "php_http.h" @@ -32,187 +28,191 @@ #include "php_http_request_pool_api.h" #include "php_http_url_api.h" -ZEND_EXTERN_MODULE_GLOBALS(http); - -#define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args) -#define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref) -#define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility) -#define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method)) +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, 0, req_args) +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequest, method, 0) +#define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility) +#define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method)) -HTTP_BEGIN_ARGS(__construct, 0, 0) +HTTP_BEGIN_ARGS(__construct, 0) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(method, 0) HTTP_ARG_VAL(options, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getOptions, 0); -HTTP_BEGIN_ARGS(setOptions, 0, 0) +HTTP_EMPTY_ARGS(getOptions); +HTTP_BEGIN_ARGS(setOptions, 0) HTTP_ARG_VAL(options, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getSslOptions, 0); -HTTP_BEGIN_ARGS(setSslOptions, 0, 0) +HTTP_EMPTY_ARGS(getSslOptions); +HTTP_BEGIN_ARGS(setSslOptions, 0) HTTP_ARG_VAL(ssl_options, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getHeaders, 0); -HTTP_BEGIN_ARGS(setHeaders, 0, 0) +HTTP_BEGIN_ARGS(addSslOptions, 0) + HTTP_ARG_VAL(ssl_optins, 0) +HTTP_END_ARGS; + +HTTP_EMPTY_ARGS(getHeaders); +HTTP_BEGIN_ARGS(setHeaders, 0) HTTP_ARG_VAL(headers, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addHeaders, 0, 1) +HTTP_BEGIN_ARGS(addHeaders, 1) HTTP_ARG_VAL(headers, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getCookies, 0); -HTTP_BEGIN_ARGS(setCookies, 0, 0) +HTTP_EMPTY_ARGS(getCookies); +HTTP_BEGIN_ARGS(setCookies, 0) HTTP_ARG_VAL(cookies, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addCookies, 0, 1) +HTTP_BEGIN_ARGS(addCookies, 1) HTTP_ARG_VAL(cookies, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getUrl, 0); -HTTP_BEGIN_ARGS(setUrl, 0, 1) +HTTP_EMPTY_ARGS(getUrl); +HTTP_BEGIN_ARGS(setUrl, 1) HTTP_ARG_VAL(url, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getMethod, 0); -HTTP_BEGIN_ARGS(setMethod, 0, 1) +HTTP_EMPTY_ARGS(getMethod); +HTTP_BEGIN_ARGS(setMethod, 1) HTTP_ARG_VAL(request_method, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getContentType, 0); -HTTP_BEGIN_ARGS(setContentType, 0, 1) +HTTP_EMPTY_ARGS(getContentType); +HTTP_BEGIN_ARGS(setContentType, 1) HTTP_ARG_VAL(content_type, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getQueryData, 0); -HTTP_BEGIN_ARGS(setQueryData, 0, 0) +HTTP_EMPTY_ARGS(getQueryData); +HTTP_BEGIN_ARGS(setQueryData, 0) HTTP_ARG_VAL(query_data, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addQueryData, 0, 1) +HTTP_BEGIN_ARGS(addQueryData, 1) HTTP_ARG_VAL(query_data, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getPostFields, 0); -HTTP_BEGIN_ARGS(setPostFields, 0, 0) +HTTP_EMPTY_ARGS(getPostFields); +HTTP_BEGIN_ARGS(setPostFields, 0) HTTP_ARG_VAL(post_fields, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addPostFields, 0, 1) +HTTP_BEGIN_ARGS(addPostFields, 1) HTTP_ARG_VAL(post_fields, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getPostFiles, 0); -HTTP_BEGIN_ARGS(setPostFiles, 0, 0) +HTTP_EMPTY_ARGS(getPostFiles); +HTTP_BEGIN_ARGS(setPostFiles, 0) HTTP_ARG_VAL(post_files, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addPostFile, 0, 2) +HTTP_BEGIN_ARGS(addPostFile, 2) HTTP_ARG_VAL(formname, 0) HTTP_ARG_VAL(filename, 0) HTTP_ARG_VAL(content_type, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getRawPostData, 0); -HTTP_BEGIN_ARGS(setRawPostData, 0, 0) +HTTP_EMPTY_ARGS(getRawPostData); +HTTP_BEGIN_ARGS(setRawPostData, 0) HTTP_ARG_VAL(raw_post_data, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(addRawPostData, 0, 1) +HTTP_BEGIN_ARGS(addRawPostData, 1) HTTP_ARG_VAL(raw_post_data, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getPutFile, 0); -HTTP_BEGIN_ARGS(setPutFile, 0, 0) +HTTP_EMPTY_ARGS(getPutFile); +HTTP_BEGIN_ARGS(setPutFile, 0) HTTP_ARG_VAL(filename, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getResponseData, 0); -HTTP_BEGIN_ARGS(getResponseHeader, 0, 0) +HTTP_EMPTY_ARGS(getResponseData); +HTTP_BEGIN_ARGS(getResponseHeader, 0) HTTP_ARG_VAL(name, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(getResponseCookie, 0, 0) +HTTP_BEGIN_ARGS(getResponseCookie, 0) HTTP_ARG_VAL(name, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getResponseBody, 0); -HTTP_EMPTY_ARGS(getResponseCode, 0); -HTTP_BEGIN_ARGS(getResponseInfo, 0, 0) +HTTP_EMPTY_ARGS(getResponseBody); +HTTP_EMPTY_ARGS(getResponseCode); +HTTP_EMPTY_ARGS(getResponseStatus); +HTTP_BEGIN_ARGS(getResponseInfo, 0) HTTP_ARG_VAL(name, 0) HTTP_END_ARGS; -HTTP_EMPTY_ARGS(getResponseMessage, 0); -HTTP_EMPTY_ARGS(getRawResponseMessage, 0); -HTTP_EMPTY_ARGS(getRequestMessage, 0); -HTTP_EMPTY_ARGS(getRawRequestMessage, 0); -HTTP_EMPTY_ARGS(getHistory, 0); -HTTP_EMPTY_ARGS(clearHistory, 0); -HTTP_EMPTY_ARGS(send, 0); +HTTP_EMPTY_ARGS(getResponseMessage); +HTTP_EMPTY_ARGS(getRawResponseMessage); +HTTP_EMPTY_ARGS(getRequestMessage); +HTTP_EMPTY_ARGS(getRawRequestMessage); +HTTP_EMPTY_ARGS(getHistory); +HTTP_EMPTY_ARGS(clearHistory); +HTTP_EMPTY_ARGS(send); -HTTP_BEGIN_ARGS(get, 0, 1) +HTTP_BEGIN_ARGS(get, 1) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(head, 0, 1) +HTTP_BEGIN_ARGS(head, 1) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(postData, 0, 2) +HTTP_BEGIN_ARGS(postData, 2) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(data, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(postFields, 0, 2) +HTTP_BEGIN_ARGS(postFields, 2) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(data, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(putFile, 0, 2) +HTTP_BEGIN_ARGS(putFile, 2) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(file, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(putStream, 0, 2) +HTTP_BEGIN_ARGS(putStream, 2) HTTP_ARG_VAL(url, 0) HTTP_ARG_VAL(stream, 0) HTTP_ARG_VAL(options, 0) HTTP_ARG_VAL(info, 1) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(methodRegister, 0, 1) +HTTP_BEGIN_ARGS(methodRegister, 1) HTTP_ARG_VAL(method_name, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(methodUnregister, 0, 1) +HTTP_BEGIN_ARGS(methodUnregister, 1) HTTP_ARG_VAL(method, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(methodName, 0, 1) +HTTP_BEGIN_ARGS(methodName, 1) HTTP_ARG_VAL(method_id, 0) HTTP_END_ARGS; -HTTP_BEGIN_ARGS(methodExists, 0, 1) +HTTP_BEGIN_ARGS(methodExists, 1) HTTP_ARG_VAL(method, 0) HTTP_END_ARGS; #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C) static inline void _http_request_object_declare_default_properties(TSRMLS_D); +#define OBJ_PROP_CE http_request_object_ce zend_class_entry *http_request_object_ce; zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) @@ -221,6 +221,7 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC) + HTTP_REQUEST_ME(addSslOptions, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(addHeaders, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getHeaders, ZEND_ACC_PUBLIC) @@ -264,6 +265,7 @@ zend_function_entry http_request_object_fe[] = { HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getResponseCookie, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC) + HTTP_REQUEST_ME(getResponseStatus, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC) HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC) @@ -298,7 +300,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) @@ -333,7 +335,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); @@ -354,6 +359,7 @@ static inline void _http_request_object_declare_default_properties(TSRMLS_D) DCL_PROP_N(PRIVATE, responseData); DCL_PROP_N(PRIVATE, responseMessage); DCL_PROP(PRIVATE, long, responseCode, 0); + DCL_PROP(PRIVATE, string, responseStatus, ""); DCL_PROP(PRIVATE, long, method, HTTP_GET); DCL_PROP(PRIVATE, string, url, ""); DCL_PROP(PRIVATE, string, contentType, ""); @@ -399,6 +405,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 */ @@ -427,11 +438,11 @@ 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(obj, url))); + obj->request->url = http_absolute_url(Z_STRVAL_P(GET_PROP(url))); - switch (obj->request->meth = Z_LVAL_P(GET_PROP(obj, method))) + switch (obj->request->meth = Z_LVAL_P(GET_PROP(method))) { case HTTP_GET: case HTTP_HEAD: @@ -440,10 +451,10 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ case HTTP_PUT: { php_stream_statbuf ssb; - php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(obj, putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL); + php_stream *stream = php_stream_open_wrapper(Z_STRVAL_P(GET_PROP(putFile)), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL); if (stream && !php_stream_stat(stream, &ssb)) { - http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1); + obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1); } else { status = FAILURE; } @@ -454,15 +465,17 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ default: { /* check for raw post data */ - zval *raw_data = GET_PROP(obj, rawPostData); + zval *raw_data = GET_PROP(rawPostData); if (Z_STRLEN_P(raw_data)) { - zval *ctype = GET_PROP(obj, contentType); + zval *ctype = GET_PROP(contentType); if (Z_STRLEN_P(ctype)) { - zval **headers, *opts = GET_PROP(obj, options); + zval **headers, *opts = GET_PROP(options); - if ((SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && (Z_TYPE_PP(headers) == IS_ARRAY)) { + if ( (Z_TYPE_P(opts) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) && + (Z_TYPE_PP(headers) == IS_ARRAY)) { zval **ct_header; /* only override if not already set */ @@ -475,7 +488,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ MAKE_STD_ZVAL(headers); array_init(headers); add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1); - add_assoc_zval(opts, "headers", headers); + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers); + zval_ptr_dtor(&headers); } } @@ -483,15 +497,17 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1); } else { - zval *zfields = GET_PROP(obj, postFields), *zfiles = GET_PROP(obj, postFiles); + zval *zfields = GET_PROP(postFields), *zfiles = GET_PROP(postFiles); HashTable *fields; HashTable *files; 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; + } } } } @@ -499,8 +515,8 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ } if (status == SUCCESS) { - zval *qdata = GET_PROP(obj, queryData); - zval *options = GET_PROP(obj, options); + zval *qdata = GET_PROP(queryData); + zval *options = GET_PROP(options); if (Z_STRLEN_P(qdata)) { if (!strchr(obj->request->url, '?')) { @@ -512,6 +528,23 @@ STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ } http_request_prepare(obj->request, Z_ARRVAL_P(options)); + + /* check if there's a onProgress method and add it as progress callback if one isn't already set */ + if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onprogress", sizeof("onprogress"))) { + zval **entry, *pcb; + + if ( (Z_TYPE_P(options) != IS_ARRAY) + || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void **) &entry) + || (!zval_is_true(*entry)))) { + MAKE_STD_ZVAL(pcb); + array_init(pcb); + ZVAL_ADDREF(getThis()); + add_next_index_zval(pcb, getThis()); + add_next_index_stringl(pcb, "onprogress", lenof("onprogress"), 1); + http_request_set_progress_callback(obj->request, pcb); + zval_ptr_dtor(&pcb); + } + } } return status; @@ -533,7 +566,7 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this size_t body_len; zval *headers, *message, *resp, *info; - if (zval_is_true(GET_PROP(obj, recordHistory))) { + if (zval_is_true(GET_PROP(recordHistory))) { /* we need to act like a zipper, as we'll receive * the requests and the responses in separate chains * for redirects @@ -559,7 +592,8 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this phpstr_fix(&obj->history); } - UPD_PROP(obj, long, responseCode, msg->http.info.response.code); + UPD_PROP(long, responseCode, msg->http.info.response.code); + UPD_PROP(string, responseStatus, msg->http.info.response.status); MAKE_STD_ZVAL(resp); array_init(resp); @@ -569,20 +603,24 @@ STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this add_assoc_zval(resp, "headers", headers); phpstr_data(PHPSTR(msg), &body, &body_len); add_assoc_stringl(resp, "body", body, body_len, 0); - SET_PROP(obj, responseData, resp); + SET_PROP(responseData, resp); zval_ptr_dtor(&resp); MAKE_STD_ZVAL(message); - ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL)); - SET_PROP(obj, responseMessage, message); + ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL), 0); + SET_PROP(responseMessage, message); zval_ptr_dtor(&message); MAKE_STD_ZVAL(info); array_init(info); http_request_info(obj->request, Z_ARRVAL_P(info)); - SET_PROP(obj, responseInfo, info); + SET_PROP(responseInfo, info); zval_ptr_dtor(&info); - + + if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) { + zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL); + } + return SUCCESS; } } @@ -591,8 +629,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; @@ -600,7 +637,7 @@ static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM MAKE_STD_ZVAL(new_opts); array_init(new_opts); - old_opts = GET_PROP(obj, options); + old_opts = GET_PROP(options); if (Z_TYPE_P(old_opts) == IS_ARRAY) { array_copy(old_opts, new_opts); } @@ -620,7 +657,7 @@ static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM ZVAL_ADDREF(opts); add_assoc_zval(new_opts, key, opts); } - SET_PROP(obj, options, new_opts); + SET_PROP(options, new_opts); zval_ptr_dtor(&new_opts); RETURN_TRUE; @@ -634,13 +671,12 @@ 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(obj, options); + opts = GET_PROP(options); 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); } @@ -655,7 +691,7 @@ static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, * Instantiate a new HttpRequest object. * * Accepts a string as optional parameter containing the target request url. - * Additianally accepts an optional int parameter specifying the request method + * Additionally accepts an optional int parameter specifying the request method * to use and an associative array as optional third parameter which will be * passed to HttpRequest::setOptions(). * @@ -667,15 +703,14 @@ 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)) { if (URL) { - UPD_STRL(obj, url, URL, URL_len); + UPD_STRL(url, URL, URL_len); } if (meth > -1) { - UPD_PROP(obj, long, method, meth); + UPD_PROP(long, method, meth); } if (options) { zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options); @@ -689,9 +724,9 @@ PHP_METHOD(HttpRequest, __construct) * * Set the request options to use. See http_get() for a full list of available options. * - * Accepts an array as optional parameters, wich values will overwrite the - * currently set request options. If the parameter is empty or mitted, - * the optoions of the HttpRequest object will be reset. + * Accepts an array as optional parameters, which values will overwrite the + * currently set request options. If the parameter is empty or omitted, + * the options of the HttpRequest object will be reset. * * Returns TRUE on success, or FALSE on failure. */ @@ -700,8 +735,7 @@ PHP_METHOD(HttpRequest, setOptions) char *key = NULL; ulong idx = 0; HashPosition pos; - zval *opts = NULL, *old_opts, *new_opts, **opt; - getObject(http_request_object, obj); + zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) { RETURN_FALSE; @@ -711,62 +745,43 @@ PHP_METHOD(HttpRequest, setOptions) array_init(new_opts); if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) { - SET_PROP(obj, options, new_opts); + SET_PROP(options, new_opts); + zval_ptr_dtor(&new_opts); RETURN_TRUE; } - - old_opts = GET_PROP(obj, options); - if (Z_TYPE_P(old_opts) == IS_ARRAY) { - array_copy(old_opts, new_opts); - } + MAKE_STD_ZVAL(add_opts); + array_init(add_opts); /* some options need extra attention -- thus cannot use array_merge() directly */ FOREACH_KEYVAL(pos, opts, key, idx, opt) { if (key) { if (!strcmp(key, "headers")) { - zval **headers; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), "headers", sizeof("headers"), (void **) &headers)) { - convert_to_array_ex(opt); - convert_to_array(*headers); - array_merge(*opt, *headers); - continue; - } + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, *opt); } else if (!strcmp(key, "cookies")) { - zval **cookies; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), "cookies", sizeof("cookies"), (void **) &cookies)) { - convert_to_array_ex(opt); - convert_to_array(*cookies); - array_merge(*opt, *cookies); - continue; - } + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addcookies", NULL, *opt); } else if (!strcmp(key, "ssl")) { - zval **ssl; - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), "ssl", sizeof("ssl"), (void **) &ssl)) { - convert_to_array_ex(opt); - convert_to_array(*ssl); - array_merge(*opt, *ssl); - continue; - } - } else if ((Z_TYPE_PP(opt) == IS_STRING) && ((!strcasecmp(key, "url")) || (!strcasecmp(key, "uri")))) { - UPD_STRL(obj, url, Z_STRVAL_PP(opt), Z_STRLEN_PP(opt)); - continue; + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addssloptions", NULL, *opt); + } else if ((!strcasecmp(key, "url")) || (!strcasecmp(key, "uri"))) { + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt); } else if (!strcmp(key, "method")) { - if (Z_TYPE_PP(opt) != IS_LONG) { - convert_to_long_ex(opt); - } - UPD_PROP(obj, long, method, Z_LVAL_PP(opt)); - continue; + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt); + } else { + ZVAL_ADDREF(*opt); + add_assoc_zval(add_opts, key, *opt); } - - ZVAL_ADDREF(*opt); - add_assoc_zval(new_opts, key, *opt); - /* reset */ key = NULL; } } - SET_PROP(obj, options, new_opts); + + old_opts = GET_PROP(options); + if (Z_TYPE_P(old_opts) == IS_ARRAY) { + array_copy(old_opts, new_opts); + } + array_merge(add_opts, new_opts); + SET_PROP(options, new_opts); zval_ptr_dtor(&new_opts); + zval_ptr_dtor(&add_opts); RETURN_TRUE; } @@ -783,10 +798,7 @@ PHP_METHOD(HttpRequest, getOptions) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *options = GET_PROP(obj, options); - - RETURN_ZVAL(options, 1, 0); + RETURN_PROP(options); } } /* }}} */ @@ -836,7 +848,7 @@ PHP_METHOD(HttpRequest, getSslOptions) * * Add request header name/value pairs. * - * Expects an ssociative array as parameter containing additional header + * Expects an associative array as parameter containing additional header * name/value pairs. * * Returns TRUE on success, or FALSE on failure. @@ -927,13 +939,12 @@ 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; } - UPD_STRL(obj, url, URL, URL_len); + UPD_STRL(url, URL, URL_len); RETURN_TRUE; } /* }}} */ @@ -949,10 +960,7 @@ PHP_METHOD(HttpRequest, getUrl) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *url = GET_PROP(obj, url); - - RETURN_ZVAL(url, 1, 0); + RETURN_PROP(url); } } /* }}} */ @@ -969,13 +977,12 @@ 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; } - UPD_PROP(obj, long, method, meth); + UPD_PROP(long, method, meth); RETURN_TRUE; } /* }}} */ @@ -991,10 +998,7 @@ PHP_METHOD(HttpRequest, getMethod) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *method = GET_PROP(obj, method); - - RETURN_ZVAL(method, 1, 0); + RETURN_PROP(method); } } /* }}} */ @@ -1013,14 +1017,13 @@ PHP_METHOD(HttpRequest, setContentType) { char *ctype; int ct_len; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) { RETURN_FALSE; } HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE); - UPD_STRL(obj, contentType, ctype, ct_len); + UPD_STRL(contentType, ctype, ct_len); RETURN_TRUE; } /* }}} */ @@ -1036,10 +1039,7 @@ PHP_METHOD(HttpRequest, getContentType) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *ctype = GET_PROP(obj, contentType); - - RETURN_ZVAL(ctype, 1, 0); + RETURN_PROP(contentType); } } /* }}} */ @@ -1058,14 +1058,13 @@ PHP_METHOD(HttpRequest, getContentType) PHP_METHOD(HttpRequest, setQueryData) { zval *qdata = NULL; - getObject(http_request_object, obj); if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) { RETURN_FALSE; } if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) { - UPD_STRL(obj, queryData, "", 0); + UPD_STRL(queryData, "", 0); } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) { char *query_data = NULL; @@ -1073,13 +1072,13 @@ PHP_METHOD(HttpRequest, setQueryData) RETURN_FALSE; } - UPD_PROP(obj, string, queryData, query_data); + UPD_PROP(string, queryData, query_data); efree(query_data); } else { zval *orig = qdata; convert_to_string_ex(&qdata); - UPD_STRL(obj, queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata)); + UPD_STRL(queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata)); if (orig != qdata) { zval_ptr_dtor(&qdata); } @@ -1099,10 +1098,7 @@ PHP_METHOD(HttpRequest, getQueryData) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *qdata = GET_PROP(obj, queryData); - - RETURN_ZVAL(qdata, 1, 0); + RETURN_PROP(queryData); } } /* }}} */ @@ -1121,19 +1117,18 @@ 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; } - old_qdata = GET_PROP(obj, queryData); + old_qdata = GET_PROP(queryData); if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) { RETURN_FALSE; } - UPD_STRL(obj, queryData, query_data, query_data_len); + UPD_STRL(queryData, query_data, query_data_len); efree(query_data); RETURN_TRUE; @@ -1153,7 +1148,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; @@ -1162,12 +1156,12 @@ PHP_METHOD(HttpRequest, addPostFields) if (zend_hash_num_elements(Z_ARRVAL_P(post_data))) { MAKE_STD_ZVAL(new_post); array_init(new_post); - old_post = GET_PROP(obj, postFields); + old_post = GET_PROP(postFields); if (Z_TYPE_P(old_post) == IS_ARRAY) { array_copy(old_post, new_post); } array_merge(post_data, new_post); - SET_PROP(obj, postFields, new_post); + SET_PROP(postFields, new_post); zval_ptr_dtor(&new_post); } @@ -1188,7 +1182,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; @@ -1199,7 +1192,7 @@ PHP_METHOD(HttpRequest, setPostFields) if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) { array_copy(post_data, post); } - SET_PROP(obj, postFields, post); + SET_PROP(postFields, post); zval_ptr_dtor(&post); RETURN_TRUE; @@ -1217,10 +1210,7 @@ PHP_METHOD(HttpRequest, getPostFields) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *post = GET_PROP(obj, postFields); - - RETURN_ZVAL(post, 1, 0); + RETURN_PROP(postFields); } } /* }}} */ @@ -1241,7 +1231,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; @@ -1251,7 +1240,7 @@ PHP_METHOD(HttpRequest, setRawPostData) raw_data = ""; } - UPD_STRL(obj, rawPostData, raw_data, data_len); + UPD_STRL(rawPostData, raw_data, data_len); RETURN_TRUE; } /* }}} */ @@ -1269,25 +1258,19 @@ 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; } if (data_len) { - zval *data, *zdata = GET_PROP(obj, rawPostData); + zval *data = zval_copy(IS_STRING, GET_PROP(rawPostData)); - ALLOC_ZVAL(data); - *data = *zdata; - zval_copy_ctor(data); - INIT_PZVAL(data); - convert_to_string(data); Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1); Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0'; memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len); - SET_PROP(obj, rawPostData, data); - zval_ptr_dtor(&data); + SET_PROP(rawPostData, data); + zval_free(&data); } RETURN_TRUE; @@ -1305,22 +1288,19 @@ PHP_METHOD(HttpRequest, getRawPostData) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *post = GET_PROP(obj, rawPostData); - - RETURN_ZVAL(post, 1, 0); + RETURN_PROP(rawPostData); } } /* }}} */ /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"]) * - * Add a file to the POST request, leaving prefiously set files unchanged. + * Add a file to the POST request, leaving previously set files unchanged. * Affects only POST and custom requests. Cannot be used with raw post data. * * Expects a string parameter containing the form element name, and a string * paremeter containing the path to the file which should be uploaded. - * Additionally accepts an optional string parameter which chould contain + * Additionally accepts an optional string parameter which should contain * the content type of the file. * * Returns TRUE on success, or FALSE if the content type seems not to contain a @@ -1331,7 +1311,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; @@ -1353,12 +1332,12 @@ PHP_METHOD(HttpRequest, addPostFile) MAKE_STD_ZVAL(new_post); array_init(new_post); - old_post = GET_PROP(obj, postFiles); + old_post = GET_PROP(postFiles); if (Z_TYPE_P(old_post) == IS_ARRAY) { array_copy(old_post, new_post); } add_next_index_zval(new_post, entry); - SET_PROP(obj, postFiles, new_post); + SET_PROP(postFiles, new_post); zval_ptr_dtor(&new_post); RETURN_TRUE; @@ -1379,7 +1358,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; @@ -1390,7 +1368,8 @@ PHP_METHOD(HttpRequest, setPostFiles) if (files && (Z_TYPE_P(files) == IS_ARRAY)) { array_copy(files, post); } - SET_PROP(obj, postFiles, post); + SET_PROP(postFiles, post); + zval_ptr_dtor(&post); RETURN_TRUE; } @@ -1407,10 +1386,7 @@ PHP_METHOD(HttpRequest, getPostFiles) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - - array_init(return_value); - array_copy(GET_PROP(obj, postFiles), return_value); + RETURN_PROP(postFiles); } } /* }}} */ @@ -1428,13 +1404,12 @@ 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; } - UPD_STRL(obj, putFile, file, file_len); + UPD_STRL(putFile, file, file_len); RETURN_TRUE; } /* }}} */ @@ -1450,10 +1425,7 @@ PHP_METHOD(HttpRequest, getPutFile) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *file = GET_PROP(obj, putFile); - - RETVAL_ZVAL(file, 1, 0); + RETURN_PROP(putFile); } } /* }}} */ @@ -1463,7 +1435,7 @@ PHP_METHOD(HttpRequest, getPutFile) * Get all response data after the request has been sent. * * Returns an associative array with the key "headers" containing an associative - * array holding all response headers, as well as the ley "body" containing a + * array holding all response headers, as well as the key "body" containing a * string with the response body. * * If redirects were allowed and several responses were received, the data @@ -1474,10 +1446,7 @@ PHP_METHOD(HttpRequest, getResponseData) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - - array_init(return_value); - array_copy(GET_PROP(obj, responseData), return_value); + RETURN_PROP(responseData); } } /* }}} */ @@ -1490,7 +1459,7 @@ PHP_METHOD(HttpRequest, getResponseData) * If the parameter is empty or omitted all response headers will be returned. * * Returns either a string with the value of the header matching name if requested, - * FALSE on failure, or an associative array containing all reponse headers. + * FALSE on failure, or an associative array containing all response headers. * * If redirects were allowed and several responses were received, the data * references the last received response. @@ -1501,15 +1470,15 @@ 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; } - data = GET_PROP(obj, responseData); - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) { - convert_to_array(*headers); + data = GET_PROP(responseData); + if ( (Z_TYPE_P(data) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) && + (Z_TYPE_PP(headers) == IS_ARRAY)) { if (!header_len || !header_name) { RETVAL_ZVAL(*headers, 1, 0); } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void **) &header)) { @@ -1545,7 +1514,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; @@ -1553,8 +1521,10 @@ PHP_METHOD(HttpRequest, getResponseCookie) array_init(return_value); - data = GET_PROP(obj, responseData); - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) { + data = GET_PROP(responseData); + if ( (Z_TYPE_P(data) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) && + (Z_TYPE_PP(headers) == IS_ARRAY)) { ulong idx = 0; char *key = NULL; zval **header = NULL; @@ -1644,10 +1614,10 @@ PHP_METHOD(HttpRequest, getResponseBody) IF_RETVAL_USED { zval **body; - getObject(http_request_object, obj); - zval *data = GET_PROP(obj, responseData); + zval *data = GET_PROP(responseData); - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body)) { + if ( (Z_TYPE_P(data) == IS_ARRAY) && + (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void **) &body))) { RETURN_ZVAL(*body, 1, 0); } else { RETURN_FALSE; @@ -1670,10 +1640,23 @@ PHP_METHOD(HttpRequest, getResponseCode) NO_ARGS; IF_RETVAL_USED { - getObject(http_request_object, obj); - zval *code = GET_PROP(obj, responseCode); - - RETVAL_ZVAL(code, 1, 0); + RETURN_PROP(responseCode); + } +} +/* }}} */ + +/* {{{ proto string HttpRequest::getResponseStatus() + * + * Get the response status (i.e. the string after the response code) after the message has been sent. + * + * Returns a string containing the response status text. + */ +PHP_METHOD(HttpRequest, getResponseStatus) +{ + NO_ARGS; + + IF_RETVAL_USED { + RETURN_PROP(responseStatus); } } /* }}} */ @@ -1700,13 +1683,16 @@ 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; } - info = GET_PROP(obj, responseInfo); + info = GET_PROP(responseInfo); + + if (Z_TYPE_P(info) != IS_ARRAY) { + RETURN_FALSE; + } if (info_len && info_name) { if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) { @@ -1730,7 +1716,7 @@ PHP_METHOD(HttpRequest, getResponseInfo) * * If redirects were allowed and several responses were received, the data * references the last received response. Use HttpMessage::getParentMessage() - * to access the data of previously received responses whithin this request + * to access the data of previously received responses within this request * cycle. * * Throws HttpException. @@ -1741,12 +1727,11 @@ PHP_METHOD(HttpRequest, getResponseMessage) IF_RETVAL_USED { zval *message; - getObject(http_request_object, obj); SET_EH_THROW_HTTP(); - message = GET_PROP(obj, responseMessage); + message = GET_PROP(responseMessage); if (Z_TYPE_P(message) == IS_OBJECT) { - RETVAL_OBJECT(message); + RETVAL_OBJECT(message, 1); } else { RETVAL_NULL(); } @@ -1763,7 +1748,7 @@ PHP_METHOD(HttpRequest, getResponseMessage) * * If redirects were allowed and several responses were received, the data * references the last received response. Use HttpMessage::getParentMessage() - * to access the data of previously sent requests whithin this request + * to access the data of previously sent requests within this request * cycle. * * Note that the internal request message is immutable, that means that the @@ -1783,7 +1768,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(); } @@ -1833,7 +1818,7 @@ PHP_METHOD(HttpRequest, getRawResponseMessage) * Get all sent requests and received responses as an HttpMessage object. * * If you don't want to record history at all, set the instance variable - * HttpRequest::$recoedHistory to FALSE. + * HttpRequest::$recordHistory to FALSE. * * Returns an HttpMessage object representing the complete request/response * history. @@ -1857,7 +1842,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(); } @@ -1937,7 +1922,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(obj, responseMessage)); + RETVAL_OBJECT(GET_PROP(responseMessage), 1); } }