| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-2005, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
/* $Id$ */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
#define HTTP_WANT_CURL
#include "php_http.h"
#include "zend_interfaces.h"
#include "php_http_api.h"
+#include "php_http_cookie_api.h"
#include "php_http_exception_object.h"
#include "php_http_message_api.h"
#include "php_http_message_object.h"
#include "php_http_request_pool_api.h"
#include "php_http_url_api.h"
-#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_ARG_VAL(name, 0)
+HTTP_BEGIN_ARGS(getResponseCookies, 0)
+ HTTP_ARG_VAL(flags, 0)
+ HTTP_ARG_VAL(allowed_extras, 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)
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)
HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC)
- HTTP_REQUEST_ME(getResponseCookie, ZEND_ACC_PUBLIC)
+ HTTP_REQUEST_ME(getResponseCookies, 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)
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)
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);
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, "");
/* 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
*/
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:
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;
}
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 */
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);
}
}
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;
+ }
}
}
}
}
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, '?')) {
}
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;
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
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);
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;
}
}
_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;
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);
}
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;
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);
}
* 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().
*
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);
*
* 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.
*/
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;
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;
}
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *options = GET_PROP(obj, options);
-
- RETURN_ZVAL(options, 1, 0);
+ RETURN_PROP(options);
}
}
/* }}} */
*
* 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.
{
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;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *url = GET_PROP(obj, url);
-
- RETURN_ZVAL(url, 1, 0);
+ RETURN_PROP(url);
}
}
/* }}} */
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;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *method = GET_PROP(obj, method);
-
- RETURN_ZVAL(method, 1, 0);
+ RETURN_PROP(method);
}
}
/* }}} */
{
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;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *ctype = GET_PROP(obj, contentType);
-
- RETURN_ZVAL(ctype, 1, 0);
+ RETURN_PROP(contentType);
}
}
/* }}} */
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;
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);
}
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *qdata = GET_PROP(obj, queryData);
-
- RETURN_ZVAL(qdata, 1, 0);
+ RETURN_PROP(queryData);
}
}
/* }}} */
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;
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;
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);
}
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;
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;
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *post = GET_PROP(obj, postFields);
-
- RETURN_ZVAL(post, 1, 0);
+ RETURN_PROP(postFields);
}
}
/* }}} */
{
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;
raw_data = "";
}
- UPD_STRL(obj, rawPostData, raw_data, data_len);
+ UPD_STRL(rawPostData, raw_data, data_len);
RETURN_TRUE;
}
/* }}} */
{
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;
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
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;
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;
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;
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;
}
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);
}
}
/* }}} */
{
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;
}
/* }}} */
NO_ARGS;
IF_RETVAL_USED {
- getObject(http_request_object, obj);
- zval *file = GET_PROP(obj, putFile);
-
- RETVAL_ZVAL(file, 1, 0);
+ RETURN_PROP(putFile);
}
}
/* }}} */
* 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
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);
}
}
/* }}} */
* 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.
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)) {
}
/* }}} */
-/* {{{ proto array HttpRequest::getResponseCookie([string name])
+/* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
*
* Get response cookie(s) after the request has been sent.
*
- * Accepts a string as optional parameter specifying the name of the cookie to read.
- * If the parameter is empty or omitted, an associative array with all received
- * cookies will be returned.
- *
- * Returns either an associative array with the cookie's name, value and any
- * additional params of the cookie matching name if requested, FALSE on failure,
- * or an array containing all received cookies as arrays.
+ * Returns an array of stdClass objects like http_parse_cookie would return.
*
* If redirects were allowed and several responses were received, the data
* references the last received response.
*/
-PHP_METHOD(HttpRequest, getResponseCookie)
+PHP_METHOD(HttpRequest, getResponseCookies)
{
IF_RETVAL_USED {
- zval *data, **headers;
- char *cookie_name = NULL;
- int cookie_len = 0;
- getObject(http_request_object, obj);
+ long flags = 0;
+ zval *allowed_extras_array = NULL, *data, **headers;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &cookie_name, &cookie_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la", &flags, &allowed_extras_array)) {
RETURN_FALSE;
}
- 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)) {
+ int i = 0;
ulong idx = 0;
- char *key = NULL;
- zval **header = NULL;
- HashPosition pos1;
-
+ char *key = NULL, **allowed_extras = NULL;
+ zval **header = NULL, **entry = NULL;
+ HashPosition pos, pos1, pos2;
+
+ array_init(return_value);
+
+ if (allowed_extras_array) {
+ allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
+ FOREACH_VAL(pos, allowed_extras_array, entry) {
+ ZVAL_ADDREF(*entry);
+ convert_to_string_ex(entry);
+ allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
+ zval_ptr_dtor(entry);
+ }
+ }
+
convert_to_array(*headers);
FOREACH_HASH_KEYVAL(pos1, Z_ARRVAL_PP(headers), key, idx, header) {
if (key && !strcasecmp(key, "Set-Cookie")) {
- /* several cookies? */
+ http_cookie_list list;
+
if (Z_TYPE_PP(header) == IS_ARRAY) {
- zval **cookie;
- HashPosition pos2;
-
- FOREACH_HASH_VAL(pos2, Z_ARRVAL_PP(header), cookie) {
- zval *cookie_hash;
- MAKE_STD_ZVAL(cookie_hash);
- array_init(cookie_hash);
-
- if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(cookie), Z_ARRVAL_P(cookie_hash))) {
- if (!cookie_len) {
- add_next_index_zval(return_value, cookie_hash);
- } else {
- zval **name;
-
- if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
- (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
- add_next_index_zval(return_value, cookie_hash);
- return; /* <<< FOUND >>> */
- } else {
- zval_dtor(cookie_hash);
- efree(cookie_hash);
- }
- }
- } else {
- zval_dtor(cookie_hash);
- efree(cookie_hash);
+ zval **single_header;
+ HashPosition pos;
+
+ FOREACH_VAL(pos2, *header, single_header) {
+ ZVAL_ADDREF(*single_header);
+ convert_to_string_ex(single_header);
+ if (http_parse_cookie_ex(&list, Z_STRVAL_PP(single_header), flags, allowed_extras)) {
+ zval *cookie;
+
+ MAKE_STD_ZVAL(cookie);
+ object_init(cookie);
+ http_cookie_list_tostruct(&list, cookie);
+ add_next_index_zval(return_value, cookie);
+ http_cookie_list_dtor(&list);
}
+ zval_ptr_dtor(single_header);
}
} else {
- zval *cookie_hash;
-
- MAKE_STD_ZVAL(cookie_hash);
- array_init(cookie_hash);
+ ZVAL_ADDREF(*header);
convert_to_string_ex(header);
-
- if (SUCCESS == http_parse_cookie(Z_STRVAL_PP(header), Z_ARRVAL_P(cookie_hash))) {
- if (!cookie_len) {
- add_next_index_zval(return_value, cookie_hash);
- } else {
- zval **name;
-
- if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(cookie_hash), "name", sizeof("name"), (void **) &name)) &&
- (!strcmp(Z_STRVAL_PP(name), cookie_name))) {
- add_next_index_zval(return_value, cookie_hash);
- } else {
- zval_dtor(cookie_hash);
- efree(cookie_hash);
- }
- }
- } else {
- zval_dtor(cookie_hash);
- efree(cookie_hash);
+ if (http_parse_cookie_ex(&list, Z_STRVAL_PP(header), flags, allowed_extras)) {
+ zval *cookie;
+
+ MAKE_STD_ZVAL(cookie);
+ object_init(cookie);
+ http_cookie_list_tostruct(&list, cookie);
+ add_next_index_zval(return_value, cookie);
+ http_cookie_list_dtor(&list);
}
+ zval_ptr_dtor(header);
}
- break;
}
/* reset key */
key = NULL;
}
+
+ if (allowed_extras) {
+ for (i = 0; allowed_extras[i]; ++i) {
+ efree(allowed_extras[i]);
+ }
+ efree(allowed_extras);
+ }
+ } else {
+ RETURN_FALSE;
}
}
}
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;
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);
}
}
/* }}} */
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)) {
*
* 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.
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();
}
*
* 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
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();
}
* 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.
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();
}
} 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);
}
}