From 0b83632b2b0a03eeca090f993259ccd95ab646fb Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Sun, 19 May 2013 11:39:21 +0000 Subject: [PATCH] - less custom macro cruft - add TODO - getservby{name,port}_r support - it's 2013 already --- LICENSE | 2 +- TODO | 4 + config9.m4 | 36 +- php_http.c | 72 +--- php_http.h | 3 +- php_http_api.h | 5 +- php_http_buffer.c | 2 +- php_http_buffer.h | 2 +- php_http_client.c | 115 ++++--- php_http_client.h | 23 +- php_http_client_curl.c | 2 +- php_http_client_curl.h | 2 +- php_http_client_request.c | 153 ++++----- php_http_client_request.h | 17 +- php_http_client_response.c | 26 +- php_http_client_response.h | 5 +- php_http_cookie.c | 290 ++++++++-------- php_http_cookie.h | 37 +- php_http_curl.c | 2 +- php_http_curl.h | 2 +- php_http_encoding.c | 191 +++++------ php_http_encoding.h | 41 +-- php_http_env.c | 217 ++++++------ php_http_env.h | 19 +- php_http_env_request.c | 101 +++--- php_http_env_request.h | 10 +- php_http_env_response.c | 189 +++++------ php_http_env_response.h | 20 +- php_http_etag.c | 2 +- php_http_etag.h | 2 +- php_http_exception.c | 50 ++- php_http_exception.h | 5 +- php_http_filter.c | 2 +- php_http_filter.h | 2 +- php_http_header_parser.c | 4 +- php_http_header_parser.h | 2 +- php_http_headers.c | 109 +++--- php_http_headers.h | 13 +- php_http_info.c | 2 +- php_http_info.h | 2 +- php_http_message.c | 635 +++++++++++++++++------------------ php_http_message.h | 57 +--- php_http_message_body.c | 161 ++++----- php_http_message_body.h | 20 +- php_http_message_parser.c | 2 +- php_http_message_parser.h | 2 +- php_http_misc.c | 6 +- php_http_misc.h | 76 +---- php_http_negotiate.c | 2 +- php_http_negotiate.h | 2 +- php_http_object.c | 114 +++---- php_http_object.h | 12 +- php_http_options.c | 2 +- php_http_options.h | 2 +- php_http_params.c | 162 +++++---- php_http_params.h | 14 +- php_http_querystring.c | 282 ++++++++-------- php_http_querystring.h | 30 +- php_http_strlist.c | 2 +- php_http_strlist.h | 2 +- php_http_url.c | 191 +++++++---- php_http_url.h | 12 +- php_http_version.c | 2 +- php_http_version.h | 2 +- tests/clientresponse002.phpt | 4 +- 65 files changed, 1551 insertions(+), 2028 deletions(-) create mode 100644 TODO diff --git a/LICENSE b/LICENSE index b3f886e..0fa6885 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2010, Michael Wallner . +Copyright (c) 2004-2013, Michael Wallner . All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/TODO b/TODO new file mode 100644 index 0000000..b46bf1f --- /dev/null +++ b/TODO @@ -0,0 +1,4 @@ +* let http_info.request.url be a php_url +* let the message body be a simple query string unless files are added +* revisit error handling + \ No newline at end of file diff --git a/config9.m4 b/config9.m4 index e32d146..ea6c692 100644 --- a/config9.m4 +++ b/config9.m4 @@ -100,7 +100,9 @@ dnl ---- PHP_CHECK_FUNC(gethostname, nsl) PHP_CHECK_FUNC(getdomainname, nsl) PHP_CHECK_FUNC(getservbyport, nsl) + PHP_CHECK_FUNC(getservbyport_r, nsl) PHP_CHECK_FUNC(getservbyname, nsl) + PHP_CHECK_FUNC(getservbyname_r, nsl) dnl ---- dnl ZLIB @@ -129,40 +131,6 @@ dnl ---- fi fi -dnl ---- -dnl SERF -dnl ---- -dnl -dnl if test "$PHP_HTTP_LIBSERF_DIR" = "no"; then -dnl AC_DEFINE([PHP_HTTP_HAVE_SERF], [0], [ ]) -dnl else -dnl AC_MSG_CHECKING([for serf-?/serf.h]) -dnl SERF_DIR= -dnl for i in "$PHP_HTTP_LIBSERF_DIR" /usr/local /usr /opt; do -dnl if test -f "$i/include/serf-0/serf.h"; then -dnl SERF_DIR=$i -dnl SERF_VER=0 -dnl break -dnl elif test -f "$i/include/serf-1/serf.h"; then -dnl SERF_DIR=$i -dnl SERF_VER=1 -dnl fi -dnl done - -dnl if test "x$SERF_DIR" = "x"; then -dnl AC_MSG_RESULT([not found]) -dnl AC_DEFINE([PHP_HTTP_HAVE_SERF], [0], [ ]) -dnl else -dnl AC_MSG_RESULT([found in $SERF_DIR]) - -dnl PHP_ADD_INCLUDE($SERF_DIR/include/serf-$SERF_VER) -dnl PHP_ADD_LIBRARY_WITH_PATH(serf-$SERF_VER, $SERF_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD) -dnl AC_DEFINE([PHP_HTTP_HAVE_SERF], [1], [Have libserf support]) -dnl HTTP_HAVE_A_REQUEST_LIB=true -dnl fi -dnl fi -dnl - dnl ---- dnl CURL dnl ---- diff --git a/php_http.c b/php_http.c index 914d695..62c1f8d 100644 --- a/php_http.c +++ b/php_http.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -79,28 +79,6 @@ zend_module_entry http_module_entry = { int http_module_number; -static HashTable http_module_classes; -void php_http_register_class(zend_class_entry *(*get_ce)(void)) -{ - zend_hash_next_index_insert(&http_module_classes, &get_ce, sizeof(get_ce), NULL); -} -static void php_http_registered_classes(php_http_buffer_t *buf, unsigned flags) -{ - HashPosition pos; - zend_class_entry *(**get_ce)(void); - - FOREACH_HASH_VAL(pos, &http_module_classes, get_ce) { - zend_class_entry *ce = (*get_ce)(); - if ((flags && (ce->ce_flags & flags)) || (!flags && !(ce->ce_flags & 0x0fff))) { - if (buf->used) { - php_http_buffer_appends(buf, ", "); - } - php_http_buffer_append(buf, ce->name, ce->name_length); - } - } - php_http_buffer_fix(buf); -} - #if PHP_DEBUG && !HAVE_GCOV void _dpf(int type, const char *data, size_t length) { @@ -146,7 +124,7 @@ zend_php_http_globals *php_http_globals(void) #endif PHP_INI_BEGIN() - PHP_HTTP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode) + STD_PHP_INI_ENTRY("http.etag.mode", "crc32b", PHP_INI_ALL, OnUpdateString, env.etag_mode, zend_php_http_globals, php_http_globals) PHP_INI_END() PHP_MINIT_FUNCTION(http) @@ -155,8 +133,6 @@ PHP_MINIT_FUNCTION(http) ZEND_INIT_MODULE_GLOBALS(php_http, php_http_globals_init_once, NULL); REGISTER_INI_ENTRIES(); - zend_hash_init(&http_module_classes, 0, NULL, NULL, 1); - if (0 || SUCCESS != PHP_MINIT_CALL(http_object) || SUCCESS != PHP_MINIT_CALL(http_exception) @@ -203,8 +179,6 @@ PHP_MSHUTDOWN_FUNCTION(http) return FAILURE; } - zend_hash_destroy(&http_module_classes); - return SUCCESS; } @@ -238,7 +212,6 @@ PHP_RSHUTDOWN_FUNCTION(http) PHP_MINFO_FUNCTION(http) { - unsigned i; php_http_buffer_t buf; php_http_buffer_init(&buf); @@ -272,49 +245,8 @@ PHP_MINFO_FUNCTION(http) php_info_print_table_row(3, "libevent", "disabled", "disabled"); #endif -#if PHP_HTTP_HAVE_SERF - { - int v[3]; - - serf_lib_version(&v[0], &v[1], &v[2]); - php_http_buffer_appendf(&buf, "%d.%d.%d", v[0], v[1], v[2]); - php_http_buffer_fix(&buf); - php_info_print_table_row(3, "libserf", SERF_VERSION_STRING, buf.data); - php_http_buffer_reset(&buf); - } -#else - php_info_print_table_row(3, "libserf", "disabled", "disabled"); -#endif php_info_print_table_end(); - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "Registered API"); - for (i = 0; http_functions[i].fname; ++i) { - if (buf.used) { - php_http_buffer_appends(&buf, ", "); - } - php_http_buffer_appendl(&buf, http_functions[i].fname); - } - php_http_buffer_fix(&buf); - php_info_print_table_row(2, "Functions", buf.data); - php_http_buffer_reset(&buf); - php_http_registered_classes(&buf, ZEND_ACC_INTERFACE); - php_info_print_table_row(2, "Interfaces", buf.data); - php_http_buffer_reset(&buf); - php_http_registered_classes(&buf, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - php_info_print_table_row(2, "Abstract Classes", buf.data); - php_http_buffer_reset(&buf); - php_http_registered_classes(&buf, 0); - php_info_print_table_row(2, "Implemented Classes", buf.data); - php_http_buffer_reset(&buf); - php_http_registered_classes(&buf, ZEND_ACC_FINAL_CLASS); - php_info_print_table_row(2, "Final Classes", buf.data); - php_http_buffer_dtor(&buf); - - php_info_print_table_row(2, "Stream Filters", "http.chunked_encode, http.chunked_decode, http.inflate, http.deflate"); - php_info_print_table_end(); - - DISPLAY_INI_ENTRIES(); } diff --git a/php_http.h b/php_http.h index 40ecfb4..bb9c2d0 100644 --- a/php_http.h +++ b/php_http.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -19,7 +19,6 @@ zend_module_entry http_module_entry; #define phpext_http_ptr &http_module_entry int http_module_number; -void php_http_register_class(zend_class_entry *(*get_ce)(void)); #endif /* PHP_EXT_HTTP_H */ diff --git a/php_http_api.h b/php_http_api.h index 631b620..211c6eb 100644 --- a/php_http_api.h +++ b/php_http_api.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -64,6 +64,9 @@ typedef int STATUS; # ifdef HAVE_UNISTD_H # include # endif +# ifdef HAVE_ERRNO_H +# include +# endif #endif #include diff --git a/php_http_buffer.c b/php_http_buffer.c index 68e9694..84272d0 100644 --- a/php_http_buffer.c +++ b/php_http_buffer.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_buffer.h b/php_http_buffer.h index aaa4408..8ee4eae 100644 --- a/php_http_buffer.h +++ b/php_http_buffer.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_client.c b/php_http_client.c index f23322d..1f4e09a 100644 --- a/php_http_client.c +++ b/php_http_client.c @@ -1,3 +1,15 @@ +/* + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*/ + #include "php_http_api.h" #include "php_http_client.h" @@ -351,7 +363,7 @@ static void handle_history(zval *zclient, php_http_message_t *request, php_http_ { zval *new_hist, *old_hist = zend_read_property(php_http_client_class_entry, zclient, ZEND_STRL("history"), 0 TSRMLS_CC); php_http_message_t *zipped = php_http_message_zip(response, request); - zend_object_value ov = php_http_message_object_new_ex(php_http_message_get_class_entry(), zipped, NULL TSRMLS_CC); + zend_object_value ov = php_http_message_object_new_ex(php_http_message_class_entry, zipped, NULL TSRMLS_CC); MAKE_STD_ZVAL(new_hist); ZVAL_OBJVAL(new_hist, ov, 0); @@ -387,7 +399,7 @@ static STATUS handle_response(void *arg, php_http_client_t *client, php_http_cli *response = NULL; MAKE_STD_ZVAL(zresponse); - ZVAL_OBJVAL(zresponse, php_http_message_object_new_ex(php_http_client_response_get_class_entry(), msg, &msg_obj TSRMLS_CC), 0); + ZVAL_OBJVAL(zresponse, php_http_message_object_new_ex(php_http_client_response_class_entry, msg, &msg_obj TSRMLS_CC), 0); MAKE_STD_ZVAL(zrequest); ZVAL_OBJVAL(zrequest, ((php_http_message_object_t *) e->opaque)->zv, 1); @@ -397,7 +409,7 @@ static STATUS handle_response(void *arg, php_http_client_t *client, php_http_cli MAKE_STD_ZVAL(info); array_init(info); php_http_client_getopt(client, PHP_HTTP_CLIENT_OPT_TRANSFER_INFO, e->request, &Z_ARRVAL_P(info)); - zend_update_property(php_http_client_response_get_class_entry(), zresponse, ZEND_STRL("transferInfo"), info TSRMLS_CC); + zend_update_property(php_http_client_response_class_entry, zresponse, ZEND_STRL("transferInfo"), info TSRMLS_CC); zval_ptr_dtor(&info); zend_objects_store_add_ref_by_handle(msg_obj->zv.handle TSRMLS_CC); @@ -476,7 +488,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_construct, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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; @@ -589,12 +601,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_enqueue, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, enqueue) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry(), &fci, &fcc)) { + 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); @@ -630,10 +642,10 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_dequeue, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, dequeue) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { zval *request; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_get_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 *msg_obj = zend_object_store_get_object(request TSRMLS_CC); @@ -650,12 +662,12 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_requeue, 0, 0, 1) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, requeue) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry(), &fci, &fcc)) { + 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 = { @@ -691,7 +703,7 @@ static PHP_METHOD(HttpClient, getResponse) { zval *zrequest = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &zrequest, php_http_client_request_get_class_entry())) { + 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); if (!zrequest) { @@ -738,9 +750,9 @@ static PHP_METHOD(HttpClient, send) { RETVAL_FALSE; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { if (SUCCESS == zend_parse_parameters_none()) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_exec(obj->client); @@ -779,7 +791,7 @@ static PHP_METHOD(HttpClient, wait) timeout_val.tv_sec = (time_t) timeout; timeout_val.tv_usec = PHP_HTTP_USEC(timeout) % PHP_HTTP_MCROSEC; - RETURN_SUCCESS(php_http_client_wait(obj->client, timeout > 0 ? &timeout_val : NULL)); + RETURN_BOOL(SUCCESS == php_http_client_wait(obj->client, timeout > 0 ? &timeout_val : NULL)); } RETURN_FALSE; } @@ -832,7 +844,7 @@ static PHP_METHOD(HttpClient, notify) { zval *request = NULL, *zprogress = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O!o!", &request, php_http_client_request_get_class_entry(), &zprogress)) { + 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); if (Z_TYPE_P(observers) == IS_OBJECT) { @@ -898,7 +910,7 @@ ZEND_BEGIN_ARG_INFO_EX(ai_HttpClient_getObservers, 0, 0, 0) ZEND_END_ARG_INFO(); static PHP_METHOD(HttpClient, getObservers) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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); @@ -913,8 +925,8 @@ static PHP_METHOD(HttpClient, getProgressInfo) { zval *request; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_get_class_entry())) { + 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; @@ -940,8 +952,8 @@ static PHP_METHOD(HttpClient, getTransferInfo) { zval *request; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, php_http_client_request_get_class_entry())) { + 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); @@ -1059,33 +1071,33 @@ static PHP_METHOD(HttpClient, getAvailableDrivers) { } static zend_function_entry php_http_client_methods[] = { - PHP_ME(HttpClient, __construct, ai_HttpClient_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_ME(HttpClient, reset, ai_HttpClient_reset, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, enqueue, ai_HttpClient_enqueue, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, dequeue, ai_HttpClient_dequeue, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, requeue, ai_HttpClient_requeue, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, send, ai_HttpClient_send, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, once, ai_HttpClient_once, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, wait, ai_HttpClient_wait, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getResponse, ai_HttpClient_getResponse, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getHistory, ai_HttpClient_getHistory, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, enablePipelining, ai_HttpClient_enablePipelining, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, enableEvents, ai_HttpClient_enableEvents, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, notify, ai_HttpClient_notify, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, attach, ai_HttpClient_attach, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, detach, ai_HttpClient_detach, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getObservers, ai_HttpClient_getObservers, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getProgressInfo, ai_HttpClient_getProgressInfo, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getTransferInfo, ai_HttpClient_getTransferInfo, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, setOptions, ai_HttpClient_setOptions, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getOptions, ai_HttpClient_getOptions, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, setSslOptions, ai_HttpClient_setSslOptions, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, addSslOptions, ai_HttpClient_addSslOptions, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getSslOptions, ai_HttpClient_getSslOptions, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, setCookies, ai_HttpClient_setCookies, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, addCookies, ai_HttpClient_addCookies, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getCookies, ai_HttpClient_getCookies, ZEND_ACC_PUBLIC) - PHP_ME(HttpClient, getAvailableDrivers, ai_HttpClient_getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpClient, __construct, ai_HttpClient_construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpClient, reset, ai_HttpClient_reset, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, enqueue, ai_HttpClient_enqueue, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, dequeue, ai_HttpClient_dequeue, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, requeue, ai_HttpClient_requeue, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, send, ai_HttpClient_send, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, once, ai_HttpClient_once, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, wait, ai_HttpClient_wait, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getResponse, ai_HttpClient_getResponse, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getHistory, ai_HttpClient_getHistory, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, enablePipelining, ai_HttpClient_enablePipelining, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, enableEvents, ai_HttpClient_enableEvents, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, notify, ai_HttpClient_notify, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, attach, ai_HttpClient_attach, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, detach, ai_HttpClient_detach, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getObservers, ai_HttpClient_getObservers, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getProgressInfo, ai_HttpClient_getProgressInfo, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getTransferInfo, ai_HttpClient_getTransferInfo, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, setOptions, ai_HttpClient_setOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getOptions, ai_HttpClient_getOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, setSslOptions, ai_HttpClient_setSslOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, addSslOptions, ai_HttpClient_addSslOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getSslOptions, ai_HttpClient_getSslOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, setCookies, ai_HttpClient_setCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, addCookies, ai_HttpClient_addCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getCookies, ai_HttpClient_getCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpClient, getAvailableDrivers, ai_HttpClient_getAvailableDrivers, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) EMPTY_FUNCTION_ENTRY }; @@ -1114,3 +1126,12 @@ PHP_MSHUTDOWN_FUNCTION(http_client) zend_hash_destroy(&php_http_client_drivers); 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 + */ diff --git a/php_http_client.h b/php_http_client.h index 9a7c630..9bc5295 100644 --- a/php_http_client.h +++ b/php_http_client.h @@ -1,3 +1,15 @@ +/* + +--------------------------------------------------------------------+ + | 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 | + +--------------------------------------------------------------------+ +*/ + #ifndef PHP_HTTP_CLIENT_H #define PHP_HTTP_CLIENT_H @@ -99,7 +111,7 @@ typedef struct php_http_client { #endif } php_http_client_t; -zend_class_entry *php_http_client_class_entry; +PHP_HTTP_API zend_class_entry *php_http_client_class_entry; typedef struct php_http_client_object { zend_object zo; @@ -133,3 +145,12 @@ PHP_MINIT_FUNCTION(http_client); PHP_MSHUTDOWN_FUNCTION(http_client); #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 + */ diff --git a/php_http_client_curl.c b/php_http_client_curl.c index ca7aaeb..a5af70d 100644 --- a/php_http_client_curl.c +++ b/php_http_client_curl.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_client_curl.h b/php_http_client_curl.h index 51320a2..6495568 100644 --- a/php_http_client_curl.h +++ b/php_http_client_curl.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_client_request.c b/php_http_client_request.c index 42117f9..2d427a3 100644 --- a/php_http_client_request.c +++ b/php_http_client_request.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -16,86 +16,27 @@ void php_http_client_options_set_subr(zval *this_ptr, char *key, size_t len, zva 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_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpClientRequest, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpClientRequest, method, 0) -#define PHP_HTTP_CLIENT_REQUEST_ME(method, visibility) PHP_ME(HttpClientRequest, method, PHP_HTTP_ARGS(HttpClientRequest, method), visibility) -#define PHP_HTTP_CLIENT_REQUEST_ALIAS(method, func) PHP_HTTP_STATIC_ME_ALIAS(method, func, PHP_HTTP_ARGS(HttpClientRequest, method)) -#define PHP_HTTP_CLIENT_REQUEST_MALIAS(me, al, vis) ZEND_FENTRY(me, ZEND_MN(HttpClientRequest_##al), PHP_HTTP_ARGS(HttpClientRequest, al), vis) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(method, 0) - PHP_HTTP_ARG_VAL(url, 0) - PHP_HTTP_ARG_ARR(headers, 1, 0) - PHP_HTTP_ARG_OBJ(http\\Message\\Body, body, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getContentType); -PHP_HTTP_BEGIN_ARGS(setContentType, 1) - PHP_HTTP_ARG_VAL(content_type, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getQuery); -PHP_HTTP_BEGIN_ARGS(setQuery, 0) - PHP_HTTP_ARG_VAL(query_data, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addQuery, 1) - PHP_HTTP_ARG_VAL(query_data, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getOptions); -PHP_HTTP_BEGIN_ARGS(setOptions, 0) - PHP_HTTP_ARG_ARR(options, 1, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getSslOptions); -PHP_HTTP_BEGIN_ARGS(setSslOptions, 0) - PHP_HTTP_ARG_ARR(ssl_options, 1, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addSslOptions, 0) - PHP_HTTP_ARG_ARR(ssl_options, 1, 0) -PHP_HTTP_END_ARGS; - - -static zend_class_entry *php_http_client_request_class_entry; - -zend_class_entry * php_http_client_request_get_class_entry(void) -{ - return php_http_client_request_class_entry; -} - -static zend_function_entry php_http_client_request_method_entry[] = { - PHP_HTTP_CLIENT_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_CLIENT_REQUEST_ME(getQuery, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(setQuery, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(addQuery, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(getContentType, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(setContentType, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(setOptions, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC) - PHP_HTTP_CLIENT_REQUEST_ME(addSslOptions, ZEND_ACC_PUBLIC) - EMPTY_FUNCTION_ENTRY -}; - - -PHP_METHOD(HttpClientRequest, __construct) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest___construct, 0, 0, 0) + ZEND_ARG_INFO(0, method) + ZEND_ARG_INFO(0, url) + ZEND_ARG_ARRAY_INFO(0, headers, 1) + ZEND_ARG_OBJ_INFO(0, body, http\\Message\\Body, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, __construct) { char *meth_str = NULL, *url_str = NULL; int meth_len = 0, url_len = 0; zval *zheaders = NULL, *zbody = NULL; - with_error_handling(EH_THROW, php_http_exception_get_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_get_class_entry())) { + 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_message_body_object_t *body_obj = NULL; if (zbody) { body_obj = zend_object_store_get_object(zbody TSRMLS_CC); Z_OBJ_ADDREF_P(zbody); - obj->body = Z_OBJVAL_P(zbody); + obj->body->zv = Z_OBJVAL_P(zbody); php_http_message_body_addref(body_obj->body); } @@ -122,8 +63,10 @@ PHP_METHOD(HttpClientRequest, __construct) } end_error_handling(); } - -PHP_METHOD(HttpClientRequest, setContentType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setContentType, 0, 0, 1) + ZEND_ARG_INFO(0, content_type) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, setContentType) { char *ct_str; int ct_len; @@ -147,7 +90,9 @@ PHP_METHOD(HttpClientRequest, setContentType) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpClientRequest, getContentType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getContentType, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, getContentType) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -158,7 +103,10 @@ PHP_METHOD(HttpClientRequest, getContentType) RETURN_FALSE; } -PHP_METHOD(HttpClientRequest, setQuery) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setQuery, 0, 0, 0) + ZEND_ARG_INFO(0, query_data) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, setQuery) { zval *qdata = NULL; @@ -199,7 +147,9 @@ PHP_METHOD(HttpClientRequest, setQuery) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpClientRequest, getQuery) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getQuery, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, getQuery) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -218,7 +168,10 @@ PHP_METHOD(HttpClientRequest, getQuery) } } -PHP_METHOD(HttpClientRequest, addQuery) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_addQuery, 0, 0, 1) + ZEND_ARG_INFO(0, query_data) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, addQuery) { zval *qdata; @@ -252,7 +205,10 @@ PHP_METHOD(HttpClientRequest, addQuery) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpClientRequest, setOptions) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setOptions, 0, 0, 0) + ZEND_ARG_ARRAY_INFO(0, options, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, setOptions) { zval *opts = NULL; @@ -263,15 +219,21 @@ PHP_METHOD(HttpClientRequest, setOptions) } } -PHP_METHOD(HttpClientRequest, getOptions) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getOptions, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, getOptions) { if (SUCCESS == zend_parse_parameters_none()) { - RETURN_PROP(php_http_client_request_class_entry, "options"); + 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; } -PHP_METHOD(HttpClientRequest, setSslOptions) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_setSslOptions, 0, 0, 0) + ZEND_ARG_ARRAY_INFO(0, ssl_options, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, setSslOptions) { zval *opts = NULL; @@ -282,7 +244,10 @@ PHP_METHOD(HttpClientRequest, setSslOptions) } } -PHP_METHOD(HttpClientRequest, addSslOptions) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_addSslOptions, 0, 0, 0) + ZEND_ARG_ARRAY_INFO(0, ssl_options, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, addSslOptions) { zval *opts = NULL; @@ -293,16 +258,38 @@ PHP_METHOD(HttpClientRequest, addSslOptions) } } -PHP_METHOD(HttpClientRequest, getSslOptions) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpClientRequest_getSslOptions, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpClientRequest, getSslOptions) { if (SUCCESS == zend_parse_parameters_none()) { php_http_client_options_get_subr(getThis(), ZEND_STRS("ssl"), return_value TSRMLS_CC); } } +static zend_function_entry php_http_client_request_methods[] = { + PHP_ME(HttpClientRequest, __construct, ai_HttpClientRequest___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpClientRequest, setContentType, ai_HttpClientRequest_setContentType, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, getContentType, ai_HttpClientRequest_getContentType, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, setQuery, ai_HttpClientRequest_setQuery, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, getQuery, ai_HttpClientRequest_getQuery, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, addQuery, ai_HttpClientRequest_addQuery, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, setOptions, ai_HttpClientRequest_setOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, getOptions, ai_HttpClientRequest_getOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, setSslOptions, ai_HttpClientRequest_setSslOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, getSslOptions, ai_HttpClientRequest_getSslOptions, ZEND_ACC_PUBLIC) + PHP_ME(HttpClientRequest, addSslOptions, ai_HttpClientRequest_addSslOptions, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_client_request_class_entry; + PHP_MINIT_FUNCTION(http_client_request) { - PHP_HTTP_REGISTER_CLASS(http\\Client, Request, http_client_request, php_http_message_get_class_entry(), 0); + zend_class_entry ce = {0}; + + INIT_NS_CLASS_ENTRY(ce, "http\\Client", "Request", php_http_client_request_methods); + php_http_client_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC); zend_declare_property_null(php_http_client_request_class_entry, ZEND_STRL("options"), ZEND_ACC_PROTECTED TSRMLS_CC); diff --git a/php_http_client_request.h b/php_http_client_request.h index 2087f4d..5f4da53 100644 --- a/php_http_client_request.h +++ b/php_http_client_request.h @@ -6,27 +6,14 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #ifndef PHP_HTTP_CLIENT_REQUEST_H #define PHP_HTTP_CLIENT_REQUEST_H -zend_class_entry *php_http_client_request_get_class_entry(void); - -PHP_METHOD(HttpClientRequest, __construct); -PHP_METHOD(HttpClientRequest, setContentType); -PHP_METHOD(HttpClientRequest, getContentType); -PHP_METHOD(HttpClientRequest, setQuery); -PHP_METHOD(HttpClientRequest, getQuery); -PHP_METHOD(HttpClientRequest, addQuery); -PHP_METHOD(HttpClientRequest, setOptions); -PHP_METHOD(HttpClientRequest, getOptions); -PHP_METHOD(HttpClientRequest, addSslOptions); -PHP_METHOD(HttpClientRequest, setSslOptions); -PHP_METHOD(HttpClientRequest, getSslOptions); - +PHP_HTTP_API zend_class_entry *php_http_client_request_class_entry; PHP_MINIT_FUNCTION(http_client_request); #endif /* PHP_HTTP_CLIENT_REQUEST_H */ diff --git a/php_http_client_response.c b/php_http_client_response.c index 5068856..de27904 100644 --- a/php_http_client_response.c +++ b/php_http_client_response.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -53,7 +53,7 @@ static PHP_METHOD(HttpClientResponse, getCookies) zval *cookie; MAKE_STD_ZVAL(cookie); - ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list, NULL TSRMLS_CC), 0); + ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); add_next_index_zval(return_value, cookie); } zval_ptr_dtor(&data); @@ -64,7 +64,7 @@ static PHP_METHOD(HttpClientResponse, getCookies) zval *cookie; MAKE_STD_ZVAL(cookie); - ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_get_class_entry(), list, NULL TSRMLS_CC), 0); + ZVAL_OBJVAL(cookie, php_http_cookie_object_new_ex(php_http_cookie_class_entry, list, NULL TSRMLS_CC), 0); add_next_index_zval(return_value, cookie); } zval_ptr_dtor(&data); @@ -93,7 +93,7 @@ static PHP_METHOD(HttpClientResponse, getTransferInfo) int info_len = 0; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) { - zval **infop, *info = zend_read_property(php_http_client_response_get_class_entry(), getThis(), ZEND_STRL("transferInfo"), 0 TSRMLS_CC); + zval **infop, *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_ARRAY) { @@ -111,22 +111,20 @@ static PHP_METHOD(HttpClientResponse, getTransferInfo) RETURN_FALSE; } -static zend_class_entry *php_http_client_response_class_entry; - -zend_class_entry *php_http_client_response_get_class_entry(void) -{ - return php_http_client_response_class_entry; -} - -static zend_function_entry php_http_client_response_method_entry[] = { - PHP_ME(HttpClientResponse, getCookies, ai_HttpClientResponse_getCookies, ZEND_ACC_PUBLIC) +static zend_function_entry php_http_client_response_methods[] = { + PHP_ME(HttpClientResponse, getCookies, ai_HttpClientResponse_getCookies, ZEND_ACC_PUBLIC) PHP_ME(HttpClientResponse, getTransferInfo, ai_HttpClientResponse_getTransferInfo, ZEND_ACC_PUBLIC) EMPTY_FUNCTION_ENTRY }; +zend_class_entry *php_http_client_response_class_entry; + PHP_MINIT_FUNCTION(http_client_response) { - PHP_HTTP_REGISTER_CLASS(http\\Client, Response, http_client_response, php_http_message_get_class_entry(), 0); + zend_class_entry ce = {0}; + + 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); return SUCCESS; } diff --git a/php_http_client_response.h b/php_http_client_response.h index 7ff0ae5..6cf677a 100644 --- a/php_http_client_response.h +++ b/php_http_client_response.h @@ -6,15 +6,14 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #ifndef PHP_HTTP_CLIENT_RESPONSE_H #define PHP_HTTP_CLIENT_RESPONSE_H -zend_class_entry *php_http_client_response_get_class_entry(void); - +PHP_HTTP_API zend_class_entry *php_http_client_response_class_entry; PHP_MINIT_FUNCTION(http_client_response); #endif /* PHP_HTTP_CLIENT_RESPONSE_H */ diff --git a/php_http_cookie.c b/php_http_cookie.c index 008c76d..d9f2551 100644 --- a/php_http_cookie.c +++ b/php_http_cookie.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -359,117 +359,8 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c *len = buf.used; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpCookie, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpCookie, method, 0) -#define PHP_HTTP_COOKIE_ME(method, visibility) PHP_ME(HttpCookie, method, PHP_HTTP_ARGS(HttpCookie, method), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(cookie_string, 0) - PHP_HTTP_ARG_VAL(parser_flags, 0) - PHP_HTTP_ARG_VAL(allowed_extras, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(toArray); -PHP_HTTP_EMPTY_ARGS(getCookies); -PHP_HTTP_EMPTY_ARGS(getExtras); -PHP_HTTP_EMPTY_ARGS(getDomain); -PHP_HTTP_EMPTY_ARGS(getPath); -PHP_HTTP_EMPTY_ARGS(getExpires); -PHP_HTTP_EMPTY_ARGS(getMaxAge); -PHP_HTTP_EMPTY_ARGS(getFlags); -PHP_HTTP_EMPTY_ARGS(toString); - -PHP_HTTP_BEGIN_ARGS(setDomain, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setPath, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setExpires, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setMaxAge, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setFlags, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setCookies, 0) - PHP_HTTP_ARG_VAL(cookies, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(addCookies, 1) - PHP_HTTP_ARG_VAL(cookies, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setExtras, 0) - PHP_HTTP_ARG_VAL(extras, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(addExtras, 1) - PHP_HTTP_ARG_VAL(extras, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setCookie, 1) - PHP_HTTP_ARG_VAL(cookie_name, 0) - PHP_HTTP_ARG_VAL(cookie_value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(addCookie, 1) - PHP_HTTP_ARG_VAL(cookie_name, 0) - PHP_HTTP_ARG_VAL(cookie_value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(getCookie, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(setExtra, 1) - PHP_HTTP_ARG_VAL(extra_name, 0) - PHP_HTTP_ARG_VAL(extra_value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(addExtra, 1) - PHP_HTTP_ARG_VAL(extra_name, 0) - PHP_HTTP_ARG_VAL(extra_value, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(getExtra, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_cookie_class_entry; - -zend_class_entry *php_http_cookie_get_class_entry(void) -{ - return php_http_cookie_class_entry; -} - -static zend_function_entry php_http_cookie_method_entry[] = { - PHP_HTTP_COOKIE_ME(__construct, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getCookies, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setCookies, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(addCookies, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getCookie, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setCookie, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(addCookie, ZEND_ACC_PUBLIC) - - PHP_HTTP_COOKIE_ME(getExtras, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setExtras, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(addExtras, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getExtra, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setExtra, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(addExtra, ZEND_ACC_PUBLIC) - - PHP_HTTP_COOKIE_ME(getDomain, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setDomain, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getPath, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setPath, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getExpires, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setExpires, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getMaxAge, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setMaxAge, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(getFlags, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(setFlags, ZEND_ACC_PUBLIC) - - PHP_HTTP_COOKIE_ME(toArray, ZEND_ACC_PUBLIC) - PHP_HTTP_COOKIE_ME(toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpCookie, __toString, toString, PHP_HTTP_ARGS(HttpCookie, toString), ZEND_ACC_PUBLIC) - EMPTY_FUNCTION_ENTRY -}; + static zend_object_handlers php_http_cookie_object_handlers; zend_object_value php_http_cookie_object_new(zend_class_entry *ce TSRMLS_DC) @@ -479,7 +370,6 @@ zend_object_value php_http_cookie_object_new(zend_class_entry *ce TSRMLS_DC) zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_cookie_list_t *list, php_http_cookie_object_t **ptr TSRMLS_DC) { - zend_object_value ov; php_http_cookie_object_t *o; o = ecalloc(sizeof(*o), 1); @@ -494,10 +384,10 @@ zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_c *ptr = o; } - ov.handle = zend_objects_store_put(o, NULL, php_http_cookie_object_free, NULL TSRMLS_CC); - ov.handlers = &php_http_cookie_object_handlers; + o->zv.handle = zend_objects_store_put(o, NULL, php_http_cookie_object_free, NULL TSRMLS_CC); + o->zv.handlers = &php_http_cookie_object_handlers; - return ov; + return o->zv; } #define PHP_HTTP_COOKIE_OBJECT_INIT(obj) \ @@ -514,7 +404,7 @@ zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC) PHP_HTTP_COOKIE_OBJECT_INIT(old_obj); - ov = php_http_cookie_object_new_ex(old_obj->o.ce, php_http_cookie_list_copy(old_obj->list, NULL), &new_obj TSRMLS_CC); + ov = php_http_cookie_object_new_ex(old_obj->zo.ce, php_http_cookie_list_copy(old_obj->list, NULL), &new_obj TSRMLS_CC); zend_objects_clone_members((zend_object *) new_obj, ov, (zend_object *) old_obj, Z_OBJ_HANDLE_P(getThis()) TSRMLS_CC); return ov; @@ -529,9 +419,14 @@ void php_http_cookie_object_free(void *object TSRMLS_DC) efree(obj); } -PHP_METHOD(HttpCookie, __construct) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie___construct, 0, 0, 0) + ZEND_ARG_INFO(0, cookie_string) + ZEND_ARG_INFO(0, parser_flags) + ZEND_ARG_INFO(0, allowed_extras) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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; @@ -539,7 +434,7 @@ PHP_METHOD(HttpCookie, __construct) 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_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { char **ae = NULL; @@ -596,7 +491,9 @@ PHP_METHOD(HttpCookie, __construct) } end_error_handling(); } -PHP_METHOD(HttpCookie, getCookies) +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); @@ -610,7 +507,10 @@ PHP_METHOD(HttpCookie, getCookies) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setCookies) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setCookies, 0, 0, 0) + ZEND_ARG_INFO(0, cookies) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setCookies) { HashTable *cookies = NULL; @@ -627,7 +527,10 @@ PHP_METHOD(HttpCookie, setCookies) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, addCookies) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookies, 0, 0, 1) + ZEND_ARG_INFO(0, cookies) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, addCookies) { HashTable *cookies = NULL; @@ -641,8 +544,9 @@ PHP_METHOD(HttpCookie, addCookies) RETVAL_ZVAL(getThis(), 1, 0); } - -PHP_METHOD(HttpCookie, getExtras) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getExtras, 0, 0, 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); @@ -656,7 +560,10 @@ PHP_METHOD(HttpCookie, getExtras) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setExtras) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtras, 0, 0, 0) + ZEND_ARG_INFO(0, extras) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setExtras) { HashTable *extras = NULL; @@ -673,7 +580,10 @@ PHP_METHOD(HttpCookie, setExtras) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, addExtras) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtras, 0, 0, 1) + ZEND_ARG_INFO(0, extras) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, addExtras) { HashTable *extras = NULL; @@ -687,7 +597,10 @@ PHP_METHOD(HttpCookie, addExtras) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getCookie) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getCookie, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, getCookie) { char *name_str; int name_len; @@ -705,7 +618,11 @@ PHP_METHOD(HttpCookie, getCookie) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setCookie) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setCookie, 0, 0, 1) + ZEND_ARG_INFO(0, cookie_name) + ZEND_ARG_INFO(0, cookie_value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setCookie) { char *name_str, *value_str = NULL; int name_len, value_len = 0; @@ -724,7 +641,11 @@ PHP_METHOD(HttpCookie, setCookie) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, addCookie) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addCookie, 0, 0, 1) + ZEND_ARG_INFO(0, cookie_name) + ZEND_ARG_INFO(0, cookie_value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, addCookie) { char *name_str, *value_str; int name_len, value_len; @@ -739,7 +660,10 @@ PHP_METHOD(HttpCookie, addCookie) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getExtra) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getExtra, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, getExtra) { char *name_str; int name_len; @@ -757,7 +681,11 @@ PHP_METHOD(HttpCookie, getExtra) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setExtra) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExtra, 0, 0, 1) + ZEND_ARG_INFO(0, extra_name) + ZEND_ARG_INFO(0, extra_value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setExtra) { char *name_str, *value_str = NULL; int name_len, value_len = 0; @@ -776,7 +704,11 @@ PHP_METHOD(HttpCookie, setExtra) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, addExtra) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_addExtra, 0, 0, 1) + ZEND_ARG_INFO(0, extra_name) + ZEND_ARG_INFO(0, extra_value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, addExtra) { char *name_str, *value_str; int name_len, value_len; @@ -791,7 +723,9 @@ PHP_METHOD(HttpCookie, addExtra) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getDomain) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getDomain, 0, 0, 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); @@ -806,7 +740,10 @@ PHP_METHOD(HttpCookie, getDomain) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setDomain) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setDomain, 0, 0, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setDomain) { char *domain_str = NULL; int domain_len = 0; @@ -821,7 +758,9 @@ PHP_METHOD(HttpCookie, setDomain) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getPath) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getPath, 0, 0, 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); @@ -836,7 +775,10 @@ PHP_METHOD(HttpCookie, getPath) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setPath) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setPath, 0, 0, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setPath) { char *path_str = NULL; int path_len = 0; @@ -851,7 +793,9 @@ PHP_METHOD(HttpCookie, setPath) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getExpires) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getExpires, 0, 0, 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); @@ -863,7 +807,10 @@ PHP_METHOD(HttpCookie, getExpires) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setExpires) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setExpires, 0, 0, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setExpires) { long ts = -1; @@ -877,7 +824,9 @@ PHP_METHOD(HttpCookie, setExpires) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getMaxAge) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getMaxAge, 0, 0, 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); @@ -889,7 +838,10 @@ PHP_METHOD(HttpCookie, getMaxAge) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setMaxAge) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setMaxAge, 0, 0, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setMaxAge) { long ts = -1; @@ -903,7 +855,9 @@ PHP_METHOD(HttpCookie, setMaxAge) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, getFlags) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_getFlags, 0, 0, 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); @@ -915,7 +869,10 @@ PHP_METHOD(HttpCookie, getFlags) RETURN_FALSE; } -PHP_METHOD(HttpCookie, setFlags) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_setFlags, 0, 0, 0) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpCookie, setFlags) { long flags = 0; @@ -929,7 +886,9 @@ PHP_METHOD(HttpCookie, setFlags) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpCookie, toString) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpCookie_toString, 0, 0, 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); @@ -944,7 +903,9 @@ PHP_METHOD(HttpCookie, toString) RETURN_EMPTY_STRING(); } -PHP_METHOD(HttpCookie, toArray) +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); @@ -956,9 +917,48 @@ PHP_METHOD(HttpCookie, toArray) } } +static zend_function_entry php_http_cookie_methods[] = { + PHP_ME(HttpCookie, __construct, ai_HttpCookie___construct, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getCookies, ai_HttpCookie_getCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setCookies, ai_HttpCookie_setCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, addCookies, ai_HttpCookie_addCookies, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getCookie, ai_HttpCookie_getCookie, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setCookie, ai_HttpCookie_setCookie, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, addCookie, ai_HttpCookie_addCookie, ZEND_ACC_PUBLIC) + + PHP_ME(HttpCookie, getExtras, ai_HttpCookie_getExtras, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setExtras, ai_HttpCookie_setExtras, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, addExtras, ai_HttpCookie_addExtras, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getExtra, ai_HttpCookie_getExtra, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setExtra, ai_HttpCookie_setExtra, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, addExtra, ai_HttpCookie_addExtra, ZEND_ACC_PUBLIC) + + PHP_ME(HttpCookie, getDomain, ai_HttpCookie_getDomain, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setDomain, ai_HttpCookie_setDomain, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getPath, ai_HttpCookie_getPath, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setPath, ai_HttpCookie_setPath, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getExpires, ai_HttpCookie_getExpires, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setExpires, ai_HttpCookie_setExpires, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getMaxAge, ai_HttpCookie_getMaxAge, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setMaxAge, ai_HttpCookie_setMaxAge, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, getFlags, ai_HttpCookie_getFlags, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, setFlags, ai_HttpCookie_setFlags, ZEND_ACC_PUBLIC) + + PHP_ME(HttpCookie, toArray, ai_HttpCookie_toArray, ZEND_ACC_PUBLIC) + PHP_ME(HttpCookie, toString, ai_HttpCookie_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpCookie, __toString, toString, ai_HttpCookie_toString, ZEND_ACC_PUBLIC) + + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_cookie_class_entry; + PHP_MINIT_FUNCTION(http_cookie) { - PHP_HTTP_REGISTER_CLASS(http, Cookie, http_cookie, php_http_object_get_class_entry(), 0); + 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->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; diff --git a/php_http_cookie.h b/php_http_cookie.h index 7ff0b7c..9d5b7c8 100644 --- a/php_http_cookie.h +++ b/php_http_cookie.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -57,11 +57,11 @@ PHP_HTTP_API void php_http_cookie_list_to_string(php_http_cookie_list_t *list, c 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_API void php_http_cookie_list_to_struct(php_http_cookie_list_t *list, zval *strct); - -zend_class_entry *php_http_cookie_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_cookie_class_entry; typedef struct php_http_cookie_object { - zend_object o; + zend_object zo; + zend_object_value zv; php_http_cookie_list_t *list; } php_http_cookie_object_t; @@ -70,34 +70,7 @@ zend_object_value php_http_cookie_object_new_ex(zend_class_entry *ce, php_http_c zend_object_value php_http_cookie_object_clone(zval *this_ptr TSRMLS_DC); void php_http_cookie_object_free(void *object TSRMLS_DC); -PHP_METHOD(HttpCookie, __construct); -PHP_METHOD(HttpCookie, getCookies); -PHP_METHOD(HttpCookie, setCookies); -PHP_METHOD(HttpCookie, addCookies); -PHP_METHOD(HttpCookie, getExtras); -PHP_METHOD(HttpCookie, setExtras); -PHP_METHOD(HttpCookie, addExtras); -PHP_METHOD(HttpCookie, getCookie); -PHP_METHOD(HttpCookie, setCookie); -PHP_METHOD(HttpCookie, addCookie); -PHP_METHOD(HttpCookie, getExtra); -PHP_METHOD(HttpCookie, setExtra); -PHP_METHOD(HttpCookie, addExtra); -PHP_METHOD(HttpCookie, getDomain); -PHP_METHOD(HttpCookie, setDomain); -PHP_METHOD(HttpCookie, getPath); -PHP_METHOD(HttpCookie, setPath); -PHP_METHOD(HttpCookie, getExpires); -PHP_METHOD(HttpCookie, setExpires); -PHP_METHOD(HttpCookie, getMaxAge); -PHP_METHOD(HttpCookie, setMaxAge); -PHP_METHOD(HttpCookie, getFlags); -PHP_METHOD(HttpCookie, setFlags); -PHP_METHOD(HttpCookie, toString); -PHP_METHOD(HttpCookie, toArray); - -extern PHP_MINIT_FUNCTION(http_cookie); - +PHP_MINIT_FUNCTION(http_cookie); #endif diff --git a/php_http_curl.c b/php_http_curl.c index 6b2bd33..6607ca1 100644 --- a/php_http_curl.c +++ b/php_http_curl.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_curl.h b/php_http_curl.h index f7116cd..4621d5a 100644 --- a/php_http_curl.h +++ b/php_http_curl.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_encoding.c b/php_http_encoding.c index 9767ee4..54dc19c 100644 --- a/php_http_encoding.c +++ b/php_http_encoding.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -913,38 +913,6 @@ PHP_HTTP_API php_http_encoding_stream_ops_t *php_http_encoding_stream_get_dechun return &php_http_encoding_dechunk_ops; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEncodingStream, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEncodingStream, method, 0) -#define PHP_HTTP_ENCSTREAM_ME(method, visibility) PHP_ME(HttpEncodingStream, method, PHP_HTTP_ARGS(HttpEncodingStream, method), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(update, 1) - PHP_HTTP_ARG_VAL(data, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(flush); -PHP_HTTP_EMPTY_ARGS(done); -PHP_HTTP_EMPTY_ARGS(finish); - -static zend_class_entry *php_http_encoding_stream_class_entry; - -zend_class_entry *php_http_encoding_stream_get_class_entry(void) -{ - return php_http_encoding_stream_class_entry; -} - -static zend_function_entry php_http_encoding_stream_method_entry[] = { - PHP_HTTP_ENCSTREAM_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_ENCSTREAM_ME(update, ZEND_ACC_PUBLIC) - PHP_HTTP_ENCSTREAM_ME(flush, ZEND_ACC_PUBLIC) - PHP_HTTP_ENCSTREAM_ME(done, ZEND_ACC_PUBLIC) - PHP_HTTP_ENCSTREAM_ME(finish, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; static zend_object_handlers php_http_encoding_stream_object_handlers; zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRMLS_DC) @@ -954,7 +922,6 @@ zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRML zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_encoding_stream_object_t **ptr TSRMLS_DC) { - zend_object_value ov; php_http_encoding_stream_object_t *o; o = ecalloc(1, sizeof(*o)); @@ -969,10 +936,10 @@ zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, p o->stream = s; } - ov.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_encoding_stream_object_free, NULL TSRMLS_CC); - ov.handlers = &php_http_encoding_stream_object_handlers; + o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_encoding_stream_object_free, NULL TSRMLS_CC); + o->zv.handlers = &php_http_encoding_stream_object_handlers; - return ov; + return o->zv; } zend_object_value php_http_encoding_stream_object_clone(zval *this_ptr TSRMLS_DC) @@ -997,23 +964,26 @@ void php_http_encoding_stream_object_free(void *object TSRMLS_DC) efree(o); } -PHP_METHOD(HttpEncodingStream, __construct) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream___construct, 0, 0, 0) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEncodingStream, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + 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_get_class_entry() TSRMLS_CC)) { + 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_get_class_entry() TSRMLS_CC)) { + } 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_get_class_entry() TSRMLS_CC)) { + } else if (instanceof_function(obj->zo.ce, php_http_dechunk_stream_class_entry TSRMLS_CC)) { ops = &php_http_encoding_dechunk_ops; } @@ -1031,7 +1001,10 @@ PHP_METHOD(HttpEncodingStream, __construct) } end_error_handling(); } -PHP_METHOD(HttpEncodingStream, update) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_update, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEncodingStream, update) { int data_len; char *data_str; @@ -1051,7 +1024,9 @@ PHP_METHOD(HttpEncodingStream, update) RETURN_FALSE; } -PHP_METHOD(HttpEncodingStream, flush) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_flush, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEncodingStream, flush) { if (SUCCESS == zend_parse_parameters_none()) { php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1072,7 +1047,9 @@ PHP_METHOD(HttpEncodingStream, flush) RETURN_FALSE; } -PHP_METHOD(HttpEncodingStream, done) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_done, 0, 0, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEncodingStream, done) { if (SUCCESS == zend_parse_parameters_none()) { php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1084,7 +1061,9 @@ PHP_METHOD(HttpEncodingStream, done) RETURN_FALSE; } -PHP_METHOD(HttpEncodingStream, finish) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEncodingStream_finish, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEncodingStream, finish) { if (SUCCESS == zend_parse_parameters_none()) { php_http_encoding_stream_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1109,31 +1088,20 @@ PHP_METHOD(HttpEncodingStream, finish) RETURN_FALSE; } -#undef PHP_HTTP_BEGIN_ARGS -#undef PHP_HTTP_EMPTY_ARGS -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpDeflateStream, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpDeflateStream, method, 0) -#define PHP_HTTP_DEFLATE_ME(method, visibility) PHP_ME(HttpDeflateStream, method, PHP_HTTP_ARGS(HttpDeflateStream, method), visibility) - -PHP_HTTP_BEGIN_ARGS(encode, 1) - PHP_HTTP_ARG_VAL(data, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_deflate_stream_class_entry; - -zend_class_entry *php_http_deflate_stream_get_class_entry(void) -{ - return php_http_deflate_stream_class_entry; -} - -static zend_function_entry php_http_deflate_stream_method_entry[] = { - PHP_HTTP_DEFLATE_ME(encode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - +static zend_function_entry php_http_encoding_stream_methods[] = { + PHP_ME(HttpEncodingStream, __construct, ai_HttpEncodingStream___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpEncodingStream, update, ai_HttpEncodingStream_update, ZEND_ACC_PUBLIC) + PHP_ME(HttpEncodingStream, flush, ai_HttpEncodingStream_flush, ZEND_ACC_PUBLIC) + PHP_ME(HttpEncodingStream, done, ai_HttpEncodingStream_done, ZEND_ACC_PUBLIC) + PHP_ME(HttpEncodingStream, finish, ai_HttpEncodingStream_finish, ZEND_ACC_PUBLIC) EMPTY_FUNCTION_ENTRY }; -PHP_METHOD(HttpDeflateStream, encode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpDeflateStream_encode, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpDeflateStream, encode) { char *str; int len; @@ -1150,30 +1118,15 @@ PHP_METHOD(HttpDeflateStream, encode) RETURN_FALSE; } -#undef PHP_HTTP_BEGIN_ARGS -#undef PHP_HTTP_EMPTY_ARGS -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpInflateStream, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpInflateStream, method, 0) -#define PHP_HTTP_INFLATE_ME(method, visibility) PHP_ME(HttpInflateStream, method, PHP_HTTP_ARGS(HttpInflateStream, method), visibility) - -PHP_HTTP_BEGIN_ARGS(decode, 1) - PHP_HTTP_ARG_VAL(data, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_inflate_stream_class_entry; - -zend_class_entry *php_http_inflate_stream_get_class_entry(void) -{ - return php_http_inflate_stream_class_entry; -} - -static zend_function_entry php_http_inflate_stream_method_entry[] = { - PHP_HTTP_INFLATE_ME(decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - +static zend_function_entry php_http_deflate_stream_methods[] = { + PHP_ME(HttpDeflateStream, encode, ai_HttpDeflateStream_encode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) EMPTY_FUNCTION_ENTRY }; -PHP_METHOD(HttpInflateStream, decode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpInflateStream_decode, 0, 0, 1) + ZEND_ARG_INFO(0, data) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpInflateStream, decode) { char *str; int len; @@ -1189,31 +1142,16 @@ PHP_METHOD(HttpInflateStream, decode) RETURN_FALSE; } -#undef PHP_HTTP_BEGIN_ARGS -#undef PHP_HTTP_EMPTY_ARGS -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpDechunkStream, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpDechunkStream, method, 0) -#define PHP_HTTP_DECHUNK_ME(method, visibility) PHP_ME(HttpDechunkStream, method, PHP_HTTP_ARGS(HttpDechunkStream, method), visibility) - -PHP_HTTP_BEGIN_ARGS(decode, 1) - PHP_HTTP_ARG_VAL(data, 0) - PHP_HTTP_ARG_VAL(decoded_len, 1) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_dechunk_stream_class_entry; - -zend_class_entry *php_http_dechunk_stream_get_class_entry(void) -{ - return php_http_dechunk_stream_class_entry; -} - -static zend_function_entry php_http_dechunk_stream_method_entry[] = { - PHP_HTTP_DECHUNK_ME(decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - +static zend_function_entry php_http_inflate_stream_methods[] = { + PHP_ME(HttpInflateStream, decode, ai_HttpInflateStream_decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) EMPTY_FUNCTION_ENTRY }; -PHP_METHOD(HttpDechunkStream, decode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpDechunkStream_decode, 0, 0, 1) + ZEND_ARG_INFO(0, data) + ZEND_ARG_INFO(1, decoded_len) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpDechunkStream, decode) { char *str; int len; @@ -1235,9 +1173,23 @@ PHP_METHOD(HttpDechunkStream, decode) RETURN_FALSE; } +static zend_function_entry php_http_dechunk_stream_methods[] = { + PHP_ME(HttpDechunkStream, decode, ai_HttpDechunkStream_decode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_encoding_stream_class_entry; +zend_class_entry *php_http_deflate_stream_class_entry; +zend_class_entry *php_http_inflate_stream_class_entry; +zend_class_entry *php_http_dechunk_stream_class_entry; + PHP_MINIT_FUNCTION(http_encoding) { - PHP_HTTP_REGISTER_CLASS(http\\Encoding, Stream, http_encoding_stream, php_http_object_get_class_entry(), ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + 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->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)); php_http_encoding_stream_object_handlers.clone_obj = php_http_encoding_stream_object_clone; @@ -1246,7 +1198,9 @@ PHP_MINIT_FUNCTION(http_encoding) zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_SYNC"), PHP_HTTP_ENCODING_STREAM_FLUSH_SYNC TSRMLS_CC); zend_declare_class_constant_long(php_http_encoding_stream_class_entry, ZEND_STRL("FLUSH_FULL"), PHP_HTTP_ENCODING_STREAM_FLUSH_FULL TSRMLS_CC); - PHP_HTTP_REGISTER_CLASS(http\\Encoding\\Stream, Deflate, http_deflate_stream, php_http_encoding_stream_class_entry, 0); + memset(&ce, 0, sizeof(ce)); + INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Deflate", php_http_deflate_stream_methods); + php_http_deflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_GZIP"), PHP_HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC); zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("TYPE_ZLIB"), PHP_HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC); @@ -1260,8 +1214,13 @@ PHP_MINIT_FUNCTION(http_encoding) zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_RLE"), PHP_HTTP_DEFLATE_STRATEGY_RLE TSRMLS_CC); zend_declare_class_constant_long(php_http_deflate_stream_class_entry, ZEND_STRL("STRATEGY_FIXED"), PHP_HTTP_DEFLATE_STRATEGY_FIXED TSRMLS_CC); - PHP_HTTP_REGISTER_CLASS(http\\Encoding\\Stream, Inflate, http_inflate_stream, php_http_encoding_stream_class_entry, 0); - PHP_HTTP_REGISTER_CLASS(http\\Encoding\\Stream, Dechunk, http_dechunk_stream, php_http_encoding_stream_class_entry, 0); + memset(&ce, 0, sizeof(ce)); + INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Inflate", php_http_inflate_stream_methods); + php_http_inflate_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); + + memset(&ce, 0, sizeof(ce)); + INIT_NS_CLASS_ENTRY(ce, "http\\Encoding\\Stream", "Dechunk", php_http_dechunk_stream_methods); + php_http_dechunk_stream_class_entry = zend_register_internal_class_ex(&ce, php_http_encoding_stream_class_entry, NULL TSRMLS_CC); return SUCCESS; } diff --git a/php_http_encoding.h b/php_http_encoding.h index 84dfac0..decc585 100644 --- a/php_http_encoding.h +++ b/php_http_encoding.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -170,50 +170,21 @@ PHP_HTTP_API STATUS php_http_encoding_inflate(const char *data, size_t data_len, typedef struct php_http_encoding_stream_object { zend_object zo; + zend_object_value zv; php_http_encoding_stream_t *stream; } php_http_encoding_stream_object_t; -zend_class_entry *php_http_encoding_stream_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_encoding_stream_class_entry; zend_object_value php_http_encoding_stream_object_new(zend_class_entry *ce TSRMLS_DC); zend_object_value php_http_encoding_stream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_encoding_stream_object_t **ptr TSRMLS_DC); zend_object_value php_http_encoding_stream_object_clone(zval *object TSRMLS_DC); void php_http_encoding_stream_object_free(void *object TSRMLS_DC); -zend_class_entry *php_http_deflate_stream_get_class_entry(void); -zend_class_entry *php_http_inflate_stream_get_class_entry(void); -zend_class_entry *php_http_dechunk_stream_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_deflate_stream_class_entry; +PHP_HTTP_API zend_class_entry *php_http_inflate_stream_class_entry; +PHP_HTTP_API zend_class_entry *php_http_dechunk_stream_class_entry; -PHP_METHOD(HttpEncodingStream, __construct); -PHP_METHOD(HttpEncodingStream, update); -PHP_METHOD(HttpEncodingStream, flush); -PHP_METHOD(HttpEncodingStream, done); -PHP_METHOD(HttpEncodingStream, finish); - -PHP_METHOD(HttpDeflateStream, encode); -PHP_METHOD(HttpInflateStream, decode); -PHP_METHOD(HttpDechunkStream, decode); - -/* -typedef struct php_http_inflatestream_object { - zend_object zo; - php_http_encoding_stream_t *stream; -} php_http_inflatestream_object_t; - -extern zend_class_entry *php_http_inflatestream_class_entry; -extern zend_function_entry php_http_inflatestream_method_entry[]; - -extern zend_object_value php_http_inflatestream_object_new(zend_class_entry *ce TSRMLS_DC); -extern zend_object_value php_http_inflatestream_object_new_ex(zend_class_entry *ce, php_http_encoding_stream_t *s, php_http_inflatestream_object_t **ptr TSRMLS_DC); -extern zend_object_value php_http_inflatestream_object_clone(zval *object TSRMLS_DC); -extern void php_http_inflatestream_object_free(void *object TSRMLS_DC); - -PHP_METHOD(HttpInflateStream, __construct); -PHP_METHOD(HttpInflateStream, factory); -PHP_METHOD(HttpInflateStream, update); -PHP_METHOD(HttpInflateStream, flush); -PHP_METHOD(HttpInflateStream, finish); -*/ #endif /* diff --git a/php_http_env.c b/php_http_env.c index ee7d27f..a470bd5 100644 --- a/php_http_env.c +++ b/php_http_env.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -581,7 +581,6 @@ PHP_HTTP_API STATUS php_http_env_set_response_header_value(long http_code, const } } - static PHP_HTTP_STRLIST(php_http_env_response_status) = PHP_HTTP_STRLIST_ITEM("Continue") PHP_HTTP_STRLIST_ITEM("Switching Protocols") @@ -678,98 +677,10 @@ PHP_HTTP_API const char *php_http_env_get_response_status_for_code(unsigned code return php_http_strlist_find(php_http_env_response_status, 100, code); } - -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnv, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnv, method, 0) -#define PHP_HTTP_ENV_ME(method) PHP_ME(HttpEnv, method, PHP_HTTP_ARGS(HttpEnv, method), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - -PHP_HTTP_BEGIN_ARGS(getRequestHeader, 0) - PHP_HTTP_ARG_VAL(header_name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(getRequestBody, 0) - PHP_HTTP_ARG_VAL(body_class_name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(getResponseStatusForCode, 1) - PHP_HTTP_ARG_VAL(code, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getResponseStatusForAllCodes); - -PHP_HTTP_BEGIN_ARGS(getResponseHeader, 0) - PHP_HTTP_ARG_VAL(header_name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getResponseCode); - -PHP_HTTP_BEGIN_ARGS(setResponseHeader, 1) - PHP_HTTP_ARG_VAL(header_name, 0) - PHP_HTTP_ARG_VAL(header_value, 0) - PHP_HTTP_ARG_VAL(response_code, 0) - PHP_HTTP_ARG_VAL(replace_header, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setResponseCode, 1) - PHP_HTTP_ARG_VAL(code, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiateLanguage, 1) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(result_array, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiateContentType, 1) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(result_array, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiateCharset, 1) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(result_array, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiateEncoding, 1) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(result_array, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiate, 2) - PHP_HTTP_ARG_VAL(value, 0) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(primary_type_separator, 0) - PHP_HTTP_ARG_VAL(result_array, 1) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_env_class_entry; - -zend_class_entry *php_http_env_get_class_entry(void) -{ - return php_http_env_class_entry; -} - -static zend_function_entry php_http_env_method_entry[] = { - PHP_HTTP_ENV_ME(getRequestHeader) - PHP_HTTP_ENV_ME(getRequestBody) - - PHP_HTTP_ENV_ME(getResponseStatusForCode) - PHP_HTTP_ENV_ME(getResponseStatusForAllCodes) - - PHP_HTTP_ENV_ME(getResponseHeader) - PHP_HTTP_ENV_ME(getResponseCode) - PHP_HTTP_ENV_ME(setResponseHeader) - PHP_HTTP_ENV_ME(setResponseCode) - - PHP_HTTP_ENV_ME(negotiateLanguage) - PHP_HTTP_ENV_ME(negotiateContentType) - PHP_HTTP_ENV_ME(negotiateEncoding) - PHP_HTTP_ENV_ME(negotiateCharset) - PHP_HTTP_ENV_ME(negotiate) - - EMPTY_FUNCTION_ENTRY -}; - -PHP_METHOD(HttpEnv, getRequestHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestHeader, 0, 0, 0) + ZEND_ARG_INFO(0, header_name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getRequestHeader) { char *header_name_str = NULL; int header_name_len = 0; @@ -792,23 +703,29 @@ PHP_METHOD(HttpEnv, getRequestHeader) RETURN_FALSE; } -PHP_METHOD(HttpEnv, getRequestBody) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getRequestBody, 0, 0, 0) + ZEND_ARG_INFO(0, body_class_name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getRequestBody) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { - zend_class_entry *class_entry = php_http_message_body_get_class_entry(); + with_error_handling(EH_THROW, php_http_exception_class_entry) { + 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); - if (SUCCESS == php_http_new(&ov, class_entry, (php_http_new_t) php_http_message_body_object_new_ex, php_http_message_body_get_class_entry(), php_http_message_body_init(&body, NULL TSRMLS_CC), NULL TSRMLS_CC)) { + 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(); } -PHP_METHOD(HttpEnv, getResponseStatusForCode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForCode, 0, 0, 1) + ZEND_ARG_INFO(0, code) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getResponseStatusForCode) { long code; @@ -818,7 +735,9 @@ PHP_METHOD(HttpEnv, getResponseStatusForCode) RETURN_FALSE; } -PHP_METHOD(HttpEnv, getResponseStatusForAllCodes) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseStatusForAllCodes, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getResponseStatusForAllCodes) { const char *s; unsigned c; @@ -837,7 +756,10 @@ PHP_METHOD(HttpEnv, getResponseStatusForAllCodes) } } -PHP_METHOD(HttpEnv, getResponseHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseHeader, 0, 0, 0) + ZEND_ARG_INFO(0, header_name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getResponseHeader) { char *header_name_str = NULL; int header_name_len = 0; @@ -859,7 +781,9 @@ PHP_METHOD(HttpEnv, getResponseHeader) RETURN_FALSE; } -PHP_METHOD(HttpEnv, getResponseCode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_getResponseCode, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, getResponseCode) { if (SUCCESS == zend_parse_parameters_none()) { RETURN_LONG(php_http_env_get_response_code(TSRMLS_C)); @@ -867,7 +791,13 @@ PHP_METHOD(HttpEnv, getResponseCode) RETURN_FALSE; } -PHP_METHOD(HttpEnv, setResponseHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseHeader, 0, 0, 1) + ZEND_ARG_INFO(0, header_name) + ZEND_ARG_INFO(0, header_value) + ZEND_ARG_INFO(0, response_code) + ZEND_ARG_INFO(0, replace_header) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, setResponseHeader) { char *header_name_str; int header_name_len; @@ -876,22 +806,29 @@ PHP_METHOD(HttpEnv, setResponseHeader) zend_bool replace_header = 1; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) { - RETURN_SUCCESS(php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC)); + RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC)); } RETURN_FALSE; } -PHP_METHOD(HttpEnv, setResponseCode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1) + ZEND_ARG_INFO(0, code) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, setResponseCode) { long code; if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) { - RETURN_SUCCESS(php_http_env_set_response_code(code TSRMLS_CC)); + RETURN_BOOL(SUCCESS == php_http_env_set_response_code(code TSRMLS_CC)); } RETURN_FALSE; } -PHP_METHOD(HttpEnv, negotiateLanguage) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateLanguage, 0, 0, 1) + ZEND_ARG_INFO(0, supported) + ZEND_ARG_INFO(1, result_array) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, negotiateLanguage) { HashTable *supported; zval *rs_array = NULL; @@ -908,7 +845,11 @@ PHP_METHOD(HttpEnv, negotiateLanguage) } } -PHP_METHOD(HttpEnv, negotiateCharset) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateCharset, 0, 0, 1) + ZEND_ARG_INFO(0, supported) + ZEND_ARG_INFO(1, result_array) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, negotiateCharset) { HashTable *supported; zval *rs_array = NULL; @@ -924,7 +865,11 @@ PHP_METHOD(HttpEnv, negotiateCharset) } } -PHP_METHOD(HttpEnv, negotiateEncoding) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateEncoding, 0, 0, 1) + ZEND_ARG_INFO(0, supported) + ZEND_ARG_INFO(1, result_array) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, negotiateEncoding) { HashTable *supported; zval *rs_array = NULL; @@ -940,7 +885,11 @@ PHP_METHOD(HttpEnv, negotiateEncoding) } } -PHP_METHOD(HttpEnv, negotiateContentType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiateContentType, 0, 0, 1) + ZEND_ARG_INFO(0, supported) + ZEND_ARG_INFO(1, result_array) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, negotiateContentType) { HashTable *supported; zval *rs_array = NULL; @@ -956,7 +905,13 @@ PHP_METHOD(HttpEnv, negotiateContentType) } } -PHP_METHOD(HttpEnv, negotiate) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_negotiate, 0, 0, 2) + ZEND_ARG_INFO(0, value) + ZEND_ARG_INFO(0, supported) + ZEND_ARG_INFO(0, primary_type_separator) + ZEND_ARG_INFO(1, result_array) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnv, negotiate) { HashTable *supported; zval *rs_array = NULL; @@ -981,6 +936,27 @@ PHP_METHOD(HttpEnv, negotiate) } } +static zend_function_entry php_http_env_methods[] = { + PHP_ME(HttpEnv, getRequestHeader, ai_HttpEnv_getRequestHeader, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, getRequestBody, ai_HttpEnv_getRequestBody, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + + PHP_ME(HttpEnv, getResponseStatusForCode, ai_HttpEnv_getResponseStatusForCode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, getResponseStatusForAllCodes, ai_HttpEnv_getResponseStatusForAllCodes, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + + PHP_ME(HttpEnv, getResponseHeader, ai_HttpEnv_getResponseHeader, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, getResponseCode, ai_HttpEnv_getResponseCode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, setResponseHeader, ai_HttpEnv_setResponseHeader, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, setResponseCode, ai_HttpEnv_setResponseCode, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + + PHP_ME(HttpEnv, negotiateLanguage, ai_HttpEnv_negotiateLanguage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, negotiateContentType, ai_HttpEnv_negotiateContentType, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, negotiateEncoding, ai_HttpEnv_negotiateEncoding, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, negotiateCharset, ai_HttpEnv_negotiateCharset, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + PHP_ME(HttpEnv, negotiate, ai_HttpEnv_negotiate, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + + EMPTY_FUNCTION_ENTRY +}; + #ifdef PHP_HTTP_HAVE_JSON #include "ext/json/php_json.h" @@ -997,11 +973,8 @@ static SAPI_POST_HANDLER_FUNC(php_http_json_post_handler) } } -#endif - -PHP_MINIT_FUNCTION(http_env) +static void php_http_env_register_json_handler(TSRMLS_D) { -#ifdef PHP_HTTP_HAVE_JSON sapi_post_entry entry = {NULL, 0, NULL, NULL}; entry.post_reader = sapi_read_standard_form_data; @@ -1014,9 +987,21 @@ PHP_MINIT_FUNCTION(http_env) entry.content_type = "application/json"; entry.content_type_len = lenof("application/json"); sapi_register_post_entry(&entry TSRMLS_CC); +} #endif - PHP_HTTP_REGISTER_CLASS(http, Env, http_env, NULL, 0); +zend_class_entry *php_http_env_class_entry; + +PHP_MINIT_FUNCTION(http_env) +{ + 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); + +#ifdef PHP_HTTP_HAVE_JSON + php_http_env_register_json_handler(TSRMLS_C); +#endif return SUCCESS; } diff --git a/php_http_env.h b/php_http_env.h index c78ced6..dac10da 100644 --- a/php_http_env.h +++ b/php_http_env.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -72,22 +72,7 @@ PHP_HTTP_API zval *php_http_env_get_server_var(const char *key_str, size_t key_l #define php_http_env_got_server_var(v) (NULL != php_http_env_get_server_var((v), strlen(v), 1 TSRMLS_CC)) PHP_HTTP_API zval *php_http_env_get_superglobal(const char *key, size_t key_len TSRMLS_DC); -zend_class_entry *php_http_env_get_class_entry(void); - -PHP_METHOD(HttpEnv, getRequestHeader); -PHP_METHOD(HttpEnv, getRequestBody); -PHP_METHOD(HttpEnv, getResponseStatusForCode); -PHP_METHOD(HttpEnv, getResponseStatusForAllCodes); -PHP_METHOD(HttpEnv, getResponseHeader); -PHP_METHOD(HttpEnv, getResponseCode); -PHP_METHOD(HttpEnv, setResponseHeader); -PHP_METHOD(HttpEnv, setResponseCode); -PHP_METHOD(HttpEnv, negotiateLanguage); -PHP_METHOD(HttpEnv, negotiateCharset); -PHP_METHOD(HttpEnv, negotiateEncoding); -PHP_METHOD(HttpEnv, negotiateContentType); -PHP_METHOD(HttpEnv, negotiate); - +PHP_HTTP_API zend_class_entry *php_http_env_class_entry; PHP_MINIT_FUNCTION(http_env); PHP_RINIT_FUNCTION(http_env); PHP_RSHUTDOWN_FUNCTION(http_env); diff --git a/php_http_env_request.c b/php_http_env_request.c index d9d33ef..a19ad63 100644 --- a/php_http_env_request.c +++ b/php_http_env_request.c @@ -6,53 +6,12 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #include "php_http_api.h" - -#undef PHP_HTTP_BEGIN_ARGS -#undef PHP_HTTP_EMPTY_ARGS -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnvRequest, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnvRequest, method, 0) -#define PHP_HTTP_ENV_REQUEST_ME(method, visibility) PHP_ME(HttpEnvRequest, method, PHP_HTTP_ARGS(HttpEnvRequest, method), visibility) - -PHP_HTTP_EMPTY_ARGS(__construct); - -PHP_HTTP_BEGIN_ARGS(getQuery, 0) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(type, 0) - PHP_HTTP_ARG_VAL(defval, 0) - PHP_HTTP_ARG_VAL(delete, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(getForm, 0) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(type, 0) - PHP_HTTP_ARG_VAL(defval, 0) - PHP_HTTP_ARG_VAL(delete, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getFiles); - -static zend_class_entry *php_http_env_request_class_entry; - -zend_class_entry *php_http_env_request_get_class_entry(void) -{ - return php_http_env_request_class_entry; -} - -zend_function_entry php_http_env_request_method_entry[] = { - PHP_HTTP_ENV_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_ENV_REQUEST_ME(getForm, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_REQUEST_ME(getQuery, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_REQUEST_ME(getFiles, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; - static int grab_file(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key *key) { zval *zfiles, **name, **zname, **error, **zerror, **type, **ztype, **size, **zsize, **tmp_name = zpp; @@ -151,20 +110,23 @@ static int grab_files(void *zpp TSRMLS_DC, int argc, va_list argv, zend_hash_key } \ } while(0) -PHP_METHOD(HttpEnvRequest, __construct) + +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest___construct, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvRequest, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); if (SUCCESS == zend_parse_parameters_none()) { zval *zsg, *zqs; obj->message = php_http_message_init_env(obj->message, PHP_HTTP_REQUEST TSRMLS_CC); - obj->body.handle = 0; + 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_get_class_entry()); + 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); } @@ -172,7 +134,7 @@ PHP_METHOD(HttpEnvRequest, __construct) zsg = php_http_env_get_superglobal(ZEND_STRL("_POST") TSRMLS_CC); MAKE_STD_ZVAL(zqs); - object_init_ex(zqs, php_http_querystring_get_class_entry()); + 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); } @@ -213,35 +175,65 @@ PHP_METHOD(HttpEnvRequest, __construct) RETVAL_ZVAL(rv, 0, 1); \ } while(0); -PHP_METHOD(HttpEnvRequest, getForm) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getForm, 0, 0, 0) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, defval) + ZEND_ARG_INFO(0, delete) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvRequest, getForm) { if (ZEND_NUM_ARGS()) { call_querystring_get("form"); } else { - RETURN_PROP(php_http_env_request_class_entry, "form"); + zval *zform = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("form"), 0 TSRMLS_CC); + RETURN_ZVAL(zform, 1, 0); } } -PHP_METHOD(HttpEnvRequest, getQuery) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getQuery, 0, 0, 0) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, defval) + ZEND_ARG_INFO(0, delete) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvRequest, getQuery) { if (ZEND_NUM_ARGS()) { call_querystring_get("query"); } else { - RETURN_PROP(php_http_env_request_class_entry, "query"); + zval *zquery = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("query"), 0 TSRMLS_CC); + RETURN_ZVAL(zquery, 1, 0); } } -PHP_METHOD(HttpEnvRequest, getFiles) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvRequest_getFiles, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvRequest, getFiles) { if (SUCCESS == zend_parse_parameters_none()) { - RETURN_PROP(php_http_env_request_class_entry, "files"); + zval *zfiles = zend_read_property(php_http_env_request_class_entry, getThis(), ZEND_STRL("files"), 0 TSRMLS_CC); + RETURN_ZVAL(zfiles, 1, 0); } } +static zend_function_entry php_http_env_request_methods[] = { + PHP_ME(HttpEnvRequest, __construct, ai_HttpEnvRequest___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpEnvRequest, getForm, ai_HttpEnvRequest_getForm, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvRequest, getQuery, ai_HttpEnvRequest_getQuery, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvRequest, getFiles, ai_HttpEnvRequest_getFiles, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_env_request_class_entry; PHP_MINIT_FUNCTION(http_env_request) { - PHP_HTTP_REGISTER_CLASS(http\\Env, Request, http_env_request, php_http_message_get_class_entry(), 0); + zend_class_entry ce = {0}; + + INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Request", php_http_env_request_methods); + php_http_env_request_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC); + zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("query"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("form"), ZEND_ACC_PROTECTED TSRMLS_CC); zend_declare_property_null(php_http_env_request_class_entry, ZEND_STRL("files"), ZEND_ACC_PROTECTED TSRMLS_CC); @@ -249,7 +241,6 @@ PHP_MINIT_FUNCTION(http_env_request) return SUCCESS; } - /* * Local variables: * tab-width: 4 diff --git a/php_http_env_request.h b/php_http_env_request.h index 7b529a1..f6b8f40 100644 --- a/php_http_env_request.h +++ b/php_http_env_request.h @@ -6,20 +6,14 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #ifndef PHP_HTTP_ENV_REQUEST_H #define PHP_HTTP_ENV_REQUEST_H -zend_class_entry *php_http_env_request_get_class_entry(void); - -PHP_METHOD(HttpEnvRequest, __construct); -PHP_METHOD(HttpEnvRequest, getForm); -PHP_METHOD(HttpEnvRequest, getQuery); -PHP_METHOD(HttpEnvRequest, getFiles); - +PHP_HTTP_API zend_class_entry *php_http_env_request_class_entry; PHP_MINIT_FUNCTION(http_env_request); #endif diff --git a/php_http_env_response.c b/php_http_env_response.c index 66f4782..aac52be 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -82,7 +82,7 @@ static php_http_message_body_t *get_body(zval *options TSRMLS_DC) php_http_message_body_t *body = NULL; if ((zbody = get_option(options, ZEND_STRL("body") TSRMLS_CC))) { - if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_get_class_entry() TSRMLS_CC)) { + if ((Z_TYPE_P(zbody) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) { php_http_message_body_object_t *body_obj = zend_object_store_get_object(zbody TSRMLS_CC); body = body_obj->body; @@ -98,7 +98,7 @@ static php_http_message_t *get_request(zval *options TSRMLS_DC) php_http_message_t *request = NULL; if ((zrequest = get_option(options, ZEND_STRL("request") TSRMLS_CC))) { - if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_get_class_entry() TSRMLS_CC)) { + if (Z_TYPE_P(zrequest) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zrequest), php_http_message_class_entry TSRMLS_CC)) { php_http_message_object_t *request_obj = zend_object_store_get_object(zrequest TSRMLS_CC); request = request_obj->message; @@ -1047,88 +1047,6 @@ PHP_HTTP_API php_http_env_response_ops_t *php_http_env_response_get_stream_ops(v return &php_http_env_response_stream_ops; } -#undef PHP_HTTP_BEGIN_ARGS -#undef PHP_HTTP_EMPTY_ARGS -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpEnvResponse, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpEnvResponse, method, 0) -#define PHP_HTTP_ENV_RESPONSE_ME(method, visibility) PHP_ME(HttpEnvResponse, method, PHP_HTTP_ARGS(HttpEnvResponse, method), visibility) - -PHP_HTTP_EMPTY_ARGS(__construct); - -PHP_HTTP_BEGIN_ARGS(__invoke, 1) - PHP_HTTP_ARG_VAL(ob_string, 0) - PHP_HTTP_ARG_VAL(ob_flags, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setEnvRequest, 1) - PHP_HTTP_ARG_OBJ(http\\Message, env_request, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setContentType, 1) - PHP_HTTP_ARG_VAL(content_type, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setContentEncoding, 1) - PHP_HTTP_ARG_VAL(content_encoding, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setContentDisposition, 1) - PHP_HTTP_ARG_ARR(disposition_params, 1, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setCacheControl, 1) - PHP_HTTP_ARG_VAL(cache_control, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setLastModified, 1) - PHP_HTTP_ARG_VAL(last_modified, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(isCachedByLastModified, 0) - PHP_HTTP_ARG_VAL(header_name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setEtag, 1) - PHP_HTTP_ARG_VAL(etag, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(isCachedByEtag, 0) - PHP_HTTP_ARG_VAL(header_name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setThrottleRate, 1) - PHP_HTTP_ARG_VAL(chunk_size, 0) - PHP_HTTP_ARG_VAL(delay, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(send); - -static zend_class_entry *php_http_env_response_class_entry; - -zend_class_entry *php_http_env_response_get_class_entry(void) -{ - return php_http_env_response_class_entry; -} - -static zend_function_entry php_http_env_response_method_entry[] = { - PHP_HTTP_ENV_RESPONSE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_ENV_RESPONSE_ME(__invoke, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setEnvRequest, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setContentEncoding, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setLastModified, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(isCachedByLastModified, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setEtag, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(isCachedByEtag, ZEND_ACC_PUBLIC) - PHP_HTTP_ENV_RESPONSE_ME(setThrottleRate, ZEND_ACC_PUBLIC) - - PHP_HTTP_ENV_RESPONSE_ME(send, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; - #define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \ do { \ if (!obj->message) { \ @@ -1136,13 +1054,15 @@ static zend_function_entry php_http_env_response_method_entry[] = { } \ } while (0) -PHP_METHOD(HttpEnvResponse, __construct) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___construct, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); if (SUCCESS == zend_parse_parameters_none()) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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(); } @@ -1151,7 +1071,11 @@ PHP_METHOD(HttpEnvResponse, __construct) } -PHP_METHOD(HttpEnvResponse, __invoke) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1) + ZEND_ARG_INFO(0, ob_string) + ZEND_ARG_INFO(0, ob_flags) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, __invoke) { char *ob_str; int ob_len; @@ -1162,7 +1086,7 @@ PHP_METHOD(HttpEnvResponse, __invoke) PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj); - if (obj->body.handle || SUCCESS == php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), NULL TSRMLS_CC)) { + if (obj->body || SUCCESS == php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC)) { php_http_message_body_append(obj->message->body, ob_str, ob_len); RETURN_TRUE; } @@ -1170,16 +1094,22 @@ PHP_METHOD(HttpEnvResponse, __invoke) } } -PHP_METHOD(HttpEnvResponse, setEnvRequest) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEnvRequest, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, env_request, http\\Message, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setEnvRequest) { zval *env_req = NULL; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_get_class_entry())) { + 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); } } -PHP_METHOD(HttpEnvResponse, setContentType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1) + ZEND_ARG_INFO(0, content_type) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setContentType) { char *ct_str = NULL; int ct_len = 0; @@ -1189,7 +1119,10 @@ PHP_METHOD(HttpEnvResponse, setContentType) } } -PHP_METHOD(HttpEnvResponse, setContentDisposition) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1) + ZEND_ARG_ARRAY_INFO(0, disposition_params, 1) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setContentDisposition) { zval *zdisposition; @@ -1198,7 +1131,10 @@ PHP_METHOD(HttpEnvResponse, setContentDisposition) } } -PHP_METHOD(HttpEnvResponse, setContentEncoding) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1) + ZEND_ARG_INFO(0, content_encoding) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setContentEncoding) { long ce; @@ -1207,7 +1143,10 @@ PHP_METHOD(HttpEnvResponse, setContentEncoding) } } -PHP_METHOD(HttpEnvResponse, setCacheControl) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1) + ZEND_ARG_INFO(0, cache_control) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setCacheControl) { char *cc_str = NULL; int cc_len = 0; @@ -1217,7 +1156,10 @@ PHP_METHOD(HttpEnvResponse, setCacheControl) } } -PHP_METHOD(HttpEnvResponse, setLastModified) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1) + ZEND_ARG_INFO(0, last_modified) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setLastModified) { long last_modified; @@ -1226,7 +1168,10 @@ PHP_METHOD(HttpEnvResponse, setLastModified) } } -PHP_METHOD(HttpEnvResponse, isCachedByLastModified) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified, 0, 0, 0) + ZEND_ARG_INFO(0, header_name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, isCachedByLastModified) { char *header_name_str = NULL; int header_name_len = 0; @@ -1242,7 +1187,10 @@ PHP_METHOD(HttpEnvResponse, isCachedByLastModified) RETURN_FALSE; } -PHP_METHOD(HttpEnvResponse, setEtag) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEtag, 0, 0, 1) + ZEND_ARG_INFO(0, etag) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setEtag) { char *etag_str = NULL; int etag_len = 0; @@ -1252,7 +1200,10 @@ PHP_METHOD(HttpEnvResponse, setEtag) } } -PHP_METHOD(HttpEnvResponse, isCachedByEtag) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag, 0, 0, 0) + ZEND_ARG_INFO(0, header_name) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, isCachedByEtag) { char *header_name_str = NULL; int header_name_len = 0; @@ -1267,7 +1218,11 @@ PHP_METHOD(HttpEnvResponse, isCachedByEtag) RETURN_FALSE; } -PHP_METHOD(HttpEnvResponse, setThrottleRate) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setThrottleRate, 0, 0, 1) + ZEND_ARG_INFO(0, chunk_size) + ZEND_ARG_INFO(0, delay) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, setThrottleRate) { long chunk_size; double delay = 1; @@ -1280,7 +1235,9 @@ PHP_METHOD(HttpEnvResponse, setThrottleRate) RETURN_FALSE; } -PHP_METHOD(HttpEnvResponse, send) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpEnvResponse, send) { zval *zstream = NULL; php_stream *s = NULL; @@ -1295,7 +1252,7 @@ PHP_METHOD(HttpEnvResponse, send) php_http_env_response_t *r; if ((r = php_http_env_response_init(NULL, getThis(), php_http_env_response_get_stream_ops(), s TSRMLS_CC))) { - RETVAL_SUCCESS(php_http_env_response_send(r)); + RETVAL_BOOL(SUCCESS == php_http_env_response_send(r)); php_http_env_response_free(&r); } } @@ -1303,16 +1260,38 @@ PHP_METHOD(HttpEnvResponse, send) php_http_env_response_t r; if (php_http_env_response_init(&r, getThis(), NULL, NULL TSRMLS_CC)) { - RETVAL_SUCCESS(php_http_env_response_send(&r)); + RETVAL_BOOL(SUCCESS == php_http_env_response_send(&r)); php_http_env_response_dtor(&r); } } } } +static zend_function_entry php_http_env_response_methods[] = { + PHP_ME(HttpEnvResponse, __construct, ai_HttpEnvResponse___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpEnvResponse, __invoke, ai_HttpEnvResponse___invoke, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setEnvRequest, ai_HttpEnvResponse_setEnvRequest, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setContentType, ai_HttpEnvResponse_setContentType, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setContentDisposition, ai_HttpEnvResponse_setContentDisposition, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setContentEncoding, ai_HttpEnvResponse_setContentEncoding, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setCacheControl, ai_HttpEnvResponse_setCacheControl, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setLastModified, ai_HttpEnvResponse_setLastModified, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, isCachedByLastModified, ai_HttpEnvResponse_isCachedByLastModified, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setEtag, ai_HttpEnvResponse_setEtag, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, isCachedByEtag, ai_HttpEnvResponse_isCachedByEtag, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, setThrottleRate, ai_HttpEnvResponse_setThrottleRate, ZEND_ACC_PUBLIC) + PHP_ME(HttpEnvResponse, send, ai_HttpEnvResponse_send, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_env_response_class_entry; + PHP_MINIT_FUNCTION(http_env_response) { - PHP_HTTP_REGISTER_CLASS(http\\Env, Response, http_env_response, php_http_message_get_class_entry(), 0); + zend_class_entry ce = {0}; + + INIT_NS_CLASS_ENTRY(ce, "http\\Env", "Response", php_http_env_response_methods); + php_http_env_response_class_entry = zend_register_internal_class_ex(&ce, php_http_message_class_entry, NULL TSRMLS_CC); zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE TSRMLS_CC); zend_declare_class_constant_long(php_http_env_response_class_entry, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP TSRMLS_CC); diff --git a/php_http_env_response.h b/php_http_env_response.h index 4139656..f79730f 100644 --- a/php_http_env_response.h +++ b/php_http_env_response.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -73,23 +73,7 @@ PHP_HTTP_API void php_http_env_response_free(php_http_env_response_t **r); 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_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); -zend_class_entry *php_http_env_response_get_class_entry(void); - -PHP_METHOD(HttpEnvResponse, __construct); -PHP_METHOD(HttpEnvResponse, __invoke); -PHP_METHOD(HttpEnvResponse, setEnvRequest); -PHP_METHOD(HttpEnvResponse, setContentType); -PHP_METHOD(HttpEnvResponse, setContentDisposition); -PHP_METHOD(HttpEnvResponse, setContentEncoding); -PHP_METHOD(HttpEnvResponse, setCacheControl); -PHP_METHOD(HttpEnvResponse, setLastModified); -PHP_METHOD(HttpEnvResponse, isCachedByLastModified); -PHP_METHOD(HttpEnvResponse, setEtag); -PHP_METHOD(HttpEnvResponse, isCachedByEtag); -PHP_METHOD(HttpEnvResponse, setThrottleRate); -PHP_METHOD(HttpEnvResponse, send); - - +PHP_HTTP_API zend_class_entry *php_http_env_response_class_entry; PHP_MINIT_FUNCTION(http_env_response); #endif diff --git a/php_http_etag.c b/php_http_etag.c index 3a69756..b9c0333 100644 --- a/php_http_etag.c +++ b/php_http_etag.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_etag.h b/php_http_etag.h index 899ec1c..dd0e3d1 100644 --- a/php_http_etag.h +++ b/php_http_etag.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_exception.c b/php_http_exception.c index 2c6dc1f..2ce163a 100644 --- a/php_http_exception.c +++ b/php_http_exception.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -18,13 +18,6 @@ # define PHP_HTTP_DBG_EXCEPTIONS 0 #endif -static zend_class_entry *php_http_exception_class_entry; - -zend_class_entry *php_http_exception_get_class_entry(void) -{ - return php_http_exception_class_entry; -} - #if PHP_HTTP_DBG_EXCEPTIONS static void php_http_exception_hook(zval *ex TSRMLS_DC) { @@ -37,27 +30,32 @@ static void php_http_exception_hook(zval *ex TSRMLS_DC) } #endif +zend_class_entry *php_http_exception_class_entry; + PHP_MINIT_FUNCTION(http_exception) { - PHP_HTTP_REGISTER_EXCEPTION(Exception, php_http_exception_class_entry, zend_exception_get_default(TSRMLS_C)); + zend_class_entry 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_get_class_entry(), ZEND_STRL("E_UNKNOWN"), PHP_HTTP_E_UNKNOWN TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_RUNTIME"), PHP_HTTP_E_RUNTIME TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_INVALID_PARAM"), PHP_HTTP_E_INVALID_PARAM TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_HEADER"), PHP_HTTP_E_HEADER TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_MALFORMED_HEADERS"), PHP_HTTP_E_MALFORMED_HEADERS TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_MESSAGE"), PHP_HTTP_E_MESSAGE TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_MESSAGE_TYPE"), PHP_HTTP_E_MESSAGE_TYPE TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_MESSAGE_BODY"), PHP_HTTP_E_MESSAGE_BODY TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_ENCODING"), PHP_HTTP_E_ENCODING TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_CLIENT"), PHP_HTTP_E_CLIENT TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_CLIENT_POOL"), PHP_HTTP_E_CLIENT_POOL TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_CLIENT_DATASHARE"), PHP_HTTP_E_CLIENT_DATASHARE TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_SOCKET"), PHP_HTTP_E_SOCKET TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_RESPONSE"), PHP_HTTP_E_RESPONSE TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_URL"), PHP_HTTP_E_URL TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_QUERYSTRING"), PHP_HTTP_E_QUERYSTRING TSRMLS_CC); - zend_declare_class_constant_long(php_http_exception_get_class_entry(), ZEND_STRL("E_COOKIE"), PHP_HTTP_E_COOKIE 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); #if PHP_HTTP_DBG_EXCEPTIONS zend_throw_exception_hook = php_http_exception_hook; diff --git a/php_http_exception.h b/php_http_exception.h index f48f9b4..d7e5ee7 100644 --- a/php_http_exception.h +++ b/php_http_exception.h @@ -6,15 +6,14 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #ifndef PHP_HTTP_EXCEPTION_H #define PHP_HTTP_EXCEPTION_H -zend_class_entry *php_http_exception_get_class_entry(void); - +PHP_HTTP_API zend_class_entry *php_http_exception_class_entry; PHP_MINIT_FUNCTION(http_exception); #endif diff --git a/php_http_filter.c b/php_http_filter.c index c3aaf2d..b91b5f4 100644 --- a/php_http_filter.c +++ b/php_http_filter.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_filter.h b/php_http_filter.h index 4b4806d..b2b8682 100644 --- a/php_http_filter.h +++ b/php_http_filter.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_header_parser.c b/php_http_header_parser.c index 866a84e..8636ed3 100644 --- a/php_http_header_parser.c +++ b/php_http_header_parser.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -26,7 +26,6 @@ static const php_http_header_parser_state_spec_t php_http_header_parser_states[] {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) { if (!parser) { @@ -39,7 +38,6 @@ PHP_HTTP_API php_http_header_parser_t *php_http_header_parser_init(php_http_head 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, ...) { va_list va_args; diff --git a/php_http_header_parser.h b/php_http_header_parser.h index 0c26db3..1c07da2 100644 --- a/php_http_header_parser.h +++ b/php_http_header_parser.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_headers.c b/php_http_headers.c index 519eb7a..68e2f6a 100644 --- a/php_http_headers.c +++ b/php_http_headers.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -114,68 +114,16 @@ PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC) return ret; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpHeader, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpHeader, method, 0) -#define PHP_HTTP_HEADER_ME(method, v) PHP_ME(HttpHeader, method, PHP_HTTP_ARGS(HttpHeader, method), v) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(serialize); -PHP_HTTP_BEGIN_ARGS(unserialize, 1) - PHP_HTTP_ARG_VAL(serialized, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(match, 1) - PHP_HTTP_ARG_VAL(value, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(negotiate, 1) - PHP_HTTP_ARG_VAL(supported, 0) - PHP_HTTP_ARG_VAL(result, 1) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(parse, 1) - PHP_HTTP_ARG_VAL(string, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(getParams, 0) - PHP_HTTP_ARG_VAL(param_sep, 0) - PHP_HTTP_ARG_VAL(arg_sep, 0) - PHP_HTTP_ARG_VAL(val_sep, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_header_class_entry; - -zend_class_entry *php_http_header_get_class_entry(void) -{ - return php_http_header_class_entry; -} - -static zend_function_entry php_http_header_method_entry[] = { - PHP_HTTP_HEADER_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_HEADER_ME(serialize, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpHeader, __toString, serialize, PHP_HTTP_ARGS(HttpHeader, serialize), ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpHeader, toString, serialize, PHP_HTTP_ARGS(HttpHeader, serialize), ZEND_ACC_PUBLIC) - PHP_HTTP_HEADER_ME(unserialize, ZEND_ACC_PUBLIC) - PHP_HTTP_HEADER_ME(match, ZEND_ACC_PUBLIC) - PHP_HTTP_HEADER_ME(negotiate, ZEND_ACC_PUBLIC) - PHP_HTTP_HEADER_ME(getParams, ZEND_ACC_PUBLIC) - PHP_HTTP_HEADER_ME(parse, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - EMPTY_FUNCTION_ENTRY -}; - +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_get_class_entry()) { + 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); @@ -189,6 +137,8 @@ PHP_METHOD(HttpHeader, __construct) } 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; @@ -210,6 +160,9 @@ PHP_METHOD(HttpHeader, serialize) 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; @@ -248,6 +201,10 @@ PHP_METHOD(HttpHeader, unserialize) } +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; @@ -264,6 +221,10 @@ PHP_METHOD(HttpHeader, match) 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; @@ -299,6 +260,12 @@ PHP_METHOD(HttpHeader, negotiate) } } +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; @@ -307,7 +274,7 @@ PHP_METHOD(HttpHeader, getParams) ZVAL_STRINGL(&zctor, "__construct", lenof("__construct"), 0); MAKE_STD_ZVAL(zparams_obj); - object_init_ex(zparams_obj, php_http_params_get_class_entry()); + 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); @@ -324,6 +291,10 @@ PHP_METHOD(HttpHeader, getParams) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpHeader_parse, 0, 0, 1) + ZEND_ARG_INFO(0, string) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpHeader, parse) { char *header_str; @@ -374,9 +345,27 @@ PHP_METHOD(HttpHeader, parse) } } +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) { - PHP_HTTP_REGISTER_CLASS(http, Header, http_header, php_http_object_get_class_entry(), 0); + 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); diff --git a/php_http_headers.h b/php_http_headers.h index 8eae254..88a988a 100644 --- a/php_http_headers.h +++ b/php_http_headers.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -22,16 +22,7 @@ PHP_HTTP_API void php_http_headers_to_string(php_http_buffer_t *str, HashTable * PHP_HTTP_API zval *php_http_header_value_to_string(zval *header TSRMLS_DC); -zend_class_entry *php_http_header_get_class_entry(void); - -PHP_METHOD(HttpHeader, __construct); -PHP_METHOD(HttpHeader, serialize); -PHP_METHOD(HttpHeader, unserialize); -PHP_METHOD(HttpHeader, match); -PHP_METHOD(HttpHeader, negotiate); -PHP_METHOD(HttpHeader, getParams); -PHP_METHOD(HttpHeader, parse); - +PHP_HTTP_API zend_class_entry *php_http_header_class_entry; PHP_MINIT_FUNCTION(http_header); #endif diff --git a/php_http_info.c b/php_http_info.c index 09964bb..baccfc1 100644 --- a/php_http_info.c +++ b/php_http_info.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_info.h b/php_http_info.h index 92a3f33..87aa791 100644 --- a/php_http_info.h +++ b/php_http_info.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_message.c b/php_http_message.c index 57b66b3..80c488e 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -495,186 +495,10 @@ PHP_HTTP_API void php_http_message_free(php_http_message_t **message) } } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0) -#define PHP_HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, PHP_HTTP_ARGS(HttpMessage, method), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(message, 0) - PHP_HTTP_ARG_VAL(greedy, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getBody); -PHP_HTTP_BEGIN_ARGS(setBody, 1) - PHP_HTTP_ARG_VAL(body, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addBody, 1) - PHP_HTTP_ARG_VAL(body, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(getHeader, 1) - PHP_HTTP_ARG_VAL(header, 0) - PHP_HTTP_ARG_VAL(into_class, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(setHeader, 1) - PHP_HTTP_ARG_VAL(header, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addHeader, 2) - PHP_HTTP_ARG_VAL(header, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getHeaders); -PHP_HTTP_BEGIN_ARGS(setHeaders, 1) - PHP_HTTP_ARG_VAL(headers, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addHeaders, 1) - PHP_HTTP_ARG_VAL(headers, 0) - PHP_HTTP_ARG_VAL(append, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getType); -PHP_HTTP_BEGIN_ARGS(setType, 1) - PHP_HTTP_ARG_VAL(type, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getInfo); -PHP_HTTP_BEGIN_ARGS(setInfo, 1) - PHP_HTTP_ARG_VAL(http_info, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getResponseCode); -PHP_HTTP_BEGIN_ARGS(setResponseCode, 1) - PHP_HTTP_ARG_VAL(response_code, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getResponseStatus); -PHP_HTTP_BEGIN_ARGS(setResponseStatus, 1) - PHP_HTTP_ARG_VAL(response_status, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getRequestMethod); -PHP_HTTP_BEGIN_ARGS(setRequestMethod, 1) - PHP_HTTP_ARG_VAL(request_method, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getRequestUrl); -PHP_HTTP_BEGIN_ARGS(setRequestUrl, 1) - PHP_HTTP_ARG_VAL(url, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getHttpVersion); -PHP_HTTP_BEGIN_ARGS(setHttpVersion, 1) - PHP_HTTP_ARG_VAL(http_version, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getParentMessage); -PHP_HTTP_EMPTY_ARGS(__toString); -PHP_HTTP_BEGIN_ARGS(toString, 0) - PHP_HTTP_ARG_VAL(include_parent, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(toCallback, 1) - PHP_HTTP_ARG_VAL(callback, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_BEGIN_ARGS(toStream, 1) - PHP_HTTP_ARG_VAL(stream, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(count); - -PHP_HTTP_EMPTY_ARGS(serialize); -PHP_HTTP_BEGIN_ARGS(unserialize, 1) - PHP_HTTP_ARG_VAL(serialized, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(rewind); -PHP_HTTP_EMPTY_ARGS(valid); -PHP_HTTP_EMPTY_ARGS(key); -PHP_HTTP_EMPTY_ARGS(current); -PHP_HTTP_EMPTY_ARGS(next); - -PHP_HTTP_EMPTY_ARGS(detach); -PHP_HTTP_BEGIN_ARGS(prepend, 1) - PHP_HTTP_ARG_OBJ(http\\Message, message, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_EMPTY_ARGS(reverse); - -PHP_HTTP_BEGIN_ARGS(isMultipart, 0) - PHP_HTTP_ARG_VAL(boundary, 1) -PHP_HTTP_END_ARGS; -PHP_HTTP_EMPTY_ARGS(splitMultipartBody); - static zval *php_http_message_object_read_prop(zval *object, zval *member, int type PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); static void php_http_message_object_write_prop(zval *object, zval *member, zval *value PHP_HTTP_ZEND_LITERAL_DC TSRMLS_DC); static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC); -static zend_class_entry *php_http_message_class_entry; - -zend_class_entry *php_http_message_get_class_entry(void) -{ - return php_http_message_class_entry; -} - -static zend_function_entry php_http_message_method_entry[] = { - PHP_HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(addBody, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getHeader, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setHeader, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(addHeader, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getType, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getInfo, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setInfo, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getResponseStatus, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setResponseStatus, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getRequestUrl, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setRequestUrl, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(toCallback, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(toStream, ZEND_ACC_PUBLIC) - - /* implements Countable */ - PHP_HTTP_MESSAGE_ME(count, ZEND_ACC_PUBLIC) - - /* implements Serializable */ - PHP_HTTP_MESSAGE_ME(serialize, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(unserialize, ZEND_ACC_PUBLIC) - - /* implements Iterator */ - PHP_HTTP_MESSAGE_ME(rewind, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(valid, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(current, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(key, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(next, ZEND_ACC_PUBLIC) - - ZEND_MALIAS(HttpMessage, __toString, toString, PHP_HTTP_ARGS(HttpMessage, __toString), ZEND_ACC_PUBLIC) - - PHP_HTTP_MESSAGE_ME(detach, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(prepend, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(reverse, ZEND_ACC_PUBLIC) - - PHP_HTTP_MESSAGE_ME(isMultipart, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_ME(splitMultipartBody, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; static zend_object_handlers php_http_message_object_handlers; static HashTable php_http_message_object_prophandlers; @@ -781,8 +605,8 @@ static void php_http_message_object_prophandler_set_headers(php_http_message_obj zval_ptr_dtor(&cpy); } static void php_http_message_object_prophandler_get_body(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { - if (obj->body.handle) { - RETVAL_OBJVAL(obj->body, 1); + if (obj->body) { + RETVAL_OBJVAL(obj->body->zv, 1); } else { RETVAL_NULL(); } @@ -792,7 +616,7 @@ static void php_http_message_object_prophandler_set_body(php_http_message_object } static void php_http_message_object_prophandler_get_parent_message(php_http_message_object_t *obj, zval *return_value TSRMLS_DC) { if (obj->message->parent) { - RETVAL_OBJVAL(obj->parent, 1); + RETVAL_OBJVAL(obj->parent->zv, 1); } else { RETVAL_NULL(); } @@ -802,61 +626,14 @@ static void php_http_message_object_prophandler_set_parent_message(php_http_mess php_http_message_object_t *parent_obj = zend_object_store_get_object(value TSRMLS_CC); if (obj->message->parent) { - zend_objects_store_del_ref_by_handle(obj->parent.handle TSRMLS_CC); + zend_objects_store_del_ref_by_handle(obj->parent->zv.handle TSRMLS_CC); } Z_OBJ_ADDREF_P(value); - obj->parent = Z_OBJVAL_P(value); + obj->parent = parent_obj; obj->message->parent = parent_obj->message; } } -PHP_MINIT_FUNCTION(http_message) -{ - PHP_HTTP_REGISTER_CLASS(http, Message, http_message, php_http_object_get_class_entry(), 0); - 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; - php_http_message_object_handlers.read_property = php_http_message_object_read_prop; - php_http_message_object_handlers.write_property = php_http_message_object_write_prop; - php_http_message_object_handlers.get_properties = php_http_message_object_get_props; - php_http_message_object_handlers.get_property_ptr_ptr = NULL; - - zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator); - - zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1); - zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url); - zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status); - zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers); - zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED TSRMLS_CC); - php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message); - - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE TSRMLS_CC); - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST TSRMLS_CC); - zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE TSRMLS_CC); - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(http_message) -{ - zend_hash_destroy(&php_http_message_object_prophandlers); - - return SUCCESS; -} - #define PHP_HTTP_MESSAGE_OBJECT_INIT(obj) \ do { \ if (!obj->message) { \ @@ -876,39 +653,33 @@ void php_http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_D php_http_message_count(i, obj->message); if (i > 1) { - zend_object_value *ovalues = NULL; - php_http_message_object_t **objects = NULL; + php_http_message_object_t **objects; int last; objects = ecalloc(i, sizeof(**objects)); - ovalues = ecalloc(i, sizeof(*ovalues)); /* we are the first message */ objects[0] = obj; - ovalues[0] = getThis()->value.obj; /* fetch parents */ - for (i = 1; obj->parent.handle; ++i) { - ovalues[i] = obj->parent; - objects[i] = obj = zend_object_store_get_object_by_handle(obj->parent.handle TSRMLS_CC); + for (i = 1; obj->parent; ++i) { + objects[i] = obj = obj->parent; } /* reorder parents */ for (last = --i; i; --i) { objects[i]->message->parent = objects[i-1]->message; - objects[i]->parent = ovalues[i-1]; + objects[i]->parent = objects[i-1]; } objects[0]->message->parent = NULL; - objects[0]->parent.handle = 0; - objects[0]->parent.handlers = NULL; + objects[0]->parent = NULL; /* add ref, because we previously have not been a parent message */ Z_OBJ_ADDREF_P(getThis()); - RETVAL_OBJVAL(ovalues[last], 1); + RETVAL_OBJVAL(objects[last]->zv, 0); efree(objects); - efree(ovalues); } else { RETURN_ZVAL(getThis(), 1, 0); } @@ -918,8 +689,7 @@ void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool to { zval m; php_http_message_t *save_parent_msg = NULL; - zend_object_value save_parent_obj = {0, NULL}; - php_http_message_object_t *obj = zend_object_store_get_object(this_ptr TSRMLS_CC); + php_http_message_object_t *save_parent_obj = NULL, *obj = zend_object_store_get_object(this_ptr TSRMLS_CC); php_http_message_object_t *prepend_obj = zend_object_store_get_object(prepend TSRMLS_CC); INIT_PZVAL(&m); @@ -930,24 +700,24 @@ void php_http_message_object_prepend(zval *this_ptr, zval *prepend, zend_bool to save_parent_msg = obj->message->parent; } else { /* iterate to the most parent object */ - while (obj->parent.handle) { - m.value.obj = obj->parent; - obj = zend_object_store_get_object(&m TSRMLS_CC); + while (obj->parent) { + obj = obj->parent; } } /* prepend */ - obj->parent = prepend->value.obj; + obj->parent = prepend_obj; obj->message->parent = prepend_obj->message; /* add ref */ zend_objects_store_add_ref(prepend TSRMLS_CC); - while (prepend_obj->parent.handle) { - m.value.obj = prepend_obj->parent; + /* + 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; @@ -973,7 +743,7 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval is_resource: body = php_http_message_body_init(NULL, s TSRMLS_CC); - if (SUCCESS != php_http_new(&ov, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, body, NULL TSRMLS_CC)) { + if (SUCCESS != php_http_new(&ov, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, body, NULL TSRMLS_CC)) { php_http_message_body_free(&body); return FAILURE; } @@ -983,7 +753,7 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval break; case IS_OBJECT: - if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_get_class_entry() TSRMLS_CC)) { + if (instanceof_function(Z_OBJCE_P(zbody), php_http_message_body_class_entry TSRMLS_CC)) { Z_OBJ_ADDREF_P(zbody); break; } @@ -1001,13 +771,13 @@ STATUS php_http_message_object_set_body(php_http_message_object_t *msg_obj, zval body_obj = zend_object_store_get_object(zbody TSRMLS_CC); - if (msg_obj->body.handle) { - zend_objects_store_del_ref_by_handle(msg_obj->body.handle TSRMLS_CC); + if (msg_obj->body) { + zend_objects_store_del_ref_by_handle(msg_obj->body->zv.handle TSRMLS_CC); } php_http_message_body_free(&msg_obj->message->body); msg_obj->message->body = php_http_message_body_init(&body_obj->body, NULL TSRMLS_CC); - msg_obj->body = Z_OBJVAL_P(zbody); + msg_obj->body = body_obj; if (tmp) { FREE_ZVAL(tmp); @@ -1035,9 +805,9 @@ zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_ if (msg) { o->message = msg; if (msg->parent) { - o->parent = php_http_message_object_new_ex(ce, msg->parent, NULL TSRMLS_CC); + php_http_message_object_new_ex(ce, msg->parent, &o->parent TSRMLS_CC); } - o->body = php_http_message_body_object_new_ex(php_http_message_body_get_class_entry(), php_http_message_body_init(&msg->body, NULL TSRMLS_CC), NULL TSRMLS_CC); + php_http_message_body_object_new_ex(php_http_message_body_class_entry, php_http_message_body_init(&msg->body, NULL TSRMLS_CC), &o->body TSRMLS_CC); } o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_object_free, NULL TSRMLS_CC); @@ -1072,11 +842,13 @@ void php_http_message_object_free(void *object TSRMLS_DC) efree(o->message); o->message = NULL; } - if (o->parent.handle) { - zend_objects_store_del_ref_by_handle(o->parent.handle TSRMLS_CC); + if (o->parent) { + zend_objects_store_del_ref_by_handle(o->parent->zv.handle TSRMLS_CC); + o->parent = NULL; } - if (o->body.handle) { - zend_objects_store_del_ref_by_handle(o->body.handle TSRMLS_CC); + if (o->body) { + zend_objects_store_del_ref_by_handle(o->body->zv.handle TSRMLS_CC); + o->body = NULL; } zend_object_std_dtor((zend_object *) o TSRMLS_CC); efree(o); @@ -1191,15 +963,15 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) ASSOC_PROP(zval, "headers", headers); MAKE_STD_ZVAL(body); - if (!obj->body.handle) { - php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), NULL TSRMLS_CC); + if (!obj->body) { + php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC); } - ZVAL_OBJVAL(body, obj->body, 1); + ZVAL_OBJVAL(body, obj->body->zv, 1); ASSOC_PROP(zval, "body", body); MAKE_STD_ZVAL(parent); if (msg->parent) { - ZVAL_OBJVAL(parent, obj->parent, 1); + ZVAL_OBJVAL(parent, obj->parent->zv, 1); } else { ZVAL_NULL(parent); } @@ -1208,16 +980,18 @@ static HashTable *php_http_message_object_get_props(zval *object TSRMLS_DC) return props; } -/* PHP */ - -PHP_METHOD(HttpMessage, __construct) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___construct, 0, 0, 0) + ZEND_ARG_INFO(0, message) + ZEND_ARG_INFO(0, greedy) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, __construct) { zend_bool greedy = 1; zval *zmessage = NULL; php_http_message_t *msg = NULL; php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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; @@ -1246,7 +1020,7 @@ PHP_METHOD(HttpMessage, __construct) php_http_message_dtor(obj->message); obj->message = msg; if (obj->message->parent) { - obj->parent = php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, NULL TSRMLS_CC); + php_http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, &obj->parent TSRMLS_CC); } } } @@ -1255,30 +1029,35 @@ PHP_METHOD(HttpMessage, __construct) } -PHP_METHOD(HttpMessage, getBody) +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_get_class_entry()) { + 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_INIT(obj); - if (!obj->body.handle) { + if (!obj->body) { php_http_message_body_addref(obj->message->body); - php_http_new(&obj->body, php_http_message_body_get_class_entry(), (php_http_new_t) php_http_message_body_object_new_ex, NULL, obj->message->body, NULL TSRMLS_CC); + 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.handle) { - RETVAL_OBJVAL(obj->body, 1); + if (obj->body) { + RETVAL_OBJVAL(obj->body->zv, 1); } } } end_error_handling(); } -PHP_METHOD(HttpMessage, setBody) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setBody, 0, 0, 1) + ZEND_ARG_INFO(0, body) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setBody) { zval *zbody; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_get_class_entry())) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zbody, php_http_message_body_class_entry)) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); PHP_HTTP_MESSAGE_OBJECT_INIT(obj); @@ -1287,11 +1066,14 @@ PHP_METHOD(HttpMessage, setBody) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, addBody) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addBody, 0, 0, 1) + ZEND_ARG_INFO(0, body) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, addBody) { zval *new_body; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &new_body, php_http_message_body_get_class_entry())) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &new_body, php_http_message_body_class_entry)) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); php_http_message_body_object_t *new_obj = zend_object_store_get_object(new_body TSRMLS_CC); @@ -1301,7 +1083,11 @@ PHP_METHOD(HttpMessage, addBody) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeader, 0, 0, 1) + ZEND_ARG_INFO(0, header) + ZEND_ARG_INFO(0, into_class) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getHeader) { char *header_str; int header_len; @@ -1316,7 +1102,7 @@ PHP_METHOD(HttpMessage, getHeader) if ((header = php_http_message_header(obj->message, header_str, header_len, 0))) { if (!header_ce) { RETURN_ZVAL(header, 1, 1); - } else if (instanceof_function(header_ce, php_http_header_get_class_entry() TSRMLS_CC)) { + } else if (instanceof_function(header_ce, php_http_header_class_entry TSRMLS_CC)) { zval *header_name, **argv[2]; MAKE_STD_ZVAL(header_name); @@ -1341,7 +1127,9 @@ PHP_METHOD(HttpMessage, getHeader) RETURN_FALSE; } -PHP_METHOD(HttpMessage, getHeaders) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHeaders, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getHeaders) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1353,7 +1141,11 @@ PHP_METHOD(HttpMessage, getHeaders) } } -PHP_METHOD(HttpMessage, setHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeader, 0, 0, 1) + ZEND_ARG_INFO(0, header) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setHeader) { zval *zvalue = NULL; char *name_str; @@ -1376,7 +1168,10 @@ PHP_METHOD(HttpMessage, setHeader) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, setHeaders) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHeaders, 0, 0, 1) + ZEND_ARG_INFO(0, headers) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setHeaders) { zval *new_headers = NULL; @@ -1393,7 +1188,11 @@ PHP_METHOD(HttpMessage, setHeaders) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, addHeader) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeader, 0, 0, 2) + ZEND_ARG_INFO(0, header) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, addHeader) { zval *zvalue; char *name_str; @@ -1419,7 +1218,11 @@ PHP_METHOD(HttpMessage, addHeader) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, addHeaders) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_addHeaders, 0, 0, 1) + ZEND_ARG_INFO(0, headers) + ZEND_ARG_INFO(0, append) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, addHeaders) { zval *new_headers; zend_bool append = 0; @@ -1434,7 +1237,9 @@ PHP_METHOD(HttpMessage, addHeaders) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getType, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getType) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1445,7 +1250,10 @@ PHP_METHOD(HttpMessage, getType) } } -PHP_METHOD(HttpMessage, setType) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setType, 0, 0, 1) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setType) { long type; @@ -1459,7 +1267,9 @@ PHP_METHOD(HttpMessage, setType) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getInfo) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getInfo, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getInfo) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1483,7 +1293,10 @@ PHP_METHOD(HttpMessage, getInfo) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setInfo) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setInfo, 0, 0, 1) + ZEND_ARG_INFO(0, http_info) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setInfo) { char *str; int len; @@ -1501,7 +1314,9 @@ PHP_METHOD(HttpMessage, setInfo) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getHttpVersion) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getHttpVersion, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getHttpVersion) { if (SUCCESS == zend_parse_parameters_none()) { char *str; @@ -1517,7 +1332,10 @@ PHP_METHOD(HttpMessage, getHttpVersion) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setHttpVersion) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setHttpVersion, 0, 0, 1) + ZEND_ARG_INFO(0, http_version) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setHttpVersion) { char *v_str; int v_len; @@ -1535,7 +1353,9 @@ PHP_METHOD(HttpMessage, setHttpVersion) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getResponseCode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseCode, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getResponseCode) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1548,7 +1368,10 @@ PHP_METHOD(HttpMessage, getResponseCode) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setResponseCode) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseCode, 0, 0, 1) + ZEND_ARG_INFO(0, response_code) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setResponseCode) { long code; zend_bool strict = 1; @@ -1570,7 +1393,9 @@ PHP_METHOD(HttpMessage, setResponseCode) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getResponseStatus) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getResponseStatus, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getResponseStatus) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1588,7 +1413,10 @@ PHP_METHOD(HttpMessage, getResponseStatus) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setResponseStatus) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setResponseStatus, 0, 0, 1) + ZEND_ARG_INFO(0, response_status) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setResponseStatus) { char *status; int status_len; @@ -1604,7 +1432,9 @@ PHP_METHOD(HttpMessage, setResponseStatus) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getRequestMethod) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestMethod, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getRequestMethod) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1622,7 +1452,10 @@ PHP_METHOD(HttpMessage, getRequestMethod) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setRequestMethod) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestMethod, 0, 0, 1) + ZEND_ARG_INFO(0, request_method) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setRequestMethod) { char *method; int method_len; @@ -1643,7 +1476,9 @@ PHP_METHOD(HttpMessage, setRequestMethod) RETVAL_ZVAL(getThis(), 1, 0); } -PHP_METHOD(HttpMessage, getRequestUrl) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getRequestUrl, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getRequestUrl) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1661,7 +1496,10 @@ PHP_METHOD(HttpMessage, getRequestUrl) RETURN_FALSE; } -PHP_METHOD(HttpMessage, setRequestUrl) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_setRequestUrl, 0, 0, 1) + ZEND_ARG_INFO(0, url) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, setRequestUrl) { char *url_str; int url_len; @@ -1681,17 +1519,18 @@ PHP_METHOD(HttpMessage, setRequestUrl) RETVAL_ZVAL(getThis(), 1, 0); } - -PHP_METHOD(HttpMessage, getParentMessage) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_getParentMessage, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, getParentMessage) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_INIT(obj); if (obj->message->parent) { - RETVAL_OBJVAL(obj->parent, 1); + RETVAL_OBJVAL(obj->parent->zv, 1); } else { php_http_error(HE_WARNING, PHP_HTTP_E_RUNTIME, "HttpMessage does not have a parent message"); } @@ -1699,7 +1538,12 @@ PHP_METHOD(HttpMessage, getParentMessage) } end_error_handling(); } -PHP_METHOD(HttpMessage, toString) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage___toString, 0, 0, 0) +ZEND_END_ARG_INFO(); +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toString, 0, 0, 0) + ZEND_ARG_INFO(0, include_parent) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, toString) { zend_bool include_parent = 0; @@ -1722,7 +1566,10 @@ PHP_METHOD(HttpMessage, toString) RETURN_EMPTY_STRING(); } -PHP_METHOD(HttpMessage, toStream) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toStream, 0, 0, 1) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, toStream) { zval *zstream; @@ -1737,7 +1584,10 @@ PHP_METHOD(HttpMessage, toStream) } } -PHP_METHOD(HttpMessage, toCallback) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_toCallback, 0, 0, 1) + ZEND_ARG_INFO(0, callback) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, toCallback) { php_http_pass_fcall_arg_t fcd; @@ -1759,7 +1609,9 @@ PHP_METHOD(HttpMessage, toCallback) RETURN_FALSE; } -PHP_METHOD(HttpMessage, serialize) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_serialize, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, serialize) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1774,7 +1626,10 @@ PHP_METHOD(HttpMessage, serialize) RETURN_EMPTY_STRING(); } -PHP_METHOD(HttpMessage, unserialize) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_unserialize, 0, 0, 1) + ZEND_ARG_INFO(0, serialized) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, unserialize) { int length; char *serialized; @@ -1796,9 +1651,11 @@ PHP_METHOD(HttpMessage, unserialize) } } -PHP_METHOD(HttpMessage, detach) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_detach, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, detach) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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); @@ -1809,7 +1666,10 @@ PHP_METHOD(HttpMessage, detach) } end_error_handling(); } -PHP_METHOD(HttpMessage, prepend) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_prepend, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, message, http\\Message, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, prepend) { zval *prepend; zend_bool top = 1; @@ -1839,14 +1699,19 @@ PHP_METHOD(HttpMessage, prepend) } } -PHP_METHOD(HttpMessage, reverse) +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_METHOD(HttpMessage, isMultipart) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_isMultipart, 0, 0, 0) + ZEND_ARG_INFO(1, boundary) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, isMultipart) { zval *zboundary = NULL; @@ -1865,7 +1730,9 @@ PHP_METHOD(HttpMessage, isMultipart) } } -PHP_METHOD(HttpMessage, splitMultipartBody) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_splitMultipartBody, 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); @@ -1884,7 +1751,9 @@ PHP_METHOD(HttpMessage, splitMultipartBody) } } -PHP_METHOD(HttpMessage, count) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_count, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, count) { if (SUCCESS == zend_parse_parameters_none()) { long i = 0; @@ -1898,7 +1767,9 @@ PHP_METHOD(HttpMessage, count) RETURN_FALSE; } -PHP_METHOD(HttpMessage, rewind) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_rewind, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, rewind) { if (SUCCESS == zend_parse_parameters_none()) { zval *zobj = getThis(); @@ -1912,7 +1783,9 @@ PHP_METHOD(HttpMessage, rewind) } } -PHP_METHOD(HttpMessage, valid) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_valid, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, valid) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1921,7 +1794,9 @@ PHP_METHOD(HttpMessage, valid) } } -PHP_METHOD(HttpMessage, next) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_next, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, next) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1929,10 +1804,10 @@ PHP_METHOD(HttpMessage, next) if (obj->iterator) { php_http_message_object_t *itr = zend_object_store_get_object(obj->iterator TSRMLS_CC); - if (itr && itr->parent.handle) { + if (itr && itr->parent) { zval *old = obj->iterator; MAKE_STD_ZVAL(obj->iterator); - ZVAL_OBJVAL(obj->iterator, itr->parent, 1); + ZVAL_OBJVAL(obj->iterator, itr->parent->zv, 1); zval_ptr_dtor(&old); } else { zval_ptr_dtor(&obj->iterator); @@ -1942,7 +1817,9 @@ PHP_METHOD(HttpMessage, next) } } -PHP_METHOD(HttpMessage, key) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_key, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, key) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1951,7 +1828,9 @@ PHP_METHOD(HttpMessage, key) } } -PHP_METHOD(HttpMessage, current) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessage_current, 0, 0, 0) +ZEND_END_ARG_INFO(); +static PHP_METHOD(HttpMessage, current) { if (SUCCESS == zend_parse_parameters_none()) { php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); @@ -1962,6 +1841,114 @@ PHP_METHOD(HttpMessage, current) } } +static zend_function_entry php_http_message_methods[] = { + PHP_ME(HttpMessage, __construct, ai_HttpMessage___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpMessage, getBody, ai_HttpMessage_getBody, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setBody, ai_HttpMessage_setBody, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, addBody, ai_HttpMessage_addBody, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getHeader, ai_HttpMessage_getHeader, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setHeader, ai_HttpMessage_setHeader, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, addHeader, ai_HttpMessage_addHeader, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getHeaders, ai_HttpMessage_getHeaders, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setHeaders, ai_HttpMessage_setHeaders, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, addHeaders, ai_HttpMessage_addHeaders, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getType, ai_HttpMessage_getType, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setType, ai_HttpMessage_setType, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getInfo, ai_HttpMessage_getInfo, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setInfo, ai_HttpMessage_setInfo, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getResponseCode, ai_HttpMessage_getResponseCode, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setResponseCode, ai_HttpMessage_setResponseCode, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getResponseStatus, ai_HttpMessage_getResponseStatus, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setResponseStatus, ai_HttpMessage_setResponseStatus, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getRequestMethod, ai_HttpMessage_getRequestMethod, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setRequestMethod, ai_HttpMessage_setRequestMethod, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getRequestUrl, ai_HttpMessage_getRequestUrl, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setRequestUrl, ai_HttpMessage_setRequestUrl, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getHttpVersion, ai_HttpMessage_getHttpVersion, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, setHttpVersion, ai_HttpMessage_setHttpVersion, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, getParentMessage, ai_HttpMessage_getParentMessage, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, toString, ai_HttpMessage_toString, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, toCallback, ai_HttpMessage_toCallback, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, toStream, ai_HttpMessage_toStream, ZEND_ACC_PUBLIC) + + /* implements Countable */ + PHP_ME(HttpMessage, count, ai_HttpMessage_count, ZEND_ACC_PUBLIC) + + /* implements Serializable */ + PHP_ME(HttpMessage, serialize, ai_HttpMessage_serialize, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, unserialize, ai_HttpMessage_unserialize, ZEND_ACC_PUBLIC) + + /* implements Iterator */ + PHP_ME(HttpMessage, rewind, ai_HttpMessage_rewind, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, valid, ai_HttpMessage_valid, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, current, ai_HttpMessage_current, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, key, ai_HttpMessage_key, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, next, ai_HttpMessage_next, ZEND_ACC_PUBLIC) + + ZEND_MALIAS(HttpMessage, __toString, toString, ai_HttpMessage___toString, ZEND_ACC_PUBLIC) + + PHP_ME(HttpMessage, detach, ai_HttpMessage_detach, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, prepend, ai_HttpMessage_prepend, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, reverse, ai_HttpMessage_reverse, ZEND_ACC_PUBLIC) + + PHP_ME(HttpMessage, isMultipart, ai_HttpMessage_isMultipart, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessage, splitMultipartBody, ai_HttpMessage_splitMultipartBody, ZEND_ACC_PUBLIC) + + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_message_class_entry; + +PHP_MINIT_FUNCTION(http_message) +{ + 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->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; + php_http_message_object_handlers.read_property = php_http_message_object_read_prop; + php_http_message_object_handlers.write_property = php_http_message_object_write_prop; + php_http_message_object_handlers.get_properties = php_http_message_object_get_props; + php_http_message_object_handlers.get_property_ptr_ptr = NULL; + + zend_class_implements(php_http_message_class_entry TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator); + + zend_hash_init(&php_http_message_object_prophandlers, 9, NULL, NULL, 1); + zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("type"), PHP_HTTP_NONE, ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("type"), php_http_message_object_prophandler_get_type, php_http_message_object_prophandler_set_type); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("body"), ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("body"), php_http_message_object_prophandler_get_body, php_http_message_object_prophandler_set_body); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestMethod"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("requestMethod"), php_http_message_object_prophandler_get_request_method, php_http_message_object_prophandler_set_request_method); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("requestUrl"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("requestUrl"), php_http_message_object_prophandler_get_request_url, php_http_message_object_prophandler_set_request_url); + zend_declare_property_string(php_http_message_class_entry, ZEND_STRL("responseStatus"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("responseStatus"), php_http_message_object_prophandler_get_response_status, php_http_message_object_prophandler_set_response_status); + zend_declare_property_long(php_http_message_class_entry, ZEND_STRL("responseCode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("responseCode"), php_http_message_object_prophandler_get_response_code, php_http_message_object_prophandler_set_response_code); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("httpVersion"), ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("httpVersion"), php_http_message_object_prophandler_get_http_version, php_http_message_object_prophandler_set_http_version); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("headers"), ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("headers"), php_http_message_object_prophandler_get_headers, php_http_message_object_prophandler_set_headers); + zend_declare_property_null(php_http_message_class_entry, ZEND_STRL("parentMessage"), ZEND_ACC_PROTECTED TSRMLS_CC); + php_http_message_object_add_prophandler(ZEND_STRL("parentMessage"), php_http_message_object_prophandler_get_parent_message, php_http_message_object_prophandler_set_parent_message); + + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_NONE"), PHP_HTTP_NONE TSRMLS_CC); + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_REQUEST"), PHP_HTTP_REQUEST TSRMLS_CC); + zend_declare_class_constant_long(php_http_message_class_entry, ZEND_STRL("TYPE_RESPONSE"), PHP_HTTP_RESPONSE TSRMLS_CC); + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(http_message) +{ + zend_hash_destroy(&php_http_message_object_prophandlers); + + return SUCCESS; +} + /* * Local variables: * tab-width: 4 diff --git a/php_http_message.h b/php_http_message.h index e45cabf..e94714f 100644 --- a/php_http_message.h +++ b/php_http_message.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -71,17 +71,16 @@ PHP_HTTP_API php_http_message_t *php_http_message_zip(php_http_message_t *one, p 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 */ - typedef struct php_http_message_object { zend_object zo; zend_object_value zv; php_http_message_t *message; - zend_object_value parent, body; + struct php_http_message_object *parent; + php_http_message_body_object_t *body; zval *iterator; } php_http_message_object_t; -zend_class_entry *php_http_message_get_class_entry(void); +zend_class_entry *php_http_message_class_entry; PHP_MINIT_FUNCTION(http_message); PHP_MSHUTDOWN_FUNCTION(http_message); @@ -95,54 +94,6 @@ zend_object_value php_http_message_object_new_ex(zend_class_entry *ce, php_http_ zend_object_value php_http_message_object_clone(zval *object TSRMLS_DC); void php_http_message_object_free(void *object TSRMLS_DC); -PHP_METHOD(HttpMessage, __construct); -PHP_METHOD(HttpMessage, getBody); -PHP_METHOD(HttpMessage, setBody); -PHP_METHOD(HttpMessage, addBody); -PHP_METHOD(HttpMessage, getHeader); -PHP_METHOD(HttpMessage, setHeader); -PHP_METHOD(HttpMessage, addHeader); -PHP_METHOD(HttpMessage, getHeaders); -PHP_METHOD(HttpMessage, setHeaders); -PHP_METHOD(HttpMessage, addHeaders); -PHP_METHOD(HttpMessage, getType); -PHP_METHOD(HttpMessage, setType); -PHP_METHOD(HttpMessage, getInfo); -PHP_METHOD(HttpMessage, setInfo); -PHP_METHOD(HttpMessage, getResponseCode); -PHP_METHOD(HttpMessage, setResponseCode); -PHP_METHOD(HttpMessage, getResponseStatus); -PHP_METHOD(HttpMessage, setResponseStatus); -PHP_METHOD(HttpMessage, getRequestMethod); -PHP_METHOD(HttpMessage, setRequestMethod); -PHP_METHOD(HttpMessage, getRequestUrl); -PHP_METHOD(HttpMessage, setRequestUrl); -PHP_METHOD(HttpMessage, getHttpVersion); -PHP_METHOD(HttpMessage, setHttpVersion); -PHP_METHOD(HttpMessage, guessContentType); -PHP_METHOD(HttpMessage, getParentMessage); -PHP_METHOD(HttpMessage, send); -PHP_METHOD(HttpMessage, toString); -PHP_METHOD(HttpMessage, toStream); -PHP_METHOD(HttpMessage, toCallback); - -PHP_METHOD(HttpMessage, count); -PHP_METHOD(HttpMessage, serialize); -PHP_METHOD(HttpMessage, unserialize); -PHP_METHOD(HttpMessage, rewind); -PHP_METHOD(HttpMessage, valid); -PHP_METHOD(HttpMessage, current); -PHP_METHOD(HttpMessage, key); -PHP_METHOD(HttpMessage, next); - -PHP_METHOD(HttpMessage, factory); - -PHP_METHOD(HttpMessage, detach); -PHP_METHOD(HttpMessage, prepend); -PHP_METHOD(HttpMessage, reverse); - -PHP_METHOD(HttpMessage, isMultipart); -PHP_METHOD(HttpMessage, splitMultipartBody); #endif /* diff --git a/php_http_message_body.c b/php_http_message_body.c index cf2f0a9..fd5b762 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -539,85 +539,8 @@ PHP_HTTP_API php_http_message_t *php_http_message_body_split(php_http_message_bo return msg; } -/* PHP */ - -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpMessageBody, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpMessageBody, method, 0) -#define PHP_HTTP_MESSAGE_BODY_ME(method, visibility) PHP_ME(HttpMessageBody, method, PHP_HTTP_ARGS(HttpMessageBody, method), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(stream, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(__toString); -PHP_HTTP_BEGIN_ARGS(unserialize, 1) - PHP_HTTP_ARG_VAL(serialized, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(toStream, 1) - PHP_HTTP_ARG_VAL(stream, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(toCallback, 1) - PHP_HTTP_ARG_VAL(callback, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getResource); - -PHP_HTTP_BEGIN_ARGS(append, 1) - PHP_HTTP_ARG_VAL(string, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addForm, 0) - PHP_HTTP_ARG_ARR(fields, 1, 0) - PHP_HTTP_ARG_ARR(files, 1, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(addPart, 1) - PHP_HTTP_ARG_OBJ(http\\Message, message, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(etag); - -PHP_HTTP_BEGIN_ARGS(stat, 0) - PHP_HTTP_ARG_VAL(what, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_message_body_class_entry; - -zend_class_entry *php_http_message_body_get_class_entry(void) -{ - return php_http_message_body_class_entry; -} - -static zend_function_entry php_http_message_body_method_entry[] = { - PHP_HTTP_MESSAGE_BODY_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_MESSAGE_BODY_ME(__toString, ZEND_ACC_PUBLIC) - PHP_MALIAS(HttpMessageBody, toString, __toString, args_for_HttpMessageBody___toString, ZEND_ACC_PUBLIC) - PHP_MALIAS(HttpMessageBody, serialize, __toString, args_for_HttpMessageBody___toString, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(unserialize, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(toStream, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(toCallback, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(getResource, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(append, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(addForm, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(addPart, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(etag, ZEND_ACC_PUBLIC) - PHP_HTTP_MESSAGE_BODY_ME(stat, ZEND_ACC_PUBLIC) - EMPTY_FUNCTION_ENTRY -}; static zend_object_handlers php_http_message_body_object_handlers; -PHP_MINIT_FUNCTION(http_message_body) -{ - PHP_HTTP_REGISTER_CLASS(http\\Message, Body, http_message_body, php_http_object_get_class_entry(), 0); - 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; - zend_class_implements(php_http_message_body_class_entry TSRMLS_CC, 1, zend_ce_serializable); - return SUCCESS; -} - zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_DC) { return php_http_message_body_object_new_ex(ce, NULL, NULL TSRMLS_CC); @@ -625,7 +548,6 @@ zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_D zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_http_message_body_t *body, php_http_message_body_object_t **ptr TSRMLS_DC) { - zend_object_value ov; php_http_message_body_object_t *o; o = ecalloc(1, sizeof(php_http_message_body_object_t)); @@ -640,10 +562,10 @@ zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_ o->body = body; } - ov.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_body_object_free, NULL TSRMLS_CC); - ov.handlers = &php_http_message_body_object_handlers; + o->zv.handle = zend_objects_store_put((zend_object *) o, NULL, php_http_message_body_object_free, NULL TSRMLS_CC); + o->zv.handlers = &php_http_message_body_object_handlers; - return ov; + return o->zv; } zend_object_value php_http_message_body_object_clone(zval *object TSRMLS_DC) @@ -663,9 +585,7 @@ void php_http_message_body_object_free(void *object TSRMLS_DC) { php_http_message_body_object_t *obj = object; - if (!obj->shared) { - php_http_message_body_free(&obj->body); - } + php_http_message_body_free(&obj->body); zend_object_std_dtor((zend_object *) obj TSRMLS_CC); efree(obj); } @@ -677,13 +597,16 @@ void php_http_message_body_object_free(void *object TSRMLS_DC) } \ } while(0) +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody___construct, 0, 0, 0) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, __construct) { php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC); zval *zstream = NULL; php_stream *stream; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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); @@ -700,6 +623,8 @@ PHP_METHOD(HttpMessageBody, __construct) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody___toString, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, __toString) { if (SUCCESS == zend_parse_parameters_none()) { @@ -717,6 +642,9 @@ PHP_METHOD(HttpMessageBody, __toString) RETURN_EMPTY_STRING(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_unserialize, 0, 0, 1) + ZEND_ARG_INFO(0, serialized) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, unserialize) { char *us_str; @@ -730,6 +658,9 @@ PHP_METHOD(HttpMessageBody, unserialize) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_toStream, 0, 0, 1) + ZEND_ARG_INFO(0, stream) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, toStream) { zval *zstream; @@ -748,7 +679,9 @@ PHP_METHOD(HttpMessageBody, toStream) RETURN_FALSE; } - +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_toCallback, 0, 0, 1) + ZEND_ARG_INFO(0, callback) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, toCallback) { php_http_pass_fcall_arg_t fcd; @@ -772,6 +705,8 @@ PHP_METHOD(HttpMessageBody, toCallback) RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_getResource, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, getResource) { if (SUCCESS == zend_parse_parameters_none()) { @@ -784,6 +719,9 @@ PHP_METHOD(HttpMessageBody, getResource) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_append, 0, 0, 1) + ZEND_ARG_INFO(0, string) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, append) { char *str; @@ -799,6 +737,10 @@ PHP_METHOD(HttpMessageBody, append) RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addForm, 0, 0, 0) + ZEND_ARG_ARRAY_INFO(0, fields, 1) + ZEND_ARG_ARRAY_INFO(0, files, 1) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, addForm) { HashTable *fields = NULL, *files = NULL; @@ -808,16 +750,19 @@ PHP_METHOD(HttpMessageBody, addForm) PHP_HTTP_MESSAGE_BODY_OBJECT_INIT(obj); - RETURN_SUCCESS(php_http_message_body_add_form(obj->body, fields, files)); + RETURN_BOOL(SUCCESS == php_http_message_body_add_form(obj->body, fields, files)); } RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_addPart, 0, 0, 1) + ZEND_ARG_OBJ_INFO(0, message, http\\Message, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, addPart) { zval *zobj; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobj, php_http_message_get_class_entry())) { + 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); @@ -829,6 +774,8 @@ PHP_METHOD(HttpMessageBody, addPart) RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_etag, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, etag) { if (SUCCESS == zend_parse_parameters_none()) { @@ -844,6 +791,9 @@ PHP_METHOD(HttpMessageBody, etag) RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpMessageBody_stat, 0, 0, 0) + ZEND_ARG_INFO(0, what) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpMessageBody, stat) { char *field_str = NULL; @@ -891,6 +841,39 @@ PHP_METHOD(HttpMessageBody, stat) RETURN_FALSE; } +static zend_function_entry php_http_message_body_methods[] = { + PHP_ME(HttpMessageBody, __construct, ai_HttpMessageBody___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpMessageBody, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) + PHP_MALIAS(HttpMessageBody, toString, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) + PHP_MALIAS(HttpMessageBody, serialize, __toString, ai_HttpMessageBody___toString, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, unserialize, ai_HttpMessageBody_unserialize, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, toStream, ai_HttpMessageBody_toStream, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, toCallback, ai_HttpMessageBody_toCallback, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, getResource, ai_HttpMessageBody_getResource, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, append, ai_HttpMessageBody_append, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, addForm, ai_HttpMessageBody_addForm, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, addPart, ai_HttpMessageBody_addPart, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, etag, ai_HttpMessageBody_etag, ZEND_ACC_PUBLIC) + PHP_ME(HttpMessageBody, stat, ai_HttpMessageBody_stat, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_message_body_class_entry; + +PHP_MINIT_FUNCTION(http_message_body) +{ + 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->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; + zend_class_implements(php_http_message_body_class_entry TSRMLS_CC, 1, zend_ce_serializable); + + return SUCCESS; +} + /* * Local variables: * tab-width: 4 diff --git a/php_http_message_body.h b/php_http_message_body.h index 55016b7..10b87bc 100644 --- a/php_http_message_body.h +++ b/php_http_message_body.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -51,15 +51,13 @@ static inline php_stream *php_http_message_body_stream(php_http_message_body_t * return zend_fetch_resource(NULL TSRMLS_CC, body->stream_id, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream()); } - typedef struct php_http_message_body_object { zend_object zo; + zend_object_value zv; php_http_message_body_t *body; - unsigned shared:1; } php_http_message_body_object_t; -zend_class_entry *php_http_message_body_get_class_entry(void); - +PHP_HTTP_API zend_class_entry *php_http_message_body_class_entry; PHP_MINIT_FUNCTION(http_message_body); zend_object_value php_http_message_body_object_new(zend_class_entry *ce TSRMLS_DC); @@ -67,18 +65,6 @@ zend_object_value php_http_message_body_object_new_ex(zend_class_entry *ce, php_ zend_object_value php_http_message_body_object_clone(zval *object TSRMLS_DC); void php_http_message_body_object_free(void *object TSRMLS_DC); -PHP_METHOD(HttpMessageBody, __construct); -PHP_METHOD(HttpMessageBody, __toString); -PHP_METHOD(HttpMessageBody, unserialize); -PHP_METHOD(HttpMessageBody, getResource); -PHP_METHOD(HttpMessageBody, toStream); -PHP_METHOD(HttpMessageBody, toCallback); -PHP_METHOD(HttpMessageBody, append); -PHP_METHOD(HttpMessageBody, addForm); -PHP_METHOD(HttpMessageBody, addPart); -PHP_METHOD(HttpMessageBody, etag); -PHP_METHOD(HttpMessageBody, stat); - #endif /* diff --git a/php_http_message_parser.c b/php_http_message_parser.c index 5d80766..cc29c28 100644 --- a/php_http_message_parser.c +++ b/php_http_message_parser.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_message_parser.h b/php_http_message_parser.h index 09e038b..8ecf991 100644 --- a/php_http_message_parser.h +++ b/php_http_message_parser.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_misc.c b/php_http_misc.c index 092662a..3ad9988 100644 --- a/php_http_misc.c +++ b/php_http_misc.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -253,7 +253,7 @@ static inline int scope_error_handling(long type TSRMLS_DC) return EH_THROW; } - if (EG(This) && instanceof_function(Z_OBJCE_P(EG(This)), php_http_object_get_class_entry() TSRMLS_CC)) { + 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); } @@ -268,7 +268,7 @@ void php_http_error(long type TSRMLS_DC, long code, const char *format, ...) switch (scope_error_handling(type TSRMLS_CC)) { case EH_THROW: { char *message; - zend_class_entry *ce = php_http_exception_get_class_entry(); + zend_class_entry *ce = php_http_exception_class_entry; /* FIXME wat? */ if (0&& EG(exception_class) && instanceof_function(EG(exception_class), ce TSRMLS_CC)) { diff --git a/php_http_misc.h b/php_http_misc.h index 314fc24..358c75b 100644 --- a/php_http_misc.h +++ b/php_http_misc.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -21,9 +21,6 @@ /* CR LF */ #define PHP_HTTP_CRLF "\r\n" -/* max URL length */ -#define PHP_HTTP_URL_MAXLEN 4096 - /* def URL arg separator */ #define PHP_HTTP_URL_ARGSEP "&" @@ -202,9 +199,6 @@ static inline STATUS php_http_ini_entry(const char *name_str, size_t name_len, c 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 bool (v == SUCCESS) */ -#define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v)) -#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v)) /* return object(values) */ #define RETVAL_OBJECT(o, addref) \ RETVAL_OBJVAL((o)->value.obj, addref) @@ -222,29 +216,6 @@ STATUS php_http_method_call(zval *object, const char *method_str, size_t method_ if (addref && Z_OBJ_HT_P(zv)->add_ref) { \ Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \ } -/* return property */ -#define RETVAL_PROP(CE, n) RETVAL_PROP_EX(CE, getThis(), n) -#define RETURN_PROP(CE, n) RETURN_PROP_EX(CE, getThis(), n) -#define RETVAL_PROP_EX(CE, this, n) \ - { \ - zval *__prop = zend_read_property(CE, this, ZEND_STRL(n), 0 TSRMLS_CC); \ - RETVAL_ZVAL(__prop, 1, 0); \ - } -#define RETURN_PROP_EX(CE, this, n) \ - { \ - zval *__prop = zend_read_property(CE, this, ZEND_STRL(n), 0 TSRMLS_CC); \ - RETURN_ZVAL(__prop, 1, 0); \ - } -#define RETVAL_SPROP(CE, n) \ - { \ - zval *__prop = zend_read_static_property(CE, ZEND_STRL(n), 0 TSRMLS_CC); \ - RETVAL_ZVAL(__prop, 1, 0); \ - } -#define RETURN_SPROP(CE, n) \ - { \ - zval *__prop = zend_read_static_property(CE, ZEND_STRL(n), 0 TSRMLS_CC); \ - RETURN_ZVAL(__prop, 1, 0); \ - } #define Z_OBJ_DELREF(z) \ if (Z_OBJ_HT(z)->del_ref) { \ @@ -271,15 +242,6 @@ STATUS php_http_method_call(zval *object, const char *method_str, size_t method_ Z_OBJ_HT_PP(z)->add_ref(*(z) TSRMLS_CC); \ } -#define PHP_HTTP_BEGIN_ARGS_EX(class, method, ret_ref, req_args) ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 0, ret_ref, req_args) -#define PHP_HTTP_BEGIN_ARGS_AR(class, method, ret_ref, req_args) ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 1, ret_ref, req_args) -#define PHP_HTTP_END_ARGS } -#define PHP_HTTP_EMPTY_ARGS_EX(class, method, ret_ref) PHP_HTTP_BEGIN_ARGS_EX(class, method, ret_ref, 0) PHP_HTTP_END_ARGS -#define PHP_HTTP_ARGS(class, method) args_for_ ##class## _ ##method -#define PHP_HTTP_ARG_VAL(name, pass_ref) ZEND_ARG_INFO(pass_ref, name) -#define PHP_HTTP_ARG_OBJ(class, name, allow_null) ZEND_ARG_OBJ_INFO(0, name, class, allow_null) -#define PHP_HTTP_ARG_ARR(name, allow_null, pass_ref) ZEND_ARG_ARRAY_INFO(pass_ref, name, allow_null) - #define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0} #define PHP_MINIT_CALL(func) PHP_MINIT(func)(INIT_FUNC_ARGS_PASSTHRU) @@ -287,41 +249,6 @@ STATUS php_http_method_call(zval *object, const char *method_str, size_t method_ #define PHP_MSHUTDOWN_CALL(func) PHP_MSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU) #define PHP_RSHUTDOWN_CALL(func) PHP_RSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU) - -#define PHP_HTTP_INI_ENTRY(entry, default, scope, updater, global) \ - STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_php_http_globals, php_http_globals) -#define PHP_HTTP_INI_ENTRY_EX(entry, default, scope, updater, displayer, global) \ - STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_php_http_globals, php_http_globals, displayer) - -#define PHP_HTTP_REGISTER_CLASS(ns, classname, name, parent, flags) \ - { \ - zend_class_entry ce; \ - memset(&ce, 0, sizeof(zend_class_entry)); \ - INIT_NS_CLASS_ENTRY(ce, #ns, #classname, php_ ##name## _method_entry); \ - php_ ##name## _class_entry = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ - php_ ##name## _class_entry->ce_flags |= flags; \ - php_http_register_class(php_ ##name## _get_class_entry); \ - } - -#define PHP_HTTP_REGISTER_INTERFACE(ns, ifacename, name, flags) \ - { \ - zend_class_entry ce; \ - memset(&ce, 0, sizeof(zend_class_entry)); \ - INIT_NS_CLASS_ENTRY(ce, #ns, #ifacename, php_ ##name## _method_entry); \ - php_ ##name## _class_entry = zend_register_internal_interface(&ce TSRMLS_CC); \ - php_ ##name## _class_entry->ce_flags |= flags; \ - php_http_register_class(php_ ##name## _get_class_entry); \ - } - -#define PHP_HTTP_REGISTER_EXCEPTION(classname, cename, parent) \ - { \ - zend_class_entry ce; \ - memset(&ce, 0, sizeof(zend_class_entry)); \ - INIT_NS_CLASS_ENTRY(ce, "http", #classname, NULL); \ - ce.create_object = NULL; \ - cename = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \ - } - /* ARRAYS */ PHP_HTTP_API unsigned php_http_array_list(HashTable *ht TSRMLS_DC, unsigned argc, ...); @@ -436,6 +363,7 @@ typedef enum php_http_error { } php_http_error_t; #endif + /* * Local variables: * tab-width: 4 diff --git a/php_http_negotiate.c b/php_http_negotiate.c index 2352e67..ad2357e 100644 --- a/php_http_negotiate.c +++ b/php_http_negotiate.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_negotiate.h b/php_http_negotiate.h index 95e2fa1..f31226b 100644 --- a/php_http_negotiate.h +++ b/php_http_negotiate.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_object.c b/php_http_object.c index d7f1a0f..4ec54d3 100644 --- a/php_http_object.c +++ b/php_http_object.c @@ -6,14 +6,16 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ #include "php_http_api.h" -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) +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)) { @@ -21,7 +23,10 @@ PHP_HTTP_API STATUS php_http_new(zend_object_value *ov, zend_class_entry *ce, ph return FAILURE; } - *ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC); + ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC); + if (ovp) { + *ovp = ov; + } return SUCCESS; } @@ -37,7 +42,7 @@ PHP_HTTP_API zend_error_handling_t php_http_object_get_error_handling(zval *obje zval_ptr_dtor(&lzeh); return eh; } - zeh = zend_read_static_property(php_http_object_get_class_entry(), ZEND_STRL("defaultErrorHandling"), 0 TSRMLS_CC); + 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); @@ -47,45 +52,6 @@ PHP_HTTP_API zend_error_handling_t php_http_object_get_error_handling(zval *obje return EH_NORMAL; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpObject, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpObject, method, 0) -#define PHP_HTTP_OBJECT_ME(method, visibility) PHP_ME(HttpObject, method, PHP_HTTP_ARGS(HttpObject, method), visibility) - -PHP_HTTP_BEGIN_ARGS(setErrorHandling, 1) - PHP_HTTP_ARG_VAL(eh, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getErrorHandling); - -PHP_HTTP_BEGIN_ARGS(setDefaultErrorHandling, 1) - PHP_HTTP_ARG_VAL(eh, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getDefaultErrorHandling); - -PHP_HTTP_BEGIN_ARGS(triggerError, 3) - PHP_HTTP_ARG_VAL(error_type, 0) - PHP_HTTP_ARG_VAL(error_code, 0) - PHP_HTTP_ARG_VAL(error_message, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_object_class_entry; - -zend_class_entry *php_http_object_get_class_entry(void) -{ - return php_http_object_class_entry; -} - -static zend_function_entry php_http_object_method_entry[] = { - PHP_HTTP_OBJECT_ME(setErrorHandling, ZEND_ACC_PUBLIC) - PHP_HTTP_OBJECT_ME(getErrorHandling, ZEND_ACC_PUBLIC) - PHP_HTTP_OBJECT_ME(setDefaultErrorHandling, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_HTTP_OBJECT_ME(getDefaultErrorHandling, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) - PHP_HTTP_OBJECT_ME(triggerError, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; - zend_object_value php_http_object_new(zend_class_entry *ce TSRMLS_DC) { return php_http_object_new_ex(ce, NULL, NULL TSRMLS_CC); @@ -93,7 +59,6 @@ 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) { - zend_object_value ov; php_http_object_t *o; o = ecalloc(1, sizeof(php_http_object_t)); @@ -104,17 +69,23 @@ zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, ph *ptr = o; } - ov.handle = zend_objects_store_put(o, NULL, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC); - ov.handlers = zend_get_std_object_handlers(); + o->zv.handle = zend_objects_store_put(o, NULL, (zend_objects_free_object_storage_t) zend_objects_free_object_storage, NULL TSRMLS_CC); + o->zv.handlers = zend_get_std_object_handlers(); - return ov; + return o->zv; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getErrorHandling, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpObject, getErrorHandling) { - RETURN_PROP(php_http_object_get_class_entry(), "errorHandling"); + zval *zeh = zend_read_property(php_http_object_class_entry, getThis(), ZEND_STRL("errorHandling"), 0 TSRMLS_CC); + RETURN_ZVAL(zeh, 1, 0); } +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; @@ -124,7 +95,7 @@ PHP_METHOD(HttpObject, setErrorHandling) case EH_NORMAL: case EH_SUPPRESS: case EH_THROW: - zend_update_property_long(php_http_object_get_class_entry(), getThis(), ZEND_STRL("errorHandling"), eh TSRMLS_CC); + zend_update_property_long(php_http_object_class_entry, getThis(), ZEND_STRL("errorHandling"), eh TSRMLS_CC); break; default: @@ -136,11 +107,17 @@ PHP_METHOD(HttpObject, setErrorHandling) RETURN_ZVAL(getThis(), 1, 0); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpObject_getDefaultErrorHandling, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpObject, getDefaultErrorHandling) { - RETURN_SPROP(php_http_object_get_class_entry(), "defaultErrorHandling"); + 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; @@ -150,7 +127,7 @@ PHP_METHOD(HttpObject, setDefaultErrorHandling) case EH_NORMAL: case EH_SUPPRESS: case EH_THROW: - zend_update_static_property_long(php_http_object_get_class_entry(), ZEND_STRL("defaultErrorHandling"), eh TSRMLS_CC); + zend_update_static_property_long(php_http_object_class_entry, ZEND_STRL("defaultErrorHandling"), eh TSRMLS_CC); break; default: @@ -160,6 +137,11 @@ PHP_METHOD(HttpObject, setDefaultErrorHandling) } } +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) { long eh, code; @@ -171,17 +153,33 @@ PHP_METHOD(HttpObject, triggerError) } } +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) { - PHP_HTTP_REGISTER_CLASS(http, Object, http_object, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - php_http_object_get_class_entry()->create_object = php_http_object_new; + 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_get_class_entry(), ZEND_STRL("defaultErrorHandling"), (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC); - zend_declare_property_null(php_http_object_get_class_entry(), ZEND_STRL("errorHandling"), ZEND_ACC_PROTECTED TSRMLS_CC); + 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_get_class_entry(), ZEND_STRL("EH_NORMAL"), EH_NORMAL TSRMLS_CC); - zend_declare_class_constant_long(php_http_object_get_class_entry(), ZEND_STRL("EH_SUPPRESS"), EH_SUPPRESS TSRMLS_CC); - zend_declare_class_constant_long(php_http_object_get_class_entry(), ZEND_STRL("EH_THROW"), EH_THROW 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; } diff --git a/php_http_object.h b/php_http_object.h index 0ebd33c..7c88f20 100644 --- a/php_http_object.h +++ b/php_http_object.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -19,10 +19,10 @@ PHP_HTTP_API STATUS php_http_new(zend_object_value *ov, zend_class_entry *ce, ph typedef struct php_http_object { zend_object zo; + zend_object_value zv; } php_http_object_t; -zend_class_entry *php_http_object_get_class_entry(void); - +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); @@ -30,12 +30,6 @@ zend_object_value php_http_object_new_ex(zend_class_entry *ce, void *nothing, ph PHP_HTTP_API zend_error_handling_t php_http_object_get_error_handling(zval *object TSRMLS_DC); -PHP_METHOD(HttpObject, setErrorHandling); -PHP_METHOD(HttpObject, getErrorHandling); -PHP_METHOD(HttpObject, setDefaultErrorHandling); -PHP_METHOD(HttpObject, getDefaultErrorHandling); -PHP_METHOD(HttpObject, triggerError); - #endif diff --git a/php_http_options.c b/php_http_options.c index bbc10c9..07a5d7b 100644 --- a/php_http_options.c +++ b/php_http_options.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_options.h b/php_http_options.h index 1146f05..479b155 100644 --- a/php_http_options.h +++ b/php_http_options.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_params.c b/php_http_params.c index be627dc..2356dc9 100644 --- a/php_http_params.c +++ b/php_http_params.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -676,87 +676,6 @@ PHP_HTTP_API php_http_buffer_t *php_http_params_to_string(php_http_buffer_t *buf return buf; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpParams, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpParams, method, 0) -#define PHP_HTTP_PARAMS_ME(method, visibility) PHP_ME(HttpParams, method, PHP_HTTP_ARGS(HttpParams, method), visibility) -#define PHP_HTTP_PARAMS_GME(method, visibility) PHP_ME(HttpParams, method, PHP_HTTP_ARGS(HttpParams, __getter), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(params, 0) - PHP_HTTP_ARG_VAL(param_sep, 0) - PHP_HTTP_ARG_VAL(arg_sep, 0) - PHP_HTTP_ARG_VAL(val_sep, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(toArray); -PHP_HTTP_EMPTY_ARGS(toString); - -PHP_HTTP_BEGIN_ARGS(offsetExists, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetUnset, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetGet, 1) - PHP_HTTP_ARG_VAL(name, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetSet, 2) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_params_class_entry; - -zend_class_entry *php_http_params_get_class_entry(void) -{ - return php_http_params_class_entry; -} - -static zend_function_entry php_http_params_method_entry[] = { - PHP_HTTP_PARAMS_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) - - PHP_HTTP_PARAMS_ME(toArray, ZEND_ACC_PUBLIC) - PHP_HTTP_PARAMS_ME(toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpParams, __toString, toString, PHP_HTTP_ARGS(HttpParams, toString), ZEND_ACC_PUBLIC) - - PHP_HTTP_PARAMS_ME(offsetExists, ZEND_ACC_PUBLIC) - PHP_HTTP_PARAMS_ME(offsetUnset, ZEND_ACC_PUBLIC) - PHP_HTTP_PARAMS_ME(offsetSet, ZEND_ACC_PUBLIC) - PHP_HTTP_PARAMS_ME(offsetGet, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; - -PHP_MINIT_FUNCTION(http_params) -{ - PHP_HTTP_REGISTER_CLASS(http, Params, http_params, php_http_object_get_class_entry(), 0); - - 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); - zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_ARG_SEP"), ZEND_STRL(";") TSRMLS_CC); - zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("=") TSRMLS_CC); - zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL("") TSRMLS_CC); - - zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW TSRMLS_CC); - zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC); - zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED TSRMLS_CC); - zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION TSRMLS_CC); - zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY TSRMLS_CC); - - zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC TSRMLS_CC); - - return SUCCESS; -} - PHP_HTTP_API php_http_params_token_t **php_http_params_separator_init(zval *zv TSRMLS_DC) { zval **sep; @@ -800,9 +719,16 @@ PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separ } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams___construct, 0, 0, 0) + ZEND_ARG_INFO(0, params) + 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(HttpParams, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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; @@ -864,14 +790,19 @@ PHP_METHOD(HttpParams, __construct) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toArray, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, toArray) { - if (SUCCESS != zend_parse_parameters_none()) { - RETURN_FALSE; + if (SUCCESS == zend_parse_parameters_none()) { + zval *zparams = zend_read_property(php_http_params_class_entry, getThis(), ZEND_STRL("params"), 0 TSRMLS_CC); + RETURN_ZVAL(zparams, 1, 0); } - RETURN_PROP(php_http_params_class_entry, "params"); + RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_toString, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, toString) { zval **tmp, *zparams, *zpsep, *zasep, *zvsep, *zflags; @@ -911,6 +842,9 @@ PHP_METHOD(HttpParams, toString) RETVAL_PHP_HTTP_BUFFER_VAL(&buf); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetExists, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, offsetExists) { char *name_str; @@ -928,6 +862,9 @@ PHP_METHOD(HttpParams, offsetExists) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, offsetGet) { char *name_str; @@ -944,7 +881,9 @@ PHP_METHOD(HttpParams, offsetGet) } } - +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetUnset, 0, 0, 1) + ZEND_ARG_INFO(0, name) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, offsetUnset) { char *name_str; @@ -960,6 +899,10 @@ PHP_METHOD(HttpParams, offsetUnset) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpParams_offsetSet, 0, 0, 2) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpParams, offsetSet) { zval *nvalue; @@ -1010,6 +953,51 @@ PHP_METHOD(HttpParams, offsetSet) } } +static zend_function_entry php_http_params_methods[] = { + PHP_ME(HttpParams, __construct, ai_HttpParams___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) + + PHP_ME(HttpParams, toArray, ai_HttpParams_toArray, ZEND_ACC_PUBLIC) + PHP_ME(HttpParams, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpParams, __toString, toString, ai_HttpParams_toString, ZEND_ACC_PUBLIC) + + PHP_ME(HttpParams, offsetExists, ai_HttpParams_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(HttpParams, offsetUnset, ai_HttpParams_offsetUnset, ZEND_ACC_PUBLIC) + PHP_ME(HttpParams, offsetSet, ai_HttpParams_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(HttpParams, offsetGet, ai_HttpParams_offsetGet, ZEND_ACC_PUBLIC) + + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_params_class_entry; + +PHP_MINIT_FUNCTION(http_params) +{ + 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); + 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); + zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_ARG_SEP"), ZEND_STRL(";") TSRMLS_CC); + zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("DEF_VAL_SEP"), ZEND_STRL("=") TSRMLS_CC); + zend_declare_class_constant_stringl(php_http_params_class_entry, ZEND_STRL("COOKIE_PARAM_SEP"), ZEND_STRL("") TSRMLS_CC); + + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_RAW"), PHP_HTTP_PARAMS_RAW TSRMLS_CC); + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DEFAULT"), PHP_HTTP_PARAMS_DEFAULT TSRMLS_CC); + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_URLENCODED"), PHP_HTTP_PARAMS_URLENCODED TSRMLS_CC); + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_DIMENSION"), PHP_HTTP_PARAMS_DIMENSION TSRMLS_CC); + zend_declare_class_constant_long(php_http_params_class_entry, ZEND_STRL("PARSE_QUERY"), PHP_HTTP_PARAMS_QUERY TSRMLS_CC); + + zend_declare_property_null(php_http_params_class_entry, ZEND_STRL("params"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("param_sep"), ZEND_STRL(","), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("arg_sep"), ZEND_STRL(";"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_stringl(php_http_params_class_entry, ZEND_STRL("val_sep"), ZEND_STRL("="), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_long(php_http_params_class_entry, ZEND_STRL("flags"), PHP_HTTP_PARAMS_DEFAULT, ZEND_ACC_PUBLIC TSRMLS_CC); + + return SUCCESS; +} + /* * Local variables: * tab-width: 4 diff --git a/php_http_params.h b/php_http_params.h index 716cba8..a9ac564 100644 --- a/php_http_params.h +++ b/php_http_params.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -22,7 +22,7 @@ typedef struct php_http_params_token { #define PHP_HTTP_PARAMS_DEFAULT 0x01 #define PHP_HTTP_PARAMS_URLENCODED 0x04 #define PHP_HTTP_PARAMS_DIMENSION 0x08 -#define PHP_HTTP_PARAMS_QUERY (PHP_HTTP_PARAMS_URLENCODED|PHP_HTTP_PARAMS_DIMENSION) +#define PHP_HTTP_PARAMS_QUERY (PHP_HTTP_PARAMS_URLENCODED|PHP_HTTP_PARAMS_DIMENSION) typedef struct php_http_params_opts { php_http_params_token_t input; @@ -42,21 +42,13 @@ PHP_HTTP_API void php_http_params_separator_free(php_http_params_token_t **separ typedef php_http_object_t php_http_params_object_t; -zend_class_entry *php_http_params_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_params_class_entry; PHP_MINIT_FUNCTION(http_params); #define php_http_params_object_new php_http_object_new #define php_http_params_object_new_ex php_http_object_new_ex -PHP_METHOD(HttpParams, __construct); -PHP_METHOD(HttpParams, toString); -PHP_METHOD(HttpParams, toArray); -PHP_METHOD(HttpParams, offsetExists); -PHP_METHOD(HttpParams, offsetUnset); -PHP_METHOD(HttpParams, offsetSet); -PHP_METHOD(HttpParams, offsetGet); - #endif /* diff --git a/php_http_querystring.c b/php_http_querystring.c index 2c6ca28..3dde39b 100644 --- a/php_http_querystring.c +++ b/php_http_querystring.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -20,7 +20,6 @@ # include #endif - #define QS_MERGE 1 static inline void php_http_querystring_set(zval *instance, zval *params, int flags TSRMLS_DC) @@ -28,20 +27,20 @@ static inline void php_http_querystring_set(zval *instance, zval *params, int fl zval *qa; if (flags & QS_MERGE) { - qa = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_querystring_get_class_entry(), instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC)); + qa = php_http_zsep(1, IS_ARRAY, zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC)); } else { MAKE_STD_ZVAL(qa); array_init(qa); } php_http_querystring_update(qa, params, NULL TSRMLS_CC); - zend_update_property(php_http_querystring_get_class_entry(), instance, ZEND_STRL("queryArray"), qa TSRMLS_CC); + zend_update_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), qa TSRMLS_CC); zval_ptr_dtor(&qa); } static inline void php_http_querystring_str(zval *instance, zval *return_value TSRMLS_DC) { - zval *qa = zend_read_property(php_http_querystring_get_class_entry(), instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC); + zval *qa = zend_read_property(php_http_querystring_class_entry, instance, ZEND_STRL("queryArray"), 0 TSRMLS_CC); if (Z_TYPE_P(qa) == IS_ARRAY) { php_http_querystring_update(qa, NULL, return_value TSRMLS_CC); @@ -52,7 +51,7 @@ static inline void php_http_querystring_str(zval *instance, zval *return_value T static inline void php_http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC) { - zval **arrval, *qarray = zend_read_property(php_http_querystring_get_class_entry(), getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC); + zval **arrval, *qarray = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC); if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_symtable_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) { if (type) { @@ -226,8 +225,8 @@ PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval ZVAL_NULL(&zv); /* squeeze the hash out of the zval */ - if (Z_TYPE_P(params) == IS_OBJECT && instanceof_function(Z_OBJCE_P(params), php_http_querystring_get_class_entry() TSRMLS_CC)) { - zv_ptr = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_get_class_entry(), params, ZEND_STRL("queryArray"), 0 TSRMLS_CC)); + if (Z_TYPE_P(params) == IS_OBJECT && instanceof_function(Z_OBJCE_P(params), php_http_querystring_class_entry TSRMLS_CC)) { + zv_ptr = php_http_ztyp(IS_ARRAY, zend_read_property(php_http_querystring_class_entry, params, ZEND_STRL("queryArray"), 0 TSRMLS_CC)); ptr = Z_ARRVAL_P(zv_ptr); } else if (Z_TYPE_P(params) == IS_OBJECT || Z_TYPE_P(params) == IS_ARRAY) { ptr = HASH_OF(params); @@ -320,154 +319,29 @@ PHP_HTTP_API STATUS php_http_querystring_update(zval *qarray, zval *params, zval return SUCCESS; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpQueryString, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpQueryString, method, 0) -#define PHP_HTTP_QUERYSTRING_ME(method, visibility) PHP_ME(HttpQueryString, method, PHP_HTTP_ARGS(HttpQueryString, method), visibility) -#define PHP_HTTP_QUERYSTRING_GME(method, visibility) PHP_ME(HttpQueryString, method, PHP_HTTP_ARGS(HttpQueryString, __getter), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(params, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getGlobalInstance); - -PHP_HTTP_EMPTY_ARGS(toArray); -PHP_HTTP_EMPTY_ARGS(toString); - -PHP_HTTP_BEGIN_ARGS(get, 0) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(type, 0) - PHP_HTTP_ARG_VAL(defval, 0) - PHP_HTTP_ARG_VAL(delete, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(set, 1) - PHP_HTTP_ARG_VAL(params, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(mod, 0) - PHP_HTTP_ARG_VAL(params, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(__getter, 1) - PHP_HTTP_ARG_VAL(name, 0) - PHP_HTTP_ARG_VAL(defval, 0) - PHP_HTTP_ARG_VAL(delete, 0) -PHP_HTTP_END_ARGS; - -#ifdef PHP_HTTP_HAVE_ICONV -PHP_HTTP_BEGIN_ARGS(xlate, 2) - PHP_HTTP_ARG_VAL(from_encoding, 0) - PHP_HTTP_ARG_VAL(to_encoding, 0) -PHP_HTTP_END_ARGS; -#endif - -PHP_HTTP_EMPTY_ARGS(serialize); -PHP_HTTP_BEGIN_ARGS(unserialize, 1) - PHP_HTTP_ARG_VAL(serialized, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetGet, 1) - PHP_HTTP_ARG_VAL(offset, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetSet, 2) - PHP_HTTP_ARG_VAL(offset, 0) - PHP_HTTP_ARG_VAL(value, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetExists, 1) - PHP_HTTP_ARG_VAL(offset, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_BEGIN_ARGS(offsetUnset, 1) - PHP_HTTP_ARG_VAL(offset, 0) -PHP_HTTP_END_ARGS; - -PHP_HTTP_EMPTY_ARGS(getIterator); - -static zend_class_entry *php_http_querystring_class_entry; - -zend_class_entry *php_http_querystring_get_class_entry(void) -{ - return php_http_querystring_class_entry; -} - -static zend_function_entry php_http_querystring_method_entry[] = { - PHP_HTTP_QUERYSTRING_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) - - PHP_HTTP_QUERYSTRING_ME(toArray, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpQueryString, __toString, toString, PHP_HTTP_ARGS(HttpQueryString, toString), ZEND_ACC_PUBLIC) - - PHP_HTTP_QUERYSTRING_ME(get, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(set, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(mod, ZEND_ACC_PUBLIC) - - PHP_HTTP_QUERYSTRING_GME(getBool, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_GME(getInt, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_GME(getFloat, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_GME(getString, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_GME(getArray, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_GME(getObject, ZEND_ACC_PUBLIC) - - PHP_HTTP_QUERYSTRING_ME(getIterator, ZEND_ACC_PUBLIC) - - PHP_HTTP_QUERYSTRING_ME(getGlobalInstance, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) -#ifdef PHP_HTTP_HAVE_ICONV - PHP_HTTP_QUERYSTRING_ME(xlate, ZEND_ACC_PUBLIC) -#endif - - /* Implements Serializable */ - PHP_HTTP_QUERYSTRING_ME(serialize, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(unserialize, ZEND_ACC_PUBLIC) - - /* Implements ArrayAccess */ - PHP_HTTP_QUERYSTRING_ME(offsetGet, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(offsetSet, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(offsetExists, ZEND_ACC_PUBLIC) - PHP_HTTP_QUERYSTRING_ME(offsetUnset, ZEND_ACC_PUBLIC) - - EMPTY_FUNCTION_ENTRY -}; - -PHP_MINIT_FUNCTION(http_querystring) -{ - PHP_HTTP_REGISTER_CLASS(http, QueryString, http_querystring, php_http_object_get_class_entry(), 0); - - 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); - zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("queryArray"), ZEND_ACC_PRIVATE TSRMLS_CC); - - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_BOOL"), PHP_HTTP_QUERYSTRING_TYPE_BOOL TSRMLS_CC); - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_INT"), PHP_HTTP_QUERYSTRING_TYPE_INT TSRMLS_CC); - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_FLOAT"), PHP_HTTP_QUERYSTRING_TYPE_FLOAT TSRMLS_CC); - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_STRING"), PHP_HTTP_QUERYSTRING_TYPE_STRING TSRMLS_CC); - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_ARRAY"), PHP_HTTP_QUERYSTRING_TYPE_ARRAY TSRMLS_CC); - zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_OBJECT"), PHP_HTTP_QUERYSTRING_TYPE_OBJECT TSRMLS_CC); - - return SUCCESS; -} - +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString___construct, 0, 0, 0) + ZEND_ARG_INFO(0, params) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, __construct) { zval *params = NULL; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + 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(); } +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_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { if (SUCCESS == zend_parse_parameters_none()) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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); if (Z_TYPE_P(instance) != IS_OBJECT) { @@ -497,11 +371,13 @@ PHP_METHOD(HttpQueryString, getGlobalInstance) } end_error_handling(); } +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_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { if (SUCCESS == zend_parse_parameters_none()) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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); @@ -514,6 +390,8 @@ PHP_METHOD(HttpQueryString, getIterator) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_toString, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, toString) { if (SUCCESS != zend_parse_parameters_none()) { @@ -522,14 +400,23 @@ PHP_METHOD(HttpQueryString, toString) php_http_querystring_str(getThis(), return_value TSRMLS_CC); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_toArray, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, toArray) { if (SUCCESS == zend_parse_parameters_none()) { - RETURN_PROP(php_http_querystring_class_entry, "queryArray"); + zval *zqa = zend_read_property(php_http_querystring_class_entry, getThis(), ZEND_STRL("queryArray"), 0 TSRMLS_CC); + RETURN_ZVAL(zqa, 1, 0); } RETURN_FALSE; } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_get, 0, 0, 0) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, type) + ZEND_ARG_INFO(0, defval) + ZEND_ARG_INFO(0, delete) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, get) { char *name_str = NULL; @@ -571,6 +458,9 @@ PHP_METHOD(HttpQueryString, get) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_set, 0, 0, 1) + ZEND_ARG_INFO(0, params) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, set) { zval *params; @@ -583,13 +473,16 @@ PHP_METHOD(HttpQueryString, set) RETVAL_ZVAL(getThis(), 1, 0); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_mod, 0, 0, 0) + ZEND_ARG_INFO(0, params) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, mod) { zval *params; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + 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(); @@ -597,6 +490,11 @@ PHP_METHOD(HttpQueryString, mod) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString___getter, 0, 0, 1) + ZEND_ARG_INFO(0, name) + ZEND_ARG_INFO(0, defval) + ZEND_ARG_INFO(0, delete) +ZEND_END_ARG_INFO(); #define PHP_HTTP_QUERYSTRING_GETTER(method, TYPE) \ PHP_METHOD(HttpQueryString, method) \ { \ @@ -616,14 +514,18 @@ PHP_HTTP_QUERYSTRING_GETTER(getArray, IS_ARRAY); PHP_HTTP_QUERYSTRING_GETTER(getObject, IS_OBJECT); #ifdef PHP_HTTP_HAVE_ICONV +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_xlate, 0, 0, 2) + ZEND_ARG_INFO(0, from_encoding) + ZEND_ARG_INFO(0, to_encoding) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, xlate) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + 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); @@ -643,6 +545,8 @@ PHP_METHOD(HttpQueryString, xlate) } #endif /* HAVE_ICONV */ +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_serialize, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, serialize) { if (SUCCESS != zend_parse_parameters_none()) { @@ -651,13 +555,16 @@ PHP_METHOD(HttpQueryString, serialize) php_http_querystring_str(getThis(), return_value TSRMLS_CC); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_unserialize, 0, 0, 1) + ZEND_ARG_INFO(0, serialized) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, unserialize) { zval *serialized; - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + 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 { @@ -668,6 +575,9 @@ PHP_METHOD(HttpQueryString, unserialize) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetGet, 0, 0, 1) + ZEND_ARG_INFO(0, offset) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, offsetGet) { char *offset_str; @@ -685,6 +595,10 @@ PHP_METHOD(HttpQueryString, offsetGet) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetSet, 0, 0, 2) + ZEND_ARG_INFO(0, offset) + ZEND_ARG_INFO(0, value) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, offsetSet) { char *offset_str; @@ -703,6 +617,9 @@ PHP_METHOD(HttpQueryString, offsetSet) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetExists, 0, 0, 1) + ZEND_ARG_INFO(0, offset) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, offsetExists) { char *offset_str; @@ -722,6 +639,9 @@ PHP_METHOD(HttpQueryString, offsetExists) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpQueryString_offsetUnset, 0, 0, 1) + ZEND_ARG_INFO(0, offset) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpQueryString, offsetUnset) { char *offset_str; @@ -738,6 +658,66 @@ PHP_METHOD(HttpQueryString, offsetUnset) } } +zend_class_entry *php_http_querystring_class_entry; + +static zend_function_entry php_http_querystring_methods[] = { + PHP_ME(HttpQueryString, __construct, ai_HttpQueryString___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL) + + PHP_ME(HttpQueryString, toArray, ai_HttpQueryString_toArray, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, toString, ai_HttpQueryString_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpQueryString, __toString, toString, ai_HttpQueryString_toString, ZEND_ACC_PUBLIC) + + PHP_ME(HttpQueryString, get, ai_HttpQueryString_get, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, set, ai_HttpQueryString_set, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, mod, ai_HttpQueryString_mod, ZEND_ACC_PUBLIC) + + PHP_ME(HttpQueryString, getBool, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, getInt, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, getFloat, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, getString, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, getArray, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, getObject, ai_HttpQueryString___getter, ZEND_ACC_PUBLIC) + + PHP_ME(HttpQueryString, getIterator, ai_HttpQueryString_getIterator, ZEND_ACC_PUBLIC) + + PHP_ME(HttpQueryString, getGlobalInstance, ai_HttpQueryString_getGlobalInstance, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) +#ifdef PHP_HTTP_HAVE_ICONV + PHP_ME(HttpQueryString, xlate, ai_HttpQueryString_xlate, ZEND_ACC_PUBLIC) +#endif + + /* Implements Serializable */ + PHP_ME(HttpQueryString, serialize, ai_HttpQueryString_serialize, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, unserialize, ai_HttpQueryString_unserialize, ZEND_ACC_PUBLIC) + + /* Implements ArrayAccess */ + PHP_ME(HttpQueryString, offsetGet, ai_HttpQueryString_offsetGet, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, offsetSet, ai_HttpQueryString_offsetSet, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, offsetExists, ai_HttpQueryString_offsetExists, ZEND_ACC_PUBLIC) + PHP_ME(HttpQueryString, offsetUnset, ai_HttpQueryString_offsetUnset, ZEND_ACC_PUBLIC) + + EMPTY_FUNCTION_ENTRY +}; + +PHP_MINIT_FUNCTION(http_querystring) +{ + 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); + 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); + zend_declare_property_null(php_http_querystring_class_entry, ZEND_STRL("queryArray"), ZEND_ACC_PRIVATE TSRMLS_CC); + + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_BOOL"), PHP_HTTP_QUERYSTRING_TYPE_BOOL TSRMLS_CC); + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_INT"), PHP_HTTP_QUERYSTRING_TYPE_INT TSRMLS_CC); + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_FLOAT"), PHP_HTTP_QUERYSTRING_TYPE_FLOAT TSRMLS_CC); + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_STRING"), PHP_HTTP_QUERYSTRING_TYPE_STRING TSRMLS_CC); + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_ARRAY"), PHP_HTTP_QUERYSTRING_TYPE_ARRAY TSRMLS_CC); + zend_declare_class_constant_long(php_http_querystring_class_entry, ZEND_STRL("TYPE_OBJECT"), PHP_HTTP_QUERYSTRING_TYPE_OBJECT TSRMLS_CC); + + return SUCCESS; +} /* * Local variables: diff --git a/php_http_querystring.h b/php_http_querystring.h index e34ccc0..6418f83 100644 --- a/php_http_querystring.h +++ b/php_http_querystring.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -28,39 +28,13 @@ typedef php_http_object_t php_http_querystring_object_t; #define PHP_HTTP_QUERYSTRING_TYPE_ARRAY IS_ARRAY #define PHP_HTTP_QUERYSTRING_TYPE_OBJECT IS_OBJECT -zend_class_entry *php_http_querystring_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_querystring_class_entry; PHP_MINIT_FUNCTION(http_querystring); #define php_http_querystring_object_new php_http_object_new #define php_http_querystring_object_new_ex php_http_object_new_ex -PHP_METHOD(HttpQueryString, getGlobalInstance); -PHP_METHOD(HttpQueryString, __construct); -PHP_METHOD(HttpQueryString, getIterator); -PHP_METHOD(HttpQueryString, toString); -PHP_METHOD(HttpQueryString, toArray); -PHP_METHOD(HttpQueryString, get); -PHP_METHOD(HttpQueryString, set); -PHP_METHOD(HttpQueryString, mod); -PHP_METHOD(HttpQueryString, getBool); -PHP_METHOD(HttpQueryString, getInt); -PHP_METHOD(HttpQueryString, getFloat); -PHP_METHOD(HttpQueryString, getString); -PHP_METHOD(HttpQueryString, getArray); -PHP_METHOD(HttpQueryString, getObject); -#ifdef PHP_HTTP_HAVE_ICONV -PHP_METHOD(HttpQueryString, xlate); -#endif /* PHP_HTTP_HAVE_ICONV */ -PHP_METHOD(HttpQueryString, factory); -PHP_METHOD(HttpQueryString, singleton); -PHP_METHOD(HttpQueryString, serialize); -PHP_METHOD(HttpQueryString, unserialize); -PHP_METHOD(HttpQueryString, offsetGet); -PHP_METHOD(HttpQueryString, offsetSet); -PHP_METHOD(HttpQueryString, offsetExists); -PHP_METHOD(HttpQueryString, offsetUnset); - #endif /* PHP_HTTP_QUERYSTRING_H */ /* diff --git a/php_http_strlist.c b/php_http_strlist.c index 3a52f3b..fa1fd01 100644 --- a/php_http_strlist.c +++ b/php_http_strlist.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_strlist.h b/php_http_strlist.h index 35bdd9f..319113f 100644 --- a/php_http_strlist.h +++ b/php_http_strlist.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_url.c b/php_http_url.c index aeee9e8..d95eb5a 100644 --- a/php_http_url.c +++ b/php_http_url.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -42,13 +42,98 @@ static inline char *localhostname(void) return estrndup("localhost", lenof("localhost")); } +static inline unsigned port(const char *scheme) +{ + unsigned port = 80; + +#if defined(ZTS) && defined(HAVE_GETSERVBYPORT_R) + int rc; + size_t len = 0xff; + char *buf = NULL; + struct servent *se_res = NULL, se_buf = {0}; + + do { + buf = erealloc(buf, len); + rc = getservbyname_r(scheme, "tcp", &se_buf, buf, len, &se_res); + len *= 2; + } while (rc == ERANGE && len <= 0xfff); + + if (!rc) { + port = ntohs(se_res->s_port); + } + + efree(buf); +#elif !defined(ZTS) && defined(HAVE_GETSERVBYPORT) + struct servent *se; + + if ((se = getservbyname(scheme, "tcp")) && se->s_port) { + port = ntohs(se->s_port); + } +#endif + + return port; +} +static inline char *scheme(unsigned port) +{ + char *scheme; +#if defined(ZTS) && defined(HAVE_GETSERVBYPORT_R) + int rc; + size_t len = 0xff; + char *buf = NULL; + struct servent *se_res = NULL, se_buf = {0}; +#elif !defined(ZTS) && defined(HAVE_GETSERVBYPORT) + struct servent *se; +#endif + + switch (port) { + case 443: + scheme = estrndup("https", lenof("https")); + break; + +#if defined(ZTS) && !defined(HAVE_GETSERVBYPORT_R) + default: +#elif !defined(ZTS) && !defined(HAVE_GETSERVBYPORT) + default: +#endif + case 80: + case 0: + scheme = estrndup("http", lenof("http")); + break; + +#if defined(ZTS) && defined(HAVE_GETSERVBYPORT_R) + default: + do { + buf = erealloc(buf, len); + rc = getservbyport_r(htons(port), "tcp", &se_buf, buf, len, &se_res); + len *= 2; + } while (rc == ERANGE && len <= 0xfff); + + if (!rc && se_res) { + scheme = estrdup(se_res->s_name); + } else { + scheme = estrndup("http", lenof("http")); + } + + efree(buf); + break; + +#elif !defined(ZTS) && defined(HAVE_GETSERVBYPORT) + default: + if ((se = getservbyport(htons(port), "tcp")) && se->s_name) { + scheme = estrdup(se->s_name); + } else { + scheme = estrndup("http", lenof("http")); + } + break; +#endif + } + return scheme; +} + static php_url *php_http_url_from_env(php_url *url TSRMLS_DC) { zval *https, *zhost, *zport; long port; -#ifdef HAVE_GETSERVBYPORT - struct servent *se; -#endif if (!url) { url = ecalloc(1, sizeof(*url)); @@ -64,28 +149,8 @@ static php_url *php_http_url_from_env(php_url *url TSRMLS_DC) https = php_http_env_get_server_var(ZEND_STRL("HTTPS"), 1 TSRMLS_CC); if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) { url->scheme = estrndup("https", lenof("https")); - } else switch (url->port) { - case 443: - url->scheme = estrndup("https", lenof("https")); - break; - -#ifndef HAVE_GETSERVBYPORT - default: -#endif - case 80: - case 0: - url->scheme = estrndup("http", lenof("http")); - break; - -#ifdef HAVE_GETSERVBYPORT - default: - if ((se = getservbyport(htons(url->port), "tcp")) && se->s_name) { - url->scheme = estrdup(se->s_name); - } else { - url->scheme = estrndup("http", lenof("http")); - } - break; -#endif + } else { + url->scheme = scheme(url->port); } /* host */ @@ -121,9 +186,6 @@ static php_url *php_http_url_from_env(php_url *url TSRMLS_DC) 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) { php_url *url, *tmp_url = NULL; -#ifdef HAVE_GETSERVBYNAME - struct servent *se; -#endif /* set from env if requested */ if (flags & PHP_HTTP_URL_FROM_ENV) { @@ -277,10 +339,7 @@ PHP_HTTP_API void php_http_url(int flags, const php_url *old_url, const php_url if (url->port) { if ( ((url->port == 80) && !strcmp(url->scheme, "http")) || ((url->port ==443) && !strcmp(url->scheme, "https")) -#ifdef HAVE_GETSERVBYNAME - || ((se = getservbyname(url->scheme, "tcp")) && se->s_port && - (url->port == ntohs(se->s_port))) -#endif + || ( url->port == port(url->scheme)) ) { url->port = 0; } @@ -329,47 +388,19 @@ PHP_HTTP_API STATUS php_http_url_encode_hash_ex(HashTable *hash, php_http_buffer return SUCCESS; } -#define PHP_HTTP_BEGIN_ARGS(method, req_args) PHP_HTTP_BEGIN_ARGS_EX(HttpUrl, method, 0, req_args) -#define PHP_HTTP_EMPTY_ARGS(method) PHP_HTTP_EMPTY_ARGS_EX(HttpUrl, method, 0) -#define PHP_HTTP_URL_ME(method, visibility) PHP_ME(HttpUrl, method, PHP_HTTP_ARGS(HttpUrl, method), visibility) - -PHP_HTTP_BEGIN_ARGS(__construct, 0) - PHP_HTTP_ARG_VAL(old_url, 0) - PHP_HTTP_ARG_VAL(new_url, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; -PHP_HTTP_EMPTY_ARGS(toString); -PHP_HTTP_EMPTY_ARGS(toArray); - -PHP_HTTP_BEGIN_ARGS(mod, 1) - PHP_HTTP_ARG_VAL(more_url_parts, 0) - PHP_HTTP_ARG_VAL(flags, 0) -PHP_HTTP_END_ARGS; - -static zend_class_entry *php_http_url_class_entry; - -zend_class_entry *php_http_url_get_class_entry(void) -{ - return php_http_url_class_entry; -} - -static zend_function_entry php_http_url_method_entry[] = { - PHP_HTTP_URL_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) - PHP_HTTP_URL_ME(mod, ZEND_ACC_PUBLIC) - PHP_HTTP_URL_ME(toString, ZEND_ACC_PUBLIC) - ZEND_MALIAS(HttpUrl, __toString, toString, PHP_HTTP_ARGS(HttpUrl, toString), ZEND_ACC_PUBLIC) - PHP_HTTP_URL_ME(toArray, ZEND_ACC_PUBLIC) - EMPTY_FUNCTION_ENTRY -}; - +ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl___construct, 0, 0, 0) + ZEND_ARG_INFO(0, old_url) + ZEND_ARG_INFO(0, new_url) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpUrl, __construct) { - with_error_handling(EH_THROW, php_http_exception_get_class_entry()) { + 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_get_class_entry()) { + with_error_handling(EH_THROW, php_http_exception_class_entry) { php_url *res_purl, *new_purl = NULL, *old_purl = NULL; if (new_url) { @@ -427,6 +458,10 @@ PHP_METHOD(HttpUrl, __construct) } end_error_handling(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_mod, 0, 0, 1) + ZEND_ARG_INFO(0, more_url_parts) + ZEND_ARG_INFO(0, flags) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpUrl, mod) { zval *new_url = NULL; @@ -471,6 +506,8 @@ PHP_METHOD(HttpUrl, mod) } } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toString, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpUrl, toString) { if (SUCCESS == zend_parse_parameters_none()) { @@ -488,6 +525,8 @@ PHP_METHOD(HttpUrl, toString) RETURN_EMPTY_STRING(); } +ZEND_BEGIN_ARG_INFO_EX(ai_HttpUrl_toArray, 0, 0, 0) +ZEND_END_ARG_INFO(); PHP_METHOD(HttpUrl, toArray) { if (SUCCESS != zend_parse_parameters_none()) { @@ -497,9 +536,23 @@ PHP_METHOD(HttpUrl, toArray) array_copy(HASH_OF(getThis()), HASH_OF(return_value)); } +static zend_function_entry php_http_url_methods[] = { + PHP_ME(HttpUrl, __construct, ai_HttpUrl___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_ME(HttpUrl, mod, ai_HttpUrl_mod, ZEND_ACC_PUBLIC) + PHP_ME(HttpUrl, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC) + ZEND_MALIAS(HttpUrl, __toString, toString, ai_HttpUrl_toString, ZEND_ACC_PUBLIC) + PHP_ME(HttpUrl, toArray, ai_HttpUrl_toArray, ZEND_ACC_PUBLIC) + EMPTY_FUNCTION_ENTRY +}; + +zend_class_entry *php_http_url_class_entry; + PHP_MINIT_FUNCTION(http_url) { - PHP_HTTP_REGISTER_CLASS(http, Url, http_url, php_http_object_get_class_entry(), 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); 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); diff --git a/php_http_url.h b/php_http_url.h index 30f7780..938cf07 100644 --- a/php_http_url.h +++ b/php_http_url.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ @@ -211,18 +211,12 @@ static inline HashTable *php_http_url_to_struct(php_url *url, zval *strct TSRMLS return Z_ARRVAL(arr); } -zend_class_entry *php_http_url_get_class_entry(void); +PHP_HTTP_API zend_class_entry *php_http_url_class_entry; +PHP_MINIT_FUNCTION(http_url); #define php_http_url_object_new php_http_object_new #define php_http_url_object_new_ex php_http_object_new_ex -PHP_METHOD(HttpUrl, __construct); -PHP_METHOD(HttpUrl, mod); -PHP_METHOD(HttpUrl, toString); -PHP_METHOD(HttpUrl, toArray); - -PHP_MINIT_FUNCTION(http_url); - #endif /* diff --git a/php_http_version.c b/php_http_version.c index 41c8499..45f7a30 100644 --- a/php_http_version.c +++ b/php_http_version.c @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/php_http_version.h b/php_http_version.h index cfd3c99..8053646 100644 --- a/php_http_version.h +++ b/php_http_version.h @@ -6,7 +6,7 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2011, Michael Wallner | + | Copyright (c) 2004-2013, Michael Wallner | +--------------------------------------------------------------------+ */ diff --git a/tests/clientresponse002.phpt b/tests/clientresponse002.phpt index 6cc3c3a..3a0c50a 100644 --- a/tests/clientresponse002.phpt +++ b/tests/clientresponse002.phpt @@ -24,7 +24,7 @@ Test \["cookies"\]\=\> array\(1\) \{ \["temp"\]\=\> - string\(13\) "\d+\.\d+" + string\(1[23]\) "\d+\.\d+" \} \["extras"\]\=\> array\(0\) \{ @@ -44,7 +44,7 @@ array\(7\) \{ \["cookies"\]\=\> array\(1\) \{ \["perm"\]\=\> - string\(13\) "\d+\.\d+" + string\(1[23]\) "\d+\.\d+" \} \["extras"\]\=\> array\(0\) \{ -- 2.30.2