From 2a0a84763479e6eebd30f685e5f64afd7e7cb3bc Mon Sep 17 00:00:00 2001 From: advect Date: Wed, 29 Sep 2010 08:47:06 +0900 Subject: php: update 0.3.0 --- php/msgpack.c | 139 +++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 90 insertions(+), 49 deletions(-) (limited to 'php/msgpack.c') diff --git a/php/msgpack.c b/php/msgpack.c index 62fb68d..5d4f926 100644 --- a/php/msgpack.c +++ b/php/msgpack.c @@ -15,6 +15,7 @@ #include "msgpack_pack.h" #include "msgpack_unpack.h" #include "msgpack_class.h" +#include "msgpack/version.h" static ZEND_FUNCTION(msgpack_serialize); static ZEND_FUNCTION(msgpack_unserialize); @@ -27,20 +28,46 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_msgpack_unserialize, 0, 0, 1) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO() +PHP_INI_BEGIN() +STD_PHP_INI_BOOLEAN( + "msgpack.error_display", "1", PHP_INI_ALL, OnUpdateBool, + error_display, zend_msgpack_globals, msgpack_globals) +STD_PHP_INI_BOOLEAN( + "msgpack.php_only", "1", PHP_INI_ALL, OnUpdateBool, + php_only, zend_msgpack_globals, msgpack_globals) +PHP_INI_END() + PS_SERIALIZER_FUNCS(msgpack); static const zend_function_entry msgpack_functions[] = { ZEND_FE(msgpack_serialize, arginfo_msgpack_serialize) ZEND_FE(msgpack_unserialize, arginfo_msgpack_unserialize) ZEND_FALIAS(msgpack_pack, msgpack_serialize, arginfo_msgpack_serialize) - ZEND_FALIAS(msgpack_unpack, msgpack_unserialize, - arginfo_msgpack_unserialize) + ZEND_FALIAS(msgpack_unpack, msgpack_unserialize, arginfo_msgpack_unserialize) {NULL, NULL, NULL} }; +static void msgpack_init_globals(zend_msgpack_globals *msgpack_globals) +{ + TSRMLS_FETCH(); + + if (PG(display_errors)) + { + msgpack_globals->error_display = 1; + } + else + { + msgpack_globals->error_display = 0; + } + + msgpack_globals->php_only = 1; +} + static ZEND_MINIT_FUNCTION(msgpack) { - MSGPACK_G(error_display) = 1; + ZEND_INIT_MODULE_GLOBALS(msgpack, msgpack_init_globals, NULL); + + REGISTER_INI_ENTRIES(); #if HAVE_PHP_SESSION php_session_register_serializer("msgpack", @@ -48,7 +75,14 @@ static ZEND_MINIT_FUNCTION(msgpack) PS_SERIALIZER_DECODE_NAME(msgpack)); #endif - msgpack_init_class(TSRMLS_CC); + msgpack_init_class(); + + return SUCCESS; +} + +static ZEND_MSHUTDOWN_FUNCTION(msgpack) +{ + UNREGISTER_INI_ENTRIES(); return SUCCESS; } @@ -56,12 +90,15 @@ static ZEND_MINIT_FUNCTION(msgpack) static ZEND_MINFO_FUNCTION(msgpack) { php_info_print_table_start(); - php_info_print_table_row(2, "msgpack support", "enabled"); - php_info_print_table_row(2, "msgpack version", MSGPACK_VERSION); + php_info_print_table_row(2, "MessagePack Support", "enabled"); #if HAVE_PHP_SESSION - php_info_print_table_row(2, "msgpack Session Support", "enabled" ); + php_info_print_table_row(2, "Session Support", "enabled" ); #endif + php_info_print_table_row(2, "extension Version", MSGPACK_EXTENSION_VERSION); + php_info_print_table_row(2, "header Version", MSGPACK_VERSION); php_info_print_table_end(); + + DISPLAY_INI_ENTRIES(); } zend_module_entry msgpack_module_entry = { @@ -71,7 +108,7 @@ zend_module_entry msgpack_module_entry = { "msgpack", msgpack_functions, ZEND_MINIT(msgpack), - NULL, + ZEND_MSHUTDOWN(msgpack), NULL, NULL, ZEND_MINFO(msgpack), @@ -109,7 +146,6 @@ PS_SERIALIZER_ENCODE_FUNC(msgpack) PS_SERIALIZER_DECODE_FUNC(msgpack) { - php_unserialize_data_t var_hash; int ret; HashTable *tmp_hash; HashPosition tmp_hash_pos; @@ -117,38 +153,29 @@ PS_SERIALIZER_DECODE_FUNC(msgpack) ulong key_long; uint key_len; zval *tmp; - zval **data; - msgpack_unserialize_data mpsd; + zval **value; + size_t off = 0; + msgpack_unpack_t mp; + php_unserialize_data_t var_hash; - PHP_VAR_UNSERIALIZE_INIT(var_hash); + ALLOC_INIT_ZVAL(tmp); - MAKE_STD_ZVAL(tmp); + template_init(&mp); - mpsd.data = (unsigned char *)val;; - mpsd.length = vallen; - mpsd.offset = 0; + msgpack_unserialize_var_init(&var_hash); - ret = msgpack_unserialize_zval(&tmp, &mpsd, &var_hash TSRMLS_CC); + (&mp)->user.retval = (zval *)tmp; + (&mp)->user.var_hash = (php_unserialize_data_t *)&var_hash; - switch (ret) - { - case MSGPACK_UNPACK_EXTRA_BYTES: - case MSGPACK_UNPACK_SUCCESS: - break; - case MSGPACK_UNPACK_PARSE_ERROR: - case MSGPACK_UNPACK_CONTINUE: - default: - zval_ptr_dtor(&tmp); - return FAILURE; - } + ret = template_execute(&mp, (char *)val, (size_t)vallen, &off); - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); + msgpack_unserialize_var_destroy(&var_hash); tmp_hash = HASH_OF(tmp); zend_hash_internal_pointer_reset_ex(tmp_hash, &tmp_hash_pos); while (zend_hash_get_current_data_ex( - tmp_hash, (void *)&data, &tmp_hash_pos) == SUCCESS) + tmp_hash, (void *)&value, &tmp_hash_pos) == SUCCESS) { ret = zend_hash_get_current_key_ex( tmp_hash, &key_str, &key_len, &key_long, 0, &tmp_hash_pos); @@ -158,7 +185,8 @@ PS_SERIALIZER_DECODE_FUNC(msgpack) /* ??? */ break; case HASH_KEY_IS_STRING: - php_set_session_var(key_str, key_len - 1, *data, NULL TSRMLS_CC); + php_set_session_var( + key_str, key_len - 1, *value, NULL TSRMLS_CC); php_add_session_var(key_str, key_len - 1 TSRMLS_CC); break; } @@ -185,46 +213,59 @@ PHP_MSGPACK_API void php_msgpack_unserialize( zval *return_value, char *str, size_t str_len TSRMLS_DC) { int ret; + size_t off = 0; + msgpack_unpack_t mp; php_unserialize_data_t var_hash; - msgpack_unserialize_data mpsd; if (str_len <= 0) { RETURN_NULL(); } - PHP_VAR_UNSERIALIZE_INIT(var_hash); + template_init(&mp); - mpsd.data = (unsigned char *)str; - mpsd.length = str_len; - mpsd.offset = 0; + msgpack_unserialize_var_init(&var_hash); - ret = msgpack_unserialize_zval(&return_value, &mpsd, &var_hash TSRMLS_CC); + (&mp)->user.retval = (zval *)return_value; + (&mp)->user.var_hash = (php_unserialize_data_t *)&var_hash; + + ret = template_execute(&mp, str, (size_t)str_len, &off); + + msgpack_unserialize_var_destroy(&var_hash); switch (ret) { case MSGPACK_UNPACK_PARSE_ERROR: - zend_error(E_WARNING, - "[msgpack] (php_msgpack_unserialize) Parse error"); + if (MSGPACK_G(error_display)) + { + zend_error(E_WARNING, + "[msgpack] (php_msgpack_unserialize) Parse error"); + } break; case MSGPACK_UNPACK_CONTINUE: - zend_error(E_WARNING, - "[msgpack] (php_msgpack_unserialize) " - "Insufficient data for unserializeng"); + if (MSGPACK_G(error_display)) + { + zend_error(E_WARNING, + "[msgpack] (php_msgpack_unserialize) " + "Insufficient data for unserializing"); + } break; case MSGPACK_UNPACK_EXTRA_BYTES: - zend_error(E_WARNING, - "[msgpack] (php_msgpack_unserialize) Extra bytes"); - break; case MSGPACK_UNPACK_SUCCESS: + if (off < (size_t)str_len && MSGPACK_G(error_display)) + { + zend_error(E_WARNING, + "[msgpack] (php_msgpack_unserialize) Extra bytes"); + } break; default: - zend_error(E_WARNING, - "[msgpack] (php_msgpack_unserialize) Unknown result"); + if (MSGPACK_G(error_display)) + { + zend_error(E_WARNING, + "[msgpack] (php_msgpack_unserialize) Unknown result"); + } break; } - - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); } static ZEND_FUNCTION(msgpack_serialize) -- cgit v1.2.1