+ STATUS ret;
+ zval *info;
+ http_message *msg;
+
+ /* always fetch info */
+ MAKE_STD_ZVAL(info);
+ array_init(info);
+ http_request_info(obj->request, Z_ARRVAL_P(info));
+ SET_PROP(responseInfo, info);
+ zval_ptr_dtor(&info);
+
+ /* parse response message */
+ phpstr_fix(&obj->request->conv.request);
+ phpstr_fix(&obj->request->conv.response);
+
+ if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)))) {
+ zval *message;
+
+ if (zval_is_true(GET_PROP(recordHistory))) {
+ zval *hist, *history = GET_PROP(history);
+ http_message *response = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
+ http_message *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
+
+ MAKE_STD_ZVAL(hist);
+ ZVAL_OBJVAL(hist, http_message_object_new_ex(http_message_object_ce, http_message_interconnect(response, request), NULL), 0);
+ if (Z_TYPE_P(history) == IS_OBJECT) {
+ http_message_object_prepend(hist, history);
+ }
+ SET_PROP(history, hist);
+ zval_ptr_dtor(&hist);
+ }
+
+ UPD_PROP(long, responseCode, msg->http.info.response.code);
+ UPD_PROP(string, responseStatus, STR_PTR(msg->http.info.response.status));
+
+ MAKE_STD_ZVAL(message);
+ ZVAL_OBJVAL(message, http_message_object_new_ex(http_message_object_ce, msg, NULL), 0);
+ SET_PROP(responseMessage, message);
+ zval_ptr_dtor(&message);
+
+ ret = SUCCESS;
+ } else {
+ /* update properties with empty values*/
+ zval *znull;
+
+ MAKE_STD_ZVAL(znull);
+ ZVAL_NULL(znull);
+ SET_PROP(responseMessage, znull);
+ zval_ptr_dtor(&znull);
+
+ 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;
+ }
+
+ http_request_set_progress_callback(obj->request, NULL);
+
+ 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(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
+ }
+
+ 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(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry));
+ } else {
+ array_join(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry), 0, prettify_keys ? ARRAY_JOIN_PRETTIFY : 0);
+ }
+ }
+ } else if (opts) {
+ if (prettify_keys) {
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(opts), apply_pretty_key, 0);
+ }
+ ZVAL_ADDREF(opts);
+ add_assoc_zval_ex(new_opts, key, len, 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);
+
+ 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(Z_ARRVAL_PP(options), Z_ARRVAL_P(return_value));
+ }
+ }
+}
+
+
+/* ### USERLAND ### */
+
+/* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET[, array options]]])
+ Create a new HttpRequest object instance. */
+PHP_METHOD(HttpRequest, __construct)
+{
+ char *URL = NULL;
+ int URL_len;
+ long meth = -1;
+ zval *options = NULL;
+
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!", &URL, &URL_len, &meth, &options)) {
+ if (URL) {
+ UPD_STRL(url, URL, URL_len);
+ }
+ if (meth > -1) {
+ UPD_PROP(long, method, meth);
+ }
+ if (options) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
+ }
+ }
+ SET_EH_NORMAL();
+}
+/* }}} */
+
+/* {{{ proto HttpRequest HttpRequest::factory([string url[, int request_method HTTP_METH_GET[, array options[, string class_name = "HttpRequest"]]]])
+ Create a new HttpRequest object instance. */
+PHP_METHOD(HttpRequest, factory)
+{
+ char *cn = NULL, *URL = NULL;
+ int cl = 0, URL_len = 0;
+ long meth = -1;
+ zval *options = NULL;
+ zend_object_value ov;
+
+ SET_EH_THROW_HTTP();
+ if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!s", &URL, &URL_len, &meth, &options, &cn, &cl) &&
+ SUCCESS == http_object_new(&ov, cn, cl, _http_request_object_new_ex, http_request_object_ce, NULL, NULL)) {
+ RETVAL_OBJVAL(ov, 0);
+ getThis() = return_value;
+ if (URL) {
+ UPD_STRL(url, URL, URL_len);
+ }
+ if (meth > -1) {
+ UPD_PROP(long, method, meth);
+ }
+ if (options) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
+ }
+ }
+ SET_EH_NORMAL();
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setOptions([array options])
+ Set the request options to use. See http_get() for a full list of available options. */
+PHP_METHOD(HttpRequest, setOptions)
+{
+ HashKey key = initHashKey(0);
+ HashPosition pos;
+ zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(new_opts);
+ array_init(new_opts);
+
+ if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
+ SET_PROP(options, new_opts);
+ zval_ptr_dtor(&new_opts);
+ RETURN_TRUE;
+ }
+
+ 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, opt) {
+ if (key.type == HASH_KEY_IS_STRING) {
+ if (!strcmp(key.str, "headers")) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, *opt);
+ } else if (!strcmp(key.str, "cookies")) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addcookies", NULL, *opt);
+ } else if (!strcmp(key.str, "ssl")) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addssloptions", NULL, *opt);
+ } else if ((!strcasecmp(key.str, "url")) || (!strcasecmp(key.str, "uri"))) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt);
+ } else if (!strcmp(key.str, "method")) {
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt);
+#if HTTP_CURL_VERSION(7,14,1)
+ } else if (!strcmp(key.str, "resetcookies")) {
+ getObject(http_request_object, obj);
+ http_request_reset_cookies(obj->request, 0);
+#endif
+ } else if (!strcmp(key.str, "enablecookies")) {
+ getObject(http_request_object, obj);
+ http_request_enable_cookies(obj->request);
+ } else if (!strcasecmp(key.str, "recordHistory")) {
+ UPD_PROP(bool, recordHistory, 1);
+ } else {
+ ZVAL_ADDREF(*opt);
+ add_assoc_zval_ex(add_opts, key.str, key.len, *opt);
+ }
+ }
+ }
+
+ old_opts = GET_PROP(options);
+ if (Z_TYPE_P(old_opts) == IS_ARRAY) {
+ array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
+ }
+ array_join(Z_ARRVAL_P(add_opts), Z_ARRVAL_P(new_opts), 0, 0);
+ SET_PROP(options, new_opts);
+ zval_ptr_dtor(&new_opts);
+ zval_ptr_dtor(&add_opts);
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getOptions()
+ Get currently set options. */
+PHP_METHOD(HttpRequest, getOptions)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(options);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setSslOptions([array options])
+ Set SSL options. */
+PHP_METHOD(HttpRequest, setSslOptions)
+{
+ http_request_object_set_options_subr("ssl", 1, 0);
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addSslOptions(array options)
+ Set additional SSL options. */
+PHP_METHOD(HttpRequest, addSslOptions)
+{
+ http_request_object_set_options_subr("ssl", 0, 0);
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getSslOtpions()
+ Get previously set SSL options. */
+PHP_METHOD(HttpRequest, getSslOptions)
+{
+ http_request_object_get_options_subr("ssl");
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addHeaders(array headers)
+ Add request header name/value pairs. */
+PHP_METHOD(HttpRequest, addHeaders)
+{
+ http_request_object_set_options_subr("headers", 0, 1);
+}
+
+/* {{{ proto bool HttpRequest::setHeaders([array headers])
+ Set request header name/value pairs. */
+PHP_METHOD(HttpRequest, setHeaders)
+{
+ http_request_object_set_options_subr("headers", 1, 1);
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getHeaders()
+ Get previously set request headers. */
+PHP_METHOD(HttpRequest, getHeaders)
+{
+ http_request_object_get_options_subr("headers");
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setCookies([array cookies])
+ Set cookies. */
+PHP_METHOD(HttpRequest, setCookies)
+{
+ http_request_object_set_options_subr("cookies", 1, 0);
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addCookies(array cookies)
+ Add cookies. */
+PHP_METHOD(HttpRequest, addCookies)
+{
+ http_request_object_set_options_subr("cookies", 0, 0);
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getCookies()
+ Get previously set cookies. */
+PHP_METHOD(HttpRequest, getCookies)
+{
+ http_request_object_get_options_subr("cookies");
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::enableCookies()
+ Enable automatic sending of received cookies. Note that customly set cookies will be sent anyway. */
+PHP_METHOD(HttpRequest, enableCookies)
+{
+ NO_ARGS {
+ getObject(http_request_object, obj);
+ RETURN_SUCCESS(http_request_enable_cookies(obj->request));
+ }
+
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
+ Reset all automatically received/sent cookies. Note that customly set cookies are not affected. */
+PHP_METHOD(HttpRequest, resetCookies)
+{
+ zend_bool session_only = 0;
+ getObject(http_request_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &session_only)) {
+ RETURN_FALSE;
+ }
+ RETURN_SUCCESS(http_request_reset_cookies(obj->request, session_only));
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setUrl(string url)
+ Set the request URL. */
+PHP_METHOD(HttpRequest, setUrl)
+{
+ char *URL = NULL;
+ int URL_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) {
+ RETURN_FALSE;
+ }
+
+ UPD_STRL(url, URL, URL_len);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getUrl()
+ Get the previously set request URL. */
+PHP_METHOD(HttpRequest, getUrl)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(url);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setMethod(int request_method)
+ Set the request method. */
+PHP_METHOD(HttpRequest, setMethod)
+{
+ long meth;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
+ RETURN_FALSE;
+ }
+
+ UPD_PROP(long, method, meth);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto int HttpRequest::getMethod()
+ Get the previously set request method. */
+PHP_METHOD(HttpRequest, getMethod)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(method);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setContentType(string content_type)
+ Set the content type the post request should have. */
+PHP_METHOD(HttpRequest, setContentType)
+{
+ char *ctype;
+ int ct_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) {
+ RETURN_FALSE;
+ }
+
+ if (ct_len) {
+ HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
+ }
+ UPD_STRL(contentType, ctype, ct_len);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getContentType()
+ Get the previously content type. */
+PHP_METHOD(HttpRequest, getContentType)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(contentType);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
+ Set the URL query parameters to use, overwriting previously set query parameters. */
+PHP_METHOD(HttpRequest, setQueryData)
+{
+ zval *qdata = NULL;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
+ RETURN_FALSE;
+ }
+
+ if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
+ UPD_STRL(queryData, "", 0);
+ } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
+ char *query_data = NULL;
+
+ if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) {
+ RETURN_FALSE;
+ }
+
+ UPD_PROP(string, queryData, query_data);
+ efree(query_data);
+ } else {
+ zval *orig = qdata;
+
+ convert_to_string_ex(&qdata);
+ UPD_STRL(queryData, Z_STRVAL_P(qdata), Z_STRLEN_P(qdata));
+ if (orig != qdata) {
+ zval_ptr_dtor(&qdata);
+ }
+ }
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getQueryData()
+ Get the current query data in form of an urlencoded query string. */
+PHP_METHOD(HttpRequest, getQueryData)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(queryData);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addQueryData(array query_params)
+ Add parameters to the query parameter list, leaving previously set unchanged. */
+PHP_METHOD(HttpRequest, addQueryData)
+{
+ zval *qdata, *old_qdata;
+ char *query_data = NULL;
+ size_t query_data_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) {
+ RETURN_FALSE;
+ }
+
+ 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(queryData, query_data, query_data_len);
+ efree(query_data);
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addPostFields(array post_data)
+ Adds POST data entries, leaving previously set unchanged, unless a post entry with the same name already exists. */
+PHP_METHOD(HttpRequest, addPostFields)
+{
+ zval *post_data, *old_post, *new_post;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &post_data)) {
+ RETURN_FALSE;
+ }
+
+ if (zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
+ MAKE_STD_ZVAL(new_post);
+ array_init(new_post);
+ old_post = GET_PROP(postFields);
+ if (Z_TYPE_P(old_post) == IS_ARRAY) {
+ array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
+ }
+ array_join(Z_ARRVAL_P(post_data), Z_ARRVAL_P(new_post), 0, 0);
+ SET_PROP(postFields, new_post);
+ zval_ptr_dtor(&new_post);
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setPostFields([array post_data])
+ Set the POST data entries, overwriting previously set POST data. */
+PHP_METHOD(HttpRequest, setPostFields)
+{
+ zval *post, *post_data = NULL;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &post_data)) {
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(post);
+ array_init(post);
+ if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
+ array_copy(Z_ARRVAL_P(post_data), Z_ARRVAL_P(post));
+ }
+ SET_PROP(postFields, post);
+ zval_ptr_dtor(&post);
+
+ RETURN_TRUE;
+}
+/* }}}*/
+
+/* {{{ proto array HttpRequest::getPostFields()
+ Get previously set POST data. */
+PHP_METHOD(HttpRequest, getPostFields)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ RETURN_PROP(postFields);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setRawPostData([string raw_post_data])
+ Set raw post data to send, overwriting previously set raw post data. Don't forget to specify a content type. */
+PHP_METHOD(HttpRequest, setRawPostData)
+{
+ char *raw_data = NULL;
+ int data_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) {
+ RETURN_FALSE;
+ }
+
+ if (!raw_data) {
+ raw_data = "";
+ }
+
+ UPD_STRL(rawPostData, raw_data, data_len);
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::addRawPostData(string raw_post_data)
+ Add raw post data, leaving previously set raw post data unchanged. */
+PHP_METHOD(HttpRequest, addRawPostData)
+{
+ char *raw_data;
+ int data_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) {
+ RETURN_FALSE;
+ }
+
+ if (data_len) {
+ zval *data = GET_PROP(rawPostData);
+
+ if (Z_STRLEN_P(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);
+ } else {
+ UPD_STRL(putData, raw_data, data_len);
+ }
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getRawPostData()
+ Get previously set raw post data. */
+PHP_METHOD(HttpRequest, getRawPostData)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ 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 previously set files unchanged. */
+PHP_METHOD(HttpRequest, addPostFile)
+{
+ zval *entry, *old_post, *new_post;
+ char *name, *file, *type = NULL;
+ int name_len, file_len, type_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) {
+ RETURN_FALSE;
+ }
+
+ if (type_len) {
+ HTTP_CHECK_CONTENT_TYPE(type, RETURN_FALSE);
+ } else {
+ type = "application/x-octetstream";
+ type_len = sizeof("application/x-octetstream") - 1;
+ }
+
+ MAKE_STD_ZVAL(entry);
+ array_init(entry);
+
+ add_assoc_stringl(entry, "name", name, name_len, 1);
+ add_assoc_stringl(entry, "type", type, type_len, 1);
+ add_assoc_stringl(entry, "file", file, file_len, 1);
+
+ MAKE_STD_ZVAL(new_post);
+ array_init(new_post);
+ old_post = GET_PROP(postFiles);
+ if (Z_TYPE_P(old_post) == IS_ARRAY) {
+ array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
+ }
+ add_next_index_zval(new_post, entry);
+ SET_PROP(postFiles, new_post);
+ zval_ptr_dtor(&new_post);
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HttpRequest::setPostFiles([array post_files])
+ Set files to post, overwriting previously set post files. */
+PHP_METHOD(HttpRequest, setPostFiles)
+{
+ zval *files = NULL, *post;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!/", &files)) {
+ RETURN_FALSE;
+ }
+
+ MAKE_STD_ZVAL(post);
+ array_init(post);
+ if (files && (Z_TYPE_P(files) == IS_ARRAY)) {
+ array_copy(Z_ARRVAL_P(files), Z_ARRVAL_P(post));
+ }
+ SET_PROP(postFiles, post);
+ zval_ptr_dtor(&post);
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getPostFiles()
+ Get all previously added POST files. */
+PHP_METHOD(HttpRequest, getPostFiles)
+{
+ NO_ARGS;