--- /dev/null
+# Throw Exceptions:
+
+* on setters, that return self
+* on getters, that return objects
as libcurl saves the cookies to the file on curl_easy_destroy(),
cookies are not saved until the CURL handle will be recycled.
Thus one would either need to
- * run PHP with http.persistent.handles.limit = 0
- * call http_persistent_handles_clean() every request
- * call $HttpRequest->flushCookies(), which is available
+ * run PHP with raphf.persistent_handles.limit = 0
+ * call raphf\persistent_handles_clean() every request
+ * call $client->flushCookies(), which is available
since libcurl v7.17.1 and does not work with the
procedural API
- Anyway, none of these options is really perfect, so using
- HttpRequestDatashare with cookies enabled is probably the
- best thing to do.
HTTP and Proxy authentication information (username/password) can not be
unset with NULL prior libcurl v7.19.6 and separate options for setting
username and password--which work--are only available since v7.19.6.
* let http_info.request.url be a php_url
* let the message body be a simple query string unless files are added
+* php_http_message_serialize reverses the chain twice; remove that
* revisit error handling
-
\ No newline at end of file
+ * ditch http\Object
+ * interfacize http\Exception
+ * subclass Exceptions
+ * zend_throw_exception
\ No newline at end of file
AC_MSG_RESULT([found: $CURL_CONFIG])
fi
- dnl Debian stable has currently 7.18.2
+ dnl RHEL6: 7.19.7
+ dnl SUSE11: 7.19.7
+ dnl Debian wheezy: 7.26.0
+ dnl Debian sqeeze: 7.21.0
+ dnl Debian ancient 7.18.2
AC_MSG_CHECKING([for curl version >= 7.18.2])
CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
AC_MSG_RESULT([$CURL_VERSION])
php_http_exception.c \
php_http_filter.c \
php_http_header_parser.c \
- php_http_headers.c \
+ php_http_header.c \
php_http_info.c \
php_http_message_body.c \
php_http_message.c \
php_http_filter.h \
php_http.h \
php_http_header_parser.h \
- php_http_headers.h \
+ php_http_header.h \
php_http_info.h \
php_http_message_body.h \
php_http_message.h \
</lead>
<date>2013-08-12</date>
<version>
- <release>2.0.0beta5</release>
+ <release>2.0.0RC1</release>
<api>2.0.0</api>
</version>
<stability>
<notes><![CDATA[
Extended HTTP support. Again. Keep in mind that it's got the major version 2, because it's incompatible with pecl_http v1.
-* Introduces the http namespace.
-* Message bodies have been remodeled to use PHP temporary streams instead of in-memory buffers.
-* The utterly misunderstood HttpResponse class has been reimplemented as http\Env\Response inheriting http\Message.
-* Currently, there's only one Exception class left, http\Exception.
-* Errors triggered by the extension can be configured statically by http\Object::$defaultErrorHandling or inherited http\Object->errorHandling.
-* The request ecosystem has been modularized to support different libraries, though for the moment only libcurl is supported.
+Documentation:
+http://devel-m6w6.rhcloud.com/mdref/http
+
+Code Coverage:
+http://dev.iworks.at/ext-http/lcov/ext/http/
+
]]></notes>
<contents>
<dir name="/">
<file role="src" name="php_http.h"/>
<file role="src" name="php_http_header_parser.c"/>
<file role="src" name="php_http_header_parser.h"/>
- <file role="src" name="php_http_headers.c"/>
- <file role="src" name="php_http_headers.h"/>
+ <file role="src" name="php_http_header.c"/>
+ <file role="src" name="php_http_header.h"/>
<file role="src" name="php_http_info.c"/>
<file role="src" name="php_http_info.h"/>
<file role="src" name="php_http_message_body.c"/>
<file role="test" name="message014.phpt"/>
<file role="test" name="message015.phpt"/>
<file role="test" name="negotiate001.phpt"/>
- <file role="test" name="object001.phpt"/>
- <file role="test" name="object002.phpt"/>
- <file role="test" name="object003.phpt"/>
- <file role="test" name="object004.phpt"/>
- <file role="test" name="object005.phpt"/>
- <file role="test" name="object006.phpt"/>
- <file role="test" name="object007.phpt"/>
- <file role="test" name="object008.phpt"/>
- <file role="test" name="object009.phpt"/>
<file role="test" name="params001.phpt"/>
<file role="test" name="params002.phpt"/>
<file role="test" name="phpunit.phpt"/>
REGISTER_INI_ENTRIES();
if (0
- || SUCCESS != PHP_MINIT_CALL(http_object)
|| SUCCESS != PHP_MINIT_CALL(http_exception)
|| SUCCESS != PHP_MINIT_CALL(http_cookie)
|| SUCCESS != PHP_MINIT_CALL(http_encoding)
#include <ext/date/php_date.h>
#include <zend_interfaces.h>
+#include <zend_exceptions.h>
+
#ifdef PHP_WIN32
# define PHP_HTTP_API __declspec(dllexport)
/* make functions that return SUCCESS|FAILURE more obvious */
typedef int STATUS;
-/* inline doc */
-#define _RETURNS(type)
-
#if (defined(HAVE_ICONV) || defined(PHP_HTTP_HAVE_EXT_ICONV)) && (PHP_HTTP_SHARED_DEPS || !defined(COMPILE_DL_ICONV))
# define PHP_HTTP_HAVE_ICONV
#endif
#include "php_http_exception.h"
#include "php_http_filter.h"
#include "php_http_header_parser.h"
-#include "php_http_headers.h"
+#include "php_http_header.h"
#include "php_http_message_body.h"
#include "php_http_message_parser.h"
#include "php_http_negotiate.h"
*/
static HashTable php_http_client_drivers;
-PHP_HTTP_API STATUS php_http_client_driver_add(php_http_client_driver_t *driver)
+STATUS php_http_client_driver_add(php_http_client_driver_t *driver)
{
return zend_hash_add(&php_http_client_drivers, driver->name_str, driver->name_len + 1, (void *) driver, sizeof(php_http_client_driver_t), NULL);
}
-PHP_HTTP_API STATUS php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver)
+STATUS php_http_client_driver_get(const char *name_str, size_t name_len, php_http_client_driver_t *driver)
{
php_http_client_driver_t *tmp;
return ZEND_HASH_APPLY_KEEP;
}
-PHP_HTTP_API void php_http_client_driver_list(HashTable *ht TSRMLS_DC)
+void php_http_client_driver_list(HashTable *ht TSRMLS_DC)
{
zend_hash_apply_with_argument(&php_http_client_drivers, apply_driver_list, ht TSRMLS_CC);
}
}
}
-PHP_HTTP_API php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC)
+php_http_client_t *php_http_client_init(php_http_client_t *h, php_http_client_ops_t *ops, php_resource_factory_t *rf, void *init_arg TSRMLS_DC)
{
php_http_client_t *free_h = NULL;
if (h->ops->init) {
if (!(h = h->ops->init(h, init_arg))) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Could not initialize client");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize client");
if (free_h) {
- efree(h);
+ efree(free_h);
}
}
}
return h;
}
-PHP_HTTP_API php_http_client_t *php_http_client_copy(php_http_client_t *from, php_http_client_t *to)
+php_http_client_t *php_http_client_copy(php_http_client_t *from, php_http_client_t *to)
{
if (from->ops->copy) {
return from->ops->copy(from, to);
return NULL;
}
-PHP_HTTP_API void php_http_client_dtor(php_http_client_t *h)
+void php_http_client_dtor(php_http_client_t *h)
{
php_http_client_reset(h);
php_resource_factory_free(&h->rf);
}
-PHP_HTTP_API void php_http_client_free(php_http_client_t **h) {
+void php_http_client_free(php_http_client_t **h) {
if (*h) {
php_http_client_dtor(*h);
efree(*h);
}
}
-PHP_HTTP_API STATUS php_http_client_enqueue(php_http_client_t *h, php_http_client_enqueue_t *enqueue)
+STATUS php_http_client_enqueue(php_http_client_t *h, php_http_client_enqueue_t *enqueue)
{
TSRMLS_FETCH_FROM_CTX(h->ts);
if (h->ops->enqueue) {
if (php_http_client_enqueued(h, enqueue->request, NULL)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to enqueue request; request already in queue");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to enqueue request; request already in queue");
return FAILURE;
}
return h->ops->enqueue(h, enqueue);
return FAILURE;
}
-PHP_HTTP_API STATUS php_http_client_dequeue(php_http_client_t *h, php_http_message_t *request)
+STATUS php_http_client_dequeue(php_http_client_t *h, php_http_message_t *request)
{
TSRMLS_FETCH_FROM_CTX(h->ts);
php_http_client_enqueue_t *enqueue = php_http_client_enqueued(h, request, NULL);
if (!enqueue) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to dequeue request; request not in queue");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to dequeue request; request not in queue");
return FAILURE;
}
return h->ops->dequeue(h, enqueue);
return FAILURE;
}
-PHP_HTTP_API php_http_client_enqueue_t *php_http_client_enqueued(php_http_client_t *h, void *compare_arg, php_http_client_enqueue_cmp_func_t compare_func)
+php_http_client_enqueue_t *php_http_client_enqueued(php_http_client_t *h, void *compare_arg, php_http_client_enqueue_cmp_func_t compare_func)
{
zend_llist_element *el = NULL;
return el ? (php_http_client_enqueue_t *) el->data : NULL;
}
-PHP_HTTP_API STATUS php_http_client_wait(php_http_client_t *h, struct timeval *custom_timeout)
+STATUS php_http_client_wait(php_http_client_t *h, struct timeval *custom_timeout)
{
if (h->ops->wait) {
return h->ops->wait(h, custom_timeout);
return FAILURE;
}
-PHP_HTTP_API int php_http_client_once(php_http_client_t *h)
+int php_http_client_once(php_http_client_t *h)
{
if (h->ops->once) {
return h->ops->once(h);
return FAILURE;
}
-PHP_HTTP_API STATUS php_http_client_exec(php_http_client_t *h)
+STATUS php_http_client_exec(php_http_client_t *h)
{
if (h->ops->exec) {
return h->ops->exec(h);
return FAILURE;
}
-PHP_HTTP_API void php_http_client_reset(php_http_client_t *h)
+void php_http_client_reset(php_http_client_t *h)
{
if (h->ops->reset) {
h->ops->reset(h);
zend_llist_clean(&h->responses);
}
-PHP_HTTP_API STATUS php_http_client_setopt(php_http_client_t *h, php_http_client_setopt_opt_t opt, void *arg)
+STATUS php_http_client_setopt(php_http_client_t *h, php_http_client_setopt_opt_t opt, void *arg)
{
if (h->ops->setopt) {
return h->ops->setopt(h, opt, arg);
return FAILURE;
}
-PHP_HTTP_API STATUS php_http_client_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg, void *res_ptr)
+STATUS php_http_client_getopt(php_http_client_t *h, php_http_client_getopt_opt_t opt, void *arg, void *res_ptr)
{
if (h->ops->getopt) {
return h->ops->getopt(h, opt, arg, res_ptr);
if (e->closure.fci.size) {
zval *retval = NULL;
+ zend_error_handling zeh;
zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 1, &zresponse);
- with_error_handling(EH_NORMAL, NULL) {
- zend_fcall_info_call(&e->closure.fci, &e->closure.fcc, &retval, NULL TSRMLS_CC);
- } end_error_handling();
+ zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
+ zend_fcall_info_call(&e->closure.fci, &e->closure.fcc, &retval, NULL TSRMLS_CC);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
zend_fcall_info_argn(&e->closure.fci TSRMLS_CC, 0);
if (retval) {
static void handle_progress(void *arg, php_http_client_t *client, php_http_client_enqueue_t *e, php_http_client_progress_state_t *progress)
{
zval *zrequest, *zprogress, *retval = NULL, *zclient;
+ zend_error_handling zeh;
TSRMLS_FETCH_FROM_CTX(client->ts);
MAKE_STD_ZVAL(zclient);
add_property_double(zprogress, "dlnow", progress->dl.now);
add_property_double(zprogress, "ultotal", progress->ul.total);
add_property_double(zprogress, "ulnow", progress->ul.now);
- with_error_handling(EH_NORMAL, NULL) {
- zend_call_method_with_2_params(&zclient, NULL, NULL, "notify", &retval, zrequest, zprogress);
- } end_error_handling();
+ zend_replace_error_handling(EH_NORMAL, NULL, &zeh TSRMLS_CC);
+ zend_call_method_with_2_params(&zclient, NULL, NULL, "notify", &retval, zrequest, zprogress);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
zval_ptr_dtor(&zclient);
zval_ptr_dtor(&zrequest);
zval_ptr_dtor(&zprogress);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
char *driver_str = NULL, *persistent_handle_str = NULL;
int driver_len = 0, persistent_handle_len = 0;
+ php_http_client_driver_t driver;
+ php_resource_factory_t *rf = NULL;
+ php_http_client_object_t *obj;
+ zval *os;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len)) {
- php_http_client_driver_t driver;
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &driver_str, &driver_len, &persistent_handle_str, &persistent_handle_len), invalid_arg, return);
- if (SUCCESS == php_http_client_driver_get(driver_str, driver_len, &driver)) {
- php_resource_factory_t *rf = NULL;
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *os;
+ if (SUCCESS != php_http_client_driver_get(driver_str, driver_len, &driver)) {
+ php_http_throw(unexpected_val, "Failed to locate \"%s\" client request handler", driver_str);
+ return;
+ }
- MAKE_STD_ZVAL(os);
- object_init_ex(os, spl_ce_SplObjectStorage);
- zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), os TSRMLS_CC);
- zval_ptr_dtor(&os);
+ MAKE_STD_ZVAL(os);
+ object_init_ex(os, spl_ce_SplObjectStorage);
+ zend_update_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), os TSRMLS_CC);
+ zval_ptr_dtor(&os);
- if (persistent_handle_len) {
- char *name_str;
- size_t name_len;
- php_persistent_handle_factory_t *pf;
+ if (persistent_handle_len) {
+ char *name_str;
+ size_t name_len;
+ php_persistent_handle_factory_t *pf;
- name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver.name_str);
- php_http_pretty_key(name_str + sizeof("http\\Client"), driver.name_len, 1, 1);
+ name_len = spprintf(&name_str, 0, "http\\Client\\%s", driver.name_str);
+ php_http_pretty_key(name_str + sizeof("http\\Client"), driver.name_len, 1, 1);
- if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL TSRMLS_CC))) {
- rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon);
- }
+ if ((pf = php_persistent_handle_concede(NULL , name_str, name_len, persistent_handle_str, persistent_handle_len, NULL, NULL TSRMLS_CC))) {
+ rf = php_resource_factory_init(NULL, php_persistent_handle_get_resource_factory_ops(), pf, (void (*)(void *)) php_persistent_handle_abandon);
+ }
- efree(name_str);
- }
+ efree(name_str);
+ }
- if ((obj->client = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC))) {
- obj->client->callback.response.func = handle_response;
- obj->client->callback.response.arg = obj;
- obj->client->callback.progress.func = handle_progress;
- obj->client->callback.progress.arg = obj;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- obj->client->responses.dtor = response_dtor;
- }
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to locate \"%s\" client request handler", driver_str);
- }
- }
- } end_error_handling();
+ php_http_expect(obj->client = php_http_client_init(NULL, driver.client_ops, rf, NULL TSRMLS_CC), runtime, return);
+
+ obj->client->callback.response.func = handle_response;
+ obj->client->callback.response.arg = obj;
+ obj->client->callback.progress.func = handle_progress;
+ obj->client->callback.progress.arg = obj;
+
+ obj->client->responses.dtor = response_dtor;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_reset, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, reset)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj;
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ obj->iterator = 0;
+ php_http_client_reset(obj->client);
- obj->iterator = 0;
- php_http_client_reset(obj->client);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, enqueue)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *request;
- zend_fcall_info fci = empty_fcall_info;
- zend_fcall_info_cache fcc = empty_fcall_info_cache;
+ zval *request;
+ zend_fcall_info fci = empty_fcall_info;
+ zend_fcall_info_cache fcc = empty_fcall_info_cache;
+ php_http_client_object_t *obj;
+ php_http_message_object_t *msg_obj;
+ php_http_client_enqueue_t q;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return);
- if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to enqueue request; request already in queue");
- } else {
- php_http_client_enqueue_t q;
- q.request = msg_obj->message;
- q.options = combined_options(getThis(), request TSRMLS_CC);
- q.dtor = msg_queue_dtor;
- q.opaque = msg_obj;
- q.closure.fci = fci;
- q.closure.fcc = fcc;
-
- if (fci.size) {
- Z_ADDREF_P(fci.function_name);
- if (fci.object_ptr) {
- Z_ADDREF_P(fci.object_ptr);
- }
- }
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ msg_obj = zend_object_store_get_object(request TSRMLS_CC);
- zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
- php_http_client_enqueue(obj->client, &q);
- }
+ if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
+ php_http_throw(bad_method_call, "Failed to enqueue request; request already in queue", NULL);
+ return;
+ }
+
+ q.request = msg_obj->message;
+ q.options = combined_options(getThis(), request TSRMLS_CC);
+ q.dtor = msg_queue_dtor;
+ q.opaque = msg_obj;
+ q.closure.fci = fci;
+ q.closure.fcc = fcc;
+
+ if (fci.size) {
+ Z_ADDREF_P(fci.function_name);
+ if (fci.object_ptr) {
+ Z_ADDREF_P(fci.object_ptr);
}
- } end_error_handling();
+ }
+
+ zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_enqueue(obj->client, &q), runtime,
+ msg_queue_dtor(&q);
+ return;
+ );
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, dequeue)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *request;
+ zval *request;
+ php_http_client_object_t *obj;
+ php_http_message_object_t *msg_obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
- php_http_client_dequeue(obj->client, msg_obj->message);
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+
+ if (!php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
+ php_http_throw(bad_method_call, "Failed to dequeue request; request not in queue", NULL);
+ return;
+ }
+
+ php_http_expect(SUCCESS == php_http_client_dequeue(obj->client, msg_obj->message), runtime, return);
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, requeue)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *request;
- zend_fcall_info fci = empty_fcall_info;
- zend_fcall_info_cache fcc = empty_fcall_info_cache;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *msg_obj = zend_object_store_get_object(request TSRMLS_CC);
- php_http_client_enqueue_t q;
- q.request = msg_obj->message;
- q.options = combined_options(getThis(), request TSRMLS_CC);
- q.dtor = msg_queue_dtor;
- q.opaque = msg_obj;
- q.closure.fci = fci;
- q.closure.fcc = fcc;
-
- if (fci.size) {
- Z_ADDREF_P(fci.function_name);
- if (fci.object_ptr) {
- Z_ADDREF_P(fci.object_ptr);
- }
- }
+ zval *request;
+ zend_fcall_info fci = empty_fcall_info;
+ zend_fcall_info_cache fcc = empty_fcall_info_cache;
+ php_http_client_object_t *obj;
+ php_http_message_object_t *msg_obj;
+ php_http_client_enqueue_t q;
- zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
- if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
- php_http_client_dequeue(obj->client, msg_obj->message);
- }
- php_http_client_enqueue(obj->client, &q);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|f", &request, php_http_client_request_class_entry, &fci, &fcc), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ msg_obj = zend_object_store_get_object(request TSRMLS_CC);
+
+ if (php_http_client_enqueued(obj->client, msg_obj->message, NULL)) {
+ php_http_expect(SUCCESS == php_http_client_dequeue(obj->client, msg_obj->message), runtime, return);
+ }
+
+ q.request = msg_obj->message;
+ q.options = combined_options(getThis(), request TSRMLS_CC);
+ q.dtor = msg_queue_dtor;
+ q.opaque = msg_obj;
+ q.closure.fci = fci;
+ q.closure.fcc = fcc;
+
+ if (fci.size) {
+ Z_ADDREF_P(fci.function_name);
+ if (fci.object_ptr) {
+ Z_ADDREF_P(fci.object_ptr);
}
- } end_error_handling();
+ }
+
+ zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_enqueue(obj->client, &q), runtime,
+ msg_queue_dtor(&q);
+ return;
+ );
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, getResponse)
{
zval *zrequest = NULL;
+ php_http_client_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_class_entry)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_class_entry), invalid_arg, return);
- if (!zrequest) {
- /* pop off the last respone */
- if (obj->client->responses.tail) {
- php_http_message_object_t *response_obj = *(php_http_message_object_t **) obj->client->responses.tail->data;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- /* pop off and go */
- if (response_obj) {
- RETVAL_OBJVAL(response_obj->zv, 1);
- zend_llist_remove_tail(&obj->client->responses);
- }
- }
- } else {
- /* lookup the response with the request */
- zend_llist_element *el = NULL;
- php_http_message_object_t *req_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
+ if (zrequest) {
+ /* lookup the response with the request */
+ zend_llist_element *el = NULL;
+ php_http_message_object_t *req_obj = zend_object_store_get_object(zrequest TSRMLS_CC);
- for (el = obj->client->responses.head; el; el = el->next) {
- php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data;
+ for (el = obj->client->responses.head; el; el = el->next) {
+ php_http_message_object_t *response_obj = *(php_http_message_object_t **) el->data;
- if (response_obj->message->parent == req_obj->message) {
- RETVAL_OBJVAL(response_obj->zv, 1);
- break;
- }
+ if (response_obj->message->parent == req_obj->message) {
+ RETURN_OBJVAL(response_obj->zv, 1);
}
}
+
+ /* not found for the request! */
+ php_http_throw(unexpected_val, "Could not find response for the request", NULL);
+ return;
+ }
+
+ /* pop off the last response */
+ if (obj->client->responses.tail) {
+ php_http_message_object_t *response_obj = *(php_http_message_object_t **) obj->client->responses.tail->data;
+
+ /* pop off and go */
+ if (response_obj) {
+ RETVAL_OBJVAL(response_obj->zv, 1);
+ zend_llist_remove_tail(&obj->client->responses);
+ }
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, getHistory)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- zval *zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC);
- RETVAL_ZVAL(zhistory, 1, 0);
- }
+ zval *zhistory;
+
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ zhistory = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("history"), 0 TSRMLS_CC);
+ RETVAL_ZVAL(zhistory, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_send, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, send)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_client_object_t *obj;
- php_http_client_exec(obj->client);
- } end_error_handling();
- }
- } end_error_handling();
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_exec(obj->client), runtime, return);
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, enablePipelining)
{
zend_bool enable = 1;
+ php_http_client_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING, &enable), unexpected_val, return);
- php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_ENABLE_PIPELINING, &enable);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpClient, enableEvents)
{
zend_bool enable = 1;
+ php_http_client_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_USE_EVENTS, &enable), unexpected_val, return);
- php_http_client_setopt(obj->client, PHP_HTTP_CLIENT_OPT_USE_EVENTS, &enable);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, notify)
{
- zval *request = NULL, *zprogress = NULL;
+ zval *request = NULL, *zprogress = NULL, *observers, **args[3];
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_class_entry, &zprogress)) {
- zval **args[3], *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_class_entry, &zprogress), invalid_arg, return);
- if (Z_TYPE_P(observers) == IS_OBJECT) {
- Z_ADDREF_P(getThis());
- args[0] = &getThis();
- if (request) {
- Z_ADDREF_P(request);
- }
- args[1] = &request;
- if (zprogress) {
- Z_ADDREF_P(zprogress);
- }
- args[2] = &zprogress;
- spl_iterator_apply(observers, notify, args TSRMLS_CC);
- zval_ptr_dtor(&getThis());
- if (request) {
- zval_ptr_dtor(&request);
- }
- if (zprogress) {
- zval_ptr_dtor(&zprogress);
- }
- }
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+
+ if (Z_TYPE_P(observers) != IS_OBJECT) {
+ php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
+ return;
+ }
+
+ Z_ADDREF_P(getThis());
+ args[0] = &getThis();
+ if (request) {
+ Z_ADDREF_P(request);
+ }
+ args[1] = &request;
+ if (zprogress) {
+ Z_ADDREF_P(zprogress);
+ }
+ args[2] = &zprogress;
+ spl_iterator_apply(observers, notify, args TSRMLS_CC);
+ zval_ptr_dtor(&getThis());
+ if (request) {
+ zval_ptr_dtor(&request);
+ }
+ if (zprogress) {
+ zval_ptr_dtor(&zprogress);
}
RETVAL_ZVAL(getThis(), 1, 0);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, attach)
{
- zval *observer;
+ zval *observers, *observer, *retval = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver)) {
- zval *retval = NULL, *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
- zend_call_method_with_1_params(&observers, NULL, NULL, "attach", &retval, observer);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver), invalid_arg, return);
+
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+
+ if (Z_TYPE_P(observers) != IS_OBJECT) {
+ php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
+ return;
+ }
+
+ zend_call_method_with_1_params(&observers, NULL, NULL, "attach", &retval, observer);
+ if (retval) {
+ zval_ptr_dtor(&retval);
}
RETVAL_ZVAL(getThis(), 1, 0);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, detach)
{
- zval *observer;
+ zval *observers, *observer, *retval = NULL;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver), invalid_arg, return);
+
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &observer, spl_ce_SplObserver)) {
- zval *retval, *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
- zend_call_method_with_1_params(&observers, NULL, NULL, "detach", &retval, observer);
+ if (Z_TYPE_P(observers) != IS_OBJECT) {
+ php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
+ return;
+ }
+
+ zend_call_method_with_1_params(&observers, NULL, NULL, "detach", &retval, observer);
+ if (retval) {
zval_ptr_dtor(&retval);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClient, getObservers)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- zval *observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
- RETVAL_ZVAL(observers, 1, 0);
- }
- } end_error_handling();
+ zval *observers;
+
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ observers = zend_read_property(php_http_client_class_entry, getThis(), ZEND_STRL("observers"), 0 TSRMLS_CC);
+
+ if (Z_TYPE_P(observers) != IS_OBJECT) {
+ php_http_throw(unexpected_val, "Observer storage is corrupted", NULL);
+ return;
+ }
+
+ RETVAL_ZVAL(observers, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getProgressInfo, 0, 0, 1)
static PHP_METHOD(HttpClient, getProgressInfo)
{
zval *request;
+ php_http_client_object_t *obj;
+ php_http_message_object_t *req_obj;
+ php_http_client_progress_state_t *progress;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
- php_http_client_progress_state_t *progress;
-
- if (SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, req_obj->message, &progress)) {
- object_init(return_value);
- add_property_bool(return_value, "started", progress->started);
- add_property_bool(return_value, "finished", progress->finished);
- add_property_string(return_value, "info", STR_PTR(progress->info), 1);
- add_property_double(return_value, "dltotal", progress->dl.total);
- add_property_double(return_value, "dlnow", progress->dl.now);
- add_property_double(return_value, "ultotal", progress->ul.total);
- add_property_double(return_value, "ulnow", progress->ul.now);
- }
- }
- } end_error_handling();
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ req_obj = zend_object_store_get_object(request TSRMLS_CC);
+
+ php_http_expect(SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_PROGRESS_INFO, req_obj->message, &progress), unexpected_val, return);
+
+ object_init(return_value);
+ add_property_bool(return_value, "started", progress->started);
+ add_property_bool(return_value, "finished", progress->finished);
+ add_property_string(return_value, "info", STR_PTR(progress->info), 1);
+ add_property_double(return_value, "dltotal", progress->dl.total);
+ add_property_double(return_value, "dlnow", progress->dl.now);
+ add_property_double(return_value, "ultotal", progress->ul.total);
+ add_property_double(return_value, "ulnow", progress->ul.now);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getTransferInfo, 0, 0, 1)
static PHP_METHOD(HttpClient, getTransferInfo)
{
zval *request;
+ HashTable *info;
+ php_http_client_object_t *obj;
+ php_http_message_object_t *req_obj;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry)) {
- HashTable *info;
- php_http_client_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *req_obj = zend_object_store_get_object(request TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_class_entry), invalid_arg, return);
- object_init(return_value);
- info = HASH_OF(return_value);
- php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &info);
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ req_obj = zend_object_store_get_object(request TSRMLS_CC);
+
+ object_init(return_value);
+ info = HASH_OF(return_value);
+ php_http_expect(SUCCESS == php_http_client_getopt(obj->client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, req_obj->message, &info), unexpected_val, return);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_setOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set(getThis(), opts TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set(getThis(), opts TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addSslOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getSslOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 1 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 1 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_addCookies, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("cookies"), opts, 0 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getCookies, 0, 0, 0)
if (msg && CURLMSG_DONE == msg->msg) {
if (CURLE_OK != msg->data.result) {
php_http_curle_storage_t *st = php_http_curle_get_storage(msg->easy_handle);
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "%s; %s (%s)", curl_easy_strerror(msg->data.result), STR_PTR(st->errorbuffer), STR_PTR(st->url));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s; %s (%s)", curl_easy_strerror(msg->data.result), STR_PTR(st->errorbuffer), STR_PTR(st->url));
}
if ((enqueue = php_http_client_enqueued(context, msg->easy_handle, compare_queue))) {
while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket_action(curl->handle, CURL_SOCKET_TIMEOUT, 0, &curl->unfinished)));
if (CURLM_OK != rc) {
- php_http_error(HE_WARNING, PHP_HTTP_E_SOCKET, "%s", curl_multi_strerror(rc));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_multi_strerror(rc));
}
php_http_curlm_responsehandler(context);
while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket_action(curl->handle, socket, etoca(action), &curl->unfinished)));
if (CURLM_OK != rc) {
- php_http_error(HE_WARNING, PHP_HTTP_E_SOCKET, "%s", curl_multi_strerror(rc));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", curl_multi_strerror(rc));
}
php_http_curlm_responsehandler(context);
return 0;
default:
- php_http_error(HE_WARNING, PHP_HTTP_E_SOCKET, "Unknown socket action %d", action);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown socket action %d", action);
return -1;
}
break;
}
if (rv != SUCCESS) {
- php_http_error(HE_NOTICE, PHP_HTTP_E_CLIENT, "Could not set option %s", opt->name.s);
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Could not set option %s", opt->name.s);
}
return rv;
}
TSRMLS_FETCH_FROM_CTX(h->ts);
if (!(handle = php_resource_factory_handle_ctor(rf, NULL TSRMLS_CC))) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Failed to initialize curl handle");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize curl handle");
return NULL;
}
/* request url */
if (!PHP_HTTP_INFO(msg).request.url) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot request empty URL");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot request empty URL");
return FAILURE;
}
storage->errorbuffer[0] = '\0';
if (PHP_HTTP_INFO(msg).request.method) {
curl_easy_setopt(curl->handle, CURLOPT_CUSTOMREQUEST, PHP_HTTP_INFO(msg).request.method);
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_REQUEST_METHOD, "Cannot use empty request method");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use empty request method");
return FAILURE;
}
break;
TSRMLS_FETCH_FROM_CTX(h->ts);
if (!handle && !(handle = php_resource_factory_handle_ctor(h->rf, NULL TSRMLS_CC))) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_POOL, "Failed to initialize curl handle");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize curl handle");
return NULL;
}
php_resource_factory_t *rf = NULL;
if (!url || !*url) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Cannot request empty URL");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot request empty URL");
return NULL;
}
purl = php_url_parse(url);
if (!purl) {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Could not parse URL '%s'", url);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse URL '%s'", url);
return NULL;
} else {
char *id_str = NULL;
return SUCCESS;
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT_POOL, "Could not enqueue request: %s", curl_multi_strerror(rs));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not enqueue request: %s", curl_multi_strerror(rs));
return FAILURE;
}
}
zend_llist_del_element(&h->requests, handler->handle, (int (*)(void *, void *)) compare_queue);
return SUCCESS;
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_CLIENT, "Could not dequeue request: %s", curl_multi_strerror(rs));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not dequeue request: %s", curl_multi_strerror(rs));
}
return FAILURE;
if (curl->useevents) {
TSRMLS_FETCH_FROM_CTX(h->ts);
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented");
return FAILURE;
}
#endif
#if PHP_HTTP_HAVE_EVENT
if (curl->useevents) {
TSRMLS_FETCH_FROM_CTX(h->ts);
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "not implemented");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "not implemented");
return FAILURE;
}
#endif
#endif
if (ev_rc < 0) {
- php_http_error(HE_ERROR, PHP_HTTP_E_RUNTIME, "Error in event_base_dispatch()");
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in event_base_dispatch()");
return FAILURE;
}
} while (curl->unfinished);
if (SUCCESS != php_http_client_curl_wait(h, NULL)) {
#ifdef PHP_WIN32
/* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
- php_http_error(HE_WARNING, PHP_HTTP_E_SOCKET, "WinSock error: %d", WSAGetLastError());
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "WinSock error: %d", WSAGetLastError());
#else
- php_http_error(HE_WARNING, PHP_HTTP_E_SOCKET, strerror(errno));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno));
#endif
return FAILURE;
}
php_http_client_curl_getopt
};
-PHP_HTTP_API php_http_client_ops_t *php_http_client_curl_get_ops(void)
+php_http_client_ops_t *php_http_client_curl_get_ops(void)
{
return &php_http_client_curl_ops;
}
void php_http_client_options_set(zval *this_ptr, zval *opts TSRMLS_DC);
void php_http_client_options_get_subr(zval *this_ptr, char *key, size_t len, zval *return_value TSRMLS_DC);
+#define PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->message) { \
+ obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC); \
+ } \
+ } while(0)
+
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest___construct, 0, 0, 0)
ZEND_ARG_INFO(0, method)
ZEND_ARG_INFO(0, url)
char *meth_str = NULL, *url_str = NULL;
int meth_len = 0, url_len = 0;
zval *zheaders = NULL, *zbody = NULL;
+ php_http_message_object_t *obj;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!O!", &meth_str, &meth_len, &url_str, &url_len, &zheaders, &zbody, php_http_message_body_class_entry)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!a!O!", &meth_str, &meth_len, &url_str, &url_len, &zheaders, &zbody, php_http_message_body_class_entry), invalid_arg, return);
- if (obj->message) {
- php_http_message_set_type(obj->message, PHP_HTTP_REQUEST);
- } else {
- obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC);
- }
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (zbody) {
- php_http_message_object_set_body(obj, zbody TSRMLS_CC);
- }
- if (meth_str && meth_len) {
- PHP_HTTP_INFO(obj->message).request.method = estrndup(meth_str, meth_len);
- }
- if (url_str && url_len) {
- PHP_HTTP_INFO(obj->message).request.url = estrndup(url_str, url_len);
- }
- if (zheaders) {
- array_copy(Z_ARRVAL_P(zheaders), &obj->message->hdrs);
- }
- }
- } end_error_handling();
+ if (obj->message) {
+ php_http_message_set_type(obj->message, PHP_HTTP_REQUEST);
+ } else {
+ obj->message = php_http_message_init(NULL, PHP_HTTP_REQUEST, NULL TSRMLS_CC);
+ }
+
+ if (zbody) {
+ php_http_expect(SUCCESS == php_http_message_object_set_body(obj, zbody TSRMLS_CC), unexpected_val, return);
+ }
+ if (meth_str && meth_len) {
+ PHP_HTTP_INFO(obj->message).request.method = estrndup(meth_str, meth_len);
+ }
+ if (url_str && url_len) {
+ PHP_HTTP_INFO(obj->message).request.url = estrndup(url_str, url_len);
+ }
+ if (zheaders) {
+ array_copy(Z_ARRVAL_P(zheaders), &obj->message->hdrs);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setContentType, 0, 0, 1)
{
char *ct_str;
int ct_len;
+ php_http_message_object_t *obj;
+ zval *zct;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ct_str, &ct_len)) {
- int invalid = 0;
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ct_str, &ct_len), invalid_arg, return);
- if (ct_len) {
- PHP_HTTP_CHECK_CONTENT_TYPE(ct_str, invalid = 1);
- }
+ if (ct_len && !strchr(ct_str, '/')) {
+ php_http_throw(unexpected_val, "Content type \"%s\" does not seem to contain a primary and a secondary part", ct_str);
+ return;
+ }
- if (!invalid) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zct;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
+
+ MAKE_STD_ZVAL(zct);
+ ZVAL_STRINGL(zct, ct_str, ct_len, 1);
+ zend_hash_update(&obj->message->hdrs, "Content-Type", sizeof("Content-Type"), (void *) &zct, sizeof(void *), NULL);
- MAKE_STD_ZVAL(zct);
- ZVAL_STRINGL(zct, ct_str, ct_len, 1);
- zend_hash_update(&obj->message->hdrs, "Content-Type", sizeof("Content-Type"), (void *) &zct, sizeof(void *), NULL);
- }
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
zval *zct;
+ PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
+
php_http_message_update_headers(obj->message);
zct = php_http_message_header(obj->message, ZEND_STRL("Content-Type"), 1);
if (zct) {
static PHP_METHOD(HttpClientRequest, setQuery)
{
zval *qdata = NULL;
+ php_http_message_object_t *obj;
+ php_url *old_url = NULL, new_url = {NULL};
+ char empty[] = "";
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_url *old_url = NULL, new_url = {NULL};
- char empty[] = "";
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata), invalid_arg, return);
- if (qdata) {
- zval arr, str;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- INIT_PZVAL(&arr);
- array_init(&arr);
- INIT_PZVAL(&str);
- ZVAL_NULL(&str);
+ PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
- php_http_querystring_update(&arr, qdata, &str TSRMLS_CC);
- new_url.query = Z_STRVAL(str);
- zval_dtor(&arr);
- } else {
- new_url.query = &empty[0];
- }
+ if (qdata) {
+ zval arr, str;
- if (obj->message->http.info.request.url) {
- old_url = php_url_parse(obj->message->http.info.request.url);
- efree(obj->message->http.info.request.url);
- }
+ INIT_PZVAL(&arr);
+ array_init(&arr);
+ INIT_PZVAL(&str);
+ ZVAL_NULL(&str);
+
+ php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str TSRMLS_CC), bad_querystring,
+ zval_dtor(&arr);
+ return;
+ );
+ new_url.query = Z_STRVAL(str);
+ zval_dtor(&arr);
+ } else {
+ new_url.query = &empty[0];
+ }
- php_http_url(PHP_HTTP_URL_REPLACE, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
+ if (obj->message->http.info.request.url) {
+ old_url = php_url_parse(obj->message->http.info.request.url);
+ efree(obj->message->http.info.request.url);
+ }
- if (old_url) {
- php_url_free(old_url);
- }
- if (new_url.query != &empty[0]) {
- STR_FREE(new_url.query);
- }
+ php_http_url(PHP_HTTP_URL_REPLACE, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
+
+ if (old_url) {
+ php_url_free(old_url);
}
+ if (new_url.query != &empty[0]) {
+ STR_FREE(new_url.query);
+ }
+
RETVAL_ZVAL(getThis(), 1, 0);
}
if (SUCCESS == zend_parse_parameters_none()) {
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
+
if (obj->message->http.info.request.url) {
php_url *purl = php_url_parse(obj->message->http.info.request.url);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpClientRequest, addQuery)
{
- zval *qdata;
+ zval *qdata, arr, str;
+ php_http_message_object_t *obj;
+ php_url *old_url = NULL, new_url = {NULL};
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &qdata)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_url *old_url = NULL, new_url = {NULL};
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &qdata), invalid_arg, return);
- zval arr, str;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- INIT_PZVAL(&arr);
- array_init(&arr);
- INIT_PZVAL(&str);
- ZVAL_NULL(&str);
+ PHP_HTTP_CLIENT_REQUEST_OBJECT_INIT(obj);
- php_http_querystring_update(&arr, qdata, &str TSRMLS_CC);
- new_url.query = Z_STRVAL(str);
- zval_dtor(&arr);
+ INIT_PZVAL(&arr);
+ array_init(&arr);
+ INIT_PZVAL(&str);
+ ZVAL_NULL(&str);
- if (obj->message->http.info.request.url) {
- old_url = php_url_parse(obj->message->http.info.request.url);
- efree(obj->message->http.info.request.url);
- }
+ php_http_expect(SUCCESS == php_http_querystring_update(&arr, qdata, &str TSRMLS_CC), bad_querystring,
+ zval_dtor(&arr);
+ return;
+ );
+ new_url.query = Z_STRVAL(str);
+ zval_dtor(&arr);
+
+ if (obj->message->http.info.request.url) {
+ old_url = php_url_parse(obj->message->http.info.request.url);
+ efree(obj->message->http.info.request.url);
+ }
- php_http_url(PHP_HTTP_URL_JOIN_QUERY, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
+ php_http_url(PHP_HTTP_URL_JOIN_QUERY, old_url, &new_url, NULL, &obj->message->http.info.request.url, NULL TSRMLS_CC);
- if (old_url) {
- php_url_free(old_url);
- }
- STR_FREE(new_url.query);
+ if (old_url) {
+ php_url_free(old_url);
}
+ STR_FREE(new_url.query);
+
RETVAL_ZVAL(getThis(), 1, 0);
}
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set(getThis(), opts TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set(getThis(), opts TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getOptions, 0, 0, 0)
zval *zoptions = zend_read_property(php_http_client_request_class_entry, getThis(), ZEND_STRL("options"), 0 TSRMLS_CC);
RETURN_ZVAL(zoptions, 1, 0);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setSslOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 1 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_addSslOptions, 0, 0, 0)
{
zval *opts = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
- php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_client_options_set_subr(getThis(), ZEND_STRS("ssl"), opts, 0 TSRMLS_CC);
+
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getSslOptions, 0, 0, 0)
{
char *info_name = NULL;
int info_len = 0;
- zval *infop, *info;
+ zval *info;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
- return;
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len), invalid_arg, return);
info = zend_read_property(php_http_client_response_class_entry, getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC);
/* request completed? */
- if (Z_TYPE_P(info) == IS_OBJECT) {
- if (info_len && info_name) {
- infop = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
-
- if (infop) {
- RETURN_ZVAL(infop, 1, 0);
- } else {
- php_http_error(HE_NOTICE, PHP_HTTP_E_INVALID_PARAM, "Could not find transfer info named %s", info_name);
- }
- } else {
- RETURN_ZVAL(info, 1, 0);
+ if (Z_TYPE_P(info) != IS_OBJECT) {
+ php_http_throw(bad_method_call, "Incomplete state", NULL);
+ return;
+ }
+
+ if (info_len && info_name) {
+ info = zend_read_property(NULL, info, php_http_pretty_key(info_name, info_len, 0, 0), info_len, 0 TSRMLS_CC);
+
+ if (!info) {
+ php_http_throw(unexpected_val, "Could not find transfer info with name '%s'", info_name);
+ return;
}
}
- RETURN_FALSE;
+
+ RETURN_ZVAL(info, 1, 0);
}
static zend_function_entry php_http_client_response_methods[] = {
INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Response", php_http_client_response_methods);
php_http_client_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC);
+ zend_declare_property_null(php_http_client_response_class_entry, ZEND_STRL("transferInfo"), ZEND_ACC_PROTECTED TSRMLS_CC);
return SUCCESS;
}
#include "php_http_api.h"
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_init(php_http_cookie_list_t *list TSRMLS_DC)
{
if (!list) {
list = emalloc(sizeof(*list));
return list;
}
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to)
+php_http_cookie_list_t *php_http_cookie_list_copy(php_http_cookie_list_t *from, php_http_cookie_list_t *to)
{
TSRMLS_FETCH_FROM_CTX(from->ts);
return to;
}
-PHP_HTTP_API void php_http_cookie_list_dtor(php_http_cookie_list_t *list)
+void php_http_cookie_list_dtor(php_http_cookie_list_t *list)
{
if (list) {
zend_hash_destroy(&list->cookies);
-PHP_HTTP_API void php_http_cookie_list_free(php_http_cookie_list_t **list)
+void php_http_cookie_list_free(php_http_cookie_list_t **list)
{
if (*list) {
php_http_cookie_list_dtor(*list);
}
}
-PHP_HTTP_API const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zcookie)
+const char *php_http_cookie_list_get_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zcookie)
{
zval **cookie;
if ((SUCCESS != zend_symtable_find(&list->cookies, name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
return Z_STRVAL_PP(cookie);
}
-PHP_HTTP_API const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zextra)
+const char *php_http_cookie_list_get_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, zval **zextra)
{
zval **extra;
return Z_STRVAL_PP(extra);
}
-PHP_HTTP_API void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
+void php_http_cookie_list_add_cookie(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
zval *cookie_value;
zend_symtable_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
}
-PHP_HTTP_API void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
+void php_http_cookie_list_add_extra(php_http_cookie_list_t *list, const char *name, size_t name_len, const char *value, size_t value_len)
{
zval *cookie_value;
zval_ptr_dtor(&arg);
}
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_parse(php_http_cookie_list_t *list, const char *str, size_t len, long flags, char **allowed_extras TSRMLS_DC)
{
php_http_params_opts_t opts;
HashTable params;
return list;
}
-PHP_HTTP_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
+void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct)
{
zval array, *cookies, *extras;
TSRMLS_FETCH_FROM_CTX(list->ts);
add_assoc_string(&array, "domain", STR_PTR(list->domain), 1);
}
-PHP_HTTP_API php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC)
+php_http_cookie_list_t *php_http_cookie_list_from_struct(php_http_cookie_list_t *list, zval *strct TSRMLS_DC)
{
zval **tmp, *cpy;
HashTable *ht = HASH_OF(strct);
efree(enc_str[1]);
}
-PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
+void php_http_cookie_list_to_string(php_http_cookie_list_t *list, char **str, size_t *len)
{
php_http_buffer_t buf;
zval **val;
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zcookie = NULL;
- long flags = 0;
- HashTable *allowed_extras = NULL;
+ php_http_cookie_object_t *obj;
+ zval *zcookie = NULL;
+ long flags = 0;
+ char **ae = NULL;
+ HashTable *allowed_extras = NULL;
+ zend_error_handling zeh;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!lH", &zcookie, &flags, &allowed_extras)) {
- if (zcookie) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- char **ae = NULL;
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!lH", &zcookie, &flags, &allowed_extras), invalid_arg, return);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (allowed_extras && zend_hash_num_elements(allowed_extras)) {
- char **ae_ptr = safe_emalloc(zend_hash_num_elements(allowed_extras) + 1, sizeof(char *), 0);
- HashPosition pos;
- zval **val;
+ zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ if (zcookie) {
- ae = ae_ptr;
- FOREACH_HASH_VAL(pos, allowed_extras, val) {
- zval *cpy = php_http_ztyp(IS_STRING, *val);
+ if (allowed_extras && zend_hash_num_elements(allowed_extras)) {
+ char **ae_ptr = safe_emalloc(zend_hash_num_elements(allowed_extras) + 1, sizeof(char *), 0);
+ HashPosition pos;
+ zval **val;
- *ae_ptr++ = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
- zval_ptr_dtor(&cpy);
- }
- *ae_ptr = NULL;
- }
+ ae = ae_ptr;
+ FOREACH_HASH_VAL(pos, allowed_extras, val) {
+ zval *cpy = php_http_ztyp(IS_STRING, *val);
- switch (Z_TYPE_P(zcookie)) {
- case IS_OBJECT:
- if (instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry TSRMLS_CC)) {
- php_http_cookie_object_t *zco = zend_object_store_get_object(zcookie TSRMLS_CC);
-
- if (zco->list) {
- obj->list = php_http_cookie_list_copy(zco->list, NULL);
- }
- break;
- }
- /* no break */
- case IS_ARRAY:
- obj->list = php_http_cookie_list_from_struct(obj->list, zcookie TSRMLS_CC);
- break;
- default: {
- zval *cpy = php_http_ztyp(IS_STRING, zcookie);
-
- obj->list = php_http_cookie_list_parse(obj->list, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), flags, ae TSRMLS_CC);
- zval_ptr_dtor(&cpy);
- break;
- }
- }
+ *ae_ptr++ = estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
+ zval_ptr_dtor(&cpy);
+ }
+ *ae_ptr = NULL;
+ }
- if (ae) {
- char **ae_ptr;
+ switch (Z_TYPE_P(zcookie)) {
+ case IS_OBJECT:
+ if (instanceof_function(Z_OBJCE_P(zcookie), php_http_cookie_class_entry TSRMLS_CC)) {
+ php_http_cookie_object_t *zco = zend_object_store_get_object(zcookie TSRMLS_CC);
- for (ae_ptr = ae; *ae_ptr; ++ae_ptr) {
- efree(*ae_ptr);
- }
- efree(ae);
+ if (zco->list) {
+ obj->list = php_http_cookie_list_copy(zco->list, NULL);
}
- } end_error_handling();
+ break;
+ }
+ /* no break */
+ case IS_ARRAY:
+ obj->list = php_http_cookie_list_from_struct(obj->list, zcookie TSRMLS_CC);
+ break;
+ default: {
+ zval *cpy = php_http_ztyp(IS_STRING, zcookie);
+
+ obj->list = php_http_cookie_list_parse(obj->list, Z_STRVAL_P(cpy), Z_STRLEN_P(cpy), flags, ae TSRMLS_CC);
+ zval_ptr_dtor(&cpy);
+ break;
}
}
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- } end_error_handling();
+
+ if (ae) {
+ char **ae_ptr;
+
+ for (ae_ptr = ae; *ae_ptr; ++ae_ptr) {
+ efree(*ae_ptr);
+ }
+ efree(ae);
+ }
+ }
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getCookies, 0, 0, 0)
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, getCookies)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ php_http_cookie_object_t *obj;
- array_init(return_value);
- array_copy(&obj->list->cookies, Z_ARRVAL_P(return_value));
+ if (SUCCESS != zend_parse_parameters_none()) {
return;
}
- RETURN_FALSE;
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ array_init(return_value);
+ array_copy(&obj->list->cookies, Z_ARRVAL_P(return_value));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setCookies, 0, 0, 0)
static PHP_METHOD(HttpCookie, setCookies)
{
HashTable *cookies = NULL;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &cookies)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &cookies), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_hash_clean(&obj->list->cookies);
- if (cookies) {
- array_copy(cookies, &obj->list->cookies);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ zend_hash_clean(&obj->list->cookies);
+ if (cookies) {
+ array_copy(cookies, &obj->list->cookies);
}
+
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpCookie, addCookies)
{
HashTable *cookies = NULL;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &cookies)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &cookies), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY);
- array_join(cookies, &obj->list->cookies, 1, ARRAY_JOIN_STRONLY);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, getExtras)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_cookie_object_t *obj;
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
-
- array_init(return_value);
- array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ array_init(return_value);
+ array_copy(&obj->list->extras, Z_ARRVAL_P(return_value));
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtras, 0, 0, 0)
static PHP_METHOD(HttpCookie, setExtras)
{
HashTable *extras = NULL;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &extras)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|H", &extras), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zend_hash_clean(&obj->list->extras);
- if (extras) {
- array_copy(extras, &obj->list->extras);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ zend_hash_clean(&obj->list->extras);
+ if (extras) {
+ array_copy(extras, &obj->list->extras);
}
+
RETVAL_ZVAL(getThis(), 1, 0);
}
static PHP_METHOD(HttpCookie, addExtras)
{
HashTable *extras = NULL;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &extras)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H", &extras), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY);
- array_join(extras, &obj->list->extras, 1, ARRAY_JOIN_STRONLY);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
{
char *name_str;
int name_len;
+ zval *zvalue;
+ php_http_cookie_object_t *obj;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ return;
+ }
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zvalue;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- if (php_http_cookie_list_get_cookie(obj->list, name_str, name_len, &zvalue)) {
- RETURN_ZVAL(zvalue, 1, 0);
- }
+ if (php_http_cookie_list_get_cookie(obj->list, name_str, name_len, &zvalue)) {
+ RETURN_ZVAL(zvalue, 1, 0);
}
}
{
char *name_str, *value_str = NULL;
int name_len, value_len = 0;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!value_str) {
- php_http_cookie_list_del_cookie(obj->list, name_str, name_len);
- } else {
- php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ if (!value_str) {
+ php_http_cookie_list_del_cookie(obj->list, name_str, name_len);
+ } else {
+ php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
}
+
RETVAL_ZVAL(getThis(), 1, 0);
}
{
char *name_str, *value_str;
int name_len, value_len;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
- php_http_cookie_list_add_cookie(obj->list, name_str, name_len, value_str, value_len);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
{
char *name_str;
int name_len;
+ zval *zvalue;
+ php_http_cookie_object_t *obj;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ return;
+ }
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- zval *zvalue;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
- if (php_http_cookie_list_get_extra(obj->list, name_str, name_len, &zvalue)) {
- RETURN_ZVAL(zvalue, 1, 0);
- }
+ if (php_http_cookie_list_get_extra(obj->list, name_str, name_len, &zvalue)) {
+ RETURN_ZVAL(zvalue, 1, 0);
}
}
{
char *name_str, *value_str = NULL;
int name_len, value_len = 0;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (!value_str) {
- php_http_cookie_list_del_extra(obj->list, name_str, name_len);
- } else {
- php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
- }
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ if (!value_str) {
+ php_http_cookie_list_del_extra(obj->list, name_str, name_len);
+ } else {
+ php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
}
+
RETVAL_ZVAL(getThis(), 1, 0);
}
{
char *name_str, *value_str;
int name_len, value_len;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
- php_http_cookie_list_add_extra(obj->list, name_str, name_len, value_str, value_len);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, getDomain)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_cookie_object_t *obj;
+
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
+ }
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (obj->list->domain) {
- RETURN_STRING(obj->list->domain, 1);
- }
- RETURN_NULL();
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ if (obj->list->domain) {
+ RETURN_STRING(obj->list->domain, 1);
}
}
{
char *domain_str = NULL;
int domain_len = 0;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &domain_str, &domain_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &domain_str, &domain_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ STR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
- STR_SET(obj->list->domain, domain_str ? estrndup(domain_str, domain_len) : NULL);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, getPath)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_cookie_object_t *obj;
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
+ }
- if (obj->list->path) {
- RETURN_STRING(obj->list->path, 1);
- }
- RETURN_NULL();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ if (obj->list->path) {
+ RETURN_STRING(obj->list->path, 1);
}
}
{
char *path_str = NULL;
int path_len = 0;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &path_str, &path_len)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &path_str, &path_len), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ STR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
- STR_SET(obj->list->path, path_str ? estrndup(path_str, path_len) : NULL);
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, getExpires)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ php_http_cookie_object_t *obj;
- RETURN_LONG(obj->list->expires);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ RETURN_LONG(obj->list->expires);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExpires, 0, 0, 0)
static PHP_METHOD(HttpCookie, setExpires)
{
long ts = -1;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ obj->list->expires = ts;
- obj->list->expires = ts;
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, getMaxAge)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_cookie_object_t *obj;
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
-
- RETURN_LONG(obj->list->max_age);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ RETURN_LONG(obj->list->max_age);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setMaxAge, 0, 0, 0)
static PHP_METHOD(HttpCookie, setMaxAge)
{
long ts = -1;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ obj->list->max_age = ts;
- obj->list->max_age = ts;
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpCookie, getFlags)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ php_http_cookie_object_t *obj;
- RETURN_LONG(obj->list->flags);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ RETURN_LONG(obj->list->flags);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setFlags, 0, 0, 0)
static PHP_METHOD(HttpCookie, setFlags)
{
long flags = 0;
+ php_http_cookie_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags), invalid_arg, return);
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ obj->list->flags = flags;
- obj->list->flags = flags;
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, toString)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- char *str;
- size_t len;
+ php_http_cookie_object_t *obj;
+ char *str;
+ size_t len;
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
-
- php_http_cookie_list_to_string(obj->list, &str, &len);
- RETURN_STRINGL(str, len, 0);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ RETURN_EMPTY_STRING();
}
- RETURN_EMPTY_STRING();
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ php_http_cookie_list_to_string(obj->list, &str, &len);
+
+ RETURN_STRINGL(str, len, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_toArray, 0, 0, 0)
ZEND_END_ARG_INFO();;
static PHP_METHOD(HttpCookie, toArray)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_cookie_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_cookie_object_t *obj;
- PHP_HTTP_COOKIE_OBJECT_INIT(obj);
-
- array_init(return_value);
- php_http_cookie_list_to_struct(obj->list, return_value);
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_COOKIE_OBJECT_INIT(obj);
+
+ array_init(return_value);
+ php_http_cookie_list_to_struct(obj->list, return_value);
}
static zend_function_entry php_http_cookie_methods[] = {
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Cookie", php_http_cookie_methods);
- php_http_cookie_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_cookie_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
php_http_cookie_class_entry->create_object = php_http_cookie_object_new;
memcpy(&php_http_cookie_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
php_http_cookie_object_handlers.clone_obj = php_http_cookie_object_clone;
}
}
-PHP_HTTP_API const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+const char *php_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
{
int eol_len = 0;
char *n_ptr = NULL;
* not encoded data and return a copy
*/
if (e_ptr == encoded) {
- php_http_error(HE_NOTICE, PHP_HTTP_E_ENCODING, "Data does not seem to be chunked encoded");
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Data does not seem to be chunked encoded");
memcpy(*decoded, encoded, encoded_len);
*decoded_len = encoded_len;
decoded[*decoded_len] = '\0';
return encoded + encoded_len;
} else {
efree(*decoded);
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
return NULL;
}
}
/* there should be CRLF after the chunk size, but we'll ignore SP+ too */
if (*n_ptr && !eol_match(&n_ptr, &eol_len)) {
if (eol_len == 2) {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
}
}
n_ptr += eol_len;
/* chunk size pretends more data than we actually got, so it's probably a truncated message */
if (chunk_len > (rest = encoded + encoded_len - n_ptr)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
chunk_len = rest;
}
return status;
}
-PHP_HTTP_API STATUS php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+STATUS php_http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
{
int status, level, wbits, strategy;
z_stream Z;
}
}
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Could not deflate data: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not deflate data: %s", zError(status));
return FAILURE;
}
-PHP_HTTP_API STATUS php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+STATUS php_http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
{
z_stream Z;
int status, wbits = PHP_HTTP_WINDOW_BITS_ANY;
}
}
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Could not inflate data: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not inflate data: %s", zError(status));
return FAILURE;
}
-PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags TSRMLS_DC)
+php_http_encoding_stream_t *php_http_encoding_stream_init(php_http_encoding_stream_t *s, php_http_encoding_stream_ops_t *ops, unsigned flags TSRMLS_DC)
{
int freeme;
return NULL;
}
-PHP_HTTP_API php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to)
+php_http_encoding_stream_t *php_http_encoding_stream_copy(php_http_encoding_stream_t *from, php_http_encoding_stream_t *to)
{
TSRMLS_FETCH_FROM_CTX(from->ts);
return NULL;
}
-PHP_HTTP_API STATUS php_http_encoding_stream_reset(php_http_encoding_stream_t **s)
+STATUS php_http_encoding_stream_reset(php_http_encoding_stream_t **s)
{
php_http_encoding_stream_t *ss;
if ((*s)->ops->dtor) {
return FAILURE;
}
-PHP_HTTP_API STATUS php_http_encoding_stream_update(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len)
+STATUS php_http_encoding_stream_update(php_http_encoding_stream_t *s, const char *in_str, size_t in_len, char **out_str, size_t *out_len)
{
if (!s->ops->update) {
return FAILURE;
return s->ops->update(s, in_str, in_len, out_str, out_len);
}
-PHP_HTTP_API STATUS php_http_encoding_stream_flush(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
+STATUS php_http_encoding_stream_flush(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
{
if (!s->ops->flush) {
*out_str = NULL;
return s->ops->flush(s, out_str, out_len);
}
-PHP_HTTP_API zend_bool php_http_encoding_stream_done(php_http_encoding_stream_t *s)
+zend_bool php_http_encoding_stream_done(php_http_encoding_stream_t *s)
{
if (!s->ops->done) {
return 0;
return s->ops->done(s);
}
-PHP_HTTP_API STATUS php_http_encoding_stream_finish(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
+STATUS php_http_encoding_stream_finish(php_http_encoding_stream_t *s, char **out_str, size_t *out_len)
{
if (!s->ops->finish) {
*out_str = NULL;
return s->ops->finish(s, out_str, out_len);
}
-PHP_HTTP_API void php_http_encoding_stream_dtor(php_http_encoding_stream_t *s)
+void php_http_encoding_stream_dtor(php_http_encoding_stream_t *s)
{
if (s->ops->dtor) {
s->ops->dtor(s);
}
}
-PHP_HTTP_API void php_http_encoding_stream_free(php_http_encoding_stream_t **s)
+void php_http_encoding_stream_free(php_http_encoding_stream_t **s)
{
if (*s) {
if ((*s)->ops->dtor) {
status = Z_MEM_ERROR;
}
pefree(ctx, p);
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to initialize deflate encoding stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize deflate encoding stream: %s", zError(status));
return NULL;
}
status = Z_MEM_ERROR;
}
pefree(ctx, p);
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to initialize inflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to initialize inflate stream: %s", zError(status));
return NULL;
}
deflateEnd(to_ctx);
status = Z_MEM_ERROR;
}
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to copy deflate encoding stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy deflate encoding stream: %s", zError(status));
return NULL;
}
inflateEnd(to_ctx);
status = Z_MEM_ERROR;
}
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to copy inflate encoding stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: %s", zError(status));
return NULL;
}
return to;
}
pefree(to_ctx, p);
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to copy inflate encoding stream: out of memory");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to copy inflate encoding stream: out of memory");
return NULL;
}
STR_SET(*encoded, NULL);
*encoded_len = 0;
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to update deflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update deflate stream: %s", zError(status));
return FAILURE;
}
break;
}
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to update inflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to update inflate stream: %s", zError(status));
return FAILURE;
}
TSRMLS_FETCH_FROM_CTX(s->ts);
if (ctx->zeroed) {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Dechunk encoding stream has already reached the end of chunked input");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dechunk encoding stream has already reached the end of chunked input");
return FAILURE;
}
if ((PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(&ctx->buffer, data, data_len)) || !php_http_buffer_fix(&ctx->buffer)) {
/* if strtoul() stops at the beginning of the buffered data
there's something oddly wrong, i.e. bad input */
if (stop == ctx->buffer.data) {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to parse chunk len from '%.*s'", MIN(16, ctx->buffer.used), ctx->buffer.data);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse chunk len from '%.*s'", (int) MIN(16, ctx->buffer.used), ctx->buffer.data);
php_http_buffer_dtor(&tmp);
return FAILURE;
}
STR_SET(*encoded, NULL);
*encoded_len = 0;
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to flush deflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to flush deflate stream: %s", zError(status));
return FAILURE;
}
STR_SET(*encoded, NULL);
*encoded_len = 0;
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to finish deflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish deflate stream: %s", zError(status));
return FAILURE;
}
STR_SET(*decoded, NULL);
*decoded_len = 0;
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Failed to finish inflate stream: %s", zError(status));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish inflate stream: %s", zError(status));
return FAILURE;
}
deflate_dtor
};
-PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_deflate_ops(void)
+php_http_encoding_stream_ops_t *php_http_encoding_stream_get_deflate_ops(void)
{
return &php_http_encoding_deflate_ops;
}
inflate_dtor
};
-PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_inflate_ops(void)
+php_http_encoding_stream_ops_t *php_http_encoding_stream_get_inflate_ops(void)
{
return &php_http_encoding_inflate_ops;
}
dechunk_dtor
};
-PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_dechunk_ops(void)
+php_http_encoding_stream_ops_t *php_http_encoding_stream_get_dechunk_ops(void)
{
return &php_http_encoding_dechunk_ops;
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEncodingStream, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- long flags = 0;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
-
- if (!obj->stream) {
- php_http_encoding_stream_ops_t *ops = NULL;
-
- if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry TSRMLS_CC)) {
- ops = &php_http_encoding_deflate_ops;
- } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry TSRMLS_CC)) {
- ops = &php_http_encoding_inflate_ops;
- } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) {
- ops = &php_http_encoding_dechunk_ops;
- }
+ long flags = 0;
+ php_http_encoding_stream_object_t *obj;
+ php_http_encoding_stream_ops_t *ops;
- if (ops) {
- obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags TSRMLS_CC);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "Unknown HttpEncodingStream class %s", obj->zo.ce->name);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags), invalid_arg, return);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_ENCODING, "HttpEncodingStream cannot be initialized twice");
- }
- } end_error_handling();
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (obj->stream) {
+ php_http_throw(bad_method_call, "http\\Encoding\\Stream cannot be initialized twice", NULL);
+ return;
+ }
+
+ if (instanceof_function(obj->zo.ce, php_http_deflate_stream_class_entry TSRMLS_CC)) {
+ ops = &php_http_encoding_deflate_ops;
+ } else if (instanceof_function(obj->zo.ce, php_http_inflate_stream_class_entry TSRMLS_CC)) {
+ ops = &php_http_encoding_inflate_ops;
+ } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) {
+ ops = &php_http_encoding_dechunk_ops;
+ } else {
+ php_http_throw(runtime, "Unknown http\\Encoding\\Stream class '%s'", obj->zo.ce->name);
+ return;
+ }
+
+ php_http_expect(obj->stream = php_http_encoding_stream_init(obj->stream, ops, flags TSRMLS_CC), runtime, return);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_update, 0, 0, 1)
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Encoding", "Stream", php_http_encoding_stream_methods);
- php_http_encoding_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_encoding_stream_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
php_http_encoding_stream_class_entry->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
php_http_encoding_stream_class_entry->create_object = php_http_encoding_stream_object_new;
memcpy(&php_http_encoding_stream_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
return SUCCESS;
}
-PHP_HTTP_API void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC)
+void php_http_env_get_request_headers(HashTable *headers TSRMLS_DC)
{
php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
zval **hsv, **header;
}
}
-PHP_HTTP_API char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC)
+char *php_http_env_get_request_header(const char *name_str, size_t name_len, size_t *len, php_http_message_t *request TSRMLS_DC)
{
HashTable *request_headers;
zval **zvalue = NULL;
return val;
}
-PHP_HTTP_API int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC)
+int php_http_env_got_request_header(const char *name_str, size_t name_len, php_http_message_t *request TSRMLS_DC)
{
HashTable *request_headers;
char *key = php_http_pretty_key(estrndup(name_str, name_len), name_len, 1, 1);
return got;
}
-PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC)
+zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC)
{
zval **hsv;
return *hsv;
}
-PHP_HTTP_API zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
+zval *php_http_env_get_server_var(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
{
zval *hsv, **var;
char *env;
return *var;
}
-PHP_HTTP_API php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
+php_http_message_body_t *php_http_env_get_request_body(TSRMLS_D)
{
if (!PHP_HTTP_G->env.request.body) {
php_stream *s = php_stream_temp_new();
return PHP_HTTP_G->env.request.body;
}
-PHP_HTTP_API const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC)
+const char *php_http_env_get_request_method(php_http_message_t *request TSRMLS_DC)
{
const char *m;
return m ? m : "GET";
}
-PHP_HTTP_API php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request TSRMLS_DC)
+php_http_range_status_t php_http_env_get_request_ranges(HashTable *ranges, size_t length, php_http_message_t *request TSRMLS_DC)
{
zval *zentry;
char *range, *rp, c;
php_http_buffer_appends(PHP_HTTP_BUFFER(arg), PHP_HTTP_CRLF);
}
-PHP_HTTP_API STATUS php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
+STATUS php_http_env_get_response_headers(HashTable *headers_ht TSRMLS_DC)
{
STATUS status;
php_http_buffer_t headers;
zend_llist_apply_with_argument(&SG(sapi_headers).headers, grab_headers, &headers TSRMLS_CC);
php_http_buffer_fix(&headers);
- status = php_http_headers_parse(headers.data, headers.used, headers_ht, NULL, NULL TSRMLS_CC);
+ status = php_http_header_parse(headers.data, headers.used, headers_ht, NULL, NULL TSRMLS_CC);
php_http_buffer_dtor(&headers);
return status;
}
-PHP_HTTP_API char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC)
+char *php_http_env_get_response_header(const char *name_str, size_t name_len TSRMLS_DC)
{
char *val = NULL;
HashTable headers;
return val;
}
-PHP_HTTP_API long php_http_env_get_response_code(TSRMLS_D)
+long php_http_env_get_response_code(TSRMLS_D)
{
long code = SG(sapi_headers).http_response_code;
return code ? code : 200;
}
-PHP_HTTP_API STATUS php_http_env_set_response_code(long http_code TSRMLS_DC)
+STATUS php_http_env_set_response_code(long http_code TSRMLS_DC)
{
return sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) http_code TSRMLS_CC);
}
-PHP_HTTP_API STATUS php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
+STATUS php_http_env_set_response_status_line(long code, php_http_version_t *v TSRMLS_DC)
{
sapi_header_line h = {NULL, 0, 0};
STATUS ret;
return ret;
}
-PHP_HTTP_API STATUS php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC)
+STATUS php_http_env_set_response_protocol_version(php_http_version_t *v TSRMLS_DC)
{
return php_http_env_set_response_status_line(php_http_env_get_response_code(TSRMLS_C), v TSRMLS_CC);
}
-PHP_HTTP_API STATUS php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC)
+STATUS php_http_env_set_response_header(long http_code, const char *header_str, size_t header_len, zend_bool replace TSRMLS_DC)
{
sapi_header_line h = {estrndup(header_str, header_len), header_len, http_code};
STATUS ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, (void *) &h TSRMLS_CC);
return ret;
}
-PHP_HTTP_API STATUS php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC)
+STATUS php_http_env_set_response_header_va(long http_code, zend_bool replace, const char *fmt, va_list argv TSRMLS_DC)
{
STATUS ret = FAILURE;
sapi_header_line h = {NULL, 0, http_code};
return ret;
}
-PHP_HTTP_API STATUS php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...)
+STATUS php_http_env_set_response_header_format(long http_code, zend_bool replace TSRMLS_DC, const char *fmt, ...)
{
STATUS ret;
va_list args;
return ret;
}
-PHP_HTTP_API STATUS php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC)
+STATUS php_http_env_set_response_header_value(long http_code, const char *name_str, size_t name_len, zval *value, zend_bool replace TSRMLS_DC)
{
if (!value) {
sapi_header_line h = {(char *) name_str, name_len, http_code};
PHP_HTTP_STRLIST_STOP
;
-PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code)
+const char *php_http_env_get_response_status_for_code(unsigned code)
{
return php_http_strlist_find(php_http_env_response_status, 100, code);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnv, getRequestBody)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zend_class_entry *class_entry = php_http_message_body_class_entry;
+ zend_object_value ov;
+ php_http_message_body_t *body;
+ zend_class_entry *class_entry = php_http_message_body_class_entry;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry)) {
- zend_object_value ov;
- php_http_message_body_t *body = php_http_env_get_request_body(TSRMLS_C);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &class_entry), invalid_arg, return);
- if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, php_http_message_body_init(&body, NULL TSRMLS_CC), NULL TSRMLS_CC)) {
- RETVAL_OBJVAL(ov, 0);
- }
- }
- } end_error_handling();
+ body = php_http_env_get_request_body(TSRMLS_C);
+ if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_class_entry, body, NULL TSRMLS_CC)) {
+ RETVAL_OBJVAL(ov, 0);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForCode, 0, 0, 1)
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Env", php_http_env_methods);
- php_http_env_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_env_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
#ifdef PHP_HTTP_HAVE_JSON
php_http_env_register_json_handler(TSRMLS_C);
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvRequest, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
+ zval *zsg, *zqs;
- if (SUCCESS == zend_parse_parameters_none()) {
- zval *zsg, *zqs;
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC);
- obj->body = NULL;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ obj->body = NULL;
- zsg = php_http_env_get_superglobal(ZEND_STRL("_GET") TSRMLS_CC);
- MAKE_STD_ZVAL(zqs);
- object_init_ex(zqs, php_http_querystring_class_entry);
- if (SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC)) {
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), zqs TSRMLS_CC);
- }
- zval_ptr_dtor(&zqs);
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC), unexpected_val, return);
- zsg = php_http_env_get_superglobal(ZEND_STRL("_POST") TSRMLS_CC);
- MAKE_STD_ZVAL(zqs);
- object_init_ex(zqs, php_http_querystring_class_entry);
- if (SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC)) {
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), zqs TSRMLS_CC);
- }
+ zsg = php_http_env_get_superglobal(ZEND_STRL("_GET") TSRMLS_CC);
+ MAKE_STD_ZVAL(zqs);
+ object_init_ex(zqs, php_http_querystring_class_entry);
+ php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
zval_ptr_dtor(&zqs);
-
- MAKE_STD_ZVAL(zqs);
- array_init(zqs);
- if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES") TSRMLS_CC))) {
- zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg) TSRMLS_CC, grab_files, 1, zqs);
- }
-
- zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
+ return;
+ );
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), zqs TSRMLS_CC);
+ zval_ptr_dtor(&zqs);
+
+ zsg = php_http_env_get_superglobal(ZEND_STRL("_POST") TSRMLS_CC);
+ MAKE_STD_ZVAL(zqs);
+ object_init_ex(zqs, php_http_querystring_class_entry);
+ php_http_expect(SUCCESS == php_http_querystring_ctor(zqs, zsg TSRMLS_CC), unexpected_val,
zval_ptr_dtor(&zqs);
- }
- PHP_HTTP_ENV_REQUEST_OBJECT_INIT(obj);
- } end_error_handling();
+ return;
+ );
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), zqs TSRMLS_CC);
+ zval_ptr_dtor(&zqs);
+
+ MAKE_STD_ZVAL(zqs);
+ array_init(zqs);
+ if ((zsg = php_http_env_get_superglobal(ZEND_STRL("_FILES") TSRMLS_CC))) {
+ zend_hash_apply_with_arguments(Z_ARRVAL_P(zsg) TSRMLS_CC, grab_files, 1, zqs);
+ }
+ zend_update_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), zqs TSRMLS_CC);
+ zval_ptr_dtor(&zqs);
}
#define call_querystring_get(prop) \
return request;
}
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
int free_etag = 0;
return ret;
}
-PHP_HTTP_API php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
+php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *options, const char *header_str, size_t header_len, php_http_message_t *request TSRMLS_DC)
{
php_http_cache_status_t ret = PHP_HTTP_CACHE_NO;
char *header;
return 0;
}
- if (php_http_env_got_request_header(ZEND_STRL("Authorizsation"), request TSRMLS_CC)) {
+ if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request TSRMLS_CC)) {
return 0;
}
return SUCCESS;
}
-PHP_HTTP_API php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
+php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
{
zend_bool free_r;
return r;
}
-PHP_HTTP_API void php_http_env_response_dtor(php_http_env_response_t *r)
+void php_http_env_response_dtor(php_http_env_response_t *r)
{
if (r->ops->dtor) {
r->ops->dtor(r);
}
}
-PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r)
+void php_http_env_response_free(php_http_env_response_t **r)
{
if (*r) {
php_http_env_response_dtor(*r);
if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
if (Z_TYPE_P(zoption) == IS_ARRAY) {
- php_http_headers_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+ php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
}
zval_ptr_dtor(&zoption);
}
zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
zval_ptr_dtor(&zoption);
- if (Z_STRLEN_P(zoption_copy)) {
- PHP_HTTP_CHECK_CONTENT_TYPE(Z_STRVAL_P(zoption_copy), ret = FAILURE) else {
- if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
- r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
- }
+ if (Z_STRLEN_P(zoption_copy) && strchr(Z_STRVAL_P(zoption_copy), '/')) {
+ if (SUCCESS == (ret = r->ops->set_header(r, "Content-Type: %.*s", Z_STRLEN_P(zoption_copy), Z_STRVAL_P(zoption_copy)))) {
+ r->content.type = estrndup(Z_STRVAL_P(zoption_copy), Z_STRLEN_P(zoption_copy));
}
}
zval_ptr_dtor(&zoption_copy);
&& 2 == php_http_array_list(Z_ARRVAL_PP(range) TSRMLS_CC, 2, &begin, &end)
) {
/* send chunk */
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
- php_http_env_response_send_done(r);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ if (ret == SUCCESS) {
+ ret = php_http_env_response_send_done(r);
+ }
zend_hash_destroy(&r->range.values);
- ret = SUCCESS;
} else {
/* this should never happen */
zend_hash_destroy(&r->range.values);
Z_LVAL_PP(end),
r->content.length
);
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, Z_LVAL_PP(begin), Z_LVAL_PP(end) - Z_LVAL_PP(begin) + 1);
}
}
- php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
- php_http_env_response_send_done(r);
+
+ if (ret == SUCCESS) {
+ php_http_buffer_appendf(r->buffer, PHP_HTTP_CRLF "--%s--", r->range.boundary);
+ ret = php_http_env_response_send_done(r);
+ }
zend_hash_destroy(&r->range.values);
}
} else {
- php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, 0, 0);
- php_http_env_response_send_done(r);
+ ret = php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_env_response_send_data, r, 0, 0);
+ if (ret == SUCCESS) {
+ ret = php_http_env_response_send_done(r);
+ }
}
}
return ret;
}
-PHP_HTTP_API STATUS php_http_env_response_send(php_http_env_response_t *r)
+STATUS php_http_env_response_send(php_http_env_response_t *r)
{
php_http_message_t *request;
php_http_message_body_t *body;
}
if (SUCCESS != php_http_env_response_send_head(r, request)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response headers");
return FAILURE;
}
if (SUCCESS != php_http_env_response_send_body(r)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to send response body");
return FAILURE;
}
if (SUCCESS != r->ops->finish(r)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to finish response");
return FAILURE;
}
php_http_env_response_sapi_finish
};
-PHP_HTTP_API php_http_env_response_ops_t *php_http_env_response_get_sapi_ops(void)
+php_http_env_response_ops_t *php_http_env_response_get_sapi_ops(void)
{
return &php_http_env_response_sapi_ops;
}
php_http_env_response_stream_finish
};
-PHP_HTTP_API php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
+php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
{
return &php_http_env_response_stream_ops;
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpEnvResponse, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters_none()) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC);
- } end_error_handling();
- }
- PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
- } end_error_handling();
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1)
{
zval *env_req = NULL;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry)) {
- set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1)
char *ct_str = NULL;
int ct_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len)) {
- set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1)
{
zval *zdisposition;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition)) {
- zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return);
+
+ zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1)
{
long ce;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce)) {
- set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1)
char *cc_str = NULL;
int cc_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len)) {
- set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &cc_str, &cc_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1)
{
long last_modified;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified)) {
- set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &last_modified), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified, 0, 0, 0)
char *etag_str = NULL;
int etag_len = 0;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len)) {
- set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &etag_str, &etag_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag, 0, 0, 0)
long chunk_size;
double delay = 1;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay)) {
- set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
- set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
- RETVAL_ZVAL(getThis(), 1, 0);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|d", &chunk_size, &delay), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0 TSRMLS_CC);
+ set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send, 0, 0, 0)
#include <ext/standard/sha1.h>
#include <ext/standard/md5.h>
-PHP_HTTP_API php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC)
+php_http_etag_t *php_http_etag_init(const char *mode TSRMLS_DC)
{
void *ctx;
php_http_etag_t *e;
return e;
}
-PHP_HTTP_API char *php_http_etag_finish(php_http_etag_t *e)
+char *php_http_etag_finish(php_http_etag_t *e)
{
unsigned char digest[128] = {0};
char *etag = NULL;
return etag;
}
-PHP_HTTP_API size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len)
+size_t php_http_etag_update(php_http_etag_t *e, const char *data_ptr, size_t data_len)
{
if (!strcasecmp(e->mode, "crc32b")) {
uint i, c = *((uint *) e->ctx);
#include "php_http_api.h"
-#include <zend_exceptions.h>
+#include <ext/spl/spl_exceptions.h>
#ifndef PHP_HTTP_DBG_EXCEPTIONS
# define PHP_HTTP_DBG_EXCEPTIONS 0
}
#endif
-zend_class_entry *php_http_exception_class_entry;
+zend_class_entry *php_http_exception_interface_class_entry;
+zend_class_entry *php_http_exception_runtime_class_entry;
+zend_class_entry *php_http_exception_unexpected_val_class_entry;
+zend_class_entry *php_http_exception_bad_method_call_class_entry;
+zend_class_entry *php_http_exception_invalid_arg_class_entry;
+zend_class_entry *php_http_exception_bad_header_class_entry;
+zend_class_entry *php_http_exception_bad_url_class_entry;
+zend_class_entry *php_http_exception_bad_message_class_entry;
+zend_class_entry *php_http_exception_bad_conversion_class_entry;
+zend_class_entry *php_http_exception_bad_querystring_class_entry;
PHP_MINIT_FUNCTION(http_exception)
{
- zend_class_entry ce = {0};
+ zend_class_entry *cep, ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Exception", NULL);
- php_http_exception_class_entry = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_UNKNOWN"), PHP_HTTP_E_UNKNOWN TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RUNTIME"), PHP_HTTP_E_RUNTIME TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_INVALID_PARAM"), PHP_HTTP_E_INVALID_PARAM TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_HEADER"), PHP_HTTP_E_HEADER TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MALFORMED_HEADERS"), PHP_HTTP_E_MALFORMED_HEADERS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE"), PHP_HTTP_E_MESSAGE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_TYPE"), PHP_HTTP_E_MESSAGE_TYPE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_MESSAGE_BODY"), PHP_HTTP_E_MESSAGE_BODY TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_ENCODING"), PHP_HTTP_E_ENCODING TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_CLIENT"), PHP_HTTP_E_CLIENT TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_CLIENT_POOL"), PHP_HTTP_E_CLIENT_POOL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_CLIENT_DATASHARE"), PHP_HTTP_E_CLIENT_DATASHARE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_SOCKET"), PHP_HTTP_E_SOCKET TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_RESPONSE"), PHP_HTTP_E_RESPONSE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_URL"), PHP_HTTP_E_URL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_QUERYSTRING"), PHP_HTTP_E_QUERYSTRING TSRMLS_CC);
- zend_declare_class_constant_long(php_http_exception_class_entry, ZEND_STRL("E_COOKIE"), PHP_HTTP_E_COOKIE TSRMLS_CC);
+ php_http_exception_interface_class_entry = zend_register_internal_interface(&ce TSRMLS_CC);
+ /*
+ * Would be great to only have a few exceptions and rather more identifying
+ * error codes, but zend_replace_error_handling() does not accept any codes.
+ */
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "RuntimeException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_runtime_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "UnexpectedValueException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_UnexpectedValueException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_unexpected_val_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMethodCallException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_BadMethodCallException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_method_call_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "InvalidArgumentException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_InvalidArgumentException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_invalid_arg_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadHeaderException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_header_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadUrlException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_url_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadMessageException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_message_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadConversionException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_conversion_class_entry = cep;
+
+ memset(&ce, 0, sizeof(ce));
+ INIT_NS_CLASS_ENTRY(ce, "http\\Exception", "BadQueryStringException", NULL);
+ cep = zend_register_internal_class_ex(&ce, spl_ce_DomainException, NULL TSRMLS_CC);
+ zend_class_implements(cep TSRMLS_CC, 1, php_http_exception_interface_class_entry);
+ php_http_exception_bad_querystring_class_entry = cep;
+
#if PHP_HTTP_DBG_EXCEPTIONS
zend_throw_exception_hook = php_http_exception_hook;
#endif
#ifndef PHP_HTTP_EXCEPTION_H
#define PHP_HTTP_EXCEPTION_H
-PHP_HTTP_API zend_class_entry *php_http_exception_class_entry;
+/* short hand for zend_throw_exception_ex */
+#define php_http_throw(e, fmt, ...) \
+ zend_throw_exception_ex(php_http_exception_ ##e## _class_entry, 0 TSRMLS_CC, fmt, __VA_ARGS__)
+
+/* wrap a call with replaced zend_error_handling */
+#define php_http_expect(test, e, fail) \
+ do { \
+ zend_error_handling __zeh; \
+ zend_replace_error_handling(EH_THROW, php_http_exception_ ##e## _class_entry, &__zeh TSRMLS_CC); \
+ if (!(test)) { \
+ zend_restore_error_handling(&__zeh TSRMLS_CC); \
+ fail; \
+ } \
+ zend_restore_error_handling(&__zeh TSRMLS_CC); \
+ } while(0)
+
+PHP_HTTP_API zend_class_entry *php_http_exception_interface_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_runtime_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_unexpected_val_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_method_call_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_invalid_arg_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_header_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_url_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_message_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_conversion_class_entry;
+PHP_HTTP_API zend_class_entry *php_http_exception_bad_querystring_class_entry;
+
PHP_MINIT_FUNCTION(http_exception);
#endif
--- /dev/null
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#include "php_http_api.h"
+
+STATUS php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC)
+{
+ php_http_header_parser_t ctx;
+ php_http_buffer_t buf;
+ php_http_header_parser_state_t rs;
+
+ if (!php_http_buffer_from_string_ex(&buf, header, length)) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not allocate buffer");
+ return FAILURE;
+ }
+
+ if (!php_http_header_parser_init(&ctx TSRMLS_CC)) {
+ php_http_buffer_dtor(&buf);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not initialize header parser");
+ return FAILURE;
+ }
+
+ rs = php_http_header_parser_parse(&ctx, &buf, PHP_HTTP_HEADER_PARSER_CLEANUP, headers, callback_func, callback_data);
+ php_http_header_parser_dtor(&ctx);
+ php_http_buffer_dtor(&buf);
+
+ if (rs == PHP_HTTP_HEADER_PARSER_STATE_FAILURE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse headers");
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
+void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC)
+{
+ HashPosition pos1, pos2;
+ php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval **header, **single_header;
+
+ FOREACH_HASH_KEYVAL(pos1, headers, key, header) {
+ if (key.type == HASH_KEY_IS_STRING) {
+ if (key.len == sizeof("Set-Cookie") && !strcasecmp(key.str, "Set-Cookie") && Z_TYPE_PP(header) == IS_ARRAY) {
+ FOREACH_VAL(pos2, *header, single_header) {
+ if (Z_TYPE_PP(single_header) == IS_ARRAY) {
+ php_http_cookie_list_t *cookie = php_http_cookie_list_from_struct(NULL, *single_header TSRMLS_CC);
+
+ if (cookie) {
+ char *buf;
+ size_t len;
+
+ php_http_cookie_list_to_string(cookie, &buf, &len);
+ cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", buf);
+ php_http_cookie_list_free(&cookie);
+ efree(buf);
+ }
+ } else {
+ zval *strval = php_http_header_value_to_string(*single_header TSRMLS_CC);
+
+ cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", Z_STRVAL_P(strval));
+ zval_ptr_dtor(&strval);
+ }
+ }
+ } else {
+ zval *strval = php_http_header_value_to_string(*header TSRMLS_CC);
+
+ cb(cb_arg, crlf ? "%s: %s" PHP_HTTP_CRLF : "%s: %s", key.str, Z_STRVAL_P(strval));
+ zval_ptr_dtor(&strval);
+ }
+ }
+ }
+}
+
+void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC)
+{
+ php_http_header_to_callback(headers, 1, (php_http_pass_format_callback_t) php_http_buffer_appendf, str TSRMLS_CC);
+}
+
+zval *php_http_header_value_to_string(zval *header TSRMLS_DC)
+{
+ zval *ret;
+
+ if (Z_TYPE_P(header) == IS_BOOL) {
+ MAKE_STD_ZVAL(ret);
+ ZVAL_STRING(ret, Z_BVAL_P(header) ? "true" : "false", 1);
+ } else if (Z_TYPE_P(header) == IS_ARRAY) {
+ zval **val;
+ HashPosition pos;
+ php_http_buffer_t str;
+
+ php_http_buffer_init(&str);
+ MAKE_STD_ZVAL(ret);
+ FOREACH_VAL(pos,header, val) {
+ zval *strval = php_http_header_value_to_string(*val TSRMLS_CC);
+
+ php_http_buffer_appendf(&str, str.used ? ", %s":"%s", Z_STRVAL_P(strval));
+ zval_ptr_dtor(&strval);
+ }
+ php_http_buffer_fix(&str);
+ ZVAL_STRINGL(ret, str.data, str.used, 0);
+ } else {
+ ret = php_http_zsep(1, IS_STRING, header);
+ }
+
+ return ret;
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader___construct, 0, 0, 0)
+ ZEND_ARG_INFO(0, name)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, __construct)
+{
+ char *name_str = NULL, *value_str = NULL;
+ int name_len = 0, value_len = 0;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", &name_str, &name_len, &value_str, &value_len), invalid_arg, return);
+
+ if (name_str && name_len) {
+ char *pretty_str = estrndup(name_str, name_len);
+ zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len TSRMLS_CC);
+ efree(pretty_str);
+ }
+ if (value_str && value_len) {
+ zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("value"), value_str, value_len TSRMLS_CC);
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_serialize, 0, 0, 0)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, serialize)
+{
+ if (SUCCESS == zend_parse_parameters_none()) {
+ php_http_buffer_t buf;
+ zval *zname, *zvalue;
+
+ php_http_buffer_init(&buf);
+ zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
+ php_http_buffer_append(&buf, Z_STRVAL_P(zname), Z_STRLEN_P(zname));
+ zval_ptr_dtor(&zname);
+ zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
+ if (Z_STRLEN_P(zvalue)) {
+ php_http_buffer_appends(&buf, ": ");
+ php_http_buffer_append(&buf, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue));
+ } else {
+ php_http_buffer_appends(&buf, ":");
+ }
+ zval_ptr_dtor(&zvalue);
+
+ RETURN_PHP_HTTP_BUFFER_VAL(&buf);
+ }
+ RETURN_EMPTY_STRING();
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_unserialize, 0, 0, 1)
+ ZEND_ARG_INFO(0, serialized)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, unserialize)
+{
+ char *serialized_str;
+ int serialized_len;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized_str, &serialized_len)) {
+ HashTable ht;
+
+ zend_hash_init(&ht, 1, NULL, ZVAL_PTR_DTOR, 0);
+ if (SUCCESS == php_http_header_parse(serialized_str, serialized_len, &ht, NULL, NULL TSRMLS_CC)) {
+ if (zend_hash_num_elements(&ht)) {
+ zval **val, *cpy;
+ char *str;
+ uint len;
+ ulong idx;
+
+ zend_hash_internal_pointer_reset(&ht);
+ switch (zend_hash_get_current_key_ex(&ht, &str, &len, &idx, 0, NULL)) {
+ case HASH_KEY_IS_STRING:
+ zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), str, len - 1 TSRMLS_CC);
+ break;
+ case HASH_KEY_IS_LONG:
+ zend_update_property_long(php_http_header_class_entry, getThis(), ZEND_STRL("name"), idx TSRMLS_CC);
+ break;
+ default:
+ break;
+ }
+ zend_hash_get_current_data(&ht, (void *) &val);
+ cpy = php_http_zsep(1, IS_STRING, *val);
+ zend_update_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), cpy TSRMLS_CC);
+ zval_ptr_dtor(&cpy);
+ }
+ }
+ zend_hash_destroy(&ht);
+ }
+
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_match, 0, 0, 1)
+ ZEND_ARG_INFO(0, value)
+ ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, match)
+{
+ char *val_str;
+ int val_len;
+ long flags = PHP_HTTP_MATCH_LOOSE;
+ zval *zvalue;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &val_str, &val_len, &flags)) {
+ return;
+ }
+
+ zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
+ RETVAL_BOOL(php_http_match(Z_STRVAL_P(zvalue), val_str, flags));
+ zval_ptr_dtor(&zvalue);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_negotiate, 0, 0, 1)
+ ZEND_ARG_INFO(0, supported)
+ ZEND_ARG_INFO(1, result)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, negotiate)
+{
+ HashTable *supported, *rs;
+ zval *zname, *zvalue, *rs_array = NULL;
+ char *sep_str = NULL;
+ size_t sep_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
+ return;
+ }
+ if (rs_array) {
+ zval_dtor(rs_array);
+ array_init(rs_array);
+ }
+
+ zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
+ if (!strcasecmp(Z_STRVAL_P(zname), "Accept")) {
+ sep_str = "/";
+ sep_len = 1;
+ } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
+ sep_str = "-";
+ sep_len = 1;
+ }
+ zval_ptr_dtor(&zname);
+
+ zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
+ if ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
+ } else {
+ PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
+ }
+ zval_ptr_dtor(&zvalue);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_getParams, 0, 0, 0)
+ ZEND_ARG_INFO(0, param_sep)
+ ZEND_ARG_INFO(0, arg_sep)
+ ZEND_ARG_INFO(0, val_sep)
+ ZEND_ARG_INFO(0, flags)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, getParams)
+{
+ zval zctor, *zparams_obj, **zargs = NULL;
+
+ INIT_PZVAL(&zctor);
+ ZVAL_STRINGL(&zctor, "__construct", lenof("__construct"), 0);
+
+ MAKE_STD_ZVAL(zparams_obj);
+ object_init_ex(zparams_obj, php_http_params_class_entry);
+
+ zargs = (zval **) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval *));
+ zargs[0] = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("value"), 0 TSRMLS_CC);
+ if (ZEND_NUM_ARGS()) {
+ zend_get_parameters_array(ZEND_NUM_ARGS(), ZEND_NUM_ARGS(), &zargs[1]);
+ }
+
+ if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs TSRMLS_CC)) {
+ RETVAL_ZVAL(zparams_obj, 0, 1);
+ }
+
+ if (zargs) {
+ efree(zargs);
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_parse, 0, 0, 1)
+ ZEND_ARG_INFO(0, string)
+ ZEND_ARG_INFO(0, header_class)
+ZEND_END_ARG_INFO();
+PHP_METHOD(HttpHeader, parse)
+{
+ char *header_str;
+ int header_len;
+ zend_class_entry *ce = NULL;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C", &header_str, &header_len, &ce)) {
+ array_init(return_value);
+
+ if (SUCCESS != php_http_header_parse(header_str, header_len, Z_ARRVAL_P(return_value), NULL, NULL TSRMLS_CC)) {
+ zval_dtor(return_value);
+ RETURN_FALSE;
+ } else {
+ if (ce && instanceof_function(ce, php_http_header_class_entry TSRMLS_CC)) {
+ HashPosition pos;
+ php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
+ zval **val;
+
+ FOREACH_KEYVAL(pos, return_value, key, val) {
+ zval *zho, *zkey, *zvalue;
+
+ Z_ADDREF_PP(val);
+ zvalue = *val;
+
+ MAKE_STD_ZVAL(zkey);
+ if (key.type == HASH_KEY_IS_LONG) {
+ ZVAL_LONG(zkey, key.num);
+ } else {
+ ZVAL_STRINGL(zkey, key.str, key.len - 1, 1);
+ }
+
+ MAKE_STD_ZVAL(zho);
+ object_init_ex(zho, ce);
+ zend_call_method_with_2_params(&zho, ce, NULL, "__construct", NULL, zkey, zvalue);
+
+ if (key.type == HASH_KEY_IS_LONG) {
+ zend_hash_index_update(Z_ARRVAL_P(return_value), key.num, (void *) &zho, sizeof(zval *), NULL);
+ } else {
+ zend_hash_update(Z_ARRVAL_P(return_value), key.str, key.len, (void *) &zho, sizeof(zval *), NULL);
+ }
+
+ zval_ptr_dtor(&zvalue);
+ zval_ptr_dtor(&zkey);
+ }
+ }
+ }
+ }
+}
+
+static zend_function_entry php_http_header_methods[] = {
+ PHP_ME(HttpHeader, __construct, ai_HttpHeader___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
+ PHP_ME(HttpHeader, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
+ ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
+ ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpHeader, match, ai_HttpHeader_match, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpHeader, negotiate, ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpHeader, getParams, ai_HttpHeader_getParams, ZEND_ACC_PUBLIC)
+ PHP_ME(HttpHeader, parse, ai_HttpHeader_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
+ EMPTY_FUNCTION_ENTRY
+};
+
+zend_class_entry *php_http_header_class_entry;
+
+PHP_MINIT_FUNCTION(http_header)
+{
+ zend_class_entry ce = {0};
+
+ INIT_NS_CLASS_ENTRY(ce, "http", "Header", php_http_header_methods);
+ php_http_header_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ zend_class_implements(php_http_header_class_entry TSRMLS_CC, 1, zend_ce_serializable);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_LOOSE"), PHP_HTTP_MATCH_LOOSE TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_CASE"), PHP_HTTP_MATCH_CASE TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_WORD"), PHP_HTTP_MATCH_WORD TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_FULL"), PHP_HTTP_MATCH_FULL TSRMLS_CC);
+ zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_STRICT"), PHP_HTTP_MATCH_STRICT TSRMLS_CC);
+ zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
+ zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("value"), ZEND_ACC_PUBLIC TSRMLS_CC);
+
+ return SUCCESS;
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+
--- /dev/null
+/*
+ +--------------------------------------------------------------------+
+ | PECL :: http |
+ +--------------------------------------------------------------------+
+ | Redistribution and use in source and binary forms, with or without |
+ | modification, are permitted provided that the conditions mentioned |
+ | in the accompanying LICENSE file are met. |
+ +--------------------------------------------------------------------+
+ | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
+ +--------------------------------------------------------------------+
+*/
+
+#ifndef PHP_HTTP_HEADERS_H
+#define PHP_HTTP_HEADERS_H
+
+#include "php_http_info.h"
+
+PHP_HTTP_API STATUS php_http_header_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC);
+
+PHP_HTTP_API void php_http_header_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC);
+PHP_HTTP_API void php_http_header_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC);
+
+PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC);
+
+PHP_HTTP_API zend_class_entry *php_http_header_class_entry;
+PHP_MINIT_FUNCTION(http_header);
+
+#endif
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
+ */
+
{PHP_HTTP_HEADER_PARSER_STATE_DONE, 0}
};
-PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC)
+php_http_header_parser_t *php_http_header_parser_init(php_http_header_parser_t *parser TSRMLS_DC)
{
if (!parser) {
parser = emalloc(sizeof(*parser));
return parser;
}
-PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_push(php_http_header_parser_t *parser, unsigned argc, ...)
+php_http_header_parser_state_t php_http_header_parser_state_push(php_http_header_parser_t *parser, unsigned argc, ...)
{
va_list va_args;
unsigned i;
return state;
}
-PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_is(php_http_header_parser_t *parser)
+php_http_header_parser_state_t php_http_header_parser_state_is(php_http_header_parser_t *parser)
{
php_http_header_parser_state_t *state;
return PHP_HTTP_HEADER_PARSER_STATE_START;
}
-PHP_HTTP_API php_http_header_parser_state_t php_http_header_parser_state_pop(php_http_header_parser_t *parser)
+php_http_header_parser_state_t php_http_header_parser_state_pop(php_http_header_parser_t *parser)
{
php_http_header_parser_state_t state, *state_ptr;
if (SUCCESS == zend_stack_top(&parser->stack, (void *) &state_ptr)) {
return PHP_HTTP_HEADER_PARSER_STATE_START;
}
-PHP_HTTP_API void php_http_header_parser_dtor(php_http_header_parser_t *parser)
+void php_http_header_parser_dtor(php_http_header_parser_t *parser)
{
zend_stack_destroy(&parser->stack);
php_http_info_dtor(&parser->info);
STR_FREE(parser->_val.str);
}
-PHP_HTTP_API void php_http_header_parser_free(php_http_header_parser_t **parser)
+void php_http_header_parser_free(php_http_header_parser_t **parser)
{
if (*parser) {
php_http_header_parser_dtor(*parser);
}
}
-PHP_HTTP_API STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg)
+STATUS php_http_header_parser_parse(php_http_header_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, HashTable *headers, php_http_info_callback_t callback_func, void *callback_arg)
{
TSRMLS_FETCH_FROM_CTX(parser->ts);
+++ /dev/null
-/*
- +--------------------------------------------------------------------+
- | PECL :: http |
- +--------------------------------------------------------------------+
- | Redistribution and use in source and binary forms, with or without |
- | modification, are permitted provided that the conditions mentioned |
- | in the accompanying LICENSE file are met. |
- +--------------------------------------------------------------------+
- | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
- +--------------------------------------------------------------------+
-*/
-
-#include "php_http_api.h"
-
-PHP_HTTP_API STATUS php_http_headers_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC)
-{
- php_http_header_parser_t ctx;
- php_http_buffer_t buf;
- php_http_header_parser_state_t rs;
-
- if (!php_http_buffer_from_string_ex(&buf, header, length)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not allocate buffer");
- return FAILURE;
- }
-
- if (!php_http_header_parser_init(&ctx TSRMLS_CC)) {
- php_http_buffer_dtor(&buf);
- php_http_error(HE_WARNING, PHP_HTTP_E_HEADER, "Could not initialize header parser");
- return FAILURE;
- }
-
- rs = php_http_header_parser_parse(&ctx, &buf, PHP_HTTP_HEADER_PARSER_CLEANUP, headers, callback_func, callback_data);
- php_http_header_parser_dtor(&ctx);
- php_http_buffer_dtor(&buf);
-
- if (rs == PHP_HTTP_HEADER_PARSER_STATE_FAILURE) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MALFORMED_HEADERS, "Could not parse headers");
- return FAILURE;
- }
-
- return SUCCESS;
-}
-
-PHP_HTTP_API void php_http_headers_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC)
-{
- HashPosition pos1, pos2;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **header, **single_header;
-
- FOREACH_HASH_KEYVAL(pos1, headers, key, header) {
- if (key.type == HASH_KEY_IS_STRING) {
- if (key.len == sizeof("Set-Cookie") && !strcasecmp(key.str, "Set-Cookie") && Z_TYPE_PP(header) == IS_ARRAY) {
- FOREACH_VAL(pos2, *header, single_header) {
- if (Z_TYPE_PP(single_header) == IS_ARRAY) {
- php_http_cookie_list_t *cookie = php_http_cookie_list_from_struct(NULL, *single_header TSRMLS_CC);
-
- if (cookie) {
- char *buf;
- size_t len;
-
- php_http_cookie_list_to_string(cookie, &buf, &len);
- cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", buf);
- php_http_cookie_list_free(&cookie);
- efree(buf);
- }
- } else {
- zval *strval = php_http_header_value_to_string(*single_header TSRMLS_CC);
-
- cb(cb_arg, crlf ? "Set-Cookie: %s" PHP_HTTP_CRLF : "Set-Cookie: %s", Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
- }
- }
- } else {
- zval *strval = php_http_header_value_to_string(*header TSRMLS_CC);
-
- cb(cb_arg, crlf ? "%s: %s" PHP_HTTP_CRLF : "%s: %s", key.str, Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
- }
- }
- }
-}
-
-PHP_HTTP_API void php_http_headers_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC)
-{
- php_http_headers_to_callback(headers, 1, (php_http_pass_format_callback_t) php_http_buffer_appendf, str TSRMLS_CC);
-}
-
-PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC)
-{
- zval *ret;
-
- if (Z_TYPE_P(header) == IS_BOOL) {
- MAKE_STD_ZVAL(ret);
- ZVAL_STRING(ret, Z_BVAL_P(header) ? "true" : "false", 1);
- } else if (Z_TYPE_P(header) == IS_ARRAY) {
- zval **val;
- HashPosition pos;
- php_http_buffer_t str;
-
- php_http_buffer_init(&str);
- MAKE_STD_ZVAL(ret);
- FOREACH_VAL(pos,header, val) {
- zval *strval = php_http_header_value_to_string(*val TSRMLS_CC);
-
- php_http_buffer_appendf(&str, str.used ? ", %s":"%s", Z_STRVAL_P(strval));
- zval_ptr_dtor(&strval);
- }
- php_http_buffer_fix(&str);
- ZVAL_STRINGL(ret, str.data, str.used, 0);
- } else {
- ret = php_http_zsep(1, IS_STRING, header);
- }
-
- return ret;
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader___construct, 0, 0, 0)
- ZEND_ARG_INFO(0, name)
- ZEND_ARG_INFO(0, value)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, __construct)
-{
- char *name_str = NULL, *value_str = NULL;
- int name_len = 0, value_len = 0;
-
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!s!", &name_str, &name_len, &value_str, &value_len)) {
- if (name_str && name_len) {
- char *pretty_str = estrndup(name_str, name_len);
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), php_http_pretty_key(pretty_str, name_len, 1, 1), name_len TSRMLS_CC);
- efree(pretty_str);
- }
- if (value_str && value_len) {
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("value"), value_str, value_len TSRMLS_CC);
- }
- }
- } end_error_handling();
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_serialize, 0, 0, 0)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, serialize)
-{
- php_http_buffer_t buf;
- zval *zname, *zvalue;
-
- php_http_buffer_init(&buf);
- zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
- php_http_buffer_append(&buf, Z_STRVAL_P(zname), Z_STRLEN_P(zname));
- zval_ptr_dtor(&zname);
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- if (Z_STRLEN_P(zvalue)) {
- php_http_buffer_appends(&buf, ": ");
- php_http_buffer_append(&buf, Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue));
- } else {
- php_http_buffer_appends(&buf, ":");
- }
- zval_ptr_dtor(&zvalue);
-
- RETURN_PHP_HTTP_BUFFER_VAL(&buf);
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_unserialize, 0, 0, 1)
- ZEND_ARG_INFO(0, serialized)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, unserialize)
-{
- char *serialized_str;
- int serialized_len;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized_str, &serialized_len)) {
- HashTable ht;
-
- zend_hash_init(&ht, 1, NULL, ZVAL_PTR_DTOR, 0);
- if (SUCCESS == php_http_headers_parse(serialized_str, serialized_len, &ht, NULL, NULL TSRMLS_CC)) {
- if (zend_hash_num_elements(&ht)) {
- zval **val, *cpy;
- char *str;
- uint len;
- ulong idx;
-
- zend_hash_internal_pointer_reset(&ht);
- switch (zend_hash_get_current_key_ex(&ht, &str, &len, &idx, 0, NULL)) {
- case HASH_KEY_IS_STRING:
- zend_update_property_stringl(php_http_header_class_entry, getThis(), ZEND_STRL("name"), str, len - 1 TSRMLS_CC);
- break;
- case HASH_KEY_IS_LONG:
- zend_update_property_long(php_http_header_class_entry, getThis(), ZEND_STRL("name"), idx TSRMLS_CC);
- break;
- default:
- break;
- }
- zend_hash_get_current_data(&ht, (void *) &val);
- cpy = php_http_zsep(1, IS_STRING, *val);
- zend_update_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), cpy TSRMLS_CC);
- zval_ptr_dtor(&cpy);
- }
- }
- zend_hash_destroy(&ht);
- }
-
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_match, 0, 0, 1)
- ZEND_ARG_INFO(0, value)
- ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, match)
-{
- char *val_str;
- int val_len;
- long flags = PHP_HTTP_MATCH_LOOSE;
- zval *zvalue;
-
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sl", &val_str, &val_len, &flags)) {
- return;
- }
-
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- RETVAL_BOOL(php_http_match(Z_STRVAL_P(zvalue), val_str, flags));
- zval_ptr_dtor(&zvalue);
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_negotiate, 0, 0, 1)
- ZEND_ARG_INFO(0, supported)
- ZEND_ARG_INFO(1, result)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, negotiate)
-{
- HashTable *supported, *rs;
- zval *zname, *zvalue, *rs_array = NULL;
- char *sep_str = NULL;
- size_t sep_len = 0;
-
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "H|z", &supported, &rs_array)) {
- return;
- }
- if (rs_array) {
- zval_dtor(rs_array);
- array_init(rs_array);
- }
-
- zname = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("name"), 0 TSRMLS_CC));
- if (!strcasecmp(Z_STRVAL_P(zname), "Accept")) {
- sep_str = "/";
- sep_len = 1;
- } else if (!strcasecmp(Z_STRVAL_P(zname), "Accept-Language")) {
- sep_str = "-";
- sep_len = 1;
- }
- zval_ptr_dtor(&zname);
-
- zvalue = php_http_ztyp(IS_STRING, zend_read_property(php_http_header_class_entry, getThis(), ZEND_STRL("value"), 0 TSRMLS_CC));
- if ((rs = php_http_negotiate(Z_STRVAL_P(zvalue), Z_STRLEN_P(zvalue), supported, sep_str, sep_len TSRMLS_CC))) {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
- } else {
- PHP_HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
- }
- zval_ptr_dtor(&zvalue);
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_getParams, 0, 0, 0)
- ZEND_ARG_INFO(0, param_sep)
- ZEND_ARG_INFO(0, arg_sep)
- ZEND_ARG_INFO(0, val_sep)
- ZEND_ARG_INFO(0, flags)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, getParams)
-{
- zval zctor, *zparams_obj, **zargs = NULL;
-
- INIT_PZVAL(&zctor);
- ZVAL_STRINGL(&zctor, "__construct", lenof("__construct"), 0);
-
- MAKE_STD_ZVAL(zparams_obj);
- object_init_ex(zparams_obj, php_http_params_class_entry);
-
- zargs = (zval **) ecalloc(ZEND_NUM_ARGS()+1, sizeof(zval *));
- zargs[0] = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("value"), 0 TSRMLS_CC);
- if (ZEND_NUM_ARGS()) {
- zend_get_parameters_array(ZEND_NUM_ARGS(), ZEND_NUM_ARGS(), &zargs[1]);
- }
-
- if (SUCCESS == call_user_function(NULL, &zparams_obj, &zctor, return_value, ZEND_NUM_ARGS()+1, zargs TSRMLS_CC)) {
- RETVAL_ZVAL(zparams_obj, 0, 1);
- }
-
- if (zargs) {
- efree(zargs);
- }
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_parse, 0, 0, 1)
- ZEND_ARG_INFO(0, string)
- ZEND_ARG_INFO(0, header_class)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpHeader, parse)
-{
- char *header_str;
- int header_len;
- zend_class_entry *ce = NULL;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|C", &header_str, &header_len, &ce)) {
- array_init(return_value);
-
- if (SUCCESS != php_http_headers_parse(header_str, header_len, Z_ARRVAL_P(return_value), NULL, NULL TSRMLS_CC)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MALFORMED_HEADERS, "Could not parse headers");
- zval_dtor(return_value);
- RETVAL_NULL();
- } else {
- if (ce && instanceof_function(ce, php_http_header_class_entry TSRMLS_CC)) {
- HashPosition pos;
- php_http_array_hashkey_t key = php_http_array_hashkey_init(0);
- zval **val;
-
- FOREACH_KEYVAL(pos, return_value, key, val) {
- zval *zho, *zkey, *zvalue;
-
- Z_ADDREF_PP(val);
- zvalue = *val;
-
- MAKE_STD_ZVAL(zkey);
- if (key.type == HASH_KEY_IS_LONG) {
- ZVAL_LONG(zkey, key.num);
- } else {
- ZVAL_STRINGL(zkey, key.str, key.len - 1, 1);
- }
-
- MAKE_STD_ZVAL(zho);
- object_init_ex(zho, ce);
- zend_call_method_with_2_params(&zho, ce, NULL, "__construct", NULL, zkey, zvalue);
-
- if (key.type == HASH_KEY_IS_LONG) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), key.num, (void *) &zho, sizeof(zval *), NULL);
- } else {
- zend_hash_update(Z_ARRVAL_P(return_value), key.str, key.len, (void *) &zho, sizeof(zval *), NULL);
- }
-
- zval_ptr_dtor(&zvalue);
- zval_ptr_dtor(&zkey);
- }
- }
- }
- }
-}
-
-static zend_function_entry php_http_header_methods[] = {
- PHP_ME(HttpHeader, __construct, ai_HttpHeader___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
- PHP_ME(HttpHeader, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
- ZEND_MALIAS(HttpHeader, __toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
- ZEND_MALIAS(HttpHeader, toString, serialize, ai_HttpHeader_serialize, ZEND_ACC_PUBLIC)
- PHP_ME(HttpHeader, unserialize, ai_HttpHeader_unserialize, ZEND_ACC_PUBLIC)
- PHP_ME(HttpHeader, match, ai_HttpHeader_match, ZEND_ACC_PUBLIC)
- PHP_ME(HttpHeader, negotiate, ai_HttpHeader_negotiate, ZEND_ACC_PUBLIC)
- PHP_ME(HttpHeader, getParams, ai_HttpHeader_getParams, ZEND_ACC_PUBLIC)
- PHP_ME(HttpHeader, parse, ai_HttpHeader_parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
- EMPTY_FUNCTION_ENTRY
-};
-
-zend_class_entry *php_http_header_class_entry;
-
-PHP_MINIT_FUNCTION(http_header)
-{
- zend_class_entry ce = {0};
-
- INIT_NS_CLASS_ENTRY(ce, "http", "Header", php_http_header_methods);
- php_http_header_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
- zend_class_implements(php_http_header_class_entry TSRMLS_CC, 1, zend_ce_serializable);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_LOOSE"), PHP_HTTP_MATCH_LOOSE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_CASE"), PHP_HTTP_MATCH_CASE TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_WORD"), PHP_HTTP_MATCH_WORD TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_FULL"), PHP_HTTP_MATCH_FULL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_header_class_entry, ZEND_STRL("MATCH_STRICT"), PHP_HTTP_MATCH_STRICT TSRMLS_CC);
- zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("name"), ZEND_ACC_PUBLIC TSRMLS_CC);
- zend_declare_property_null(php_http_header_class_entry, ZEND_STRL("value"), ZEND_ACC_PUBLIC TSRMLS_CC);
-
- return SUCCESS;
-}
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
-
+++ /dev/null
-/*
- +--------------------------------------------------------------------+
- | PECL :: http |
- +--------------------------------------------------------------------+
- | Redistribution and use in source and binary forms, with or without |
- | modification, are permitted provided that the conditions mentioned |
- | in the accompanying LICENSE file are met. |
- +--------------------------------------------------------------------+
- | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
- +--------------------------------------------------------------------+
-*/
-
-#ifndef PHP_HTTP_HEADERS_H
-#define PHP_HTTP_HEADERS_H
-
-#include "php_http_info.h"
-
-PHP_HTTP_API STATUS php_http_headers_parse(const char *header, size_t length, HashTable *headers, php_http_info_callback_t callback_func, void **callback_data TSRMLS_DC);
-
-PHP_HTTP_API void php_http_headers_to_callback(HashTable *headers, zend_bool crlf, php_http_pass_format_callback_t cb, void *cb_arg TSRMLS_DC);
-PHP_HTTP_API void php_http_headers_to_string(php_http_buffer_t *str, HashTable *headers TSRMLS_DC);
-
-PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC);
-
-PHP_HTTP_API zend_class_entry *php_http_header_class_entry;
-PHP_MINIT_FUNCTION(http_header);
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: noet sw=4 ts=4 fdm=marker
- * vim<600: noet sw=4 ts=4
- */
-
#include "php_http_api.h"
-PHP_HTTP_API php_http_info_t *php_http_info_init(php_http_info_t *i TSRMLS_DC)
+php_http_info_t *php_http_info_init(php_http_info_t *i TSRMLS_DC)
{
if (!i) {
i = emalloc(sizeof(*i));
return i;
}
-PHP_HTTP_API void php_http_info_dtor(php_http_info_t *i)
+void php_http_info_dtor(php_http_info_t *i)
{
switch (i->type) {
case PHP_HTTP_REQUEST:
}
}
-PHP_HTTP_API void php_http_info_free(php_http_info_t **i)
+void php_http_info_free(php_http_info_t **i)
{
if (*i) {
php_http_info_dtor(*i);
}
}
-PHP_HTTP_API php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC)
+php_http_info_t *php_http_info_parse(php_http_info_t *info, const char *pre_header TSRMLS_DC)
{
const char *end, *http;
zend_bool free_info = !info;
static void message_headers(php_http_message_t *msg, php_http_buffer_t *str);
-PHP_HTTP_API zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
+zend_bool php_http_message_info_callback(php_http_message_t **message, HashTable **headers, php_http_info_t *info TSRMLS_DC)
{
php_http_message_t *old = *message;
return old != *message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body TSRMLS_DC)
+php_http_message_t *php_http_message_init(php_http_message_t *message, php_http_message_type_t type, php_http_message_body_t *body TSRMLS_DC)
{
if (!message) {
message = emalloc(sizeof(*message));
return message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC)
+php_http_message_t *php_http_message_init_env(php_http_message_t *message, php_http_message_type_t type TSRMLS_DC)
{
int free_msg = !message;
zval *sval, tval;
#if PHP_VERSION_ID >= 50400
if (php_output_get_level(TSRMLS_C)) {
if (php_output_get_status(TSRMLS_C) & PHP_OUTPUT_SENT) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body, output has already been sent at %s:%d", php_output_get_start_filename(TSRMLS_C), php_output_get_start_lineno(TSRMLS_C));
goto error;
} else if (SUCCESS != php_output_get_contents(&tval TSRMLS_CC)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Could not fetch response body");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch response body");
goto error;
} else {
php_http_message_body_append(message->body, Z_STRVAL(tval), Z_STRLEN(tval));
return message;
}
-PHP_HTTP_API php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC)
+php_http_message_t *php_http_message_parse(php_http_message_t *msg, const char *str, size_t len, zend_bool greedy TSRMLS_DC)
{
php_http_message_parser_t p;
php_http_buffer_t buf;
return msg;
}
-PHP_HTTP_API zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join)
+zval *php_http_message_header(php_http_message_t *msg, const char *key_str, size_t key_len, int join)
{
zval *ret = NULL, **header;
char *key = php_http_pretty_key(estrndup(key_str, key_len), key_len, 1, 1);
return ret;
}
-PHP_HTTP_API zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
+zend_bool php_http_message_is_multipart(php_http_message_t *msg, char **boundary)
{
zval *ct = php_http_message_header(msg, ZEND_STRL("Content-Type"), 1);
zend_bool is_multipart = 0;
}
/* */
-PHP_HTTP_API void php_http_message_set_type(php_http_message_t *message, php_http_message_type_t type)
+void php_http_message_set_type(php_http_message_t *message, php_http_message_type_t type)
{
/* just act if different */
if (type != message->type) {
}
}
-PHP_HTTP_API void php_http_message_set_info(php_http_message_t *message, php_http_info_t *info)
+void php_http_message_set_info(php_http_message_t *message, php_http_info_t *info)
{
php_http_message_set_type(message, info->type);
message->http.version = info->http.version;
}
}
-PHP_HTTP_API void php_http_message_update_headers(php_http_message_t *msg)
+void php_http_message_update_headers(php_http_message_t *msg)
{
zval *h;
size_t size;
}
php_http_message_update_headers(msg);
- php_http_headers_to_string(str, &msg->hdrs TSRMLS_CC);
+ php_http_header_to_string(str, &msg->hdrs TSRMLS_CC);
}
-PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
+void php_http_message_to_callback(php_http_message_t *msg, php_http_pass_callback_t cb, void *cb_arg)
{
php_http_buffer_t str;
}
}
-PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length)
+void php_http_message_to_string(php_http_message_t *msg, char **string, size_t *length)
{
php_http_buffer_t str;
char *data;
php_http_buffer_dtor(&str);
}
-PHP_HTTP_API void php_http_message_serialize(php_http_message_t *message, char **string, size_t *length)
+void php_http_message_serialize(php_http_message_t *message, char **string, size_t *length)
{
char *buf;
php_http_buffer_t str;
php_http_buffer_dtor(&str);
}
-PHP_HTTP_API php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
+php_http_message_t *php_http_message_reverse(php_http_message_t *msg)
{
int i, c = 0;
return msg;
}
-PHP_HTTP_API php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two)
+php_http_message_t *php_http_message_zip(php_http_message_t *one, php_http_message_t *two)
{
php_http_message_t *dst = php_http_message_copy(one, NULL), *src = php_http_message_copy(two, NULL), *tmp_dst, *tmp_src, *ret = dst;
return ret;
}
-PHP_HTTP_API php_http_message_t *php_http_message_copy_ex(php_http_message_t *from, php_http_message_t *to, zend_bool parents)
+php_http_message_t *php_http_message_copy_ex(php_http_message_t *from, php_http_message_t *to, zend_bool parents)
{
php_http_message_t *temp, *copy = NULL;
php_http_info_t info;
return copy;
}
-PHP_HTTP_API php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to)
+php_http_message_t *php_http_message_copy(php_http_message_t *from, php_http_message_t *to)
{
return php_http_message_copy_ex(from, to, 1);
}
-PHP_HTTP_API void php_http_message_dtor(php_http_message_t *message)
+void php_http_message_dtor(php_http_message_t *message)
{
if (message) {
zend_hash_destroy(&message->hdrs);
}
}
-PHP_HTTP_API void php_http_message_free(php_http_message_t **message)
+void php_http_message_free(php_http_message_t **message)
{
if (*message) {
if ((*message)->parent) {
/* add ref */
zend_objects_store_add_ref(prepend TSRMLS_CC);
- /*
- while (prepend_obj->parent) {
- m.value.obj = prepend_obj->parent->zv;
- zend_objects_store_add_ref(&m TSRMLS_CC);
- prepend_obj = zend_object_store_get_object(&m TSRMLS_CC);
- }
- */
+
if (!top) {
prepend_obj->parent = save_parent_obj;
prepend_obj->message->parent = save_parent_msg;
case IS_RESOURCE:
php_stream_from_zval_no_verify(s, &zbody);
if (!s) {
- php_http_error(HE_THROW, PHP_HTTP_E_CLIENT, "not a valid stream resource");
+ php_http_throw(unexpected_val, "The stream is not a valid resource", NULL);
return FAILURE;
}
zval *zmessage = NULL;
php_http_message_t *msg = NULL;
php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ zend_error_handling zeh;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!b", &zmessage, &greedy) && zmessage) {
- if (Z_TYPE_P(zmessage) == IS_RESOURCE) {
- php_stream *s;
- php_http_message_parser_t p;
-
- php_stream_from_zval(s, &zmessage);
- if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
- unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
-
- php_http_message_parser_parse_stream(&p, s, flags, &msg);
- php_http_message_parser_dtor(&p);
- }
-
- if (!msg) {
- php_http_error(HE_THROW, PHP_HTTP_E_MESSAGE, "could not parse message from stream");
- }
- } else {
- zmessage = php_http_ztyp(IS_STRING, zmessage);
- if (!(msg = php_http_message_parse(NULL, Z_STRVAL_P(zmessage), Z_STRLEN_P(zmessage), greedy TSRMLS_CC))) {
- php_http_error(HE_THROW, PHP_HTTP_E_MESSAGE, "could not parse message: %.*s", MIN(25, Z_STRLEN_P(zmessage)), Z_STRVAL_P(zmessage));
- }
- zval_ptr_dtor(&zmessage);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!b", &zmessage, &greedy), invalid_arg, return);
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_message_class_entry, &zeh TSRMLS_CC);
+ if (zmessage && Z_TYPE_P(zmessage) == IS_RESOURCE) {
+ php_stream *s;
+ php_http_message_parser_t p;
+ zend_error_handling zeh;
- if (msg) {
- php_http_message_dtor(obj->message);
- obj->message = msg;
- if (obj->message->parent) {
- php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, &obj->parent TSRMLS_CC);
+ zend_replace_error_handling(EH_THROW, php_http_exception_unexpected_val_class_entry, &zeh TSRMLS_CC);
+ php_stream_from_zval(s, &zmessage);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+
+ if (s && php_http_message_parser_init(&p TSRMLS_CC)) {
+ unsigned flags = (greedy ? PHP_HTTP_MESSAGE_PARSER_GREEDY : 0);
+
+ if (PHP_HTTP_MESSAGE_PARSER_STATE_FAILURE == php_http_message_parser_parse_stream(&p, s, flags, &msg)) {
+ if (!EG(exception)) {
+ php_http_throw(bad_message, "Could not parse message from stream", NULL);
}
}
+
+ php_http_message_parser_dtor(&p);
}
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- } end_error_handling();
+ if (!msg && !EG(exception)) {
+ php_http_throw(bad_message, "Empty message received from stream", NULL);
+ }
+ } else if (zmessage) {
+ zmessage = php_http_ztyp(IS_STRING, zmessage);
+ msg = php_http_message_parse(NULL, Z_STRVAL_P(zmessage), Z_STRLEN_P(zmessage), greedy TSRMLS_CC);
+
+ if (!msg && !EG(exception)) {
+ php_http_throw(bad_message, "Could not parse message: %.*s", MIN(25, Z_STRLEN_P(zmessage)), Z_STRVAL_P(zmessage));
+ }
+ zval_ptr_dtor(&zmessage);
+ }
+
+ if (msg) {
+ php_http_message_dtor(obj->message);
+ obj->message = msg;
+ if (obj->message->parent) {
+ php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, &obj->parent TSRMLS_CC);
+ }
+ }
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getBody, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, getBody)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (!obj->body) {
- php_http_message_body_addref(obj->message->body);
- php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC);
- }
- if (obj->body) {
- RETVAL_OBJVAL(obj->body->zv, 1);
- }
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (!obj->body) {
+ php_http_message_body_addref(obj->message->body);
+ php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, (void *) &obj->body TSRMLS_CC);
+ }
+ if (obj->body) {
+ RETVAL_OBJVAL(obj->body->zv, 1);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setBody, 0, 0, 1)
return;
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Class '%s' is not as descendant of http\\Header", header_ce->name);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class '%s' is not as descendant of http\\Header", header_ce->name);
}
}
}
{
char *str;
int len;
+ php_http_message_object_t *obj;
php_http_info_t inf;
- if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- if (php_http_info_parse(&inf, str TSRMLS_CC)) {
- php_http_message_set_info(obj->message, &inf);
- php_http_info_dtor(&inf);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_MALFORMED_HEADERS, "Could not parse message info '%s'", str);
- }
+ if (!php_http_info_parse(&inf, str TSRMLS_CC)) {
+ php_http_throw(bad_header, "Could not parse message info '%s'", str);
+ return;
}
+
+ php_http_message_set_info(obj->message, &inf);
+ php_http_info_dtor(&inf);
+
RETVAL_ZVAL(getThis(), 1, 0);
}
{
char *v_str;
int v_len;
+ php_http_version_t version;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &v_str, &v_len)) {
- php_http_version_t version;
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &v_str, &v_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ php_http_expect(php_http_version_parse(&version, v_str TSRMLS_CC), unexpected_val, return);
+
+ obj->message->http.version = version;
- if (php_http_version_parse(&version, v_str TSRMLS_CC)) {
- obj->message->http.version = version;
- }
- }
RETVAL_ZVAL(getThis(), 1, 0);
}
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not if type response");
+ RETURN_FALSE;
+ }
+
RETURN_LONG(obj->message->http.info.response.code);
}
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseCode, 0, 0, 1)
ZEND_ARG_INFO(0, response_code)
+ ZEND_ARG_INFO(0, strict)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, setResponseCode)
{
long code;
zend_bool strict = 1;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &code, &strict), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
- if (strict && (code < 100 || code > 599)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Invalid response code (100-599): %ld", code);
- RETURN_FALSE;
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
+ return;
+ }
- obj->message->http.info.response.code = code;
- STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+ if (strict && (code < 100 || code > 599)) {
+ php_http_throw(invalid_arg, "Invalid response code (100-599): %ld", code);
+ return;
}
+
+ obj->message->http.info.response.code = code;
+ STR_SET(obj->message->http.info.response.status, estrdup(php_http_env_get_response_status_for_code(code)));
+
RETVAL_ZVAL(getThis(), 1, 0);
}
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type response");
+ }
+
if (obj->message->http.info.response.status) {
RETURN_STRING(obj->message->http.info.response.status, 1);
} else {
{
char *status;
int status_len;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_MESSAGE_TYPE_CHECK(RESPONSE, obj->message, RETURN_FALSE);
- STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_RESPONSE) {
+ php_http_throw(bad_method_call, "http\\Message is not of type response", NULL);
}
+
+ STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request");
+ RETURN_FALSE;
+ }
+
if (obj->message->http.info.request.method) {
RETURN_STRING(obj->message->http.info.request.method, 1);
} else {
{
char *method;
int method_len;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
- if (method_len < 1) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
- RETURN_FALSE;
- }
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+ return;
+ }
- STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+ if (method_len < 1) {
+ php_http_throw(invalid_arg, "Cannot set http\\Message's request method to an empty string", NULL);
+ return;
}
+
+ STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "http\\Message is not of type request");
+ RETURN_FALSE;
+ }
+
if (obj->message->http.info.request.url) {
RETURN_STRING(obj->message->http.info.request.url, 1);
} else {
{
char *url_str;
int url_len;
+ php_http_message_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url_str, &url_len)) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &url_str, &url_len), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- PHP_HTTP_MESSAGE_TYPE_CHECK(REQUEST, obj->message, RETURN_FALSE);
- if (url_len < 1) {
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUrl to an empty string");
- RETURN_FALSE;
- }
- STR_SET(obj->message->http.info.request.url, estrndup(url_str, url_len));
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (obj->message->type != PHP_HTTP_REQUEST) {
+ php_http_throw(bad_method_call, "http\\Message is not of type request", NULL);
+ return;
}
+
+ if (url_len < 1) {
+ php_http_throw(invalid_arg, "Cannot set http\\Message's request url to an empty string", NULL);
+ return;
+ }
+
+ STR_SET(obj->message->http.info.request.url, estrndup(url_str, url_len));
RETVAL_ZVAL(getThis(), 1, 0);
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, getParentMessage)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (obj->message->parent) {
- RETVAL_OBJVAL(obj->parent->zv, 1);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "HttpMessage does not have a parent message");
- }
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (!obj->message->parent) {
+ php_http_throw(unexpected_val, "http\\Message has not parent message", NULL);
+ return;
+ }
+
+ RETVAL_OBJVAL(obj->parent->zv, 1);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0)
obj->message = msg;
} else {
obj->message = php_http_message_init(NULL, 0, NULL TSRMLS_CC);
- php_http_error(HE_ERROR, PHP_HTTP_E_RUNTIME, "Could not unserialize HttpMessage");
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not unserialize http\\Message");
}
}
}
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, detach)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_message_object_t *obj;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
- }
- } end_error_handling();
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ RETVAL_OBJVAL(php_http_message_object_new_ex(obj->zo.ce, php_http_message_copy_ex(obj->message, NULL, 0), NULL TSRMLS_CC), 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend, 0, 0, 1)
{
zval *prepend;
zend_bool top = 1;
+ php_http_message_t *msg[2];
+ php_http_message_object_t *obj, *prepend_obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, php_http_message_class_entry, &top)) {
- php_http_message_t *msg[2];
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, php_http_message_class_entry, &top), invalid_arg, return);
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
- PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj);
-
- /* safety check */
- for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
- for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
- if (msg[0] == msg[1]) {
- php_http_error(HE_THROW, PHP_HTTP_E_INVALID_PARAM, "Cannot prepend a message located within the same message chain");
- return;
- }
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(prepend_obj);
+
+ /* safety check */
+ for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
+ for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
+ if (msg[0] == msg[1]) {
+ php_http_throw(unexpected_val, "Cannot prepend a message located within the same message chain", NULL);
+ return;
}
}
-
- php_http_message_object_prepend(getThis(), prepend, top TSRMLS_CC);
}
+
+ php_http_message_object_prepend(getThis(), prepend, top TSRMLS_CC);
+ RETURN_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_reverse, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, reverse)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_reverse(getThis(), return_value TSRMLS_CC);
- }
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ php_http_message_object_reverse(getThis(), return_value TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart, 0, 0, 0)
ZEND_END_ARG_INFO();
static PHP_METHOD(HttpMessage, splitMultipartBody)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- char *boundary = NULL;
+ php_http_message_object_t *obj;
+ php_http_message_t *msg;
+ char *boundary = NULL;
- PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- if (php_http_message_is_multipart(obj->message, &boundary)) {
- php_http_message_t *msg;
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if ((msg = php_http_message_body_split(obj->message->body, boundary))) {
- RETVAL_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
- }
- }
- STR_FREE(boundary);
+ PHP_HTTP_MESSAGE_OBJECT_INIT(obj);
+
+ if (!php_http_message_is_multipart(obj->message, &boundary)) {
+ php_http_throw(bad_method_call, "http\\Message is not a multipart message", NULL);
+ return;
}
+
+ php_http_expect(msg = php_http_message_body_split(obj->message->body, boundary), bad_message, return);
+
+ STR_FREE(boundary);
+
+ RETURN_OBJVAL(php_http_message_object_new_ex(php_http_message_class_entry, msg, NULL TSRMLS_CC), 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0)
php_http_message_count(i, obj->message);
RETURN_LONG(i);
}
- RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind, 0, 0, 0)
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Message", php_http_message_methods);
- php_http_message_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_message_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
php_http_message_class_entry->create_object = php_http_message_object_new;
memcpy(&php_http_message_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
php_http_message_object_handlers.clone_obj = php_http_message_object_clone;
/* required minimum length of an HTTP message "HTTP/1.1" */
#define PHP_HTTP_MESSAGE_MIN_SIZE 8
#define PHP_HTTP_MESSAGE_TYPE(TYPE, msg) ((msg) && ((msg)->type == PHP_HTTP_ ##TYPE))
-#define PHP_HTTP_MESSAGE_TYPE_CHECK(type, msg, action) \
- if (!PHP_HTTP_MESSAGE_TYPE(type, (msg))) { \
- php_http_error(HE_NOTICE, PHP_HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type "#type); \
- action; \
- }
typedef php_http_info_type_t php_http_message_type_t;
typedef struct php_http_message php_http_message_t;
php_http_message_body_appendf(body, "--%s" PHP_HTTP_CRLF, php_http_message_body_boundary(body)); \
} \
} while(0)
+
#define BOUNDARY_CLOSE(body) \
php_http_message_body_appendf(body, PHP_HTTP_CRLF "--%s--" PHP_HTTP_CRLF, php_http_message_body_boundary(body))
static STATUS add_recursive_fields(php_http_message_body_t *body, const char *name, zval *value);
static STATUS add_recursive_files(php_http_message_body_t *body, const char *name, zval *value);
-PHP_HTTP_API php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body_ptr, php_stream *stream TSRMLS_DC)
+php_http_message_body_t *php_http_message_body_init(php_http_message_body_t **body_ptr, php_stream *stream TSRMLS_DC)
{
php_http_message_body_t *body;
return body;
}
-PHP_HTTP_API unsigned php_http_message_body_addref(php_http_message_body_t *body)
+unsigned php_http_message_body_addref(php_http_message_body_t *body)
{
return ++body->refcount;
}
-PHP_HTTP_API php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to)
+php_http_message_body_t *php_http_message_body_copy(php_http_message_body_t *from, php_http_message_body_t *to)
{
if (from) {
TSRMLS_FETCH_FROM_CTX(from->ts);
return to;
}
-PHP_HTTP_API void php_http_message_body_free(php_http_message_body_t **body_ptr)
+void php_http_message_body_free(php_http_message_body_t **body_ptr)
{
if (*body_ptr) {
php_http_message_body_t *body = *body_ptr;
if (!--body->refcount) {
TSRMLS_FETCH_FROM_CTX(body->ts);
- /* NO FIXME: shows leakinfo in DEBUG mode */
+ /* NOFIXME: shows leakinfo in DEBUG mode */
zend_list_delete(body->stream_id);
STR_FREE(body->boundary);
efree(body);
}
}
-PHP_HTTP_API const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body)
+const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body)
{
TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_stat(php_http_message_body_stream(body), &body->ssb);
return &body->ssb;
}
-PHP_HTTP_API const char *php_http_message_body_boundary(php_http_message_body_t *body)
+const char *php_http_message_body_boundary(php_http_message_body_t *body)
{
if (!body->boundary) {
union { double dbl; int num[2]; } data;
return body->boundary;
}
-PHP_HTTP_API char *php_http_message_body_etag(php_http_message_body_t *body)
+char *php_http_message_body_etag(php_http_message_body_t *body)
{
const php_stream_statbuf *ssb = php_http_message_body_stat(body);
TSRMLS_FETCH_FROM_CTX(body->ts);
}
}
-PHP_HTTP_API void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen)
+void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen)
{
php_stream *s = php_http_message_body_stream(body);
TSRMLS_FETCH_FROM_CTX(body->ts);
*len = php_stream_copy_to_mem(s, buf, forlen, 0);
}
-PHP_HTTP_API void php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *dst, off_t offset, size_t forlen)
+STATUS php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *dst, off_t offset, size_t forlen)
{
php_stream *s = php_http_message_body_stream(body);
TSRMLS_FETCH_FROM_CTX(body->ts);
php_stream_seek(s, offset, SEEK_SET);
+
if (!forlen) {
forlen = -1;
}
- php_stream_copy_to_stream_ex(s, dst, forlen, NULL);
+ return php_stream_copy_to_stream_ex(s, dst, forlen, NULL);
}
-PHP_HTTP_API void php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen)
+STATUS php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen)
{
php_stream *s = php_http_message_body_stream(body);
char *buf = emalloc(0x1000);
size_t read = php_stream_read(s, buf, MIN(forlen, 0x1000));
if (read) {
- cb(cb_arg, buf, read);
+ if (-1 == cb(cb_arg, buf, read)) {
+ return FAILURE;
+ }
}
if (read < MIN(forlen, sizeof(buf))) {
}
}
efree(buf);
+
+ return SUCCESS;
}
-PHP_HTTP_API size_t php_http_message_body_append(php_http_message_body_t *body, const char *buf, size_t len)
+size_t php_http_message_body_append(php_http_message_body_t *body, const char *buf, size_t len)
{
php_stream *s;
+ size_t written;
TSRMLS_FETCH_FROM_CTX(body->ts);
if (!(s = php_http_message_body_stream(body))) {
return -1;
}
- php_stream_seek(s, 0, SEEK_END);
- return php_stream_write(s, buf, len);
+ if (s->ops->seek) {
+ php_stream_seek(s, 0, SEEK_END);
+ }
+
+ written = php_stream_write(s, buf, len);
+
+ if (written != len) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to append %zu bytes to body; wrote %zu", len, written);
+ }
+
+ return len;
}
-PHP_HTTP_API size_t php_http_message_body_appendf(php_http_message_body_t *body, const char *fmt, ...)
+size_t php_http_message_body_appendf(php_http_message_body_t *body, const char *fmt, ...)
{
va_list argv;
char *print_str;
return print_len;
}
-PHP_HTTP_API STATUS php_http_message_body_add_form(php_http_message_body_t *body, HashTable *fields, HashTable *files)
+STATUS php_http_message_body_add_form(php_http_message_body_t *body, HashTable *fields, HashTable *files)
{
zval tmp;
return SUCCESS;
}
-PHP_HTTP_API void php_http_message_body_add_part(php_http_message_body_t *body, php_http_message_t *part)
+void php_http_message_body_add_part(php_http_message_body_t *body, php_http_message_t *part)
{
TSRMLS_FETCH_FROM_CTX(body->ts);
}
-PHP_HTTP_API STATUS php_http_message_body_add_form_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len)
+STATUS php_http_message_body_add_form_field(php_http_message_body_t *body, const char *name, const char *value_str, size_t value_len)
{
char *safe_name;
TSRMLS_FETCH_FROM_CTX(body->ts);
return SUCCESS;
}
-PHP_HTTP_API STATUS php_http_message_body_add_form_file(php_http_message_body_t *body, const char *name, const char *ctype, const char *path, php_stream *in)
+STATUS php_http_message_body_add_form_file(php_http_message_body_t *body, const char *name, const char *ctype, const char *path, php_stream *in)
{
char *safe_name, *path_dup = estrdup(path), *bname;
size_t bname_len;
TSRMLS_FETCH_FROM_CTX(body->ts);
if (Z_TYPE_P(value) != IS_ARRAY && Z_TYPE_P(value) != IS_OBJECT) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "Expected array or object (name, type, file) for message body file to add");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected array or object (name, type, file) for message body file to add");
return FAILURE;
}
len = 0;
} else {
/* let this be garbage */
- php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "Malformed multipart boundary at pos %zu", consumed);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Malformed multipart boundary at pos %zu", consumed);
return -1;
}
}
return consumed;
}
-PHP_HTTP_API php_http_message_t *php_http_message_body_split(php_http_message_body_t *body, const char *boundary)
+php_http_message_t *php_http_message_body_split(php_http_message_body_t *body, const char *boundary)
{
php_stream *s = php_http_message_body_stream(body);
php_http_buffer_t *tmp = NULL;
zval *zstream = NULL;
php_stream *stream;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r!", &zstream)) {
- if (zstream) {
- php_stream_from_zval(stream, &zstream);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r!", &zstream), invalid_arg, return);
- if (stream) {
- if (obj->body) {
- php_http_message_body_free(&obj->body);
- }
- obj->body = php_http_message_body_init(NULL, stream TSRMLS_CC);
- }
- }
- PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+ if (zstream) {
+ php_http_expect(php_stream_from_zval_no_verify(stream, &zstream), unexpected_val, return);
+
+ if (obj->body) {
+ php_http_message_body_free(&obj->body);
}
- } end_error_handling();
+ obj->body = php_http_message_body_init(NULL, stream TSRMLS_CC);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody___toString, 0, 0, 0)
{
char *str;
int len;
+ php_http_message_body_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len), invalid_arg, return);
- PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- if (len != php_http_message_body_append(obj->body, str, len)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "Could not append to body");
- }
- RETURN_ZVAL(getThis(), 1, 0);
- }
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+ php_http_expect(len == php_http_message_body_append(obj->body, str, len), runtime, return);
+
+ RETURN_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addForm, 0, 0, 0)
PHP_METHOD(HttpMessageBody, addForm)
{
HashTable *fields = NULL, *files = NULL;
+ php_http_message_body_object_t *obj;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h!h!", &fields, &files)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h!h!", &fields, &files), invalid_arg, return);
- PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_body_add_form(obj->body, fields, files);
- RETURN_ZVAL(getThis(), 1, 0);
- }
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+ php_http_expect(SUCCESS == php_http_message_body_add_form(obj->body, fields, files), runtime, return);
+
+ RETURN_ZVAL(getThis(), 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addPart, 0, 0, 1)
PHP_METHOD(HttpMessageBody, addPart)
{
zval *zobj;
+ php_http_message_body_object_t *obj;
+ php_http_message_object_t *mobj;
+ zend_error_handling zeh;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobj, php_http_message_class_entry)) {
- php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
- php_http_message_object_t *mobj = zend_object_store_get_object(zobj TSRMLS_CC);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobj, php_http_message_class_entry), invalid_arg, return);
- PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+ mobj = zend_object_store_get_object(zobj TSRMLS_CC);
+
+ PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj);
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ php_http_message_body_add_part(obj->body, mobj->message);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
- php_http_message_body_add_part(obj->body, mobj->message);
+ if (!EG(exception)) {
RETURN_ZVAL(getThis(), 1, 0);
}
}
RETURN_LONG(sb->sb.st_ctime);
break;
default:
- php_http_error(HE_WARNING, PHP_HTTP_E_MESSAGE_BODY, "unknown stat field: '%s' (should be one of [s]ize, [a]time, [m]time or [c]time)", field_str);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown stat field: '%s' (should be one of [s]ize, [a]time, [m]time or [c]time)", field_str);
break;
}
} else {
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http\\Message", "Body", php_http_message_body_methods);
- php_http_message_body_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_message_body_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
php_http_message_body_class_entry->create_object = php_http_message_body_object_new;
memcpy(&php_http_message_body_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
php_http_message_body_object_handlers.clone_obj = php_http_message_body_object_clone;
PHP_HTTP_API size_t php_http_message_body_append(php_http_message_body_t *body, const char *buf, size_t len);
PHP_HTTP_API size_t php_http_message_body_appendf(php_http_message_body_t *body, const char *fmt, ...);
PHP_HTTP_API void php_http_message_body_to_string(php_http_message_body_t *body, char **buf, size_t *len, off_t offset, size_t forlen);
-PHP_HTTP_API void php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *s, off_t offset, size_t forlen);
-PHP_HTTP_API void php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen);
+PHP_HTTP_API STATUS php_http_message_body_to_stream(php_http_message_body_t *body, php_stream *s, off_t offset, size_t forlen);
+PHP_HTTP_API STATUS php_http_message_body_to_callback(php_http_message_body_t *body, php_http_pass_callback_t cb, void *cb_arg, off_t offset, size_t forlen);
PHP_HTTP_API void php_http_message_body_free(php_http_message_body_t **body);
PHP_HTTP_API const php_stream_statbuf *php_http_message_body_stat(php_http_message_body_t *body);
#define php_http_message_body_size(b) (php_http_message_body_stat((b))->sb.st_size)
}
#endif
-PHP_HTTP_API php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser TSRMLS_DC)
+php_http_message_parser_t *php_http_message_parser_init(php_http_message_parser_t *parser TSRMLS_DC)
{
if (!parser) {
parser = emalloc(sizeof(*parser));
return parser;
}
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_push(php_http_message_parser_t *parser, unsigned argc, ...)
+php_http_message_parser_state_t php_http_message_parser_state_push(php_http_message_parser_t *parser, unsigned argc, ...)
{
php_http_message_parser_state_t state;
va_list va_args;
return state;
}
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_is(php_http_message_parser_t *parser)
+php_http_message_parser_state_t php_http_message_parser_state_is(php_http_message_parser_t *parser)
{
php_http_message_parser_state_t *state;
return PHP_HTTP_MESSAGE_PARSER_STATE_START;
}
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_state_pop(php_http_message_parser_t *parser)
+php_http_message_parser_state_t php_http_message_parser_state_pop(php_http_message_parser_t *parser)
{
php_http_message_parser_state_t state, *state_ptr;
if (SUCCESS == zend_stack_top(&parser->stack, (void *) &state_ptr)) {
return PHP_HTTP_MESSAGE_PARSER_STATE_START;
}
-PHP_HTTP_API void php_http_message_parser_dtor(php_http_message_parser_t *parser)
+void php_http_message_parser_dtor(php_http_message_parser_t *parser)
{
php_http_header_parser_dtor(&parser->header);
zend_stack_destroy(&parser->stack);
}
}
-PHP_HTTP_API void php_http_message_parser_free(php_http_message_parser_t **parser)
+void php_http_message_parser_free(php_http_message_parser_t **parser)
{
if (*parser) {
php_http_message_parser_dtor(*parser);
}
}
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_message_parser_t *parser, php_stream *s, unsigned flags, php_http_message_t **message)
+php_http_message_parser_state_t php_http_message_parser_parse_stream(php_http_message_parser_t *parser, php_stream *s, unsigned flags, php_http_message_t **message)
{
php_http_buffer_t buf;
php_http_message_parser_state_t state = PHP_HTTP_MESSAGE_PARSER_STATE_START;
}
-PHP_HTTP_API php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, php_http_message_t **message)
+php_http_message_parser_state_t php_http_message_parser_parse(php_http_message_parser_t *parser, php_http_buffer_t *buffer, unsigned flags, php_http_message_t **message)
{
char *str = NULL;
size_t len = 0;
/* SLEEP */
-PHP_HTTP_API void php_http_sleep(double s)
+void php_http_sleep(double s)
{
#if defined(PHP_WIN32)
Sleep((DWORD) PHP_HTTP_MSEC(s));
/* ARRAYS */
-PHP_HTTP_API unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...)
+unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...)
{
HashPosition pos;
unsigned argl = 0;
/* PASS CALLBACK */
-PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len)
+size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len)
{
php_http_pass_fcall_arg_t *fcd = cb_arg;
zval *zdata;
return len;
}
-/* ERROR */
-
-static inline int scope_error_handling(long type TSRMLS_DC)
-{
- if ((type == E_THROW) || (EG(error_handling) == EH_THROW)) {
- return EH_THROW;
- }
-
- if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), php_http_object_class_entry TSRMLS_CC)) {
- return php_http_object_get_error_handling(EG(This) TSRMLS_CC);
- }
-
- return EH_NORMAL;
-}
-
-void php_http_error(long type TSRMLS_DC, long code, const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- switch (scope_error_handling(type TSRMLS_CC)) {
- case EH_THROW: {
- char *message;
- zend_class_entry *ce = php_http_exception_class_entry;
-
- /* FIXME wat? */
- if (0&& EG(exception_class) && instanceof_function(EG(exception_class), ce TSRMLS_CC)) {
- ce = EG(exception_class);
- }
-
- vspprintf(&message, 0, format, args);
- zend_throw_exception(ce, message, code TSRMLS_CC);
- efree(message);
- break;
- }
- case EH_NORMAL:
- php_verror(NULL, "", type, format, args TSRMLS_CC);
- break;
- case EH_SUPPRESS:
- break;
- }
- va_end(args);
-}
/* ZEND */
-STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC)
-{
- zend_fcall_info fci;
- zval zmethod;
- zval *retval;
- STATUS rv;
-
- fci.size = sizeof(fci);
- fci.object_ptr = object;
- fci.function_name = &zmethod;
- fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval;
- fci.param_count = argc;
- fci.params = argv;
- fci.no_separation = 1;
- fci.symbol_table = NULL;
- fci.function_table = NULL;
-
- INIT_PZVAL(&zmethod);
- ZVAL_STRINGL(&zmethod, method_str, method_len, 0);
- rv = zend_call_function(&fci, NULL TSRMLS_CC);
-
- if (!retval_ptr && retval) {
- zval_ptr_dtor(&retval);
- }
- return rv;
-}
/*
* Local variables:
* tab-width: 4
/* STRING UTILITIES */
-#define PHP_HTTP_CHECK_CONTENT_TYPE(ct, action) \
- if (!strchr((ct), '/')) { \
- php_http_error(HE_WARNING, PHP_HTTP_E_INVALID_PARAM, \
- "Content type \"%s\" does not seem to contain a primary and a secondary part", (ct)); \
- action; \
- }
-
-
#ifndef STR_SET
# define STR_SET(STR, SET) \
{ \
return FAILURE;
}
-STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC);
-
/* return object(values) */
#define RETVAL_OBJECT(o, addref) \
RETVAL_OBJVAL((o)->value.obj, addref)
PHP_HTTP_API size_t php_http_pass_fcall_callback(void *cb_arg, const char *str, size_t len);
-/* ERROR */
-
-extern void php_http_error(long type TSRMLS_DC, long code, const char *format, ...);
-
-#define with_error_handling(eh, ec) \
- { \
- zend_error_handling __eh; \
- zend_replace_error_handling((eh), (ec), &__eh TSRMLS_CC);
-
-#define end_error_handling() \
- zend_restore_error_handling(&__eh TSRMLS_CC); \
- }
-
-#ifndef E_THROW
-# define E_THROW -1
-#endif
-#define HE_THROW E_THROW TSRMLS_CC
-#define HE_NOTICE E_NOTICE TSRMLS_CC
-#define HE_WARNING E_WARNING TSRMLS_CC
-#define HE_ERROR E_ERROR TSRMLS_CC
-
-typedef enum php_http_error {
- PHP_HTTP_E_UNKNOWN = 0,
- PHP_HTTP_E_RUNTIME,
- PHP_HTTP_E_INVALID_PARAM,
- PHP_HTTP_E_HEADER,
- PHP_HTTP_E_MALFORMED_HEADERS,
- PHP_HTTP_E_REQUEST_METHOD,
- PHP_HTTP_E_MESSAGE,
- PHP_HTTP_E_MESSAGE_TYPE,
- PHP_HTTP_E_MESSAGE_BODY,
- PHP_HTTP_E_ENCODING,
- PHP_HTTP_E_CLIENT,
- PHP_HTTP_E_CLIENT_POOL,
- PHP_HTTP_E_CLIENT_DATASHARE,
- PHP_HTTP_E_REQUEST_FACTORY,
- PHP_HTTP_E_SOCKET,
- PHP_HTTP_E_RESPONSE,
- PHP_HTTP_E_URL,
- PHP_HTTP_E_QUERYSTRING,
- PHP_HTTP_E_COOKIE,
-} php_http_error_t;
-
#endif
/*
return ZEND_HASH_APPLY_KEEP;
}
-PHP_HTTP_API HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len TSRMLS_DC)
+HashTable *php_http_negotiate(const char *value_str, size_t value_len, HashTable *supported, const char *primary_sep_str, size_t primary_sep_len TSRMLS_DC)
{
HashTable *result = NULL;
#include "php_http_api.h"
-PHP_HTTP_API STATUS php_http_new(zend_object_value *ovp, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
-{
- zend_object_value ov;
-
- if (!ce) {
- ce = parent_ce;
- } else if (parent_ce && !instanceof_function(ce, parent_ce TSRMLS_CC)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "Class %s does not extend %s", ce->name, parent_ce->name);
- return FAILURE;
- }
-
- ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
- if (ovp) {
- *ovp = ov;
- }
- return SUCCESS;
-}
-
-PHP_HTTP_API zend_error_handling_t php_http_object_get_error_handling(zval *object TSRMLS_DC)
-{
- zval *zeh, *lzeh;
- long eh;
-
- zeh = zend_read_property(Z_OBJCE_P(object), object, ZEND_STRL("errorHandling"), 0 TSRMLS_CC);
- if (Z_TYPE_P(zeh) != IS_NULL) {
- lzeh = php_http_ztyp(IS_LONG, zeh);
- eh = Z_LVAL_P(lzeh);
- zval_ptr_dtor(&lzeh);
- return eh;
- }
- zeh = zend_read_static_property(php_http_object_class_entry, ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC);
- if (Z_TYPE_P(zeh) != IS_NULL) {
- lzeh = php_http_ztyp(IS_LONG, zeh);
- eh = Z_LVAL_P(lzeh);
- zval_ptr_dtor(&lzeh);
- return eh;
- }
- return EH_NORMAL;
-}
-
zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC)
{
return php_http_object_new_ex(ce, NULL, NULL TSRMLS_CC);
return o->zv;
}
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getErrorHandling, 0, 0, 0)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpObject, getErrorHandling)
+STATUS php_http_new(zend_object_value *ovp, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
{
- zval *zeh = zend_read_property(php_http_object_class_entry, getThis(), ZEND_STRL("errorHandling"), 0 TSRMLS_CC);
- RETURN_ZVAL(zeh, 1, 0);
-}
+ zend_object_value ov;
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_setErrorHandling, 0, 0, 1)
- ZEND_ARG_INFO(0, eh)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpObject, setErrorHandling)
-{
- long eh;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &eh)) {
- switch (eh) {
- case EH_NORMAL:
- case EH_SUPPRESS:
- case EH_THROW:
- zend_update_property_long(php_http_object_class_entry, getThis(), ZEND_STRL("errorHandling"), eh TSRMLS_CC);
- break;
-
- default:
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "unknown error handling code (%ld)", eh);
- break;
- }
+ if (!ce) {
+ ce = parent_ce;
+ } else if (parent_ce && !instanceof_function(ce, parent_ce TSRMLS_CC)) {
+ php_http_throw(unexpected_val, "Class %s does not extend %s", ce->name, parent_ce->name);
+ return FAILURE;
}
- RETURN_ZVAL(getThis(), 1, 0);
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getDefaultErrorHandling, 0, 0, 0)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpObject, getDefaultErrorHandling)
-{
- zval *zdeh = zend_read_static_property(php_http_object_class_entry, ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC);
- RETURN_ZVAL(zdeh, 1, 0);
-}
-
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_setDefaultErrorHandling, 0, 0, 1)
- ZEND_ARG_INFO(0, eh)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpObject, setDefaultErrorHandling)
-{
- long eh;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &eh)) {
- switch (eh) {
- case EH_NORMAL:
- case EH_SUPPRESS:
- case EH_THROW:
- zend_update_static_property_long(php_http_object_class_entry, ZEND_STRL("defaultErrorHandling"), eh TSRMLS_CC);
- break;
-
- default:
- php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "unknown error handling code (%ld)", eh);
- break;
- }
+ ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
+ if (ovp) {
+ *ovp = ov;
}
+ return SUCCESS;
}
-ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_triggerError, 0, 0, 3)
- ZEND_ARG_INFO(0, error_type)
- ZEND_ARG_INFO(0, error_code)
- ZEND_ARG_INFO(0, error_message)
-ZEND_END_ARG_INFO();
-PHP_METHOD(HttpObject, triggerError)
+STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC)
{
- long eh, code;
- char *msg_str;
- int msg_len;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lls", &eh, &code, &msg_str, &msg_len)) {
- php_http_error(eh TSRMLS_CC, code, "%.*s", msg_len, msg_str);
+ zend_fcall_info fci;
+ zval zmethod;
+ zval *retval;
+ STATUS rv;
+
+ fci.size = sizeof(fci);
+ fci.object_ptr = object;
+ fci.function_name = &zmethod;
+ fci.retval_ptr_ptr = retval_ptr ? retval_ptr : &retval;
+ fci.param_count = argc;
+ fci.params = argv;
+ fci.no_separation = 1;
+ fci.symbol_table = NULL;
+ fci.function_table = NULL;
+
+ INIT_PZVAL(&zmethod);
+ ZVAL_STRINGL(&zmethod, method_str, method_len, 0);
+ rv = zend_call_function(&fci, NULL TSRMLS_CC);
+
+ if (!retval_ptr && retval) {
+ zval_ptr_dtor(&retval);
}
+ return rv;
}
-static zend_function_entry php_http_object_methods[] = {
- PHP_ME(HttpObject, setErrorHandling, ai_HttpObject_setErrorHandling, ZEND_ACC_PUBLIC)
- PHP_ME(HttpObject, getErrorHandling, ai_HttpObject_getErrorHandling, ZEND_ACC_PUBLIC)
- PHP_ME(HttpObject, setDefaultErrorHandling, ai_HttpObject_setDefaultErrorHandling, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
- PHP_ME(HttpObject, getDefaultErrorHandling, ai_HttpObject_getDefaultErrorHandling, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
- PHP_ME(HttpObject, triggerError, ai_HttpObject_triggerError, ZEND_ACC_PUBLIC)
-
- EMPTY_FUNCTION_ENTRY
-};
-
-zend_class_entry *php_http_object_class_entry;
-
-PHP_MINIT_FUNCTION(http_object)
-{
- zend_class_entry ce = {0};
-
- INIT_NS_CLASS_ENTRY(ce, "http", "Object", php_http_object_methods);
- php_http_object_class_entry = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
- php_http_object_class_entry->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
- php_http_object_class_entry->create_object = php_http_object_new;
-
- zend_declare_property_null(php_http_object_class_entry, ZEND_STRL("defaultErrorHandling"), (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
- zend_declare_property_null(php_http_object_class_entry, ZEND_STRL("errorHandling"), ZEND_ACC_PROTECTED TSRMLS_CC);
-
- zend_declare_class_constant_long(php_http_object_class_entry, ZEND_STRL("EH_NORMAL"), EH_NORMAL TSRMLS_CC);
- zend_declare_class_constant_long(php_http_object_class_entry, ZEND_STRL("EH_SUPPRESS"), EH_SUPPRESS TSRMLS_CC);
- zend_declare_class_constant_long(php_http_object_class_entry, ZEND_STRL("EH_THROW"), EH_THROW TSRMLS_CC);
-
- return SUCCESS;
-}
-
-
/*
* Local variables:
* tab-width: 4
#ifndef PHP_HTTP_OBJECT_H
#define PHP_HTTP_OBJECT_H
-typedef zend_object_value (*php_http_new_t)(zend_class_entry *ce, void *, void ** TSRMLS_DC);
-
-PHP_HTTP_API STATUS php_http_new(zend_object_value *ov, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC);
-
typedef struct php_http_object {
zend_object zo;
zend_object_value zv;
} php_http_object_t;
-PHP_HTTP_API zend_class_entry *php_http_object_class_entry;
-PHP_MINIT_FUNCTION(http_object);
-
zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC);
zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, php_http_object_t **ptr TSRMLS_DC);
-PHP_HTTP_API zend_error_handling_t php_http_object_get_error_handling(zval *object TSRMLS_DC);
+typedef zend_object_value (*php_http_new_t)(zend_class_entry *ce, void *, void ** TSRMLS_DC);
+
+STATUS php_http_new(zend_object_value *ov, zend_class_entry *ce, php_http_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC);
+STATUS php_http_method_call(zval *object, const char *method_str, size_t method_len, int argc, zval **argv[], zval **retval_ptr TSRMLS_DC);
#endif
#include "php_http_api.h"
-PHP_HTTP_API php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_bool persistent)
+php_http_options_t *php_http_options_init(php_http_options_t *registry, zend_bool persistent)
{
if (!registry) {
registry = pecalloc(1, sizeof(*registry), persistent);
return registry;
}
-PHP_HTTP_API STATUS php_http_options_apply(php_http_options_t *registry, HashTable *options, void *userdata)
+STATUS php_http_options_apply(php_http_options_t *registry, HashTable *options, void *userdata)
{
HashPosition pos;
zval *val;
return SUCCESS;
}
-PHP_HTTP_API void php_http_options_dtor(php_http_options_t *registry)
+void php_http_options_dtor(php_http_options_t *registry)
{
zend_hash_destroy(®istry->options);
}
-PHP_HTTP_API void php_http_options_free(php_http_options_t **registry)
+void php_http_options_free(php_http_options_t **registry)
{
if (*registry) {
php_http_options_dtor(*registry);
}
}
-PHP_HTTP_API php_http_option_t *php_http_option_register(php_http_options_t *registry, const char *name_str, size_t name_len, ulong option, zend_uchar type)
+php_http_option_t *php_http_option_register(php_http_options_t *registry, const char *name_str, size_t name_len, ulong option, zend_uchar type)
{
php_http_option_t opt, *dst = NULL;
return dst;
}
-PHP_HTTP_API zval *php_http_option_get(php_http_option_t *opt, HashTable *options, void *userdata)
+zval *php_http_option_get(php_http_option_t *opt, HashTable *options, void *userdata)
{
if (options) {
zval **zoption;
PHP_HTTP_PARAMS_DEFAULT
};
-PHP_HTTP_API php_http_params_opts_t *php_http_params_opts_default_get(php_http_params_opts_t *opts)
+php_http_params_opts_t *php_http_params_opts_default_get(php_http_params_opts_t *opts)
{
if (!opts) {
opts = emalloc(sizeof(*opts));
case '[':
if (++level > PG(max_input_nesting_level)) {
zval_ptr_dtor(&arr);
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Max input nesting level of %ld exceeded", PG(max_input_nesting_level));
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Max input nesting level of %ld exceeded", (long) PG(max_input_nesting_level));
return;
}
if (ptr - var == 0) {
}
}
-PHP_HTTP_API HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts TSRMLS_DC)
+HashTable *php_http_params_parse(HashTable *params, const php_http_params_opts_t *opts TSRMLS_DC)
{
php_http_params_state_t state = {{NULL,0}, {NULL,0}, {NULL,0}, {NULL,0}, {NULL,NULL,NULL}, 0, 0};
}
}
-PHP_HTTP_API php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
+php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf, HashTable *params, const char *pss, size_t psl, const char *ass, size_t asl, const char *vss, size_t vsl, unsigned flags TSRMLS_DC)
{
zval **zparam;
HashPosition pos, pos1;
return buf;
}
-PHP_HTTP_API php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC)
+php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC)
{
zval **sep;
HashPosition pos;
return ret;
}
-PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separator)
+void php_http_params_separator_free(php_http_params_token_t **separator)
{
php_http_params_token_t **sep = separator;
if (sep) {
ZEND_END_ARG_INFO();
PHP_METHOD(HttpParams, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *zcopy, *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
- long flags = PHP_HTTP_PARAMS_DEFAULT;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags)) {
- switch (ZEND_NUM_ARGS()) {
- case 5:
- zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags TSRMLS_CC);
- /* no break */
- case 4:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
- /* no break */
- case 3:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep TSRMLS_CC);
- /* no break */
- case 2:
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep TSRMLS_CC);
- /* no break */
- }
+ zval *zcopy, *zparams = NULL, *param_sep = NULL, *arg_sep = NULL, *val_sep = NULL;
+ long flags = PHP_HTTP_PARAMS_DEFAULT;
+ zend_error_handling zeh;
- if (zparams) {
- switch (Z_TYPE_P(zparams)) {
- case IS_OBJECT:
- case IS_ARRAY:
- zcopy = php_http_zsep(1, IS_ARRAY, zparams);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zcopy TSRMLS_CC);
- zval_ptr_dtor(&zcopy);
- break;
- default:
- zcopy = php_http_ztyp(IS_STRING, zparams);
- if (Z_STRLEN_P(zcopy)) {
- php_http_params_opts_t opts = {
- {Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy)},
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC),
- NULL, flags
- };
-
- MAKE_STD_ZVAL(zparams);
- array_init(zparams);
- php_http_params_parse(Z_ARRVAL_P(zparams), &opts TSRMLS_CC);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
-
- php_http_params_separator_free(opts.param);
- php_http_params_separator_free(opts.arg);
- php_http_params_separator_free(opts.val);
- }
- zval_ptr_dtor(&zcopy);
- break;
- }
- } else {
- MAKE_STD_ZVAL(zparams);
- array_init(zparams);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z/z/z/l", &zparams, ¶m_sep, &arg_sep, &val_sep, &flags), invalid_arg, return);
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_runtime_class_entry, &zeh TSRMLS_CC);
+ {
+ switch (ZEND_NUM_ARGS()) {
+ case 5:
+ zend_update_property_long(php_http_params_class_entry, getThis(), ZEND_STRL("flags"), flags TSRMLS_CC);
+ /* no break */
+ case 4:
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), val_sep TSRMLS_CC);
+ /* no break */
+ case 3:
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), arg_sep TSRMLS_CC);
+ /* no break */
+ case 2:
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), param_sep TSRMLS_CC);
+ /* no break */
+ }
+
+ if (zparams) {
+ switch (Z_TYPE_P(zparams)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ zcopy = php_http_zsep(1, IS_ARRAY, zparams);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zcopy TSRMLS_CC);
+ zval_ptr_dtor(&zcopy);
+ break;
+ default:
+ zcopy = php_http_ztyp(IS_STRING, zparams);
+ if (Z_STRLEN_P(zcopy)) {
+ php_http_params_opts_t opts = {
+ {Z_STRVAL_P(zcopy), Z_STRLEN_P(zcopy)},
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("param_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("arg_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ php_http_params_separator_init(zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("val_sep"), 0 TSRMLS_CC) TSRMLS_CC),
+ NULL, flags
+ };
+
+ MAKE_STD_ZVAL(zparams);
+ array_init(zparams);
+ php_http_params_parse(Z_ARRVAL_P(zparams), &opts TSRMLS_CC);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
+ zval_ptr_dtor(&zparams);
+
+ php_http_params_separator_free(opts.param);
+ php_http_params_separator_free(opts.arg);
+ php_http_params_separator_free(opts.val);
+ }
+ zval_ptr_dtor(&zcopy);
+ break;
}
+ } else {
+ MAKE_STD_ZVAL(zparams);
+ array_init(zparams);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
+ zval_ptr_dtor(&zparams);
}
- } end_error_handling();
+ }
+ zend_restore_error_handling(&zeh TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toArray, 0, 0, 0)
{
char *name_str;
int name_len;
+ zval **zparam, *zparams;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
- zval **zparam, *zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ return;
+ }
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- RETVAL_BOOL(Z_TYPE_PP(zparam) != IS_NULL);
- } else {
- RETVAL_FALSE;
- }
- zval_ptr_dtor(&zparams);
+ zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
+ RETVAL_BOOL(Z_TYPE_PP(zparam) != IS_NULL);
+ } else {
+ RETVAL_FALSE;
}
+ zval_ptr_dtor(&zparams);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetGet, 0, 0, 1)
{
char *name_str;
int name_len;
+ zval **zparam, *zparams;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
- zval **zparam, *zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ return;
+ }
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- RETVAL_ZVAL(*zparam, 1, 0);
- }
+ zparams = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
- zval_ptr_dtor(&zparams);
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
+ RETVAL_ZVAL(*zparam, 1, 0);
}
+
+ zval_ptr_dtor(&zparams);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetUnset, 0, 0, 1)
{
char *name_str;
int name_len;
+ zval *zparams;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
- zval *zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name_str, &name_len)) {
+ return;
+ }
- zend_symtable_del(Z_ARRVAL_P(zparams), name_str, name_len + 1);
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
+ zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
- zval_ptr_dtor(&zparams);
- }
+ zend_symtable_del(Z_ARRVAL_P(zparams), name_str, name_len + 1);
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
+
+ zval_ptr_dtor(&zparams);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetSet, 0, 0, 2)
zval *nvalue;
char *name_str;
int name_len;
+ zval **zparam, *zparams;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &nvalue)) {
- zval **zparam, *zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
-
- if (name_len) {
- if (Z_TYPE_P(nvalue) == IS_ARRAY) {
- zval *new_zparam;
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name_str, &name_len, &nvalue)) {
+ return;
+ }
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- new_zparam = php_http_zsep(1, IS_ARRAY, *zparam);
- array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(new_zparam), 0, 0);
- } else {
- new_zparam = nvalue;
- Z_ADDREF_P(new_zparam);
- }
- add_assoc_zval_ex(zparams, name_str, name_len + 1, new_zparam);
- } else {
- zval *tmp;
+ zparams = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC));
- if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
- tmp = php_http_zsep(1, IS_ARRAY, *zparam);
- } else {
- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
- }
+ if (name_len) {
+ if (Z_TYPE_P(nvalue) == IS_ARRAY) {
+ zval *new_zparam;
- Z_ADDREF_P(nvalue);
- add_assoc_zval_ex(tmp, ZEND_STRS("value"), nvalue);
- add_assoc_zval_ex(zparams, name_str, name_len + 1, tmp);
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
+ new_zparam = php_http_zsep(1, IS_ARRAY, *zparam);
+ array_join(Z_ARRVAL_P(nvalue), Z_ARRVAL_P(new_zparam), 0, 0);
+ } else {
+ new_zparam = nvalue;
+ Z_ADDREF_P(new_zparam);
}
+ add_assoc_zval_ex(zparams, name_str, name_len + 1, new_zparam);
} else {
- zval *tmp = php_http_ztyp(IS_STRING, nvalue), *arr;
+ zval *tmp;
- MAKE_STD_ZVAL(arr);
- array_init(arr);
- add_assoc_bool_ex(arr, ZEND_STRS("value"), 1);
- add_assoc_zval_ex(zparams, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 1, arr);
- zval_ptr_dtor(&tmp);
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(zparams), name_str, name_len + 1, (void *) &zparam)) {
+ tmp = php_http_zsep(1, IS_ARRAY, *zparam);
+ } else {
+ MAKE_STD_ZVAL(tmp);
+ array_init(tmp);
+ }
+
+ Z_ADDREF_P(nvalue);
+ add_assoc_zval_ex(tmp, ZEND_STRS("value"), nvalue);
+ add_assoc_zval_ex(zparams, name_str, name_len + 1, tmp);
}
+ } else {
+ zval *tmp = php_http_ztyp(IS_STRING, nvalue), *arr;
- zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
- zval_ptr_dtor(&zparams);
+ MAKE_STD_ZVAL(arr);
+ array_init(arr);
+ add_assoc_bool_ex(arr, ZEND_STRS("value"), 1);
+ add_assoc_zval_ex(zparams, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp) + 1, arr);
+ zval_ptr_dtor(&tmp);
}
+
+ zend_update_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), zparams TSRMLS_CC);
+ zval_ptr_dtor(&zparams);
}
static zend_function_entry php_http_params_methods[] = {
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Params", php_http_params_methods);
- php_http_params_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_params_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_params_class_entry->create_object = php_http_params_object_new;
zend_class_implements(php_http_params_class_entry TSRMLS_CC, 1, zend_ce_arrayaccess);
zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_PARAM_SEP"), ZEND_STRL(",") TSRMLS_CC);
}
#ifdef PHP_HTTP_HAVE_ICONV
-PHP_HTTP_API STATUS php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe TSRMLS_DC)
+STATUS php_http_querystring_xlate(zval *dst, zval *src, const char *ie, const char *oe TSRMLS_DC)
{
HashPosition pos;
zval **entry = NULL;
FOREACH_KEYVAL(pos, src, key, entry) {
if (key.type == HASH_KEY_IS_STRING) {
if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.str, key.len-1, &xkey, &xlen, oe, ie)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe);
return FAILURE;
}
}
if (key.type == HASH_KEY_IS_STRING) {
efree(xkey);
}
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe);
return FAILURE;
}
if (key.type == HASH_KEY_IS_STRING) {
}
#endif /* HAVE_ICONV */
-PHP_HTTP_API STATUS php_http_querystring_ctor(zval *instance, zval *params TSRMLS_DC)
+STATUS php_http_querystring_ctor(zval *instance, zval *params TSRMLS_DC)
{
php_http_querystring_set(instance, params, 0 TSRMLS_CC);
return SUCCESS;
return ZEND_HASH_APPLY_KEEP;
}
-PHP_HTTP_API STATUS php_http_querystring_parse(HashTable *ht, const char *str, size_t len TSRMLS_DC)
+STATUS php_http_querystring_parse(HashTable *ht, const char *str, size_t len TSRMLS_DC)
{
STATUS rv = FAILURE;
php_http_params_opts_t opts;
return rv;
}
-PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval *outstring TSRMLS_DC)
+STATUS php_http_querystring_update(zval *qarray, zval *params, zval *outstring TSRMLS_DC)
{
/* enforce proper type */
if (Z_TYPE_P(qarray) != IS_ARRAY) {
zval_dtor(outstring);
ZVAL_STRINGL(outstring, s, l, 0);
} else {
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Failed to encode query string");
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to encode query string");
return FAILURE;
}
}
PHP_METHOD(HttpQueryString, __construct)
{
zval *params = NULL;
+ zend_error_handling zeh;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶ms)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_http_querystring_set(getThis(), params, 0 TSRMLS_CC);
- } end_error_handling();
- }
- } end_error_handling();
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", ¶ms), invalid_arg, return);
+
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh TSRMLS_CC);
+ php_http_querystring_set(getThis(), params, 0 TSRMLS_CC);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getGlobalInstance, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getGlobalInstance)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *instance = *zend_std_get_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), 0 PHP_HTTP_ZEND_LITERAL_CCN TSRMLS_CC);
+ zval *instance;
- if (Z_TYPE_P(instance) != IS_OBJECT) {
- zval **_GET = NULL;
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
- zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
+ instance = *zend_std_get_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), 0 PHP_HTTP_ZEND_LITERAL_CCN TSRMLS_CC);
- if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET))
- && (Z_TYPE_PP(_GET) == IS_ARRAY)
- ) {
- MAKE_STD_ZVAL(instance);
- ZVAL_OBJVAL(instance, php_http_querystring_object_new(php_http_querystring_class_entry TSRMLS_CC), 0);
+ if (Z_TYPE_P(instance) != IS_OBJECT) {
+ zval **_GET = NULL;
- SEPARATE_ZVAL_TO_MAKE_IS_REF(_GET);
- convert_to_array(*_GET);
- zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), *_GET TSRMLS_CC);
+ zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
- zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), instance TSRMLS_CC);
- zval_ptr_dtor(&instance);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Could not acquire reference to superglobal GET array");
- }
- }
- RETVAL_ZVAL(instance, 1, 0);
- } end_error_handling();
+ if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET))
+ && (Z_TYPE_PP(_GET) == IS_ARRAY)
+ ) {
+ MAKE_STD_ZVAL(instance);
+ ZVAL_OBJVAL(instance, php_http_querystring_object_new(php_http_querystring_class_entry TSRMLS_CC), 0);
+
+ SEPARATE_ZVAL_TO_MAKE_IS_REF(_GET);
+ convert_to_array(*_GET);
+ zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), *_GET TSRMLS_CC);
+
+ zend_update_static_property(php_http_querystring_class_entry, ZEND_STRL("instance"), instance TSRMLS_CC);
+ zval_ptr_dtor(&instance);
+ } else {
+ php_http_throw(unexpected_val, "Could not acquire reference to superglobal GET array", NULL);
}
- } end_error_handling();
+ }
+
+ RETVAL_ZVAL(instance, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_getIterator, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, getIterator)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters_none()) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *retval = NULL, *qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
-
- object_init_ex(return_value, spl_ce_RecursiveArrayIterator);
- zend_call_method_with_1_params(&return_value, spl_ce_RecursiveArrayIterator, NULL, "__construct", &retval, qa);
- if (retval) {
- zval_ptr_dtor(&retval);
- }
- } end_error_handling();
- }
- } end_error_handling();
+ zval *retval = NULL, *qa;
+
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+
+ object_init_ex(return_value, spl_ce_RecursiveArrayIterator);
+ zend_call_method_with_1_params(&return_value, spl_ce_RecursiveArrayIterator, NULL, "__construct", &retval, qa);
+ if (retval) {
+ zval_ptr_dtor(&retval);
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_toString, 0, 0, 0)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, toArray)
{
- if (SUCCESS == zend_parse_parameters_none()) {
- zval *zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
- RETURN_ZVAL(zqa, 1, 0);
+ zval *zqa;
+
+ if (SUCCESS != zend_parse_parameters_none()) {
+ return;
}
+
+ zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ RETURN_ZVAL(zqa, 1, 0);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_get, 0, 0, 0)
zval *params;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms)) {
- RETURN_FALSE;
+ return;
}
php_http_querystring_set(getThis(), params, QS_MERGE TSRMLS_CC);
PHP_METHOD(HttpQueryString, mod)
{
zval *params;
+ zend_error_handling zeh;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms), invalid_arg, return);
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- ZVAL_OBJVAL(return_value, Z_OBJ_HT_P(getThis())->clone_obj(getThis() TSRMLS_CC), 0);
- php_http_querystring_set(return_value, params, QS_MERGE TSRMLS_CC);
- } end_error_handling();
- }
- } end_error_handling();
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_querystring_class_entry, &zeh TSRMLS_CC);
+ ZVAL_OBJVAL(return_value, Z_OBJ_HT_P(getThis())->clone_obj(getThis() TSRMLS_CC), 0);
+ php_http_querystring_set(return_value, params, QS_MERGE TSRMLS_CC);
+ zend_restore_error_handling(&zeh TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString___getter, 0, 0, 1)
ZEND_END_ARG_INFO();
PHP_METHOD(HttpQueryString, xlate)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- char *ie, *oe;
- int ie_len, oe_len;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *na, *qa = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC));
-
- MAKE_STD_ZVAL(na);
- array_init(na);
- if (SUCCESS == php_http_querystring_xlate(na, qa, ie, oe TSRMLS_CC)) {
- php_http_querystring_set(getThis(), na, 0 TSRMLS_CC);
- }
+ char *ie, *oe;
+ int ie_len, oe_len;
+ zval *na, *qa;
- zval_ptr_dtor(&na);
- zval_ptr_dtor(&qa);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len), invalid_arg, return);
- RETVAL_ZVAL(getThis(), 1, 0);
- } end_error_handling();
- }
- } end_error_handling();
+ MAKE_STD_ZVAL(na);
+ array_init(na);
+ qa = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC));
+
+ php_http_expect(SUCCESS == php_http_querystring_xlate(na, qa, ie, oe TSRMLS_CC), bad_conversion,
+ zval_ptr_dtor(&na);
+ zval_ptr_dtor(&qa);
+ return;
+ );
+
+ php_http_querystring_set(getThis(), na, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
+ zval_ptr_dtor(&na);
+ zval_ptr_dtor(&qa);
}
#endif /* HAVE_ICONV */
{
zval *serialized;
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- if (Z_TYPE_P(serialized) == IS_STRING) {
- php_http_querystring_set(getThis(), serialized, 0 TSRMLS_CC);
- } else {
- php_http_error(HE_WARNING, PHP_HTTP_E_QUERYSTRING, "Expected a string as parameter");
- }
- } end_error_handling();
- }
- } end_error_handling();
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
+ return;
+ }
+
+ if (Z_TYPE_P(serialized) == IS_STRING) {
+ php_http_querystring_set(getThis(), serialized, 0 TSRMLS_CC);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expected a string as parameter");
+ }
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetGet, 0, 0, 1)
{
char *offset_str;
int offset_len;
- zval **value;
+ zval **value, *qa;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ return;
+ }
- if ((SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len))) {
- zval *qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
- if (Z_TYPE_P(qa) == IS_ARRAY
- && SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
- ) {
+ if (Z_TYPE_P(qa) == IS_ARRAY) {
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)) {
RETVAL_ZVAL(*value, 1, 0);
}
}
{
char *offset_str;
int offset_len;
- zval *value;
+ zval *value, *param;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
- zval *param;
-
- MAKE_STD_ZVAL(param);
- array_init(param);
- Z_ADDREF_P(value);
- add_assoc_zval_ex(param, offset_str, offset_len + 1, value);
- php_http_querystring_set(getThis(), param, 0 TSRMLS_CC);
- zval_ptr_dtor(¶m);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
+ return;
}
+
+ MAKE_STD_ZVAL(param);
+ array_init(param);
+ Z_ADDREF_P(value);
+ add_assoc_zval_ex(param, offset_str, offset_len + 1, value);
+ php_http_querystring_set(getThis(), param, 0 TSRMLS_CC);
+ zval_ptr_dtor(¶m);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetExists, 0, 0, 1)
{
char *offset_str;
int offset_len;
- zval **value;
+ zval **value, *qa;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ return;
+ }
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
- zval *qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
+ qa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC);
- if (Z_TYPE_P(qa) == IS_ARRAY
- && SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)
- && Z_TYPE_PP(value) != IS_NULL
- ) {
- RETURN_TRUE;
+ if (Z_TYPE_P(qa) == IS_ARRAY) {
+ if (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qa), offset_str, offset_len + 1, (void *) &value)) {
+ RETURN_BOOL(Z_TYPE_PP(value) != IS_NULL);
}
- RETURN_FALSE;
}
+ RETURN_FALSE;
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetUnset, 0, 0, 1)
{
char *offset_str;
int offset_len;
+ zval *param;
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
- zval *param;
-
- MAKE_STD_ZVAL(param);
- array_init(param);
- add_assoc_null_ex(param, offset_str, offset_len + 1);
- php_http_querystring_set(getThis(), param, QS_MERGE TSRMLS_CC);
- zval_ptr_dtor(¶m);
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
+ return;
}
+
+ MAKE_STD_ZVAL(param);
+ array_init(param);
+ add_assoc_null_ex(param, offset_str, offset_len + 1);
+ php_http_querystring_set(getThis(), param, QS_MERGE TSRMLS_CC);
+ zval_ptr_dtor(¶m);
}
zend_class_entry *php_http_querystring_class_entry;
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "QueryString", php_http_querystring_methods);
- php_http_querystring_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_querystring_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
+ php_http_querystring_class_entry->create_object = php_http_querystring_object_new;
zend_class_implements(php_http_querystring_class_entry TSRMLS_CC, 3, zend_ce_serializable, zend_ce_arrayaccess, zend_ce_aggregate);
zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("instance"), (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
#include "php_http_api.h"
-PHP_HTTP_API php_http_strlist_iterator_t *php_http_strlist_iterator_init(php_http_strlist_iterator_t *iter, const char list[], unsigned factor)
+php_http_strlist_iterator_t *php_http_strlist_iterator_init(php_http_strlist_iterator_t *iter, const char list[], unsigned factor)
{
if (!iter) {
iter = emalloc(sizeof(*iter));
return iter;
}
-PHP_HTTP_API const char *php_http_strlist_iterator_this(php_http_strlist_iterator_t *iter, unsigned *id)
+const char *php_http_strlist_iterator_this(php_http_strlist_iterator_t *iter, unsigned *id)
{
if (id) {
*id = (iter->major + 1) * iter->factor + iter->minor;
return iter->p;
}
-PHP_HTTP_API const char *php_http_strlist_iterator_next(php_http_strlist_iterator_t *iter)
+const char *php_http_strlist_iterator_next(php_http_strlist_iterator_t *iter)
{
if (*iter->p) {
while (*iter->p) {
return iter->p;
}
-PHP_HTTP_API void php_http_strlist_iterator_dtor(php_http_strlist_iterator_t *iter)
+void php_http_strlist_iterator_dtor(php_http_strlist_iterator_t *iter)
{
}
-PHP_HTTP_API void php_http_strlist_iterator_free(php_http_strlist_iterator_t **iter)
+void php_http_strlist_iterator_free(php_http_strlist_iterator_t **iter)
{
if (*iter) {
efree(*iter);
}
}
-PHP_HTTP_API const char *php_http_strlist_find(const char list[], unsigned factor, unsigned item)
+const char *php_http_strlist_find(const char list[], unsigned factor, unsigned item)
{
unsigned M = 0, m = 0, major, minor;
const char *p = &list[0];
return url;
}
-PHP_HTTP_API void php_http_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC)
+void php_http_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC)
{
php_url *url, *tmp_url = NULL;
}
}
-PHP_HTTP_API STATUS php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC)
+STATUS php_http_url_encode_hash(HashTable *hash, const char *pre_encoded_str, size_t pre_encoded_len, char **encoded_str, size_t *encoded_len TSRMLS_DC)
{
const char *arg_sep_str;
size_t arg_sep_len;
return SUCCESS;
}
-PHP_HTTP_API STATUS php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len TSRMLS_DC)
+STATUS php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer_t *qstr, const char *arg_sep_str, size_t arg_sep_len, const char *val_sep_str, size_t val_sep_len, const char *pre_encoded_str, size_t pre_encoded_len TSRMLS_DC)
{
if (pre_encoded_len && pre_encoded_str) {
php_http_buffer_append(qstr, pre_encoded_str, pre_encoded_len);
ZEND_END_ARG_INFO();
PHP_METHOD(HttpUrl, __construct)
{
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- zval *new_url = NULL, *old_url = NULL;
- long flags = PHP_HTTP_URL_FROM_ENV;
-
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags)) {
- with_error_handling(EH_THROW, php_http_exception_class_entry) {
- php_url *res_purl, *new_purl = NULL, *old_purl = NULL;
-
- if (new_url) {
- switch (Z_TYPE_P(new_url)) {
- case IS_OBJECT:
- case IS_ARRAY:
- new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
- break;
- default: {
- zval *cpy = php_http_ztyp(IS_STRING, new_url);
+ zval *new_url = NULL, *old_url = NULL;
+ long flags = PHP_HTTP_URL_FROM_ENV;
+ zend_error_handling zeh;
- new_purl = php_url_parse(Z_STRVAL_P(cpy));
- zval_ptr_dtor(&cpy);
- break;
- }
- }
- if (!new_purl) {
- return;
- }
- }
- if (old_url) {
- switch (Z_TYPE_P(old_url)) {
- case IS_OBJECT:
- case IS_ARRAY:
- old_purl = php_http_url_from_struct(NULL, HASH_OF(old_url) TSRMLS_CC);
- break;
- default: {
- zval *cpy = php_http_ztyp(IS_STRING, old_url);
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!z!l", &old_url, &new_url, &flags), invalid_arg, return);
- old_purl = php_url_parse(Z_STRVAL_P(cpy));
- zval_ptr_dtor(&cpy);
- break;
- }
- }
- if (!old_purl) {
- if (new_purl) {
- php_url_free(new_purl);
- }
- return;
- }
- }
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
+ {
+ php_url *res_purl, *new_purl = NULL, *old_purl = NULL;
- php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
- php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
+ if (new_url) {
+ switch (Z_TYPE_P(new_url)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ new_purl = php_http_url_from_struct(NULL, HASH_OF(new_url) TSRMLS_CC);
+ break;
+ default: {
+ zval *cpy = php_http_ztyp(IS_STRING, new_url);
- php_url_free(res_purl);
- if (old_purl) {
- php_url_free(old_purl);
+ new_purl = php_url_parse(Z_STRVAL_P(cpy));
+ zval_ptr_dtor(&cpy);
+ break;
}
+ }
+ if (!new_purl) {
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+ return;
+ }
+ }
+ if (old_url) {
+ switch (Z_TYPE_P(old_url)) {
+ case IS_OBJECT:
+ case IS_ARRAY:
+ old_purl = php_http_url_from_struct(NULL, HASH_OF(old_url) TSRMLS_CC);
+ break;
+ default: {
+ zval *cpy = php_http_ztyp(IS_STRING, old_url);
+
+ old_purl = php_url_parse(Z_STRVAL_P(cpy));
+ zval_ptr_dtor(&cpy);
+ break;
+ }
+ }
+ if (!old_purl) {
if (new_purl) {
php_url_free(new_purl);
}
- } end_error_handling();
+ zend_restore_error_handling(&zeh TSRMLS_CC);
+ return;
+ }
+ }
+
+ php_http_url(flags, old_purl, new_purl, &res_purl, NULL, NULL TSRMLS_CC);
+ php_http_url_to_struct(res_purl, getThis() TSRMLS_CC);
+
+ php_url_free(res_purl);
+ if (old_purl) {
+ php_url_free(old_purl);
}
- } end_error_handling();
+ if (new_purl) {
+ php_url_free(new_purl);
+ }
+ }
+ zend_restore_error_handling(&zeh TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1)
{
zval *new_url = NULL;
long flags = PHP_HTTP_URL_JOIN_PATH | PHP_HTTP_URL_JOIN_QUERY;
+ zend_error_handling zeh;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags), invalid_arg, return);
- if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!|l", &new_url, &flags)) {
+ zend_replace_error_handling(EH_THROW, php_http_exception_bad_url_class_entry, &zeh TSRMLS_CC);
+ {
php_url *new_purl = NULL, *old_purl = NULL;
if (new_url) {
}
}
if (!new_purl) {
+ zend_restore_error_handling(&zeh TSRMLS_CC);
return;
}
}
php_url_free(new_purl);
}
}
+ zend_restore_error_handling(&zeh TSRMLS_CC);
}
ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0)
zend_class_entry ce = {0};
INIT_NS_CLASS_ENTRY(ce, "http", "Url", php_http_url_methods);
- php_http_url_class_entry = zend_register_internal_class_ex(&ce, php_http_object_class_entry, NULL TSRMLS_CC);
+ php_http_url_class_entry = zend_register_internal_class(&ce TSRMLS_CC);
zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("scheme"), ZEND_ACC_PUBLIC TSRMLS_CC);
zend_declare_property_null(php_http_url_class_entry, ZEND_STRL("user"), ZEND_ACC_PUBLIC TSRMLS_CC);
#include "php_http_api.h"
-PHP_HTTP_API php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC)
+php_http_version_t *php_http_version_init(php_http_version_t *v, unsigned major, unsigned minor TSRMLS_DC)
{
if (!v) {
v = emalloc(sizeof(*v));
return v;
}
-PHP_HTTP_API php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC)
+php_http_version_t *php_http_version_parse(php_http_version_t *v, const char *str TSRMLS_DC)
{
php_http_version_t tmp;
char separator = 0;
if (3 != sscanf(str, "HTTP/%u%c%u", &tmp.major, &separator, &tmp.minor)
&& 3 != sscanf(str, "%u%c%u", &tmp.major, &separator, &tmp.minor)) {
- php_http_error(HE_WARNING, PHP_HTTP_E_MALFORMED_HEADERS, "Could not parse HTTP protocol version '%s'", str);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not parse HTTP protocol version '%s'", str);
return NULL;
}
if (separator && separator != '.' && separator != ',') {
- php_http_error(HE_NOTICE, PHP_HTTP_E_MALFORMED_HEADERS, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, str);
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Non-standard version separator '%c' in HTTP protocol version '%s'", separator, str);
}
return php_http_version_init(v, tmp.major, tmp.minor TSRMLS_CC);
}
-PHP_HTTP_API void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC)
+void php_http_version_to_string(php_http_version_t *v, char **str, size_t *len, const char *pre, const char *post TSRMLS_DC)
{
*len = spprintf(str, 0, "%s%u.%u%s", pre ? pre : "", v->major, v->minor, post ? post : "");
}
-PHP_HTTP_API void php_http_version_dtor(php_http_version_t *v)
+void php_http_version_dtor(php_http_version_t *v)
{
(void) v;
}
-PHP_HTTP_API void php_http_version_free(php_http_version_t **v)
+void php_http_version_free(php_http_version_t **v)
{
if (*v) {
php_http_version_dtor(*v);
}
function testAppendError() {
- $this->setExpectedException("PHPUnit_Framework_Error");
+ $this->setExpectedException("http\Exception\RuntimeException");
$this->file->append("nope");
}
function testAppend() {
Done
--EXPECTF--
Test
-Could not fetch response body, output has already been sent at %senvresponsebody002.php:3
+http\Env\Response::__construct(): Could not fetch response body, output has already been sent at %senvresponsebody002.php:3
Done
echo "Test\n";
$header = "wass\nup";
-/* this generates two warnings because of the LF ;) */
http\Header::parse($header);
?>
--EXPECTF--
Test
-Warning: http\Header::parse(): Could not parse headers in %s on line %d
-
Warning: http\Header::parse(): Could not parse headers in %s on line %d
Done
?>
DONE
--EXPECTF--
-exception 'http\Exception' with message 'could not parse message: GET HTTP/1.1' in %s
+exception 'http\Exception\BadMessageException' with message 'Could not parse message: GET HTTP/1.1' in %s
Stack trace:
#0 %s: http\Message->__construct('GET HTTP/1.1')
#1 {main}
-exception 'http\Exception' with message 'could not parse message: GET HTTP/1.123' in %s
+exception 'http\Exception\BadMessageException' with message 'Could not parse message: GET HTTP/1.123' in %s
Stack trace:
#0 %s: http\Message->__construct('GET HTTP/1.123')
#1 {main}
-exception 'http\Exception' with message 'could not parse message: GETHTTP/1.1' in %s
+exception 'http\Exception\BadMessageException' with message 'Could not parse message: GETHTTP/1.1' in %s
Stack trace:
#0 %s: http\Message->__construct('GETHTTP/1.1')
#1 {main}
-object(http\Message)#%d (10) {
- ["errorHandling":protected]=>
- NULL
+object(http\Message)#%d (9) {
["type":protected]=>
int(1)
["body":protected]=>
- object(http\Message\Body)#%d (1) {
- ["errorHandling":protected]=>
- NULL
+ object(http\Message\Body)#%d (0) {
}
["requestMethod":protected]=>
string(3) "GET"
echo "Done\n";
--EXPECTF--
Test
-object(%s)#%d (13) {
- ["errorHandling":protected]=>
- NULL
+object(%s)#%d (12) {
["type":protected]=>
int(1)
["body":protected]=>
- object(%s)#%d (1) {
- ["errorHandling":protected]=>
- NULL
+ object(http\Message\Body)#%d (0) {
}
["requestMethod":protected]=>
string(4) "POST"
["parentMessage":protected]=>
NULL
["query":protected]=>
- object(http\QueryString)#2 (2) {
- ["errorHandling":protected]=>
- NULL
+ object(http\QueryString)#2 (1) {
["queryArray":"http\QueryString":private]=>
array(0) {
}
}
["form":protected]=>
- object(http\QueryString)#3 (2) {
- ["errorHandling":protected]=>
- NULL
+ object(http\QueryString)#3 (1) {
["queryArray":"http\QueryString":private]=>
array(0) {
}
DONE
--EXPECTF--
Test
-object(c)#%d (10) {
+object(c)#%d (9) {
["headers"]=>
array(1) {
["foo"]=>
string(3) "bar"
}
- ["errorHandling":protected]=>
- NULL
["type":protected]=>
int(0)
["body":protected]=>
- object(http\Message\Body)#%d (1) {
- ["errorHandling":protected]=>
- NULL
+ object(http\Message\Body)#%d (0) {
}
["requestMethod":protected]=>
string(0) ""
echo "Test\n";
$m = new http\Message;
-$m->setRequestUrl("/foo");
+try {
+ $m->setRequestUrl("/foo");
+} catch (http\Exception $e) {
+ echo $e->getMessage(),"\n";
+}
$m->setType(http\Message::TYPE_REQUEST);
-$m->setRequestUrl("");
+try {
+ $m->setRequestUrl("");
+} catch (http\Exception $e) {
+ echo $e->getMessage(),"\n";
+}
$m = new http\Message;
try {
$m->getParentMessage();
die("unreached");
} catch (http\Exception $e) {
- var_dump($e->getMessage());
+ echo $e->getMessage(),"\n";
}
$m = new http\Message("HTTP/1.1 200\r\nHTTP/1.1 201");
$m->prepend($m->getParentMessage());
die("unreached");
} catch (http\Exception $e) {
- var_dump($e->getMessage());
+ echo $e->getMessage(),"\n";
}
?>
Done
--EXPECTF--
Test
-
-Notice: http\Message::setRequestUrl(): HttpMessage is not of type REQUEST in %s on line %d
-
-Warning: http\Message::setRequestUrl(): Cannot set HttpMessage::requestUrl to an empty string in %s on line %d
-string(42) "HttpMessage does not have a parent message"
-string(62) "Cannot prepend a message located within the same message chain"
+http\Message is not of type request
+Cannot set http\Message's request url to an empty string
+http\Message has not parent message
+Cannot prepend a message located within the same message chain
Done
?>
DONE
--EXPECTF--
-object(http\Params)#%d (6) {
- ["errorHandling":protected]=>
- NULL
+object(http\Params)#%d (5) {
["params"]=>
array(2) {
["foo"]=>
?>
--FILE--
<?php
+error_reporting(E_ALL);
$m = new http\Message;
-$m->setHttpVersion("1-1");
-$m->setHttpVersion("one.one");
+try {
+ $m->setHttpVersion("1-1");
+ $m->setHttpVersion("one.one");
+} catch (http\Exception $e) {
+ echo $e->getMessage(),"\n";
+}
?>
--EXPECTF--
Notice: http\Message::setHttpVersion(): Non-standard version separator '-' in HTTP protocol version '1-1' in %s
-
-Warning: http\Message::setHttpVersion(): Could not parse HTTP protocol version 'one.one' in %s
+http\Message::setHttpVersion(): Could not parse HTTP protocol version 'one.one'