diff options
author | SVN Migration <svn@php.net> | 2003-02-27 17:43:39 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2003-02-27 17:43:39 +0000 |
commit | 078bcec0997ad0e07b720c43cc9e6d0e046a75ab (patch) | |
tree | 36cb0f6be2ef078fe3374de8c087b93ecf82f812 /ext/standard | |
parent | fd61f69077f6156ca71dde60ecfd9ed9765a02db (diff) | |
download | php-git-PHP-5.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PHP_5'.PHP-5
Diffstat (limited to 'ext/standard')
302 files changed, 0 insertions, 62792 deletions
diff --git a/ext/standard/CREDITS b/ext/standard/CREDITS deleted file mode 100644 index 4021b08860..0000000000 --- a/ext/standard/CREDITS +++ /dev/null @@ -1,3 +0,0 @@ -Assert -Thies C. Arntzen - diff --git a/ext/standard/Makefile.frag b/ext/standard/Makefile.frag deleted file mode 100644 index 79ed05a992..0000000000 --- a/ext/standard/Makefile.frag +++ /dev/null @@ -1,10 +0,0 @@ - -$(srcdir)/parsedate.c: $(srcdir)/parsedate.y - -$(srcdir)/var_unserializer.c: $(srcdir)/var_unserializer.re - re2c -b $(srcdir)/var_unserializer.re > $@ - -$(srcdir)/url_scanner_ex.c: $(srcdir)/url_scanner_ex.re - re2c -b $(srcdir)/url_scanner_ex.re > $@ - -$(srcdir)/info.c: $(builddir)/../../main/build-defs.h diff --git a/ext/standard/aggregation.c b/ext/standard/aggregation.c deleted file mode 100644 index d78d55a98e..0000000000 --- a/ext/standard/aggregation.c +++ /dev/null @@ -1,658 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Andrei Zmievski <andrei@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "basic_functions.h" -#include "aggregation.h" -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) -#include "ext/pcre/php_pcre.h" -#endif - -static void aggregation_info_dtor(aggregation_info *info) -{ - /* FIXME: This is here to make it compile with Engine 2 but part of this module will need rewriting */ - -#ifndef ZEND_ENGINE_2 - destroy_zend_class(info->new_ce); - efree(info->new_ce); -#else - /* FIXME: In ZE2, there seems to be an issue with refcounts or something between - * this class entry and the original; there are problems when destroying the - * function table. - * Skipping deleting here will prevent a segfault but will leak - * the class name, the static_members hash and the ce itself. - * */ - - /* destroy_zend_class(&info->new_ce); */ -#endif - zval_ptr_dtor(&info->aggr_members); - -} - -/* {{{ static zval* array_to_hash */ -static zval *array_to_hash(zval *array) -{ - zval *hash, **entry; - char *name_lc; - - /* - * Well, this just transposes the array, popularly known as flipping it, or - * giving it the finger. - */ - MAKE_STD_ZVAL(hash); - array_init(hash); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(array)); - zend_hash_get_current_data(Z_ARRVAL_P(array), (void**)&entry) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(array))) { - if (Z_TYPE_PP(entry) == IS_STRING) { - /* - * I hate case-insensitivity. Die, die, die. - */ - name_lc = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry)); - zend_str_tolower(name_lc, Z_STRLEN_PP(entry)); - add_assoc_bool_ex(hash, name_lc, Z_STRLEN_PP(entry)+1, 1); - efree(name_lc); - } - } - - return hash; -} -/* }}} */ - - -/* {{{ static void aggregate_methods() */ -static void aggregate_methods(zend_class_entry *ce, zend_class_entry *from_ce, int aggr_type, zval *aggr_filter, zend_bool exclude, zval *aggr_methods TSRMLS_DC) -{ - HashPosition pos; - zend_function *function; - char *func_name; - uint func_name_len; - ulong num_key; - zval *list_hash = NULL; -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - pcre *re = NULL; - pcre_extra *re_extra = NULL; - int re_options = 0; -#endif - - /* - * Flip the array for easy lookup, or compile the regexp. - */ - if (aggr_type == AGGREGATE_BY_LIST) { - list_hash = array_to_hash(aggr_filter); - } -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - else if (aggr_type == AGGREGATE_BY_REGEXP) { - if ((re = pcre_get_compiled_regex(Z_STRVAL_P(aggr_filter), &re_extra, &re_options)) == NULL) { - return; - } - } -#endif - - /* - * "Just because it's not nice doesn't mean it's not miraculous." - * -- _Interesting Times_, Terry Pratchett - */ - - /* - * Aggregating by list without exclusion can be done more efficiently if we - * iterate through the list and check against function table instead of the - * other way around. - */ - if (aggr_type != AGGREGATE_BY_LIST || exclude) { - zend_hash_internal_pointer_reset_ex(&from_ce->function_table, &pos); - while (zend_hash_get_current_data_ex(&from_ce->function_table, (void**)&function, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&from_ce->function_table, &func_name, &func_name_len, &num_key, 0, &pos); - - /* We do not aggregate: - * 1. constructors */ - if (!strncmp(func_name, from_ce->name, MIN(func_name_len-1, from_ce->name_length)) || - /* 2. private methods (heh, like we really have them) */ - func_name[0] == '_' || - /* 3. explicitly excluded methods */ - (aggr_type == AGGREGATE_BY_LIST && zend_hash_exists(Z_ARRVAL_P(list_hash), func_name, func_name_len)) -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - || - /* 4. methods matching regexp as modified by the exclusion flag */ - (aggr_type == AGGREGATE_BY_REGEXP && (pcre_exec(re, re_extra, func_name, func_name_len-1, 0, 0, NULL, 0) < 0) ^ exclude) == 1 -#endif - ) { - zend_hash_move_forward_ex(&from_ce->function_table, &pos); - continue; - } - - /* - * This is where the magic happens. - */ - if (zend_hash_add(&ce->function_table, func_name, func_name_len, - (void*)function, sizeof(zend_function), NULL) == SUCCESS) { - - add_next_index_stringl(aggr_methods, func_name, func_name_len-1, 1); - } - - zend_hash_move_forward_ex(&from_ce->function_table, &pos); - } - } else { - /* - * This is just like above except the other way around. - */ - zend_hash_internal_pointer_reset(Z_ARRVAL_P(list_hash)); - while (zend_hash_get_current_key_ex(Z_ARRVAL_P(list_hash), &func_name, &func_name_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING) { - if (!strncmp(func_name, from_ce->name, MIN(func_name_len-1, from_ce->name_length)) || - func_name[0] == '_' || - zend_hash_find(&from_ce->function_table, func_name, func_name_len, (void**)&function) == FAILURE) { - zend_hash_move_forward(Z_ARRVAL_P(list_hash)); - continue; - } - - if (zend_hash_add(&ce->function_table, func_name, func_name_len, - (void*)function, sizeof(zend_function), NULL) == SUCCESS) { - add_next_index_stringl(aggr_methods, func_name, func_name_len-1, 1); - } - - zend_hash_move_forward(Z_ARRVAL_P(list_hash)); - } - } - - if (list_hash) { - zval_ptr_dtor(&list_hash); - } -} -/* }}} */ - - -/* {{{ static void aggregate_properties() */ -static void aggregate_properties(zval *obj, zend_class_entry *from_ce, int aggr_type, zval *aggr_filter, zend_bool exclude, zval *aggr_props TSRMLS_DC) -{ - HashPosition pos; - zval **prop; - char *prop_name; - uint prop_name_len; - ulong num_key; - zval *list_hash = NULL; -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - pcre *re = NULL; - pcre_extra *re_extra = NULL; - int re_options = 0; -#endif - - if (!from_ce->constants_updated) { - zend_hash_apply_with_argument(&from_ce->default_properties, (apply_func_arg_t) zval_update_constant, (void *) 1 TSRMLS_CC); - from_ce->constants_updated = 1; - } - - /* - * Flip the array for easy lookup, or compile the regexp. - */ - if (aggr_type == AGGREGATE_BY_LIST) { - list_hash = array_to_hash(aggr_filter); - } -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - else if (aggr_type == AGGREGATE_BY_REGEXP) { - if ((re = pcre_get_compiled_regex(Z_STRVAL_P(aggr_filter), &re_extra, &re_options)) == NULL) { - return; - } - } -#endif - - /* - * "Just because it's not nice doesn't mean it's not miraculous." - * -- _Interesting Times_, Terry Pratchett - */ - - /* - * Aggregating by list without exclusion can be done more efficiently if we - * iterate through the list and check against default properties table - * instead of the other way around. - */ - if (aggr_type != AGGREGATE_BY_LIST || exclude) { - zend_hash_internal_pointer_reset_ex(&from_ce->default_properties, &pos); - while (zend_hash_get_current_data_ex(&from_ce->default_properties, (void**)&prop, &pos) == SUCCESS) { - zend_hash_get_current_key_ex(&from_ce->default_properties, &prop_name, &prop_name_len, &num_key, 0, &pos); - - /* We do not aggregate: - * 1. private properties (heh, like we really have them) */ - if (prop_name[0] == '_' || - /* 2. explicitly excluded properties */ - (aggr_type == AGGREGATE_BY_LIST && zend_hash_exists(Z_ARRVAL_P(list_hash), prop_name, prop_name_len)) -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - || - /* 3. properties matching regexp as modified by the exclusion flag */ - (aggr_type == AGGREGATE_BY_REGEXP && (pcre_exec(re, re_extra, prop_name, prop_name_len-1, 0, 0, NULL, 0) < 0) ^ exclude) == 1 -#endif - ) { - zend_hash_move_forward_ex(&from_ce->default_properties, &pos); - continue; - } - - /* - * This is where the magic happens. - */ - if (zend_hash_add(Z_OBJPROP_P(obj), prop_name, prop_name_len, - (void*)prop, sizeof(zval *), NULL) == SUCCESS) { - zval_add_ref(prop); - add_next_index_stringl(aggr_props, prop_name, prop_name_len-1, 1); - } - - zend_hash_move_forward_ex(&from_ce->default_properties, &pos); - } - } else { - /* - * This is just like above except the other way around. - */ - zend_hash_internal_pointer_reset(Z_ARRVAL_P(list_hash)); - while (zend_hash_get_current_key_ex(Z_ARRVAL_P(list_hash), &prop_name, &prop_name_len, &num_key, 0, NULL) == HASH_KEY_IS_STRING) { - if (prop_name[0] == '_' || - zend_hash_find(&from_ce->default_properties, prop_name, prop_name_len, (void**)&prop) == FAILURE) { - zend_hash_move_forward(Z_ARRVAL_P(list_hash)); - continue; - } - - if (zend_hash_add(Z_OBJPROP_P(obj), prop_name, prop_name_len, - (void*)prop, sizeof(zval *), NULL) == SUCCESS) { - zval_add_ref(prop); - add_next_index_stringl(aggr_props, prop_name, prop_name_len-1, 1); - } - - zend_hash_move_forward(Z_ARRVAL_P(list_hash)); - } - } - - if (list_hash) { - zval_ptr_dtor(&list_hash); - } -} -/* }}} */ - - -/* {{{ static void aggregate() */ -static void aggregate(INTERNAL_FUNCTION_PARAMETERS, int aggr_what, int aggr_type) -{ - /* Incoming parameters. */ - zval *obj, *aggr_list = NULL; - char *class_name, *class_name_lc, *aggr_regexp; - int class_name_len, aggr_regexp_len; - zend_bool exclude = 0; - - /* Other variables. */ - zval **aggr_members, z_aggr_regexp; - zend_class_entry *ce, *new_ce; - zend_function tmp_zend_function; - aggregation_info aggr_info_new, *aggr_info = &aggr_info_new; - zval *aggr_methods_new, **aggr_methods = &aggr_methods_new; - zval *aggr_props_new, **aggr_props = &aggr_props_new; - zval *aggr_filter = NULL; - int zpp_result = FAILURE; - - /* - * Ah, the beauty of the new parameter parsing API. Almost as good as Heidi Klum. - */ - switch (aggr_type) { - case AGGREGATE_ALL: - zpp_result = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "os", &obj, - &class_name, &class_name_len); - break; - - case AGGREGATE_BY_LIST: - zpp_result = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "osa|b", &obj, - &class_name, &class_name_len, - &aggr_list, &exclude); - break; - - case AGGREGATE_BY_REGEXP: - zpp_result = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "oss|b", &obj, - &class_name, &class_name_len, - &aggr_regexp, &aggr_regexp_len, &exclude); - ZVAL_STRINGL(&z_aggr_regexp, aggr_regexp, aggr_regexp_len, 0); - break; - } - - if (zpp_result == FAILURE) { - return; - } - - /* - * Case-insensitivity is like that last freaking mutant from horror movies: - * irradiated, blown in half, its eyes melting in their sockets, yet still - * dragging itself closer and closer to you until it's pulverized into - * microscopic pieces via some last-minute contrivance. And even then you - * are not sure that it's finally dead. But that's just how I feel. - */ - class_name_lc = estrndup(class_name, class_name_len); - zend_str_tolower(class_name_lc, class_name_len); - if (zend_hash_find(EG(class_table), class_name_lc, - class_name_len+1, (void **)&ce) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Expects the second parameter to be a valid class name, '%s' given", class_name); - efree(class_name_lc); - return; - } -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry**)ce; -#endif - - /* - * And God said, Let there be light; and there was light. But only once. - */ - if (!BG(aggregation_table)) { - BG(aggregation_table) = (HashTable *) emalloc(sizeof(HashTable)); - zend_hash_init(BG(aggregation_table), 5, NULL, (dtor_func_t) aggregation_info_dtor, 0); - } - - /* - * Digging deep in the rabbit hole with a long object.. and coming up - * more empty than the imagination of whoever made "Battlefield Earth". - */ - if (zend_hash_index_find(BG(aggregation_table), (long)obj, (void**)&aggr_info) == FAILURE) { - zval *tmp; - - /* - * You are not expected to understand this. - */ - new_ce = emalloc(sizeof(zend_class_entry)); - new_ce->type = ZEND_USER_CLASS; - new_ce->name = estrndup(Z_OBJCE_P(obj)->name, Z_OBJCE_P(obj)->name_length); - new_ce->name_length = Z_OBJCE_P(obj)->name_length; - new_ce->parent = Z_OBJCE_P(obj)->parent; -#ifdef ZEND_ENGINE_2 - new_ce->refcount = 1; -#else - new_ce->refcount = (int *) emalloc(sizeof(int)); - *new_ce->refcount = 1; -#endif - new_ce->constants_updated = Z_OBJCE_P(obj)->constants_updated; - zend_hash_init(&new_ce->function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0); - zend_hash_init(&new_ce->default_properties, 10, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(&new_ce->function_table, &Z_OBJCE_P(obj)->function_table, (copy_ctor_func_t) function_add_ref, &tmp_zend_function, sizeof(zend_function)); - zend_hash_copy(&new_ce->default_properties, &Z_OBJCE_P(obj)->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - -#ifdef ZEND_ENGINE_2 - ALLOC_HASHTABLE(new_ce->static_members); - zend_hash_init(new_ce->static_members, 10, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(new_ce->static_members, Z_OBJCE_P(obj)->static_members, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - zend_hash_init(&new_ce->constants_table, 10, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(&new_ce->constants_table, &Z_OBJCE_P(obj)->constants_table, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - zend_hash_init(&new_ce->class_table, 10, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(&new_ce->class_table, &Z_OBJCE_P(obj)->class_table, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - /* - zend_hash_init(&new_ce->private_properties, 10, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(&new_ce->private_properties, &Z_OBJCE_P(obj)->private_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - */ - - new_ce->constructor = Z_OBJCE_P(obj)->constructor; - new_ce->destructor = Z_OBJCE_P(obj)->destructor; - new_ce->clone = Z_OBJCE_P(obj)->clone; -#endif - - new_ce->builtin_functions = Z_OBJCE_P(obj)->builtin_functions; -#ifndef ZEND_ENGINE_2 - new_ce->handle_function_call = Z_OBJCE_P(obj)->handle_function_call; - new_ce->handle_property_get = Z_OBJCE_P(obj)->handle_property_get; - new_ce->handle_property_set = Z_OBJCE_P(obj)->handle_property_set; -#else - new_ce->__call = Z_OBJCE_P(obj)->__call; - new_ce->__get = Z_OBJCE_P(obj)->__get; - new_ce->__set = Z_OBJCE_P(obj)->__set; -#endif - /* - * Okay, that was kind of exhausting. Let's invoke programmer virtue #1 - * and stuff this where it belongs so we don't have to work so hard next - * time. - */ - /* OBJECT FIXME!! won't work with non-standard objects */ -#ifndef ZEND_ENGINE_2 - (Z_OBJ_P(obj))->ce = new_ce; -#endif - aggr_info_new.new_ce = new_ce; - MAKE_STD_ZVAL(aggr_info_new.aggr_members); - array_init(aggr_info_new.aggr_members); - - zend_hash_index_update(BG(aggregation_table), (long)obj, - (void *)&aggr_info_new, sizeof(aggregation_info), NULL); - - } else { - /* - * Seek and ye shall find. - */ - new_ce = aggr_info->new_ce; - } - - /* - * This should be easy to understand. If not, ask Rasmus about it at his - * next tutorial. - */ - if (zend_hash_find(Z_ARRVAL_P(aggr_info->aggr_members), class_name_lc, - class_name_len+1, (void **)&aggr_members) == FAILURE) { - zval *tmp; - - MAKE_STD_ZVAL(tmp); - array_init(tmp); - MAKE_STD_ZVAL(aggr_methods_new); - array_init(aggr_methods_new); - MAKE_STD_ZVAL(aggr_props_new); - array_init(aggr_props_new); - add_assoc_zval_ex(tmp, "methods", sizeof("methods"), aggr_methods_new); - add_assoc_zval_ex(tmp, "properties", sizeof("properties"), aggr_props_new); - - zend_hash_add(Z_ARRVAL_P(aggr_info->aggr_members), class_name_lc, - class_name_len+1, &tmp, sizeof(zval *), NULL); - } else { - zend_hash_find(Z_ARRVAL_PP(aggr_members), "methods", sizeof("methods"), (void**)&aggr_methods); - zend_hash_find(Z_ARRVAL_PP(aggr_members), "properties", sizeof("properties"), (void**)&aggr_props); - } - - if (aggr_type == AGGREGATE_BY_LIST) { - aggr_filter = aggr_list; - } else if (aggr_type == AGGREGATE_BY_REGEXP) { - aggr_filter = &z_aggr_regexp; - } - - if (aggr_what == AGGREGATE_METHODS || aggr_what == AGGREGATE_ALL) { - aggregate_methods(new_ce, ce, aggr_type, aggr_filter, exclude, *aggr_methods TSRMLS_CC); - } - - if (aggr_what == AGGREGATE_PROPERTIES || aggr_what == AGGREGATE_ALL) { - aggregate_properties(obj, ce, aggr_type, aggr_filter, exclude, *aggr_props TSRMLS_CC); - } - - /* - * Yes, we have to clean up after monsters. Tsk-tsk. - */ - efree(class_name_lc); -} -/* }}} */ - - -/* {{{ proto void aggregate(object obj, string class) - */ -PHP_FUNCTION(aggregate) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_ALL, AGGREGATE_ALL); -} -/* }}} */ - - -/* {{{ proto void aggregate_methods(object obj, string class) - */ -PHP_FUNCTION(aggregate_methods) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_METHODS, AGGREGATE_ALL); -} -/* }}} */ - - -/* {{{ proto void aggregate_methods_by_list(object obj, string class, array method_list [, bool exclude]) - */ -PHP_FUNCTION(aggregate_methods_by_list) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_METHODS, AGGREGATE_BY_LIST); -} -/* }}} */ - - -/* {{{ proto void aggregate_properties(object obj, string class) - */ -PHP_FUNCTION(aggregate_properties) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_PROPERTIES, AGGREGATE_ALL); -} -/* }}} */ - - -/* {{{ proto void aggregate_properties_by_list(object obj, string class, array props_list [, bool exclude]) - */ -PHP_FUNCTION(aggregate_properties_by_list) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_PROPERTIES, AGGREGATE_BY_LIST); -} -/* }}} */ - -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) -/* {{{ proto void aggregate_methods_by_regexp(object obj, string class, string regexp [, bool exclude]) - */ -PHP_FUNCTION(aggregate_methods_by_regexp) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_METHODS, AGGREGATE_BY_REGEXP); -} -/* }}} */ - - -/* {{{ proto void aggregate_properties_by_regexp(object obj, string class, string regexp [, bool exclude]) - */ -PHP_FUNCTION(aggregate_properties_by_regexp) -{ - aggregate(INTERNAL_FUNCTION_PARAM_PASSTHRU, AGGREGATE_PROPERTIES, AGGREGATE_BY_REGEXP); -} -/* }}} */ -#endif - - -/* {{{ proto array aggregation_info(object obj) - */ -PHP_FUNCTION(aggregate_info) -{ - zval *obj; - aggregation_info *aggr_info; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - return; - } - - if (!BG(aggregation_table) || - zend_hash_index_find(BG(aggregation_table), (long)obj, (void**)&aggr_info) == FAILURE) { - RETURN_FALSE; - } - - *return_value = *aggr_info->aggr_members; - zval_copy_ctor(return_value); -} -/* }}} */ - - -/* {{{ proto void deaggregate(object obj [, string class]) - */ -PHP_FUNCTION(deaggregate) -{ - zval *obj; - char *class_name = NULL, *class_name_lc; - int class_name_len; - aggregation_info *aggr_info; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o|s", &obj, - &class_name, &class_name_len) == FAILURE) { - return; - } - - if (!BG(aggregation_table) || - zend_hash_index_find(BG(aggregation_table), (long)obj, (void**)&aggr_info) == FAILURE) { - return; - } - - if (class_name) { - zval **aggr_members, - **aggr_methods, - **aggr_props, - **method, **prop; - - class_name_lc = estrndup(class_name, class_name_len); - zend_str_tolower(class_name_lc, class_name_len); - - if (zend_hash_find(Z_ARRVAL_P(aggr_info->aggr_members), class_name_lc, - class_name_len+1, (void **)&aggr_members) == FAILURE) { - efree(class_name_lc); - return; - } - - zend_hash_find(Z_ARRVAL_PP(aggr_members), "methods", sizeof("methods"), (void**)&aggr_methods); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(aggr_methods)); - zend_hash_get_current_data(Z_ARRVAL_PP(aggr_methods), (void**)&method) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_PP(aggr_methods))) { - zend_hash_del(&Z_OBJCE_P(obj)->function_table, Z_STRVAL_PP(method), Z_STRLEN_PP(method)+1); - } - - zend_hash_find(Z_ARRVAL_PP(aggr_members), "properties", sizeof("properties"), (void**)&aggr_props); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(aggr_props)); - zend_hash_get_current_data(Z_ARRVAL_PP(aggr_props), (void**)&prop) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_PP(aggr_props))) { - zend_hash_del(Z_OBJPROP_P(obj), Z_STRVAL_PP(prop), Z_STRLEN_PP(prop)+1); - } - - zend_hash_del(Z_ARRVAL_P(aggr_info->aggr_members), class_name_lc, class_name_len+1); - - efree(class_name_lc); - } else { - zend_class_entry *orig_ce; - zval **aggr_members; - zval **aggr_props, **prop; - - if (zend_hash_find(EG(class_table), Z_OBJCE_P(obj)->name, - Z_OBJCE_P(obj)->name_length+1, (void **)&orig_ce) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Internal deaggregation error"); - return; - } - - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(aggr_info->aggr_members)); - zend_hash_get_current_data(Z_ARRVAL_P(aggr_info->aggr_members), (void **)&aggr_members) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(aggr_info->aggr_members))) { - zend_hash_find(Z_ARRVAL_PP(aggr_members), "properties", sizeof("properties"), (void**)&aggr_props); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(aggr_props)); - zend_hash_get_current_data(Z_ARRVAL_PP(aggr_props), (void**)&prop) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_PP(aggr_props))) { - zend_hash_del(Z_OBJPROP_P(obj), Z_STRVAL_PP(prop), Z_STRLEN_PP(prop)+1); - } - } - - /* OBJECT FIXME!! won't work with non-standard objects */ -#ifndef ZEND_ENGINE_2 - (Z_OBJ_P(obj))->ce = orig_ce; -#endif - zend_hash_index_del(BG(aggregation_table), (long)obj); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/aggregation.h b/ext/standard/aggregation.h deleted file mode 100644 index f4cd010c60..0000000000 --- a/ext/standard/aggregation.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Andrei Zmievski <andrei@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef AGGREGATION_H -#define AGGREGATION_H - -#define AGGREGATE_ALL 0 - -#define AGGREGATE_METHODS 1 -#define AGGREGATE_PROPERTIES 2 - -#define AGGREGATE_BY_LIST 1 -#define AGGREGATE_BY_REGEXP 2 - -/* - * Data structure that is stored in aggregation_table hashtable for each object. - */ -typedef struct { - zend_class_entry *new_ce; - zval *aggr_members; -} aggregation_info; - -PHP_FUNCTION(aggregate); -PHP_FUNCTION(aggregate_methods); -PHP_FUNCTION(aggregate_methods_by_list); -PHP_FUNCTION(aggregate_methods_by_regexp); -PHP_FUNCTION(aggregate_properties); -PHP_FUNCTION(aggregate_properties_by_list); -PHP_FUNCTION(aggregate_properties_by_regexp); -PHP_FUNCTION(aggregate); -PHP_FUNCTION(deaggregate); -PHP_FUNCTION(aggregate_info); - -#endif /* AGGREGATION_H */ diff --git a/ext/standard/array.c b/ext/standard/array.c deleted file mode 100644 index 2b1fead7c5..0000000000 --- a/ext/standard/array.c +++ /dev/null @@ -1,3759 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | Rasmus Lerdorf <rasmus@php.net> | - | Andrei Zmievski <andrei@php.net> | - | Stig Venaas <venaas@php.net> | - | Jason Greene <jason@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_ini.h" -#include <stdarg.h> -#include <stdlib.h> -#include <math.h> -#include <time.h> -#include <stdio.h> -#if HAVE_STRING_H -#include <string.h> -#else -#include <strings.h> -#endif -#ifdef PHP_WIN32 -#include "win32/unistd.h" -#endif -#include "zend_globals.h" -#include "php_globals.h" -#include "php_array.h" -#include "basic_functions.h" -#include "php_string.h" -#include "php_rand.h" -#include "php_smart_str.h" - -#ifdef ZTS -int array_globals_id; -#else -php_array_globals array_globals; -#endif - -#define EXTR_OVERWRITE 0 -#define EXTR_SKIP 1 -#define EXTR_PREFIX_SAME 2 -#define EXTR_PREFIX_ALL 3 -#define EXTR_PREFIX_INVALID 4 -#define EXTR_PREFIX_IF_EXISTS 5 -#define EXTR_IF_EXISTS 6 - -#define EXTR_REFS 0x100 - -#define SORT_REGULAR 0 -#define SORT_NUMERIC 1 -#define SORT_STRING 2 - -#define SORT_DESC 3 -#define SORT_ASC 4 - -#define CASE_LOWER 0 -#define CASE_UPPER 1 - -#define COUNT_NORMAL 0 -#define COUNT_RECURSIVE 1 - -#define DIFF_NORMAL 0 -#define DIFF_ASSOC 1 - -#define INTERSECT_NORMAL 0 -#define INTERSECT_ASSOC 1 - -PHP_MINIT_FUNCTION(array) -{ -#ifdef ZTS - ts_allocate_id(&array_globals_id, sizeof(php_array_globals), NULL, NULL); -#endif - - REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", EXTR_OVERWRITE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_SKIP", EXTR_SKIP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_PREFIX_SAME", EXTR_PREFIX_SAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_PREFIX_ALL", EXTR_PREFIX_ALL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_PREFIX_INVALID", EXTR_PREFIX_INVALID, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_PREFIX_IF_EXISTS", EXTR_PREFIX_IF_EXISTS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_IF_EXISTS", EXTR_IF_EXISTS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("EXTR_REFS", EXTR_REFS, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SORT_ASC", SORT_ASC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SORT_DESC", SORT_DESC, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SORT_REGULAR", SORT_REGULAR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SORT_NUMERIC", SORT_NUMERIC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SORT_STRING", SORT_STRING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CASE_LOWER", CASE_LOWER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CASE_UPPER", CASE_UPPER, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("COUNT_NORMAL", COUNT_NORMAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("COUNT_RECURSIVE", COUNT_RECURSIVE, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(array) -{ -#ifdef ZTS - ts_free_id(array_globals_id); -#endif - - return SUCCESS; -} - -static void set_compare_func(int sort_type TSRMLS_DC) -{ - switch (sort_type) { - case SORT_NUMERIC: - ARRAYG(compare_func) = numeric_compare_function; - break; - - case SORT_STRING: - ARRAYG(compare_func) = string_compare_function; - break; - - case SORT_REGULAR: - default: - ARRAYG(compare_func) = compare_function; - break; - } -} - -static int array_key_compare(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f; - Bucket *s; - zval result; - zval first; - zval second; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - if (f->nKeyLength == 0) { - Z_TYPE(first) = IS_LONG; - Z_LVAL(first) = f->h; - } else { - Z_TYPE(first) = IS_STRING; - Z_STRVAL(first) = f->arKey; - Z_STRLEN(first) = f->nKeyLength-1; - } - - if (s->nKeyLength == 0) { - Z_TYPE(second) = IS_LONG; - Z_LVAL(second) = s->h; - } else { - Z_TYPE(second) = IS_STRING; - Z_STRVAL(second) = s->arKey; - Z_STRLEN(second) = s->nKeyLength-1; - } - - if (ARRAYG(compare_func)(&result, &first, &second TSRMLS_CC) == FAILURE) { - return 0; - } - - if (Z_TYPE(result) == IS_DOUBLE) { - if (Z_DVAL(result) < 0) { - return -1; - } else if (Z_DVAL(result) > 0) { - return 1; - } else { - return 0; - } - } - - convert_to_long(&result); - - if (Z_LVAL(result) < 0) { - return -1; - } else if (Z_LVAL(result) > 0) { - return 1; - } - - return 0; -} - -static int array_reverse_key_compare(const void *a, const void *b TSRMLS_DC) -{ - return array_key_compare(a, b TSRMLS_CC) * -1; -} - -/* {{{ proto bool krsort(array array_arg [, int sort_flags]) - Sort an array by key value in reverse order */ -PHP_FUNCTION(krsort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_reverse_key_compare, 0 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ksort(array array_arg [, int sort_flags]) - Sort an array by key */ -PHP_FUNCTION(ksort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_key_compare, 0 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - - -static int php_count_recursive(zval *array, long mode TSRMLS_DC) -{ - long cnt = 0; - zval **element; - - if (Z_TYPE_P(array) == IS_ARRAY) { - cnt = zend_hash_num_elements(Z_ARRVAL_P(array)); - if (mode == COUNT_RECURSIVE) { - HashPosition pos; - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(array), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_P(array), (void **) &element, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(array), &pos)) { - cnt += php_count_recursive(*element, COUNT_RECURSIVE TSRMLS_CC); - } - } - } - - return cnt; -} - -/* {{{ proto int count(mixed var [, int mode]) - Count the number of elements in a variable (usually an array) */ -PHP_FUNCTION(count) -{ - zval *array; - long mode = COUNT_NORMAL; - - if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "z|l", &array, &mode) == FAILURE) - return; - - switch (Z_TYPE_P(array)) { - case IS_NULL: - RETURN_LONG(0); - break; - case IS_ARRAY: - RETURN_LONG (php_count_recursive (array, mode TSRMLS_CC)); - break; - default: - RETURN_LONG(1); - break; - } -} -/* }}} */ - -/* Numbers are always smaller than strings int this function as it - * anyway doesn't make much sense to compare two different data types. - * This keeps it consistant and simple. - * - * This is not correct any more, depends on what compare_func is set to. - */ -static int array_data_compare(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f; - Bucket *s; - pval result; - pval *first; - pval *second; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - first = *((pval **) f->pData); - second = *((pval **) s->pData); - - if (ARRAYG(compare_func)(&result, first, second TSRMLS_CC) == FAILURE) { - return 0; - } - - if (Z_TYPE(result) == IS_DOUBLE) { - if (Z_DVAL(result) < 0) { - return -1; - } else if (Z_DVAL(result) > 0) { - return 1; - } else { - return 0; - } - } - - convert_to_long(&result); - - if (Z_LVAL(result) < 0) { - return -1; - } else if (Z_LVAL(result) > 0) { - return 1; - } - - return 0; -} - -static int array_reverse_data_compare(const void *a, const void *b TSRMLS_DC) -{ - return array_data_compare(a, b TSRMLS_CC)*-1; -} - -static int array_natural_general_compare(const void *a, const void *b, int fold_case) -{ - Bucket *f, *s; - zval *fval, *sval; - zval first, second; - int result; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - fval = *((pval **) f->pData); - sval = *((pval **) s->pData); - first = *fval; - second = *sval; - if (Z_TYPE_P(fval) != IS_STRING) { - zval_copy_ctor(&first); - convert_to_string(&first); - } - if (Z_TYPE_P(sval) != IS_STRING) { - zval_copy_ctor(&second); - convert_to_string(&second); - } - - result = strnatcmp_ex(Z_STRVAL(first), Z_STRLEN(first), - Z_STRVAL(second), Z_STRLEN(second), fold_case); - - if (Z_TYPE_P(fval) != IS_STRING) - zval_dtor(&first); - if (Z_TYPE_P(sval) != IS_STRING) - zval_dtor(&second); - - return result; -} - -static int array_natural_compare(const void *a, const void *b TSRMLS_DC) -{ - return array_natural_general_compare(a, b, 0); -} - -static int array_natural_case_compare(const void *a, const void *b TSRMLS_DC) -{ - return array_natural_general_compare(a, b, 1); -} - -static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) -{ - zval **array; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - if (fold_case) { - if (zend_hash_sort(target_hash, zend_qsort, array_natural_case_compare, 0 TSRMLS_CC) == FAILURE) { - return; - } - } else { - if (zend_hash_sort(target_hash, zend_qsort, array_natural_compare, 0 TSRMLS_CC) == FAILURE) { - return; - } - } - - RETURN_TRUE; -} - - -/* {{{ proto void natsort(array array_arg) - Sort an array using natural sort */ -PHP_FUNCTION(natsort) -{ - php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - - -/* {{{ proto void natcasesort(array array_arg) - Sort an array using case-insensitive natural sort */ -PHP_FUNCTION(natcasesort) -{ - php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - - -/* {{{ proto bool asort(array array_arg [, int sort_flags]) - Sort an array and maintain index association */ -PHP_FUNCTION(asort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 0 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool arsort(array array_arg [, int sort_flags]) - Sort an array in reverse order and maintain index association */ -PHP_FUNCTION(arsort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 0 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool sort(array array_arg [, int sort_flags]) - Sort an array */ -PHP_FUNCTION(sort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_data_compare, 1 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool rsort(array array_arg [, int sort_flags]) - Sort an array in reverse order */ -PHP_FUNCTION(rsort) -{ - zval *array; - long sort_type = SORT_REGULAR; - HashTable *target_hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &array, &sort_type) == FAILURE) { - RETURN_FALSE; - } - - target_hash = HASH_OF(array); - set_compare_func(sort_type TSRMLS_CC); - - if (zend_hash_sort(target_hash, zend_qsort, array_reverse_data_compare, 1 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -static int array_user_compare(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f; - Bucket *s; - zval **args[2]; - zval *retval_ptr; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - args[0] = (zval **) f->pData; - args[1] = (zval **) s->pData; - - if (call_user_function_ex(EG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0, NULL TSRMLS_CC)==SUCCESS - && retval_ptr) { - long retval; - - convert_to_long_ex(&retval_ptr); - retval = Z_LVAL_P(retval_ptr); - zval_ptr_dtor(&retval_ptr); - return retval; - } else { - return 0; - } -} - -/* {{{ proto bool usort(array array_arg, string cmp_function) - Sort an array by values using a user-defined comparison function */ -PHP_FUNCTION(usort) -{ - zval **array; - zval **old_compare_func; - HashTable *target_hash; - - old_compare_func = BG(user_compare_func_name); - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 1 TSRMLS_CC) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool uasort(array array_arg, string cmp_function) - Sort an array with a user-defined comparison function and maintain index association */ -PHP_FUNCTION(uasort) -{ - zval **array; - zval **old_compare_func; - HashTable *target_hash; - - old_compare_func = BG(user_compare_func_name); - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, zend_qsort, array_user_compare, 0 TSRMLS_CC) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} -/* }}} */ - -static int array_user_key_compare(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f; - Bucket *s; - pval key1, key2; - pval *args[2]; - pval retval; - int status; - - args[0] = &key1; - args[1] = &key2; - INIT_PZVAL(&key1); - INIT_PZVAL(&key2); - - f = *((Bucket **) a); - s = *((Bucket **) b); - - if (f->nKeyLength) { - Z_STRVAL(key1) = estrndup(f->arKey, f->nKeyLength); - Z_STRLEN(key1) = f->nKeyLength-1; - Z_TYPE(key1) = IS_STRING; - } else { - Z_LVAL(key1) = f->h; - Z_TYPE(key1) = IS_LONG; - } - if (s->nKeyLength) { - Z_STRVAL(key2) = estrndup(s->arKey, s->nKeyLength); - Z_STRLEN(key2) = s->nKeyLength-1; - Z_TYPE(key2) = IS_STRING; - } else { - Z_LVAL(key2) = s->h; - Z_TYPE(key2) = IS_LONG; - } - - status = call_user_function(EG(function_table), NULL, *BG(user_compare_func_name), &retval, 2, args TSRMLS_CC); - - zval_dtor(&key1); - zval_dtor(&key2); - - if (status == SUCCESS) { - convert_to_long(&retval); - return Z_LVAL(retval); - } else { - return 0; - } -} - -/* {{{ proto bool uksort(array array_arg, string cmp_function) - Sort an array by keys using a user-defined comparison function */ -PHP_FUNCTION(uksort) -{ - zval **array; - zval **old_compare_func; - HashTable *target_hash; - - old_compare_func = BG(user_compare_func_name); - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, zend_qsort, array_user_key_compare, 0 TSRMLS_CC) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto mixed end(array array_arg) - Advances array argument's internal pointer to the last element and return it */ -PHP_FUNCTION(end) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - zend_hash_internal_pointer_end(target_hash); - - if (return_value_used) { - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - RETURN_FALSE; - } - - *return_value = **entry; - zval_copy_ctor(return_value); - } -} -/* }}} */ - -/* {{{ proto mixed prev(array array_arg) - Move array argument's internal pointer to the previous element and return it */ -PHP_FUNCTION(prev) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - zend_hash_move_backwards(target_hash); - - if (return_value_used) { - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - RETURN_FALSE; - } - - *return_value = **entry; - zval_copy_ctor(return_value); - } -} -/* }}} */ - -/* {{{ proto mixed next(array array_arg) - Move array argument's internal pointer to the next element and return it */ -PHP_FUNCTION(next) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - zend_hash_move_forward(target_hash); - - if (return_value_used) { - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - RETURN_FALSE; - } - - *return_value = **entry; - zval_copy_ctor(return_value); - } -} -/* }}} */ - -/* {{{ proto mixed reset(array array_arg) - Set array argument's internal pointer to the first element and return it */ -PHP_FUNCTION(reset) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - zend_hash_internal_pointer_reset(target_hash); - - if (return_value_used) { - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - RETURN_FALSE; - } - - *return_value = **entry; - zval_copy_ctor(return_value); - } -} -/* }}} */ - -/* {{{ proto mixed current(array array_arg) - Return the element currently pointed to by the internal array pointer */ -PHP_FUNCTION(current) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - RETURN_FALSE; - } - *return_value = **entry; - zval_copy_ctor(return_value); -} -/* }}} */ - -/* {{{ proto mixed key(array array_arg) - Return the key of the element currently pointed to by the internal array pointer */ -PHP_FUNCTION(key) -{ - pval **array; - char *string_key; - uint string_length; - ulong num_key; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object"); - RETURN_FALSE; - } - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, NULL)) { - case HASH_KEY_IS_STRING: - RETVAL_STRINGL(string_key, string_length - 1, 1); - break; - case HASH_KEY_IS_LONG: - RETVAL_LONG(num_key); - break; - case HASH_KEY_NON_EXISTANT: - return; - } -} -/* }}} */ - -/* {{{ proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) - Return the lowest value in an array or a series of arguments */ -PHP_FUNCTION(min) -{ - int argc=ZEND_NUM_ARGS(); - pval **result; - - if (argc<=0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Atleast one value should be passed"); - RETURN_NULL(); - } - set_compare_func(SORT_REGULAR TSRMLS_CC); - if (argc == 1) { - pval **arr; - - if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { - WRONG_PARAM_COUNT; - } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result TSRMLS_CC) == SUCCESS) { - *return_value = **result; - zval_copy_ctor(return_value); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array must contain atleast one element"); - RETURN_FALSE; - } - } else { - pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); - pval **min, result; - int i; - - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args)==FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - min = args[0]; - - for (i=1; i<ZEND_NUM_ARGS(); i++) { - is_smaller_function(&result, *args[i], *min TSRMLS_CC); - if (Z_LVAL(result) == 1) { - min = args[i]; - } - } - - *return_value = **min; - zval_copy_ctor(return_value); - - efree(args); - } -} -/* }}} */ - -/* {{{ proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) - Return the highest value in an array or a series of arguments */ -PHP_FUNCTION(max) -{ - int argc=ZEND_NUM_ARGS(); - pval **result; - - if (argc<=0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Atleast one value should be passed"); - RETURN_NULL(); - } - set_compare_func(SORT_REGULAR TSRMLS_CC); - if (argc == 1) { - pval **arr; - - if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) { - WRONG_PARAM_COUNT; - } - if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result TSRMLS_CC) == SUCCESS) { - *return_value = **result; - zval_copy_ctor(return_value); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array must contain atleast one element"); - RETURN_FALSE; - } - } else { - pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); - pval **max, result; - int i; - - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - max = args[0]; - - for (i=1; i<ZEND_NUM_ARGS(); i++) { - is_smaller_or_equal_function(&result, *args[i], *max TSRMLS_CC); - if (Z_LVAL(result) == 0) { - max = args[i]; - } - } - - *return_value = **max; - zval_copy_ctor(return_value); - - efree(args); - } -} -/* }}} */ - -static int php_array_walk(HashTable *target_hash, zval **userdata, int recursive TSRMLS_DC) -{ - zval **args[3], /* Arguments to userland function */ - *retval_ptr, /* Return value - unused */ - *key; /* Entry key */ - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - - /* Set up known arguments */ - args[1] = &key; - args[2] = userdata; - - zend_hash_internal_pointer_reset_ex(target_hash, &pos); - - /* Iterate through hash */ - while (zend_hash_get_current_data_ex(target_hash, (void **)&args[0], &pos) == SUCCESS) { - if (recursive && Z_TYPE_PP(args[0]) == IS_ARRAY) { - HashTable *thash; - - thash = HASH_OF(*(args[0])); - if (thash == target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); - return 0; - } - php_array_walk(thash, userdata, recursive TSRMLS_CC); - } else { - /* Allocate space for key */ - MAKE_STD_ZVAL(key); - - /* Set up the key */ - if (zend_hash_get_current_key_ex(target_hash, &string_key, &string_key_len, &num_key, 0, &pos) == HASH_KEY_IS_LONG) { - Z_TYPE_P(key) = IS_LONG; - Z_LVAL_P(key) = num_key; - } else { - ZVAL_STRINGL(key, string_key, string_key_len-1, 1); - } - - /* Call the userland function */ - if (call_user_function_ex(EG(function_table), NULL, *BG(array_walk_func_name), - &retval_ptr, userdata ? 3 : 2, args, 0, NULL TSRMLS_CC) == SUCCESS) { - - zval_ptr_dtor(&retval_ptr); - } else { - char *func_name; - - if (zend_is_callable(*BG(array_walk_func_name), 0, &func_name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", func_name); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", func_name); - } - - efree(func_name); - break; - } - } - - zval_ptr_dtor(&key); - zend_hash_move_forward_ex(target_hash, &pos); - } - - return 0; -} - -/* {{{ proto bool array_walk(array input, string funcname [, mixed userdata]) - Apply a user function to every member of an array */ -PHP_FUNCTION(array_walk) -{ - int argc; - zval **array, - **userdata = NULL, - **old_walk_func_name; - HashTable *target_hash; - - argc = ZEND_NUM_ARGS(); - old_walk_func_name = BG(array_walk_func_name); - if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &array, &BG(array_walk_func_name), &userdata) == FAILURE) { - BG(array_walk_func_name) = old_walk_func_name; - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_FALSE; - } - if (Z_TYPE_PP(BG(array_walk_func_name)) != IS_ARRAY && - Z_TYPE_PP(BG(array_walk_func_name)) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong syntax for function name"); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_FALSE; - } - php_array_walk(target_hash, userdata, 0 TSRMLS_CC); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool array_walk_recursive(array input, string funcname [, mixed userdata]) - Apply a user function recursively to every member of an array */ -PHP_FUNCTION(array_walk_recursive) -{ - int argc; - zval **array, - **userdata = NULL, - **old_walk_func_name; - HashTable *target_hash; - - argc = ZEND_NUM_ARGS(); - old_walk_func_name = BG(array_walk_func_name); - if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &array, &BG(array_walk_func_name), &userdata) == FAILURE) { - BG(array_walk_func_name) = old_walk_func_name; - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_FALSE; - } - if (Z_TYPE_PP(BG(array_walk_func_name)) != IS_ARRAY && Z_TYPE_PP(BG(array_walk_func_name)) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong syntax for function name"); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_FALSE; - } - php_array_walk(target_hash, userdata, 1 TSRMLS_CC); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_TRUE; -} -/* }}} */ - - -/* void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) - * 0 = return boolean - * 1 = return key - */ -static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior) -{ - zval **value, /* value to check for */ - **array, /* array to check in */ - **strict, /* strict comparison or not */ - **entry, /* pointer to array entry */ - res; /* comparison result */ - HashTable *target_hash; /* array hashtable */ - HashPosition pos; /* hash iterator */ - ulong num_key; - uint str_key_len; - char *string_key; - int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function; - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &value, &array, &strict) == FAILURE) { - WRONG_PARAM_COUNT; - } - -#ifndef ZEND_ENGINE_2 - if (Z_TYPE_PP(value) == IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong datatype for first argument"); - RETURN_FALSE; - } -#endif - - if (Z_TYPE_PP(array) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong datatype for second argument"); - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() == 3) { - convert_to_boolean_ex(strict); - if (Z_LVAL_PP(strict)) { - is_equal_func = is_identical_function; - } - } - - target_hash = HASH_OF(*array); - zend_hash_internal_pointer_reset_ex(target_hash, &pos); - while (zend_hash_get_current_data_ex(target_hash, (void **)&entry, &pos) == SUCCESS) { - is_equal_func(&res, *value, *entry TSRMLS_CC); - if (Z_LVAL(res)) { - if (behavior == 0) { - RETURN_TRUE; - } else { - /* Return current key */ - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &str_key_len, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - RETURN_STRINGL(string_key, str_key_len-1, 1); - break; - case HASH_KEY_IS_LONG: - RETURN_LONG(num_key); - break; - } - } - } - - zend_hash_move_forward_ex(target_hash, &pos); - } - - RETURN_FALSE; -} - - -/* {{{ proto bool in_array(mixed needle, array haystack [, bool strict]) - Checks if the given value exists in the array */ -PHP_FUNCTION(in_array) -{ - php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto mixed array_search(mixed needle, array haystack [, bool strict]) - Searches the array for a given value and returns the corresponding key if successful */ -PHP_FUNCTION(array_search) -{ - php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - - -static int php_valid_var_name(char *var_name) -{ - int len, i; - - if (!var_name) - return 0; - - len = strlen(var_name); - - if (!isalpha((int)var_name[0]) && var_name[0] != '_') - return 0; - - if (len > 1) { - for (i=1; i<len; i++) { - if (!isalnum((int)var_name[i]) && var_name[i] != '_') { - return 0; - } - } - } - - return 1; -} - - -/* {{{ proto int extract(array var_array [, int extract_type [, string prefix]]) - Imports variables into symbol table from an array */ -PHP_FUNCTION(extract) -{ - zval **var_array, **z_extract_type, **prefix; - zval **entry, *data; - char *var_name; - smart_str final_name = {0}; - ulong num_key; - uint var_name_len; - int var_exists, extract_type, key_type, count = 0; - zend_bool extract_refs = 0; - HashPosition pos; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &var_array) == FAILURE) { - WRONG_PARAM_COUNT; - } - extract_type = EXTR_OVERWRITE; - break; - - case 2: - if (zend_get_parameters_ex(2, &var_array, &z_extract_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_extract_type); - extract_type = Z_LVAL_PP(z_extract_type); - extract_refs = (extract_type & EXTR_REFS)>>8; - extract_type &= 0xff; - if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_IF_EXISTS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Prefix expected to be specified"); - return; - } - break; - - case 3: - if (zend_get_parameters_ex(3, &var_array, &z_extract_type, &prefix) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(z_extract_type); - extract_type = Z_LVAL_PP(z_extract_type); - extract_refs = (extract_type & EXTR_REFS)>>8; - extract_type &= 0xff; - convert_to_string_ex(prefix); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_IF_EXISTS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown extract type"); - return; - } - - if (Z_TYPE_PP(var_array) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument should be an array"); - return; - } - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(var_array), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(var_array), (void **)&entry, &pos) == SUCCESS) { - key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(var_array), &var_name, &var_name_len, &num_key, 0, &pos); - var_exists = 0; - - if (key_type == HASH_KEY_IS_STRING) { - var_name_len--; - var_exists = zend_hash_exists(EG(active_symbol_table), var_name, var_name_len + 1); - } else if (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID) { - smart_str_appendl(&final_name, Z_STRVAL_PP(prefix), Z_STRLEN_PP(prefix)); - smart_str_appendc(&final_name, '_'); - smart_str_append_long(&final_name, num_key); - } else { - zend_hash_move_forward_ex(Z_ARRVAL_PP(var_array), &pos); - continue; - } - - switch (extract_type) { - case EXTR_IF_EXISTS: - if (!var_exists) break; - /* break omitted intentionally */ - - case EXTR_OVERWRITE: - smart_str_appendl(&final_name, var_name, var_name_len); - break; - - case EXTR_PREFIX_IF_EXISTS: - if (var_exists) { - smart_str_appendl(&final_name, Z_STRVAL_PP(prefix), Z_STRLEN_PP(prefix)); - smart_str_appendc(&final_name, '_'); - smart_str_appendl(&final_name, var_name, var_name_len); - } - break; - - case EXTR_PREFIX_SAME: - if (!var_exists) - smart_str_appendl(&final_name, var_name, var_name_len); - /* break omitted intentionally */ - - case EXTR_PREFIX_ALL: - if (final_name.len == 0) { - smart_str_appendl(&final_name, Z_STRVAL_PP(prefix), Z_STRLEN_PP(prefix)); - smart_str_appendc(&final_name, '_'); - smart_str_appendl(&final_name, var_name, var_name_len); - } - break; - - case EXTR_PREFIX_INVALID: - if (final_name.len == 0) { - if (!php_valid_var_name(var_name)) { - smart_str_appendl(&final_name, Z_STRVAL_PP(prefix), Z_STRLEN_PP(prefix)); - smart_str_appendc(&final_name, '_'); - smart_str_appendl(&final_name, var_name, var_name_len); - } else - smart_str_appendl(&final_name, var_name, var_name_len); - } - break; - - default: - if (!var_exists) - smart_str_appendl(&final_name, var_name, var_name_len); - break; - } - - if (final_name.len) { - smart_str_0(&final_name); - if (php_valid_var_name(final_name.c)) { - if (extract_refs) { - zval **orig_var; - - (*entry)->is_ref = 1; - (*entry)->refcount++; - if (zend_hash_find(EG(active_symbol_table), final_name.c, final_name.len+1, (void **) &orig_var) == SUCCESS - && PZVAL_IS_REF(*orig_var)) { - - (*entry)->refcount += (*orig_var)->refcount-2; - zval_dtor(*orig_var); - FREE_ZVAL(*orig_var); - *orig_var = *entry; - } else { - zend_hash_update(EG(active_symbol_table), final_name.c, final_name.len+1, entry, sizeof(zval *), NULL); - } - } else { - MAKE_STD_ZVAL(data); - *data = **entry; - zval_copy_ctor(data); - - ZEND_SET_SYMBOL(EG(active_symbol_table), final_name.c, data); - } - - count++; - } - final_name.len = 0; - } - - zend_hash_move_forward_ex(Z_ARRVAL_PP(var_array), &pos); - } - - smart_str_free(&final_name); - - RETURN_LONG(count); -} -/* }}} */ - - -static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_value, zval *entry) -{ - zval **value_ptr, *value, *data; - - if (Z_TYPE_P(entry) == IS_STRING) { - if (zend_hash_find(eg_active_symbol_table, Z_STRVAL_P(entry), - Z_STRLEN_P(entry)+1, (void **)&value_ptr) != FAILURE) { - value = *value_ptr; - ALLOC_ZVAL(data); - *data = *value; - zval_copy_ctor(data); - INIT_PZVAL(data); - - zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_P(entry), - Z_STRLEN_P(entry)+1, &data, sizeof(zval *), NULL); - } - } - else if (Z_TYPE_P(entry) == IS_ARRAY) { - HashPosition pos; - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(entry), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), (void**)&value_ptr, &pos) == SUCCESS) { - value = *value_ptr; - - php_compact_var(eg_active_symbol_table, return_value, value); - zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos); - } - } -} - - -/* {{{ proto array compact(mixed var_names [, mixed ...]) - Creates a hash containing variables and their values */ -PHP_FUNCTION(compact) -{ - zval ***args; /* function arguments array */ - int i; - - args = (zval ***)emalloc(ZEND_NUM_ARGS() * sizeof(zval **)); - - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - array_init(return_value); - - for (i=0; i<ZEND_NUM_ARGS(); i++) { - php_compact_var(EG(active_symbol_table), return_value, *args[i]); - } - - efree(args); -} -/* }}} */ - -/* {{{ proto array array_fill(int start_key, int num, mixed val) - Create an array containing num elements starting with index start_key each initialized to val */ -PHP_FUNCTION(array_fill) -{ - zval **start_key, **num, **val, *newval; - long i; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &start_key, &num, &val) == FAILURE) { - WRONG_PARAM_COUNT; - } - - /* allocate an array for return */ - array_init(return_value); - - switch (Z_TYPE_PP(start_key)) { - case IS_STRING: - case IS_LONG: - case IS_DOUBLE: - if (PZVAL_IS_REF(*val)) { - SEPARATE_ZVAL(val); - } - convert_to_long_ex(start_key); - zval_add_ref(val); - zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(start_key), val, sizeof(val), NULL); - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Wrong data type for start key"); - RETURN_FALSE; - break; - } - - convert_to_long_ex(num); - i = Z_LVAL_PP(num) - 1; - if (i < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of elements must be positive"); - RETURN_FALSE; - } - newval = *val; - while (i--) { -#ifndef ZEND_ENGINE_2 - if (newval->refcount >= 62000) { - MAKE_STD_ZVAL(newval); - *newval = **val; - zval_copy_ctor(newval); - newval->refcount = 0; - } -#endif - zval_add_ref(&newval); - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &newval, sizeof(zval *), NULL); - } -} -/* }}} */ - -/* {{{ proto array range(mixed low, mixed high[, int step]) - Create an array containing the range of integers or characters from low to high (inclusive) */ -PHP_FUNCTION(range) -{ - zval *zlow, *zhigh, *zstep = NULL; - int err = 0, is_step_double = 0; - double step = 1.0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z/|z/", &zlow, &zhigh, &zstep) == FAILURE) { - RETURN_FALSE; - } - - if (zstep) { - if (Z_TYPE_P(zstep) == IS_DOUBLE || (Z_TYPE_P(zstep) == IS_STRING && is_numeric_string(Z_STRVAL_P(zstep), Z_STRLEN_P(zstep), NULL, NULL, 0) == IS_DOUBLE)) { - is_step_double = 1; - } - - convert_to_double_ex(&zstep); - step = Z_DVAL_P(zstep); - - /* We only want positive step values. */ - if (step < 0.0) { - step *= -1; - } - } - - /* Initialize the return_value as an array. */ - array_init(return_value); - - /* If the range is given as strings, generate an array of characters. */ - if (Z_TYPE_P(zlow) == IS_STRING && Z_TYPE_P(zhigh) == IS_STRING) { - int type1, type2; - unsigned char *low, *high; - long lstep = (long) step; - - type1 = is_numeric_string(Z_STRVAL_P(zlow), Z_STRLEN_P(zlow), NULL, NULL, 0); - type2 = is_numeric_string(Z_STRVAL_P(zhigh), Z_STRLEN_P(zhigh), NULL, NULL, 0); - - if (type1 == IS_DOUBLE || type2 == IS_DOUBLE || is_step_double) { - goto double_str; - } else if (type1 == IS_LONG || type2 == IS_LONG) { - goto long_str; - } - - convert_to_string(zlow); - convert_to_string(zhigh); - low = (unsigned char *)Z_STRVAL_P(zlow); - high = (unsigned char *)Z_STRVAL_P(zhigh); - - if (*low > *high) { /* Negative steps */ - if (*low - *high < lstep || lstep <= 0) { - err = 1; - goto err; - } - for (; *low >= *high; (*low) -= (unsigned int)step) { - add_next_index_stringl(return_value, low, 1, 1); - } - } else if (*high > *low) { /* Positive steps */ - if (*high - *low < lstep || lstep <= 0) { - err = 1; - goto err; - } - for (; *low <= *high; (*low) += (unsigned int)lstep) { - add_next_index_stringl(return_value, low, 1, 1); - } - } else { - add_next_index_stringl(return_value, low, 1, 1); - } - } else if (Z_TYPE_P(zlow) == IS_DOUBLE || Z_TYPE_P(zhigh) == IS_DOUBLE || is_step_double) { - double low, high; -double_str: - convert_to_double(zlow); - convert_to_double(zhigh); - low = Z_DVAL_P(zlow); - high = Z_DVAL_P(zhigh); - - if (low > high) { /* Negative steps */ - if (low - high < step || step <= 0) { - err = 1; - goto err; - } - for (; low >= high; low -= step) { - add_next_index_double(return_value, low); - } - } else if (high > low) { /* Positive steps */ - if (high - low < step || step <= 0) { - err = 1; - goto err; - } - for (; low <= high; low += step) { - add_next_index_double(return_value, low); - } - } else { - add_next_index_double(return_value, low); - } - } else { - int low, high; - long lstep; -long_str: - convert_to_long(zlow); - convert_to_long(zhigh); - low = Z_LVAL_P(zlow); - high = Z_LVAL_P(zhigh); - lstep = (long) step; - - if (low > high) { /* Negative steps */ - if (low - high < lstep || lstep <= 0) { - err = 1; - goto err; - } - for (; low >= high; low -= lstep) { - add_next_index_long(return_value, low); - } - } else if (high > low) { /* Positive steps */ - if (high - low < lstep || lstep <= 0) { - err = 1; - goto err; - } - for (; low <= high; low += lstep) { - add_next_index_long(return_value, low); - } - } else { - add_next_index_long(return_value, low); - } - } -err: - if (err) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "step exceeds the specified range"); - zval_dtor(return_value); - RETURN_FALSE; - } -} -/* }}} */ - - -static void array_data_shuffle(zval *array TSRMLS_DC) -{ - Bucket **elems, *temp; - HashTable *hash; - int j, n_elems, rnd_idx, n_left; - - n_elems = zend_hash_num_elements(Z_ARRVAL_P(array)); - - if (n_elems <= 1) { - return; - } - - elems = (Bucket **)emalloc(n_elems * sizeof(Bucket *)); - hash = Z_ARRVAL_P(array); - n_left = n_elems; - - for (j = 0, temp = hash->pListHead; temp; temp = temp->pListNext) - elems[j++] = temp; - while (--n_left) { - rnd_idx = php_rand(TSRMLS_C); - RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); - if (rnd_idx != n_left) { - temp = elems[n_left]; - elems[n_left] = elems[rnd_idx]; - elems[rnd_idx] = temp; - } - } - - HANDLE_BLOCK_INTERRUPTIONS(); - hash->pListHead = elems[0]; - hash->pListTail = NULL; - hash->pInternalPointer = hash->pListHead; - - for (j = 0; j < n_elems; j++) { - if (hash->pListTail) { - hash->pListTail->pListNext = elems[j]; - } - elems[j]->pListLast = hash->pListTail; - elems[j]->pListNext = NULL; - hash->pListTail = elems[j]; - } - temp = hash->pListHead; - j = 0; - while (temp != NULL) { - temp->nKeyLength = 0; - temp->h = j++; - temp = temp->pListNext; - } - hash->nNextFreeElement = n_elems; - zend_hash_rehash(hash); - HANDLE_UNBLOCK_INTERRUPTIONS(); - - efree(elems); -} - -/* {{{ proto bool shuffle(array array_arg) - Randomly shuffle the contents of an array */ -PHP_FUNCTION(shuffle) -{ - zval *array; - - if (zend_parse_parameters(1 TSRMLS_CC, "a", &array) == FAILURE) { - RETURN_FALSE; - } - - array_data_shuffle(array TSRMLS_CC); - - RETURN_TRUE; -} -/* }}} */ - - -/* HashTable* php_splice(HashTable *in_hash, int offset, int length, - zval ***list, int list_count, HashTable **removed) */ -HashTable* php_splice(HashTable *in_hash, int offset, int length, - zval ***list, int list_count, HashTable **removed) -{ - HashTable *out_hash = NULL; /* Output hashtable */ - int num_in, /* Number of entries in the input hashtable */ - pos, /* Current position in the hashtable */ - i; /* Loop counter */ - Bucket *p; /* Pointer to hash bucket */ - zval *entry; /* Hash entry */ - - /* If input hash doesn't exist, we have nothing to do */ - if (!in_hash) - return NULL; - - /* Get number of entries in the input hash */ - num_in = zend_hash_num_elements(in_hash); - - /* Clamp the offset.. */ - if (offset > num_in) - offset = num_in; - else if (offset < 0 && (offset=num_in+offset) < 0) - offset = 0; - - /* ..and the length */ - if (length < 0) { - length = num_in-offset+length; - } else if (offset+length > num_in) { - length = num_in-offset; - } - - /* Create and initialize output hash */ - ALLOC_HASHTABLE(out_hash); - zend_hash_init(out_hash, 0, NULL, ZVAL_PTR_DTOR, 0); - - /* Start at the beginning of the input hash and copy - entries to output hash until offset is reached */ - for (pos=0, p=in_hash->pListHead; pos<offset && p ; pos++, p=p->pListNext) { - /* Get entry and increase reference count */ - entry = *((zval **)p->pData); - entry->refcount++; - - /* Update output hash depending on key type */ - if (p->nKeyLength) - zend_hash_update(out_hash, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL); - else - zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL); - } - - /* If hash for removed entries exists, go until offset+length - and copy the entries to it */ - if (removed != NULL) { - for ( ; pos<offset+length && p; pos++, p=p->pListNext) { - entry = *((zval **)p->pData); - entry->refcount++; - if (p->nKeyLength) - zend_hash_update(*removed, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL); - else - zend_hash_next_index_insert(*removed, &entry, sizeof(zval *), NULL); - } - } else /* otherwise just skip those entries */ - for ( ; pos<offset+length && p; pos++, p=p->pListNext); - - /* If there are entries to insert.. */ - if (list != NULL) { - /* ..for each one, create a new zval, copy entry into it - and copy it into the output hash */ - for (i=0; i<list_count; i++) { - entry = *list[i]; - if (entry->refcount>=1000) { - zval *tmp = (zval *) emalloc(sizeof(zval)); - - *tmp = *entry; - zval_copy_ctor(tmp); - tmp->refcount = 1; - tmp->is_ref = 0; - entry = tmp; - } else { - entry->refcount++; - } - zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL); - } - } - - /* Copy the remaining input hash entries to the output hash */ - for ( ; p ; p=p->pListNext) { - entry = *((zval **)p->pData); - entry->refcount++; - if (p->nKeyLength) - zend_hash_update(out_hash, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL); - else - zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL); - } - - zend_hash_internal_pointer_reset(out_hash); - return out_hash; -} -/* }}} */ - - -/* {{{ proto int array_push(array stack, mixed var [, mixed ...]) - Pushes elements onto the end of the array */ -PHP_FUNCTION(array_push) -{ - zval ***args, /* Function arguments array */ - *stack, /* Input array */ - *new_var; /* Variable to be pushed */ - int i, /* Loop counter */ - argc; /* Number of function arguments */ - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - /* Get first argument and check that it's an array */ - stack = *args[0]; - if (Z_TYPE_P(stack) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument should be an array"); - efree(args); - RETURN_FALSE; - } - - /* For each subsequent argument, make it a reference, increase refcount, - and add it to the end of the array */ - for (i=1; i<argc; i++) { - new_var = *args[i]; - new_var->refcount++; - - zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var, sizeof(zval *), NULL); - } - - /* Clean up and return the number of values in the stack */ - efree(args); - RETVAL_LONG(zend_hash_num_elements(Z_ARRVAL_P(stack))); -} -/* }}} */ - - -/* {{{ void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int which_end) */ -static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end) -{ - zval **stack, /* Input stack */ - **val; /* Value to be popped */ - char *key = NULL; - int key_len = 0; - ulong index; - - /* Get the arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &stack) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(stack) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - if (zend_hash_num_elements(Z_ARRVAL_PP(stack)) == 0) { - return; - } - - /* Get the first or last value and copy it into the return value */ - if (off_the_end) - zend_hash_internal_pointer_end(Z_ARRVAL_PP(stack)); - else - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(stack)); - zend_hash_get_current_data(Z_ARRVAL_PP(stack), (void **)&val); - *return_value = **val; - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); - - /* Delete the first or last value */ - zend_hash_get_current_key_ex(Z_ARRVAL_PP(stack), &key, &key_len, &index, 0, NULL); - zend_hash_del_key_or_index(Z_ARRVAL_PP(stack), key, key_len, index, (key) ? HASH_DEL_KEY : HASH_DEL_INDEX); - - /* If we did a shift... re-index like it did before */ - if (!off_the_end) { - int k = 0; - int should_rehash = 0; - Bucket *p = Z_ARRVAL_PP(stack)->pListHead; - while (p != NULL) { - if (p->nKeyLength == 0) { - if (p->h != k) { - p->h = k++; - should_rehash = 1; - } else { - k++; - } - } - p = p->pListNext; - } - Z_ARRVAL_PP(stack)->nNextFreeElement = k; - if (should_rehash) { - zend_hash_rehash(Z_ARRVAL_PP(stack)); - } - } else if (!key_len) { - Z_ARRVAL_PP(stack)->nNextFreeElement = Z_ARRVAL_PP(stack)->nNextFreeElement - 1; - } - - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(stack)); -} -/* }}} */ - -/* {{{ proto mixed array_pop(array stack) - Pops an element off the end of the array */ -PHP_FUNCTION(array_pop) -{ - _phpi_pop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - - -/* {{{ proto mixed array_shift(array stack) - Pops an element off the beginning of the array */ -PHP_FUNCTION(array_shift) -{ - _phpi_pop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - - -/* {{{ proto int array_unshift(array stack, mixed var [, mixed ...]) - Pushes elements onto the beginning of the array */ -PHP_FUNCTION(array_unshift) -{ - zval ***args, /* Function arguments array */ - *stack; /* Input stack */ - HashTable *new_hash; /* New hashtable for the stack */ - int argc; /* Number of function arguments */ - - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - /* Get first argument and check that it's an array */ - stack = *args[0]; - if (Z_TYPE_P(stack) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - efree(args); - RETURN_FALSE; - } - - /* Use splice to insert the elements at the beginning. Destroy old - hashtable and replace it with new one */ - new_hash = php_splice(Z_ARRVAL_P(stack), 0, 0, &args[1], argc-1, NULL); - zend_hash_destroy(Z_ARRVAL_P(stack)); - efree(Z_ARRVAL_P(stack)); - Z_ARRVAL_P(stack) = new_hash; - - /* Clean up and return the number of elements in the stack */ - efree(args); - RETVAL_LONG(zend_hash_num_elements(Z_ARRVAL_P(stack))); -} -/* }}} */ - - -/* {{{ proto array array_splice(array input, int offset [, int length [, array replacement]]) - Removes the elements designated by offset and length and replace them with supplied array */ -PHP_FUNCTION(array_splice) -{ - zval ***args, /* Function arguments array */ - *array, /* Input array */ - ***repl = NULL; /* Replacement elements */ - HashTable *new_hash = NULL; /* Output array's hash */ - Bucket *p; /* Bucket used for traversing hash */ - int argc, /* Number of function arguments */ - i, - offset, - length, - repl_num = 0; /* Number of replacement elements */ - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2 || argc > 4) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - /* Get first argument and check that it's an array */ - array = *args[0]; - if (Z_TYPE_P(array) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - efree(args); - return; - } - - /* Get the next two arguments. If length is omitted, - it's assumed to be until the end of the array */ - convert_to_long_ex(args[1]); - offset = Z_LVAL_PP(args[1]); - if (argc > 2) { - convert_to_long_ex(args[2]); - length = Z_LVAL_PP(args[2]); - } else - length = zend_hash_num_elements(Z_ARRVAL_P(array)); - - if (argc == 4) { - /* Make sure the last argument, if passed, is an array */ - convert_to_array_ex(args[3]); - - /* Create the array of replacement elements */ - repl_num = zend_hash_num_elements(Z_ARRVAL_PP(args[3])); - repl = (zval ***)emalloc(repl_num * sizeof(zval **)); - for (p=Z_ARRVAL_PP(args[3])->pListHead, i=0; p; p=p->pListNext, i++) { - repl[i] = ((zval **)p->pData); - } - } - - /* Initialize return value */ - array_init(return_value); - - /* Perform splice */ - new_hash = php_splice(Z_ARRVAL_P(array), offset, length, - repl, repl_num, - &Z_ARRVAL_P(return_value)); - - /* Replace input array's hashtable with the new one */ - zend_hash_destroy(Z_ARRVAL_P(array)); - efree(Z_ARRVAL_P(array)); - Z_ARRVAL_P(array) = new_hash; - - /* Clean up */ - if (argc == 4) - efree(repl); - efree(args); -} -/* }}} */ - - -/* {{{ proto array array_slice(array input, int offset [, int length]) - Returns elements specified by offset and length */ -PHP_FUNCTION(array_slice) -{ - zval **input, /* Input array */ - **offset, /* Offset to get elements from */ - **length, /* How many elements to get */ - **entry; /* An array entry */ - int offset_val, /* Value of the offset argument */ - length_val, /* Value of the length argument */ - num_in, /* Number of elements in the input array */ - pos, /* Current position in the array */ - argc; /* Number of function arguments */ - - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition hpos; - - - /* Get the arguments and do error-checking */ - argc = ZEND_NUM_ARGS(); - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &input, &offset, &length)) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - return; - } - - /* Make sure offset and length are integers and assume - we want all entries from offset to the end if length - is not passed */ - convert_to_long_ex(offset); - offset_val = Z_LVAL_PP(offset); - if (argc == 3) { - convert_to_long_ex(length); - length_val = Z_LVAL_PP(length); - } else { - length_val = zend_hash_num_elements(Z_ARRVAL_PP(input)); - } - - /* Initialize returned array */ - array_init(return_value); - - /* Get number of entries in the input hash */ - num_in = zend_hash_num_elements(Z_ARRVAL_PP(input)); - - /* Clamp the offset.. */ - if (offset_val > num_in) - return; - else if (offset_val < 0 && (offset_val=num_in+offset_val) < 0) - offset_val = 0; - - /* ..and the length */ - if (length_val < 0) { - length_val = num_in-offset_val+length_val; - } else if (offset_val+length_val > num_in) { - length_val = num_in-offset_val; - } - - if (length_val == 0) - return; - - /* Start at the beginning and go until we hit offset */ - pos = 0; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &hpos); - while (pos < offset_val && - zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) { - pos++; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos); - } - - /* Copy elements from input array to the one that's returned */ - while (pos < offset_val+length_val && - zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) { - - (*entry)->refcount++; - - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &hpos)) { - case HASH_KEY_IS_STRING: - zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, - entry, sizeof(zval *), NULL); - break; - - case HASH_KEY_IS_LONG: - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), - entry, sizeof(zval *), NULL); - break; - } - pos++; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos); - } -} -/* }}} */ - - -PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC) -{ - zval **src_entry, - **dest_entry; - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - - zend_hash_internal_pointer_reset_ex(src, &pos); - while (zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) { - switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - if (recursive && - zend_hash_find(dest, string_key, string_key_len, - (void **)&dest_entry) == SUCCESS) { - if (*src_entry == *dest_entry) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected"); - return 0; - } - SEPARATE_ZVAL(dest_entry); - convert_to_array_ex(dest_entry); - convert_to_array_ex(src_entry); - if (!php_array_merge(Z_ARRVAL_PP(dest_entry), - Z_ARRVAL_PP(src_entry), recursive TSRMLS_CC)) - return 0; - } else { - (*src_entry)->refcount++; - - zend_hash_update(dest, string_key, strlen(string_key)+1, - src_entry, sizeof(zval *), NULL); - } - break; - - case HASH_KEY_IS_LONG: - (*src_entry)->refcount++; - zend_hash_next_index_insert(dest, src_entry, sizeof(zval *), NULL); - break; - } - - zend_hash_move_forward_ex(src, &pos); - } - - return 1; -} - -static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive) -{ - zval ***args = NULL; - int argc, - i; - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - array_init(return_value); - - for (i=0; i<argc; i++) { - SEPARATE_ZVAL(args[i]); - convert_to_array_ex(args[i]); - php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive TSRMLS_CC); - } - - efree(args); -} - - -/* {{{ proto array array_merge(array arr1, array arr2 [, array ...]) - Merges elements from passed arrays into one array */ -PHP_FUNCTION(array_merge) -{ - php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - - -/* {{{ proto array array_merge_recursive(array arr1, array arr2 [, array ...]) - Recursively merges elements from passed arrays into one array */ -PHP_FUNCTION(array_merge_recursive) -{ - php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - - -/* {{{ proto array array_keys(array input [, mixed search_value]) - Return just the keys from the input array, optionally only for the specified search_value */ -PHP_FUNCTION(array_keys) -{ - zval **input, /* Input array */ - **search_value, /* Value to search for */ - **entry, /* An entry in the input array */ - res, /* Result of comparison */ - *new_val; /* New value */ - int add_key; /* Flag to indicate whether a key should be added */ - char *string_key; /* String key */ - uint string_key_len; - ulong num_key; /* Numeric key */ - HashPosition pos; - - search_value = NULL; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &search_value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - return; - } - - /* Initialize return array */ - array_init(return_value); - add_key = 1; - - /* Go through input array and add keys to the return array */ - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) { - if (search_value != NULL) { - is_equal_function(&res, *search_value, *entry TSRMLS_CC); - add_key = zval_is_true(&res); - } - - if (add_key) { - MAKE_STD_ZVAL(new_val); - - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 1, &pos)) { - case HASH_KEY_IS_STRING: - Z_TYPE_P(new_val) = IS_STRING; - Z_STRVAL_P(new_val) = string_key; - Z_STRLEN_P(new_val) = string_key_len-1; - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val, - sizeof(zval *), NULL); - break; - - case HASH_KEY_IS_LONG: - Z_TYPE_P(new_val) = IS_LONG; - Z_LVAL_P(new_val) = num_key; - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val, - sizeof(zval *), NULL); - break; - } - } - - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos); - } -} -/* }}} */ - - -/* {{{ proto array array_values(array input) - Return just the values from the input array */ -PHP_FUNCTION(array_values) -{ - zval **input, /* Input array */ - **entry; /* An entry in the input array */ - HashPosition pos; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - /* Initialize return array */ - array_init(return_value); - - /* Go through input array and add values to the return array */ - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) { - - (*entry)->refcount++; - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry, - sizeof(zval *), NULL); - - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos); - } -} -/* }}} */ - - -/* {{{ proto array array_count_values(array input) - Return the value as key and the frequency of that value in input as value */ -PHP_FUNCTION(array_count_values) -{ - zval **input, /* Input array */ - **entry; /* An entry in the input array */ - zval **tmp; - HashTable *myht; - HashPosition pos; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - /* Initialize return array */ - array_init(return_value); - - /* Go through input array and add values to the return array */ - myht = Z_ARRVAL_PP(input); - zend_hash_internal_pointer_reset_ex(myht, &pos); - while (zend_hash_get_current_data_ex(myht, (void **)&entry, &pos) == SUCCESS) { - if (Z_TYPE_PP(entry) == IS_LONG) { - if (zend_hash_index_find(Z_ARRVAL_P(return_value), - Z_LVAL_PP(entry), - (void**)&tmp) == FAILURE) { - zval *data; - MAKE_STD_ZVAL(data); - Z_TYPE_P(data) = IS_LONG; - Z_LVAL_P(data) = 1; - zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL); - } else { - Z_LVAL_PP(tmp)++; - } - } else if (Z_TYPE_PP(entry) == IS_STRING) { - if (zend_hash_find(Z_ARRVAL_P(return_value), - Z_STRVAL_PP(entry), - Z_STRLEN_PP(entry)+1, - (void**)&tmp) == FAILURE) { - zval *data; - MAKE_STD_ZVAL(data); - Z_TYPE_P(data) = IS_LONG; - Z_LVAL_P(data) = 1; - zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL); - } else { - Z_LVAL_PP(tmp)++; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only count STRING and INTEGER values!"); - } - - zend_hash_move_forward_ex(myht, &pos); - } -} -/* }}} */ - - -/* {{{ proto array array_reverse(array input [, bool preserve keys]) - Return input as a new array with the order of the entries reversed */ -PHP_FUNCTION(array_reverse) -{ - zval **input, /* Input array */ - **z_preserve_keys, /* Flag: whether to preserve keys */ - **entry; /* An entry in the input array */ - char *string_key; - uint string_key_len; - ulong num_key; - zend_bool preserve_keys = 0; - HashPosition pos; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &z_preserve_keys) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - if (ZEND_NUM_ARGS() > 1) { - convert_to_boolean_ex(z_preserve_keys); - preserve_keys = Z_BVAL_PP(z_preserve_keys); - } - - /* Initialize return array */ - array_init(return_value); - - zend_hash_internal_pointer_end_ex(Z_ARRVAL_PP(input), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) { - (*entry)->refcount++; - - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len, - entry, sizeof(zval *), NULL); - break; - - case HASH_KEY_IS_LONG: - if (preserve_keys) - zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, - entry, sizeof(zval *), NULL); - else - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), - entry, sizeof(zval *), NULL); - break; - } - - zend_hash_move_backwards_ex(Z_ARRVAL_PP(input), &pos); - } -} -/* }}} */ - - -/* {{{ proto array array_pad(array input, int pad_size, mixed pad_value) - Returns a copy of input array padded with pad_value to size pad_size */ -PHP_FUNCTION(array_pad) -{ - zval **input; /* Input array */ - zval **pad_size; /* Size to pad to */ - zval **pad_value; /* Padding value obviously */ - zval ***pads; /* Array to pass to splice */ - HashTable *new_hash; /* Return value from splice */ - int input_size; /* Size of the input array */ - int pad_size_abs; /* Absolute value of pad_size */ - int num_pads; /* How many pads do we need */ - int do_pad; /* Whether we should do padding at all */ - int i; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &input, &pad_size, &pad_value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - /* Make sure arguments are of the proper type */ - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - convert_to_long_ex(pad_size); - - /* Do some initial calculations */ - input_size = zend_hash_num_elements(Z_ARRVAL_PP(input)); - pad_size_abs = abs(Z_LVAL_PP(pad_size)); - do_pad = (input_size >= pad_size_abs) ? 0 : 1; - - /* Copy the original array */ - *return_value = **input; - zval_copy_ctor(return_value); - - /* If no need to pad, no need to continue */ - if (!do_pad) - return; - - /* Populate the pads array */ - num_pads = pad_size_abs - input_size; - pads = (zval ***)emalloc(num_pads * sizeof(zval **)); - for (i = 0; i < num_pads; i++) - pads[i] = pad_value; - - /* Pad on the right or on the left */ - if (Z_LVAL_PP(pad_size) > 0) - new_hash = php_splice(Z_ARRVAL_P(return_value), input_size, 0, pads, num_pads, NULL); - else - new_hash = php_splice(Z_ARRVAL_P(return_value), 0, 0, pads, num_pads, NULL); - - - /* Copy the result hash into return value */ - zend_hash_destroy(Z_ARRVAL_P(return_value)); - efree(Z_ARRVAL_P(return_value)); - Z_ARRVAL_P(return_value) = new_hash; - - /* Clean up */ - efree(pads); -} -/* }}} */ - -/* {{{ proto array array_flip(array input) - Return array with key <-> value flipped */ -PHP_FUNCTION(array_flip) -{ - zval **array, **entry, *data; - HashTable *target_hash; - char *string_key; - uint str_key_len; - ulong num_key; - HashPosition pos; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - RETURN_FALSE; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset_ex(target_hash, &pos); - while (zend_hash_get_current_data_ex(target_hash, (void **)&entry, &pos) == SUCCESS) { - MAKE_STD_ZVAL(data); - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &str_key_len, &num_key, 1, &pos)) { - case HASH_KEY_IS_STRING: - Z_STRVAL_P(data) = string_key; - Z_STRLEN_P(data) = str_key_len-1; - Z_TYPE_P(data) = IS_STRING; - break; - case HASH_KEY_IS_LONG: - Z_TYPE_P(data) = IS_LONG; - Z_LVAL_P(data) = num_key; - break; - } - - if (Z_TYPE_PP(entry) == IS_LONG) { - zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL); - } else if (Z_TYPE_PP(entry) == IS_STRING) { - zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL); - } else { - zval_ptr_dtor(&data); /* will free also zval structure */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can only flip STRING and INTEGER values!"); - } - - zend_hash_move_forward_ex(target_hash, &pos); - } -} -/* }}} */ - -/* {{{ proto array array_change_key_case(array input [, int case=CASE_LOWER]) - Retuns an array with all string keys lowercased [or uppercased] */ -PHP_FUNCTION(array_change_key_case) -{ - zval **array, **entry, **to_upper; - char *string_key; - char *new_key; - uint str_key_len; - ulong num_key; - ulong change_to_upper=0; - - HashPosition pos; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &to_upper) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (ZEND_NUM_ARGS() > 1) { - convert_to_long_ex(to_upper); - change_to_upper = Z_LVAL_PP(to_upper); - } - - if (Z_TYPE_PP(array) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - RETURN_FALSE; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(array), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(array), (void **)&entry, &pos) == SUCCESS) { - (*entry)->refcount++; - - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(array), &string_key, &str_key_len, &num_key, 0, &pos)) { - case HASH_KEY_IS_LONG: - zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, entry, sizeof(entry), NULL); - break; - case HASH_KEY_IS_STRING: - new_key=estrndup(string_key,str_key_len); - if (change_to_upper) - php_strtoupper(new_key, str_key_len - 1); - else - php_strtolower(new_key, str_key_len - 1); - zend_hash_update(Z_ARRVAL_P(return_value), new_key, str_key_len, entry, sizeof(entry), NULL); - efree(new_key); - break; - } - - zend_hash_move_forward_ex(Z_ARRVAL_PP(array), &pos); - } -} -/* }}} */ - -/* {{{ proto array array_unique(array input) - Removes duplicate values from array */ -PHP_FUNCTION(array_unique) -{ - zval **array; - HashTable *target_hash; - Bucket *p; - struct bucketindex { - Bucket *b; - unsigned int i; - }; - struct bucketindex *arTmp, *cmpdata, *lastkept; - unsigned int i; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - RETURN_FALSE; - } - - /* copy the argument array */ - *return_value = **array; - zval_copy_ctor(return_value); - - if (target_hash->nNumOfElements <= 1) /* nothing to do */ - return; - - /* create and sort array with pointers to the target_hash buckets */ - arTmp = (struct bucketindex *) pemalloc((target_hash->nNumOfElements + 1) * sizeof(struct bucketindex), target_hash->persistent); - if (!arTmp) - RETURN_FALSE; - for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext) { - arTmp[i].b = p; - arTmp[i].i = i; - } - arTmp[i].b = NULL; - set_compare_func(SORT_STRING TSRMLS_CC); - zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), array_data_compare TSRMLS_CC); - - /* go through the sorted array and delete duplicates from the copy */ - lastkept = arTmp; - for (cmpdata = arTmp + 1; cmpdata->b; cmpdata++) { - if (array_data_compare(lastkept, cmpdata TSRMLS_CC)) { - lastkept = cmpdata; - } else { - if (lastkept->i > cmpdata->i) { - p = lastkept->b; - lastkept = cmpdata; - } else { - p = cmpdata->b; - } - if (p->nKeyLength) - zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength); - else - zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); - } - } - pefree(arTmp, target_hash->persistent); -} -/* }}} */ - -static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior) -{ - zval ***args = NULL; - HashTable *hash; - int argc, i, c = 0; - Bucket ***lists, **list, ***ptrs, *p; - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - /* for each argument, create and sort list with pointers to the hash buckets */ - lists = (Bucket ***)emalloc(argc * sizeof(Bucket **)); - ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **)); - set_compare_func(SORT_STRING TSRMLS_CC); - for (i=0; i<argc; i++) { - if (Z_TYPE_PP(args[i]) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i+1); - argc = i; /* only free up to i-1 */ - goto out; - } - hash = HASH_OF(*args[i]); - list = (Bucket **) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket *), hash->persistent); - if (!list) - RETURN_FALSE; - lists[i] = list; - ptrs[i] = list; - for (p = hash->pListHead; p; p = p->pListNext) - *list++ = p; - *list = NULL; - if (behavior == INTERSECT_NORMAL) { - zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); - } else if (behavior == INTERSECT_ASSOC) { - zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_key_compare TSRMLS_CC); - } - } - - /* copy the argument array */ - *return_value = **args[0]; - zval_copy_ctor(return_value); - - /* go through the lists and look for common values */ - while (*ptrs[0]) { - for (i=1; i<argc; i++) { - if (behavior == INTERSECT_NORMAL) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) - ptrs[i]++; - } else if (behavior == INTERSECT_ASSOC) { - while (*ptrs[i] && (0 < (c = array_key_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) - ptrs[i]++; - if (!c && *ptrs[i]) { /* this means that ptrs[i] is not NULL so we can compare */ - /* and "c==0" is from last operation */ - if (array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC) != 0) { - c = 1; - /* we are going to the break */ - } else { - /* continue looping */ - } - } - } - if (!*ptrs[i]) { - /* delete any values corresponding to remains of ptrs[0] */ - /* and exit because they do not present in at least one of */ - /* the other arguments */ - for (;;) { - p = *ptrs[0]++; - if (!p) - goto out; - if (p->nKeyLength) - zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength); - else - zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); - } - } - if (c) /* here we get if not all are equal */ - break; - ptrs[i]++; - } - if (c) { - /* Value of ptrs[0] not in all arguments, delete all entries */ - /* with value < value of ptrs[i] */ - for (;;) { - p = *ptrs[0]; - if (p->nKeyLength) - zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength); - else - zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); - if (!*++ptrs[0]) - goto out; - if (behavior == INTERSECT_NORMAL) { - if (0 <= array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)) - break; - } else if (behavior == INTERSECT_ASSOC) { - /* no need of looping because indexes are unique */ - break; - } - } - } else { - /* ptrs[0] is present in all the arguments */ - /* Skip all entries with same value as ptrs[0] */ - for (;;) { - if (!*++ptrs[0]) - goto out; - if (behavior == INTERSECT_NORMAL) { - if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) - break; - } else if (behavior == INTERSECT_ASSOC) { - /* no need of looping because indexes are unique */ - break; - } - } - } - } - -out: - for (i=0; i<argc; i++) { - hash = HASH_OF(*args[i]); - pefree(lists[i], hash->persistent); - } - efree(ptrs); - efree(lists); - efree(args); -} - -/* {{{ proto array array_intersect(array arr1, array arr2 [, array ...]) - Returns the entries of arr1 that have values which are present in all the other arguments */ -PHP_FUNCTION(array_intersect) -{ - php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_NORMAL); -} -/* }}} */ - -/* {{{ proto array array_intersect_assoc(array arr1, array arr2 [, array ...]) - Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrctive check */ -PHP_FUNCTION(array_intersect_assoc) -{ - php_array_intersect(INTERNAL_FUNCTION_PARAM_PASSTHRU, INTERSECT_ASSOC); -} -/* }}} */ - - -static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) -{ - zval ***args = NULL; - HashTable *hash; - int argc, i, c; - Bucket ***lists, **list, ***ptrs, *p; - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - /* for each argument, create and sort list with pointers to the hash buckets */ - lists = (Bucket ***)emalloc(argc * sizeof(Bucket **)); - ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **)); - set_compare_func(SORT_STRING TSRMLS_CC); - for (i = 0; i < argc; i++) { - if (Z_TYPE_PP(args[i]) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is not an array", i + 1); - argc = i; /* only free up to i-1 */ - goto out; - } - hash = HASH_OF(*args[i]); - list = (Bucket **) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket *), hash->persistent); - if (!list) { - RETURN_FALSE; - } - lists[i] = list; - ptrs[i] = list; - for (p = hash->pListHead; p; p = p->pListNext) { - *list++ = p; - } - *list = NULL; - if (behavior == DIFF_NORMAL) { - zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); - } else if (behavior == DIFF_ASSOC) { - zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_key_compare TSRMLS_CC); - } - } - - /* copy the argument array */ - *return_value = **args[0]; - zval_copy_ctor(return_value); - - /* go through the lists and look for values of ptr[0] - that are not in the others */ - while (*ptrs[0]) { - c = 1; - for (i = 1; i < argc; i++) { - if (behavior == DIFF_NORMAL) { - while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) { - ptrs[i]++; - } - } else if (behavior == DIFF_ASSOC) { - while (*ptrs[i] && (0 < (c = array_key_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) { - ptrs[i]++; - } - } - if (!c) { - if (behavior == DIFF_NORMAL) { - if (*ptrs[i]) { - ptrs[i]++; - } - break; - } else if (behavior == DIFF_ASSOC) { - if (*ptrs[i]) { - if (array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC) != 0) { - c = -1; - } else { - break; - } - } - } - } - } - if (!c) { - /* ptrs[0] in one of the other arguments */ - /* delete all entries with value as ptrs[0] */ - for (;;) { - p = *ptrs[0]; - if (p->nKeyLength) { - zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength); - } else { - zend_hash_index_del(Z_ARRVAL_P(return_value), p->h); - } - if (!*++ptrs[0]) { - goto out; - } - if (behavior == DIFF_NORMAL) { - if (array_data_compare(ptrs[0] - 1, ptrs[0] TSRMLS_CC)) { - break; - } - } else if (behavior == DIFF_ASSOC) { - /* in this case no array_key_compare is needed */ - break; - } - } - } else { - /* ptrs[0] in none of the other arguments */ - /* skip all entries with value as ptrs[0] */ - for (;;) { - if (!*++ptrs[0]) { - goto out; - } - if (behavior == DIFF_NORMAL) { - if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) { - break; - } - } else if (behavior == DIFF_ASSOC) { - /* in this case no array_key_compare is needed */ - break; - } - } - } - } -out: - for (i = 0; i < argc; i++) { - hash = HASH_OF(*args[i]); - pefree(lists[i], hash->persistent); - } - efree(ptrs); - efree(lists); - efree(args); -} - -/* {{{ proto array array_diff(array arr1, array arr2 [, array ...]) - Returns the entries of arr1 that have values which are not present in any of the others arguments */ -PHP_FUNCTION(array_diff) -{ - php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_NORMAL); -} -/* }}} */ - -/* {{{ proto array array_diff_assoc(array arr1, array arr2 [, array ...]) - Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal */ -PHP_FUNCTION(array_diff_assoc) -{ - php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_ASSOC); -} -/* }}} */ - - - -#define MULTISORT_ORDER 0 -#define MULTISORT_TYPE 1 -#define MULTISORT_LAST 2 - -int multisort_compare(const void *a, const void *b TSRMLS_DC) -{ - Bucket** ab = *(Bucket ***)a; - Bucket** bb = *(Bucket ***)b; - int r; - int result = 0; - zval temp; - - r = 0; - do { - set_compare_func(ARRAYG(multisort_flags)[MULTISORT_TYPE][r] TSRMLS_CC); - - ARRAYG(compare_func)(&temp, *((zval **)ab[r]->pData), *((zval **)bb[r]->pData) TSRMLS_CC); - result = ARRAYG(multisort_flags)[MULTISORT_ORDER][r] * Z_LVAL(temp); - if (result != 0) - return result; - r++; - } while (ab[r] != NULL); - return result; -} - -#define MULTISORT_ABORT \ - for (k = 0; k < MULTISORT_LAST; k++) \ - efree(ARRAYG(multisort_flags)[k]); \ - efree(arrays); \ - efree(args); \ - RETURN_FALSE; - -/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...]) - Sort multiple arrays at once similar to how ORDER BY clause works in SQL */ -PHP_FUNCTION(array_multisort) -{ - zval*** args; - zval*** arrays; - Bucket*** indirect; - Bucket* p; - HashTable* hash; - int argc; - int array_size; - int num_arrays = 0; - int parse_state[MULTISORT_LAST]; /* 0 - flag not allowed - 1 - flag allowed */ - int sort_order = SORT_ASC; - int sort_type = SORT_REGULAR; - int i, k; - - /* Get the argument count and check it */ - argc = ZEND_NUM_ARGS(); - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - /* Allocate space for storing pointers to input arrays and sort flags. */ - arrays = (zval ***)ecalloc(argc, sizeof(zval **)); - for (i = 0; i < MULTISORT_LAST; i++) { - parse_state[i] = 0; - ARRAYG(multisort_flags)[i] = (int *)ecalloc(argc, sizeof(int)); - } - - /* Here we go through the input arguments and parse them. Each one can - be either an array or a sort flag which follows an array. If not - specified, the sort flags defaults to SORT_ASC and SORT_REGULAR - accordingly. There can't be two sort flags of the same type after an - array, and the very first argument has to be an array. - */ - for (i = 0; i < argc; i++) { - if (Z_TYPE_PP(args[i]) == IS_ARRAY) { - /* We see the next array, so we update the sort flags of - the previous array and reset the sort flags. */ - if (i > 0) { - ARRAYG(multisort_flags)[MULTISORT_ORDER][num_arrays-1] = sort_order; - ARRAYG(multisort_flags)[MULTISORT_TYPE][num_arrays-1] = sort_type; - sort_order = SORT_ASC; - sort_type = SORT_REGULAR; - } - arrays[num_arrays++] = args[i]; - - /* Next one may be an array or a list of sort flags. */ - for (k = 0; k < MULTISORT_LAST; k++) - parse_state[k] = 1; - } else if (Z_TYPE_PP(args[i]) == IS_LONG) { - switch (Z_LVAL_PP(args[i])) { - case SORT_ASC: - case SORT_DESC: - /* flag allowed here */ - if (parse_state[MULTISORT_ORDER] == 1) { - /* Save the flag and make sure then next arg is not the current flag. */ - sort_order = Z_LVAL_PP(args[i]) == SORT_DESC ? -1 : 1; - parse_state[MULTISORT_ORDER] = 0; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i+1); - MULTISORT_ABORT; - } - break; - - case SORT_REGULAR: - case SORT_NUMERIC: - case SORT_STRING: - /* flag allowed here */ - if (parse_state[MULTISORT_TYPE] == 1) { - /* Save the flag and make sure then next arg is not the current flag. */ - sort_type = Z_LVAL_PP(args[i]); - parse_state[MULTISORT_TYPE] = 0; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1); - MULTISORT_ABORT; - } - break; - - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is an unknown sort flag", i + 1); - MULTISORT_ABORT; - break; - - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or a sort flag", i + 1); - MULTISORT_ABORT; - } - } - /* Take care of the last array sort flags. */ - ARRAYG(multisort_flags)[MULTISORT_ORDER][num_arrays-1] = sort_order; - ARRAYG(multisort_flags)[MULTISORT_TYPE][num_arrays-1] = sort_type; - - /* Make sure the arrays are of the same size. */ - array_size = zend_hash_num_elements(Z_ARRVAL_PP(arrays[0])); - for (i = 0; i < num_arrays; i++) { - if (zend_hash_num_elements(Z_ARRVAL_PP(arrays[i])) != array_size) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array sizes are inconsistent"); - MULTISORT_ABORT; - } - } - - /* If all arrays are empty or have only one entry, - we don't need to do anything. */ - if (array_size <= 1) { - for (k = 0; k < MULTISORT_LAST; k++) - efree(ARRAYG(multisort_flags)[k]); - efree(arrays); - efree(args); - RETURN_TRUE; - } - - /* Create the indirection array. This array is of size MxN, where - M is the number of entries in each input array and N is the number - of the input arrays + 1. The last column is NULL to indicate the end - of the row. - */ - indirect = (Bucket ***)emalloc(array_size * sizeof(Bucket **)); - for (i = 0; i < array_size; i++) - indirect[i] = (Bucket **)emalloc((num_arrays+1) * sizeof(Bucket *)); - - for (i = 0; i < num_arrays; i++) { - k = 0; - for (p = Z_ARRVAL_PP(arrays[i])->pListHead; p; p = p->pListNext, k++) { - indirect[k][i] = p; - } - } - for (k = 0; k < array_size; k++) - indirect[k][num_arrays] = NULL; - - /* Do the actual sort magic - bada-bim, bada-boom. */ - zend_qsort(indirect, array_size, sizeof(Bucket **), multisort_compare TSRMLS_CC); - - /* Restructure the arrays based on sorted indirect - this is mostly - taken from zend_hash_sort() function. */ - HANDLE_BLOCK_INTERRUPTIONS(); - for (i = 0; i < num_arrays; i++) { - hash = Z_ARRVAL_PP(arrays[i]); - hash->pListHead = indirect[0][i];; - hash->pListTail = NULL; - hash->pInternalPointer = hash->pListHead; - - for (k = 0; k < array_size; k++) { - if (hash->pListTail) { - hash->pListTail->pListNext = indirect[k][i]; - } - indirect[k][i]->pListLast = hash->pListTail; - indirect[k][i]->pListNext = NULL; - hash->pListTail = indirect[k][i]; - } - - p = hash->pListHead; - k = 0; - while (p != NULL) { - if (p->nKeyLength == 0) - p->h = k++; - p = p->pListNext; - } - hash->nNextFreeElement = array_size; - zend_hash_rehash(hash); - } - HANDLE_UNBLOCK_INTERRUPTIONS(); - - /* Clean up. */ - for (i = 0; i < array_size; i++) - efree(indirect[i]); - efree(indirect); - for (k = 0; k < MULTISORT_LAST; k++) - efree(ARRAYG(multisort_flags)[k]); - efree(arrays); - efree(args); - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto mixed array_rand(array input [, int num_req]) - Return key/keys for random entry/entries in the array */ -PHP_FUNCTION(array_rand) -{ - zval **input, **num_req; - long randval; - int num_req_val, num_avail, key_type; - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &num_req) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument has to be an array"); - return; - } - - num_avail = zend_hash_num_elements(Z_ARRVAL_PP(input)); - - if (ZEND_NUM_ARGS() > 1) { - convert_to_long_ex(num_req); - num_req_val = Z_LVAL_PP(num_req); - if (num_req_val <= 0 || num_req_val > num_avail) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument has to be between 1 and the number of elements in the array"); - return; - } - } else - num_req_val = 1; - - /* Make the return value an array only if we need to pass back more than one - result. */ - if (num_req_val > 1) - array_init(return_value); - - /* We can't use zend_hash_index_find() because the array may have string keys or gaps. */ - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - while (num_req_val && (key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTANT) { - - randval = php_rand(TSRMLS_C); - - if ((double)(randval/(PHP_RAND_MAX+1.0)) < (double)num_req_val/(double)num_avail) { - /* If we are returning a single result, just do it. */ - if (Z_TYPE_P(return_value) != IS_ARRAY) { - if (key_type == HASH_KEY_IS_STRING) { - RETURN_STRINGL(string_key, string_key_len-1, 1); - } else { - RETURN_LONG(num_key); - } - } else { - /* Append the result to the return value. */ - if (key_type == HASH_KEY_IS_STRING) - add_next_index_stringl(return_value, string_key, string_key_len-1, 1); - else - add_next_index_long(return_value, num_key); - } - num_req_val--; - } - num_avail--; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos); - } - - if (num_req_val == num_avail) { - array_data_shuffle(return_value TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto mixed array_sum(array input) - Returns the sum of the array entries */ - -PHP_FUNCTION(array_sum) -{ - zval **input, - **entry, - entry_n; - int argc = ZEND_NUM_ARGS(); - HashPosition pos; - double dval; - - if (argc != 1 || zend_get_parameters_ex(argc, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The argument should be an array"); - return; - } - - ZVAL_LONG(return_value, 0); - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) { - - if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT) - continue; - - entry_n = **entry; - zval_copy_ctor(&entry_n); - convert_scalar_to_number(&entry_n TSRMLS_CC); - - if (Z_TYPE(entry_n) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) { - dval = (double)Z_LVAL_P(return_value) + (double)Z_LVAL(entry_n); - if ( (double)LONG_MIN <= dval && dval <= (double)LONG_MAX ) { - Z_LVAL_P(return_value) += Z_LVAL(entry_n); - continue; - } - } - convert_to_double(return_value); - convert_to_double(&entry_n); - Z_DVAL_P(return_value) += Z_DVAL(entry_n); - } -} - -/* }}} */ - -/* {{{ proto mixed array_reduce(array input, mixed callback [, int initial]) - Iteratively reduce the array to a single value via the callback. */ -PHP_FUNCTION(array_reduce) -{ - zval **input, **callback, **initial; - zval **args[2]; - zval **operand; - zval *result = NULL; - zval *retval; - char *callback_name; - HashPosition pos; - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &callback, &initial) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - return; - } - - if (!zend_is_callable(*callback, 0, &callback_name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument, '%s', should be a valid callback", callback_name); - efree(callback_name); - return; - } - efree(callback_name); - - if (ZEND_NUM_ARGS() > 2) { - result = *initial; - zval_add_ref(&result); - } - - if (zend_hash_num_elements(Z_ARRVAL_PP(input)) == 0) { - if (result) { - *return_value = *result; - zval_copy_ctor(return_value); - } - return; - } - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&operand, &pos) == SUCCESS) { - if (result) { - args[0] = &result; - args[1] = operand; - if (call_user_function_ex(EG(function_table), NULL, *callback, &retval, 2, args, 0, NULL TSRMLS_CC) == SUCCESS && retval) { - zval_ptr_dtor(&result); - result = retval; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the reduction callback"); - return; - } - } else { - result = *operand; - zval_add_ref(&result); - } - - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos); - } - - *return_value = *result; - zval_copy_ctor(return_value); - zval_ptr_dtor(&result); -} -/* }}} */ - - -/* {{{ proto array array_filter(array input [, mixed callback]) - Filters elements from the array via the callback. */ -PHP_FUNCTION(array_filter) -{ - zval **input, **callback = NULL; - zval **operand; - zval **args[1]; - zval *retval = NULL; - char *callback_name; - char *string_key; - uint string_key_len; - ulong num_key; - HashPosition pos; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &callback) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(input) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be an array"); - return; - } - - if (ZEND_NUM_ARGS() > 1) { - if (!zend_is_callable(*callback, 0, &callback_name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument, '%s', should be a valid callback", callback_name); - efree(callback_name); - return; - } - efree(callback_name); - } - - array_init(return_value); - if (zend_hash_num_elements(Z_ARRVAL_PP(input)) == 0) - return; - - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos); - zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&operand, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) { - - if (callback) { - args[0] = operand; - if (call_user_function_ex(EG(function_table), NULL, *callback, &retval, 1, args, 0, NULL TSRMLS_CC) == SUCCESS && retval) { - if (!zend_is_true(retval)) { - zval_ptr_dtor(&retval); - continue; - } else - zval_ptr_dtor(&retval); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the filter callback"); - return; - } - } else if (!zend_is_true(*operand)) - continue; - - zval_add_ref(operand); - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - zend_hash_update(Z_ARRVAL_P(return_value), string_key, - string_key_len, operand, sizeof(zval *), NULL); - break; - - case HASH_KEY_IS_LONG: - zend_hash_index_update(Z_ARRVAL_P(return_value), num_key, - operand, sizeof(zval *), NULL); - break; - } - } -} -/* }}} */ - - -/* {{{ proto array array_map(mixed callback, array input1 [, array input2 ,...]) - Applies the callback to the elements in given arrays. */ -PHP_FUNCTION(array_map) -{ - zval ***args = NULL; - zval ***params; - zval *callback; - zval *result, *null; - HashPosition *array_pos; - char *callback_name; - int i, k, maxlen = 0; - int *array_len; - - if (ZEND_NUM_ARGS() < 2) { - WRONG_PARAM_COUNT; - } - - args = (zval ***)emalloc(ZEND_NUM_ARGS() * sizeof(zval **)); - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - RETVAL_NULL(); - - callback = *args[0]; - if (Z_TYPE_P(callback) != IS_NULL) { - if (!zend_is_callable(callback, 0, &callback_name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument, '%s', should be either NULL or a valid callback", callback_name); - efree(callback_name); - efree(args); - return; - } - efree(callback_name); - } - - /* Allocate array sizes and iterators. */ - array_len = (int*)emalloc((ZEND_NUM_ARGS()-1) * sizeof(int)); - array_pos = (HashPosition*)emalloc((ZEND_NUM_ARGS()-1) * sizeof(HashPosition)); - - /* Check that arrays are indeed arrays and calculate maximum size. */ - for (i = 0; i < ZEND_NUM_ARGS()-1; i++) { - if (Z_TYPE_PP(args[i+1]) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d should be an array", i + 2); - efree(array_len); - efree(array_pos); - efree(args); - return; - } - array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(args[i+1])); - if (array_len[i] > maxlen) - maxlen = array_len[i]; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(args[i+1]), &array_pos[i]); - } - - /* Short-circuit: if no callback and only one array, just return it. */ - if (Z_TYPE_P(callback) == IS_NULL && ZEND_NUM_ARGS() == 2) { - *return_value = **args[1]; - zval_copy_ctor(return_value); - efree(array_len); - efree(array_pos); - efree(args); - return; - } - - array_init(return_value); - params = (zval ***)emalloc((ZEND_NUM_ARGS()-1) * sizeof(zval **)); - MAKE_STD_ZVAL(null); - ZVAL_NULL(null); - - /* We iterate through all the arrays at once. */ - for (k = 0; k < maxlen; k++) { - uint str_key_len; - ulong num_key; - char *str_key; - int key_type = 0; - - /* - * If no callback, the result will be an array, consisting of current - * entries from all arrays. - */ - if (Z_TYPE_P(callback) == IS_NULL) { - MAKE_STD_ZVAL(result); - array_init(result); - } - - for (i = 0; i < ZEND_NUM_ARGS()-1; i++) { - /* - * If this array still hash elements, add the current one to the - * parameter list, otherwise use null value. - */ - if (k < array_len[i]) { - zend_hash_get_current_data_ex(Z_ARRVAL_PP(args[i+1]), (void **)¶ms[i], &array_pos[i]); - - /* - * It is safe to store only last value of key type, because - * this loop will run just once if there is only 1 array. - */ - if (ZEND_NUM_ARGS() == 2) { - key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(args[1]), &str_key, &str_key_len, &num_key, 0, &array_pos[i]); - } - - zend_hash_move_forward_ex(Z_ARRVAL_PP(args[i+1]), &array_pos[i]); - } else { - if (Z_TYPE_P(callback) == IS_NULL) - zval_add_ref(&null); - params[i] = &null; - } - - if (Z_TYPE_P(callback) == IS_NULL) - add_next_index_zval(result, *params[i]); - } - - if (Z_TYPE_P(callback) != IS_NULL) { - if (!call_user_function_ex(EG(function_table), NULL, callback, &result, ZEND_NUM_ARGS()-1, params, 0, NULL TSRMLS_CC) == SUCCESS && result) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred while invoking the map callback"); - efree(array_len); - efree(args); - efree(array_pos); - zval_dtor(return_value); - RETURN_NULL(); - } - } - - if (ZEND_NUM_ARGS() > 2) { - add_next_index_zval(return_value, result); - } else { - if (key_type == HASH_KEY_IS_STRING) - add_assoc_zval_ex(return_value, str_key, str_key_len, result); - else - add_index_zval(return_value, num_key, result); - } - } - - zval_ptr_dtor(&null); - efree(params); - efree(array_len); - efree(array_pos); - efree(args); -} -/* }}} */ - - -/* {{{ proto bool array_key_exists(mixed key, array search) - Checks if the given key or index exists in the array */ -PHP_FUNCTION(array_key_exists) -{ - zval **key, /* key to check for */ - **array; /* array to check in */ - - if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &key, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(array) != IS_ARRAY && Z_TYPE_PP(array) != IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument should be either an array or an object"); - RETURN_FALSE; - } - - switch (Z_TYPE_PP(key)) { - case IS_STRING: - if (zend_hash_exists(HASH_OF(*array), Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) { - RETURN_TRUE; - } - RETURN_FALSE; - - case IS_LONG: - if (zend_hash_index_exists(HASH_OF(*array), Z_LVAL_PP(key))) { - RETURN_TRUE; - } - RETURN_FALSE; - case IS_NULL: - if (zend_hash_exists(HASH_OF(*array), "", 1)) { - RETURN_TRUE; - } - RETURN_FALSE; - - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The first argument should be either a string or an integer"); - RETURN_FALSE; - } - -} -/* }}} */ - - -/* {{{ proto array array_chunk(array input, int size [, bool preserve_keys]) - Split array into chunks */ -PHP_FUNCTION(array_chunk) -{ - int argc = ZEND_NUM_ARGS(), key_type; - long size, current = 0; - char *str_key; - uint str_key_len; - ulong num_key; - zend_bool preserve_keys = 0; - zval *input = NULL; - zval *chunk = NULL; - zval **entry; - HashPosition pos; - - if (zend_parse_parameters(argc TSRMLS_CC, "al|b", &input, &size, - &preserve_keys) == FAILURE) - return; - - /* Do bounds checking for size parameter. */ - if (size < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Size parameter expected to be greater than 0"); - return; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(input), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(input), (void**)&entry, &pos) == SUCCESS) { - /* If new chunk, create and initialize it. */ - if (!chunk) { - MAKE_STD_ZVAL(chunk); - array_init(chunk); - } - - /* Add entry to the chunk, preserving keys if necessary. */ - zval_add_ref(entry); - - if (preserve_keys) { - key_type = zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &str_key, - &str_key_len, &num_key, 0, &pos); - if (key_type == HASH_KEY_IS_STRING) { - add_assoc_zval_ex(chunk, str_key, str_key_len, *entry); - } else { - add_index_zval(chunk, num_key, *entry); - } - } else { - add_next_index_zval(chunk, *entry); - } - - /* - * If reached the chunk size, add it to the result array, and reset the - * pointer. - */ - if (!(++current % size)) { - add_next_index_zval(return_value, chunk); - chunk = NULL; - } - - zend_hash_move_forward_ex(Z_ARRVAL_P(input), &pos); - } - - /* Add the final chunk if there is one. */ - if (chunk) { - add_next_index_zval(return_value, chunk); - } -} -/* }}} */ - -/* {{{ proto array array_combine(array keys, array values) - Creates an array by using the elements of the first parameter as keys and the elements of the second as correspoding keys */ -PHP_FUNCTION(array_combine) -{ - zval *values, *keys; - HashPosition pos_values, pos_keys; - zval **entry_keys, **entry_values; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "aa", &keys, &values) == FAILURE) { - return; - } - - if (zend_hash_num_elements(Z_ARRVAL_P(keys)) == 0 || zend_hash_num_elements(Z_ARRVAL_P(values)) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Both parameters should have number of elements at least 0"); - RETURN_FALSE; - } - - - if (zend_hash_num_elements(Z_ARRVAL_P(keys)) != zend_hash_num_elements(Z_ARRVAL_P(values))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Both parameters should have equal number of elements"); - RETURN_FALSE; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(keys), &pos_keys); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(values), &pos_values); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(keys), (void **)&entry_keys, &pos_keys) == SUCCESS && - zend_hash_get_current_data_ex(Z_ARRVAL_P(values), (void **)&entry_values, &pos_values) == SUCCESS) { - if (Z_TYPE_PP(entry_keys) == IS_STRING) { - zval_add_ref(entry_values); - add_assoc_zval(return_value, Z_STRVAL_PP(entry_keys), *entry_values); - } else if (Z_TYPE_PP(entry_keys) == IS_LONG) { - zval_add_ref(entry_values); - add_index_zval(return_value, Z_LVAL_PP(entry_keys), *entry_values); - } - zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_keys), &pos_keys); - zend_hash_move_forward_ex(Z_ARRVAL_PP(entry_values), &pos_values); - } -} -/* }}} */ - -/* - * 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/ext/standard/assert.c b/ext/standard/assert.c deleted file mode 100644 index a6b2cef218..0000000000 --- a/ext/standard/assert.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes/startup/misc */ - -#include "php.h" -#include "php_assert.h" -#include "php_ini.h" - -typedef struct { - long active; - long bail; - long warning; - long quiet_eval; - zval *callback; -} php_assert_globals; - -#ifdef ZTS -#define ASSERTG(v) TSRMG(assert_globals_id, php_assert_globals *, v) -int assert_globals_id; -#else -#define ASSERTG(v) (assert_globals.v) -php_assert_globals assert_globals; -#endif - -#define SAFE_STRING(s) ((s)?(s):"") - -enum { - ASSERT_ACTIVE=1, - ASSERT_CALLBACK, - ASSERT_BAIL, - ASSERT_WARNING, - ASSERT_QUIET_EVAL -}; - -static PHP_INI_MH(OnChangeCallback) -{ - if (ASSERTG(callback)) { - zval_ptr_dtor(&ASSERTG(callback)); - } - - MAKE_STD_ZVAL(ASSERTG(callback)); - - if (new_value) { - ZVAL_STRINGL(ASSERTG(callback), new_value, new_value_length, 1); - } else { - ZVAL_EMPTY_STRING(ASSERTG(callback)); - } - - return SUCCESS; -} - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("assert.active", "1", PHP_INI_ALL, OnUpdateInt, active, php_assert_globals, assert_globals) - STD_PHP_INI_ENTRY("assert.bail", "0", PHP_INI_ALL, OnUpdateInt, bail, php_assert_globals, assert_globals) - STD_PHP_INI_ENTRY("assert.warning", "1", PHP_INI_ALL, OnUpdateInt, warning, php_assert_globals, assert_globals) - PHP_INI_ENTRY ("assert.callback", NULL, PHP_INI_ALL, OnChangeCallback) - STD_PHP_INI_ENTRY("assert.quiet_eval", "0", PHP_INI_ALL, OnUpdateInt, quiet_eval, php_assert_globals, assert_globals) -PHP_INI_END() - -static void php_assert_init_globals(php_assert_globals *assert_globals_p TSRMLS_DC) -{ - ASSERTG(callback) = NULL; -} - -PHP_MINIT_FUNCTION(assert) -{ -#ifdef ZTS - ts_allocate_id(&assert_globals_id, sizeof(php_assert_globals), (ts_allocate_ctor) php_assert_init_globals, NULL); -#else - php_assert_init_globals(&assert_globals TSRMLS_CC); -#endif - - REGISTER_INI_ENTRIES(); - - REGISTER_LONG_CONSTANT("ASSERT_ACTIVE", ASSERT_ACTIVE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("ASSERT_CALLBACK", ASSERT_CALLBACK, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("ASSERT_BAIL", ASSERT_BAIL, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("ASSERT_WARNING", ASSERT_WARNING, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("ASSERT_QUIET_EVAL", ASSERT_QUIET_EVAL, CONST_CS|CONST_PERSISTENT); - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(assert) -{ - if (ASSERTG(callback)) { - zval_ptr_dtor(&ASSERTG(callback)); - } - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(assert) -{ - if (ASSERTG(callback)) { - zval_ptr_dtor(&ASSERTG(callback)); - ASSERTG(callback) = NULL; - } - - return SUCCESS; -} - -PHP_MINFO_FUNCTION(assert) -{ - DISPLAY_INI_ENTRIES(); -} - -/* }}} */ -/* {{{ internal functions */ -/* }}} */ -/* {{{ proto int assert(string|bool assertion) - Checks if assertion is false */ - -PHP_FUNCTION(assert) -{ - zval **assertion; - int val; - char *myeval = NULL; - char *compiled_string_description; - - if (! ASSERTG(active)) { - RETURN_TRUE; - } - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &assertion) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(assertion) == IS_STRING) { - zval retval; - int old_error_reporting = 0; /* shut up gcc! */ - - myeval = Z_STRVAL_PP(assertion); - - if (ASSERTG(quiet_eval)) { - old_error_reporting = EG(error_reporting); - EG(error_reporting) = 0; - } - - compiled_string_description = zend_make_compiled_string_description("assert code" TSRMLS_CC); - if (zend_eval_string(myeval, &retval, compiled_string_description TSRMLS_CC) == FAILURE) { - efree(compiled_string_description); - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Failure evaluating code:\n%s", myeval); - /* php_error_docref() does not return in this case. */ - } - efree(compiled_string_description); - - if (ASSERTG(quiet_eval)) { - EG(error_reporting) = old_error_reporting; - } - - convert_to_boolean(&retval); - val = Z_LVAL(retval); - } else { - convert_to_boolean_ex(assertion); - val = Z_LVAL_PP(assertion); - } - - if (val) { - RETURN_TRUE; - } - - if (ASSERTG(callback)) { - zval *args[3]; - zval *retval; - int i; - uint lineno = zend_get_executed_lineno(TSRMLS_C); - char *filename = zend_get_executed_filename(TSRMLS_C); - - MAKE_STD_ZVAL(args[0]); - MAKE_STD_ZVAL(args[1]); - MAKE_STD_ZVAL(args[2]); - - ZVAL_STRING(args[0], SAFE_STRING(filename), 1); - ZVAL_LONG (args[1], lineno); - ZVAL_STRING(args[2], SAFE_STRING(myeval), 1); - - MAKE_STD_ZVAL(retval); - ZVAL_FALSE(retval); - - /* XXX do we want to check for error here? */ - call_user_function(CG(function_table), NULL, ASSERTG(callback), retval, 3, args TSRMLS_CC); - - for (i = 0; i <= 2; i++) { - zval_ptr_dtor(&(args[i])); - } - zval_ptr_dtor(&retval); - } - - if (ASSERTG(warning)) { - if (myeval) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion \"%s\" failed", myeval); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Assertion failed"); - } - } - - if (ASSERTG(bail)) { - zend_bailout(); - } -} - -/* }}} */ -/* {{{ proto mixed assert_options(int what [, mixed value]) - Set/get the various assert flags */ - -PHP_FUNCTION(assert_options) -{ - pval **what, **value; - int oldint; - int ac = ZEND_NUM_ARGS(); - - if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &what, &value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(what); - - switch (Z_LVAL_PP(what)) { - case ASSERT_ACTIVE: - oldint = ASSERTG(active); - if (ac == 2) { - convert_to_long_ex(value); - ASSERTG(active) = Z_LVAL_PP(value); - } - RETURN_LONG(oldint); - break; - - case ASSERT_BAIL: - oldint = ASSERTG(bail); - if (ac == 2) { - convert_to_long_ex(value); - ASSERTG(bail) = Z_LVAL_PP(value); - } - RETURN_LONG(oldint); - break; - - case ASSERT_QUIET_EVAL: - oldint = ASSERTG(quiet_eval); - if (ac == 2) { - convert_to_long_ex(value); - ASSERTG(quiet_eval) = Z_LVAL_PP(value); - } - RETURN_LONG(oldint); - break; - - case ASSERT_WARNING: - oldint = ASSERTG(warning); - if (ac == 2) { - convert_to_long_ex(value); - ASSERTG(warning) = Z_LVAL_PP(value); - } - RETURN_LONG(oldint); - break; - - case ASSERT_CALLBACK: - if (ac == 2) { - if (ASSERTG(callback)) { - zval_ptr_dtor(&ASSERTG(callback)); - } - ASSERTG(callback) = *value; - zval_add_ref(value); - } - RETURN_TRUE; - break; - - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown value %d", Z_LVAL_PP(what)); - break; - } - - RETURN_FALSE; -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/base64.c b/ext/standard/base64.c deleted file mode 100644 index 2449fef373..0000000000 --- a/ext/standard/base64.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <string.h> - -#include "php.h" -#include "base64.h" - -/* {{{ */ -static const char base64_table[] = - { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' - }; - -static const char base64_pad = '='; - -static const short base64_reverse_table[256] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 -}; -/* }}} */ - -/* {{{ */ -PHPAPI unsigned char *php_base64_encode(const unsigned char *str, int length, int *ret_length) -{ - const unsigned char *current = str; - int i = 0; - unsigned char *result = (unsigned char *)emalloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char)); - - while (length > 2) { /* keep going until we have less than 24 bits */ - result[i++] = base64_table[current[0] >> 2]; - result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)]; - result[i++] = base64_table[current[2] & 0x3f]; - - current += 3; - length -= 3; /* we just handle 3 octets of data */ - } - - /* now deal with the tail end of things */ - if (length != 0) { - result[i++] = base64_table[current[0] >> 2]; - if (length > 1) { - result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)]; - result[i++] = base64_table[(current[1] & 0x0f) << 2]; - result[i++] = base64_pad; - } - else { - result[i++] = base64_table[(current[0] & 0x03) << 4]; - result[i++] = base64_pad; - result[i++] = base64_pad; - } - } - if(ret_length) { - *ret_length = i; - } - result[i] = '\0'; - return result; -} -/* }}} */ - -/* {{{ */ -/* generate reverse table (do not set index 0 to 64) -static unsigned short base64_reverse_table[256]; -#define rt base64_reverse_table -void php_base64_init() -{ - char *s = emalloc(10240), *sp; - char *chp; - short idx; - - for(ch = 0; ch < 256; ch++) { - chp = strchr(base64_table, ch); - if(ch && chp) { - idx = chp - base64_table; - if (idx >= 64) idx = -1; - rt[ch] = idx; - } else { - rt[ch] = -1; - } - } - sp = s; - sprintf(sp, "static const short base64_reverse_table[256] = {\n"); - for(ch =0; ch < 256;) { - sp = s+strlen(s); - sprintf(sp, "\t% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,% 3d,\n", rt[ch+0], rt[ch+1], rt[ch+2], rt[ch+3], rt[ch+4], rt[ch+5], rt[ch+6], rt[ch+7], rt[ch+8], rt[ch+9], rt[ch+10], rt[ch+11], rt[ch+12], rt[ch+13], rt[ch+14], rt[ch+15]); - ch += 16; - } - sprintf(sp, "};"); - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Reverse_table:\n%s", s); - efree(s); -} -*/ -/* }}} */ - -/* {{{ */ -/* as above, but backwards. :) */ -PHPAPI unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length) -{ - const unsigned char *current = str; - int ch, i = 0, j = 0, k; - /* this sucks for threaded environments */ - unsigned char *result; - - result = (unsigned char *)emalloc(length + 1); - if (result == NULL) { - return NULL; - } - - /* run through the whole string, converting as we go */ - while ((ch = *current++) != '\0' && length-- > 0) { - if (ch == base64_pad) break; - - /* When Base64 gets POSTed, all pluses are interpreted as spaces. - This line changes them back. It's not exactly the Base64 spec, - but it is completely compatible with it (the spec says that - spaces are invalid). This will also save many people considerable - headache. - Turadg Aleahmad <turadg@wise.berkeley.edu> - */ - - if (ch == ' ') ch = '+'; - - ch = base64_reverse_table[ch]; - if (ch < 0) continue; - - switch(i % 4) { - case 0: - result[j] = ch << 2; - break; - case 1: - result[j++] |= ch >> 4; - result[j] = (ch & 0x0f) << 4; - break; - case 2: - result[j++] |= ch >>2; - result[j] = (ch & 0x03) << 6; - break; - case 3: - result[j++] |= ch; - break; - } - i++; - } - - k = j; - /* mop things up if we ended on a boundary */ - if (ch == base64_pad) { - switch(i % 4) { - case 0: - case 1: - efree(result); - return NULL; - case 2: - k++; - case 3: - result[k++] = 0; - } - } - if(ret_length) { - *ret_length = j; - } - result[j] = '\0'; - return result; -} -/* }}} */ - -/* {{{ proto string base64_encode(string str) - Encodes string using MIME base64 algorithm */ -PHP_FUNCTION(base64_encode) -{ - char *str; - unsigned char *result; - int str_len, ret_length; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } - result = php_base64_encode(str, str_len, &ret_length); - if (result != NULL) { - RETVAL_STRINGL(result, ret_length, 0); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto string base64_decode(string str) - Decodes string using MIME base64 algorithm */ -PHP_FUNCTION(base64_decode) -{ - char *str; - unsigned char *result; - int str_len, ret_length; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } - result = php_base64_decode(str, str_len, &ret_length); - if (result != NULL) { - RETVAL_STRINGL(result, ret_length, 0); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/base64.h b/ext/standard/base64.h deleted file mode 100644 index ddae163c18..0000000000 --- a/ext/standard/base64.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef BASE64_H -#define BASE64_H - -PHP_FUNCTION(base64_decode); -PHP_FUNCTION(base64_encode); - -PHPAPI extern unsigned char *php_base64_encode(const unsigned char *, int, int *); -PHPAPI extern unsigned char *php_base64_decode(const unsigned char *, int, int *); - -#endif /* BASE64_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c deleted file mode 100644 index 84c1347f50..0000000000 --- a/ext/standard/basic_functions.c +++ /dev/null @@ -1,3047 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_streams.h" -#include "php_main.h" -#include "php_globals.h" -#include "php_ini.h" -#include "internal_functions_registry.h" -#include "php_standard.h" -#include "php_math.h" -#include "php_incomplete_class.h" -#include "ext/standard/info.h" -#include "ext/session/php_session.h" -#include "zend_operators.h" -#include "ext/standard/dns.h" - -#include <stdarg.h> -#include <stdlib.h> -#include <math.h> -#include <time.h> -#include <stdio.h> - -#ifndef NETWARE -#include <netdb.h> -#else -/*#include "netware/env.h"*/ /* Temporary */ -#ifdef NEW_LIBC /* Same headers hold good for Winsock and Berkeley sockets */ -#include <netinet/in.h> -/*#include <arpa/inet.h>*/ -#include <netdb.h> -#else -#include <sys/socket.h> -#endif -#endif - -#if HAVE_ARPA_INET_H -# include <arpa/inet.h> -#endif - -#if HAVE_UNISTD_H -# include <unistd.h> -#endif - -#if HAVE_STRING_H -# include <string.h> -#else -# include <strings.h> -#endif - -#if HAVE_LOCALE_H -# include <locale.h> -#endif - -#if HAVE_SYS_MMAN_H -# include <sys/mman.h> -#endif - -#ifdef HARTMUT_0 -#include <getopt.h> -#endif - -#include "safe_mode.h" - -#ifdef PHP_WIN32 -# include "win32/unistd.h" -#endif - -#include "zend_globals.h" -#include "php_globals.h" -#include "SAPI.h" -#include "php_ticks.h" - - -#ifdef ZTS -int basic_globals_id; -#else -php_basic_globals basic_globals; -#endif - - -#include "php_fopen_wrappers.h" - -static unsigned char first_and_second__args_force_ref[] = { 2, BYREF_FORCE, BYREF_FORCE }; -static unsigned char second_and_third_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; -static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE }; -static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; -static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST }; -static unsigned char first_through_third_args_force_ref[] = -{3, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE}; - - -typedef struct _php_shutdown_function_entry { - zval **arguments; - int arg_count; -} php_shutdown_function_entry; - -typedef struct _user_tick_function_entry { - zval **arguments; - int arg_count; - int calling; -} user_tick_function_entry; - -/* some prototypes for local functions */ -static void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry); -static void user_tick_function_dtor(user_tick_function_entry *tick_function_entry); - -/* Demo code. Enable only if you need this. */ -#define ENABLE_TEST_CLASS 0 - -#if ENABLE_TEST_CLASS -void test_class_startup(void); -pval test_class_get_property(zend_property_reference *property_reference); -int test_class_set_property(zend_property_reference *property_reference, pval *value); -void test_class_call_function(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference); - -pval test_class_get_property(zend_property_reference *property_reference) -{ - pval result; - zend_overloaded_element *overloaded_property; - zend_llist_element *element; - - printf("Reading a property from a OverloadedTestClass object:\n"); - - for (element = property_reference->elements_list->head; element; element = element->next) { - overloaded_property = (zend_overloaded_element *) element->data; - - switch (Z_TYPE_P(overloaded_property)) { - - case OE_IS_ARRAY: - printf("Array offset: "); - break; - - case OE_IS_OBJECT: - printf("Object property: "); - break; - } - - switch (Z_TYPE(overloaded_property->element)) { - - case IS_LONG: - printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element)); - break; - - case IS_STRING: - printf("'%s'\n", Z_STRVAL(overloaded_property->element)); - break; - } - pval_destructor(&overloaded_property->element); - } - - Z_STRVAL(result) = estrndup("testing", 7); - Z_STRLEN(result) = 7; - Z_TYPE(result) = IS_STRING; - return result; -} - -int test_class_set_property(zend_property_reference *property_reference, pval * value) -{ - zend_overloaded_element *overloaded_property; - zend_llist_element *element; - - printf("Writing to a property from a OverloadedTestClass object:\n"); - printf("Writing '"); - zend_print_variable(value); - printf("'\n"); - - for (element = property_reference->elements_list->head; element; element = element->next) { - overloaded_property = (zend_overloaded_element *) element->data; - - switch (Z_TYPE_P(overloaded_property)) { - - case OE_IS_ARRAY: - printf("Array offset: "); - break; - - case OE_IS_OBJECT: - printf("Object property: "); - break; - } - - switch (Z_TYPE(overloaded_property->element)) { - - case IS_LONG: - printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element)); - break; - - case IS_STRING: - printf("'%s'\n", Z_STRVAL(overloaded_property->element)); - break; - } - pval_destructor(&overloaded_property->element); - } - return 0; -} - -void test_class_call_function(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - zend_overloaded_element *overloaded_property; - zend_llist_element *element; - - printf("Invoking a method on OverloadedTestClass object:\n"); - - for (element = property_reference->elements_list->head; element; element = element->next) { - overloaded_property = (zend_overloaded_element *) element->data; - - switch (Z_TYPE_P(overloaded_property)) { - - case OE_IS_ARRAY: - printf("Array offset: "); - break; - - case OE_IS_OBJECT: - printf("Object property: "); - break; - - case OE_IS_METHOD: - printf("Overloaded method: "); - } - - switch (Z_TYPE(overloaded_property->element)) { - - case IS_LONG: - printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element)); - break; - - case IS_STRING: - printf("'%s'\n", Z_STRVAL(overloaded_property->element)); - break; - } - pval_destructor(&overloaded_property->element); - } - - printf("%d arguments\n", ZEND_NUM_ARGS()); - RETVAL_STRING("testing", 1); -} - -void test_class_startup(void) -{ - zend_class_entry test_class_entry; - TSRMLS_FETCH(); - - INIT_OVERLOADED_CLASS_ENTRY(test_class_entry, - "OverloadedTestClass", - NULL, test_class_call_function, - test_class_get_property, - test_class_set_property); - - zend_register_internal_class(&test_class_entry TSRMLS_CC); -} -#endif - - -function_entry basic_functions[] = { - PHP_FE(constant, NULL) - PHP_FE(bin2hex, NULL) - PHP_FE(sleep, NULL) - PHP_FE(usleep, NULL) - PHP_FE(time, NULL) - PHP_FE(mktime, NULL) - PHP_FE(gmmktime, NULL) - -#if HAVE_STRFTIME - PHP_FE(strftime, NULL) - PHP_FE(gmstrftime, NULL) -#endif - - PHP_FE(strtotime, NULL) - PHP_FE(date, NULL) - PHP_FE(idate, NULL) - PHP_FE(gmdate, NULL) - PHP_FE(getdate, NULL) - PHP_FE(localtime, NULL) - PHP_FE(checkdate, NULL) - - PHP_FE(flush, NULL) - PHP_FE(wordwrap, NULL) - PHP_FE(htmlspecialchars, NULL) - PHP_FE(htmlentities, NULL) - PHP_FE(html_entity_decode, NULL) - PHP_FE(get_html_translation_table, NULL) - PHP_FE(sha1, NULL) - PHP_FE(sha1_file, NULL) - PHP_NAMED_FE(md5,php_if_md5, NULL) - PHP_NAMED_FE(md5_file,php_if_md5_file, NULL) - PHP_NAMED_FE(crc32,php_if_crc32, NULL) - - PHP_FE(iptcparse, NULL) - PHP_FE(iptcembed, NULL) - PHP_FE(getimagesize, second_args_force_ref) - PHP_FE(image_type_to_mime_type, NULL) - - PHP_FE(phpinfo, NULL) - PHP_FE(phpversion, NULL) - PHP_FE(phpcredits, NULL) - PHP_FE(php_logo_guid, NULL) - PHP_FE(zend_logo_guid, NULL) - PHP_FE(php_sapi_name, NULL) - PHP_FE(php_uname, NULL) - PHP_FE(php_ini_scanned_files, NULL) - - PHP_FE(strnatcmp, NULL) - PHP_FE(strnatcasecmp, NULL) - PHP_FE(substr_count, NULL) - PHP_FE(strspn, NULL) - PHP_FE(strcspn, NULL) - PHP_FE(strtok, NULL) - PHP_FE(strtoupper, NULL) - PHP_FE(strtolower, NULL) - PHP_FE(strpos, NULL) - PHP_FE(stripos, NULL) - PHP_FE(strrpos, NULL) - PHP_FE(strripos, NULL) - PHP_FE(strrev, NULL) - PHP_FE(hebrev, NULL) - PHP_FE(hebrevc, NULL) - PHP_FE(nl2br, NULL) - PHP_FE(basename, NULL) - PHP_FE(dirname, NULL) - PHP_FE(pathinfo, NULL) - PHP_FE(stripslashes, NULL) - PHP_FE(stripcslashes, NULL) - PHP_FE(strstr, NULL) - PHP_FE(stristr, NULL) - PHP_FE(strrchr, NULL) - PHP_FE(str_shuffle, NULL) - PHP_FE(str_word_count, NULL) - PHP_FE(str_split, NULL) - PHP_FE(strpbrk, NULL) - -#ifdef HAVE_STRCOLL - PHP_FE(strcoll, NULL) -#endif - -#ifdef HAVE_STRFMON - PHP_FE(money_format, NULL) -#endif - - PHP_FE(substr, NULL) - PHP_FE(substr_replace, NULL) - PHP_FE(quotemeta, NULL) - PHP_FE(ucfirst, NULL) - PHP_FE(ucwords, NULL) - PHP_FE(strtr, NULL) - PHP_FE(addslashes, NULL) - PHP_FE(addcslashes, NULL) - PHP_FE(rtrim, NULL) - PHP_FE(str_replace, NULL) - PHP_FE(str_ireplace, NULL) - PHP_FE(str_repeat, NULL) - PHP_FE(count_chars, NULL) - PHP_FE(chunk_split, NULL) - PHP_FE(trim, NULL) - PHP_FE(ltrim, NULL) - PHP_FE(strip_tags, NULL) - PHP_FE(similar_text, third_arg_force_ref) - PHP_FE(explode, NULL) - PHP_FE(implode, NULL) - PHP_FE(setlocale, NULL) - PHP_FE(localeconv, NULL) - -#if HAVE_NL_LANGINFO - PHP_FE(nl_langinfo, NULL) -#endif - - PHP_FE(soundex, NULL) - PHP_FE(levenshtein, NULL) - PHP_FE(chr, NULL) - PHP_FE(ord, NULL) - PHP_FE(parse_str, second_arg_force_ref) - PHP_FE(str_pad, NULL) - PHP_FALIAS(chop, rtrim, NULL) - PHP_FALIAS(strchr, strstr, NULL) - PHP_NAMED_FE(sprintf, PHP_FN(user_sprintf), NULL) - PHP_NAMED_FE(printf, PHP_FN(user_printf), NULL) - PHP_FE(vprintf, NULL) - PHP_FE(vsprintf, NULL) - PHP_FE(fprintf, NULL) - PHP_FE(vfprintf, NULL) - PHP_FE(sscanf, third_and_rest_force_ref) - PHP_FE(fscanf, third_and_rest_force_ref) - PHP_FE(parse_url, NULL) - PHP_FE(urlencode, NULL) - PHP_FE(urldecode, NULL) - PHP_FE(rawurlencode, NULL) - PHP_FE(rawurldecode, NULL) - -#ifdef HAVE_SYMLINK - PHP_FE(readlink, NULL) - PHP_FE(linkinfo, NULL) - PHP_FE(symlink, NULL) - PHP_FE(link, NULL) -#endif - - PHP_FE(unlink, NULL) - PHP_FE(exec, second_and_third_args_force_ref) - PHP_FE(system, second_arg_force_ref) - PHP_FE(escapeshellcmd, NULL) - PHP_FE(escapeshellarg, NULL) - PHP_FE(passthru, second_arg_force_ref) - PHP_FE(shell_exec, NULL) -#ifdef PHP_CAN_SUPPORT_PROC_OPEN - PHP_FE(proc_open, third_arg_force_ref) - PHP_FE(proc_close, NULL) - PHP_FE(proc_terminate, NULL) - PHP_FE(proc_get_status, NULL) -#endif - -#ifdef HAVE_NICE - PHP_FE(proc_nice, NULL) -#endif - - PHP_FE(rand, NULL) - PHP_FE(srand, NULL) - PHP_FE(getrandmax, NULL) - PHP_FE(mt_rand, NULL) - PHP_FE(mt_srand, NULL) - PHP_FE(mt_getrandmax, NULL) - -#if HAVE_GETSERVBYNAME - PHP_FE(getservbyname, NULL) -#endif - -#if HAVE_GETSERVBYPORT - PHP_FE(getservbyport, NULL) -#endif - -#if HAVE_GETPROTOBYNAME - PHP_FE(getprotobyname, NULL) -#endif - -#if HAVE_GETPROTOBYNUMBER - PHP_FE(getprotobynumber, NULL) -#endif - - PHP_FE(getmyuid, NULL) - PHP_FE(getmygid, NULL) - PHP_FE(getmypid, NULL) - PHP_FE(getmyinode, NULL) - PHP_FE(getlastmod, NULL) - - PHP_FE(base64_decode, NULL) - PHP_FE(base64_encode, NULL) - - PHP_FE(abs, NULL) - PHP_FE(ceil, NULL) - PHP_FE(floor, NULL) - PHP_FE(round, NULL) - PHP_FE(sin, NULL) - PHP_FE(cos, NULL) - PHP_FE(tan, NULL) - PHP_FE(asin, NULL) - PHP_FE(acos, NULL) - PHP_FE(atan, NULL) - PHP_FE(atan2, NULL) - PHP_FE(sinh, NULL) - PHP_FE(cosh, NULL) - PHP_FE(tanh, NULL) - -#ifdef HAVE_ASINH - PHP_FE(asinh, NULL) -#endif -#ifdef HAVE_ACOSH - PHP_FE(acosh, NULL) -#endif -#ifdef HAVE_ATANH - PHP_FE(atanh, NULL) -#endif -#if !defined(PHP_WIN32) && !defined(NETWARE) - PHP_FE(expm1, NULL) - PHP_FE(log1p, NULL) -#endif - - PHP_FE(pi, NULL) - PHP_FE(is_finite, NULL) - PHP_FE(is_nan, NULL) - PHP_FE(is_infinite, NULL) - PHP_FE(pow, NULL) - PHP_FE(exp, NULL) - PHP_FE(log, NULL) - PHP_FE(log10, NULL) - PHP_FE(sqrt, NULL) - PHP_FE(hypot, NULL) - PHP_FE(deg2rad, NULL) - PHP_FE(rad2deg, NULL) - PHP_FE(bindec, NULL) - PHP_FE(hexdec, NULL) - PHP_FE(octdec, NULL) - PHP_FE(decbin, NULL) - PHP_FE(decoct, NULL) - PHP_FE(dechex, NULL) - PHP_FE(base_convert, NULL) - PHP_FE(number_format, NULL) - PHP_FE(fmod, NULL) - PHP_FE(ip2long, NULL) - PHP_FE(long2ip, NULL) - - PHP_FE(getenv, NULL) -#ifdef HAVE_PUTENV - PHP_FE(putenv, NULL) -#endif - -#ifdef HAVE_GETOPT - PHP_FE(getopt, NULL) -#endif - -#ifdef HAVE_GETTIMEOFDAY - PHP_FE(microtime, NULL) - PHP_FE(gettimeofday, NULL) -#endif - -#ifdef HAVE_GETRUSAGE - PHP_FE(getrusage, NULL) -#endif - -#ifdef HAVE_GETTIMEOFDAY - PHP_FE(uniqid, NULL) -#endif - - PHP_FE(quoted_printable_decode, NULL) - PHP_FE(convert_cyr_string, NULL) - PHP_FE(get_current_user, NULL) - PHP_FE(set_time_limit, NULL) - PHP_FE(get_cfg_var, NULL) - PHP_FALIAS(magic_quotes_runtime, set_magic_quotes_runtime, NULL) - PHP_FE(set_magic_quotes_runtime, NULL) - PHP_FE(get_magic_quotes_gpc, NULL) - PHP_FE(get_magic_quotes_runtime, NULL) - - PHP_FE(import_request_variables, NULL) - PHP_FE(error_log, NULL) - PHP_FE(call_user_func, NULL) - PHP_FE(call_user_func_array, NULL) - PHP_FE(call_user_method, second_arg_force_ref) - PHP_FE(call_user_method_array, second_arg_force_ref) - PHP_FE(serialize, NULL) - PHP_FE(unserialize, NULL) - - PHP_FE(var_dump, NULL) - PHP_FE(var_export, NULL) - PHP_FE(debug_zval_dump, NULL) - PHP_FE(print_r, NULL) -#if MEMORY_LIMIT - PHP_FE(memory_get_usage, NULL) -#endif - - PHP_FE(register_shutdown_function, NULL) - PHP_FE(register_tick_function, NULL) - PHP_FE(unregister_tick_function, NULL) - - PHP_FE(highlight_file, NULL) - PHP_FALIAS(show_source, highlight_file, NULL) - PHP_FE(highlight_string, NULL) - - PHP_FE(ini_get, NULL) - PHP_FE(ini_get_all, NULL) - PHP_FE(ini_set, NULL) - PHP_FALIAS(ini_alter, ini_set, NULL) - PHP_FE(ini_restore, NULL) - PHP_FE(get_include_path, NULL) - PHP_FE(set_include_path, NULL) - PHP_FE(restore_include_path, NULL) - - PHP_FE(setcookie, NULL) - PHP_FE(header, NULL) - PHP_FE(headers_sent, first_and_second__args_force_ref) - - PHP_FE(connection_aborted, NULL) - PHP_FE(connection_status, NULL) - PHP_FE(ignore_user_abort, NULL) - PHP_FE(parse_ini_file, NULL) - PHP_FE(is_uploaded_file, NULL) - PHP_FE(move_uploaded_file, NULL) - - /* functions from dns.c */ - PHP_FE(gethostbyaddr, NULL) - PHP_FE(gethostbyname, NULL) - PHP_FE(gethostbynamel, NULL) - -#if HAVE_RES_SEARCH && !(defined(__BEOS__) || defined(PHP_WIN32) || defined(NETWARE)) - PHP_FE(dns_check_record, NULL) - PHP_FALIAS(checkdnsrr, dns_check_record, NULL) -# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND - PHP_FE(dns_get_mx, second_and_third_args_force_ref) - PHP_FALIAS(getmxrr, dns_get_mx, second_and_third_args_force_ref) -# endif -# if HAVE_DNS_FUNCS - PHP_FE(dns_get_record, third_and_rest_force_ref) -# endif -#endif - - /* functions from type.c */ - PHP_FE(intval, NULL) - PHP_FE(floatval, NULL) - PHP_FALIAS(doubleval, floatval, NULL) - PHP_FE(strval, NULL) - PHP_FE(gettype, NULL) - PHP_FE(settype, first_arg_force_ref) - PHP_FE(is_null, NULL) - PHP_FE(is_resource, NULL) - PHP_FE(is_bool, NULL) - PHP_FE(is_long, NULL) - PHP_FE(is_float, NULL) - PHP_FALIAS(is_int, is_long, NULL) - PHP_FALIAS(is_integer, is_long, NULL) - PHP_FALIAS(is_double, is_float, NULL) - PHP_FALIAS(is_real, is_float, NULL) - PHP_FE(is_numeric, NULL) - PHP_FE(is_string, NULL) - PHP_FE(is_array, NULL) - PHP_FE(is_object, NULL) - PHP_FE(is_scalar, NULL) - PHP_FE(is_callable, third_arg_force_ref) - - /* functions from reg.c */ - PHP_FE(ereg, third_arg_force_ref) - PHP_FE(ereg_replace, NULL) - PHP_FE(eregi, third_arg_force_ref) - PHP_FE(eregi_replace, NULL) - PHP_FE(split, NULL) - PHP_FE(spliti, NULL) - PHP_FALIAS(join, implode, NULL) - PHP_FE(sql_regcase, NULL) - - /* functions from dl.c */ - PHP_FE(dl, NULL) - - /* functions from file.c */ - PHP_FE(pclose, NULL) - PHP_FE(popen, NULL) - PHP_FE(readfile, NULL) - PHP_FE(rewind, NULL) - PHP_FE(rmdir, NULL) - PHP_FE(umask, NULL) - PHP_FE(fclose, NULL) - PHP_FE(feof, NULL) - PHP_FE(fgetc, NULL) - PHP_FE(fgets, NULL) - PHP_FE(fgetss, NULL) - PHP_FE(fread, NULL) - PHP_STATIC_FE("fopen", php_if_fopen, NULL) - PHP_FE(fpassthru, NULL) - PHP_STATIC_FE("ftruncate", php_if_ftruncate, NULL) - PHP_STATIC_FE("fstat", php_if_fstat, NULL) - PHP_FE(fseek, NULL) - PHP_FE(ftell, NULL) - PHP_FE(fflush, NULL) - PHP_FE(fwrite, NULL) - PHP_FALIAS(fputs, fwrite, NULL) - PHP_FE(mkdir, NULL) - PHP_FE(rename, NULL) - PHP_FE(copy, NULL) - PHP_FE(tempnam, NULL) - PHP_STATIC_FE("tmpfile", php_if_tmpfile, NULL) - PHP_FE(file, NULL) - PHP_FE(file_get_contents, NULL) - PHP_FE(stream_select, first_through_third_args_force_ref) - PHP_FE(stream_context_create, NULL) - PHP_FE(stream_context_set_params, NULL) - PHP_FE(stream_context_set_option, NULL) - PHP_FE(stream_context_get_options, NULL) - PHP_FE(stream_filter_prepend, NULL) - PHP_FE(stream_filter_append, NULL) - PHP_FE(fgetcsv, NULL) - PHP_FE(flock, NULL) - PHP_FE(get_meta_tags, NULL) - PHP_FE(stream_set_write_buffer, NULL) - PHP_FALIAS(set_file_buffer, stream_set_write_buffer, NULL) - - PHP_FE(set_socket_blocking, NULL) - PHP_FE(stream_set_blocking, NULL) - PHP_FALIAS(socket_set_blocking, stream_set_blocking, NULL) - - PHP_FE(stream_get_meta_data, NULL) - PHP_FE(stream_get_line, NULL) - PHP_FE(stream_register_wrapper, NULL) - PHP_FE(stream_get_wrappers, NULL) - PHP_FE(get_headers, NULL) - -#if HAVE_SYS_TIME_H || defined(PHP_WIN32) - PHP_FE(stream_set_timeout, NULL) - PHP_FALIAS(socket_set_timeout, stream_set_timeout, NULL) -#endif - - PHP_FALIAS(socket_get_status, stream_get_meta_data, NULL) - -#if (!defined(PHP_WIN32) && !defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) - PHP_FE(realpath, NULL) -#endif - -#ifdef HAVE_FNMATCH - PHP_FE(fnmatch, NULL) -#endif - - /* functions from fsock.c */ - PHP_FE(fsockopen, third_and_fourth_args_force_ref) - PHP_FE(pfsockopen, third_and_fourth_args_force_ref) - - /* functions from pack.c */ - PHP_FE(pack, NULL) - PHP_FE(unpack, NULL) - - /* functions from browscap.c */ - PHP_FE(get_browser, NULL) - -#if HAVE_CRYPT - /* functions from crypt.c */ - PHP_FE(crypt, NULL) -#endif - - /* functions from dir.c */ - PHP_FE(opendir, NULL) - PHP_FE(closedir, NULL) - PHP_FE(chdir, NULL) - -#if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC - PHP_FE(chroot, NULL) -#endif - - PHP_FE(getcwd, NULL) - PHP_FE(rewinddir, NULL) - PHP_STATIC_FE("readdir", php_if_readdir, NULL) - PHP_FALIAS(dir, getdir, NULL) - PHP_FE(scandir, NULL) -#ifdef HAVE_GLOB - PHP_FE(glob, NULL) -#endif - /* functions from filestat.c */ - PHP_FE(fileatime, NULL) - PHP_FE(filectime, NULL) - PHP_FE(filegroup, NULL) - PHP_FE(fileinode, NULL) - PHP_FE(filemtime, NULL) - PHP_FE(fileowner, NULL) - PHP_FE(fileperms, NULL) - PHP_FE(filesize, NULL) - PHP_FE(filetype, NULL) - PHP_FE(file_exists, NULL) - PHP_FE(is_writable, NULL) - PHP_FALIAS(is_writeable, is_writable, NULL) - PHP_FE(is_readable, NULL) - PHP_FE(is_executable, NULL) - PHP_FE(is_file, NULL) - PHP_FE(is_dir, NULL) - PHP_FE(is_link, NULL) - PHP_STATIC_FE("stat", php_if_stat, NULL) - PHP_STATIC_FE("lstat", php_if_lstat, NULL) - PHP_FE(chown, NULL) - PHP_FE(chgrp, NULL) - PHP_FE(chmod, NULL) -#if HAVE_UTIME - PHP_FE(touch, NULL) -#endif - PHP_FE(clearstatcache, NULL) - PHP_FE(disk_total_space, NULL) - PHP_FE(disk_free_space, NULL) - PHP_FALIAS(diskfreespace, disk_free_space, NULL) - - /* functions from mail.c */ -#ifdef HAVE_SENDMAIL - PHP_FE(mail, NULL) - PHP_FE(ezmlm_hash, NULL) -#endif - - /* functions from syslog.c */ -#ifdef HAVE_SYSLOG_H - PHP_FE(openlog, NULL) - PHP_FE(syslog, NULL) - PHP_FE(closelog, NULL) - PHP_FE(define_syslog_variables, NULL) -#endif - - /* functions from lcg.c */ - PHP_FE(lcg_value, NULL) - - /* functions from metaphone.c */ - PHP_FE(metaphone, NULL) - - /* functions from output.c */ - PHP_FE(ob_start, NULL) - PHP_FE(ob_flush, NULL) - PHP_FE(ob_clean, NULL) - PHP_FE(ob_end_flush, NULL) - PHP_FE(ob_end_clean, NULL) - PHP_FE(ob_get_flush, NULL) - PHP_FE(ob_get_clean, NULL) - PHP_FE(ob_get_length, NULL) - PHP_FE(ob_get_level, NULL) - PHP_FE(ob_get_status, NULL) - PHP_FE(ob_get_contents, NULL) - PHP_FE(ob_implicit_flush, NULL) - PHP_FE(ob_list_handlers, NULL) - - /* functions from array.c */ - PHP_FE(ksort, first_arg_force_ref) - PHP_FE(krsort, first_arg_force_ref) - PHP_FE(natsort, first_arg_force_ref) - PHP_FE(natcasesort, first_arg_force_ref) - PHP_FE(asort, first_arg_force_ref) - PHP_FE(arsort, first_arg_force_ref) - PHP_FE(sort, first_arg_force_ref) - PHP_FE(rsort, first_arg_force_ref) - PHP_FE(usort, first_arg_force_ref) - PHP_FE(uasort, first_arg_force_ref) - PHP_FE(uksort, first_arg_force_ref) - PHP_FE(shuffle, first_arg_force_ref) - PHP_FE(array_walk, first_arg_force_ref) - PHP_FE(array_walk_recursive, first_arg_force_ref) - PHP_FE(count, NULL) - PHP_FE(end, first_arg_force_ref) - PHP_FE(prev, first_arg_force_ref) - PHP_FE(next, first_arg_force_ref) - PHP_FE(reset, first_arg_force_ref) - PHP_FE(current, first_arg_force_ref) - PHP_FE(key, first_arg_force_ref) - PHP_FE(min, NULL) - PHP_FE(max, NULL) - PHP_FE(in_array, NULL) - PHP_FE(array_search, NULL) - PHP_FE(extract, NULL) - PHP_FE(compact, NULL) - PHP_FE(array_fill, NULL) - PHP_FE(range, NULL) - PHP_FE(array_multisort, NULL) - PHP_FE(array_push, first_arg_force_ref) - PHP_FE(array_pop, first_arg_force_ref) - PHP_FE(array_shift, first_arg_force_ref) - PHP_FE(array_unshift, first_arg_force_ref) - PHP_FE(array_splice, first_arg_force_ref) - PHP_FE(array_slice, NULL) - PHP_FE(array_merge, NULL) - PHP_FE(array_merge_recursive, NULL) - PHP_FE(array_keys, NULL) - PHP_FE(array_values, NULL) - PHP_FE(array_count_values, NULL) - PHP_FE(array_reverse, NULL) - PHP_FE(array_reduce, NULL) - PHP_FE(array_pad, NULL) - PHP_FE(array_flip, NULL) - PHP_FE(array_change_key_case, NULL) - PHP_FE(array_rand, NULL) - PHP_FE(array_unique, NULL) - PHP_FE(array_intersect, NULL) - PHP_FE(array_intersect_assoc, NULL) - PHP_FE(array_diff, NULL) - PHP_FE(array_diff_assoc, NULL) - PHP_FE(array_sum, NULL) - PHP_FE(array_filter, NULL) - PHP_FE(array_map, NULL) - PHP_FE(array_chunk, NULL) - PHP_FE(array_combine, NULL) - PHP_FE(array_key_exists, NULL) - - /* aliases from array.c */ - PHP_FALIAS(pos, current, first_arg_force_ref) - PHP_FALIAS(sizeof, count, NULL) - PHP_FALIAS(key_exists, array_key_exists, NULL) - - /* functions from assert.c */ - PHP_FE(assert, NULL) - PHP_FE(assert_options, NULL) - - /* functions from versioning.c */ - PHP_FE(version_compare, NULL) - - /* functions from ftok.c*/ -#if HAVE_FTOK - PHP_FE(ftok, NULL) -#endif - - PHP_FE(str_rot13, NULL) - PHP_FE(stream_get_filters, NULL) - PHP_FE(stream_register_filter, NULL) - PHP_FE(stream_bucket_make_writeable, NULL) - PHP_FE(stream_bucket_prepend, NULL) - PHP_FE(stream_bucket_append, NULL) - PHP_FE(stream_bucket_new, NULL) - PHP_FE(stream_bucket, NULL) - - /* functions from aggregate.c */ - PHP_FE(aggregate, first_arg_force_ref) - PHP_FE(aggregate_methods, first_arg_force_ref) - PHP_FE(aggregate_methods_by_list, first_arg_force_ref) - PHP_FE(aggregate_properties, first_arg_force_ref) - PHP_FE(aggregate_properties_by_list, first_arg_force_ref) -#if (HAVE_PCRE || HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE) - PHP_FE(aggregate_methods_by_regexp, first_arg_force_ref) - PHP_FE(aggregate_properties_by_regexp, first_arg_force_ref) -#endif - PHP_FE(deaggregate, first_arg_force_ref) - PHP_FE(aggregate_info, first_arg_force_ref) - PHP_FALIAS(aggregation_info, aggregate_info, first_arg_force_ref) - - PHP_FE(output_add_rewrite_var, NULL) - PHP_FE(output_reset_rewrite_vars, NULL) - PHP_FE(date_sunrise, NULL) - PHP_FE(date_sunset, NULL) - - {NULL, NULL, NULL} -}; - - -static PHP_INI_MH(OnUpdateSafeModeProtectedEnvVars) -{ - char *protected_vars, *protected_var; - char *token_buf; - int dummy = 1; - - protected_vars = estrndup(new_value, new_value_length); - zend_hash_clean(&BG(sm_protected_env_vars)); - - protected_var = php_strtok_r(protected_vars, ", ", &token_buf); - while (protected_var) { - zend_hash_update(&BG(sm_protected_env_vars), protected_var, strlen(protected_var), &dummy, sizeof(int), NULL); - protected_var = php_strtok_r(NULL, ", ", &token_buf); - } - efree(protected_vars); - return SUCCESS; -} - - -static PHP_INI_MH(OnUpdateSafeModeAllowedEnvVars) -{ - if (BG(sm_allowed_env_vars)) { - free(BG(sm_allowed_env_vars)); - } - BG(sm_allowed_env_vars) = zend_strndup(new_value, new_value_length); - return SUCCESS; -} - - -PHP_INI_BEGIN() - PHP_INI_ENTRY_EX("safe_mode_protected_env_vars", SAFE_MODE_PROTECTED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeProtectedEnvVars, NULL) - PHP_INI_ENTRY_EX("safe_mode_allowed_env_vars", SAFE_MODE_ALLOWED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeAllowedEnvVars, NULL) - PHP_INI_ENTRY("date.default_latitude", DATE_DEFAULT_LATITUDE, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("date.default_longitude", DATE_DEFAULT_LONGITUDE, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("date.sunset_zenith", DATE_SUNSET_ZENITH, PHP_INI_ALL, NULL) - PHP_INI_ENTRY("date.sunrise_zenith", DATE_SUNRISE_ZENITH, PHP_INI_ALL, NULL) -PHP_INI_END() - - -zend_module_entry basic_functions_module = { - STANDARD_MODULE_HEADER, - "standard", /* extension name */ - basic_functions, /* function list */ - PHP_MINIT(basic), /* process startup */ - PHP_MSHUTDOWN(basic), /* process shutdown */ - PHP_RINIT(basic), /* request startup */ - PHP_RSHUTDOWN(basic), /* request shutdown */ - PHP_MINFO(basic), /* extension info */ - PHP_VERSION, /* extension version */ - STANDARD_MODULE_PROPERTIES -}; - - -#if defined(HAVE_PUTENV) -static void php_putenv_destructor(putenv_entry *pe) -{ - if (pe->previous_value) { - putenv(pe->previous_value); - } else { -# if HAVE_UNSETENV - unsetenv(pe->key); -# else - char **env; - - for (env = environ; env != NULL && *env != NULL; env++) { - if (!strncmp(*env, pe->key, pe->key_len) && (*env)[pe->key_len] == '=') { /* found it */ - *env = ""; - break; - } - } -# endif - } - efree(pe->putenv_string); - efree(pe->key); -} -#endif - - -static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC) -{ - BG(next) = NULL; - BG(left) = -1; - BG(user_tick_functions) = NULL; - BG(aggregation_table) = NULL; - BG(user_filter_map) = NULL; - zend_hash_init(&BG(sm_protected_env_vars), 5, NULL, NULL, 1); - BG(sm_allowed_env_vars) = NULL; - - memset(&BG(url_adapt_state), 0, sizeof(BG(url_adapt_state))); - memset(&BG(url_adapt_state_ex), 0, sizeof(BG(url_adapt_state_ex))); - - BG(incomplete_class) = php_create_incomplete_class(TSRMLS_C); -} - - -static void basic_globals_dtor(php_basic_globals *basic_globals_p TSRMLS_DC) -{ - zend_hash_destroy(&BG(sm_protected_env_vars)); - if (BG(sm_allowed_env_vars)) { - free(BG(sm_allowed_env_vars)); - } -} - - -PHP_MINIT_FUNCTION(basic) -{ -#ifdef ZTS - ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor); -#else - basic_globals_ctor(&basic_globals TSRMLS_CC); -#endif - - REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CONNECTION_NORMAL", PHP_CONNECTION_NORMAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CONNECTION_TIMEOUT", PHP_CONNECTION_TIMEOUT, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("INI_USER", ZEND_INI_USER, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("INI_PERDIR", ZEND_INI_PERDIR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("INI_SYSTEM", ZEND_INI_SYSTEM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("INI_ALL", ZEND_INI_ALL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("SUNFUNCS_RET_TIMESTAMP", SUNFUNCS_RET_TIMESTAMP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SUNFUNCS_RET_STRING", SUNFUNCS_RET_STRING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SUNFUNCS_RET_DOUBLE", SUNFUNCS_RET_DOUBLE, CONST_CS | CONST_PERSISTENT); - -#define REGISTER_MATH_CONSTANT(x) REGISTER_DOUBLE_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT) - REGISTER_MATH_CONSTANT(M_E); - REGISTER_MATH_CONSTANT(M_LOG2E); - REGISTER_MATH_CONSTANT(M_LOG10E); - REGISTER_MATH_CONSTANT(M_LN2); - REGISTER_MATH_CONSTANT(M_LN10); - REGISTER_MATH_CONSTANT(M_PI); - REGISTER_MATH_CONSTANT(M_PI_2); - REGISTER_MATH_CONSTANT(M_PI_4); - REGISTER_MATH_CONSTANT(M_1_PI); - REGISTER_MATH_CONSTANT(M_2_PI); - REGISTER_MATH_CONSTANT(M_2_SQRTPI); - REGISTER_MATH_CONSTANT(M_SQRT2); - REGISTER_MATH_CONSTANT(M_SQRT1_2); - -#if ENABLE_TEST_CLASS - test_class_startup(); -#endif - - REGISTER_INI_ENTRIES(); - - register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU); - register_html_constants(INIT_FUNC_ARGS_PASSTHRU); - register_string_constants(INIT_FUNC_ARGS_PASSTHRU); - - PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(standard_filters)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(user_filters)(INIT_FUNC_ARGS_PASSTHRU); - -#if defined(HAVE_LOCALECONV) && defined(ZTS) - PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU); -#endif - -#if defined(HAVE_NL_LANGINFO) - PHP_MINIT(nl_langinfo)(INIT_FUNC_ARGS_PASSTHRU); -#endif - -#if HAVE_CRYPT - PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU); -#endif - - PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU); - - PHP_MINIT(dir)(INIT_FUNC_ARGS_PASSTHRU); -#ifdef HAVE_SYSLOG_H - PHP_MINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU); -#endif - PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU); -#ifdef PHP_CAN_SUPPORT_PROC_OPEN - PHP_MINIT(proc_open)(INIT_FUNC_ARGS_PASSTHRU); -#endif - - PHP_MINIT(user_streams)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(imagetypes)(INIT_FUNC_ARGS_PASSTHRU); - - php_register_url_stream_wrapper("php", &php_stream_php_wrapper TSRMLS_CC); -#ifndef PHP_CURL_URL_WRAPPERS - php_register_url_stream_wrapper("http", &php_stream_http_wrapper TSRMLS_CC); - php_register_url_stream_wrapper("ftp", &php_stream_ftp_wrapper TSRMLS_CC); -# if HAVE_OPENSSL_EXT - php_register_url_stream_wrapper("https", &php_stream_http_wrapper TSRMLS_CC); - php_register_url_stream_wrapper("ftps", &php_stream_ftp_wrapper TSRMLS_CC); -# endif -#endif - -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) -# if HAVE_DNS_FUNCS - PHP_MINIT(dns)(INIT_FUNC_ARGS_PASSTHRU); -# endif -#endif - - return SUCCESS; -} - - -PHP_MSHUTDOWN_FUNCTION(basic) -{ -#ifdef ZTS - ts_free_id(basic_globals_id); -#else - basic_globals_dtor(&basic_globals TSRMLS_CC); -#endif - - php_unregister_url_stream_wrapper("php" TSRMLS_CC); -#ifndef PHP_CURL_URL_WRAPPERS - php_unregister_url_stream_wrapper("http" TSRMLS_CC); - php_unregister_url_stream_wrapper("ftp" TSRMLS_CC); -# if HAVE_OPENSSL_EXT - php_unregister_url_stream_wrapper("https" TSRMLS_CC); - php_unregister_url_stream_wrapper("ftps" TSRMLS_CC); -# endif -#endif - - UNREGISTER_INI_ENTRIES(); - - PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(file)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(standard_filters)(SHUTDOWN_FUNC_ARGS_PASSTHRU); -#if defined(HAVE_LOCALECONV) && defined(ZTS) - PHP_MSHUTDOWN(localeconv)(SHUTDOWN_FUNC_ARGS_PASSTHRU); -#endif - - return SUCCESS; -} - - -PHP_RINIT_FUNCTION(basic) -{ - memset(BG(strtok_table), 0, 256); - BG(strtok_string) = NULL; - BG(strtok_zval) = NULL; - BG(locale_string) = NULL; - BG(user_compare_func_name) = NULL; - BG(array_walk_func_name) = NULL; - BG(page_uid) = -1; - BG(page_gid) = -1; - BG(page_inode) = -1; - BG(page_mtime) = -1; -#ifdef HAVE_PUTENV - if (zend_hash_init(&BG(putenv_ht), 1, NULL, (void (*)(void *)) php_putenv_destructor, 0) == FAILURE) { - return FAILURE; - } -#endif - BG(user_shutdown_function_names) = NULL; - -#if HAVE_CRYPT - PHP_RINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU); -#endif - - PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU); - - PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU); -#ifdef HAVE_SYSLOG_H - PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU); -#endif - PHP_RINIT(dir)(INIT_FUNC_ARGS_PASSTHRU); - PHP_RINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU); - - /* Reset magic_quotes_runtime */ - PG(magic_quotes_runtime) = INI_BOOL("magic_quotes_runtime"); - - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(basic) -{ - if (BG(strtok_zval)) { - zval_ptr_dtor(&BG(strtok_zval)); - } - BG(strtok_string) = NULL; - BG(strtok_zval) = NULL; -#ifdef HAVE_PUTENV - zend_hash_destroy(&BG(putenv_ht)); -#endif - - /* Check if locale was changed and change it back - to the value in startup environment */ - if (BG(locale_string) != NULL) { - setlocale(LC_ALL, "C"); - setlocale(LC_CTYPE, ""); - } - STR_FREE(BG(locale_string)); - - PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU); -#ifdef HAVE_SYSLOG_H - PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU); -#endif - PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_RSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_RSHUTDOWN(streams)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - - if (BG(user_tick_functions)) { - zend_llist_destroy(BG(user_tick_functions)); - efree(BG(user_tick_functions)); - BG(user_tick_functions) = NULL; - } - - if (BG(aggregation_table)) { - zend_hash_destroy(BG(aggregation_table)); - efree(BG(aggregation_table)); - BG(aggregation_table) = NULL; - } - - if (BG(user_filter_map)) { - zend_hash_destroy(BG(user_filter_map)); - efree(BG(user_filter_map)); - BG(user_filter_map) = NULL; - } - - return SUCCESS; -} - - -PHP_MINFO_FUNCTION(basic) -{ - php_info_print_table_start(); - PHP_MINFO(regex)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); - PHP_MINFO(dl)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); - PHP_MINFO(mail)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); - php_info_print_table_end(); - PHP_MINFO(assert)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); -} - - -/* {{{ proto mixed constant(string const_name) - Given the name of a constant this function will return the constants associated value */ -PHP_FUNCTION(constant) -{ - zval **const_name; - - if (ZEND_NUM_ARGS() != 1 || - zend_get_parameters_ex(1, &const_name) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(const_name); - - if (!zend_get_constant(Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Couldn't find constant %s", Z_STRVAL_PP(const_name)); - RETURN_NULL(); - } -} -/* }}} */ - -/* {{{ proto int ip2long(string ip_address) - Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */ -PHP_FUNCTION(ip2long) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - - RETURN_LONG(ntohl(inet_addr(Z_STRVAL_PP(str)))); -} -/* }}} */ - -/* {{{ proto string long2ip(int proper_address) - Converts an (IPv4) Internet network address into a string in Internet standard dotted format */ -PHP_FUNCTION(long2ip) -{ - zval **num; - unsigned long n; - struct in_addr myaddr; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(num); - - n = strtoul(Z_STRVAL_PP(num), NULL, 0); - - myaddr.s_addr = htonl(n); - RETURN_STRING(inet_ntoa(myaddr), 1); -} -/* }}} */ - - -/******************** - * System Functions * - ********************/ - -/* {{{ proto string getenv(string varname) - Get the value of an environment variable */ -PHP_FUNCTION(getenv) -{ - char *ptr, *str; - int str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - RETURN_FALSE; - } - ptr = sapi_getenv(str, str_len TSRMLS_CC); - if (! ptr) { - ptr = getenv(str); - } - if (ptr) { - RETURN_STRING(ptr, 1); - } - RETURN_FALSE; -} -/* }}} */ - -#ifdef HAVE_PUTENV -/* {{{ proto bool putenv(string setting) - Set the value of an environment variable */ -PHP_FUNCTION(putenv) -{ - pval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if (Z_STRVAL_PP(str) && *(Z_STRVAL_PP(str))) { - char *p, **env; - putenv_entry pe; - - pe.putenv_string = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); - pe.key = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); - if ((p = strchr(pe.key, '='))) { /* nullify the '=' if there is one */ - *p = '\0'; - } - pe.key_len = strlen(pe.key); - - if (PG(safe_mode)) { - /* Check the protected list */ - if (zend_hash_exists(&BG(sm_protected_env_vars), pe.key, pe.key_len)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot override protected environment variable '%s'", pe.key); - efree(pe.putenv_string); - efree(pe.key); - RETURN_FALSE; - } - - /* Check the allowed list */ - if (BG(sm_allowed_env_vars) && *BG(sm_allowed_env_vars)) { - char *allowed_env_vars = estrdup(BG(sm_allowed_env_vars)); - char *allowed_prefix = strtok(allowed_env_vars, ", "); - zend_bool allowed = 0; - - while (allowed_prefix) { - if (!strncmp(allowed_prefix, pe.key, strlen(allowed_prefix))) { - allowed = 1; - break; - } - allowed_prefix = strtok(NULL, ", "); - } - efree(allowed_env_vars); - if (!allowed) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot set environment variable '%s' - it's not in the allowed list", pe.key); - efree(pe.putenv_string); - efree(pe.key); - RETURN_FALSE; - } - } - } - - zend_hash_del(&BG(putenv_ht), pe.key, pe.key_len+1); - - /* find previous value */ - pe.previous_value = NULL; - for (env = environ; env != NULL && *env != NULL; env++) { - if (!strncmp(*env, pe.key, pe.key_len) && (*env)[pe.key_len] == '=') { /* found it */ - pe.previous_value = *env; - break; - } - } - - if (putenv(pe.putenv_string) == 0) { /* success */ - zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL); -#ifdef HAVE_TZSET - if (!strncmp(pe.key, "TZ", 2)) { - tzset(); - } -#endif - RETURN_TRUE; - } else { - efree(pe.putenv_string); - efree(pe.key); - RETURN_FALSE; - } - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter syntax."); - RETURN_FALSE; -} -/* }}} */ -#endif - -#ifdef HAVE_GETOPT -/* {{{ free_argv - Free the memory allocated to an argv array. */ -static void free_argv(char **argv, int argc) -{ - int i; - - if (argv) { - for (i = 0; i < argc; i++) { - if (argv[i]) { - efree(argv[i]); - } - } - efree(argv); - } -} -/* }}} */ - -#ifdef HARTMUT_0 -/* {{{ free_longopts - Free the memory allocated to an longopt array. */ -static void free_longopts(struct option *longopts) -{ - struct option *p; - - if(longopts) { - for(p=longopts; p->name; p++) { - efree((char *)(p->name)); - } - - efree(longopts); - } -} -/* }}} */ -#endif - -/* {{{ proto array getopt(string options [, array longopts]) - Get options from the command line argument list */ -PHP_FUNCTION(getopt) -{ - char *options = NULL, **argv = NULL; - char opt[2] = { '\0' }; - char *optname; - int argc = 0, options_len = 0, o; - zval *val, **args = NULL, *p_longopts = NULL; -#ifdef HARTMUT_0 - struct option *longopts = NULL; - int longindex = 0; -#endif - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", - &options, &options_len, &p_longopts) == FAILURE) { - RETURN_FALSE; - } - - /* - * Get argv from the global symbol table. We calculate argc ourselves - * in order to be on the safe side, even though it is also available - * from the symbol table. - */ - if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), - (void **) &args) != FAILURE) { - int pos = 0; - zval **arg; - - argc = zend_hash_num_elements(Z_ARRVAL_PP(args)); - - /* - * Attempt to allocate enough memory to hold all of the arguments - * and a trailing NULL - */ - if ((argv = (char **) emalloc((argc + 1) * sizeof(char *))) == NULL) { - RETURN_FALSE; - } - - /* Reset the array indexes. */ - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args)); - - /* Iterate over the hash to construct the argv array. */ - while (zend_hash_get_current_data(Z_ARRVAL_PP(args), - (void **)&arg) == SUCCESS) { - argv[pos++] = estrdup(Z_STRVAL_PP(arg)); - zend_hash_move_forward(Z_ARRVAL_PP(args)); - } - - /* - * The C Standard requires argv[argc] to be NULL - this might - * keep some getopt implementations happy. - */ - argv[argc] = NULL; - } else { - /* Return false if we can't find argv. */ - RETURN_FALSE; - } - - if(p_longopts) { -#ifdef HARTMUT_0 - int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts)); - struct option *p; - zval **arg; - char *name; - - longopts = (struct option *)ecalloc(c+1, sizeof(struct option)); - - if(!longopts) RETURN_FALSE; - - /* Reset the array indexes. */ - zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts)); - p = longopts; - - /* Iterate over the hash to construct the argv array. */ - while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts), - (void **)&arg) == SUCCESS) { - - p->has_arg = 0; - name = estrdup(Z_STRVAL_PP(arg)); - len = strlen(name); - if((len > 0) && (name[len-1] == ':')) { - p->has_arg++; - name[len-1] = '\0'; - if((len > 1) && (name[len-2] == ':')) { - p->has_arg++; - name[len-2] = '\0'; - } - } - - p->name = name; - p->flag = NULL; - p->val = 0; - - zend_hash_move_forward(Z_ARRVAL_P(p_longopts)); - p++; - } -#else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No support for long options in this build"); -#endif - } - - /* Initialize the return value as an array. */ - array_init(return_value); - - /* Disable getopt()'s error messages. */ - opterr = 0; - - /* Invoke getopt(3) on the argument array. */ -#ifdef HARTMUT_0 - while ((o = getopt_long(argc, argv, options, longopts, &longindex)) != -1) { -#else - while ((o = getopt(argc, argv, options)) != -1) { -#endif - /* Skip unknown arguments. */ - if (o == '?') { - continue; - } - - /* Prepare the option character and the argument string. */ - if(o == 0) { -#ifdef HARTMUT_0 - optname = (char *)longopts[longindex].name; -#else - /* o == 0 shall never happen so this only fixes a compiler warning */ - optname = NULL; -#endif - } else { - if(o == 1) o = '-'; - opt[0] = o; - optname = opt; - } - - MAKE_STD_ZVAL(val); - if (optarg != NULL) { - ZVAL_STRING(val, optarg, 1); - } else { - ZVAL_FALSE(val); - } - - /* Add this option / argument pair to the result hash. */ - if(zend_hash_find(HASH_OF(return_value), optname, strlen(optname)+1, (void **)&args) != FAILURE) { - if(Z_TYPE_PP(args) != IS_ARRAY) { - convert_to_array_ex(args); - } - zend_hash_next_index_insert(HASH_OF(*args), (void *)&val, sizeof(zval *), NULL); - } else { - zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val, - sizeof(zval *), NULL); - } - } - - free_argv(argv, argc); -#ifdef HARTMUT_0 - free_longopts(longopts); -#endif -} -/* }}} */ -#endif - -/* {{{ proto void flush(void) - Flush the output buffer */ -PHP_FUNCTION(flush) -{ - sapi_flush(TSRMLS_C); -} -/* }}} */ - -/* {{{ proto void sleep(int seconds) - Delay for a given number of seconds */ -PHP_FUNCTION(sleep) -{ - pval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(num); - php_sleep(Z_LVAL_PP(num)); -} -/* }}} */ - -/* {{{ proto void usleep(int micro_seconds) - Delay for a given number of micro seconds */ -PHP_FUNCTION(usleep) -{ -#if HAVE_USLEEP - pval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(num); - usleep(Z_LVAL_PP(num)); -#endif -} -/* }}} */ - -/* {{{ proto string get_current_user(void) - Get the name of the owner of the current PHP script */ -PHP_FUNCTION(get_current_user) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_STRING(php_get_current_user(), 1); -} -/* }}} */ - -/* {{{ proto string get_cfg_var(string option_name) - Get the value of a PHP configuration option */ -PHP_FUNCTION(get_cfg_var) -{ - pval **varname; - char *value; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - - if (cfg_get_string(Z_STRVAL_PP(varname), &value) == FAILURE) { - RETURN_FALSE; - } - RETURN_STRING(value, 1); -} -/* }}} */ - -/* {{{ proto bool set_magic_quotes_runtime(int new_setting) - Set the current active configuration setting of magic_quotes_runtime and return previous */ -PHP_FUNCTION(set_magic_quotes_runtime) -{ - pval **new_setting; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_setting) == FAILURE) { - RETURN_FALSE; - } - convert_to_boolean_ex(new_setting); - - PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int get_magic_quotes_runtime(void) - Get the current active configuration setting of magic_quotes_runtime */ -PHP_FUNCTION(get_magic_quotes_runtime) -{ - RETURN_LONG(PG(magic_quotes_runtime)); -} - -/* }}} */ - -/* {{{ proto int get_magic_quotes_gpc(void) - Get the current active configuration setting of magic_quotes_gpc */ -PHP_FUNCTION(get_magic_quotes_gpc) -{ - RETURN_LONG(PG(magic_quotes_gpc)); -} -/* }}} */ - -/* - 1st arg = error message - 2nd arg = error option - 3rd arg = optional parameters (email address or tcp address) - 4th arg = used for additional headers if email - -error options: - 0 = send to php_error_log (uses syslog or file depending on ini setting) - 1 = send via email to 3rd parameter 4th option = additional headers - 2 = send via tcp/ip to 3rd parameter (name or ip:port) - 3 = save to file in 3rd parameter -*/ - -/* {{{ proto bool error_log(string message [, int message_type [, string destination [, string extra_headers]]]) - Send an error message somewhere */ -PHP_FUNCTION(error_log) -{ - pval **string, **erropt = NULL, **option = NULL, **emailhead = NULL; - int opt_err = 0; - char *message, *opt = NULL, *headers = NULL; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &string) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument 1 invalid"); - RETURN_FALSE; - } - break; - - case 2: - if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); - break; - - case 3: - if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); - convert_to_string_ex(option); - opt = Z_STRVAL_PP(option); - break; - - case 4: - if (zend_get_parameters_ex (4, &string, &erropt, &option, &emailhead) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments"); - RETURN_FALSE; - } - break; - - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(string); - message = Z_STRVAL_PP(string); - - if (erropt != NULL) { - convert_to_long_ex(erropt); - opt_err = Z_LVAL_PP(erropt); - } - - if (option != NULL) { - convert_to_string_ex(option); - opt = Z_STRVAL_PP(option); - } - - if (emailhead != NULL) { - convert_to_string_ex(emailhead); - headers = Z_STRVAL_PP(emailhead); - } - - if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - - -PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC) -{ - php_stream *stream = NULL; - - switch (opt_err) { - - case 1: /*send an email */ - { -#if HAVE_SENDMAIL - if (!php_mail(opt, "PHP error_log message", message, headers, NULL TSRMLS_CC)) { - return FAILURE; - } -#else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Mail option not available!"); - return FAILURE; -#endif - } - break; - - case 2: /*send to an address */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "TCP/IP option not available!"); - return FAILURE; - break; - - case 3: /*save to a file */ - stream = php_stream_open_wrapper(opt, "a", IGNORE_URL | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); - if (!stream) - return FAILURE; - php_stream_write(stream, message, strlen(message)); - php_stream_close(stream); - break; - - default: - php_log_err(message TSRMLS_CC); - break; - } - return SUCCESS; -} - -/* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...]) - Call a user function which is the first parameter */ -PHP_FUNCTION(call_user_func) -{ - zval ***params; - zval *retval_ptr; - char *name; - int argc = ZEND_NUM_ARGS(); - - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - params = emalloc(sizeof(zval **) * argc); - - if (zend_get_parameters_array_ex(argc, params) == FAILURE) { - efree(params); - RETURN_FALSE; - } - - if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) { - SEPARATE_ZVAL(params[0]); - convert_to_string_ex(params[0]); - } - - if (!zend_is_callable(*params[0], 0, &name)) { - php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "First argument is expected to be a valid callback"); - efree(name); - efree(params); - RETURN_NULL(); - } - - if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc-1, params+1, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - if (argc > 1) { - SEPARATE_ZVAL(params[1]); - convert_to_string_ex(params[1]); - if (argc > 2) { - SEPARATE_ZVAL(params[2]); - convert_to_string_ex(params[2]); - php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s,%s)", name, Z_STRVAL_PP(params[1]), Z_STRVAL_PP(params[2])); - } else { - php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s(%s)", name, Z_STRVAL_PP(params[1])); - } - } else { - php_error_docref1(NULL TSRMLS_CC, name, E_WARNING, "Unable to call %s()", name); - } - } - - efree(name); - efree(params); -} -/* }}} */ - -/* {{{ proto mixed call_user_func_array(string function_name, array parameters) - Call a user function which is the first parameter with the arguments contained in array */ -PHP_FUNCTION(call_user_func_array) -{ - zval ***func_params, **func, **params; - zval *retval_ptr; - HashTable *func_params_ht; - char *name; - int count; - int current = 0; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &func, ¶ms) == FAILURE) { - WRONG_PARAM_COUNT; - } - - SEPARATE_ZVAL(params); - convert_to_array_ex(params); - - if (Z_TYPE_PP(func) != IS_STRING && Z_TYPE_PP(func) != IS_ARRAY) { - SEPARATE_ZVAL(func); - convert_to_string_ex(func); - } - - if (!zend_is_callable(*func, 0, &name)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argumented is expected to be a valid callback, '%s' was given", name); - efree(name); - RETURN_NULL(); - } - - func_params_ht = Z_ARRVAL_PP(params); - - count = zend_hash_num_elements(func_params_ht); - func_params = emalloc(sizeof(zval **) * count); - - for (zend_hash_internal_pointer_reset(func_params_ht); - zend_hash_get_current_data(func_params_ht, (void **) &func_params[current]) == SUCCESS; - zend_hash_move_forward(func_params_ht) - ) { - current++; - } - - if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", name); - } - - efree(name); - efree(func_params); -} -/* }}} */ - -#define _CUM_DEPREC "This function is deprecated, use the call_user_func variety with the array(&$obj, \"method\") syntax instead" - -/* {{{ proto mixed call_user_method(string method_name, mixed object [, mixed parameter] [, mixed ...]) - Call a user method on a specific object or class */ -PHP_FUNCTION(call_user_method) -{ - zval ***params; - zval *retval_ptr; - int arg_count = ZEND_NUM_ARGS(); - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, _CUM_DEPREC); - - if (arg_count < 2) { - WRONG_PARAM_COUNT; - } - params = (zval ***) emalloc(sizeof(zval **) * arg_count); - - if (zend_get_parameters_array_ex(arg_count, params) == FAILURE) { - efree(params); - RETURN_FALSE; - } - if (Z_TYPE_PP(params[1]) != IS_OBJECT && Z_TYPE_PP(params[1]) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name"); - efree(params); - RETURN_FALSE; - } - - SEPARATE_ZVAL(params[0]); - convert_to_string(*params[0]); - - if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0])); - } - efree(params); -} -/* }}} */ - -/* {{{ proto mixed call_user_method_array(string method_name, mixed object, array params) - Call a user method on a specific object or class using a parameter array */ -PHP_FUNCTION(call_user_method_array) -{ - zval **method_name, **obj, **params, ***method_args = NULL, *retval_ptr; - HashTable *params_ar; - int num_elems, element = 0; - - php_error_docref(NULL TSRMLS_CC, E_NOTICE, _CUM_DEPREC); - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &method_name, &obj, ¶ms) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(obj) != IS_OBJECT && Z_TYPE_PP(obj) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument is not an object or class name"); - RETURN_FALSE; - } - - SEPARATE_ZVAL(method_name); - SEPARATE_ZVAL(params); - convert_to_string_ex(method_name); - convert_to_array_ex(params); - - params_ar = HASH_OF(*params); - num_elems = zend_hash_num_elements(params_ar); - method_args = (zval ***) emalloc(sizeof(zval **) *num_elems); - - for (zend_hash_internal_pointer_reset(params_ar); - zend_hash_get_current_data(params_ar, (void **) &(method_args[element])) == SUCCESS; - zend_hash_move_forward(params_ar) - ) { - element++; - } - - if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name)); - } - - efree(method_args); -} -/* }}} */ - - -void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry) -{ - int i; - - for (i = 0; i < shutdown_function_entry->arg_count; i++) { - zval_ptr_dtor(&shutdown_function_entry->arguments[i]); - } - efree(shutdown_function_entry->arguments); -} - -void user_tick_function_dtor(user_tick_function_entry *tick_function_entry) -{ - int i; - - for (i = 0; i < tick_function_entry->arg_count; i++) { - zval_ptr_dtor(&tick_function_entry->arguments[i]); - } - efree(tick_function_entry->arguments); -} - -static int user_shutdown_function_call(php_shutdown_function_entry *shutdown_function_entry TSRMLS_DC) -{ - zval retval; - - if (call_user_function( EG(function_table), NULL, - shutdown_function_entry->arguments[0], - &retval, - shutdown_function_entry->arg_count - 1, - shutdown_function_entry->arguments + 1 - TSRMLS_CC ) == SUCCESS ) { - zval_dtor(&retval); - - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(shutdown_function_entry->arguments[0])); - } - return 0; -} - -static void user_tick_function_call(user_tick_function_entry *tick_fe TSRMLS_DC) -{ - zval retval; - zval *function = tick_fe->arguments[0]; - - /* Prevent reentrant calls to the same user ticks function */ - if (! tick_fe->calling) { - tick_fe->calling = 1; - - if (call_user_function( EG(function_table), NULL, - function, - &retval, - tick_fe->arg_count - 1, - tick_fe->arguments+1 - TSRMLS_CC) == SUCCESS) { - zval_dtor(&retval); - - } else { - zval **obj, **method; - - if (Z_TYPE_P(function) == IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function)); - } else if ( Z_TYPE_P(function) == IS_ARRAY - && zend_hash_index_find(Z_ARRVAL_P(function), 0, (void **) &obj) == SUCCESS - && zend_hash_index_find(Z_ARRVAL_P(function), 1, (void **) &method) == SUCCESS - && Z_TYPE_PP(obj) == IS_OBJECT - && Z_TYPE_PP(method) == IS_STRING ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call %s::%s() - function does not exist", Z_OBJCE_PP(obj)->name, Z_STRVAL_PP(method)); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call tick function"); - } - } - - tick_fe->calling = 0; - } -} - -static void run_user_tick_functions(int tick_count) -{ - TSRMLS_FETCH(); - - zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call TSRMLS_CC); -} - -static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_tick_function_entry * tick_fe2) -{ - zval *func1 = tick_fe1->arguments[0]; - zval *func2 = tick_fe2->arguments[0]; - TSRMLS_FETCH(); - - if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) { - return (zend_binary_zval_strcmp(func1, func2) == 0); - } else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) { - zval result; - zend_compare_arrays(&result, func1, func2 TSRMLS_CC); - return (Z_LVAL(result) == 0); - } else { - return 0; - } -} - -void php_call_shutdown_functions(void) -{ - TSRMLS_FETCH(); - - if (BG(user_shutdown_function_names)) - zend_try { - zend_hash_apply(BG(user_shutdown_function_names), (apply_func_t) user_shutdown_function_call TSRMLS_CC); - memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); - zend_hash_destroy(BG(user_shutdown_function_names)); - efree(BG(user_shutdown_function_names)); - } - zend_end_try(); -} - -/* {{{ proto void register_shutdown_function(string function_name) - Register a user-level function to be called on request termination */ -PHP_FUNCTION(register_shutdown_function) -{ - php_shutdown_function_entry shutdown_function_entry; - int i; - - shutdown_function_entry.arg_count = ZEND_NUM_ARGS(); - - if (shutdown_function_entry.arg_count < 1) { - WRONG_PARAM_COUNT; - } - - shutdown_function_entry.arguments = (pval **) emalloc(sizeof(pval *) *shutdown_function_entry.arg_count); - - if (zend_get_parameters_array(ht, shutdown_function_entry.arg_count, shutdown_function_entry.arguments) == FAILURE) { - RETURN_FALSE; - } - if (!BG(user_shutdown_function_names)) { - ALLOC_HASHTABLE(BG(user_shutdown_function_names)); - zend_hash_init(BG(user_shutdown_function_names), 0, NULL, (void (*)(void *)) user_shutdown_function_dtor, 0); - } - - for (i = 0; i < shutdown_function_entry.arg_count; i++) { - shutdown_function_entry.arguments[i]->refcount++; - } - zend_hash_next_index_insert(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry), NULL); -} -/* }}} */ - - -ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini) -{ - syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment"); - syntax_highlighter_ini->highlight_default = INI_STR("highlight.default"); - syntax_highlighter_ini->highlight_html = INI_STR("highlight.html"); - syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword"); - syntax_highlighter_ini->highlight_string = INI_STR("highlight.string"); -} - -/* {{{ proto bool highlight_file(string file_name [, bool return] ) - Syntax highlight a source file */ -PHP_FUNCTION(highlight_file) -{ - zval *filename; - zend_syntax_highlighter_ini syntax_highlighter_ini; - zend_bool i = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &filename, &i) == FAILURE) { - RETURN_FALSE; - } - convert_to_string(filename); - - if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_P(filename), NULL, CHECKUID_ALLOW_ONLY_FILE))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_P(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - if (i) { - php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC); - } - - php_get_highlight_struct(&syntax_highlighter_ini); - - if (highlight_file(Z_STRVAL_P(filename), &syntax_highlighter_ini TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - - if (i) { - php_ob_get_buffer (return_value TSRMLS_CC); - php_end_ob_buffer (0, 0 TSRMLS_CC); - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto bool highlight_string(string string [, bool return] ) - Syntax highlight a string or optionally return it */ -PHP_FUNCTION(highlight_string) -{ - zval *expr; - zend_syntax_highlighter_ini syntax_highlighter_ini; - char *hicompiled_string_description; - zend_bool i = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &expr, &i) == FAILURE) { - RETURN_FALSE; - } - convert_to_string(expr); - - if (i) { - php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC); - } - - php_get_highlight_struct(&syntax_highlighter_ini); - - hicompiled_string_description = zend_make_compiled_string_description("highlighted code" TSRMLS_CC); - - if (highlight_string(expr, &syntax_highlighter_ini, hicompiled_string_description TSRMLS_CC) == FAILURE) { - efree(hicompiled_string_description); - RETURN_FALSE; - } - efree(hicompiled_string_description); - - if (i) { - php_ob_get_buffer (return_value TSRMLS_CC); - php_end_ob_buffer (0, 0 TSRMLS_CC); - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto string ini_get(string varname) - Get a configuration option */ -PHP_FUNCTION(ini_get) -{ - pval **varname; - char *str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - - str = zend_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0); - - if (!str) { - RETURN_FALSE; - } - - RETURN_STRING(str, 1); -} -/* }}} */ - - -static int php_ini_get_option(zend_ini_entry *ini_entry, int num_args, va_list args, zend_hash_key *hash_key) -{ - zval *ini_array = va_arg(args, zval *); - int module_number = va_arg(args, int); - zval *option; - - if (module_number != 0 && ini_entry->module_number != module_number) { - return 0; - } - - if (hash_key->nKeyLength == 0 || hash_key->arKey[0] != 0) { - - MAKE_STD_ZVAL(option); - array_init(option); - - if (ini_entry->orig_value) { - add_assoc_stringl(option, "global_value", ini_entry->orig_value, ini_entry->orig_value_length, 1); - } else if (ini_entry->value) { - add_assoc_stringl(option, "global_value", ini_entry->value, ini_entry->value_length, 1); - } else { - add_assoc_null(option, "global_value"); - } - - if (ini_entry->value) { - add_assoc_stringl(option, "local_value", ini_entry->value, ini_entry->value_length, 1); - } else { - add_assoc_null(option, "local_value"); - } - - add_assoc_long(option, "access", ini_entry->modifyable); - - add_assoc_zval_ex(ini_array, ini_entry->name, ini_entry->name_length, option); - } - return 0; -} - -/* {{{ proto array ini_get_all([string extension]) - Get all configuration options */ -PHP_FUNCTION(ini_get_all) -{ - char *extname = NULL; - int extname_len = 0, extnumber = 0; - zend_module_entry *module; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &extname, &extname_len) == FAILURE) { - RETURN_FALSE; - } - - zend_ini_sort_entries(TSRMLS_C); - - if (extname) { - if (zend_hash_find(&module_registry, extname, extname_len+1, (void **) &module) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find extension '%s'", extname); - RETURN_FALSE; - } - extnumber = module->module_number; - } - - array_init(return_value); - zend_hash_apply_with_arguments(EG(ini_directives), (apply_func_args_t) php_ini_get_option, 2, return_value, extnumber TSRMLS_CC); -} -/* }}} */ - -static int php_ini_check_path(char *option_name, int option_len, char *new_option_name, int new_option_len) -{ - if ( option_len != (new_option_len-1) ) { - return 0; - } - - return strncmp(option_name, new_option_name, option_len); -} - -/* {{{ proto string ini_set(string varname, string newvalue) - Set a configuration option, returns false on error and the old value of the configuration option on success */ -PHP_FUNCTION(ini_set) -{ - pval **varname, **new_value; - char *old_value; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &varname, &new_value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - convert_to_string_ex(new_value); - - old_value = zend_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0); - - /* copy to return here, because alter might free it! */ - if (old_value) { - RETVAL_STRING(old_value, 1); - } else { - RETVAL_FALSE; - } - -#define _CHECK_PATH(var, ini) php_ini_check_path(Z_STRVAL_PP(var), Z_STRLEN_PP(var), ini, sizeof(ini)) - - /* safe_mode & basedir check */ - if (PG(safe_mode) || PG(open_basedir)) { - if (_CHECK_PATH(varname, "error_log") || - _CHECK_PATH(varname, "java.class.path") || - _CHECK_PATH(varname, "java.home") || - _CHECK_PATH(varname, "java.library.path") || - _CHECK_PATH(varname, "session.save_path") || - _CHECK_PATH(varname, "vpopmail.directory")) { - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(new_value), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - zval_dtor(return_value); - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_PP(new_value) TSRMLS_CC)) { - zval_dtor(return_value); - RETURN_FALSE; - } - } - } - - /* checks that ensure the user does not overwrite certain ini settings when safe_mode is enabled */ - if (PG(safe_mode)) { - if (!strncmp("max_execution_time", Z_STRVAL_PP(varname), sizeof("max_execution_time")) || - !strncmp("memory_limit", Z_STRVAL_PP(varname), sizeof("memory_limit")) || - !strncmp("child_terminate", Z_STRVAL_PP(varname), sizeof("child_terminate"))) { - zval_dtor(return_value); - RETURN_FALSE; - } - } - - if (zend_alter_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, Z_STRVAL_PP(new_value), Z_STRLEN_PP(new_value), - PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == FAILURE) { - zval_dtor(return_value); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string ini_restore(string varname) - Restore the value of a configuration option specified by varname */ -PHP_FUNCTION(ini_restore) -{ - pval **varname; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - - zend_restore_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, PHP_INI_STAGE_RUNTIME); -} -/* }}} */ - -/* {{{ proto string set_include_path(string varname, string newvalue) - Sets the include_path configuration option */ - -PHP_FUNCTION(set_include_path) -{ - pval **new_value; - char *old_value; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_value) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(new_value); - old_value = zend_ini_string("include_path", sizeof("include_path"), 0); - /* copy to return here, because alter might free it! */ - if (old_value) { - RETVAL_STRING(old_value, 1); - } else { - RETVAL_FALSE; - } - if (zend_alter_ini_entry("include_path", sizeof("include_path"), - Z_STRVAL_PP(new_value), Z_STRLEN_PP(new_value), - PHP_INI_USER, PHP_INI_STAGE_RUNTIME) == FAILURE) { - zval_dtor(return_value); - RETURN_FALSE; - } -} - -/* }}} */ - -/* {{{ proto string get_include_path() - Get the current include_path configuration option */ - -PHP_FUNCTION(get_include_path) -{ - char *str; - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - str = zend_ini_string("include_path", sizeof("include_path"), 0); - if (str == NULL) { - RETURN_FALSE; - } - RETURN_STRING(str, 1); -} - -/* }}} */ - -/* {{{ proto string restore_include_path() - Restore the value of the include_path configuration option */ - -PHP_FUNCTION(restore_include_path) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - zend_restore_ini_entry("include_path", sizeof("include_path"), - PHP_INI_STAGE_RUNTIME); -} - -/* }}} */ - -/* {{{ proto bool print_r(mixed var [, bool return]) - Prints out or returns information about the specified variable */ -PHP_FUNCTION(print_r) -{ - zval *var; - zend_bool i = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &i) == FAILURE) { - RETURN_FALSE; - } - - if (i) { - php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC); - } - - zend_print_pval_r(var, 0 TSRMLS_CC); - - if (i) { - php_ob_get_buffer (return_value TSRMLS_CC); - php_end_ob_buffer (0, 0 TSRMLS_CC); - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* This should go back to PHP */ - -/* {{{ proto int connection_aborted(void) - Returns true if client disconnected */ -PHP_FUNCTION(connection_aborted) -{ - RETURN_LONG(PG(connection_status) & PHP_CONNECTION_ABORTED); -} -/* }}} */ - -/* {{{ proto int connection_status(void) - Returns the connection status bitfield */ -PHP_FUNCTION(connection_status) -{ - RETURN_LONG(PG(connection_status)); -} -/* }}} */ - -/* {{{ proto int ignore_user_abort(bool value) - Set whether we want to ignore a user abort event or not */ -PHP_FUNCTION(ignore_user_abort) -{ - pval **arg; - int old_setting; - - old_setting = PG(ignore_user_abort); - switch (ZEND_NUM_ARGS()) { - - case 0: - break; - - case 1: - if (zend_get_parameters_ex(1, &arg) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg); - zend_alter_ini_entry("ignore_user_abort", sizeof("ignore_user_abort"), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), PHP_INI_USER, PHP_INI_STAGE_RUNTIME); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - RETURN_LONG(old_setting); -} -/* }}} */ - -#if HAVE_GETSERVBYNAME -/* {{{ proto int getservbyname(string service, string protocol) - Returns port associated with service. Protocol must be "tcp" or "udp" */ -PHP_FUNCTION(getservbyname) -{ - pval **name, **proto; - struct servent *serv; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &name, &proto) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(name); - convert_to_string_ex(proto); - - serv = getservbyname(Z_STRVAL_PP(name), Z_STRVAL_PP(proto)); - - if (serv == NULL) { - RETURN_FALSE; - } - - RETURN_LONG(ntohs(serv->s_port)); -} -/* }}} */ -#endif - -#if HAVE_GETSERVBYPORT -/* {{{ proto string getservbyport(int port, string protocol) - Returns service name associated with port. Protocol must be "tcp" or "udp" */ -PHP_FUNCTION(getservbyport) -{ - pval **port, **proto; - struct servent *serv; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &port, &proto) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(port); - convert_to_string_ex(proto); - - serv = getservbyport(htons((unsigned short) Z_LVAL_PP(port)), Z_STRVAL_PP(proto)); - - if (serv == NULL) { - RETURN_FALSE; - } - - RETURN_STRING(serv->s_name, 1); -} -/* }}} */ -#endif - -#if HAVE_GETPROTOBYNAME -/* {{{ proto int getprotobyname(string name) - Returns protocol number associated with name as per /etc/protocols */ -PHP_FUNCTION(getprotobyname) -{ - pval **name; - struct protoent *ent; - - if (ZEND_NUM_ARGS() != 1 - || zend_get_parameters_ex(1, &name) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(name); - - ent = getprotobyname(Z_STRVAL_PP(name)); - - if (ent == NULL) { - Z_LVAL_P(return_value) = -1; - Z_TYPE_P(return_value) = IS_LONG; - RETURN_FALSE; - } - - RETURN_LONG(ent->p_proto); -} -/* }}} */ -#endif - -#if HAVE_GETPROTOBYNUMBER -/* {{{ proto string getprotobynumber(int proto) - Returns protocol name associated with protocol number proto */ -PHP_FUNCTION(getprotobynumber) -{ - pval **proto; - struct protoent *ent; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &proto) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(proto); - - ent = getprotobynumber(Z_LVAL_PP(proto)); - - if (ent == NULL) { - RETURN_FALSE; - } - - RETURN_STRING(ent->p_name, 1); -} -/* }}} */ -#endif - -/* {{{ proto bool register_tick_function(string function_name [, mixed arg [, mixed ... ]]) - Registers a tick callback function */ -PHP_FUNCTION(register_tick_function) -{ - user_tick_function_entry tick_fe; - int i; - - tick_fe.calling = 0; - tick_fe.arg_count = ZEND_NUM_ARGS(); - if (tick_fe.arg_count < 1) { - WRONG_PARAM_COUNT; - } - - tick_fe.arguments = (zval **) emalloc(sizeof(zval *) * tick_fe.arg_count); - - if (zend_get_parameters_array(ht, tick_fe.arg_count, tick_fe.arguments) == FAILURE) { - RETURN_FALSE; - } - - if (Z_TYPE_P(tick_fe.arguments[0]) != IS_ARRAY) - convert_to_string_ex(&tick_fe.arguments[0]); - - if (!BG(user_tick_functions)) { - BG(user_tick_functions) = (zend_llist *) emalloc(sizeof(zend_llist)); - zend_llist_init(BG(user_tick_functions), - sizeof(user_tick_function_entry), - (llist_dtor_func_t) user_tick_function_dtor, 0); - php_add_tick_function(run_user_tick_functions); - } - - for (i = 0; i < tick_fe.arg_count; i++) { - tick_fe.arguments[i]->refcount++; - } - - zend_llist_add_element(BG(user_tick_functions), &tick_fe); - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void unregister_tick_function(string function_name) - Unregisters a tick callback function */ -PHP_FUNCTION(unregister_tick_function) -{ - zval **function; - user_tick_function_entry tick_fe; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &function)) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(function) != IS_ARRAY) { - convert_to_string_ex(function); - } - - tick_fe.arguments = (zval **) emalloc(sizeof(zval *)); - tick_fe.arguments[0] = *function; - tick_fe.arg_count = 1; - zend_llist_del_element(BG(user_tick_functions), &tick_fe, (int (*)(void *, void *)) user_tick_function_compare); - efree(tick_fe.arguments); -} -/* }}} */ - -/* {{{ proto bool is_uploaded_file(string path) - Check if file was created by rfc1867 upload */ -PHP_FUNCTION(is_uploaded_file) -{ - zval **path; - - if (!SG(rfc1867_uploaded_files)) { - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &path) != SUCCESS) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(path); - - if (zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool move_uploaded_file(string path, string new_path) - Move a file if and only if it was created by an upload */ -PHP_FUNCTION(move_uploaded_file) -{ - zval **path, **new_path; - zend_bool successful = 0; - - if (!SG(rfc1867_uploaded_files)) { - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &path, &new_path) != SUCCESS) { - ZEND_WRONG_PARAM_COUNT(); - } - convert_to_string_ex(path); - convert_to_string_ex(new_path); - - if (!zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) { - RETURN_FALSE; - } - - if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(new_path), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_PP(new_path) TSRMLS_CC)) { - RETURN_FALSE; - } - - VCWD_UNLINK(Z_STRVAL_PP(new_path)); - if (rename(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path)) == 0) { - successful = 1; - } else - if (php_copy_file(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path) TSRMLS_CC) == SUCCESS) { - VCWD_UNLINK(Z_STRVAL_PP(path)); - successful = 1; - } - - if (successful) { - zend_hash_del(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to move '%s' to '%s'", Z_STRVAL_PP(path), Z_STRVAL_PP(new_path)); - } - RETURN_BOOL(successful); -} -/* }}} */ - - -static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr) -{ - zval *element; - - switch (callback_type) { - - case ZEND_INI_PARSER_ENTRY: - if (!arg2) { - /* bare string - nothing to do */ - break; - } - ALLOC_ZVAL(element); - *element = *arg2; - zval_copy_ctor(element); - INIT_PZVAL(element); - zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL); - break; - - case ZEND_INI_PARSER_POP_ENTRY: - { - zval *hash, **find_hash; - - if (!arg2) { - /* bare string - nothing to do */ - break; - } - - if (zend_hash_find(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void **) &find_hash) == FAILURE) { - ALLOC_ZVAL(hash); - INIT_PZVAL(hash); - array_init(hash); - - zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &hash, sizeof(zval *), NULL); - } else { - hash = *find_hash; - } - - ALLOC_ZVAL(element); - *element = *arg2; - zval_copy_ctor(element); - INIT_PZVAL(element); - add_next_index_zval(hash, element); - } - break; - - case ZEND_INI_PARSER_SECTION: - break; - } -} - -static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr) -{ - TSRMLS_FETCH(); - - if (callback_type == ZEND_INI_PARSER_SECTION) { - MAKE_STD_ZVAL(BG(active_ini_file_section)); - array_init(BG(active_ini_file_section)); - zend_hash_update( Z_ARRVAL_P(arr), - Z_STRVAL_P(arg1), - Z_STRLEN_P(arg1)+1, - &BG(active_ini_file_section), - sizeof(zval *), NULL); - } else if (arg2) { - zval *active_arr; - - if (BG(active_ini_file_section)) { - active_arr = BG(active_ini_file_section); - } else { - active_arr = arr; - } - - php_simple_ini_parser_cb(arg1, arg2, callback_type, active_arr); - } -} - - -/* {{{ proto array parse_ini_file(string filename [, bool process_sections]) - Parse configuration file */ -PHP_FUNCTION(parse_ini_file) -{ - zval **filename, **process_sections; - zend_file_handle fh; - zend_ini_parser_cb_t ini_parser_cb; - - switch (ZEND_NUM_ARGS()) { - - case 1: - if (zend_get_parameters_ex(1, &filename) == FAILURE) { - RETURN_FALSE; - } - ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb; - break; - - case 2: - if (zend_get_parameters_ex(2, &filename, &process_sections) == FAILURE) { - RETURN_FALSE; - } - - convert_to_boolean_ex(process_sections); - - if (Z_BVAL_PP(process_sections)) { - TSRMLS_FETCH(); - - BG(active_ini_file_section) = NULL; - ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections; - } else { - ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb; - } - break; - - default: - ZEND_WRONG_PARAM_COUNT(); - break; - } - - convert_to_string_ex(filename); - - memset(&fh, 0, sizeof(fh)); - fh.filename = Z_STRVAL_PP(filename); - Z_TYPE(fh) = ZEND_HANDLE_FILENAME; - - array_init(return_value); - zend_parse_ini_file(&fh, 0, ini_parser_cb, return_value); -} -/* }}} */ - -static int copy_request_variable(void *pDest, int num_args, va_list args, zend_hash_key *hash_key) -{ - char *prefix, *new_key; - uint prefix_len, new_key_len; - zval **var = (zval **) pDest; - TSRMLS_FETCH(); - - if (num_args != 2) { - return 0; - } - - prefix = va_arg(args, char *); - prefix_len = va_arg(args, uint); - - new_key_len = prefix_len + hash_key->nKeyLength; - new_key = (char *) emalloc(new_key_len); - - memcpy(new_key, prefix, prefix_len); - memcpy(new_key+prefix_len, hash_key->arKey, hash_key->nKeyLength); - - zend_hash_del(&EG(symbol_table), new_key, new_key_len); - ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), new_key, new_key_len, *var, (*var)->refcount+1, 0); - - efree(new_key); - return 0; -} - -/* {{{ proto bool import_request_variables(string types [, string prefix]) - Import GET/POST/Cookie variables into the global scope */ -PHP_FUNCTION(import_request_variables) -{ - zval **z_types, **z_prefix; - char *types, *prefix; - uint prefix_len; - char *p; - - switch (ZEND_NUM_ARGS()) { - - case 1: - if (zend_get_parameters_ex(1, &z_types) == FAILURE) { - RETURN_FALSE; - } - prefix = ""; - prefix_len = 0; - break; - - case 2: - if (zend_get_parameters_ex(2, &z_types, &z_prefix) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(z_prefix); - prefix = Z_STRVAL_PP(z_prefix); - prefix_len = Z_STRLEN_PP(z_prefix); - break; - - default: - ZEND_WRONG_PARAM_COUNT(); - } - - if (prefix_len == 0) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "No prefix specified - possible security hazard"); - } - - convert_to_string_ex(z_types); - types = Z_STRVAL_PP(z_types); - - for (p = types; p && *p; p++) { - switch (*p) { - - case 'g': - case 'G': - zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); - break; - - case 'p': - case 'P': - zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); - zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); - break; - - case 'c': - case 'C': - zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len); - break; - } - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ - diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h deleted file mode 100644 index 9c76f72818..0000000000 --- a/ext/standard/basic_functions.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef BASIC_FUNCTIONS_H -#define BASIC_FUNCTIONS_H - -#include <sys/stat.h> - -#include "zend_highlight.h" - -#include "url_scanner.h" -#include "url_scanner_ex.h" - -extern zend_module_entry basic_functions_module; -#define basic_functions_module_ptr &basic_functions_module - -PHP_MINIT_FUNCTION(basic); -PHP_MSHUTDOWN_FUNCTION(basic); -PHP_RINIT_FUNCTION(basic); -PHP_RSHUTDOWN_FUNCTION(basic); -PHP_MINFO_FUNCTION(basic); - -PHP_FUNCTION(constant); -PHP_FUNCTION(toggle_short_open_tag); -PHP_FUNCTION(sleep); -PHP_FUNCTION(usleep); -PHP_FUNCTION(flush); -PHP_FUNCTION(ip2long); -PHP_FUNCTION(long2ip); - -/* system functions */ -PHP_FUNCTION(getenv); -PHP_FUNCTION(putenv); - -PHP_FUNCTION(getopt); - -PHP_FUNCTION(get_current_user); -PHP_FUNCTION(set_time_limit); - -PHP_FUNCTION(get_cfg_var); -PHP_FUNCTION(set_magic_quotes_runtime); -PHP_FUNCTION(get_magic_quotes_runtime); -PHP_FUNCTION(get_magic_quotes_gpc); - -PHP_FUNCTION(import_request_variables); - -PHP_FUNCTION(error_log); - -PHP_FUNCTION(call_user_func); -PHP_FUNCTION(call_user_func_array); -PHP_FUNCTION(call_user_method); -PHP_FUNCTION(call_user_method_array); - -PHP_FUNCTION(register_shutdown_function); -PHP_FUNCTION(highlight_file); -PHP_FUNCTION(highlight_string); -ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini); - -PHP_FUNCTION(ini_get); -PHP_FUNCTION(ini_get_all); -PHP_FUNCTION(ini_set); -PHP_FUNCTION(ini_restore); -PHP_FUNCTION(get_include_path); -PHP_FUNCTION(set_include_path); -PHP_FUNCTION(restore_include_path); - -PHP_FUNCTION(print_r); -PHP_FUNCTION(fprintf); -PHP_FUNCTION(vfprintf); - -PHP_FUNCTION(connection_aborted); -PHP_FUNCTION(connection_status); -PHP_FUNCTION(ignore_user_abort); - -PHP_FUNCTION(getservbyname); -PHP_FUNCTION(getservbyport); -PHP_FUNCTION(getprotobyname); -PHP_FUNCTION(getprotobynumber); - -PHP_NAMED_FUNCTION(php_if_crc32); - -PHP_FUNCTION(register_tick_function); -PHP_FUNCTION(unregister_tick_function); - -PHP_FUNCTION(is_uploaded_file); -PHP_FUNCTION(move_uploaded_file); - -/* From the INI parser */ -PHP_FUNCTION(parse_ini_file); - -PHP_FUNCTION(str_rot13); -PHP_FUNCTION(stream_get_filters); -PHP_FUNCTION(stream_register_filter); -PHP_FUNCTION(stream_bucket_make_writeable); -PHP_FUNCTION(stream_bucket_prepend); -PHP_FUNCTION(stream_bucket_append); -PHP_FUNCTION(stream_bucket_new); -PHP_FUNCTION(stream_bucket); -PHP_MINIT_FUNCTION(user_filters); - -#ifdef PHP_WIN32 -typedef unsigned int php_stat_len; -#else -typedef int php_stat_len; -#endif - -PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC); - -#if SIZEOF_INT == 4 -/* Most 32-bit and 64-bit systems have 32-bit ints */ -typedef unsigned int php_uint32; -typedef signed int php_int32; -#elif SIZEOF_LONG == 4 -/* 16-bit systems? */ -typedef unsigned long php_uint32; -typedef signed int php_int32; -#else -#error Need type which holds 32 bits -#endif - -#define MT_N (624) - -typedef struct { - HashTable *user_shutdown_function_names; - HashTable putenv_ht; - zval *strtok_zval; - char *strtok_string; - char *locale_string; - char *strtok_last; - char strtok_table[256]; - ulong strtok_len; - char str_ebuf[40]; - zval **array_walk_func_name; - zval **user_compare_func_name; - zend_llist *user_tick_functions; - - zval *active_ini_file_section; - - HashTable sm_protected_env_vars; - char *sm_allowed_env_vars; - - /* pageinfo.c */ - long page_uid; - long page_gid; - long page_inode; - long page_mtime; - - /* filestat.c */ - char *CurrentStatFile; - php_stat_len CurrentStatLength; - struct stat sb; - struct stat lsb; - - /* rand.c */ - php_uint32 state[MT_N+1]; /* state vector + 1 extra to not violate ANSI C */ - php_uint32 *next; /* next random value is computed from here */ - int left; /* can *next++ this many times before reloading */ - - unsigned int rand_seed; /* Seed for rand(), in ts version */ - - zend_bool rand_is_seeded; /* Whether rand() has been seeded */ - zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */ - - /* syslog.c */ - int syslog_started; - char *syslog_device; - - /* var.c */ - zend_class_entry *incomplete_class; - - /* url_scanner.c */ - url_adapt_state_t url_adapt_state; - /* url_scanner_ex.re */ - url_adapt_state_ex_t url_adapt_state_ex; - -#ifdef HAVE_MMAP - void *mmap_file; - size_t mmap_len; -#endif - - HashTable *aggregation_table; - HashTable *user_filter_map; -} php_basic_globals; - -#ifdef ZTS -#define BG(v) TSRMG(basic_globals_id, php_basic_globals *, v) -extern int basic_globals_id; -#else -#define BG(v) (basic_globals.v) -extern php_basic_globals basic_globals; -#endif - -#if HAVE_PUTENV -typedef struct { - char *putenv_string; - char *previous_value; - char *key; - int key_len; -} putenv_entry; -#endif - -/* Values are comma-delimited - */ -#define SAFE_MODE_PROTECTED_ENV_VARS "LD_LIBRARY_PATH" -#define SAFE_MODE_ALLOWED_ENV_VARS "PHP_" - -#endif /* BASIC_FUNCTIONS_H */ diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c deleted file mode 100644 index 6c9c1f0062..0000000000 --- a/ext/standard/browscap.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_regex.h" -#include "php_browscap.h" -#include "php_ini.h" - -#include "zend_globals.h" - -static HashTable browser_hash; -static zval *current_section; - -#define DEFAULT_SECTION_NAME "Default Browser Capability Settings" - -/* OBJECTS_FIXME: This whole extension needs going through. The use of objects looks pretty broken here */ - -static void browscap_entry_dtor(zval *pvalue) -{ - if (Z_TYPE_P(pvalue) == IS_OBJECT) { - TSRMLS_FETCH(); - - zend_hash_destroy(Z_OBJPROP_P(pvalue)); - free(Z_OBJPROP_P(pvalue)); - } -} - -/* {{{ convert_browscap_pattern - */ -static void convert_browscap_pattern(zval *pattern) -{ - register int i, j; - char *t; - - for (i=0; i<Z_STRLEN_P(pattern); i++) { - if (Z_STRVAL_P(pattern)[i]=='*' || Z_STRVAL_P(pattern)[i]=='?' || Z_STRVAL_P(pattern)[i]=='.') { - break; - } - } - - if (i==Z_STRLEN_P(pattern)) { /* no wildcards */ - Z_STRVAL_P(pattern) = zend_strndup(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern)); - return; - } - - t = (char *) malloc(Z_STRLEN_P(pattern)*2 + 1); - - for (i=0, j=0; i<Z_STRLEN_P(pattern); i++, j++) { - switch (Z_STRVAL_P(pattern)[i]) { - case '?': - t[j] = '.'; - break; - case '*': - t[j++] = '.'; - t[j] = '*'; - break; - case '.': - t[j++] = '\\'; - t[j] = '.'; - break; - default: - t[j] = Z_STRVAL_P(pattern)[i]; - break; - } - } - - if (j && (t[j-1] == '.')) { - t[j++] = '*'; - } - - t[j]=0; - Z_STRVAL_P(pattern) = t; - Z_STRLEN_P(pattern) = j; -} -/* }}} */ - -/* {{{ php_browscap_parser_cb - */ -static void php_browscap_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg) -{ - if (!arg1) { - return; - } - - switch (callback_type) { - case ZEND_INI_PARSER_ENTRY: - if (current_section && arg2) { - zval *new_property; - char *new_key; - TSRMLS_FETCH(); - - new_property = (zval *) malloc(sizeof(zval)); - INIT_PZVAL(new_property); - Z_STRVAL_P(new_property) = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):""; - Z_STRLEN_P(new_property) = Z_STRLEN_P(arg2); - Z_TYPE_P(new_property) = IS_STRING; - - new_key = zend_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)); - zend_str_tolower(new_key, Z_STRLEN_P(arg1)); - zend_hash_update(Z_OBJPROP_P(current_section), new_key, Z_STRLEN_P(arg1)+1, &new_property, sizeof(zval *), NULL); - free(new_key); - } - break; - case ZEND_INI_PARSER_SECTION: { - zval *processed; - HashTable *section_properties; - TSRMLS_FETCH(); - - /*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len+1);*/ - current_section = (zval *) malloc(sizeof(zval)); - INIT_PZVAL(current_section); - processed = (zval *) malloc(sizeof(zval)); - INIT_PZVAL(processed); - - section_properties = (HashTable *) malloc(sizeof(HashTable)); - _object_and_properties_init(current_section, ZEND_STANDARD_CLASS_DEF_PTR, section_properties ZEND_FILE_LINE_CC TSRMLS_CC); - - zend_hash_init(section_properties, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1); - zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) ¤t_section, sizeof(zval *), NULL); - - Z_STRVAL_P(processed) = Z_STRVAL_P(arg1); - Z_STRLEN_P(processed) = Z_STRLEN_P(arg1); - Z_TYPE_P(processed) = IS_STRING; - convert_browscap_pattern(processed); - zend_hash_update(section_properties, "browser_name_pattern", sizeof("browser_name_pattern"), (void *) &processed, sizeof(zval *), NULL); - } - break; - } -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(browscap) -{ - char *browscap = INI_STR("browscap"); - - if (browscap) { - zend_file_handle fh; - - if (zend_hash_init(&browser_hash, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1)==FAILURE) { - return FAILURE; - } - - fh.handle.fp = VCWD_FOPEN(browscap, "r"); - if (!fh.handle.fp) { - php_error_docref(NULL TSRMLS_CC, E_CORE_WARNING, "Cannot open '%s' for reading", browscap); - return FAILURE; - } - fh.filename = browscap; - Z_TYPE(fh) = ZEND_HANDLE_FP; - zend_parse_ini_file(&fh, 1, (zend_ini_parser_cb_t) php_browscap_parser_cb, &browser_hash); - } - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION - */ -PHP_MSHUTDOWN_FUNCTION(browscap) -{ - if (INI_STR("browscap")) { - zend_hash_destroy(&browser_hash); - } - return SUCCESS; -} -/* }}} */ - -/* {{{ browser_reg_compare - */ -static int browser_reg_compare(zval **browser, int num_args, va_list args, zend_hash_key *key) -{ - zval **browser_name; - regex_t r; - char *lookup_browser_name = va_arg(args, char *); - zval **found_browser_entry = va_arg(args, zval **); - TSRMLS_FETCH(); - - if (*found_browser_entry) { /* already found */ - return 0; - } - if(zend_hash_find(Z_OBJPROP_PP(browser), "browser_name_pattern", sizeof("browser_name_pattern"), (void **) &browser_name) == FAILURE) { - return 0; - } - if (regcomp(&r, Z_STRVAL_PP(browser_name), REG_NOSUB)!=0) { - return 0; - } - if (regexec(&r, lookup_browser_name, 0, NULL, 0)==0) { - *found_browser_entry = *browser; - } - regfree(&r); - return 0; -} -/* }}} */ - -/* {{{ proto object get_browser(string browser_name) - Get information about the capabilities of a browser */ -PHP_FUNCTION(get_browser) -{ - zval **agent_name, **agent; - zval *found_browser_entry, *tmp_copy; - char *lookup_browser_name; - - if (!INI_STR("browscap")) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "browscap ini directive not set."); - RETURN_FALSE; - } - - switch(ZEND_NUM_ARGS()) { - case 0: - if (!PG(http_globals)[TRACK_VARS_SERVER] - || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &agent_name)==FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "HTTP_USER_AGENT variable is not set, cannot determine user agent name"); - RETURN_FALSE; - } - break; - case 1: - if (zend_get_parameters_ex(1, &agent_name)==FAILURE) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string_ex(agent_name); - - if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **) &agent)==FAILURE) { - lookup_browser_name = Z_STRVAL_PP(agent_name); - found_browser_entry = NULL; - zend_hash_apply_with_arguments(&browser_hash, (apply_func_args_t) browser_reg_compare, 2, lookup_browser_name, &found_browser_entry); - - if (found_browser_entry) { - agent = &found_browser_entry; - } else if (zend_hash_find(&browser_hash, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME), (void **) &agent)==FAILURE) { - RETURN_FALSE; - } - } - - object_init(return_value); - zend_hash_copy(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *)); - - while (zend_hash_find(Z_OBJPROP_PP(agent), "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) { - - if (zend_hash_find(&browser_hash, Z_STRVAL_PP(agent_name), Z_STRLEN_PP(agent_name)+1, (void **)&agent)==FAILURE) { - break; - } - - zend_hash_merge(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 deleted file mode 100644 index 8b732a0715..0000000000 --- a/ext/standard/config.m4 +++ /dev/null @@ -1,289 +0,0 @@ -dnl $Id$ -*- sh -*- - -divert(3)dnl - -dnl -dnl Check if flush should be called explicitly after buffered io -dnl -AC_DEFUN(AC_FLUSH_IO,[ - AC_CACHE_CHECK([whether flush should be called explicitly after a buffered io], ac_cv_flush_io,[ - AC_TRY_RUN( [ -#include <stdio.h> -#include <stdlib.h> - -int main(int argc, char **argv) -{ - char *filename = tmpnam(NULL); - char buffer[64]; - int result = 0; - - FILE *fp = fopen(filename, "wb"); - if (NULL == fp) - return 0; - fputs("line 1\n", fp); - fputs("line 2\n", fp); - fclose(fp); - - fp = fopen(filename, "rb+"); - if (NULL == fp) - return 0; - fgets(buffer, sizeof(buffer), fp); - fputs("line 3\n", fp); - rewind(fp); - fgets(buffer, sizeof(buffer), fp); - if (0 != strcmp(buffer, "line 1\n")) - result = 1; - fgets(buffer, sizeof(buffer), fp); - if (0 != strcmp(buffer, "line 3\n")) - result = 1; - fclose(fp); - unlink(filename); - - exit(result); -} -],[ - ac_cv_flush_io=no -],[ - ac_cv_flush_io=yes -],[ - ac_cv_flush_io=no -])]) - if test "$ac_cv_flush_io" = "yes"; then - AC_DEFINE(HAVE_FLUSHIO, 1, [Define if flush should be called explicitly after a buffered io.]) - fi -]) - -dnl -dnl Check for crypt() capabilities -dnl -AC_DEFUN(AC_CRYPT_CAP,[ - - if test "$ac_cv_func_crypt" = "no"; then - AC_CHECK_LIB(crypt, crypt, [ - LIBS="-lcrypt $LIBS -lcrypt" - AC_DEFINE(HAVE_CRYPT, 1, [ ]) - ]) - fi - - AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[ - AC_TRY_RUN([ -#if HAVE_CRYPT_H -#include <crypt.h> -#endif - -main() { -#if HAVE_CRYPT - exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M")); -#else - exit(0); -#endif -}],[ - ac_cv_crypt_des=yes - ],[ - ac_cv_crypt_des=no - ],[ - ac_cv_crypt_des=yes - ]) - ]) - if test "$ac_cv_crypt_des" = "yes"; then - ac_result=1 - else - ac_result=0 - fi - AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, $ac_result, [Whether the system supports standard DES salt]) - - AC_CACHE_CHECK(for extended DES crypt, ac_cv_crypt_ext_des,[ - AC_TRY_RUN([ -#if HAVE_CRYPT_H -#include <crypt.h> -#endif - -main() { -#if HAVE_CRYPT - exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc")); -#else - exit(0); -#endif -}],[ - ac_cv_crypt_ext_des=yes - ],[ - ac_cv_crypt_ext_des=no - ],[ - ac_cv_crypt_ext_des=no - ]) - ]) - if test "$ac_cv_crypt_ext_des" = "yes"; then - ac_result=1 - else - ac_result=0 - fi - AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, $ac_result, [Whether the system supports extended DES salt]) - - AC_CACHE_CHECK(for MD5 crypt, ac_cv_crypt_md5,[ - AC_TRY_RUN([ -#if HAVE_CRYPT_H -#include <crypt.h> -#endif - -main() { -#if HAVE_CRYPT - char salt[15], answer[40]; - - salt[0]='$'; salt[1]='1'; salt[2]='$'; - salt[3]='r'; salt[4]='a'; salt[5]='s'; - salt[6]='m'; salt[7]='u'; salt[8]='s'; - salt[9]='l'; salt[10]='e'; salt[11]='$'; - salt[12]='\0'; - strcpy(answer,salt); - strcat(answer,"rISCgZzpwk3UhDidwXvin0"); - exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer)); -#else - exit(0); -#endif -}],[ - ac_cv_crypt_md5=yes - ],[ - ac_cv_crypt_md5=no - ],[ - ac_cv_crypt_md5=no - ]) - ]) - if test "$ac_cv_crypt_md5" = "yes"; then - ac_result=1 - else - if test "$ac_cv_crypt_des" != "yes"; then - PHP_DEBUG_MACRO(debug.log) - fi - ac_result=0 - fi - AC_DEFINE_UNQUOTED(PHP_MD5_CRYPT, $ac_result, [Whether the system supports MD5 salt]) - - AC_CACHE_CHECK(for Blowfish crypt, ac_cv_crypt_blowfish,[ - AC_TRY_RUN([ -#if HAVE_CRYPT_H -#include <crypt.h> -#endif - -main() { -#if HAVE_CRYPT - char salt[30], answer[70]; - - salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0'; - strcat(salt,"rasmuslerd............"); - strcpy(answer,salt); - strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra"); - exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer)); -#else - exit(0); -#endif -}],[ - ac_cv_crypt_blowfish=yes - ],[ - ac_cv_crypt_blowfish=no - ],[ - ac_cv_crypt_blowfish=no - ]) - ]) - if test "$ac_cv_crypt_blowfish" = "yes"; then - ac_result=1 - else - ac_result=0 - fi - AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, $ac_result, [Whether the system supports BlowFish salt]) -]) - -AC_CHECK_FUNCS(getcwd getwd asinh acosh atanh log1p hypot) - -AC_CRYPT_CAP -AC_FLUSH_IO - -divert(5)dnl - -AC_ARG_WITH(regex, -[ --with-regex=TYPE regex library type: system, apache, php. Default: php - WARNING: Do NOT use unless you know what you are doing!], -[ - case $withval in - system) - if test "$PHP_SAPI" = "apache" || test "$PHP_SAPI" = "apache2filter"; then - REGEX_TYPE=php - else - REGEX_TYPE=system - fi - ;; - apache) - REGEX_TYPE=apache - ;; - php) - REGEX_TYPE=php - ;; - *) - REGEX_TYPE=php - AC_MSG_WARN(Invalid regex library type. Using default value: php) - ;; - esac -],[ - REGEX_TYPE=php -]) - -AC_FUNC_FNMATCH - -dnl Take a look and see if there is a support means of creating a new process -dnl and defining which handles it receives -AC_DEFUN([PHP_CHECK_IF_SUPPORT_PROC_OPEN],[ - - AC_CACHE_VAL(php_can_support_proc_open,[ - AC_CHECK_FUNCS(fork CreateProcess, [ - php_can_support_proc_open=yes - break - ],[ - php_can_support_proc_open=no - ]) - ]) - - AC_MSG_CHECKING([if your OS can spawn processes with inherited handles]) - if test "$php_can_support_proc_open" = "yes"; then - AC_MSG_RESULT(yes) - AC_DEFINE(PHP_CAN_SUPPORT_PROC_OPEN,1, [Define if your system has fork/vfork/CreateProcess]) - else - AC_MSG_RESULT(no) - fi - -]) - -PHP_CHECK_IF_SUPPORT_PROC_OPEN - -dnl getopt long options disabled for now -dnl as we can't be sure that we get the right getopt.h here -dnl using the standard AC_CHECK macros -dnl AC_CHECK_HEADERS(getopt.h) -dnl AC_CHECK_FUNCS(getopt_long getopt_long_only) - -AC_CHECK_FUNCS(glob strfmon nice) - -if test "$PHP_SAPI" = "cgi" -o "$PHP_SAPI" = "cli" -o "$PHP_SAPI" = "embed"; then - AC_DEFINE(ENABLE_CHROOT_FUNC, 1, [Whether to enable chroot() function]) -fi - -dnl -dnl Detect library functions needed by php dns_xxx functions -dnl ext/standard/dns.h will collect these in a single define: HAVE_DNS_FUNCS -dnl -PHP_CHECK_FUNC(res_nmkquery, resolv, bind, socket) -PHP_CHECK_FUNC(res_nsend, resolv, bind, socket) -PHP_CHECK_FUNC(dn_expand, resolv, bind, socket) -dnl already done PHP_CHECK_FUNC(dn_skipname, resolv, bind, socket) - -PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32.c crypt.c \ - cyr_convert.c datetime.c dir.c dl.c dns.c exec.c file.c filestat.c \ - flock_compat.c formatted_print.c fsock.c head.c html.c image.c \ - info.c iptc.c lcg.c link.c mail.c math.c md5.c metaphone.c \ - microtime.c pack.c pageinfo.c parsedate.c quot_print.c rand.c \ - reg.c soundex.c string.c scanf.c syslog.c type.c uniqid.c url.c \ - url_scanner.c var.c versioning.c assert.c strnatcmp.c levenshtein.c \ - incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \ - http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ - var_unserializer.c ftok.c aggregation.c sha1.c user_filters.c \ - filters.c proc_open.c sunfuncs.c) - -PHP_ADD_MAKEFILE_FRAGMENT diff --git a/ext/standard/crc32.c b/ext/standard/crc32.c deleted file mode 100644 index c36dc068c4..0000000000 --- a/ext/standard/crc32.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "basic_functions.h" -#include "crc32.h" - -/* {{{ proto string crc32(string str) - Calculate the crc32 polynomial of a string */ -PHP_NAMED_FUNCTION(php_if_crc32) -{ - unsigned int crc = ~0; - char *p; - int len, nr; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &p, &nr) == FAILURE) { - return; - } - - len = 0 ; - for (len += nr; nr--; ++p) { - CRC32(crc, *p); - } - RETVAL_LONG(~crc); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/crc32.h b/ext/standard/crc32.h deleted file mode 100644 index f1dad697ac..0000000000 --- a/ext/standard/crc32.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - * This code implements the AUTODIN II polynomial - * The variable corresponding to the macro argument "crc" should - * be an unsigned long. - * Oroginal code by Spencer Garrett <srg@quick.com> - */ - -#define CRC32(crc, ch) (crc = (crc >> 8) ^ crc32tab[(crc ^ (ch)) & 0xff]) - -/* generated using the AUTODIN II polynomial - * x^32 + x^26 + x^23 + x^22 + x^16 + - * x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1 - */ - -static const unsigned int crc32tab[256] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, - 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, - 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, - 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, - 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, - 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, - 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, - 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, - 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, - 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, - 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, - 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, - 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, - 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/credits.c b/ext/standard/credits.c deleted file mode 100644 index 45bcc6818b..0000000000 --- a/ext/standard/credits.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "info.h" - -#define CREDIT_LINE(module, authors) php_info_print_table_row(2, module, authors) - -/* {{{ php_print_credits - */ -PHPAPI void php_print_credits(int flag) -{ - TSRMLS_FETCH(); - - if (flag & PHP_CREDITS_FULLPAGE) { - php_print_info_htmlhead(TSRMLS_C); - } - - PUTS("<h1>PHP Credits</h1>\n"); - - if (flag & PHP_CREDITS_GROUP) { - /* Group */ - - php_info_print_table_start(); - php_info_print_table_header(1, "PHP Group"); - php_info_print_table_row(1, "Thies C. Arntzen, Stig Bakken, Shane Caraveo, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_GENERAL) { - /* Design & Concept */ - php_info_print_table_start(); - php_info_print_table_header(1, "Language Design & Concept"); - php_info_print_table_row(1, "Andi Gutmans, Rasmus Lerdorf, Zeev Suraski"); - php_info_print_table_end(); - - /* PHP 4 Language */ - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "PHP 4 Authors"); - php_info_print_table_header(2, "Contribution", "Authors"); - CREDIT_LINE("Zend Scripting Language Engine", "Andi Gutmans, Zeev Suraski"); - CREDIT_LINE("Extension Module API", "Andi Gutmans, Zeev Suraski, Andrei Zmievski"); - CREDIT_LINE("UNIX Build and Modularization", "Stig Bakken, Sascha Schumann"); - CREDIT_LINE("Win32 Port", "Shane Caraveo, Zeev Suraski"); - CREDIT_LINE("Server API (SAPI) Abstraction Layer", "Andi Gutmans, Shane Caraveo, Zeev Suraski"); - CREDIT_LINE("Streams Abstraction Layer", "Wez Furlong"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_SAPI) { - /* SAPI Modules */ - - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "SAPI Modules"); - php_info_print_table_header(2, "Contribution", "Authors"); -#include "credits_sapi.h" - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_MODULES) { - /* Modules */ - - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "Module Authors"); - php_info_print_table_header(2, "Module", "Authors"); -#include "credits_ext.h" - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_DOCS) { - php_info_print_table_start(); - php_info_print_table_header(1, "PHP Documentation Team"); - php_info_print_table_row(1, "Jouni Ahto, Alexander Aulbach, Stig Bakken, Rasmus Lerdorf, Egon Schmid, Lars Torben Wilson, Jim Winstead"); - php_info_print_table_row(1, "Edited by: Stig Bakken and Egon Schmid"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_QA) { - php_info_print_table_start(); - php_info_print_table_header(1, "PHP 5.0 Quality Assurance Team"); - php_info_print_table_row(1, "Ilia Alshanetsky, Joerg Behrens, Stefan Esser, Moriyoshi Koizumi, Magnus Maatta, Sebastian Nohn, Derick Rethans, Melvyn Sopacua, Jani Taskinen"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_WEB) { - /* Website Team */ - php_info_print_table_start(); - php_info_print_table_header(1, "PHP Website Team"); - php_info_print_table_row(1, "Gabor Hojtsy, Colin Viebrock, Jim Winstead"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_FULLPAGE) { - PUTS("</center></body></html>\n"); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/credits.h b/ext/standard/credits.h deleted file mode 100644 index 6377eed1c8..0000000000 --- a/ext/standard/credits.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef CREDITS_H -#define CREDITS_H - -#ifndef HAVE_CREDITS_DEFS -#define HAVE_CREDITS_DEFS - -#define PHP_CREDITS_GROUP (1<<0) -#define PHP_CREDITS_GENERAL (1<<1) -#define PHP_CREDITS_SAPI (1<<2) -#define PHP_CREDITS_MODULES (1<<3) -#define PHP_CREDITS_DOCS (1<<4) -#define PHP_CREDITS_FULLPAGE (1<<5) -#define PHP_CREDITS_QA (1<<6) -#define PHP_CREDITS_WEB (1<<7) -#define PHP_CREDITS_ALL 0xFFFFFFFF - -#endif /* HAVE_CREDITS_DEFS */ - -PHPAPI void php_print_credits(int flag); - -#endif diff --git a/ext/standard/credits_ext.h b/ext/standard/credits_ext.h deleted file mode 100644 index 2085356fff..0000000000 --- a/ext/standard/credits_ext.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - DO NOT EDIT THIS FILE! - - it has been automaticaly created by php4/scripts/credits from - the information found in the various php4/ext/.../CREDITS and - php4/sapi/.../CREDITS files - - if you want to change an entry you have to edit the appropriate - CREDITS file instead - -*/ - -CREDIT_LINE("Assert", "Thies C. Arntzen"); -CREDIT_LINE("BC Math", "Andi Gutmans"); -CREDIT_LINE("Bzip2", "Sterling Hughes"); -CREDIT_LINE("Calendar", "Shane Caraveo, Colin Viebrock, Hartmut Holzgraefe, Wez Furlong"); -CREDIT_LINE("cpdf", "Uwe Steinmann"); -CREDIT_LINE("crack", "Alexander Feldman"); -CREDIT_LINE("ctype", "Hartmut Holzgraefe"); -CREDIT_LINE("cURL", "Sterling Hughes"); -CREDIT_LINE("Cyrus", "Sterling Hughes"); -CREDIT_LINE("DBA", "Sascha Schumann, Marcus Boerger"); -CREDIT_LINE("dBase", "Jim Winstead"); -CREDIT_LINE("DBM", "Rasmus Lerdorf, Jim Winstead"); -CREDIT_LINE("dbx (database abstraction)", "Marc Boeren, Rui Hirokawa, Frank M. Kromann"); -CREDIT_LINE("domxml", "Uwe Steinmann, Christian Stocker"); -CREDIT_LINE("dotnet", "Sam Ruby"); -CREDIT_LINE("EXIF", "Rasmus Lerdorf, Marcus Boerger"); -CREDIT_LINE("fam", "Sascha Schumann"); -CREDIT_LINE("FBSQL", "Frank M. Kromann"); -CREDIT_LINE("FDF", "Uwe Steinmann"); -CREDIT_LINE("FilePro", "Chad Robinson"); -CREDIT_LINE("FriBidi", "Onn Ben-Zvi, Tal Peer"); -CREDIT_LINE("FTP", "Stefan Esser, Andrew Skalski"); -CREDIT_LINE("GD imaging", "Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto"); -CREDIT_LINE("GetText", "Alex Plotnick"); -CREDIT_LINE("GNU GMP support", "Stanislav Malyshev"); -CREDIT_LINE("HwAPI", "Uwe Steinmann"); -CREDIT_LINE("HyperWave", "Uwe Steinmann"); -CREDIT_LINE("IMAP", "Rex Logan, Mark Musone, Brian Wang, Kaj-Michael Lang, Antoni Pamies Olive, Rasmus Lerdorf, Andrew Skalski, Chuck Hagenbuch, Daniel R Kalowsky"); -CREDIT_LINE("Informix", "Danny Heijl, Christian Cartus"); -CREDIT_LINE("Ingres II", "David Hénot"); -CREDIT_LINE("InterBase", "Jouni Ahto, Andrew Avdeev"); -CREDIT_LINE("IRCG", "Sascha Schumann"); -CREDIT_LINE("Java", "Sam Ruby"); -CREDIT_LINE("LDAP", "Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson, Stig Venaas"); -CREDIT_LINE("MCAL", "Mark Musone, Chuck Hagenbuch"); -CREDIT_LINE("mcrypt", "Sascha Schumann, Derick Rethans"); -CREDIT_LINE("MCVE", "Brad House, Chris Faulhaber, Steven Schoch"); -CREDIT_LINE("mhash", "Sascha Schumann"); -CREDIT_LINE("mime_magic", "Hartmut Holzgraefe"); -CREDIT_LINE("MING", "Dave Hayden"); -CREDIT_LINE("mnoGoSearch", "Sergey Kartashoff, Alex Barkov, Ramil Kalimullin"); -CREDIT_LINE("msession", "Mark L. Woodward"); -CREDIT_LINE("mSQL", "Zeev Suraski"); -CREDIT_LINE("MS SQL", "Frank M. Kromann"); -CREDIT_LINE("Multibyte String Functions", "Tsukada Takuya, Rui Hirokawa"); -CREDIT_LINE("MySQL", "Zeev Suraski, Zak Greant, Georg Richter"); -CREDIT_LINE("ncurses", "Ilia Alshanetsky, Wez Furlong, Hartmut Holzgraefe, Georg Richter"); -CREDIT_LINE("OCI8", "Stig Bakken, Thies C. Arntzen, Andy Sautins, David Benson"); -CREDIT_LINE("ODBC", "Stig Bakken, Andreas Karajannis, Frank M. Kromann, Daniel R. Kalowsky"); -CREDIT_LINE("OpenSSL", "Stig Venaas, Wez Furlong, Sascha Kettler"); -CREDIT_LINE("Oracle", "Stig Bakken, Mitch Golden, Rasmus Lerdorf, Andreas Karajannis, Thies C. Arntzen"); -CREDIT_LINE("Ovrimos", "Nikos Mavroyanopoulos"); -CREDIT_LINE("pcntl", "Jason Greene"); -CREDIT_LINE("PDF", "Uwe Steinmann, Rainer Schaaf"); -CREDIT_LINE("Perl Compatible Regexps", "Andrei Zmievski"); -CREDIT_LINE("Posix", "Kristian Köhntopp"); -CREDIT_LINE("PostgreSQL", "Jouni Ahto, Zeev Suraski, Yasuo Ohgaki"); -CREDIT_LINE("Pspell", "Vlad Krupin"); -CREDIT_LINE("qtdom", "Jan Borsodi"); -CREDIT_LINE("Readline", "Thies C. Arntzen"); -CREDIT_LINE("Recode", "Kristian Köhntopp"); -CREDIT_LINE("Sessions", "Sascha Schumann, Andrei Zmievski"); -CREDIT_LINE("Shared Memory Operations", "Slava Poliakov, Ilia Alshanetsky"); -CREDIT_LINE("SNMP", "Rasmus Lerdorf"); -CREDIT_LINE("Sockets", "Chris Vandomelen, Sterling Hughes, Daniel Beulshausen, Jason Greene"); -CREDIT_LINE("SWF", "Sterling Hughes"); -CREDIT_LINE("Sybase-CT", "Zeev Suraski, Tom May, Timm Friebe"); -CREDIT_LINE("Sybase-DB", "Zeev Suraski"); -CREDIT_LINE("System V Message based IPC", "Wez Furlong"); -CREDIT_LINE("System V Semaphores", "Tom May"); -CREDIT_LINE("System V Shared Memory", "Christian Cartus"); -CREDIT_LINE("tokenizer", "Andrei Zmievski"); -CREDIT_LINE("User-space object overloading", "Andrei Zmievski"); -CREDIT_LINE("Verisign Payflow Pro", "John Donagher, David Croft"); -CREDIT_LINE("W32API", "James Moore"); -CREDIT_LINE("WDDX", "Andrei Zmievski"); -CREDIT_LINE("Win32 COM", "Alan Brown, Wez Furlong, Harald Radi, Zeev Suraski"); -CREDIT_LINE("xmlrpc", "Dan Libby"); -CREDIT_LINE("XML", "Stig Bakken, Thies C. Arntzen"); -CREDIT_LINE("YAZ", "Adam Dickmeiss"); -CREDIT_LINE("Yellow Pages", "Stephanie Wehner, Fredrik Ohrn"); -CREDIT_LINE("Zip", "Sterling Hughes"); -CREDIT_LINE("Zlib", "Rasmus Lerdorf, Stefan Roehrich, Zeev Suraski, Jade Nicoletti"); diff --git a/ext/standard/credits_sapi.h b/ext/standard/credits_sapi.h deleted file mode 100644 index 3cf161eb88..0000000000 --- a/ext/standard/credits_sapi.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - DO NOT EDIT THIS FILE! - - it has been automaticaly created by php4/scripts/credits from - the information found in the various php4/ext/.../CREDITS and - php4/sapi/.../CREDITS files - - if you want to change an entry you have to edit the appropriate - CREDITS file instead - -*/ - -CREDIT_LINE("ActiveScript", "Wez Furlong"); -CREDIT_LINE("AOLserver", "Sascha Schumann"); -CREDIT_LINE("Apache 1.3 (apache_hooks)", "Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar, George Schlossnagle, Lukas Schroeder"); -CREDIT_LINE("Apache 1.3", "Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar"); -CREDIT_LINE("Apache 2.0", "Sascha Schumann, Aaron Bannert"); -CREDIT_LINE("Caudium / Roxen", "David Hedbor"); -CREDIT_LINE("CGI / FastCGI", "Rasmus Lerdorf, Stig Bakken, Shane Caraveo"); -CREDIT_LINE("CLI", "Edin Kadribasic, Marcus Boerger"); -CREDIT_LINE("Embed", "Edin Kadribasic"); -CREDIT_LINE("ISAPI", "Andi Gutmans, Zeev Suraski"); -CREDIT_LINE("Java Servlet", "Sam Ruby"); -CREDIT_LINE("NSAPI", "Jayakumar Muthukumarasamy"); -CREDIT_LINE("phttpd", "Thies C. Arntzen"); -CREDIT_LINE("pi3web", "Holger Zimmermann"); -CREDIT_LINE("Sendmail Milter", "Harald Radi"); -CREDIT_LINE("thttpd", "Sascha Schumann"); -CREDIT_LINE("tux", "Sascha Schumann"); -CREDIT_LINE("WebJames", "Alex Waugh"); diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c deleted file mode 100644 index f4220699d1..0000000000 --- a/ext/standard/crypt.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Stig Bakken <ssb@gaurdian.no> | - | Zeev Suraski <zeev@zend.com> | - | Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ -#include <stdlib.h> - -#include "php.h" - -#if HAVE_CRYPT - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if HAVE_CRYPT_H -#include <crypt.h> -#endif -#if TM_IN_SYS_TIME -#include <sys/time.h> -#else -#include <time.h> -#endif -#if HAVE_STRING_H -#include <string.h> -#else -#include <strings.h> -#endif - -#ifdef PHP_WIN32 -#include <process.h> -extern char *crypt(char *__key, char *__salt); -#endif - -#include "php_lcg.h" -#include "php_crypt.h" -#include "php_rand.h" - -/* - The capabilities of the crypt() function is determined by the test programs - run by configure from aclocal.m4. They will set PHP_STD_DES_CRYPT, - PHP_EXT_DES_CRYPT, PHP_MD5_CRYPT and PHP_BLOWFISH_CRYPT as appropriate - for the target platform -*/ -#if PHP_STD_DES_CRYPT -#define PHP_MAX_SALT_LEN 2 -#endif - -#if PHP_EXT_DES_CRYPT -#undef PHP_MAX_SALT_LEN -#define PHP_MAX_SALT_LEN 9 -#endif - -#if PHP_MD5_CRYPT -#undef PHP_MAX_SALT_LEN -#define PHP_MAX_SALT_LEN 12 -#endif - -#if PHP_BLOWFISH_CRYPT -#undef PHP_MAX_SALT_LEN -#define PHP_MAX_SALT_LEN 60 -#endif - - /* - * If the configure-time checks fail, we provide DES. - * XXX: This is a hack. Fix the real problem - */ - -#ifndef PHP_MAX_SALT_LEN -#define PHP_MAX_SALT_LEN 2 -#undef PHP_STD_DES_CRYPT -#define PHP_STD_DES_CRYPT 1 -#endif - - -#define PHP_CRYPT_RAND php_rand(TSRMLS_C) - -static int php_crypt_rand_seeded=0; - -PHP_MINIT_FUNCTION(crypt) -{ - REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", PHP_MAX_SALT_LEN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_STD_DES", PHP_STD_DES_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_EXT_DES", PHP_EXT_DES_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_MD5", PHP_MD5_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_BLOWFISH", PHP_BLOWFISH_CRYPT, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - - -PHP_RINIT_FUNCTION(crypt) -{ - if(!php_crypt_rand_seeded) { - php_srand(time(0) * getpid() * (unsigned long) (php_combined_lcg(TSRMLS_C) * 10000.0) TSRMLS_CC); - php_crypt_rand_seeded=1; - } - return SUCCESS; -} - - -static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static void php_to64(char *s, long v, int n) -{ - while (--n >= 0) { - *s++ = itoa64[v&0x3f]; - v >>= 6; - } -} - -/* {{{ proto string crypt(string str [, string salt]) - Encrypt a string */ -PHP_FUNCTION(crypt) -{ - char salt[PHP_MAX_SALT_LEN+1]; - char *str, *salt_in = NULL; - int str_len, salt_in_len; - - salt[0]=salt[PHP_MAX_SALT_LEN]='\0'; - /* This will produce suitable results if people depend on DES-encryption - available (passing always 2-character salt). At least for glibc6.1 */ - memset(&salt[1], '$', PHP_MAX_SALT_LEN-1); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &str, &str_len, - &salt_in, &salt_in_len) == FAILURE) { - return; - } - - if (salt_in) { - memcpy(salt, salt_in, MIN(PHP_MAX_SALT_LEN, salt_in_len)); - } - - /* The automatic salt generation only covers standard DES and md5-crypt */ - if(!*salt) { -#if PHP_MD5_CRYPT - strcpy(salt, "$1$"); - php_to64(&salt[3], PHP_CRYPT_RAND, 4); - php_to64(&salt[7], PHP_CRYPT_RAND, 4); - strcpy(&salt[11], "$"); -#elif PHP_STD_DES_CRYPT - php_to64(&salt[0], PHP_CRYPT_RAND, 2); - salt[2] = '\0'; -#endif - } - - RETVAL_STRING(crypt(str, salt), 1); -} -/* }}} */ -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/css.c b/ext/standard/css.c deleted file mode 100644 index e3fb08f55c..0000000000 --- a/ext/standard/css.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Colin Viebrock <colin@easydns.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "info.h" - - -/* {{{ php_info_print_css - */ -PHPAPI void php_info_print_css(void) -{ - TSRMLS_FETCH(); - - PUTS("body {background-color: #ffffff; color: #000000;}\n"); - PUTS("body, td, th, h1, h2 {font-family: sans-serif;}\n"); - PUTS("pre {margin: 0px; font-family: monospace;}\n"); - PUTS("a:link {color: #000099; text-decoration: none;}\n"); - PUTS("a:hover {text-decoration: underline;}\n"); - PUTS("table {border-collapse: collapse;}\n"); - PUTS(".center {text-align: center;}\n"); - PUTS(".center table { margin-left: auto; margin-right: auto; text-align: left;}\n"); - PUTS(".center th { text-align: center; !important }\n"); - PUTS("td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}\n"); - PUTS("h1 {font-size: 150%;}\n"); - PUTS("h2 {font-size: 125%;}\n"); - PUTS(".p {text-align: left;}\n"); - PUTS(".e {background-color: #ccccff; font-weight: bold;}\n"); - PUTS(".h {background-color: #9999cc; font-weight: bold;}\n"); - PUTS(".v {background-color: #cccccc;}\n"); - PUTS("i {color: #666666;}\n"); - PUTS("img {float: right; border: 0px;}\n"); - PUTS("hr {width: 600px; align: center; background-color: #cccccc; border: 0px; height: 1px;}\n"); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/css.h b/ext/standard/css.h deleted file mode 100644 index f809f6022e..0000000000 --- a/ext/standard/css.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Colin Viebrock <colin@easydns.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef CSS_H -#define CSS_H - -PHPAPI void php_info_print_css(void); - -#endif diff --git a/ext/standard/cyr_convert.c b/ext/standard/cyr_convert.c deleted file mode 100644 index 086bbe383b..0000000000 --- a/ext/standard/cyr_convert.c +++ /dev/null @@ -1,299 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Kirill Maximov <kir@rus.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <string.h> -#include <errno.h> - -#include "php.h" -#include "cyr_convert.h" - -#include <stdio.h> - -/***************************************************************************** -* This is codetables for different Cyrillic charsets (relative to koi8-r). -* Each table contains data for 128-255 symbols from ASCII table. -* First 256 symbols are for conversion from koi8-r to corresponding charset, -* second 256 symbols are for reverse conversion, from charset to koi8-r. -* -* Here we have the following tables: -* _cyr_win1251 - for windows-1251 charset -* _cyr_iso88595 - for iso8859-5 charset -* _cyr_cp866 - for x-cp866 charset -* _cyr_mac - for x-mac-cyrillic charset -* -*****************************************************************************/ - -typedef unsigned char _cyr_charset_table[512]; - -/* {{{ const static _cyr_charset_table _cyr_win1251 - */ -const static _cyr_charset_table _cyr_win1251 = { -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46, -46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46, -154,174,190,46,159,189,46,46,179,191,180,157,46,46,156,183, -46,46,182,166,173,46,46,158,163,152,164,155,46,46,46,167, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,184,186,32,179,191,32,32,32,32,32,180,162,32, -32,32,32,168,170,32,178,175,32,32,32,32,32,165,161,169, -254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238, -239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250, -222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206, -207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218, -}, -_cyr_cp866 = { -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -35,35,35,124,124,124,124,43,43,124,124,43,43,43,43,43, -43,45,45,124,45,43,124,124,43,43,45,45,124,45,43,45, -45,45,45,43,43,43,43,43,43,43,43,35,35,124,124,35, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209, -179,163,180,164,183,167,190,174,32,149,158,32,152,159,148,154, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -205,186,213,241,243,201,32,245,187,212,211,200,190,32,247,198, -199,204,181,240,242,185,32,244,203,207,208,202,216,32,246,32, -238,160,161,230,164,165,228,163,229,168,169,170,171,172,173,174, -175,239,224,225,226,227,166,162,236,235,167,232,237,233,231,234, -158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142, -143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154, -}, -_cyr_iso88595 = { -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,179,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209, -32,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,241,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,161,32,32,32,32,32,32,32,32,32,32,32,32, -238,208,209,230,212,213,228,211,229,216,217,218,219,220,221,222, -223,239,224,225,226,227,214,210,236,235,215,232,237,233,231,234, -206,176,177,198,180,181,196,179,197,184,185,186,187,188,189,190, -191,207,192,193,194,195,182,178,204,203,183,200,205,201,199,202, -}, -_cyr_mac = { -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240, -242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241, -160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, -176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, -128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, -144,145,146,147,148,149,150,151,152,153,154,155,156,179,163,209, -193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208, -210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,255, -0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, -16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, -32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, -48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, -64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79, -80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95, -96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111, -112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127, -192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207, -208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223, -160,161,162,222,164,165,166,167,168,169,170,171,172,173,174,175, -176,177,178,221,180,181,182,183,184,185,186,187,188,189,190,191, -254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238, -239,223,240,241,242,243,230,226,252,251,231,248,253,249,247,250, -158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142, -143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154, -}; -/* }}} */ - -/* {{{ php_convert_cyr_string -* This is the function that performs real in-place conversion of the string -* between charsets. -* Parameters: -* str - string to be converted -* from,to - one-symbol label of source and destination charset -* The following symbols are used as labels: -* k - koi8-r -* w - windows-1251 -* i - iso8859-5 -* a - x-cp866 -* d - x-cp866 -* m - x-mac-cyrillic -*****************************************************************************/ -static char * php_convert_cyr_string(unsigned char *str, int length, char from, char to TSRMLS_DC) -{ - const unsigned char *from_table, *to_table; - unsigned char tmp; - int i; - - from_table = NULL; - to_table = NULL; - - switch (toupper(from)) - { - case 'W': - from_table = _cyr_win1251; - break; - case 'A': - case 'D': - from_table = _cyr_cp866; - break; - case 'I': - from_table = _cyr_iso88595; - break; - case 'M': - from_table = _cyr_mac; - break; - case 'K': - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown source charset: %c", from); - break; - } - - switch (toupper(to)) - { - case 'W': - to_table = _cyr_win1251; - break; - case 'A': - case 'D': - to_table = _cyr_cp866; - break; - case 'I': - to_table = _cyr_iso88595; - break; - case 'M': - to_table = _cyr_mac; - break; - case 'K': - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown destination charset: %c", to); - break; - } - - - if (!str) - return (char *)str; - - for( i = 0; i<length; i++) - { - tmp = (from_table == NULL)? str[i] : from_table[ str[i] ]; - str[i] = (to_table == NULL) ? tmp : to_table[tmp + 256]; - } - return (char *)str; -} -/* }}} */ - -/* {{{ proto string convert_cyr_string(string str, string from, string to) - Convert from one Cyrillic character set to another */ -PHP_FUNCTION(convert_cyr_string) -{ - pval **str_arg, **fr_cs, **to_cs; - unsigned char *str; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3,&str_arg,&fr_cs, &to_cs)==FAILURE) - { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str_arg); - convert_to_string_ex(fr_cs); - convert_to_string_ex(to_cs); - - str = (unsigned char*) estrndup(Z_STRVAL_PP(str_arg), Z_STRLEN_PP(str_arg)); - - php_convert_cyr_string(str, Z_STRLEN_PP(str_arg), Z_STRVAL_PP(fr_cs)[0], Z_STRVAL_PP(to_cs)[0] TSRMLS_CC); - RETVAL_STRING((char *)str, 0) -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/cyr_convert.h b/ext/standard/cyr_convert.h deleted file mode 100644 index c781bc5e17..0000000000 --- a/ext/standard/cyr_convert.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Kirill Maximov <kir@rus.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef CYR_CONVERT_H -#define CYR_CONVERT_H - -PHP_FUNCTION(convert_cyr_string); - -#endif /* CYR_CONVERT_H */ - - - diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c deleted file mode 100644 index cb1b04c523..0000000000 --- a/ext/standard/datetime.c +++ /dev/null @@ -1,1067 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "zend_operators.h" -#include "datetime.h" -#include "php_globals.h" - -#include <time.h> -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif -#include <stdio.h> - -#include "php_parsedate.h" - -char *mon_full_names[] = { - "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December" -}; - -char *mon_short_names[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -char *day_full_names[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" -}; - -char *day_short_names[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" -}; - -#if !defined(HAVE_TM_ZONE) && !defined(_TIMEZONE) && !defined(HAVE_DECLARED_TIMEZONE) -#if defined(NETWARE) && defined(NEW_LIBC) -#define timezone _timezone /* timezone is called '_timezone' in new version of LibC */ -#endif -extern time_t timezone; -extern int daylight; -#endif - -static int phpday_tab[2][12] = { - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, - {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -}; - -#define isleap(year) (((year % 4) == 0 && (year % 100) != 0) || (year % 400)==0) -#define YEAR_BASE 1900 - -/* {{{ proto int time(void) - Return current UNIX timestamp */ -PHP_FUNCTION(time) -{ - RETURN_LONG((long)time(NULL)); -} -/* }}} */ - -/* {{{ php_mktime - */ -void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) -{ - pval **arguments[7]; - struct tm *ta, tmbuf; - time_t t, seconds; - int i, gmadjust, arg_count = ZEND_NUM_ARGS(); - int is_dst = -1, val, chgsecs = 0; - - if (arg_count > 7 || zend_get_parameters_array_ex(arg_count, arguments) == FAILURE) { - WRONG_PARAM_COUNT; - } - /* convert supplied arguments to longs */ - for (i = 0; i < arg_count; i++) { - convert_to_long_ex(arguments[i]); - } - t = time(NULL); -#ifdef HAVE_TZSET - tzset(); -#endif - /* - ** Set default time parameters with local time values, - ** EVEN when some GMT time parameters are specified! - ** This may give strange result, with PHP gmmktime(0, 0, 0), - ** which is assumed to return GMT midnight time - ** for today (in localtime), so that the result time may be - ** AFTER or BEFORE the current time. - ** May be we should initialize tn using gmtime(), so that - ** default parameters for PHP gmmktime would be the current - ** GMT time values... - */ - ta = php_localtime_r(&t, &tmbuf); - - /* Let DST be unknown. mktime() should compute the right value - ** and behave correctly. Unless the user overrides this. - */ - ta->tm_isdst = -1; - - /* - ** Now change date values with supplied parameters. - */ - switch(arg_count) { - case 7: /* daylight saving time flag */ -#ifdef PHP_WIN32 - if (daylight > 0) { - ta->tm_isdst = is_dst = Z_LVAL_PP(arguments[6]); - } else { - ta->tm_isdst = is_dst = 0; - } -#else - ta->tm_isdst = is_dst = Z_LVAL_PP(arguments[6]); -#endif - /* fall-through */ - case 6: /* year */ - /* special case: - a zero in year, month and day is considered illegal - as it would be interpreted as 30.11.1999 otherwise - */ - if ( ( Z_LVAL_PP(arguments[5])==0) - &&(Z_LVAL_PP(arguments[4])==0) - &&(Z_LVAL_PP(arguments[3])==0) - ) { - RETURN_LONG(-1); - } - - /* - ** Accept parameter in range 0..1000 interpreted as 1900..2900 - ** (if 100 is given, it means year 2000) - ** or in range 1001..9999 interpreted as is (this will store - ** negative tm_year for years in range 1001..1899) - ** This function is then Y2K ready, and accepts a wide range of - ** dates including the whole gregorian calendar. - ** But it cannot represent ancestral dates prior to year 1001. - ** Additionally, input parameters of 0..70 are mapped to 100..170 - */ - if (Z_LVAL_PP(arguments[5]) < 70) - ta->tm_year = Z_LVAL_PP(arguments[5]) + 100; - else - ta->tm_year = Z_LVAL_PP(arguments[5]) - - ((Z_LVAL_PP(arguments[5]) > 1000) ? 1900 : 0); - /* fall-through */ - case 5: /* day in month (1-baesd) */ - val = (*arguments[4])->value.lval; - if (val < 1) { - chgsecs += (1-val) * 60*60*24; - val = 1; - } - ta->tm_mday = val; - /* fall-through */ - case 4: /* month (zero-based) */ - val = (*arguments[3])->value.lval - 1; - while (val < 0) { - val += 12; ta->tm_year--; - } - ta->tm_mon = val; - /* fall-through */ - case 3: /* second */ - val = (*arguments[2])->value.lval; - if (val < 1) { - chgsecs += (1-val); val = 1; - } - ta->tm_sec = val; - /* fall-through */ - case 2: /* minute */ - val = (*arguments[1])->value.lval; - if (val < 1) { - chgsecs += (1-val) * 60; val = 1; - } - ta->tm_min = val; - /* fall-through */ - case 1: /* hour */ - val = (*arguments[0])->value.lval; - if (val < 1) { - chgsecs += (1-val) * 60*60; val = 1; - } - ta->tm_hour = val; - /* fall-through */ - case 0: - break; - } - - t = mktime(ta); - -#ifdef PHP_WIN32 - if (t - chgsecs < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function"); - RETURN_LONG(-1); - } -#endif - - seconds = t - chgsecs; - - if (is_dst == -1) { - struct tm t1, t2; - t1 = *localtime(&t); - t2 = *localtime(&seconds); - - if (t1.tm_isdst != t2.tm_isdst) { - seconds += (t1.tm_isdst == 1) ? 3600 : -3600; - ta = localtime(&seconds); - } - - is_dst = ta->tm_isdst; - } - - if (gm) { -#if HAVE_TM_GMTOFF - /* - ** mktime(ta) very nicely just filled ta->tm_gmtoff with - ** the exactly right value for adjustment if we want GMT. - */ - gmadjust = ta->tm_gmtoff; -#else - /* - ** If correcting for daylight savings time, we set the adjustment to - ** the value of timezone - 3600 seconds. - */ -#ifdef __CYGWIN__ - gmadjust = -(is_dst ? _timezone - 3600 : _timezone); -#else - gmadjust = -(is_dst ? timezone - 3600 : timezone); -#endif -#endif - seconds += gmadjust; - } - - RETURN_LONG(seconds); -} -/* }}} */ - -/* {{{ proto int mktime(int hour, int min, int sec, int mon, int day, int year) - Get UNIX timestamp for a date */ -PHP_FUNCTION(mktime) -{ - php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int gmmktime(int hour, int min, int sec, int mon, int day, int year) - Get UNIX timestamp for a GMT date */ -PHP_FUNCTION(gmmktime) -{ - php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_date - */ -static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) -{ - pval **format, **timestamp; - time_t the_time; - struct tm *ta, tmbuf; - int i, size = 0, length, h, beat, fd, wd, yd, wk; - char tmp_buff[32]; -#if !HAVE_TM_GMTOFF - long tzone; - char *tname[2]= {"GMT Standard Time", "BST"}; -#endif - - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &format) == FAILURE) { - WRONG_PARAM_COUNT; - } - the_time = time(NULL); - break; - case 2: - if (zend_get_parameters_ex(2, &format, ×tamp) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(timestamp); - the_time = Z_LVAL_PP(timestamp); -#ifdef PHP_WIN32 - if (the_time < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support dates prior to midnight (00:00:00), January 1, 1970"); - RETURN_FALSE; - } -#endif - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(format); - - if (gm) { - ta = php_gmtime_r(&the_time, &tmbuf); -#if !HAVE_TM_GMTOFF - tzone = 0; -#endif - } else { - ta = php_localtime_r(&the_time, &tmbuf); -#if !HAVE_TM_GMTOFF -#ifdef __CYGWIN__ - tzone = _timezone; -#else - tzone = timezone; -#endif - tname[0] = tzname[0]; -#endif - } - - if (!ta) { /* that really shouldn't happen... */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unexpected error"); - RETURN_FALSE; - } - for (i = 0; i < Z_STRLEN_PP(format); i++) { - switch (Z_STRVAL_PP(format)[i]) { - case 'r': /* rfc822 format */ - size += 31; - break; - case 'U': /* seconds since the epoch */ - size += 10; - break; - case 'F': /* month, textual, full */ - case 'l': /* day (of the week), textual */ - size += 28; - break; - case 'T': /* timezone name */ -#if HAVE_TM_ZONE - size += strlen(ta->tm_zone); -#elif HAVE_TZNAME - if (ta->tm_isdst > 0 ) { - size += strlen(tname[1]); - } else { - size += strlen(tname[0]); - } -#endif - break; - case 'Z': /* timezone offset in seconds */ - size += 6; - break; - case 'O': /* GMT offset in [+-]HHMM format */ - size += 5; - break; - case 'Y': /* year, numeric, 4 digits */ - size += 4; - break; - case 'M': /* month, textual, 3 letters */ - case 'D': /* day, textual, 3 letters */ - case 'z': /* day of the year, 1 to 366 */ - case 'B': /* Swatch Beat, 3 digits */ - size += 3; - break; - case 'y': /* year, numeric, 2 digits */ - case 'm': /* month, numeric */ - case 'n': /* month, numeric, no leading zeroes */ - case 'd': /* day of the month, numeric */ - case 'j': /* day of the month, numeric, no leading zeros */ - case 'H': /* hour, numeric, 24 hour format */ - case 'h': /* hour, numeric, 12 hour format */ - case 'G': /* hour, numeric, 24 hour format, no leading zeroes */ - case 'g': /* hour, numeric, 12 hour format, no leading zeroes */ - case 'i': /* minutes, numeric */ - case 's': /* seconds, numeric */ - case 'A': /* AM/PM */ - case 'a': /* am/pm */ - case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */ - case 't': /* days in current month */ - case 'W': /* ISO-8601 week number of year, weeks starting on Monday */ - size += 2; - break; - case '\\': - if (i < Z_STRLEN_PP(format) - 1) { - i++; - } - size ++; - break; - case 'L': /* boolean for leap year */ - case 'w': /* day of the week, numeric */ - case 'I': /* DST? */ - default: - size++; - break; - } - } - - Z_STRVAL_P(return_value) = (char *) emalloc(size + 1); - Z_STRVAL_P(return_value)[0] = '\0'; - - for (i = 0; i < Z_STRLEN_PP(format); i++) { - switch (Z_STRVAL_PP(format)[i]) { - case '\\': - if (i < Z_STRLEN_PP(format) - 1) { - char ch[2]; - ch[0]=Z_STRVAL_PP(format)[i + 1]; - ch[1]='\0'; - strcat(Z_STRVAL_P(return_value), ch); - i++; - } - break; - case 'U': /* seconds since the epoch */ - sprintf(tmp_buff, "%ld", (long)the_time); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'F': /* month, textual, full */ - strcat(Z_STRVAL_P(return_value), mon_full_names[ta->tm_mon]); - break; - case 'l': /* day (of the week), textual, full */ - strcat(Z_STRVAL_P(return_value), day_full_names[ta->tm_wday]); - break; - case 'Y': /* year, numeric, 4 digits */ - sprintf(tmp_buff, "%d", ta->tm_year + YEAR_BASE); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'M': /* month, textual, 3 letters */ - strcat(Z_STRVAL_P(return_value), mon_short_names[ta->tm_mon]); - break; - case 'D': /* day (of the week), textual, 3 letters */ - strcat(Z_STRVAL_P(return_value), day_short_names[ta->tm_wday]); - break; - case 'z': /* day (of the year) */ - sprintf(tmp_buff, "%d", ta->tm_yday); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'y': /* year, numeric, 2 digits */ - sprintf(tmp_buff, "%02d", ((ta->tm_year)%100)); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'm': /* month, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'n': /* month, numeric, no leading zeros */ - sprintf(tmp_buff, "%d", ta->tm_mon + 1); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'd': /* day of the month, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_mday); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'j': - sprintf(tmp_buff, "%d", ta->tm_mday); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'H': /* hour, numeric, 24 hour format */ - sprintf(tmp_buff, "%02d", ta->tm_hour); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'h': /* hour, numeric, 12 hour format */ - h = ta->tm_hour % 12; if (h==0) h = 12; - sprintf(tmp_buff, "%02d", h); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'G': /* hour, numeric, 24 hour format, no leading zeros */ - sprintf(tmp_buff, "%d", ta->tm_hour); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'g': /* hour, numeric, 12 hour format, no leading zeros */ - h = ta->tm_hour % 12; if (h==0) h = 12; - sprintf(tmp_buff, "%d", h); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'i': /* minutes, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_min); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 's': /* seconds, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_sec); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'A': /* AM/PM */ - strcat(Z_STRVAL_P(return_value), (ta->tm_hour >= 12 ? "PM" : "AM")); - break; - case 'a': /* am/pm */ - strcat(Z_STRVAL_P(return_value), (ta->tm_hour >= 12 ? "pm" : "am")); - break; - case 'S': /* standard english suffix, e.g. 2nd/3rd for the day of the month */ - if (ta->tm_mday >= 10 && ta->tm_mday <= 19) { - strcat(Z_STRVAL_P(return_value), "th"); - } else { - switch (ta->tm_mday % 10) { - case 1: - strcat(Z_STRVAL_P(return_value), "st"); - break; - case 2: - strcat(Z_STRVAL_P(return_value), "nd"); - break; - case 3: - strcat(Z_STRVAL_P(return_value), "rd"); - break; - default: - strcat(Z_STRVAL_P(return_value), "th"); - break; - } - } - break; - case 't': /* days in current month */ - sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+YEAR_BASE))][ta->tm_mon] ); - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'w': /* day of the week, numeric EXTENSION */ - sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'O': /* GMT offset in [+-]HHMM format */ -#if HAVE_TM_GMTOFF - sprintf(tmp_buff, "%c%02d%02d", (ta->tm_gmtoff < 0) ? '-' : '+', abs(ta->tm_gmtoff / 3600), abs( (ta->tm_gmtoff % 3600) / 60 )); -#else - sprintf(tmp_buff, "%c%02d%02d", ((ta->tm_isdst ? tzone - 3600:tzone)>0)?'-':'+', abs((ta->tm_isdst ? tzone - 3600 : tzone) / 3600), abs(((ta->tm_isdst ? tzone - 3600 : tzone) % 3600) / 60)); -#endif - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'Z': /* timezone offset in seconds */ -#if HAVE_TM_GMTOFF - sprintf(tmp_buff, "%ld", ta->tm_gmtoff); -#else - sprintf(tmp_buff, "%ld", ta->tm_isdst ? -(tzone- 3600) : -tzone); -#endif - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'L': /* boolean for leapyear */ - sprintf(tmp_buff, "%d", (isleap((ta->tm_year+YEAR_BASE)) ? 1 : 0 ) ); - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'T': /* timezone name */ -#if HAVE_TM_ZONE - strcat(Z_STRVAL_P(return_value), ta->tm_zone); -#elif HAVE_TZNAME - strcat(Z_STRVAL_P(return_value), tname[0]); -#endif - break; - case 'B': /* Swatch Beat a.k.a. Internet Time */ - beat = (((((long)the_time)-(((long)the_time) - - ((((long)the_time) % 86400) + 3600))) * 10) / 864); - while (beat < 0) { - beat += 1000; - } - beat = beat % 1000; - sprintf(tmp_buff, "%03d", beat); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'I': - sprintf(tmp_buff, "%d", ta->tm_isdst); - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'r': -#if HAVE_TM_GMTOFF - sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d", - day_short_names[ta->tm_wday], - ta->tm_mday, - mon_short_names[ta->tm_mon], - ta->tm_year + YEAR_BASE, - ta->tm_hour, - ta->tm_min, - ta->tm_sec, - (ta->tm_gmtoff < 0) ? '-' : '+', - abs(ta->tm_gmtoff / 3600), - abs( (ta->tm_gmtoff % 3600) / 60 ) - ); -#else - sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d", - day_short_names[ta->tm_wday], - ta->tm_mday, - mon_short_names[ta->tm_mon], - ta->tm_year + YEAR_BASE, - ta->tm_hour, - ta->tm_min, - ta->tm_sec, - ((ta->tm_isdst ? tzone - 3600 : tzone) > 0) ? '-' : '+', - abs((ta->tm_isdst ? tzone - 3600 : tzone) / 3600), - abs( ((ta->tm_isdst ? tzone - 3600 : tzone) % 3600) / 60 ) - ); -#endif - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - case 'W': /* ISO-8601 week number of year, weeks starting on Monday */ - wd = ta->tm_wday == 0 ? 6 : ta->tm_wday - 1; /* weekday */ - yd = ta->tm_yday + 1; /* days since January 1st */ - - fd = (7 + wd - yd % 7+ 1) % 7; /* weekday (1st January) */ - - /* week is a last year week (52 or 53) */ - if ((yd <= 7 - fd) && fd > 3){ - wk = (fd == 4 || (fd == 5 && isleap((ta->tm_year + YEAR_BASE - 1)))) ? 53 : 52; - } - /* week is a next year week (1) */ - else if (isleap((ta->tm_year+YEAR_BASE)) + 365 - yd < 3 - wd){ - wk = 1; - } - /* normal week */ - else { - wk = (yd + 6 - wd + fd) / 7 - (fd > 3); - } - - sprintf(tmp_buff, "%d", wk); /* SAFE */ - strcat(Z_STRVAL_P(return_value), tmp_buff); - break; - - default: - length = strlen(Z_STRVAL_P(return_value)); - Z_STRVAL_P(return_value)[length] = Z_STRVAL_PP(format)[i]; - Z_STRVAL_P(return_value)[length + 1] = '\0'; - break; - } - } - Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); - Z_TYPE_P(return_value) = IS_STRING; -} -/* }}} */ - -/* {{{ proto string date(string format [, int timestamp]) - Format a local time/date */ -PHP_FUNCTION(date) -{ - php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string gmdate(string format [, int timestamp]) - Format a GMT/UTC date/time */ -PHP_FUNCTION(gmdate) -{ - php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_idate - */ -int php_idate(char format, int timestamp, int gm) -{ - time_t the_time; - struct tm *ta, tmbuf; - int h, beat, fd, wd, yd, wk; -#if !HAVE_TM_GMTOFF - long tzone; - char *tname[2]= {"GMT Standard Time", "BST"}; -#endif - - the_time = timestamp; - - if (gm) { - ta = php_gmtime_r(&the_time, &tmbuf); -#if !HAVE_TM_GMTOFF - tzone = 0; -#endif - } else { - ta = php_localtime_r(&the_time, &tmbuf); -#if !HAVE_TM_GMTOFF -#ifdef __CYGWIN__ - tzone = _timezone; -#else - tzone = timezone; -#endif - tname[0] = tzname[0]; -#endif - } - - switch (format) { - case 'U': /* seconds since the epoch */ - return (long)the_time; - case 'Y': /* year, numeric, 4 digits */ - return ta->tm_year + YEAR_BASE; - case 'z': /* day (of the year) */ - return ta->tm_yday; - case 'y': /* year, numeric, 2 digits */ - return (ta->tm_year) % 100; - case 'm': /* month, numeric */ - case 'n': - return ta->tm_mon + 1; - case 'd': /* day of the month, numeric */ - case 'j': - return ta->tm_mday; - case 'H': /* hour, numeric, 24 hour format */ - case 'G': - return ta->tm_hour; - case 'h': /* hour, numeric, 12 hour format */ - case 'g': - h = ta->tm_hour % 12; - if (h == 0) { - h = 12; - } - return h; - case 'i': /* minutes, numeric */ - return ta->tm_min; - case 's': /* seconds, numeric */ - return ta->tm_sec; - case 't': /* days in current month */ - return phpday_tab[isleap((ta->tm_year + YEAR_BASE))][ta->tm_mon]; - case 'w': /* day of the week, numeric EXTENSION */ - return ta->tm_wday; - case 'Z': /* timezone offset in seconds */ -#if HAVE_TM_GMTOFF - return ta->tm_gmtoff; -#else - return ta->tm_isdst ? -(tzone - 3600) : -tzone; -#endif - case 'L': /* boolean for leapyear */ - return isleap(ta->tm_year + YEAR_BASE) ? 1 : 0; - case 'B': /* Swatch Beat a.k.a. Internet Time */ - beat = (((((long)the_time) - (((long)the_time) - ((((long)the_time) % 86400) + 3600))) * 10) / 864); - while (beat < 0) { - beat += 1000; - } - beat = beat % 1000; - return beat; - case 'I': - return ta->tm_isdst; - case 'W': /* ISO-8601 week number of year, weeks starting on Monday */ - wd = (ta->tm_wday == 0) ? 6 : ta->tm_wday - 1; /* weekday */ - yd = ta->tm_yday + 1; /* days since January 1st */ - fd = (7 + wd - yd % 7+ 1) % 7; /* weekday (1st January) */ - if ((yd <= 7 - fd) && fd > 3) { /* week is a last year week (52 or 53) */ - wk = (fd == 4 || (fd == 5 && isleap((ta->tm_year + YEAR_BASE - 1)))) ? 53 : 52; - } - /* week is a next year week (1) */ - else if (isleap((ta->tm_year + YEAR_BASE)) + 365 - yd < 3 - wd) { - wk = 1; - } - /* normal week */ - else { - wk = (yd + 6 - wd + fd) / 7 - (fd > 3); - } - return wk; - break; - default: - return 0; - } -} -/* }}} */ - -/* {{{ proto int idate(string format [, int timestamp]) - Format a local time/date as integer */ -PHP_FUNCTION(idate) -{ - zval **format, **timestamp; - int t, ret; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &format) == FAILURE) { - WRONG_PARAM_COUNT; - } - t = time(NULL); - break; - case 2: - if (zend_get_parameters_ex(2, &format, ×tamp) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(timestamp); - t = Z_LVAL_PP(timestamp); - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(format); - - if (Z_STRLEN_PP(format) != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "idate format is one char"); - RETURN_FALSE; - } - - ret = php_idate(Z_STRVAL_PP(format)[0], t, 0); - RETURN_LONG(ret); -} -/* }}} */ - -/* {{{ proto array localtime([int timestamp [, bool associative_array]]) - Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */ -PHP_FUNCTION(localtime) -{ - zval **timestamp_arg, **assoc_array_arg; - struct tm *ta, tmbuf; - time_t timestamp; - int assoc_array = 0; - int arg_count = ZEND_NUM_ARGS(); - - if (arg_count < 0 || arg_count > 2 || - zend_get_parameters_ex(arg_count, ×tamp_arg, &assoc_array_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (arg_count) { - case 0: - timestamp = (long)time(NULL); - break; - case 1: - convert_to_long_ex(timestamp_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - break; - case 2: - convert_to_long_ex(timestamp_arg); - convert_to_long_ex(assoc_array_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - assoc_array = Z_LVAL_PP(assoc_array_arg); - break; - } - -#ifdef PHP_WIN32 - if (timestamp < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function"); - RETURN_FALSE - } -#endif - - if (NULL == (ta = php_localtime_r(×tamp, &tmbuf))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid local time"); - RETURN_FALSE; - } - array_init(return_value); - - if (assoc_array) { - add_assoc_long(return_value, "tm_sec", ta->tm_sec); - add_assoc_long(return_value, "tm_min", ta->tm_min); - add_assoc_long(return_value, "tm_hour", ta->tm_hour); - add_assoc_long(return_value, "tm_mday", ta->tm_mday); - add_assoc_long(return_value, "tm_mon", ta->tm_mon); - add_assoc_long(return_value, "tm_year", ta->tm_year); - add_assoc_long(return_value, "tm_wday", ta->tm_wday); - add_assoc_long(return_value, "tm_yday", ta->tm_yday); - add_assoc_long(return_value, "tm_isdst", ta->tm_isdst); - } else { - add_next_index_long(return_value, ta->tm_sec); - add_next_index_long(return_value, ta->tm_min); - add_next_index_long(return_value, ta->tm_hour); - add_next_index_long(return_value, ta->tm_mday); - add_next_index_long(return_value, ta->tm_mon); - add_next_index_long(return_value, ta->tm_year); - add_next_index_long(return_value, ta->tm_wday); - add_next_index_long(return_value, ta->tm_yday); - add_next_index_long(return_value, ta->tm_isdst); - } -} -/* }}} */ - -/* {{{ proto array getdate([int timestamp]) - Get date/time information */ -PHP_FUNCTION(getdate) -{ - pval **timestamp_arg; - struct tm *ta, tmbuf; - time_t timestamp; - - if (ZEND_NUM_ARGS() == 0) { - timestamp = time(NULL); - } else if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, ×tamp_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } else { - convert_to_long_ex(timestamp_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - } - - ta = php_localtime_r(×tamp, &tmbuf); - if (!ta) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot perform date calculation"); - return; - } - array_init(return_value); - add_assoc_long(return_value, "seconds", ta->tm_sec); - add_assoc_long(return_value, "minutes", ta->tm_min); - add_assoc_long(return_value, "hours", ta->tm_hour); - add_assoc_long(return_value, "mday", ta->tm_mday); - add_assoc_long(return_value, "wday", ta->tm_wday); - add_assoc_long(return_value, "mon", ta->tm_mon + 1); - add_assoc_long(return_value, "year", ta->tm_year + 1900); - add_assoc_long(return_value, "yday", ta->tm_yday); - add_assoc_string(return_value, "weekday", day_full_names[ta->tm_wday], 1); - add_assoc_string(return_value, "month", mon_full_names[ta->tm_mon], 1); - add_index_long(return_value, 0, timestamp); -} -/* }}} */ - -/* {{{ php_std_date - Return date string in standard format for http headers */ -char *php_std_date(time_t t) -{ - struct tm *tm1, tmbuf; - char *str; - TSRMLS_FETCH(); - - tm1 = php_gmtime_r(&t, &tmbuf); - str = emalloc(81); - if (PG(y2k_compliance)) { - snprintf(str, 80, "%s, %02d-%s-%04d %02d:%02d:%02d GMT", - day_short_names[tm1->tm_wday], - tm1->tm_mday, - mon_short_names[tm1->tm_mon], - tm1->tm_year + 1900, - tm1->tm_hour, tm1->tm_min, tm1->tm_sec); - } else { - snprintf(str, 80, "%s, %02d-%s-%02d %02d:%02d:%02d GMT", - day_short_names[tm1->tm_wday], - tm1->tm_mday, - mon_short_names[tm1->tm_mon], - ((tm1->tm_year) % 100), - tm1->tm_hour, tm1->tm_min, tm1->tm_sec); - } - - str[79] = 0; - return (str); -} -/* }}} */ - -/* {{{ proto bool checkdate(int month, int day, int year) - Returns true(1) if it is a valid date in gregorian calendar */ -PHP_FUNCTION(checkdate) -{ - pval **month, **day, **year; - int m, d, y, res=0; - - if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &month, &day, &year) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(year) == IS_STRING) { - res = is_numeric_string(Z_STRVAL_PP(year), Z_STRLEN_PP(year), NULL, NULL, 0); - if (res != IS_LONG && res != IS_DOUBLE) { - RETURN_FALSE; - } - } - convert_to_long_ex(day); - convert_to_long_ex(month); - convert_to_long_ex(year); - y = Z_LVAL_PP(year); - m = Z_LVAL_PP(month); - d = Z_LVAL_PP(day); - - if (y < 1 || y > 32767) { - RETURN_FALSE; - } - if (m < 1 || m > 12) { - RETURN_FALSE; - } - if (d < 1 || d > phpday_tab[isleap(y)][m - 1]) { - RETURN_FALSE; - } - RETURN_TRUE; /* True : This month, day, year arguments are valid */ -} -/* }}} */ - -#if HAVE_STRFTIME -/* {{{ _php_strftime - */ -void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm) -{ - pval **format_arg, **timestamp_arg; - char *format, *buf; - time_t timestamp; - struct tm *ta, tmbuf; - int max_reallocs = 5; - size_t buf_len=64, real_len; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &format_arg)==FAILURE) { - RETURN_FALSE; - } - time(×tamp); - break; - case 2: - if (zend_get_parameters_ex(2, &format_arg, ×tamp_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(timestamp_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string_ex(format_arg); - if (Z_STRLEN_PP(format_arg)==0) { - RETURN_FALSE; - } - if (timestamp < 0) { - RETURN_FALSE; - } - format = Z_STRVAL_PP(format_arg); - if (gm) { - ta = php_gmtime_r(×tamp, &tmbuf); - } else { - ta = php_localtime_r(×tamp, &tmbuf); - } - - buf = (char *) emalloc(buf_len); - while ((real_len=strftime(buf, buf_len, format, ta))==buf_len || real_len==0) { - buf_len *= 2; - buf = (char *) erealloc(buf, buf_len); - if (!--max_reallocs) { - break; - } - } - - if (real_len && real_len != buf_len) { - buf = (char *) erealloc(buf, real_len + 1); - RETURN_STRINGL(buf, real_len, 0); - } - efree(buf); - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string strftime(string format [, int timestamp]) - Format a local time/date according to locale settings */ -PHP_FUNCTION(strftime) -{ - _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string gmstrftime(string format [, int timestamp]) - Format a GMT/UCT time/date according to locale settings */ -PHP_FUNCTION(gmstrftime) -{ - _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -#endif - -/* {{{ proto int strtotime(string time, int now) - Convert string representation of date and time to a timestamp */ -PHP_FUNCTION(strtotime) -{ - zval **z_time, **z_now; - int argc; - time_t now; - - argc = ZEND_NUM_ARGS(); - - if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &z_time, &z_now)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(z_time); - if (Z_STRLEN_PP(z_time) == 0) - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Called with empty time parameter"); - if (argc == 2) { - convert_to_long_ex(z_now); - now = Z_LVAL_PP(z_now); - RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), &now)); - } else { - RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), NULL)); - } -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h deleted file mode 100644 index 8aef601797..0000000000 --- a/ext/standard/datetime.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef DATETIME_H -#define DATETIME_H - -PHP_FUNCTION(time); -PHP_FUNCTION(mktime); -PHP_FUNCTION(gmmktime); -PHP_FUNCTION(date); -PHP_FUNCTION(idate); -PHP_FUNCTION(gmdate); -PHP_FUNCTION(localtime); -PHP_FUNCTION(getdate); -PHP_FUNCTION(checkdate); -#if HAVE_STRFTIME -PHP_FUNCTION(strftime); -PHP_FUNCTION(gmstrftime); -#endif -PHP_FUNCTION(strtotime); - -int php_idate(char format, int timestamp, int gm); -extern char *php_std_date(time_t t); -void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm); -#if HAVE_STRFTIME -void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm); -#endif - -#endif /* DATETIME_H */ diff --git a/ext/standard/dir.c b/ext/standard/dir.c deleted file mode 100644 index 6ed208372c..0000000000 --- a/ext/standard/dir.c +++ /dev/null @@ -1,505 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes/startup/misc */ - -#include "php.h" -#include "fopen_wrappers.h" -#include "file.h" -#include "php_dir.h" -#include "php_scandir.h" - -#ifdef HAVE_DIRENT_H -#include <dirent.h> -#endif - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <errno.h> - -#ifdef PHP_WIN32 -#include "win32/readdir.h" -#endif - - -#ifdef HAVE_GLOB -#ifndef PHP_WIN32 -#include <glob.h> -#else -#include "win32/glob.h" -#endif -#endif - -typedef struct { - int default_dir; -} php_dir_globals; - -#ifdef ZTS -#define DIRG(v) TSRMG(dir_globals_id, php_dir_globals *, v) -int dir_globals_id; -#else -#define DIRG(v) (dir_globals.v) -php_dir_globals dir_globals; -#endif - -#if 0 -typedef struct { - int id; - DIR *dir; -} php_dir; - -static int le_dirp; -#endif - -static zend_class_entry *dir_class_entry_ptr; - -#define FETCH_DIRP() \ - if (ZEND_NUM_ARGS() == 0) { \ - myself = getThis(); \ - if (myself) { \ - if (zend_hash_find(Z_OBJPROP_P(myself), "handle", sizeof("handle"), (void **)&tmp) == FAILURE) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find my handle property"); \ - RETURN_FALSE; \ - } \ - ZEND_FETCH_RESOURCE(dirp, php_stream *, tmp, -1, "Directory", php_file_le_stream()); \ - } else { \ - ZEND_FETCH_RESOURCE(dirp, php_stream *, 0, DIRG(default_dir), "Directory", php_file_le_stream()); \ - } \ - } else if ((ZEND_NUM_ARGS() != 1) || zend_get_parameters_ex(1, &id) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } else { \ - dirp = (php_stream *) zend_fetch_resource(id TSRMLS_CC, -1, "Directory", NULL, 1, php_file_le_stream()); \ - if(!dirp) \ - RETURN_FALSE; \ - } - -static zend_function_entry php_dir_class_functions[] = { - PHP_FALIAS(close, closedir, NULL) - PHP_FALIAS(rewind, rewinddir, NULL) - PHP_STATIC_FE("read", php_if_readdir, NULL) - {NULL, NULL, NULL} -}; - - -static void php_set_default_dir(int id TSRMLS_DC) -{ - if (DIRG(default_dir)!=-1) { - zend_list_delete(DIRG(default_dir)); - } - - if (id != -1) { - zend_list_addref(id); - } - - DIRG(default_dir) = id; -} - -PHP_RINIT_FUNCTION(dir) -{ - DIRG(default_dir) = -1; - return SUCCESS; -} - -PHP_MINIT_FUNCTION(dir) -{ - static char dirsep_str[2], pathsep_str[2]; - zend_class_entry dir_class_entry; - - INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions); - dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry TSRMLS_CC); - -#ifdef ZTS - ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL); -#endif - dirsep_str[0] = DEFAULT_SLASH; - dirsep_str[1] = '\0'; - REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", dirsep_str, CONST_CS|CONST_PERSISTENT); - pathsep_str[0] = ZEND_PATHS_SEPARATOR; - pathsep_str[1] = '\0'; - REGISTER_STRING_CONSTANT("PATH_SEPARATOR", pathsep_str, CONST_CS|CONST_PERSISTENT); - -#ifdef HAVE_GLOB -#ifdef GLOB_BRACE - REGISTER_LONG_CONSTANT("GLOB_BRACE", GLOB_BRACE, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef GLOB_ONLYDIR - REGISTER_LONG_CONSTANT("GLOB_ONLYDIR", GLOB_ONLYDIR, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef GLOB_MARK - REGISTER_LONG_CONSTANT("GLOB_MARK", GLOB_MARK, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef GLOB_NOSORT - REGISTER_LONG_CONSTANT("GLOB_NOSORT", GLOB_NOSORT, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef GLOB_NOCHECK - REGISTER_LONG_CONSTANT("GLOB_NOCHECK", GLOB_NOCHECK, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef GLOB_NOESCAPE - REGISTER_LONG_CONSTANT("GLOB_NOESCAPE", GLOB_NOESCAPE, CONST_CS | CONST_PERSISTENT); -#endif -#endif - - return SUCCESS; -} - -/* }}} */ -/* {{{ internal functions */ - -static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) -{ - pval **arg; - php_stream *dirp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - dirp = php_stream_opendir(Z_STRVAL_PP(arg), ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); - - if (dirp == NULL) { - RETURN_FALSE; - } - - php_set_default_dir(dirp->rsrc_id TSRMLS_CC); - - if (createobject) { - object_init_ex(return_value, dir_class_entry_ptr); - add_property_stringl(return_value, "path", Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), 1); - add_property_resource(return_value, "handle", dirp->rsrc_id); - php_stream_auto_cleanup(dirp); /* so we don't get warnings under debug */ - } else { - php_stream_to_zval(dirp, return_value); - } -} - -/* }}} */ -/* {{{ proto mixed opendir(string path) - Open a directory and return a dir_handle */ - -PHP_FUNCTION(opendir) -{ - _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} - -/* }}} */ -/* {{{ proto object dir(string directory) - Directory class with properties, handle and class and methods read, rewind and close */ - -PHP_FUNCTION(getdir) -{ - _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -/* }}} */ -/* {{{ proto void closedir([resource dir_handle]) - Close directory connection identified by the dir_handle */ - -PHP_FUNCTION(closedir) -{ - pval **id, **tmp, *myself; - php_stream *dirp; - - FETCH_DIRP(); - - zend_list_delete(dirp->rsrc_id); - - if (dirp->rsrc_id == DIRG(default_dir)) { - php_set_default_dir(-1 TSRMLS_CC); - } -} - -/* }}} */ - -#if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC -/* {{{ proto bool chroot(string directory) - Change root directory */ - -PHP_FUNCTION(chroot) -{ - char *str; - int ret, str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - RETURN_FALSE; - } - - ret = chroot(str); - - if (ret != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); - RETURN_FALSE; - } - - ret = chdir("/"); - - if (ret != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); - RETURN_FALSE; - } - - RETURN_TRUE; -} - -/* }}} */ -#endif - -/* {{{ proto bool chdir(string directory) - Change the current directory */ - -PHP_FUNCTION(chdir) -{ - char *str; - int ret, str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(str, NULL, CHECKUID_ALLOW_ONLY_FILE)) { - RETURN_FALSE; - } - ret = VCWD_CHDIR(str); - - if (ret != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s (errno %d)", strerror(errno), errno); - RETURN_FALSE; - } - - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto mixed getcwd(void) - Gets the current directory */ - -PHP_FUNCTION(getcwd) -{ - char path[MAXPATHLEN]; - char *ret=NULL; - - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - -#if HAVE_GETCWD - ret = VCWD_GETCWD(path, MAXPATHLEN); -#elif HAVE_GETWD - ret = VCWD_GETWD(path); -/* - * #warning is not ANSI C - * #else - * #warning no proper getcwd support for your site - */ -#endif - - if (ret) { - RETURN_STRING(path, 1); - } else { - RETURN_FALSE; - } -} - -/* }}} */ -/* {{{ proto void rewinddir([resource dir_handle]) - Rewind dir_handle back to the start */ - -PHP_FUNCTION(rewinddir) -{ - pval **id, **tmp, *myself; - php_stream *dirp; - - FETCH_DIRP(); - - php_stream_rewinddir(dirp); -} -/* }}} */ - -/* {{{ proto string readdir([resource dir_handle]) - Read directory entry from dir_handle */ - -PHP_NAMED_FUNCTION(php_if_readdir) -{ - pval **id, **tmp, *myself; - php_stream *dirp; - php_stream_dirent entry; - - FETCH_DIRP(); - - if (php_stream_readdir(dirp, &entry)) { - RETURN_STRINGL(entry.d_name, strlen(entry.d_name), 1); - } - RETURN_FALSE; -} - -/* }}} */ - -#ifdef HAVE_GLOB -/* {{{ proto array glob(string pattern [, int flags]) - Find pathnames matching a pattern */ -PHP_FUNCTION(glob) -{ - char cwd[MAXPATHLEN]; - int cwd_skip = 0; -#ifdef ZTS - char work_pattern[MAXPATHLEN]; - char *result; -#endif - char *pattern = NULL; - int pattern_len; - long flags = 0; - glob_t globbuf; - int n, ret; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &pattern, &pattern_len, &flags) == FAILURE) - return; - -#ifdef ZTS - if(!IS_ABSOLUTE_PATH(pattern, pattern_len)) { - result = VCWD_GETCWD(cwd, MAXPATHLEN); - if (!result) { - cwd[0] = '\0'; - } - cwd_skip = strlen(cwd)+1; - snprintf(work_pattern, MAXPATHLEN, "%s%c%s", cwd, DEFAULT_SLASH, pattern); - pattern = work_pattern; - } -#endif - - globbuf.gl_offs = 0; - if (0 != (ret = glob(pattern, flags, NULL, &globbuf))) { -#ifdef GLOB_NOMATCH - if (GLOB_NOMATCH == ret) { - /* Linux handles no matches as an error condition, but FreeBSD - * doesn't. This ensure that if no match is found, an empty array - * is always returned so it can be used without worrying in e.g. - * foreach() */ - array_init(return_value); - return; - } -#endif - RETURN_FALSE; - } - - /* we assume that any glob pattern will match files from one directory only - so checking the dirname of the first match should be sufficient */ - if (!globbuf.gl_pathv) { - RETURN_FALSE; - } - strncpy(cwd, globbuf.gl_pathv[0], MAXPATHLEN); - if (PG(safe_mode) && (!php_checkuid(cwd, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - if(php_check_open_basedir(cwd TSRMLS_CC)) { - RETURN_FALSE; - } - - - array_init(return_value); - for (n = 0; n < globbuf.gl_pathc; n++) { - add_next_index_string(return_value, globbuf.gl_pathv[n]+cwd_skip, 1); - } - - globfree(&globbuf); -} -/* }}} */ -#endif - -/* {{{ php_alphasortr -*/ -static int php_alphasortr(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*b)->d_name, (*a)->d_name); -} -/* }}} */ - -/* {{{ proto array scandir(string dir [, int sorting_order]) - List files & directories inside the specified path */ -PHP_FUNCTION(scandir) -{ - char *dirn; - int dirn_len; - int flags = 0; - char *path; - struct dirent **namelist; - int n, i; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &dirn, &dirn_len, &flags) == FAILURE) { - return; - } - -#ifdef ZTS - if(!IS_ABSOLUTE_PATH(dirn, dirn_len)) { - path = expand_filepath(dirn, NULL TSRMLS_CC); - } else -#endif - path = dirn; - - if (PG(safe_mode) && (!php_checkuid(path, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETVAL_FALSE; - goto err; - } - if(php_check_open_basedir(path TSRMLS_CC)) { - RETVAL_FALSE; - goto err; - } - - if (!flags) { - n = php_scandir(path, &namelist, 0, php_alphasort); - } else { - n = php_scandir(path, &namelist, 0, php_alphasortr); - } - - if (n < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "(errno %d): %s", errno, strerror(errno)); - RETVAL_FALSE; - goto err; - } - - array_init(return_value); - - for (i = 0; i < n; i++) { - add_next_index_string(return_value, namelist[i]->d_name, 1); - free(namelist[i]); - } - - if (n) { - free(namelist); - } - -err: - if (path && path != dirn) { - efree(path); - } - - return; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/dl.c b/ext/standard/dl.c deleted file mode 100644 index c7f996907f..0000000000 --- a/ext/standard/dl.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Brian Schaffner <brian@tool.net> | - | Shane Caraveo <shane@caraveo.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "dl.h" -#include "php_globals.h" -#include "ext/standard/info.h" -#include "SAPI.h" - -#if defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H -#include <stdlib.h> -#include <stdio.h> - -#ifdef HAVE_STRING_H -#include <string.h> -#else -#include <strings.h> -#endif -#ifdef PHP_WIN32 -#include "win32/param.h" -#include "win32/winutil.h" -#define GET_DL_ERROR() php_win_err() -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#define GET_DL_ERROR() dlerror() -#else -#include <sys/param.h> -#define GET_DL_ERROR() DL_ERROR() -#endif - -#endif /* defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H */ - - -/* {{{ proto int dl(string extension_filename) - Load a PHP extension at runtime */ -PHP_FUNCTION(dl) -{ - pval **file; - -#ifdef ZTS - if ((strncmp(sapi_module.name, "cgi", 3)!=0) && - (strcmp(sapi_module.name, "cli")!=0) && - (strncmp(sapi_module.name, "embed", 5)!=0)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not supported in multithreaded Web servers - use extension statements in your php.ini"); - RETURN_FALSE; - } -#endif - - /* obtain arguments */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(file); - - if (!PG(enable_dl)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extentions aren't enabled"); - } else if (PG(safe_mode)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Dynamically loaded extensions aren't allowed when running in Safe Mode"); - } else { - php_dl(*file, MODULE_TEMPORARY, return_value TSRMLS_CC); - EG(full_tables_cleanup) = 1; - } -} - -/* }}} */ - - -#if defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H - -#ifdef ZTS -#define USING_ZTS 1 -#else -#define USING_ZTS 0 -#endif - -/* {{{ php_dl - */ -void php_dl(pval *file, int type, pval *return_value TSRMLS_DC) -{ - void *handle; - char *libpath; - zend_module_entry *module_entry, *tmp; - zend_module_entry *(*get_module)(void); - int error_type; - char *extension_dir; - - if (type==MODULE_PERSISTENT) { - /* Use the configuration hash directly, the INI mechanism is not yet initialized */ - if (cfg_get_string("extension_dir", &extension_dir)==FAILURE) { - extension_dir = PHP_EXTENSION_DIR; - } - } else { - extension_dir = PG(extension_dir); - } - - if (type==MODULE_TEMPORARY) { - error_type = E_WARNING; - } else { - error_type = E_CORE_WARNING; - } - - if (extension_dir && extension_dir[0]){ - int extension_dir_len = strlen(extension_dir); - - libpath = emalloc(extension_dir_len+Z_STRLEN_P(file)+2); - - if (IS_SLASH(extension_dir[extension_dir_len-1])) { - sprintf(libpath, "%s%s", extension_dir, Z_STRVAL_P(file)); /* SAFE */ - } else { - sprintf(libpath, "%s%c%s", extension_dir, DEFAULT_SLASH, Z_STRVAL_P(file)); /* SAFE */ - } - } else { - libpath = estrndup(Z_STRVAL_P(file), Z_STRLEN_P(file)); - } - - /* load dynamic symbol */ - handle = DL_LOAD(libpath); - if (!handle) { - php_error_docref(NULL TSRMLS_CC, error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR()); - efree(libpath); - RETURN_FALSE; - } - - efree(libpath); - -#ifndef NETWARE - get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module"); - - /* - * some OS prepend _ to symbol names while their dynamic linker - * does not do that automatically. Thus we check manually for - * _get_module. - */ - - if (!get_module) - get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module"); -#else - /* NetWare doesn't support two NLMs exporting same symbol */ - { - char symbol_name[64] = "\0"; - int module_name_length = Z_STRLEN_P(file) - 4; /* '.nlm' is 4 characters; knock it off */ - - /* Take the module name (e.g.: 'php_ldap') and append '@get_module' to it */ - strncpy(symbol_name, Z_STRVAL_P(file), module_name_length); - symbol_name[module_name_length] = '\0'; - strcat(symbol_name, "@"); - strcat(symbol_name, "get_module"); - - get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, symbol_name); - } - /* NetWare doesn't prepend '_' to symbol names; so the corresponding portion of code is also - not required for NetWare */ -#endif - - if (!get_module) { - DL_UNLOAD(handle); - php_error_docref(NULL TSRMLS_CC, error_type, "Invalid library (maybe not a PHP library) '%s' ", Z_STRVAL_P(file)); - RETURN_FALSE; - } - module_entry = get_module(); - if ((module_entry->zend_debug != ZEND_DEBUG) || (module_entry->zts != USING_ZTS) - || (module_entry->zend_api != ZEND_MODULE_API_NO)) { - /* Check for pre-4.1.0 module which has a slightly different module_entry structure :( */ - struct pre_4_1_0_module_entry { - char *name; - zend_function_entry *functions; - int (*module_startup_func)(INIT_FUNC_ARGS); - int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS); - int (*request_startup_func)(INIT_FUNC_ARGS); - int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS); - void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS); - int (*global_startup_func)(void); - int (*global_shutdown_func)(void); - int globals_id; - int module_started; - unsigned char type; - void *handle; - int module_number; - unsigned char zend_debug; - unsigned char zts; - unsigned int zend_api; - }; - - char *name; - int zend_api; - unsigned char zend_debug, zts; - - if(( ((struct pre_4_1_0_module_entry *)module_entry)->zend_api > 20000000) - &&(((struct pre_4_1_0_module_entry *)module_entry)->zend_api < 20010901)) { - name = ((struct pre_4_1_0_module_entry *)module_entry)->name; - zend_api = ((struct pre_4_1_0_module_entry *)module_entry)->zend_api; - zend_debug = ((struct pre_4_1_0_module_entry *)module_entry)->zend_debug; - zts = ((struct pre_4_1_0_module_entry *)module_entry)->zts; - } else { - name = module_entry->name; - zend_api = module_entry->zend_api; - zend_debug = module_entry->zend_debug; - zts = module_entry->zts; - } - - php_error_docref(NULL TSRMLS_CC, error_type, - "%s: Unable to initialize module\n" - "Module compiled with module API=%d, debug=%d, thread-safety=%d\n" - "PHP compiled with module API=%d, debug=%d, thread-safety=%d\n" - "These options need to match\n", - name, zend_api, zend_debug, zts, - ZEND_MODULE_API_NO, ZEND_DEBUG, USING_ZTS); - DL_UNLOAD(handle); - RETURN_FALSE; - } - Z_TYPE_P(module_entry) = type; - module_entry->module_number = zend_next_free_module(); - if (module_entry->module_startup_func) { - if (module_entry->module_startup_func(type, module_entry->module_number TSRMLS_CC)==FAILURE) { - php_error_docref(NULL TSRMLS_CC, error_type, "Unable to initialize module '%s'", module_entry->name); - DL_UNLOAD(handle); - RETURN_FALSE; - } - } - zend_register_module(module_entry); - - if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) { - if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, error_type, "Unable to initialize module '%s'", module_entry->name); - DL_UNLOAD(handle); - RETURN_FALSE; - } - } - - /* update the .request_started property... */ - if (zend_hash_find(&module_registry, module_entry->name, strlen(module_entry->name)+1, (void **) &tmp)==FAILURE) { - php_error_docref(NULL TSRMLS_CC, error_type, "Loaded module '%s' got lost", module_entry->name); - RETURN_FALSE; - } - tmp->handle = handle; - - RETURN_TRUE; -} -/* }}} */ - -PHP_MINFO_FUNCTION(dl) -{ - php_info_print_table_row(2, "Dynamic Library Support", "enabled"); -} - -#else - -void php_dl(pval *file, int type, pval *return_value TSRMLS_DC) -{ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", Z_STRVAL_P(file)); - RETURN_FALSE; -} - -PHP_MINFO_FUNCTION(dl) -{ - PUTS("Dynamic Library support not available<br />.\n"); -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/dl.h b/ext/standard/dl.h deleted file mode 100644 index 34110a4671..0000000000 --- a/ext/standard/dl.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Brian Schaffner <brian@tool.net> | - | Shane Caraveo <shane@caraveo.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef DL_H -#define DL_H - -void php_dl(pval *file,int type,pval *return_value TSRMLS_DC); - - -/* dynamic loading functions */ -PHP_FUNCTION(dl); - -PHP_MINFO_FUNCTION(dl); - -#endif /* DL_H */ diff --git a/ext/standard/dns.c b/ext/standard/dns.c deleted file mode 100644 index d8799d863f..0000000000 --- a/ext/standard/dns.c +++ /dev/null @@ -1,727 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: The typical suspects | - | Pollita <pollita@php.net> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes */ -#include "php.h" - -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifdef PHP_WIN32 -#if HAVE_LIBBIND -#ifndef WINNT -#define WINNT 1 -#endif -/* located in www.php.net/extra/bindlib.zip */ -#if HAVE_ARPA_INET_H -#include "arpa/inet.h" -#endif -#include "netdb.h" -#if HAVE_ARPA_NAMESERV_H -#include "arpa/nameser.h" -#endif -#if HAVE_RESOLV_H -#include "resolv.h" -#endif -#endif /* HAVE_LIBBIND */ -#include <winsock2.h> -#else /* This holds good for NetWare too, both for Winsock and Berkeley sockets */ -#include <netinet/in.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#include <netdb.h> -#ifdef _OSD_POSIX -#undef STATUS -#undef T_UNSPEC -#endif -#if HAVE_ARPA_NAMESER_H -#include <arpa/nameser.h> -#endif -#if HAVE_RESOLV_H -#include <resolv.h> -#endif -#endif - -/* Borrowed from SYS/SOCKET.H */ -#if defined(NETWARE) && defined(USE_WINSOCK) -#define AF_INET 2 /* internetwork: UDP, TCP, etc. */ -#endif - -#include "dns.h" -/* }}} */ - -static char *php_gethostbyaddr(char *ip); -static char *php_gethostbyname(char *name); - -/* {{{ proto string gethostbyaddr(string ip_address) - Get the Internet host name corresponding to a given IP address */ -PHP_FUNCTION(gethostbyaddr) -{ - zval **arg; - char *addr; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(arg); - - addr = php_gethostbyaddr(Z_STRVAL_PP(arg)); - - if(addr == NULL) { -#if HAVE_IPV6 && !defined(__MacOSX__) -/* MacOSX at this time has support for IPv6, but not inet_pton() - * so disabling IPv6 until further notice. MacOSX 10.1.2 (kalowsky) */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Address is not a valid IPv4 or IPv6 address"); -#else - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Address is not in a.b.c.d form"); -#endif - RETVAL_FALSE; - } else { - RETVAL_STRING(addr, 0); - } -} -/* }}} */ - -/* {{{ php_gethostbyaddr */ -static char *php_gethostbyaddr(char *ip) -{ -#if HAVE_IPV6 && !defined(__MacOSX__) -/* MacOSX at this time has support for IPv6, but not inet_pton() - * so disabling IPv6 until further notice. MacOSX 10.1.2 (kalowsky) */ - struct in6_addr addr6; -#endif - struct in_addr addr; - struct hostent *hp; - -#if HAVE_IPV6 && !defined(__MacOSX__) -/* MacOSX at this time has support for IPv6, but not inet_pton() - * so disabling IPv6 until further notice. MacOSX 10.1.2 (kalowsky) */ - if (inet_pton(AF_INET6, ip, &addr6)) { - hp = gethostbyaddr((char *) &addr6, sizeof(addr6), AF_INET6); - } else if (inet_pton(AF_INET, ip, &addr)) { - hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); - } else { - return NULL; - } -#else - addr.s_addr = inet_addr(ip); - - if (addr.s_addr == -1) { - return NULL; - } - - hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); -#endif - - if (!hp || hp->h_name == NULL || hp->h_name[0] == '\0') { - return estrdup(ip); - } - - return estrdup(hp->h_name); -} -/* }}} */ - -/* {{{ proto string gethostbyname(string hostname) - Get the IP address corresponding to a given Internet host name */ -PHP_FUNCTION(gethostbyname) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - - convert_to_string_ex(arg); - - RETVAL_STRING(php_gethostbyname(Z_STRVAL_PP(arg)), 0); -} -/* }}} */ - -/* {{{ proto array gethostbynamel(string hostname) - Return a list of IP addresses that a given hostname resolves to. */ -PHP_FUNCTION(gethostbynamel) -{ - zval **arg; - struct hostent *hp; - struct in_addr in; - int i; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - ZEND_WRONG_PARAM_COUNT(); - } - convert_to_string_ex(arg); - - array_init(return_value); - - hp = gethostbyname(Z_STRVAL_PP(arg)); - if (hp == NULL || hp->h_addr_list == NULL) { - RETURN_FALSE; - } - - for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) { - in = *(struct in_addr *) hp->h_addr_list[i]; - add_next_index_string(return_value, inet_ntoa(in), 1); - } -} -/* }}} */ - -/* {{{ php_gethostbyname */ -static char *php_gethostbyname(char *name) -{ - struct hostent *hp; - struct in_addr in; - - hp = gethostbyname(name); - - if (!hp || !*(hp->h_addr_list)) { - return estrdup(name); - } - - memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr)); - - return estrdup(inet_ntoa(in)); -} -/* }}} */ - -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) - -/* {{{ proto int dns_check_recored(string host [, string type]) - Check DNS records corresponding to a given Internet host name or IP address */ -PHP_FUNCTION(dns_check_record) -{ - zval **arg1, **arg2; - int type, i; -#ifndef MAXPACKET -#define MAXPACKET 8192 /* max packet size used internally by BIND */ -#endif - u_char ans[MAXPACKET]; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - type = T_MX; - convert_to_string_ex(arg1); - break; - - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - - if (!strcasecmp("A", Z_STRVAL_PP(arg2))) type = T_A; - else if (!strcasecmp("NS", Z_STRVAL_PP(arg2))) type = T_NS; - else if (!strcasecmp("MX", Z_STRVAL_PP(arg2))) type = T_MX; - else if (!strcasecmp("PTR", Z_STRVAL_PP(arg2))) type = T_PTR; - else if (!strcasecmp("ANY", Z_STRVAL_PP(arg2))) type = T_ANY; - else if (!strcasecmp("SOA", Z_STRVAL_PP(arg2))) type = T_SOA; - else if (!strcasecmp("CNAME", Z_STRVAL_PP(arg2))) type = T_CNAME; -#ifdef T_AAAA - else if (!strcasecmp("AAAA", Z_STRVAL_PP(arg2))) type = T_AAAA; -#endif - else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type '%s' not supported", Z_STRVAL_PP(arg2)); - RETURN_FALSE; - } - break; - - default: - WRONG_PARAM_COUNT; - } - - i = res_search(Z_STRVAL_PP(arg1), C_IN, type, ans, sizeof(ans)); - - if (i < 0) { - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -#if HAVE_DNS_FUNCS - -/* PHP_DNS_xx = 1<<(T_xx-1) */ -#define PHP_DNS_A 0x00000001 -#define PHP_DNS_NS 0x00000002 -#define PHP_DNS_CNAME 0x00000010 -#define PHP_DNS_SOA 0x00000020 -#define PHP_DNS_PTR 0x00000800 -#define PHP_DNS_HINFO 0x00001000 -#define PHP_DNS_MX 0x00004000 -#define PHP_DNS_TXT 0x00008000 -#define PHP_DNS_AAAA 0x08000000 -#define PHP_DNS_ANY 0x10000000 -#define PHP_DNS_ALL (PHP_DNS_A|PHP_DNS_NS|PHP_DNS_CNAME|PHP_DNS_SOA|PHP_DNS_PTR|PHP_DNS_HINFO|PHP_DNS_MX|PHP_DNS_TXT|PHP_DNS_AAAA) - -PHP_MINIT_FUNCTION(dns) { - REGISTER_LONG_CONSTANT("DNS_A", PHP_DNS_A, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_NS", PHP_DNS_NS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_CNAME", PHP_DNS_CNAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_SOA", PHP_DNS_SOA, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_PTR", PHP_DNS_PTR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_HINFO", PHP_DNS_HINFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_MX", PHP_DNS_MX, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_TXT", PHP_DNS_TXT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_AAAA", PHP_DNS_AAAA, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_ANY", PHP_DNS_ANY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("DNS_ALL", PHP_DNS_ALL, CONST_CS | CONST_PERSISTENT); - return SUCCESS; -} - -#ifndef HFIXEDSZ -#define HFIXEDSZ 12 /* fixed data in header <arpa/nameser.h> */ -#endif /* HFIXEDSZ */ - -#ifndef QFIXEDSZ -#define QFIXEDSZ 4 /* fixed data in query <arpa/nameser.h> */ -#endif /* QFIXEDSZ */ - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif /* MAXHOSTNAMELEN */ - -#ifndef MAXRESOURCERECORDS -#define MAXRESOURCERECORDS 64 -#endif /* MAXRESOURCERECORDS */ - -typedef union { - HEADER qb1; - u_char qb2[65536]; -} querybuf; - -/* {{{ php_parserr */ -static u_char *php_parserr(u_char *cp, querybuf *answer, int type_to_fetch, int store, zval **subarray) { - u_short type, class, dlen; - u_long ttl; - long n, i; - u_short s; - u_char *tp; - char name[MAXHOSTNAMELEN]; - - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof(name)) - 2); - if (n < 0) { - return NULL; - } - cp += n; - - GETSHORT(type, cp); - GETSHORT(class, cp); - GETLONG(ttl, cp); - GETSHORT(dlen, cp); - if (type_to_fetch != T_ANY && type != type_to_fetch) { - *subarray = NULL; - cp += dlen; - return cp; - } - - if (!store) { - *subarray = NULL; - cp += dlen; - return cp; - } - - MAKE_STD_ZVAL(*subarray); - array_init(*subarray); - - add_assoc_string(*subarray, "host", name, 1); - switch (type) { - case T_A: - add_assoc_string(*subarray, "type", "A", 1); - sprintf(name, "%d.%d.%d.%d", cp[0], cp[1], cp[2], cp[3]); - add_assoc_string(*subarray, "ip", name, 1); - cp += dlen; - break; - case T_MX: - add_assoc_string(*subarray, "type", "MX", 1); - GETSHORT(n, cp); - add_assoc_long(*subarray, "pri", n); - /* no break; */ - case T_CNAME: - if (type == T_CNAME) - add_assoc_string(*subarray, "type", "CNAME", 1); - /* no break; */ - case T_NS: - if (type == T_NS) - add_assoc_string(*subarray, "type", "NS", 1); - /* no break; */ - case T_PTR: - if (type == T_PTR) - add_assoc_string(*subarray, "type", "PTR", 1); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) - 2); - if (n < 0) { - return NULL; - } - cp += n; - add_assoc_string(*subarray, "target", name, 1); - break; - case T_HINFO: - /* See RFC 1010 for values */ - add_assoc_string(*subarray, "type", "HINFO", 1); - GETSHORT(n, cp); - add_assoc_long(*subarray, "cpu", n); - GETSHORT(n, cp); - add_assoc_long(*subarray, "os", n); - break; - case T_TXT: - add_assoc_string(*subarray, "type", "TXT", 1); - n = cp[0]; - for(i=1; i<=n; i++) - name[i-1] = cp[i]; - name[i-1] = '\0'; - cp += dlen; - add_assoc_string(*subarray, "txt", name, 1); - break; - case T_SOA: - add_assoc_string(*subarray, "type", "SOA", 1); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) -2); - if (n < 0) { - return NULL; - } - cp += n; - add_assoc_string(*subarray, "mname", name, 1); - n = dn_expand(answer->qb2, answer->qb2+65536, cp, name, (sizeof name) -2); - if (n < 0) { - return NULL; - } - cp += n; - add_assoc_string(*subarray, "rname", name, 1); - GETLONG(n, cp); - add_assoc_long(*subarray, "serial", n); - GETLONG(n, cp); - add_assoc_long(*subarray, "refresh", n); - GETLONG(n, cp); - add_assoc_long(*subarray, "retry", n); - GETLONG(n, cp); - add_assoc_long(*subarray, "expire", n); - GETLONG(n, cp); - add_assoc_long(*subarray, "minimum-ttl", n); - break; - -#ifdef T_AAAA - case T_AAAA: - tp = name; - for(i=0; i < 8; i++) { - GETSHORT(s, cp); - if (s > 0) { - if (tp > (u_char *)name) { - tp[0] = ':'; - tp++; - } - sprintf(tp,"%x",s); - tp += strlen(tp); - } else if (s == 0) { - if ((tp > (u_char *)name) && (tp[-1] != ':')) { - tp[0] = ':'; - tp++; - } - } - } - if ((tp > (u_char *)name) && (tp[-1] == ':')) - tp[-1] = '\0'; - tp[0] = '\0'; - add_assoc_string(*subarray, "type", "AAAA", 1); - add_assoc_string(*subarray, "ipv6", name, 1); - break; -#endif - - default: - cp += dlen; - } - - add_assoc_string(*subarray, "class", "IN", 1); - add_assoc_long(*subarray, "ttl", ttl); - - return cp; -} -/* }}} */ - -/* {{{ proto array|false dns_get_record(string hostname [, int type[, array authns, array addtl]]) - Get any Resource Record corresponding to a given Internet host name */ -PHP_FUNCTION(dns_get_record) -{ - zval *subarray[MAXRESOURCERECORDS]; - pval *addtl, *host, *authns, *fetch_type; - int addtl_recs = 0; - int type_to_fetch, type_param = PHP_DNS_ANY; - int current_subarray = 0; - struct __res_state res; - HEADER *hp; - querybuf buf, answer, *ans; - u_char *cp = NULL, *end = NULL; - long n, qd, an, ns = 0, ar = 0; - int type, first_query = 1, store_results = 1; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters(ht, 1, &host) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (zend_get_parameters(ht, 2, &host, &fetch_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - type_param = Z_LVAL_P(fetch_type); - break; - case 4: - if (zend_get_parameters(ht, 4, &host, &fetch_type, &authns, &addtl) == FAILURE) { - WRONG_PARAM_COUNT; - } - type_param = Z_LVAL_P(fetch_type); - pval_destructor(authns); - addtl_recs = 1; /* We want the additional Records */ - array_init(authns); - pval_destructor(addtl); - array_init(addtl); - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string(host); - - if (type_param&~PHP_DNS_ALL && type_param!=PHP_DNS_ANY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type '%d' not supported", type_param); - RETURN_FALSE; - } - - /* Initialize the return array */ - array_init(return_value); - - /* - We emulate an or'ed type mask by querying type by type. (Steps 0 - 8) - * If additional info is wanted we check again with T_ANY (step 9/10) - * store_results is used to skip storing the results retrieved in step - * 10 when results were already fetched. - * - In case of PHP_DNS_ANY we use the directly fetch T_ANY. (step 10) - */ - for(type = (type_param==PHP_DNS_ANY ? 10 : 0); type < (addtl_recs ? 11 : 9) || first_query; type++) - { - first_query = 0; - switch(type) { - case 0: - type_to_fetch = type_param&PHP_DNS_A ? T_A : 0; - break; - case 1: - type_to_fetch = type_param&PHP_DNS_NS ? T_NS : 0; - break; - case 2: - type_to_fetch = type_param&PHP_DNS_CNAME ? T_CNAME : 0; - break; - case 3: - type_to_fetch = type_param&PHP_DNS_SOA ? T_SOA : 0; - break; - case 4: - type_to_fetch = type_param&PHP_DNS_PTR ? T_PTR : 0; - break; - case 5: - type_to_fetch = type_param&PHP_DNS_HINFO ? T_HINFO : 0; - break; - case 6: - type_to_fetch = type_param&PHP_DNS_MX ? T_MX : 0; - break; - case 7: - type_to_fetch = type_param&PHP_DNS_TXT ? T_TXT : 0; - break; - case 8: -#ifdef T_AAAA - type_to_fetch = type_param&PHP_DNS_AAAA ? T_AAAA : 0; - break; -#else - continue; -#endif - case 9: - store_results = 0; - continue; - default: - case 10: - type_to_fetch = T_ANY; - break; - } - if (type_to_fetch) { - res_ninit(&res); - res.retrans = 5; - res.options &= ~RES_DEFNAMES; - - n = res_nmkquery(&res, QUERY, Z_STRVAL_P(host), C_IN, type_to_fetch, NULL, 0, NULL, buf.qb2, sizeof buf); - if (n<0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "res_nmkquery() failed"); - zval_dtor(return_value); - RETURN_FALSE; - } - n = res_nsend(&res, buf.qb2, n, answer.qb2, sizeof answer); - if (n<0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "res_nsend() failed"); - zval_dtor(return_value); - RETURN_FALSE; - } - - cp = answer.qb2 + HFIXEDSZ; - end = answer.qb2 + n; - ans = &answer; - hp = (HEADER *)ans; - qd = ntohs(hp->qdcount); - an = ntohs(hp->ancount); - ns = ntohs(hp->nscount); - ar = ntohs(hp->arcount); - - /* Skip QD entries, they're only used by dn_expand later on */ - while (qd-- > 0) { - n = dn_skipname(cp, end); - if (n < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to parse DNS data received"); - zval_dtor(return_value); - RETURN_FALSE; - } - cp += n + QFIXEDSZ; - } - - /* YAY! Our real answers! */ - while (an-- && cp && cp < end) { - cp = php_parserr(cp, &answer, type_to_fetch, store_results, &subarray[current_subarray]); - if (subarray[current_subarray] != NULL && store_results) - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&subarray[current_subarray], sizeof(zval *), NULL); - current_subarray++; - } - res_nclose(&res); - } - } - - if (addtl_recs) { - /* List of Authoritative Name Servers */ - while (ns-- > 0 && cp && cp < end) { - cp = php_parserr(cp, &answer, T_ANY, 1, &subarray[current_subarray]); - if (subarray[current_subarray] != NULL) - zend_hash_next_index_insert(HASH_OF(authns), (void *)&subarray[current_subarray], sizeof(zval *), NULL); - current_subarray++; - } - /* Additional records associated with authoritative name servers */ - while (ar-- > 0 && cp && cp < end) { - cp = php_parserr(cp, &answer, T_ANY, 1, &subarray[current_subarray]); - if (subarray[current_subarray] != NULL) - zend_hash_next_index_insert(HASH_OF(addtl), (void *)&subarray[current_subarray], sizeof(zval *), NULL); - current_subarray++; - } - } -} -/* }}} */ -#endif /* HAVE_DNS_FUNCS */ - -#if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND -/* {{{ proto bool dns_get_mx(string hostname, array mxhosts [, array weight]) - Get MX records corresponding to a given Internet host name */ -PHP_FUNCTION(dns_get_mx) -{ - pval *host, *mx_list, *weight_list; - int need_weight = 0; - int count, qdc; - u_short type, weight; - u_char ans[MAXPACKET]; - char buf[MAXHOSTNAMELEN]; - HEADER *hp; - u_char *cp, *end; - int i; - - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters(ht, 2, &host, &mx_list) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - - case 3: - if (zend_get_parameters(ht, 3, &host, &mx_list, &weight_list) == FAILURE) { - WRONG_PARAM_COUNT; - } - need_weight = 1; - pval_destructor(weight_list); /* start with clean array */ - array_init(weight_list); - break; - - default: - WRONG_PARAM_COUNT; - } - - convert_to_string(host); - pval_destructor(mx_list); /* start with clean array */ - array_init(mx_list); - - /* Go! */ - i = res_search(Z_STRVAL_P(host), C_IN, T_MX, (u_char *)&ans, sizeof(ans)); - if (i < 0) { - RETURN_FALSE; - } - if (i > sizeof(ans)) { - i = sizeof(ans); - } - hp = (HEADER *)&ans; - cp = (u_char *)&ans + HFIXEDSZ; - end = (u_char *)&ans +i; - for (qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) { - if ((i = dn_skipname(cp, end)) < 0 ) { - RETURN_FALSE; - } - } - count = ntohs((unsigned short)hp->ancount); - while (--count >= 0 && cp < end) { - if ((i = dn_skipname(cp, end)) < 0 ) { - RETURN_FALSE; - } - cp += i; - GETSHORT(type, cp); - cp += INT16SZ + INT32SZ; - GETSHORT(i, cp); - if (type != T_MX) { - cp += i; - continue; - } - GETSHORT(weight, cp); - if ((i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0) { - RETURN_FALSE; - } - cp += i; - add_next_index_string(mx_list, buf, 1); - if (need_weight) { - add_next_index_long(weight_list, weight); - } - } - RETURN_TRUE; -} -/* }}} */ -#endif /* HAVE_DN_SKIPNAME && HAVE_DN_EXPAND */ - -#endif /* HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32) || defined(NETWARE)) */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/dns.h b/ext/standard/dns.h deleted file mode 100644 index 303d4705dc..0000000000 --- a/ext/standard/dns.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: The typical suspects | - | Marcus Boerger <helly@php.net> | - | Pollita <pollita@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef DNS_H -#define DNS_H - -#if HAVE_RES_NMKQUERY & HAVE_RES_NSEND & HAVE_DN_EXPAND & HAVE_DN_SKIPNAME -#define HAVE_DNS_FUNCS 1 -#endif - -PHP_FUNCTION(gethostbyaddr); -PHP_FUNCTION(gethostbyname); -PHP_FUNCTION(gethostbynamel); - -#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32)) - -PHP_FUNCTION(dns_check_record); -# if HAVE_DN_SKIPNAME && HAVE_DN_EXPAND -PHP_FUNCTION(dns_get_mx); -# endif - -# if HAVE_DNS_FUNCS - -PHP_FUNCTION(dns_get_record); - -PHP_MINIT_FUNCTION(dns); - -# endif -#endif - -#ifndef INT16SZ -#define INT16SZ 2 -#endif - -#ifndef INT32SZ -#define INT32SZ 4 -#endif - -#endif /* DNS_H */ diff --git a/ext/standard/exec.c b/ext/standard/exec.c deleted file mode 100644 index 7d17c8e00f..0000000000 --- a/ext/standard/exec.c +++ /dev/null @@ -1,445 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@php.net> | - | Ilia Alshanetsky <iliaa@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include <ctype.h> -#include "php_string.h" -#include "safe_mode.h" -#include "ext/standard/head.h" -#include "ext/standard/file.h" -#include "exec.h" -#include "php_globals.h" -#include "SAPI.h" - -#if HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif - -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif - -#if HAVE_NICE && HAVE_UNISTD_H -#include <unistd.h> -#endif - -/* {{{ php_exec - * If type==0, only last line of output is returned (exec) - * If type==1, all lines will be printed and last lined returned (system) - * If type==2, all lines will be saved to given array (exec with &$array) - * If type==3, output will be printed binary, no lines will be saved or returned (passthru) - * - */ -int php_exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC) -{ - FILE *fp; - char *buf, *tmp=NULL; - int buflen, l, pclose_return; - char *cmd_p, *b, *c, *d=NULL; - php_stream *stream; - size_t bufl = 0; -#if PHP_SIGCHILD - void (*sig_handler)(); -#endif - - if (PG(safe_mode)) { - if ((c = strchr(cmd, ' '))) { - *c = '\0'; - c++; - } - if (strstr(cmd, "..")) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No '..' components allowed in path"); - goto err; - } - b = strrchr(cmd, PHP_DIR_SEPARATOR); - spprintf(&d, 0, "%s%s%s%s", PG(safe_mode_exec_dir), (b ? "" : "/"), (b ? b : cmd), (c ? " " : ""), (c ? c : "")); - if (c) { - *(c - 1) = ' '; - } - cmd_p = php_escape_shell_cmd(d); - efree(d); - d = cmd_p; - } else { - cmd_p = cmd; - } - -#if PHP_SIGCHILD - sig_handler = signal (SIGCHLD, SIG_DFL); -#endif - -#ifdef PHP_WIN32 - fp = VCWD_POPEN(cmd_p, "rb"); -#else - fp = VCWD_POPEN(cmd_p, "r"); -#endif - if (!fp) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to fork [%s]", cmd); - goto err; - } - - stream = php_stream_fopen_from_pipe(fp, "rb"); - - buf = (char *) emalloc(EXEC_INPUT_BUF); - buflen = EXEC_INPUT_BUF; - - if (type != 3) { - b = buf; - - while (php_stream_get_line(stream, b, EXEC_INPUT_BUF, &bufl)) { - /* no new line found, let's read some more */ - if (b[bufl - 1] != '\n' && !php_stream_eof(stream)) { - if (buflen < (bufl + EXEC_INPUT_BUF)) { - bufl += b - buf; - buflen = bufl + EXEC_INPUT_BUF; - buf = erealloc(buf, buflen); - b = buf + bufl; - } else { - b += bufl; - } - continue; - } else if (b != buf) { - bufl += buflen - EXEC_INPUT_BUF; - } - - if (type == 1) { - PHPWRITE(buf, bufl); - sapi_flush(TSRMLS_C); - } else if (type == 2) { - /* strip trailing whitespaces */ - l = bufl; - while (l-- && isspace(buf[l])); - if (l != (bufl - 1)) { - bufl = l + 1; - buf[bufl] = '\0'; - } - add_next_index_stringl(array, buf, bufl, 1); - } - b = buf; - } - if (bufl) { - /* strip trailing whitespaces if we have not done so already */ - if (type != 2) { - l = bufl; - while (l-- && isspace(buf[l])); - if (l != (bufl - 1)) { - bufl = l + 1; - buf[bufl] = '\0'; - } - } - - /* Return last line from the shell command */ - if (PG(magic_quotes_runtime)) { - int len; - - tmp = php_addslashes(buf, bufl, &len, 0 TSRMLS_CC); - RETVAL_STRINGL(tmp, len, 0); - } else { - RETVAL_STRINGL(buf, bufl, 1); - } - } else { /* should return NULL, but for BC we return "" */ - RETVAL_EMPTY_STRING(); - } - } else { - while((bufl = php_stream_read(stream, buf, EXEC_INPUT_BUF)) > 0) { - PHPWRITE(buf, bufl); - } - } - - pclose_return = php_stream_close(stream); - efree(buf); - -done: -#if PHP_SIGCHILD - signal (SIGCHLD, sig_handler); -#endif - if (d) { - efree(d); - } - return pclose_return; -err: - pclose_return = -1; - goto done; -} -/* }}} */ - -static void php_exec_ex(INTERNAL_FUNCTION_PARAMETERS, int mode) -{ - char *cmd; - int cmd_len; - zval *ret_code=NULL, *ret_array=NULL; - int ret; - - if (mode) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &cmd, &cmd_len, &ret_code) == FAILURE) { - RETURN_FALSE; - } - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zz", &cmd, &cmd_len, &ret_array, &ret_code) == FAILURE) { - RETURN_FALSE; - } - } - if (!cmd_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot execute a blank command"); - RETURN_FALSE; - } - - if (!ret_array) { - ret = php_exec(mode, cmd, NULL, return_value TSRMLS_CC); - } else { - zval_dtor(ret_array); - array_init(ret_array); - ret = php_exec(2, cmd, ret_array, return_value TSRMLS_CC); - } - if (ret_code) { - zval_dtor(ret_code); - ZVAL_LONG(ret_code, ret); - } -} - -/* {{{ proto string exec(string command [, array &output [, int &return_value]]) - Execute an external program */ -PHP_FUNCTION(exec) -{ - php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} - -/* }}} */ - -/* {{{ proto int system(string command [, int &return_value]) - Execute an external program and display output */ -PHP_FUNCTION(system) -{ - php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto void passthru(string command [, int &return_value]) - Execute an external program and display raw output */ -PHP_FUNCTION(passthru) -{ - php_exec_ex(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); -} -/* }}} */ - -/* {{{ php_escape_shell_cmd - Escape all chars that could possibly be used to - break out of a shell command - - This function emalloc's a string and returns the pointer. - Remember to efree it when done with it. - - *NOT* safe for binary strings -*/ -char *php_escape_shell_cmd(char *str) { - register int x, y, l; - char *cmd; - - l = strlen(str); - cmd = emalloc(2 * l + 1); - - for (x = 0, y = 0; x < l; x++) { - switch (str[x]) { - case '#': /* This is character-set independent */ - case '&': - case ';': - case '`': - case '\'': - case '"': - case '|': - case '*': - case '?': - case '~': - case '<': - case '>': - case '^': - case '(': - case ')': - case '[': - case ']': - case '{': - case '}': - case '$': - case '\\': - case '\x0A': /* excluding these two */ - case '\xFF': - cmd[y++] = '\\'; - /* fall-through */ - default: - cmd[y++] = str[x]; - - } - } - cmd[y] = '\0'; - return cmd; -} -/* }}} */ - -/* {{{ php_escape_shell_arg - */ -char *php_escape_shell_arg(char *str) { - int x, y, l; - char *cmd; - - y = 0; - l = strlen(str); - - cmd = emalloc(4 * l + 3); /* worst case */ - - cmd[y++] = '\''; - - for (x = 0; x < l; x++) { - switch (str[x]) { - case '\'': - cmd[y++] = '\''; - cmd[y++] = '\\'; - cmd[y++] = '\''; - /* fall-through */ - default: - cmd[y++] = str[x]; - } - } - cmd[y++] = '\''; - cmd[y] = '\0'; - return cmd; -} -/* }}} */ - -/* {{{ proto string escapeshellcmd(string command) - Escape shell metacharacters */ -PHP_FUNCTION(escapeshellcmd) -{ - pval **arg1; - char *cmd = NULL; - - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg1); - if (Z_STRLEN_PP(arg1)) { - cmd = php_escape_shell_cmd(Z_STRVAL_PP(arg1)); - RETVAL_STRING(cmd, 1); - efree(cmd); - } -} -/* }}} */ - -/* {{{ proto string escapeshellarg(string arg) - Quote and escape an argument for use in a shell command */ -PHP_FUNCTION(escapeshellarg) -{ - pval **arg1; - char *cmd = NULL; - - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg1); - if (Z_STRLEN_PP(arg1)) { - cmd = php_escape_shell_arg(Z_STRVAL_PP(arg1)); - RETVAL_STRING(cmd, 1); - efree(cmd); - } -} -/* }}} */ - -/* {{{ proto string shell_exec(string cmd) - Use pclose() for FILE* that has been opened via popen() */ -PHP_FUNCTION(shell_exec) -{ - FILE *in; - size_t total_readbytes; - pval **cmd; - char *ret; - php_stream *stream; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &cmd)==FAILURE) { - WRONG_PARAM_COUNT; - } - - if (PG(safe_mode)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot execute using backquotes in Safe Mode"); - RETURN_FALSE; - } - - convert_to_string_ex(cmd); -#ifdef PHP_WIN32 - if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "rt"))==NULL) { -#else - if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "r"))==NULL) { -#endif - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to execute '%s'", Z_STRVAL_PP(cmd)); - RETURN_FALSE; - } - - stream = php_stream_fopen_from_pipe(in, "rb"); - total_readbytes = php_stream_copy_to_mem(stream, &ret, PHP_STREAM_COPY_ALL, 0); - php_stream_close(stream); - - if (total_readbytes > 0) { - RETURN_STRINGL(ret, total_readbytes, 0); - } else { - RETURN_NULL(); - } -} -/* }}} */ - -#ifdef HAVE_NICE -/* {{{ proto bool proc_nice(int priority) - Change the priority of the current process */ -PHP_FUNCTION(proc_nice) -{ - long pri; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pri) == FAILURE) { - RETURN_FALSE; - } - - errno = 0; - nice(pri); - if (errno) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only a super user may attempt to increase the priority of a process."); - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/exec.h b/ext/standard/exec.h deleted file mode 100644 index 6d5fb66f70..0000000000 --- a/ext/standard/exec.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef EXEC_H -#define EXEC_H - -PHP_FUNCTION(system); -PHP_FUNCTION(exec); -PHP_FUNCTION(escapeshellcmd); -PHP_FUNCTION(escapeshellarg); -PHP_FUNCTION(passthru); -PHP_FUNCTION(shell_exec); -PHP_FUNCTION(proc_open); -PHP_FUNCTION(proc_get_status); -PHP_FUNCTION(proc_close); -PHP_FUNCTION(proc_terminate); -PHP_FUNCTION(proc_nice); -PHP_MINIT_FUNCTION(proc_open); - -char *php_escape_shell_cmd(char *); -char *php_escape_shell_arg(char *); -int php_exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC); - -#endif /* EXEC_H */ diff --git a/ext/standard/file.c b/ext/standard/file.c deleted file mode 100644 index 9da076e08a..0000000000 --- a/ext/standard/file.c +++ /dev/null @@ -1,2828 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Stig Bakken <ssb@fast.no> | - | Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) | - | PHP streams by Wez Furlong (wez@thebrainroom.com) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ - -/* {{{ includes */ - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/flock_compat.h" -#include "ext/standard/exec.h" -#include "ext/standard/php_filestat.h" -#include "php_open_temporary_file.h" -#include "ext/standard/basic_functions.h" -#include "php_ini.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#include "win32/winutil.h" -#elif defined(NETWARE) && !defined(NEW_LIBC) -/*#include <ws2nlm.h>*/ -#include <sys/socket.h> -#include "netware/param.h" -#else -#include <sys/param.h> -#include <sys/select.h> -#if defined(NETWARE) && defined(USE_WINSOCK) -#include <novsock2.h> -#else -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#endif -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif -#include "ext/standard/head.h" -#include "safe_mode.h" -#include "php_string.h" -#include "file.h" -#if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#elif defined(NETWARE) -#include "netware/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#include "fsock.h" -#include "fopen_wrappers.h" -#include "php_streams.h" -#include "php_globals.h" - -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> -#endif - -#if MISSING_FCLOSE_DECL -extern int fclose(FILE *); -#endif - -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif - -#include "scanf.h" -#include "zend_API.h" - -#ifdef ZTS -int file_globals_id; -#else -php_file_globals file_globals; -#endif - -#ifdef HAVE_FNMATCH -#include <fnmatch.h> -#endif - -/* }}} */ -/* {{{ ZTS-stuff / Globals / Prototypes */ - -/* sharing globals is *evil* */ -static int le_stream_context = FAILURE; - -/* }}} */ -/* {{{ Module-Stuff */ - -static ZEND_RSRC_DTOR_FUNC(file_context_dtor) -{ - php_stream_context_free((php_stream_context*)rsrc->ptr); -} - -static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC) -{ - FG(pclose_ret) = 0; - FG(user_stream_current_filename) = NULL; - FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE; -} - -static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC) -{ -} - - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals) - STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateInt, default_socket_timeout, php_file_globals, file_globals) - STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateInt, auto_detect_line_endings, php_file_globals, file_globals) -PHP_INI_END() - -PHP_MINIT_FUNCTION(file) -{ - le_stream_context = zend_register_list_destructors_ex(file_context_dtor, NULL, "stream-context", module_number); - -#ifdef ZTS - ts_allocate_id(&file_globals_id, sizeof(php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor); -#else - file_globals_ctor(&file_globals TSRMLS_CC); -#endif - - REGISTER_INI_ENTRIES(); - - REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SEEK_CUR", SEEK_CUR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("SEEK_END", SEEK_END, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOCK_SH", 1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOCK_EX", 2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOCK_UN", 3, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOCK_NB", 4, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_CONNECT", PHP_STREAM_NOTIFY_CONNECT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_REQUIRED", PHP_STREAM_NOTIFY_AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_RESULT", PHP_STREAM_NOTIFY_AUTH_RESULT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_MIME_TYPE_IS", PHP_STREAM_NOTIFY_MIME_TYPE_IS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FILE_SIZE_IS", PHP_STREAM_NOTIFY_FILE_SIZE_IS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_REDIRECTED", PHP_STREAM_NOTIFY_REDIRECTED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_PROGRESS", PHP_STREAM_NOTIFY_PROGRESS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FAILURE", PHP_STREAM_NOTIFY_FAILURE, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_INFO", PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_WARN", PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_ERR", PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_FILTER_READ", PHP_STREAM_FILTER_READ, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_FILTER_WRITE", PHP_STREAM_FILTER_WRITE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_FILTER_ALL", PHP_STREAM_FILTER_ALL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("FILE_USE_INCLUDE_PATH", PHP_FILE_USE_INCLUDE_PATH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_IGNORE_NEW_LINES", PHP_FILE_IGNORE_NEW_LINES, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FILE_SKIP_EMPTY_LINES", PHP_FILE_SKIP_EMPTY_LINES, CONST_CS | CONST_PERSISTENT); - -#ifdef HAVE_FNMATCH - REGISTER_LONG_CONSTANT("FNM_NOESCAPE", FNM_NOESCAPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FNM_PATHNAME", FNM_PATHNAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("FNM_PERIOD", FNM_PERIOD, CONST_CS | CONST_PERSISTENT); -#ifdef FNM_CASEFOLD /* a GNU extension */ /* TODO emulate if not available */ - REGISTER_LONG_CONSTANT("FNM_CASEFOLD", FNM_CASEFOLD, CONST_CS | CONST_PERSISTENT); -#endif -#endif - - return SUCCESS; -} - -/* }}} */ - -PHP_MSHUTDOWN_FUNCTION(file) -{ -#ifndef ZTS - file_globals_dtor(&file_globals TSRMLS_CC); -#endif - return SUCCESS; -} - - - -/* {{{ proto bool flock(resource fp, int operation [, int &wouldblock]) - Portable file locking */ - -static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; - -PHP_FUNCTION(flock) -{ - zval *arg1, *arg3 = NULL; - int fd, act; - php_stream *stream; - long operation = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &arg1, &operation, &arg3) == FAILURE) { - return; - } - - php_stream_from_zval(stream, &arg1); - - if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 1) == FAILURE) { - RETURN_FALSE; - } - - act = operation & 3; - if (act < 1 || act > 3) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal operation argument"); - RETURN_FALSE; - } - - /* flock_values contains all possible actions if (operation & 4) we won't block on the lock */ - act = flock_values[act - 1] | (operation & 4 ? LOCK_NB : 0); - if (!php_stream_lock(stream, act)) { - if (operation && errno == EWOULDBLOCK && arg3 && PZVAL_IS_REF(arg3)) { - convert_to_long_ex(&arg3); - ZVAL_LONG(arg3, 1); - } - RETURN_TRUE; - } - RETURN_FALSE; -} - -/* }}} */ - -#define PHP_META_UNSAFE ".\\+*?[^]$() " - -/* {{{ proto array get_meta_tags(string filename [, bool use_include_path]) - Extracts all meta tag content attributes from a file and returns an array */ - -PHP_FUNCTION(get_meta_tags) -{ - char *filename; - int filename_len; - zend_bool use_include_path = 0; - int in_tag = 0, done = 0; - int looking_for_val = 0, have_name = 0, have_content = 0; - int saw_name = 0, saw_content = 0; - char *name = NULL, *value = NULL, *temp = NULL; - php_meta_tags_token tok, tok_last; - php_meta_tags_data md; - - /* Initiailize our structure */ - memset(&md, 0, sizeof(md)); - - /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", - &filename, &filename_len, &use_include_path) == FAILURE) { - return; - } - - md.stream = php_stream_open_wrapper(filename, "rb", - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); - - if (!md.stream) { - RETURN_FALSE; - } - - array_init(return_value); - - tok_last = TOK_EOF; - - while (!done && (tok = php_next_meta_token(&md TSRMLS_CC)) != TOK_EOF) { - if (tok == TOK_ID) { - if (tok_last == TOK_OPENTAG) { - md.in_meta = !strcasecmp("meta", md.token_data); - } else if (tok_last == TOK_SLASH && in_tag) { - if (strcasecmp("head", md.token_data) == 0) { - /* We are done here! */ - done = 1; - } - } else if (tok_last == TOK_EQUAL && looking_for_val) { - if (saw_name) { - /* Get the NAME attr (Single word attr, non-quoted) */ - temp = name = estrndup(md.token_data, md.token_len); - - while (temp && *temp) { - if (strchr(PHP_META_UNSAFE, *temp)) { - *temp = '_'; - } - temp++; - } - - have_name = 1; - } else if (saw_content) { - /* Get the CONTENT attr (Single word attr, non-quoted) */ - if (PG(magic_quotes_runtime)) { - value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC); - } else { - value = estrndup(md.token_data, md.token_len); - } - - have_content = 1; - } - - looking_for_val = 0; - } else { - if (md.in_meta) { - if (strcasecmp("name", md.token_data) == 0) { - saw_name = 1; - saw_content = 0; - looking_for_val = 1; - } else if (strcasecmp("content", md.token_data) == 0) { - saw_name = 0; - saw_content = 1; - looking_for_val = 1; - } - } - } - } else if (tok == TOK_STRING && tok_last == TOK_EQUAL && looking_for_val) { - if (saw_name) { - /* Get the NAME attr (Quoted single/double) */ - temp = name = estrndup(md.token_data, md.token_len); - - while (temp && *temp) { - if (strchr(PHP_META_UNSAFE, *temp)) { - *temp = '_'; - } - temp++; - } - - have_name = 1; - } else if (saw_content) { - /* Get the CONTENT attr (Single word attr, non-quoted) */ - if (PG(magic_quotes_runtime)) { - value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC); - } else { - value = estrndup(md.token_data, md.token_len); - } - - have_content = 1; - } - - looking_for_val = 0; - } else if (tok == TOK_OPENTAG) { - if (looking_for_val) { - looking_for_val = 0; - have_name = saw_name = 0; - have_content = saw_content = 0; - } - in_tag = 1; - } else if (tok == TOK_CLOSETAG) { - if (have_name) { - /* For BC */ - php_strtolower(name, strlen(name)); - if (have_content) { - add_assoc_string(return_value, name, value, 0); - } else { - add_assoc_string(return_value, name, empty_string, 0); - } - - efree(name); - } else if (have_content) { - efree(value); - } - - name = value = NULL; - - /* Reset all of our flags */ - in_tag = looking_for_val = 0; - have_name = saw_name = 0; - have_content = saw_content = 0; - md.in_meta = 0; - } - - tok_last = tok; - - if (md.token_data) - efree(md.token_data); - - md.token_data = NULL; - } - - php_stream_close(md.stream); -} - -/* }}} */ - -/* {{{ proto string file_get_contents(string filename [, bool use_include_path]) - Read the entire file into a string */ -PHP_FUNCTION(file_get_contents) -{ - char *filename; - int filename_len; - char *contents; - zend_bool use_include_path = 0; - php_stream *stream; - int len, newlen; - - /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", - &filename, &filename_len, &use_include_path) == FAILURE) { - return; - } - - stream = php_stream_open_wrapper(filename, "rb", - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); - if (!stream) { - RETURN_FALSE; - } - - /* uses mmap if possible */ - if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) >= 0) { - - if (PG(magic_quotes_runtime)) { - contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */ - len = newlen; - } - - RETVAL_STRINGL(contents, len, 0); - } else { - RETVAL_FALSE; - } - - php_stream_close(stream); - -} -/* }}} */ - -/* {{{ proto array file(string filename [, int flags]) - Read entire file into an array */ - -#define PHP_FILE_BUF_SIZE 80 - -PHP_FUNCTION(file) -{ - char *filename; - int filename_len; - char *slashed, *target_buf=NULL, *p, *s, *e; - register int i = 0; - int target_len, len; - char eol_marker = '\n'; - long flags = 0; - zend_bool use_include_path; - zend_bool include_new_line; - zend_bool skip_blank_lines; - php_stream *stream; - - /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) { - return; - } - if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%l' flag is not supported.", flags); - RETURN_FALSE; - } - - use_include_path = flags & PHP_FILE_USE_INCLUDE_PATH; - include_new_line = !(flags & PHP_FILE_IGNORE_NEW_LINES); - skip_blank_lines = flags & PHP_FILE_SKIP_EMPTY_LINES; - - stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); - if (!stream) { - RETURN_FALSE; - } - - /* Initialize return array */ - array_init(return_value); - - if ((target_len = php_stream_copy_to_mem(stream, &target_buf, PHP_STREAM_COPY_ALL, 0))) { - s = target_buf; - e = target_buf + target_len; - - if (!(p = php_stream_locate_eol(stream, target_buf, target_len TSRMLS_CC))) { - p = e; - goto parse_eol; - } - - if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) { - eol_marker = '\r'; - } - - /* for performance reasons the code is duplicated, so that the if (include_new_line) - * will not need to be done for every single line in the file. - */ - if (include_new_line) { - do { - p++; - parse_eol: - if (PG(magic_quotes_runtime)) { - /* s is in target_buf which is freed at the end of the function */ - slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC); - add_index_stringl(return_value, i++, slashed, len, 0); - } else { - add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); - } - s = p; - } while ((p = memchr(p, eol_marker, (e-p)))); - } else { - do { - if (skip_blank_lines && !(p-s)) { - s = ++p; - continue; - } - if (PG(magic_quotes_runtime)) { - /* s is in target_buf which is freed at the end of the function */ - slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC); - add_index_stringl(return_value, i++, slashed, len, 0); - } else { - add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); - } - s = ++p; - } while ((p = memchr(p, eol_marker, (e-p)))); - } - - /* handle any left overs of files without new lines */ - if (s != e) { - p = e; - goto parse_eol; - } - } - - if (target_buf) { - efree(target_buf); - } - php_stream_close(stream); -} -/* }}} */ - -/* {{{ proto string tempnam(string dir, string prefix) - Create a unique filename in a directory */ -PHP_FUNCTION(tempnam) -{ - pval **arg1, **arg2; - char *d; - char *opened_path; - char p[64]; - FILE *fp; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - - if (php_check_open_basedir(Z_STRVAL_PP(arg1) TSRMLS_CC)) { - RETURN_FALSE; - } - - d = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1)); - strlcpy(p, Z_STRVAL_PP(arg2), sizeof(p)); - - if ((fp = php_open_temporary_file(d, p, &opened_path TSRMLS_CC))) { - fclose(fp); - RETVAL_STRING(opened_path, 0); - } else { - RETVAL_FALSE; - } - efree(d); -} -/* }}} */ - -/* {{{ proto resource tmpfile(void) - Create a temporary file that will be deleted automatically after use */ -PHP_NAMED_FUNCTION(php_if_tmpfile) -{ - php_stream *stream; - - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - stream = php_stream_fopen_tmpfile(); - - if (stream) { - php_stream_to_zval(stream, return_value); - } - else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto resource stream_get_meta_data(resource fp) - Retrieves header/meta data from streams/file pointers */ -PHP_FUNCTION(stream_get_meta_data) -{ - zval **arg1; - php_stream *stream; - zval *newval; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - php_stream_from_zval(stream, arg1); - - array_init(return_value); - - if (stream->wrapperdata) { - MAKE_STD_ZVAL(newval); - *newval = *(stream->wrapperdata); - zval_copy_ctor(newval); - - add_assoc_zval(return_value, "wrapper_data", newval); - } - if (stream->wrapper) { - add_assoc_string(return_value, "wrapper_type", (char *)stream->wrapper->wops->label, 1); - } - add_assoc_string(return_value, "stream_type", (char *)stream->ops->label, 1); - -#if 0 /* TODO: needs updating for new filter API */ - if (stream->filterhead) { - php_stream_filter *filter; - - MAKE_STD_ZVAL(newval); - array_init(newval); - - for (filter = stream->filterhead; filter != NULL; filter = filter->next) { - add_next_index_string(newval, (char *)filter->fops->label, 1); - } - - add_assoc_zval(return_value, "filters", newval); - } -#endif - - add_assoc_long(return_value, "unread_bytes", stream->writepos - stream->readpos); - -#if 0 - if (php_stream_is(stream, PHP_STREAM_IS_SOCKET)) { - php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM(stream); - - add_assoc_bool(return_value, "timed_out", sock->timeout_event); - add_assoc_bool(return_value, "blocked", sock->is_blocked); - add_assoc_bool(return_value, "eof", stream->eof); - } else { -#endif - add_assoc_bool(return_value, "timed_out", 0); - add_assoc_bool(return_value, "blocked", 1); - add_assoc_bool(return_value, "eof", php_stream_eof(stream)); -#if 0 - } -#endif - -} -/* }}} */ - -/* {{{ proto array stream_get_wrappers() - Retrieves list of registered stream wrappers */ -PHP_FUNCTION(stream_get_wrappers) -{ - HashTable *url_stream_wrappers_hash; - char *stream_protocol; - int key_flags, stream_protocol_len = 0; - - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) { - array_init(return_value); - for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash); - (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT; - zend_hash_move_forward(url_stream_wrappers_hash)) { - if (key_flags == HASH_KEY_IS_STRING) { - add_next_index_stringl(return_value, stream_protocol, stream_protocol_len, 1); - } - } - } else { - RETURN_FALSE; - } - -} -/* }}} */ - -/* {{{ stream_select related functions */ -static int stream_array_to_fd_set(zval *stream_array, fd_set *fds, int *max_fd TSRMLS_DC) -{ - zval **elem; - php_stream *stream; - int this_fd; - - if (Z_TYPE_P(stream_array) != IS_ARRAY) { - return 0; - } - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - - php_stream_from_zval_no_verify(stream, elem); - if (stream == NULL) { - continue; - } - /* get the fd. - * NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag - * when casting. It is only used here so that the buffered data warning - * is not displayed. - * */ - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) { - FD_SET(this_fd, fds); - if (this_fd > *max_fd) { - *max_fd = this_fd; - } - } - } - return 1; -} - -static int stream_array_from_fd_set(zval *stream_array, fd_set *fds TSRMLS_DC) -{ - zval **elem, **dest_elem; - php_stream *stream; - HashTable *new_hash; - int this_fd, ret = 0; - - if (Z_TYPE_P(stream_array) != IS_ARRAY) { - return 0; - } - ALLOC_HASHTABLE(new_hash); - zend_hash_init(new_hash, 0, NULL, ZVAL_PTR_DTOR, 0); - - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - - php_stream_from_zval_no_verify(stream, elem); - if (stream == NULL) { - continue; - } - /* get the fd - * NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag - * when casting. It is only used here so that the buffered data warning - * is not displayed. - */ - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | PHP_STREAM_CAST_INTERNAL, (void*)&this_fd, 1)) { - if (FD_ISSET(this_fd, fds)) { - zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem); - if (dest_elem) { - zval_add_ref(dest_elem); - } - ret++; - continue; - } - } - } - - /* destroy old array and add new one */ - zend_hash_destroy(Z_ARRVAL_P(stream_array)); - efree(Z_ARRVAL_P(stream_array)); - - zend_hash_internal_pointer_reset(new_hash); - Z_ARRVAL_P(stream_array) = new_hash; - - return ret; -} - -static int stream_array_emulate_read_fd_set(zval *stream_array TSRMLS_DC) -{ - zval **elem, **dest_elem; - php_stream *stream; - HashTable *new_hash; - int ret = 0; - - if (Z_TYPE_P(stream_array) != IS_ARRAY) { - return 0; - } - ALLOC_HASHTABLE(new_hash); - zend_hash_init(new_hash, 0, NULL, ZVAL_PTR_DTOR, 0); - - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array)); - zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) &elem) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(stream_array))) { - - php_stream_from_zval_no_verify(stream, elem); - if (stream == NULL) { - continue; - } - if ((stream->writepos - stream->readpos) > 0) { - /* allow readable non-descriptor based streams to participate in stream_select. - * Non-descriptor streams will only "work" if they have previously buffered the - * data. Not ideal, but better than nothing. - * This branch of code also allows blocking streams with buffered data to - * operate correctly in stream_select. - * */ - zend_hash_next_index_insert(new_hash, (void *)elem, sizeof(zval *), (void **)&dest_elem); - if (dest_elem) { - zval_add_ref(dest_elem); - } - ret++; - continue; - } - } - - if (ret > 0) { - /* destroy old array and add new one */ - zend_hash_destroy(Z_ARRVAL_P(stream_array)); - efree(Z_ARRVAL_P(stream_array)); - - zend_hash_internal_pointer_reset(new_hash); - Z_ARRVAL_P(stream_array) = new_hash; - } else { - zend_hash_destroy(new_hash); - FREE_HASHTABLE(new_hash); - } - - return ret; -} -/* }}} */ - -#ifdef PHP_WIN32 -/* Win32 select() will only work with sockets, so we roll our own implementation that will - * get the OS file handle from regular fd's and sockets and then use WaitForMultipleObjects(). - * This implementation is not as feature-full as posix select, but it works for our purposes - */ -static int php_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv) -{ - HANDLE *handles; - DWORD waitret; - DWORD ms_total; - int i, f, s, fd_count = 0, sock_count = 0; - int retval; - fd_set ard, awr, aex; /* active fd sets */ - - for (i = 0; i < max_fd; i++) { - if (FD_ISSET(i, rfds) || FD_ISSET(i, wfds) || FD_ISSET(i, efds)) { - if (_get_osfhandle(i) == 0xffffffff) { - /* it is a socket */ - sock_count++; - } else { - fd_count++; - } - } - } - - if (fd_count + sock_count == 0) { - return 0; - } - - handles = (HANDLE*)emalloc((fd_count + sock_count) * sizeof(HANDLE)); - - /* populate the events and handles arrays */ - f = 0; - s = 0; - for (i = 0; i < max_fd; i++) { - if (FD_ISSET(i, rfds) || FD_ISSET(i, wfds) || FD_ISSET(i, efds)) { - long h = _get_osfhandle(i); - if (h == 0xFFFFFFFF) { - HANDLE evt; - long evt_flags = 0; - - if (FD_ISSET(i, rfds)) { - evt_flags |= FD_READ|FD_CONNECT|FD_ACCEPT|FD_CLOSE; - } - if (FD_ISSET(i, wfds)) { - evt_flags |= FD_WRITE; - } - if (FD_ISSET(i, efds)) { - evt_flags |= FD_OOB; - } - - evt = WSACreateEvent(); - WSAEventSelect(i, evt, evt_flags); - - handles[fd_count + s] = evt; - s++; - } else { - handles[f++] = (HANDLE)h; - } - } - } - - /* calculate how long we need to wait in milliseconds */ - if (tv == NULL) { - ms_total = INFINITE; - } else { - ms_total = tv->tv_sec * 1000; - ms_total += tv->tv_usec / 1000; - } - - waitret = MsgWaitForMultipleObjects(fd_count + sock_count, handles, FALSE, ms_total, QS_ALLEVENTS); - - if (waitret == WAIT_TIMEOUT) { - retval = 0; - } else if (waitret == 0xFFFFFFFF) { - retval = -1; - } else { - - FD_ZERO(&ard); - FD_ZERO(&awr); - FD_ZERO(&aex); - - f = 0; - retval = 0; - for (i = 0; i < max_fd; i++) { - if (FD_ISSET(i, rfds) || FD_ISSET(i, wfds) || FD_ISSET(i, efds)) { - if (f >= fd_count) { - /* socket event */ - HANDLE evt = handles[f]; - - if (WAIT_OBJECT_0 == WaitForSingleObject(evt, 0)) { - /* check for various signal states */ - if (FD_ISSET(i, rfds)) { - WSAEventSelect(i, evt, FD_READ|FD_CONNECT|FD_ACCEPT|FD_CLOSE); - if (WAIT_OBJECT_0 == WaitForSingleObject(evt, 0)) { - FD_SET(i, &ard); - } - } - if (FD_ISSET(i, wfds)) { - WSAEventSelect(i, evt, FD_WRITE); - if (WAIT_OBJECT_0 == WaitForSingleObject(evt, 0)) { - FD_SET(i, &awr); - } - } - if (FD_ISSET(i, efds)) { - WSAEventSelect(i, evt, FD_OOB); - if (WAIT_OBJECT_0 == WaitForSingleObject(evt, 0)) { - FD_SET(i, &aex); - } - } - retval++; - } - - WSACloseEvent(evt); - - } else { - if (WAIT_OBJECT_0 == WaitForSingleObject(handles[f], 0)) { - if (FD_ISSET(i, rfds)) { - FD_SET(i, &ard); - } - if (FD_ISSET(i, wfds)) { - FD_SET(i, &awr); - } - if (FD_ISSET(i, efds)) { - FD_SET(i, &aex); - } - retval++; - } - - } - f++; - } - } - - if (rfds) { - *rfds = ard; - } - if (wfds) { - *wfds = awr; - } - if (efds) { - *efds = aex; - } - } - - efree(handles); - - return retval; -} -#else -#define php_select(m, r, w, e, t) select(m, r, w, e, t) -#endif - -/* {{{ proto int stream_select(array &read_streams, array &write_streams, array &except_streams, int tv_sec[, int tv_usec]) - Runs the select() system call on the sets of streams with a timeout specified by tv_sec and tv_usec */ -PHP_FUNCTION(stream_select) -{ - zval *r_array, *w_array, *e_array, *sec; - struct timeval tv; - struct timeval *tv_p = NULL; - fd_set rfds, wfds, efds; - int max_fd = 0; - int retval, sets = 0, usec = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) - return; - - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&efds); - - if (r_array != NULL) sets += stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC); - if (w_array != NULL) sets += stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC); - if (e_array != NULL) sets += stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC); - - if (!sets) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stream arrays were passed"); - RETURN_FALSE; - } - - /* If seconds is not set to null, build the timeval, else we wait indefinitely */ - if (sec != NULL) { - convert_to_long_ex(&sec); - tv.tv_sec = Z_LVAL_P(sec); - tv.tv_usec = usec; - tv_p = &tv; - } - - /* slight hack to support buffered data; if there is data sitting in the - * read buffer of any of the streams in the read array, let's pretend - * that we selected, but return only the readable sockets */ - if (r_array != NULL) { - - retval = stream_array_emulate_read_fd_set(r_array TSRMLS_CC); - if (retval > 0) { - RETURN_LONG(retval); - } - } - - retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p); - - if (retval == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s (max_fd=%d)", - errno, strerror(errno), max_fd); - RETURN_FALSE; - } - - if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC); - if (w_array != NULL) stream_array_from_fd_set(w_array, &wfds TSRMLS_CC); - if (e_array != NULL) stream_array_from_fd_set(e_array, &efds TSRMLS_CC); - - RETURN_LONG(retval); -} -/* }}} */ - -/* {{{ stream_context related functions */ -static void user_space_stream_notifier(php_stream_context *context, int notifycode, int severity, - char *xmsg, int xcode, size_t bytes_sofar, size_t bytes_max, void * ptr TSRMLS_DC) -{ - zval *callback = (zval*)context->notifier->ptr; - zval *retval = NULL; - zval zvs[6]; - zval *ps[6]; - zval **ptps[6]; - int i; - - for (i = 0; i < 6; i++) { - INIT_ZVAL(zvs[i]); - ps[i] = &zvs[i]; - ptps[i] = &ps[i]; - } - - ZVAL_LONG(ps[0], notifycode); - ZVAL_LONG(ps[1], severity); - if (xmsg) { - ZVAL_STRING(ps[2], xmsg, 0); - } else { - ZVAL_NULL(ps[2]); - } - ZVAL_LONG(ps[3], xcode); - ZVAL_LONG(ps[4], bytes_sofar); - ZVAL_LONG(ps[5], bytes_max); - - if (FAILURE == call_user_function_ex(EG(function_table), NULL, callback, &retval, 6, ptps, 0, NULL TSRMLS_CC)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call user notifier"); - } - if (retval) { - zval_ptr_dtor(&retval); - } -} - -static int parse_context_options(php_stream_context *context, zval *options) -{ - HashPosition pos, opos; - zval **wval, **oval; - char *wkey, *okey; - int wkey_len, okey_len; - int ret = SUCCESS; - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(options), &pos); - while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_P(options), (void**)&wval, &pos)) { - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_P(options), &wkey, &wkey_len, NULL, 0, &pos) - && Z_TYPE_PP(wval) == IS_ARRAY) { - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(wval), &opos); - while (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)&oval, &opos)) { - - if (HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), &okey, &okey_len, NULL, 0, &opos)) { - ZVAL_ADDREF(*oval); - php_stream_context_set_option(context, wkey, okey, *oval); - } - zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), &opos); - } - - } else { - zend_error(E_WARNING, "options should have the form [\"wrappername\"][\"optionname\"] = $value"); - } - zend_hash_move_forward_ex(Z_ARRVAL_P(options), &pos); - } - - return ret; -} - -static int parse_context_params(php_stream_context *context, zval *params) -{ - int ret = SUCCESS; - zval **tmp; - - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "notification", sizeof("notification"), (void**)&tmp)) { - - if (context->notifier) { - php_stream_notification_free(context->notifier); - context->notifier = NULL; - } - - context->notifier = php_stream_notification_alloc(); - context->notifier->func = user_space_stream_notifier; - context->notifier->ptr = *tmp; - ZVAL_ADDREF(*tmp); - } - if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), "options", sizeof("options"), (void**)&tmp)) { - parse_context_options(context, *tmp); - } - - return ret; -} - -/* given a zval which is either a stream or a context, return the underlying - * stream_context. If it is a stream that does not have a context assigned, it - * will create and assign a context and return that. */ -static php_stream_context *decode_context_param(zval *contextresource TSRMLS_DC) -{ - php_stream_context *context = NULL; - - context = zend_fetch_resource(&contextresource TSRMLS_CC, -1, "Stream-Context", NULL, 1, le_stream_context); - if (context == NULL) { - php_stream *stream; - - php_stream_from_zval_no_verify(stream, &contextresource); - - if (stream) { - context = stream->context; - if (context == NULL) { - context = stream->context = php_stream_context_alloc(); - } - } - } - - return context; -} -/* }}} */ - -/* {{{ proto array stream_context_get_options(resource context|resource stream) - Retrieve options for a stream/wrapper/context */ -PHP_FUNCTION(stream_context_get_options) -{ - zval *zcontext; - php_stream_context *context; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) { - RETURN_FALSE; - } - context = decode_context_param(zcontext TSRMLS_CC); - ZEND_VERIFY_RESOURCE(context); - - array_init(return_value); - *return_value = *context->options; - zval_copy_ctor(return_value); - -} -/* }}} */ - -/* {{{ proto bool stream_context_set_option(resource context|resource stream, string wrappername, string optionname, mixed value) - Set an option for a wrapper */ -PHP_FUNCTION(stream_context_set_option) -{ - zval *options = NULL, *zcontext = NULL, *zvalue = NULL; - php_stream_context *context; - char *wrappername, *optionname; - int wrapperlen, optionlen; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, - "rssz", &zcontext, &wrappername, &wrapperlen, - &optionname, &optionlen, &zvalue) == FAILURE) { - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, - "ra", &zcontext, &options) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "called with wrong number or type of parameters; please RTM"); - RETURN_FALSE; - } - } - - /* figure out where the context is coming from exactly */ - context = decode_context_param(zcontext TSRMLS_CC); - ZEND_VERIFY_RESOURCE(context); - - if (options) { - /* handle the array syntax */ - RETVAL_BOOL(parse_context_options(context, options) == SUCCESS); - } else { - ZVAL_ADDREF(zvalue); - php_stream_context_set_option(context, wrappername, optionname, zvalue); - RETVAL_TRUE; - } -} -/* }}} */ - -/* {{{ proto bool stream_context_set_params(resource context|resource stream, array options) - Set parameters for a file context */ -PHP_FUNCTION(stream_context_set_params) -{ - zval *params, *zcontext; - php_stream_context *context; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zcontext, ¶ms) == FAILURE) { - RETURN_FALSE; - } - - context = decode_context_param(zcontext TSRMLS_CC); - ZEND_VERIFY_RESOURCE(context); - - RETVAL_BOOL(parse_context_params(context, params) == SUCCESS); -} -/* }}} */ - -/* {{{ proto resource stream_context_create([array options]) - Create a file context and optionally set parameters */ -PHP_FUNCTION(stream_context_create) -{ - zval *params = NULL; - php_stream_context *context; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", ¶ms) == FAILURE) { - RETURN_FALSE; - } - - context = php_stream_context_alloc(); - - if (params) { - parse_context_options(context, params); - } - - ZEND_REGISTER_RESOURCE(return_value, context, le_stream_context); -} -/* }}} */ - -/* {{{ streams filter functions */ -static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *zstream; - php_stream *stream; - char *filtername, *filterparams = NULL; - int filternamelen, filterparamslen = 0, read_write = 0; - php_stream_filter *filter; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ls", &zstream, - &filtername, &filternamelen, &read_write, &filterparams, &filterparamslen) == FAILURE) { - RETURN_FALSE; - } - - php_stream_from_zval(stream, &zstream); - - if ((read_write & PHP_STREAM_FILTER_ALL) == 0) { - /* Chain not specified. - * Examine stream->mode to determine which filters are needed - * There's no harm in attaching a filter to an unused chain, - * but why waste the memory and clock cycles? - */ - if (strchr(stream->mode, 'r') || strchr(stream->mode, '+')) { - read_write |= PHP_STREAM_FILTER_READ; - } - if (strchr(stream->mode, 'w') || strchr(stream->mode, '+') || strchr(stream->mode, 'a')) { - read_write |= PHP_STREAM_FILTER_WRITE; - } - } - - if (read_write & PHP_STREAM_FILTER_READ) { - filter = php_stream_filter_create(filtername, filterparams, filterparamslen, php_stream_is_persistent(stream) TSRMLS_CC); - if (filter == NULL) { - RETURN_FALSE; - } - - if (append) { - php_stream_filter_append(&stream->readfilters, filter); - } else { - php_stream_filter_prepend(&stream->readfilters, filter); - } - } - - if (read_write & PHP_STREAM_FILTER_WRITE) { - filter = php_stream_filter_create(filtername, filterparams, filterparamslen, php_stream_is_persistent(stream) TSRMLS_CC); - if (filter == NULL) { - RETURN_FALSE; - } - - if (append) { - php_stream_filter_append(&stream->writefilters, filter); - } else { - php_stream_filter_prepend(&stream->writefilters, filter); - } - } - - RETURN_TRUE; -} - -/* {{{ proto bool stream_filter_prepend(resource stream, string filtername[, int read_write[, string filterparams]]) - Prepend a filter to a stream */ -PHP_FUNCTION(stream_filter_prepend) -{ - apply_filter_to_stream(0, INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto bool stream_filter_append(resource stream, string filtername[, int read_write[, string filterparams]]) - Append a filter to a stream */ -PHP_FUNCTION(stream_filter_append) -{ - apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto string stream_get_line(resource stream, int maxlen, string ending) - Read up to maxlen bytes from a stream or until the ending string is found */ -PHP_FUNCTION(stream_get_line) -{ - char *str; - int str_len; - long max_length; - zval *zstream; - char *buf; - size_t buf_size; - php_stream *stream; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rls", &zstream, &max_length, &str, &str_len) == FAILURE) { - RETURN_FALSE; - } - - if (max_length < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The maximum allowed length must be greater then or equal to zero."); - RETURN_FALSE; - } - - php_stream_from_zval(stream, &zstream); - - if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) { - RETURN_STRINGL(buf, buf_size, 0); - } else { - RETURN_FALSE; - } -} - -/* }}} */ - -/* {{{ proto resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) - Open a file or a URL and return a file pointer */ -PHP_NAMED_FUNCTION(php_if_fopen) -{ - char *filename, *mode; - int filename_len, mode_len; - zend_bool use_include_path = 0; - zval *zcontext = NULL; - php_stream *stream; - php_stream_context *context = NULL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|br", &filename, &filename_len, - &mode, &mode_len, &use_include_path, &zcontext) == FAILURE) { - RETURN_FALSE; - } - if (zcontext) { - ZEND_FETCH_RESOURCE(context, php_stream_context*, &zcontext, -1, "stream-context", le_stream_context); - } - - stream = php_stream_open_wrapper_ex(filename, mode, - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL, context); - - if (stream == NULL) { - RETURN_FALSE; - } - - php_stream_to_zval(stream, return_value); - - return; -} -/* }}} */ - -/* {{{ proto bool fclose(resource fp) - Close an open file pointer */ -PHPAPI PHP_FUNCTION(fclose) -{ - zval **arg1; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - php_stream_close(stream); - - RETURN_TRUE; -} - -/* }}} */ - -/* {{{ proto resource popen(string command, string mode) - Execute a command and open either a read or a write pipe to it */ - -PHP_FUNCTION(popen) -{ - zval **arg1, **arg2; - FILE *fp; - char *p, *tmp = NULL; - char *b, buf[1024]; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - p = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2)); - if (PG(safe_mode)){ - b = strchr(Z_STRVAL_PP(arg1), ' '); - if (!b) { - b = strrchr(Z_STRVAL_PP(arg1), '/'); - } else { - char *c; - c = Z_STRVAL_PP(arg1); - while((*b != '/') && (b != c)) { - b--; - } - if (b == c) { - b = NULL; - } - } - if (b) { - snprintf(buf, sizeof(buf), "%s%s", PG(safe_mode_exec_dir), b); - } else { - snprintf(buf, sizeof(buf), "%s/%s", PG(safe_mode_exec_dir), Z_STRVAL_PP(arg1)); - } - - tmp = php_escape_shell_cmd(buf); - fp = VCWD_POPEN(tmp, p); - efree(tmp); - - if (!fp) { - php_error_docref2(NULL TSRMLS_CC, buf, p, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - } else { - fp = VCWD_POPEN(Z_STRVAL_PP(arg1), p); - if (!fp) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno)); - efree(p); - RETURN_FALSE; - } - } - stream = php_stream_fopen_from_pipe(fp, p); - - if (stream == NULL) { - php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno)); - RETVAL_FALSE; - } else { - php_stream_to_zval(stream, return_value); - } - - efree(p); -} -/* }}} */ - -/* {{{ proto int pclose(resource fp) - Close a file pointer opened by popen() */ -PHP_FUNCTION(pclose) -{ - zval **arg1; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - RETURN_LONG(php_stream_close(stream)); -} -/* }}} */ - -/* {{{ proto bool feof(resource fp) - Test for end-of-file on a file pointer */ -PHPAPI PHP_FUNCTION(feof) -{ - zval **arg1; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - if (php_stream_eof(stream)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool stream_set_blocking(resource socket, int mode) - Set blocking/non-blocking mode on a socket or stream */ -PHP_FUNCTION(stream_set_blocking) -{ - zval **arg1, **arg2; - int block; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - convert_to_long_ex(arg2); - block = Z_LVAL_PP(arg2); - - if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1) - RETURN_FALSE; - RETURN_TRUE; -} - -/* }}} */ - -/* {{{ proto bool set_socket_blocking(resource socket, int mode) - Set blocking/non-blocking mode on a socket */ -PHP_FUNCTION(set_socket_blocking) -{ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "This function is deprecated, use stream_set_blocking() instead"); - PHP_FN(stream_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto bool stream_set_timeout(resource stream, int seconds, int microseconds) - Set timeout on stream read to seconds + microseonds */ -#if HAVE_SYS_TIME_H || defined(PHP_WIN32) -PHP_FUNCTION(stream_set_timeout) -{ - zval **socket, **seconds, **microseconds; - struct timeval t; - php_stream *stream; - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, µseconds)==FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, socket); - - convert_to_long_ex(seconds); - t.tv_sec = Z_LVAL_PP(seconds); - - if (ZEND_NUM_ARGS() == 3) { - convert_to_long_ex(microseconds); - t.tv_usec = Z_LVAL_PP(microseconds) % 1000000; - t.tv_sec += Z_LVAL_PP(microseconds) / 1000000; - } - else - t.tv_usec = 0; - - if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) { - RETURN_TRUE; - } - - RETURN_FALSE; -} -#endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) */ -/* }}} */ - -/* {{{ proto string fgets(resource fp[, int length]) - Get a line from file pointer */ -PHPAPI PHP_FUNCTION(fgets) -{ - zval **arg1, **arg2; - int len = 1024; - char *buf = NULL; - int argc = ZEND_NUM_ARGS(); - size_t line_len = 0; - php_stream *stream; - - if (argc<1 || argc>2 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - if (argc == 1) { - /* ask streams to give us a buffer of an appropriate size */ - buf = php_stream_get_line(stream, NULL, 0, &line_len); - if (buf == NULL) - goto exit_failed; - } else if (argc > 1) { - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - - if (len < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative"); - RETURN_FALSE; - } - - buf = ecalloc(len + 1, sizeof(char)); - if (php_stream_get_line(stream, buf, len, &line_len) == NULL) - goto exit_failed; - } - - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, &Z_STRLEN_P(return_value), 1 TSRMLS_CC); - Z_TYPE_P(return_value) = IS_STRING; - } else { - ZVAL_STRINGL(return_value, buf, line_len, 0); - /* resize buffer if it's much larger than the result. - * Only needed if the user requested a buffer size. */ - if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) { - Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1); - } - } - return; - -exit_failed: - RETVAL_FALSE; - if (buf) - efree(buf); -} -/* }}} */ - -/* {{{ proto string fgetc(resource fp) - Get a character from file pointer */ -PHPAPI PHP_FUNCTION(fgetc) -{ - zval **arg1; - char *buf; - int result; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - buf = emalloc(2 * sizeof(char)); - - result = php_stream_getc(stream); - - if (result == EOF) { - efree(buf); - RETVAL_FALSE; - } else { - buf[0] = result; - buf[1] = '\0'; - - RETURN_STRINGL(buf, 1, 0); - } -} -/* }}} */ - -/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags]) - Get a line from file pointer and strip HTML tags */ -PHPAPI PHP_FUNCTION(fgetss) -{ - zval **fd, **bytes = NULL, **allow=NULL; - size_t len = 0; - size_t actual_len, retval_len; - char *buf = NULL, *retval; - php_stream *stream; - char *allowed_tags=NULL; - int allowed_tags_len=0; - - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &fd) == FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) { - RETURN_FALSE; - } - break; - case 3: - if (zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - allowed_tags = Z_STRVAL_PP(allow); - allowed_tags_len = Z_STRLEN_PP(allow); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - php_stream_from_zval(stream, fd); - - if (bytes != NULL) { - convert_to_long_ex(bytes); - if (Z_LVAL_PP(bytes) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative"); - RETURN_FALSE; - } - - len = (size_t) Z_LVAL_PP(bytes); - buf = emalloc(sizeof(char) * (len + 1)); - /*needed because recv doesnt set null char at end*/ - memset(buf, 0, len + 1); - } - - if ((retval = php_stream_get_line(stream, buf, len, &actual_len)) == NULL) { - if (buf != NULL) { - efree(buf); - } - RETURN_FALSE; - } - - retval_len = php_strip_tags(retval, actual_len, &stream->fgetss_state, allowed_tags, allowed_tags_len); - - RETURN_STRINGL(retval, retval_len, 0); -} -/* }}} */ - -/* {{{ proto mixed fscanf(resource stream, string format [, string ...]) - Implements a mostly ANSI compatible fscanf() */ -PHP_FUNCTION(fscanf) -{ - int result; - zval **file_handle, **format_string; - size_t len; - int type; - char *buf; - void *what; - - zval ***args; - int argCount; - - argCount = ZEND_NUM_ARGS(); - if (argCount < 2) { - WRONG_PARAM_COUNT; - } - args = (zval ***)emalloc(argCount * sizeof(zval **)); - if (zend_get_parameters_array_ex(argCount, args) == FAILURE) { - efree( args ); - WRONG_PARAM_COUNT; - } - - file_handle = args[0]; - format_string = args[1]; - - what = zend_fetch_resource(file_handle TSRMLS_CC, -1, "File-Handle", &type, 2, - php_file_le_stream(), php_file_le_pstream()); - - /* - * we can't do a ZEND_VERIFY_RESOURCE(what), otherwise we end up - * with a leak if we have an invalid filehandle. This needs changing - * if the code behind ZEND_VERIFY_RESOURCE changed. - cc - */ - if (!what) { - efree(args); - RETURN_FALSE; - } - - - buf = php_stream_get_line((php_stream *) what, NULL, 0, &len); - if (buf == NULL) { - efree(args); - RETURN_FALSE; - } - - convert_to_string_ex(format_string); - result = php_sscanf_internal(buf, Z_STRVAL_PP(format_string), - argCount, args, 2, &return_value TSRMLS_CC); - - efree(args); - efree(buf); - - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { - WRONG_PARAM_COUNT; - } - -} -/* }}} */ - -/* {{{ proto int fwrite(resource fp, string str [, int length]) - Binary-safe file write */ -PHPAPI PHP_FUNCTION(fwrite) -{ - zval **arg1, **arg2, **arg3=NULL; - int ret; - int num_bytes; - char *buffer = NULL; - php_stream *stream; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - num_bytes = Z_STRLEN_PP(arg2); - break; - case 3: - if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - convert_to_long_ex(arg3); - num_bytes = MIN(Z_LVAL_PP(arg3), Z_STRLEN_PP(arg2)); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - php_stream_from_zval(stream, arg1); - - if (!arg3 && PG(magic_quotes_runtime)) { - buffer = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2)); - php_stripslashes(buffer, &num_bytes TSRMLS_CC); - } - - ret = php_stream_write(stream, buffer ? buffer : Z_STRVAL_PP(arg2), num_bytes); - if (buffer) { - efree(buffer); - } - - RETURN_LONG(ret); -} -/* }}} */ - -/* {{{ proto bool fflush(resource fp) - Flushes output */ -PHPAPI PHP_FUNCTION(fflush) -{ - zval **arg1; - int ret; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - ret = php_stream_flush(stream); - if (ret) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int stream_set_write_buffer(resource fp, int buffer) - Set file write buffer */ -PHP_FUNCTION(stream_set_write_buffer) -{ - zval **arg1, **arg2; - int ret; - size_t buff; - php_stream *stream; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - php_stream_from_zval(stream, arg1); - - convert_to_long_ex(arg2); - buff = Z_LVAL_PP(arg2); - - /* if buff is 0 then set to non-buffered */ - if (buff == 0) { - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_NONE, NULL); - } else { - ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buff); - } - - RETURN_LONG(ret == 0 ? 0 : EOF); -} -/* }}} */ - -/* {{{ proto bool rewind(resource fp) - Rewind the position of a file pointer */ -PHPAPI PHP_FUNCTION(rewind) -{ - zval **arg1; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - if (-1 == php_stream_rewind(stream)) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int ftell(resource fp) - Get file pointer's read/write position */ -PHPAPI PHP_FUNCTION(ftell) -{ - zval **arg1; - long ret; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - ret = php_stream_tell(stream); - if (ret == -1) { - RETURN_FALSE; - } - RETURN_LONG(ret); -} -/* }}} */ - -/* {{{ proto int fseek(resource fp, int offset [, int whence]) - Seek on a file pointer */ -PHPAPI PHP_FUNCTION(fseek) -{ - zval **arg1, **arg2, **arg3; - int argcount = ZEND_NUM_ARGS(), whence = SEEK_SET; - php_stream *stream; - - if (argcount < 2 || argcount > 3 || - zend_get_parameters_ex(argcount, &arg1, &arg2, &arg3) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - convert_to_long_ex(arg2); - if (argcount > 2) { - convert_to_long_ex(arg3); - whence = Z_LVAL_PP(arg3); - } - - RETURN_LONG(php_stream_seek(stream, Z_LVAL_PP(arg2), whence)); -} - -/* }}} */ - -/* {{{ proto int mkdir(char *dir int mode) -*/ - -PHPAPI int php_mkdir(char *dir, long mode TSRMLS_DC) -{ - int ret; - - if (PG(safe_mode) && (!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - return -1; - } - - if (php_check_open_basedir(dir TSRMLS_CC)) { - return -1; - } - - if ((ret = VCWD_MKDIR(dir, (mode_t)mode)) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno)); - } - - return ret; -} -/* }}} */ - -/* {{{ proto bool mkdir(string pathname [, int mode [, bool recursive]) - Create a directory */ -PHP_FUNCTION(mkdir) -{ - int dir_len, ret; - long mode = 0777; - char *dir; - zend_bool recursive = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &dir, &dir_len, &mode, &recursive) == FAILURE) { - return; - } - - if (!recursive) { - ret = php_mkdir(dir, mode TSRMLS_CC); - } else { - /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ - char *p, *e, *buf; - struct stat sb; - - buf = estrndup(dir, dir_len); - e = buf + dir_len; - - /* find a top level directory we need to create */ - while ((p = strrchr(buf, DEFAULT_SLASH))) { - *p = '\0'; - if (VCWD_STAT(buf, &sb) == 0) { - *p = DEFAULT_SLASH; - break; - } - } - if (p == buf) { - ret = php_mkdir(dir, mode TSRMLS_CC); - } else if (!(ret = php_mkdir(buf, mode TSRMLS_CC))) { - if (!p) { - p = buf; - } - /* create any needed directories if the creation of the 1st directory worked */ - while (++p != e) { - if (*p == '\0' && *(p + 1) != '\0') { - *p = DEFAULT_SLASH; - if ((ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno)); - break; - } - } - } - } - efree(buf); - } - - if (ret < 0) { - RETURN_FALSE; - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto bool rmdir(string dirname) - Remove a directory */ -PHP_FUNCTION(rmdir) -{ - zval **arg1; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg1); - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(arg1), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_PP(arg1) TSRMLS_CC)) { - RETURN_FALSE; - } - - ret = VCWD_RMDIR(Z_STRVAL_PP(arg1)); - if (ret < 0) { - php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int readfile(string filename [, bool use_include_path]) - Output a file or a URL */ -PHP_FUNCTION(readfile) -{ - zval **arg1, **arg2; - int size=0; - int use_include_path=0; - php_stream *stream; - - /* check args */ - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - use_include_path = Z_LVAL_PP(arg2); - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - - stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); - if (stream) { - size = php_stream_passthru(stream); - php_stream_close(stream); - RETURN_LONG(size); - } - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto int umask([int mask]) - Return or change the umask */ -PHP_FUNCTION(umask) -{ - pval **arg1; - int oldumask; - int arg_count = ZEND_NUM_ARGS(); - - oldumask = umask(077); - - if (arg_count == 0) { - umask(oldumask); - } else { - if (arg_count > 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg1); - umask(Z_LVAL_PP(arg1)); - } - - /* XXX we should maybe reset the umask after each request! */ - - RETURN_LONG(oldumask); -} - -/* }}} */ - -/* {{{ proto int fpassthru(resource fp) - Output all remaining data from a file pointer */ - -PHPAPI PHP_FUNCTION(fpassthru) -{ - zval **arg1; - int size; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - size = php_stream_passthru(stream); - RETURN_LONG(size); -} -/* }}} */ - -/* {{{ proto bool rename(string old_name, string new_name) - Rename a file */ -PHP_FUNCTION(rename) -{ - zval **old_arg, **new_arg; - char *old_name, *new_name; - int ret; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &old_arg, &new_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(old_arg); - convert_to_string_ex(new_arg); - - old_name = Z_STRVAL_PP(old_arg); - new_name = Z_STRVAL_PP(new_arg); - - if (PG(safe_mode) &&(!php_checkuid(old_name, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(old_name TSRMLS_CC)) { - RETURN_FALSE; - } - - ret = VCWD_RENAME(old_name, new_name); - - if (ret == -1) { - php_error_docref2(NULL TSRMLS_CC, old_name, new_name, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool unlink(string filename) - Delete a file */ -PHP_FUNCTION(unlink) -{ - zval **filename; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - ret = VCWD_UNLINK(Z_STRVAL_PP(filename)); - if (ret == -1) { - php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(filename), E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - /* Clear stat cache */ - PHP_FN(clearstatcache)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool ftruncate(resource fp, int size) - Truncate file to 'size' length */ -PHP_NAMED_FUNCTION(php_if_ftruncate) -{ - zval **fp , **size; - short int ret; - int fd; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, fp); - - convert_to_long_ex(size); - - if (!php_stream_truncate_supported(stream)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream!"); - RETURN_FALSE; - } - - RETURN_BOOL(0 == php_stream_truncate_set_size(stream, Z_LVAL_PP(size))); -} -/* }}} */ - -/* {{{ proto int fstat(resource fp) - Stat() on a filehandle */ -PHP_NAMED_FUNCTION(php_if_fstat) -{ - zval **fp; - zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev, - *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks; - php_stream *stream; - php_stream_statbuf stat_ssb; - - char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", - "size", "atime", "mtime", "ctime", "blksize", "blocks"}; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, fp); - - if (php_stream_stat(stream, &stat_ssb)) { - RETURN_FALSE; - } - - array_init(return_value); - - MAKE_LONG_ZVAL_INCREF(stat_dev, stat_ssb.sb.st_dev); - MAKE_LONG_ZVAL_INCREF(stat_ino, stat_ssb.sb.st_ino); - MAKE_LONG_ZVAL_INCREF(stat_mode, stat_ssb.sb.st_mode); - MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_ssb.sb.st_nlink); - MAKE_LONG_ZVAL_INCREF(stat_uid, stat_ssb.sb.st_uid); - MAKE_LONG_ZVAL_INCREF(stat_gid, stat_ssb.sb.st_gid); -#ifdef HAVE_ST_RDEV - MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_ssb.sb.st_rdev); -#else - MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); -#endif - MAKE_LONG_ZVAL_INCREF(stat_size, stat_ssb.sb.st_size); -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime.tv_sec); - MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime.tv_sec); - MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime.tv_sec); -#else - MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime); - MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime); - MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime); -#endif - -#ifdef HAVE_ST_BLKSIZE - MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_ssb.sb.st_blksize); -#else - MAKE_LONG_ZVAL_INCREF(stat_blksize,-1); -#endif -#ifdef HAVE_ST_BLOCKS - MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_ssb.sb.st_blocks); -#else - MAKE_LONG_ZVAL_INCREF(stat_blocks,-1); -#endif - /* Store numeric indexes in propper order */ - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL); - - /* Store string indexes referencing the same zval*/ - zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *)&stat_dev, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *)&stat_ino, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *)&stat_mode, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *)&stat_nlink, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *)&stat_uid, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *)&stat_gid, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *)&stat_rdev, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *)&stat_size, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *)&stat_atime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *)&stat_mtime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *)&stat_ctime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *)&stat_blksize, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *)&stat_blocks, sizeof(zval *), NULL); -} -/* }}} */ - -/* {{{ proto bool copy(string source_file, string destination_file) - Copy a file */ -PHP_FUNCTION(copy) -{ - zval **source, **target; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &source, &target) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(source); - convert_to_string_ex(target); - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(source), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(Z_STRVAL_PP(source) TSRMLS_CC)) { - RETURN_FALSE; - } - - if (php_copy_file(Z_STRVAL_PP(source), Z_STRVAL_PP(target) TSRMLS_CC)==SUCCESS) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ php_copy_file - */ -PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) -{ - php_stream *srcstream = NULL, *deststream = NULL; - int ret = FAILURE; - - srcstream = php_stream_open_wrapper(src, "rb", - STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS, - NULL); - - if (!srcstream) { - return ret; - } - - deststream = php_stream_open_wrapper(dest, "wb", - ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); - - if (srcstream && deststream) { - ret = php_stream_copy_to_stream(srcstream, deststream, PHP_STREAM_COPY_ALL) == 0 ? FAILURE : SUCCESS; - } - if (srcstream) { - php_stream_close(srcstream); - } - if (deststream) { - php_stream_close(deststream); - } - return ret; -} -/* }}} */ - -/* {{{ proto string fread(resource fp, int length) - Binary-safe file read */ -PHPAPI PHP_FUNCTION(fread) -{ - zval **arg1, **arg2; - int len; - php_stream *stream; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - php_stream_from_zval(stream, arg1); - - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - if (len < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative"); - RETURN_FALSE; - } - - Z_STRVAL_P(return_value) = emalloc(len + 1); - Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len); - - /* needed because recv/read/gzread doesnt put a null at the end*/ - Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; - - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value), - Z_STRLEN_P(return_value), &Z_STRLEN_P(return_value), 1 TSRMLS_CC); - } - Z_TYPE_P(return_value) = IS_STRING; -} -/* }}} */ - -/* {{{ proto array fgetcsv(resource fp, int length [, string delimiter [, string enclosure]]) - Get line from file pointer and parse for CSV fields */ -PHP_FUNCTION(fgetcsv) -{ - char *temp, *tptr, *bptr, *lineEnd; - char delimiter = ','; /* allow this to be set as parameter */ - char enclosure = '"'; /* allow this to be set as parameter */ - - /* first section exactly as php_fgetss */ - - zval **fd, **bytes, **p_delim, **p_enclosure; - int len, temp_len; - char *buf; - php_stream *stream; - - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - - case 3: - if (zend_get_parameters_ex(3, &fd, &bytes, &p_delim) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(p_delim); - /* Make sure that there is at least one character in string */ - if (Z_STRLEN_PP(p_delim) < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character"); - return; - } - /* use first character from string */ - delimiter = Z_STRVAL_PP(p_delim)[0]; - break; - - case 4: - if (zend_get_parameters_ex(4, &fd, &bytes, &p_delim, &p_enclosure) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(p_delim); - /* Make sure that there is at least one character in string */ - if (Z_STRLEN_PP(p_delim) < 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character"); - return; - } - /* use first character from string */ - delimiter = Z_STRVAL_PP(p_delim)[0]; - - convert_to_string_ex(p_enclosure); - /* use first character from string */ - enclosure = Z_STRVAL_PP(p_enclosure)[0]; - - break; - - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - php_stream_from_zval(stream, fd); - - convert_to_long_ex(bytes); - len = Z_LVAL_PP(bytes); - if (len < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative"); - RETURN_FALSE; - } - - buf = emalloc(len + 1); - /* needed because recv/read/gzread doesnt set null char at end */ - memset(buf, 0, len + 1); - - if (php_stream_gets(stream, buf, len) == NULL) { - efree(buf); - RETURN_FALSE; - } - - /* Now into new section that parses buf for delimiter/enclosure fields */ - - /* Strip trailing space from buf, saving end of line in case required for enclosure field */ - - lineEnd = emalloc(len + 1); - bptr = buf; - tptr = buf + strlen(buf) -1; - while ( isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--; - tptr++; - strcpy(lineEnd, tptr); - - /* add single space - makes it easier to parse trailing null field */ - *tptr++ = ' '; - *tptr = 0; - - /* reserve workspace for building each individual field */ - - temp_len = len; - temp = emalloc(temp_len + 1); /* unlikely but possible! */ - tptr = temp; - - /* Initialize return array */ - array_init(return_value); - - /* Main loop to read CSV fields */ - /* NB this routine will return a single null entry for a blank line */ - - do { - /* 1. Strip any leading space */ - while(isspace((int)*(unsigned char *)bptr) && (*bptr!=delimiter)) bptr++; - /* 2. Read field, leaving bptr pointing at start of next field */ - if (enclosure && *bptr == enclosure) { - bptr++; /* move on to first character in field */ - - /* 2A. handle enclosure delimited field */ - while (*bptr) { - /* we need to determine if the enclosure is 'real' or is it escaped */ - if (*(bptr - 1) == '\\') { - int escape_cnt = 0; - char *bptr_p = bptr - 2; - - while (bptr_p > buf && *bptr_p == '\\') { - escape_cnt++; - bptr_p--; - } - if (!(escape_cnt % 2)) { - goto normal_char; - continue; - } - } - - if (*bptr == enclosure) { - /* handle the enclosure */ - if ( *(bptr+1) == enclosure) { - /* embedded enclosure */ - *tptr++ = *bptr; bptr +=2; - } else { - /* must be end of string - skip to start of next field or end */ - while ( (*bptr != delimiter) && *bptr ) bptr++; - if (*bptr == delimiter) bptr++; - *tptr=0; /* terminate temporary string */ - break; /* .. from handling this field - resumes at 3. */ - } - } else { -normal_char: - /* normal character */ - *tptr++ = *bptr++; - - if (*bptr == 0) { /* embedded line end? */ - *(tptr-1)=0; /* remove space character added on reading line */ - strcat(temp, lineEnd); /* add the embedded line end to the field */ - - /* read a new line from input, as at start of routine */ - memset(buf, 0, len+1); - - if (php_stream_gets(stream, buf, len) == NULL) { - /* we've got an unterminated enclosure, assign all the data - * from the start of the enclosure to end of data to the last element - */ - if (temp_len > len) { - break; - } - - efree(lineEnd); - efree(temp); - efree(buf); - zval_dtor(return_value); - RETURN_FALSE; - } - - temp_len += len; - temp = erealloc(temp, temp_len+1); - bptr = buf; - tptr = buf + strlen(buf) -1; - while (isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter) && (tptr > bptr)) - tptr--; - tptr++; - strcpy(lineEnd, tptr); - *tptr++ = ' '; - *tptr = 0; - - tptr = temp; /* reset temp pointer to end of field as read so far */ - while (*tptr) - tptr++; - } - } - } - } else { - /* 2B. Handle non-enclosure field */ - while ((*bptr != delimiter) && *bptr) - *tptr++ = *bptr++; - *tptr=0; /* terminate temporary string */ - - if (strlen(temp)) { - tptr--; - while (isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter)) - *tptr-- = 0; /* strip any trailing spaces */ - } - - if (*bptr == delimiter) - bptr++; - } - - /* 3. Now pass our field back to php */ - add_next_index_string(return_value, temp, 1); - tptr = temp; - } while (*bptr); - - efree(lineEnd); - efree(temp); - efree(buf); -} -/* }}} */ - - -#if (!defined(PHP_WIN32) && !defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) -/* {{{ proto string realpath(string path) - Return the resolved path */ -PHP_FUNCTION(realpath) -{ - zval **path; - char resolved_path_buff[MAXPATHLEN]; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(path); - - if (VCWD_REALPATH(Z_STRVAL_PP(path), resolved_path_buff)) { - RETURN_STRING(resolved_path_buff, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ -#endif - -/* See http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 */ -#define PHP_META_HTML401_CHARS "-_.:" - -/* {{{ php_next_meta_token - Tokenizes an HTML file for get_meta_tags */ -php_meta_tags_token php_next_meta_token(php_meta_tags_data *md TSRMLS_DC) -{ - int ch = 0, compliment; - char buff[META_DEF_BUFSIZE + 1]; - - memset((void *)buff, 0, META_DEF_BUFSIZE + 1); - - while (md->ulc || (!php_stream_eof(md->stream) && (ch = php_stream_getc(md->stream)))) { - if(php_stream_eof(md->stream)) - break; - - if (md->ulc) { - ch = md->lc; - md->ulc = 0; - } - - switch (ch) { - case '<': - return TOK_OPENTAG; - break; - case '>': - return TOK_CLOSETAG; - break; - case '=': - return TOK_EQUAL; - break; - case '/': - return TOK_SLASH; - break; - case '\'': - case '"': - compliment = ch; - md->token_len = 0; - while (!php_stream_eof(md->stream) && - (ch = php_stream_getc(md->stream)) && - ch != compliment && ch != '<' && ch != '>') { - - buff[(md->token_len)++] = ch; - - if (md->token_len == META_DEF_BUFSIZE) - break; - } - - if (ch == '<' || ch == '>') { - /* Was just an apostrohpe */ - md->ulc = 1; - md->lc = ch; - } - - /* We don't need to alloc unless we are in a meta tag */ - if (md->in_meta) { - md->token_data = (char *) emalloc(md->token_len + 1); - memcpy(md->token_data, buff, md->token_len+1); - } - - return TOK_STRING; - break; - case '\n': - case '\r': - case '\t': - break; - case ' ': - return TOK_SPACE; - break; - default: - if (isalnum(ch)) { - md->token_len = 0; - buff[(md->token_len)++] = ch; - while (!php_stream_eof(md->stream) && - (ch = php_stream_getc(md->stream)) && - (isalnum(ch) || strchr(PHP_META_HTML401_CHARS, ch))) { - - buff[(md->token_len)++] = ch; - - if (md->token_len == META_DEF_BUFSIZE) - break; - } - - /* This is ugly, but we have to replace ungetc */ - if (!isalpha(ch) && ch != '-') { - md->ulc = 1; - md->lc = ch; - } - - md->token_data = (char *) emalloc(md->token_len + 1); - memcpy(md->token_data, buff, md->token_len+1); - - return TOK_ID; - } else { - return TOK_OTHER; - } - break; - } - } - - return TOK_EOF; -} - -/* }}} */ - -#ifdef HAVE_FNMATCH -/* {{{ proto bool fnmatch(string pattern, string filename [, int flags]) - Match filename against pattern */ -PHP_FUNCTION(fnmatch) -{ - char *pattern = NULL; - char *filename = NULL; - int argc = ZEND_NUM_ARGS(); - int pattern_len; - int filename_len; - long flags=0; - - if (zend_parse_parameters(argc TSRMLS_CC, "ss|l", - &pattern, &pattern_len, - &filename, &filename_len, - &flags) - == FAILURE) - return; - - RETURN_BOOL( ! fnmatch( pattern, filename, flags )); -} -/* }}} */ -#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/ext/standard/file.h b/ext/standard/file.h deleted file mode 100644 index ffd2669315..0000000000 --- a/ext/standard/file.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */ - -#ifndef FILE_H -#define FILE_H - -PHP_MINIT_FUNCTION(file); -PHP_MSHUTDOWN_FUNCTION(file); - -PHP_FUNCTION(tempnam); -PHP_NAMED_FUNCTION(php_if_tmpfile); -PHP_NAMED_FUNCTION(php_if_fopen); -PHPAPI PHP_FUNCTION(fclose); -PHP_FUNCTION(popen); -PHP_FUNCTION(pclose); -PHPAPI PHP_FUNCTION(feof); -PHPAPI PHP_FUNCTION(fread); -PHPAPI PHP_FUNCTION(fgetc); -PHPAPI PHP_FUNCTION(fgets); -PHP_FUNCTION(fscanf); -PHPAPI PHP_FUNCTION(fgetss); -PHP_FUNCTION(fgetcsv); -PHPAPI PHP_FUNCTION(fwrite); -PHPAPI PHP_FUNCTION(fflush); -PHPAPI PHP_FUNCTION(rewind); -PHPAPI PHP_FUNCTION(ftell); -PHPAPI PHP_FUNCTION(fseek); -PHP_FUNCTION(mkdir); -PHP_FUNCTION(rmdir); -PHPAPI PHP_FUNCTION(fpassthru); -PHP_FUNCTION(readfile); -PHP_FUNCTION(umask); -PHP_FUNCTION(rename); -PHP_FUNCTION(unlink); -PHP_FUNCTION(copy); -PHP_FUNCTION(file); -PHP_FUNCTION(file_get_contents); -PHP_FUNCTION(set_socket_blocking); /* deprecated */ -PHP_FUNCTION(stream_set_blocking); -PHP_FUNCTION(stream_select); -PHP_FUNCTION(stream_set_timeout); -PHP_FUNCTION(stream_set_write_buffer); -PHP_FUNCTION(stream_get_wrappers); -PHP_FUNCTION(stream_get_line); -PHP_FUNCTION(get_meta_tags); -PHP_FUNCTION(flock); -PHP_FUNCTION(fd_set); -PHP_FUNCTION(fd_isset); -#if (!defined(PHP_WIN32) && !defined(__BEOS__) && HAVE_REALPATH) || defined(ZTS) -PHP_FUNCTION(realpath); -PHP_FUNCTION(fnmatch); -#endif -PHP_NAMED_FUNCTION(php_if_ftruncate); -PHP_NAMED_FUNCTION(php_if_fstat); - -PHP_FUNCTION(stream_get_meta_data); -PHP_FUNCTION(stream_register_wrapper); -PHP_FUNCTION(stream_context_create); -PHP_FUNCTION(stream_context_set_params); -PHP_FUNCTION(stream_context_set_option); -PHP_FUNCTION(stream_context_get_options); -PHP_FUNCTION(stream_filter_prepend); -PHP_FUNCTION(stream_filter_append); -PHP_MINIT_FUNCTION(user_streams); - -PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC); -PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC); - -#define META_DEF_BUFSIZE 8192 - -#define PHP_FILE_USE_INCLUDE_PATH 1 -#define PHP_FILE_IGNORE_NEW_LINES 2 -#define PHP_FILE_SKIP_EMPTY_LINES 4 - -typedef enum _php_meta_tags_token { - TOK_EOF = 0, - TOK_OPENTAG, - TOK_CLOSETAG, - TOK_SLASH, - TOK_EQUAL, - TOK_SPACE, - TOK_ID, - TOK_STRING, - TOK_OTHER -} php_meta_tags_token; - -typedef struct _php_meta_tags_data { - php_stream *stream; - int ulc; - int lc; - char *input_buffer; - char *token_data; - int token_len; - int in_meta; -} php_meta_tags_data; - -php_meta_tags_token php_next_meta_token(php_meta_tags_data * TSRMLS_DC); - -typedef struct { - int pclose_ret; - size_t def_chunk_size; - long auto_detect_line_endings; - long default_socket_timeout; - char *user_agent; - char *user_stream_current_filename; /* for simple recursion protection */ -} php_file_globals; - -#ifdef ZTS -#define FG(v) TSRMG(file_globals_id, php_file_globals *, v) -extern int file_globals_id; -#else -#define FG(v) (file_globals.v) -extern php_file_globals file_globals; -#endif - - -#endif /* FILE_H */ - diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c deleted file mode 100644 index 8321ceb41a..0000000000 --- a/ext/standard/filestat.c +++ /dev/null @@ -1,931 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "safe_mode.h" -#include "fopen_wrappers.h" -#include "php_globals.h" - -#include <stdlib.h> -#include <sys/stat.h> -#include <string.h> -#include <errno.h> -#include <ctype.h> -#include <time.h> - -#if HAVE_UNISTD_H -# include <unistd.h> -#endif - -#if HAVE_SYS_VFS_H -# include <sys/vfs.h> -#endif - -#ifdef OS2 -# define INCL_DOS -# include <os2.h> -#endif - -#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) -# include <sys/statvfs.h> -#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS) -# include <sys/statfs.h> -#elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_STATFS) -# include <sys/mount.h> -#endif - -#if HAVE_PWD_H -# ifdef PHP_WIN32 -# include "win32/pwd.h" -# elif defined(NETWARE) -# include "netware/pwd.h" -# else -# include <pwd.h> -# endif -#endif - -#if HAVE_GRP_H -# ifdef PHP_WIN32 -# include "win32/grp.h" -# else -# include <grp.h> -# endif -#endif - -#if HAVE_UTIME -# ifdef PHP_WIN32 -# include <sys/utime.h> -# else -# include <utime.h> -# endif -#endif - -#include "basic_functions.h" -#include "php_filestat.h" - -#ifndef S_ISDIR -#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR) -#endif -#ifndef S_ISREG -#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG) -#endif -#ifndef S_ISLNK -#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK) -#endif - -#define S_IXROOT ( S_IXUSR | S_IXGRP | S_IXOTH ) - -/* Switches for various filestat functions: */ -#define FS_PERMS 0 -#define FS_INODE 1 -#define FS_SIZE 2 -#define FS_OWNER 3 -#define FS_GROUP 4 -#define FS_ATIME 5 -#define FS_MTIME 6 -#define FS_CTIME 7 -#define FS_TYPE 8 -#define FS_IS_W 9 -#define FS_IS_R 10 -#define FS_IS_X 11 -#define FS_IS_FILE 12 -#define FS_IS_DIR 13 -#define FS_IS_LINK 14 -#define FS_EXISTS 15 -#define FS_LSTAT 16 -#define FS_STAT 17 - - -PHP_RINIT_FUNCTION(filestat) -{ - BG(CurrentStatFile)=NULL; - BG(CurrentStatLength)=0; - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(filestat) -{ - if (BG(CurrentStatFile)) { - efree (BG(CurrentStatFile)); - } - return SUCCESS; -} - -/* {{{ proto float disk_total_space(string path) - Get total disk space for filesystem that path is on */ -PHP_FUNCTION(disk_total_space) -{ - pval **path; -#ifdef WINDOWS - double bytestotal; - - HINSTANCE kernel32; - FARPROC gdfse; - typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); - gdfse_func func; - - /* These are used by GetDiskFreeSpaceEx, if available. */ - ULARGE_INTEGER FreeBytesAvailableToCaller; - ULARGE_INTEGER TotalNumberOfBytes; - ULARGE_INTEGER TotalNumberOfFreeBytes; - - /* These are used by GetDiskFreeSpace otherwise. */ - DWORD SectorsPerCluster; - DWORD BytesPerSector; - DWORD NumberOfFreeClusters; - DWORD TotalNumberOfClusters; - -#else /* not - WINDOWS */ -#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - struct statvfs buf; -#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - struct statfs buf; -#endif - double bytestotal = 0; -#endif /* WINDOWS */ - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(path); - - if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { - RETURN_FALSE; - } - -#ifdef WINDOWS - /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2, - so we have to jump through some hoops to see if the function - exists. */ - kernel32 = LoadLibrary("kernel32.dll"); - if (kernel32) { - gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA"); - /* It's available, so we can call it. */ - if (gdfse) { - func = (gdfse_func)gdfse; - if (func(Z_STRVAL_PP(path), - &FreeBytesAvailableToCaller, - &TotalNumberOfBytes, - &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; - - /* i know - this is ugly, but i works <thies@thieso.net> */ - bytestotal = TotalNumberOfBytes.HighPart * - (double) (((unsigned long)1) << 31) * 2.0 + - TotalNumberOfBytes.LowPart; - } - /* If it's not available, we just use GetDiskFreeSpace */ - else { - if (GetDiskFreeSpace(Z_STRVAL_PP(path), - &SectorsPerCluster, &BytesPerSector, - &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; - bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector; - } - } - else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load kernel32.dll"); - RETURN_FALSE; - } - -#elif defined(OS2) - { - FSALLOCATE fsinfo; - char drive = Z_STRVAL_PP(path)[0] & 95; - - if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) - bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit; - } -#else /* WINDOWS, OS/2 */ -#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; - if (buf.f_frsize) { - bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize)); - } else { - bytestotal = (((double)buf.f_blocks) * ((double)buf.f_bsize)); - } - -#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; - bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks)); -#endif -#endif /* WINDOWS */ - - RETURN_DOUBLE(bytestotal); -} -/* }}} */ - -/* {{{ proto float disk_free_space(string path) - Get free disk space for filesystem that path is on */ -PHP_FUNCTION(disk_free_space) -{ - pval **path; -#ifdef WINDOWS - double bytesfree; - - HINSTANCE kernel32; - FARPROC gdfse; - typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); - gdfse_func func; - - /* These are used by GetDiskFreeSpaceEx, if available. */ - ULARGE_INTEGER FreeBytesAvailableToCaller; - ULARGE_INTEGER TotalNumberOfBytes; - ULARGE_INTEGER TotalNumberOfFreeBytes; - - /* These are used by GetDiskFreeSpace otherwise. */ - DWORD SectorsPerCluster; - DWORD BytesPerSector; - DWORD NumberOfFreeClusters; - DWORD TotalNumberOfClusters; - -#else /* not - WINDOWS */ -#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - struct statvfs buf; -#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - struct statfs buf; -#endif - double bytesfree = 0; -#endif /* WINDOWS */ - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(path); - - if (php_check_open_basedir(Z_STRVAL_PP(path) TSRMLS_CC)) { - RETURN_FALSE; - } - -#ifdef WINDOWS - /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2, - so we have to jump through some hoops to see if the function - exists. */ - kernel32 = LoadLibrary("kernel32.dll"); - if (kernel32) { - gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA"); - /* It's available, so we can call it. */ - if (gdfse) { - func = (gdfse_func)gdfse; - if (func(Z_STRVAL_PP(path), - &FreeBytesAvailableToCaller, - &TotalNumberOfBytes, - &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; - - /* i know - this is ugly, but i works <thies@thieso.net> */ - bytesfree = FreeBytesAvailableToCaller.HighPart * - (double) (((unsigned long)1) << 31) * 2.0 + - FreeBytesAvailableToCaller.LowPart; - } - /* If it's not available, we just use GetDiskFreeSpace */ - else { - if (GetDiskFreeSpace(Z_STRVAL_PP(path), - &SectorsPerCluster, &BytesPerSector, - &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; - bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector; - } - } - else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load kernel32.dll"); - RETURN_FALSE; - } - -#elif defined(OS2) - { - FSALLOCATE fsinfo; - char drive = Z_STRVAL_PP(path)[0] & 95; - - if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) - bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail; - } -#else /* WINDOWS, OS/2 */ -#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) - if (statvfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; - if (buf.f_frsize) { - bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize)); - } else { - bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize)); - } -#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS) - if (statfs(Z_STRVAL_PP(path), &buf)) RETURN_FALSE; - bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail)); -#endif -#endif /* WINDOWS */ - - RETURN_DOUBLE(bytesfree); -} -/* }}} */ - -/* {{{ proto bool chgrp(string filename, mixed group) - Change file group */ -PHP_FUNCTION(chgrp) -{ -#if !defined(WINDOWS) && !defined(NETWARE) /* I guess 'chgrp' won't be available on NetWare */ - pval **filename, **group; - gid_t gid; - struct group *gr=NULL; - int ret; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &group)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - if (Z_TYPE_PP(group) == IS_STRING) { - gr = getgrnam(Z_STRVAL_PP(group)); - if (!gr) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", - Z_STRVAL_PP(group)); - RETURN_FALSE; - } - gid = gr->gr_gid; - } else { - convert_to_long_ex(group); - gid = Z_LVAL_PP(group); - } - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid); - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -#else - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool chown (string filename, mixed user) - Change file owner */ -PHP_FUNCTION(chown) -{ -#if !defined(WINDOWS) && !defined(NETWARE) /* I guess 'chown' won't be available on NetWare */ - pval **filename, **user; - int ret; - uid_t uid; - struct passwd *pw = NULL; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &user)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - if (Z_TYPE_PP(user) == IS_STRING) { - pw = getpwnam(Z_STRVAL_PP(user)); - if (!pw) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", - Z_STRVAL_PP(user)); - RETURN_FALSE; - } - uid = pw->pw_uid; - } else { - convert_to_long_ex(user); - uid = Z_LVAL_PP(user); - } - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1); - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } -#endif - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool chmod(string filename, int mode) - Change file mode */ -PHP_FUNCTION(chmod) -{ - pval **filename, **mode; - int ret; - mode_t imode; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &mode)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - convert_to_long_ex(mode); - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - imode = (mode_t) Z_LVAL_PP(mode); - /* in safe mode, do not allow to setuid files. - Setuiding files could allow users to gain privileges - that safe mode doesn't give them. - */ - if(PG(safe_mode)) - imode &= 0777; - - ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode); - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -#if HAVE_UTIME -/* {{{ proto bool touch(string filename [, int time [, int atime]]) - Set modification time of file */ -PHP_FUNCTION(touch) -{ - pval **filename, **filetime, **fileatime; - int ret; -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc sb; -#else - struct stat sb; -#endif - FILE *file; - struct utimbuf newtimebuf; - struct utimbuf *newtime = NULL; - int ac = ZEND_NUM_ARGS(); - - - if (ac == 1 && zend_get_parameters_ex(1, &filename) != FAILURE) { -#ifndef HAVE_UTIME_NULL - newtime = &newtimebuf; - newtime->modtime = newtime->actime = time(NULL); -#endif - } else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) { - convert_to_long_ex(filetime); - newtime = &newtimebuf; - newtime->modtime = newtime->actime = Z_LVAL_PP(filetime); - } else if (ac == 3 && zend_get_parameters_ex(3, &filename, &filetime, &fileatime) != FAILURE) { - convert_to_long_ex(fileatime); - convert_to_long_ex(filetime); - newtime = &newtimebuf; - newtime->actime = Z_LVAL_PP(fileatime); - newtime->modtime = Z_LVAL_PP(filetime); - } else { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) { - RETURN_FALSE; - } - - /* create the file if it doesn't exist already */ - ret = VCWD_STAT(Z_STRVAL_PP(filename), &sb); - if (ret == -1) { - file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w"); - if (file == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno)); - RETURN_FALSE; - } - fclose(file); - } - - ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime); - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Utime failed: %s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ -#endif - -/* {{{ proto void clearstatcache(void) - Clear file stat cache */ -PHP_FUNCTION(clearstatcache) -{ - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); - BG(CurrentStatFile) = NULL; - } -} -/* }}} */ - -#define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT) -#define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK) - -/* {{{ php_stat - */ -static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value TSRMLS_DC) -{ - zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev, - *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks; -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc *stat_sb; -#else - struct stat *stat_sb; -#endif - int rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */ - char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", - "size", "atime", "mtime", "ctime", "blksize", "blocks"}; - - if (!filename_length) { - RETURN_FALSE; - } - - if (PG(safe_mode) &&(!php_checkuid_ex(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR, IS_EXISTS_CHECK(type) ? CHECKUID_NO_ERRORS : 0))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(filename TSRMLS_CC)) { - RETURN_FALSE; - } - - switch (type) { - case FS_IS_W: - RETURN_BOOL (!VCWD_ACCESS(filename, W_OK)); - case FS_IS_R: - RETURN_BOOL (!VCWD_ACCESS(filename, R_OK)); - case FS_IS_X: - RETURN_BOOL (!VCWD_ACCESS(filename, X_OK)); - case FS_EXISTS: - RETURN_BOOL (!VCWD_ACCESS(filename, F_OK)); - } - - stat_sb = &BG(sb); - - if (!BG(CurrentStatFile) || strcmp(filename, BG(CurrentStatFile))) { - if (!BG(CurrentStatFile) || filename_length > BG(CurrentStatLength)) { - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); - } - BG(CurrentStatLength) = filename_length; - BG(CurrentStatFile) = estrndup(filename, filename_length); - } else { - memcpy(BG(CurrentStatFile), filename, filename_length+1); - } -#if HAVE_SYMLINK - BG(lsb).st_mode = 0; /* mark lstat buf invalid */ -#endif - if (VCWD_STAT(BG(CurrentStatFile), &BG(sb)) == -1) { - if (!IS_LINK_OPERATION(type) && (!IS_EXISTS_CHECK(type) || errno != ENOENT)) { /* fileexists() test must print no error */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); - } - efree(BG(CurrentStatFile)); - BG(CurrentStatFile) = NULL; - if (!IS_LINK_OPERATION(type)) { /* Don't require success for link operation */ - RETURN_FALSE; - } - } - } - -#if HAVE_SYMLINK - if (IS_LINK_OPERATION(type) && !BG(lsb).st_mode) { - /* do lstat if the buffer is empty */ - if (VCWD_LSTAT(filename, &BG(lsb)) == -1) { - if (!IS_EXISTS_CHECK(type) || errno != ENOENT) { /* fileexists() test must print no error */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Lstat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); - } - RETURN_FALSE; - } - } -#endif - - -#ifndef NETWARE - if (type >= FS_IS_W && type <= FS_IS_X) { - if(BG(sb).st_uid==getuid()) { - rmask=S_IRUSR; - wmask=S_IWUSR; - xmask=S_IXUSR; - } else if(BG(sb).st_gid==getgid()) { - rmask=S_IRGRP; - wmask=S_IWGRP; - xmask=S_IXGRP; - } else { - int groups, n, i; - gid_t *gids; - - groups = getgroups(0, NULL); - if(groups) { - gids=(gid_t *)emalloc(groups*sizeof(gid_t)); - n=getgroups(groups, gids); - for(i=0;i<n;i++){ - if(BG(sb).st_gid==gids[i]) { - rmask=S_IRGRP; - wmask=S_IWGRP; - xmask=S_IXGRP; - break; - } - } - efree(gids); - } - } - } -#endif - - switch (type) { - case FS_PERMS: - RETURN_LONG((long)BG(sb).st_mode); - case FS_INODE: - RETURN_LONG((long)BG(sb).st_ino); - case FS_SIZE: -#if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)(stat_sb->st_size)); -#else - RETURN_LONG((long)BG(sb).st_size); -#endif - case FS_OWNER: - RETURN_LONG((long)BG(sb).st_uid); - case FS_GROUP: - RETURN_LONG((long)BG(sb).st_gid); - case FS_ATIME: -#if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)((stat_sb->st_atime).tv_sec)); -#else - RETURN_LONG((long)BG(sb).st_atime); -#endif - case FS_MTIME: -#if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)((stat_sb->st_mtime).tv_sec)); -#else - RETURN_LONG((long)BG(sb).st_mtime); -#endif - case FS_CTIME: -#if defined(NETWARE) && defined(NEW_LIBC) - RETURN_LONG((long)((stat_sb->st_ctime).tv_sec)); -#else - RETURN_LONG((long)BG(sb).st_ctime); -#endif - case FS_TYPE: -#if HAVE_SYMLINK - if (S_ISLNK(BG(lsb).st_mode)) { - RETURN_STRING("link", 1); - } -#endif - switch(BG(sb).st_mode&S_IFMT) { - case S_IFIFO: RETURN_STRING("fifo", 1); - case S_IFCHR: RETURN_STRING("char", 1); - case S_IFDIR: RETURN_STRING("dir", 1); - case S_IFBLK: RETURN_STRING("block", 1); - case S_IFREG: RETURN_STRING("file", 1); -#if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__) - case S_IFSOCK: RETURN_STRING("socket", 1); -#endif - } - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown file type (%d)", BG(sb).st_mode&S_IFMT); - RETURN_STRING("unknown", 1); - case FS_IS_W: -#ifndef NETWARE /* getuid is not available on NetWare */ - if (getuid()==0) { - RETURN_TRUE; /* root */ - } -#endif /* NETWARE */ - RETURN_BOOL((BG(sb).st_mode & wmask) != 0); - case FS_IS_R: -#ifndef NETWARE /* getuid is not available on NetWare */ - if (getuid()==0) { - RETURN_TRUE; /* root */ - } -#endif /* NETWARE */ - RETURN_BOOL((BG(sb).st_mode&rmask)!=0); - case FS_IS_X: -#ifndef NETWARE /* getuid is not available on NetWare */ - if (getuid()==0) { - xmask = S_IXROOT; /* root */ - } -#endif /* NETWARE */ - RETURN_BOOL((BG(sb).st_mode&xmask)!=0 && !S_ISDIR(BG(sb).st_mode)); - case FS_IS_FILE: - RETURN_BOOL(S_ISREG(BG(sb).st_mode)); - case FS_IS_DIR: - RETURN_BOOL(S_ISDIR(BG(sb).st_mode)); - case FS_IS_LINK: -#if HAVE_SYMLINK - RETURN_BOOL(S_ISLNK(BG(lsb).st_mode)); -#else - RETURN_FALSE; -#endif - case FS_EXISTS: - RETURN_TRUE; /* the false case was done earlier */ - case FS_LSTAT: -#if HAVE_SYMLINK - stat_sb = &BG(lsb); -#endif - /* FALLTHROUGH */ - case FS_STAT: - array_init(return_value); - - MAKE_LONG_ZVAL_INCREF(stat_dev, stat_sb->st_dev); - MAKE_LONG_ZVAL_INCREF(stat_ino, stat_sb->st_ino); - MAKE_LONG_ZVAL_INCREF(stat_mode, stat_sb->st_mode); - MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_sb->st_nlink); - MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb->st_uid); - MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb->st_gid); -#ifdef HAVE_ST_RDEV - MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev); -#else - MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); -#endif - MAKE_LONG_ZVAL_INCREF(stat_size, stat_sb->st_size); -#if defined(NETWARE) && defined(NEW_LIBC) - MAKE_LONG_ZVAL_INCREF(stat_atime, (stat_sb->st_atime).tv_sec); - MAKE_LONG_ZVAL_INCREF(stat_mtime, (stat_sb->st_mtime).tv_sec); - MAKE_LONG_ZVAL_INCREF(stat_ctime, (stat_sb->st_ctime).tv_sec); -#else - MAKE_LONG_ZVAL_INCREF(stat_atime, stat_sb->st_atime); - MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_sb->st_mtime); - MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_sb->st_ctime); -#endif -#ifdef HAVE_ST_BLKSIZE - MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_sb->st_blksize); -#else - MAKE_LONG_ZVAL_INCREF(stat_blksize,-1); -#endif -#ifdef HAVE_ST_BLOCKS - MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_sb->st_blocks); -#else - MAKE_LONG_ZVAL_INCREF(stat_blocks,-1); -#endif - /* Store numeric indexes in propper order */ - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL); - - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL); - zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL); - - /* Store string indexes referencing the same zval*/ - zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *) &stat_dev, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *) &stat_ino, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *) &stat_mode, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *) &stat_nlink, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *) &stat_uid, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *) &stat_gid, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *) &stat_rdev, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *) &stat_size, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *) &stat_atime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *) &stat_mtime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *) &stat_ctime, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *) &stat_blksize, sizeof(zval *), NULL); - zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *) &stat_blocks, sizeof(zval *), NULL); - - return; - } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Didn't understand stat call"); - RETURN_FALSE; -} -/* }}} */ - -/* another quickie macro to make defining similar functions easier */ -#define FileFunction(name, funcnum) \ -void name(INTERNAL_FUNCTION_PARAMETERS) { \ - pval **filename; \ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } \ - convert_to_string_ex(filename); \ - php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC); \ -} - -/* {{{ proto int fileperms(string filename) - Get file permissions */ -FileFunction(PHP_FN(fileperms), FS_PERMS) -/* }}} */ - -/* {{{ proto int fileinode(string filename) - Get file inode */ -FileFunction(PHP_FN(fileinode), FS_INODE) -/* }}} */ - -/* {{{ proto int filesize(string filename) - Get file size */ -FileFunction(PHP_FN(filesize), FS_SIZE) -/* }}} */ - -/* {{{ proto int fileowner(string filename) - Get file owner */ -FileFunction(PHP_FN(fileowner), FS_OWNER) -/* }}} */ - -/* {{{ proto int filegroup(string filename) - Get file group */ -FileFunction(PHP_FN(filegroup), FS_GROUP) -/* }}} */ - -/* {{{ proto int fileatime(string filename) - Get last access time of file */ -FileFunction(PHP_FN(fileatime), FS_ATIME) -/* }}} */ - -/* {{{ proto int filemtime(string filename) - Get last modification time of file */ -FileFunction(PHP_FN(filemtime), FS_MTIME) -/* }}} */ - -/* {{{ proto int filectime(string filename) - Get inode modification time of file */ -FileFunction(PHP_FN(filectime), FS_CTIME) -/* }}} */ - -/* {{{ proto string filetype(string filename) - Get file type */ -FileFunction(PHP_FN(filetype), FS_TYPE) -/* }}} */ - -/* {{{ proto bool is_writable(string filename) - Returns true if file can be written */ -FileFunction(PHP_FN(is_writable), FS_IS_W) -/* }}} */ - -/* {{{ proto bool is_readable(string filename) - Returns true if file can be read */ -FileFunction(PHP_FN(is_readable), FS_IS_R) -/* }}} */ - -/* {{{ proto bool is_executable(string filename) - Returns true if file is executable */ -FileFunction(PHP_FN(is_executable), FS_IS_X) -/* }}} */ - -/* {{{ proto bool is_file(string filename) - Returns true if file is a regular file */ -FileFunction(PHP_FN(is_file), FS_IS_FILE) -/* }}} */ - -/* {{{ proto bool is_dir(string filename) - Returns true if file is directory */ -FileFunction(PHP_FN(is_dir), FS_IS_DIR) -/* }}} */ - -/* {{{ proto bool is_link(string filename) - Returns true if file is symbolic link */ -FileFunction(PHP_FN(is_link), FS_IS_LINK) -/* }}} */ - -/* {{{ proto bool file_exists(string filename) - Returns true if filename exists */ -FileFunction(PHP_FN(file_exists), FS_EXISTS) -/* }}} */ - -/* {{{ proto array lstat(string filename) - Give information about a file or symbolic link */ -FileFunction(php_if_lstat, FS_LSTAT) -/* }}} */ - -/* {{{ proto array stat(string filename) - Give information about a file */ -FileFunction(php_if_stat, FS_STAT) -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/filters.c b/ext/standard/filters.c deleted file mode 100644 index 918377a5e7..0000000000 --- a/ext/standard/filters.c +++ /dev/null @@ -1,1907 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: | - | Wez Furlong (wez@thebrainroom.com) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/basic_functions.h" -#include "ext/standard/file.h" -#include "ext/standard/php_string.h" - -/* {{{ rot13 stream filter implementation */ -static char rot13_from[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static char rot13_to[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"; - -static php_stream_filter_status_t strfilter_rot13_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - php_stream_bucket *bucket; - size_t consumed = 0; - - while (buckets_in->head) { - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); - - php_strtr(bucket->buf, bucket->buflen, rot13_from, rot13_to, 52); - consumed += bucket->buflen; - - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); - } - - if (bytes_consumed) { - *bytes_consumed = consumed; - } - - return PSFS_PASS_ON; -} - -static php_stream_filter_ops strfilter_rot13_ops = { - strfilter_rot13_filter, - NULL, - "string.rot13" -}; - -static php_stream_filter *strfilter_rot13_create(const char *filtername, const char *filterparams, - int filterparamslen, int persistent TSRMLS_DC) -{ - return php_stream_filter_alloc(&strfilter_rot13_ops, NULL, persistent); -} - -static php_stream_filter_factory strfilter_rot13_factory = { - strfilter_rot13_create -}; -/* }}} */ - -/* {{{ string.toupper / string.tolower stream filter implementation */ -static char lowercase[] = "abcdefghijklmnopqrstuvwxyz"; -static char uppercase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - -static php_stream_filter_status_t strfilter_toupper_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - php_stream_bucket *bucket; - size_t consumed = 0; - - while (buckets_in->head) { - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); - - php_strtr(bucket->buf, bucket->buflen, lowercase, uppercase, 26); - consumed += bucket->buflen; - - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); - } - - if (bytes_consumed) { - *bytes_consumed = consumed; - } - - return PSFS_PASS_ON; -} - -static php_stream_filter_status_t strfilter_tolower_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - php_stream_bucket *bucket; - size_t consumed = 0; - - while (buckets_in->head) { - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); - - php_strtr(bucket->buf, bucket->buflen, uppercase, lowercase, 26); - consumed += bucket->buflen; - - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); - } - - if (bytes_consumed) { - *bytes_consumed = consumed; - } - - return PSFS_PASS_ON; -} - -static php_stream_filter_ops strfilter_toupper_ops = { - strfilter_toupper_filter, - NULL, - "string.toupper" -}; - -static php_stream_filter_ops strfilter_tolower_ops = { - strfilter_tolower_filter, - NULL, - "string.tolower" -}; - -static php_stream_filter *strfilter_toupper_create(const char *filtername, const char *filterparams, - int filterparamslen, int persistent TSRMLS_DC) -{ - return php_stream_filter_alloc(&strfilter_toupper_ops, NULL, persistent); -} - -static php_stream_filter *strfilter_tolower_create(const char *filtername, const char *filterparams, - int filterparamslen, int persistent TSRMLS_DC) -{ - return php_stream_filter_alloc(&strfilter_tolower_ops, NULL, persistent); -} - -static php_stream_filter_factory strfilter_toupper_factory = { - strfilter_toupper_create -}; - -static php_stream_filter_factory strfilter_tolower_factory = { - strfilter_tolower_create -}; -/* }}} */ - -/* {{{ strip_tags filter implementation */ -typedef struct _php_strip_tags_filter { - const char *allowed_tags; - int allowed_tags_len; - int state; - int persistent; -} php_strip_tags_filter; - -static int php_strip_tags_filter_ctor(php_strip_tags_filter *inst, const char *allowed_tags, int allowed_tags_len, int persistent) -{ - if (allowed_tags != NULL) { - inst->allowed_tags = pemalloc(allowed_tags_len, persistent); - memcpy((char *)inst->allowed_tags, allowed_tags, allowed_tags_len); - inst->allowed_tags_len = allowed_tags_len; - } else { - inst->allowed_tags = NULL; - } - inst->state = 0; - inst->persistent = persistent; - - return SUCCESS; -} - -static void php_strip_tags_filter_dtor(php_strip_tags_filter *inst) -{ - if (inst->allowed_tags != NULL) { - pefree((void *)inst->allowed_tags, inst->persistent); - } -} - -static php_stream_filter_status_t strfilter_strip_tags_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - php_stream_bucket *bucket; - size_t consumed = 0; - php_strip_tags_filter *inst = (php_strip_tags_filter *) thisfilter->abstract; - - while (buckets_in->head) { - bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); - consumed = bucket->buflen; - - bucket->buflen = php_strip_tags(bucket->buf, bucket->buflen, &(inst->state), (char *)inst->allowed_tags, inst->allowed_tags_len); - - php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); - } - - if (bytes_consumed) { - *bytes_consumed = consumed; - } - - return PSFS_PASS_ON; -} - -static void strfilter_strip_tags_dtor(php_stream_filter *thisfilter TSRMLS_DC) -{ - assert(thisfilter->abstract != NULL); - - php_strip_tags_filter_dtor((php_strip_tags_filter *)thisfilter->abstract); - - pefree(thisfilter->abstract, ((php_strip_tags_filter *)thisfilter->abstract)->persistent); -} - -static php_stream_filter_ops strfilter_strip_tags_ops = { - strfilter_strip_tags_filter, - strfilter_strip_tags_dtor, - "string.strip_tags" -}; - -static php_stream_filter *strfilter_strip_tags_create(const char *filtername, const char *filterparams, - int filterparamslen, int persistent TSRMLS_DC) -{ - php_strip_tags_filter *inst; - inst = pemalloc(sizeof(php_strip_tags_filter), persistent); - - if (php_strip_tags_filter_ctor(inst, filterparams, filterparamslen, persistent) != SUCCESS) { - pefree(inst, persistent); - return NULL; - } - - return php_stream_filter_alloc(&strfilter_strip_tags_ops, inst, persistent); -} - -static php_stream_filter_factory strfilter_strip_tags_factory = { - strfilter_strip_tags_create -}; - -/* }}} */ - -/* {{{ base64 / quoted_printable stream filter implementation */ - -typedef enum _php_conv_err_t { - PHP_CONV_ERR_SUCCESS = SUCCESS, - PHP_CONV_ERR_UNKNOWN, - PHP_CONV_ERR_TOO_BIG, - PHP_CONV_ERR_INVALID_SEQ, - PHP_CONV_ERR_UNEXPECTED_EOS, - PHP_CONV_ERR_EXISTS, - PHP_CONV_ERR_NOT_FOUND -} php_conv_err_t; - -typedef struct _php_conv php_conv; - -typedef php_conv_err_t (*php_conv_convert_func)(php_conv *, const char **, size_t *, char **, size_t *); -typedef void (*php_conv_dtor_func)(php_conv *); - -struct _php_conv { - php_conv_convert_func convert_op; - php_conv_dtor_func dtor; -}; - -#define php_conv_convert(a, b, c, d, e) ((php_conv *)(a))->convert_op((php_conv *)(a), (b), (c), (d), (e)) -#define php_conv_dtor(a) ((php_conv *)a)->dtor((a)) - -/* {{{ php_conv_base64_encode */ -typedef struct _php_conv_base64_encode { - php_conv _super; - - unsigned char erem[3]; - size_t erem_len; - unsigned int line_ccnt; - unsigned int line_len; - const char *lbchars; - int lbchars_dup; - size_t lbchars_len; - int persistent; -} php_conv_base64_encode; - -static php_conv_err_t php_conv_base64_encode_convert(php_conv_base64_encode *inst, const char **in_p, size_t *in_left, char **out_p, size_t *out_left); -static void php_conv_base64_encode_dtor(php_conv_base64_encode *inst); - -static unsigned char b64_tbl_enc[256] = { - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/', - 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P', - 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f', - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', - 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' -}; - -static php_conv_err_t php_conv_base64_encode_ctor(php_conv_base64_encode *inst, unsigned int line_len, const char *lbchars, size_t lbchars_len, int lbchars_dup, int persistent) -{ - inst->_super.convert_op = (php_conv_convert_func) php_conv_base64_encode_convert; - inst->_super.dtor = (php_conv_dtor_func) php_conv_base64_encode_dtor; - inst->erem_len = 0; - inst->line_ccnt = line_len; - inst->line_len = line_len; - if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); - inst->lbchars_len = lbchars_len; - } else { - inst->lbchars = NULL; - } - inst->lbchars_dup = lbchars_dup; - inst->persistent = persistent; - return SUCCESS; -} - -static void php_conv_base64_encode_dtor(php_conv_base64_encode *inst) -{ - assert(inst != NULL); - if (inst->lbchars_dup && inst->lbchars != NULL) { - pefree((void *)inst->lbchars, inst->persistent); - } -} - -static php_conv_err_t php_conv_base64_encode_flush(php_conv_base64_encode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p) -{ - volatile php_conv_err_t err = PHP_CONV_ERR_SUCCESS; - register unsigned char *pd; - register size_t ocnt; - unsigned int line_ccnt; - - pd = (unsigned char *)(*out_pp); - ocnt = *out_left_p; - line_ccnt = inst->line_ccnt; - - switch (inst->erem_len) { - case 0: - /* do nothing */ - break; - - case 1: - if (line_ccnt < 4 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len) { - return PHP_CONV_ERR_TOO_BIG; - } - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 4) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = b64_tbl_enc[(inst->erem[0] >> 2)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[0] << 4)]; - *(pd++) = '='; - *(pd++) = '='; - inst->erem_len = 0; - ocnt -= 4; - line_ccnt -= 4; - break; - - case 2: - if (line_ccnt < 4 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len) { - return PHP_CONV_ERR_TOO_BIG; - } - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 4) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = b64_tbl_enc[(inst->erem[0] >> 2)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[0] << 4) | (inst->erem[1] >> 4)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[1] << 2)]; - *(pd++) = '='; - inst->erem_len = 0; - ocnt -=4; - line_ccnt -= 4; - break; - - default: - /* should not happen... */ - err = PHP_CONV_ERR_UNKNOWN; - break; - } -out: - *out_pp = (char *)pd; - *out_left_p = ocnt; - inst->line_ccnt = line_ccnt; - return err; -} - -static php_conv_err_t php_conv_base64_encode_convert(php_conv_base64_encode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p) -{ - volatile php_conv_err_t err = PHP_CONV_ERR_SUCCESS; - register size_t ocnt, icnt; - register unsigned char *ps, *pd; - register unsigned int line_ccnt; - size_t nbytes_written; - - if (in_pp == NULL || in_left_p == NULL) { - return php_conv_base64_encode_flush(inst, in_pp, in_left_p, out_pp, out_left_p); - } - - pd = (unsigned char *)(*out_pp); - ocnt = *out_left_p; - ps = (unsigned char *)(*in_pp); - icnt = *in_left_p; - line_ccnt = inst->line_ccnt; - nbytes_written = 0; - - /* consume the remainder first */ - switch (inst->erem_len) { - case 1: - if (icnt >= 2) { - if (line_ccnt < 4 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len) { - return PHP_CONV_ERR_TOO_BIG; - } - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 4) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = b64_tbl_enc[(inst->erem[0] >> 2)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[0] << 4) | (ps[0] >> 4)]; - *(pd++) = b64_tbl_enc[(unsigned char)(ps[0] << 2) | (ps[1] >> 6)]; - *(pd++) = b64_tbl_enc[ps[1]]; - ocnt -= 4; - ps += 2; - icnt -= 2; - inst->erem_len = 0; - line_ccnt -= 4; - } - break; - - case 2: - if (icnt >= 1) { - if (inst->line_ccnt < 4 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len) { - return PHP_CONV_ERR_TOO_BIG; - } - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 4) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = b64_tbl_enc[(inst->erem[0] >> 2)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[0] << 4) | (inst->erem[1] >> 4)]; - *(pd++) = b64_tbl_enc[(unsigned char)(inst->erem[1] << 2) | (ps[0] >> 6)]; - *(pd++) = b64_tbl_enc[ps[0]]; - ocnt -= 4; - ps += 1; - icnt -= 1; - inst->erem_len = 0; - line_ccnt -= 4; - } - break; - } - - while (icnt >= 3) { - if (line_ccnt < 4 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 4) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = b64_tbl_enc[ps[0] >> 2]; - *(pd++) = b64_tbl_enc[(unsigned char)(ps[0] << 4) | (ps[1] >> 4)]; - *(pd++) = b64_tbl_enc[(unsigned char)(ps[1] << 2) | (ps[2] >> 6)]; - *(pd++) = b64_tbl_enc[ps[2]]; - - ps += 3; - icnt -=3; - ocnt -= 4; - line_ccnt -= 4; - } - for (;icnt > 0; icnt--) { - inst->erem[inst->erem_len++] = *(ps++); - } - -out: - *in_pp = (const char *)ps; - *in_left_p = icnt; - *out_pp = (char *)pd; - *out_left_p = ocnt; - inst->line_ccnt = line_ccnt; - - return err; -} - -/* }}} */ - -/* {{{ php_conv_base64_decode */ -typedef struct _php_conv_base64_decode { - php_conv _super; - - unsigned int urem; - unsigned int urem_nbits; - unsigned int ustat; - int eos; -} php_conv_base64_decode; - -static php_conv_err_t php_conv_base64_decode_convert(php_conv_base64_decode *inst, const char **in_p, size_t *in_left, char **out_p, size_t *out_left); -static void php_conv_base64_decode_dtor(php_conv_base64_decode *inst); - -static unsigned int b64_tbl_dec[256] = { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64,128, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 -}; - -static int php_conv_base64_decode_ctor(php_conv_base64_decode *inst) -{ - inst->_super.convert_op = (php_conv_convert_func) php_conv_base64_decode_convert; - inst->_super.dtor = (php_conv_dtor_func) php_conv_base64_decode_dtor; - - inst->urem = 0; - inst->urem_nbits = 0; - inst->ustat = 0; - inst->eos = 0; - return SUCCESS; -} - -static void php_conv_base64_decode_dtor(php_conv_base64_decode *inst) -{ - /* do nothing */ -} - -#define bmask(a) (0xffff >> (16 - a)) -static php_conv_err_t php_conv_base64_decode_convert(php_conv_base64_decode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p) -{ - php_conv_err_t err; - - unsigned int urem, urem_nbits; - unsigned int pack, pack_bcnt; - unsigned char *ps, *pd; - size_t icnt, ocnt; - unsigned int ustat; - - const static unsigned int nbitsof_pack = 8; - - if (in_pp == NULL || in_left_p == NULL) { - if (inst->eos || inst->urem_nbits == 0) { - return SUCCESS; - } - return PHP_CONV_ERR_UNEXPECTED_EOS; - } - - err = PHP_CONV_ERR_SUCCESS; - - ps = (unsigned char *)*in_pp; - pd = (unsigned char *)*out_pp; - icnt = *in_left_p; - ocnt = *out_left_p; - - urem = inst->urem; - urem_nbits = inst->urem_nbits; - ustat = inst->ustat; - - pack = 0; - pack_bcnt = nbitsof_pack; - - for (;;) { - if (pack_bcnt >= urem_nbits) { - pack_bcnt -= urem_nbits; - pack |= (urem << pack_bcnt); - urem_nbits = 0; - } else { - urem_nbits -= pack_bcnt; - pack |= (urem >> urem_nbits); - urem &= bmask(urem_nbits); - pack_bcnt = 0; - } - if (pack_bcnt > 0) { - unsigned int i; - - if (icnt < 1) { - break; - } - - i = b64_tbl_dec[(unsigned int)*(ps++)]; - icnt--; - ustat |= i & 0x80; - - if (!(i & 0xc0)) { - if (ustat) { - err = PHP_CONV_ERR_INVALID_SEQ; - break; - } - if (6 <= pack_bcnt) { - pack_bcnt -= 6; - pack |= (i << pack_bcnt); - urem = 0; - } else { - urem_nbits = 6 - pack_bcnt; - pack |= (i >> urem_nbits); - urem = i & bmask(urem_nbits); - pack_bcnt = 0; - } - } else if (ustat) { - if (pack_bcnt == 8 || pack_bcnt == 2) { - err = PHP_CONV_ERR_INVALID_SEQ; - break; - } - inst->eos = 1; - } - } - if ((pack_bcnt | ustat) == 0) { - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = pack; - ocnt--; - pack = 0; - pack_bcnt = nbitsof_pack; - } - } - - if (urem_nbits >= pack_bcnt) { - urem |= (pack << (urem_nbits - pack_bcnt)); - urem_nbits += (nbitsof_pack - pack_bcnt); - } else { - urem |= (pack >> (pack_bcnt - urem_nbits)); - urem_nbits += (nbitsof_pack - pack_bcnt); - } - - inst->urem = urem; - inst->urem_nbits = urem_nbits; - inst->ustat = ustat; - - *in_pp = (const char *)ps; - *in_left_p = icnt; - *out_pp = (char *)pd; - *out_left_p = ocnt; - - return err; -} -#undef bmask -/* }}} */ - -/* {{{ php_conv_qprint_encode */ -typedef struct _php_conv_qprint_encode { - php_conv _super; - - int opts; - unsigned int line_ccnt; - unsigned int line_len; - const char *lbchars; - int lbchars_dup; - size_t lbchars_len; - int persistent; - unsigned int lb_ptr; - unsigned int lb_cnt; -} php_conv_qprint_encode; - -#define PHP_CONV_QPRINT_OPT_BINARY 0x00000001 -#define PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST 0x00000002 - -static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst); -static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p); - -static void php_conv_qprint_encode_dtor(php_conv_qprint_encode *inst) -{ - assert(inst != NULL); - if (inst->lbchars_dup && inst->lbchars != NULL) { - pefree((void *)inst->lbchars, inst->persistent); - } -} - -#define NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, lbchars) \ - ((lb_ptr) < (lb_cnt) ? (lbchars)[(lb_ptr)] : *(ps)) - -#define CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt) \ - if ((lb_ptr) < (lb_cnt)) { \ - (lb_ptr)++; \ - } else { \ - (lb_cnt) = (lb_ptr) = 0; \ - --(icnt); \ - (ps)++; \ - } - -static php_conv_err_t php_conv_qprint_encode_convert(php_conv_qprint_encode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p) -{ - php_conv_err_t err = PHP_CONV_ERR_SUCCESS; - unsigned char *ps, *pd; - size_t icnt, ocnt; - unsigned int c; - unsigned int line_ccnt; - unsigned int lb_ptr; - unsigned int lb_cnt; - int opts; - static char qp_digits[] = "0123456789ABCDEF"; - - line_ccnt = inst->line_ccnt; - opts = inst->opts; - lb_ptr = inst->lb_ptr; - lb_cnt = inst->lb_cnt; - - if ((in_pp == NULL || in_left_p == NULL) && (lb_ptr >=lb_cnt)) { - return PHP_CONV_ERR_SUCCESS; - } - - ps = (unsigned char *)(*in_pp); - icnt = *in_left_p; - pd = (unsigned char *)(*out_pp); - ocnt = *out_left_p; - - for (;;) { - if (!(opts & PHP_CONV_QPRINT_OPT_BINARY) && inst->lbchars != NULL && inst->lbchars_len > 0) { - /* look ahead for the line break chars to make a right decision - * how to consume incoming characters */ - - if (icnt > 0 && *ps == inst->lbchars[lb_cnt]) { - lb_cnt++; - - if (lb_cnt >= inst->lbchars_len) { - unsigned int i; - - if (ocnt < lb_cnt) { - lb_cnt--; - err = PHP_CONV_ERR_TOO_BIG; - break; - } - - for (i = 0; i < lb_cnt; i++) { - *(pd++) = inst->lbchars[i]; - ocnt--; - } - line_ccnt = inst->line_len; - lb_ptr = lb_cnt = 0; - } - ps++, icnt--; - continue; - } - } - - if (lb_ptr >= lb_cnt && icnt <= 0) { - break; - } - - c = NEXT_CHAR(ps, icnt, lb_ptr, lb_cnt, inst->lbchars); - - if (!(opts & PHP_CONV_QPRINT_OPT_BINARY) && (c == '\t' || c == ' ')) { - if (line_ccnt < 2 && inst->lbchars != NULL) { - if (ocnt < inst->lbchars_len + 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - - *(pd++) = '='; - ocnt--; - line_ccnt--; - - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } else { - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = c; - ocnt--; - line_ccnt--; - CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt); - } - } else if ((!(opts & PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST) || line_ccnt < inst->line_len) && ((c >= 33 && c <= 60) || (c >= 62 && c <= 126))) { - if (line_ccnt < 2) { - if (ocnt < inst->lbchars_len + 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = '='; - ocnt--; - line_ccnt--; - - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = c; - ocnt--; - line_ccnt--; - CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt); - } else { - if (line_ccnt < 4) { - if (ocnt < inst->lbchars_len + 1) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = '='; - ocnt--; - line_ccnt--; - - memcpy(pd, inst->lbchars, inst->lbchars_len); - pd += inst->lbchars_len; - ocnt -= inst->lbchars_len; - line_ccnt = inst->line_len; - } - if (ocnt < 3) { - err = PHP_CONV_ERR_TOO_BIG; - break; - } - *(pd++) = '='; - *(pd++) = qp_digits[(c >> 4)]; - *(pd++) = qp_digits[(c & 0x0f)]; - ocnt -= 3; - line_ccnt -= 3; - CONSUME_CHAR(ps, icnt, lb_ptr, lb_cnt); - } - } - - *in_pp = (const char *)ps; - *in_left_p = icnt; - *out_pp = (char *)pd; - *out_left_p = ocnt; - inst->line_ccnt = line_ccnt; - inst->lb_ptr = lb_ptr; - inst->lb_cnt = lb_cnt; - return err; -} -#undef NEXT_CHAR -#undef CONSUME_CHAR - -static php_conv_err_t php_conv_qprint_encode_ctor(php_conv_qprint_encode *inst, unsigned int line_len, const char *lbchars, size_t lbchars_len, int lbchars_dup, int opts, int persistent) -{ - if (line_len < 4 && lbchars != NULL) { - return PHP_CONV_ERR_TOO_BIG; - } - inst->_super.convert_op = (php_conv_convert_func) php_conv_qprint_encode_convert; - inst->_super.dtor = (php_conv_dtor_func) php_conv_qprint_encode_dtor; - inst->line_ccnt = line_len; - inst->line_len = line_len; - if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); - inst->lbchars_len = lbchars_len; - } else { - inst->lbchars = NULL; - } - inst->lbchars_dup = lbchars_dup; - inst->persistent = persistent; - inst->opts = opts; - inst->lb_cnt = inst->lb_ptr = 0; - return PHP_CONV_ERR_SUCCESS; -} -/* }}} */ - -/* {{{ php_conv_qprint_decode */ -typedef struct _php_conv_qprint_decode { - php_conv _super; - - int scan_stat; - unsigned int next_char; - const char *lbchars; - int lbchars_dup; - size_t lbchars_len; - int persistent; - unsigned int lb_ptr; - unsigned int lb_cnt; -} php_conv_qprint_decode; - -static void php_conv_qprint_decode_dtor(php_conv_qprint_decode *inst) -{ - assert(inst != NULL); - if (inst->lbchars_dup && inst->lbchars != NULL) { - pefree((void *)inst->lbchars, inst->persistent); - } -} - -static php_conv_err_t php_conv_qprint_decode_convert(php_conv_qprint_decode *inst, const char **in_pp, size_t *in_left_p, char **out_pp, size_t *out_left_p) -{ - php_conv_err_t err = PHP_CONV_ERR_SUCCESS; - size_t icnt, ocnt; - unsigned char *ps, *pd; - unsigned int scan_stat; - unsigned int next_char; - unsigned int lb_ptr, lb_cnt; - - lb_ptr = inst->lb_ptr; - lb_cnt = inst->lb_cnt; - - if ((in_pp == NULL || in_left_p == NULL) && lb_cnt == lb_ptr) { - if (inst->scan_stat != 0) { - return PHP_CONV_ERR_UNEXPECTED_EOS; - } - return PHP_CONV_ERR_SUCCESS; - } - - ps = (unsigned char *)(*in_pp); - icnt = *in_left_p; - pd = (unsigned char *)(*out_pp); - ocnt = *out_left_p; - scan_stat = inst->scan_stat; - next_char = inst->next_char; - - for (;;) { - switch (scan_stat) { - case 0: { - if (icnt <= 0) { - goto out; - } - if (*ps == '=') { - scan_stat = 1; - } else { - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = *ps; - ocnt--; - } - ps++, icnt--; - } break; - - case 1: { - if (icnt <= 0) { - goto out; - } - if (*ps == ' ' || *ps == '\t') { - scan_stat = 4; - ps++, icnt--; - break; - } else if (lb_cnt < inst->lbchars_len && - *ps == (unsigned char)inst->lbchars[lb_cnt]) { - lb_cnt++; - scan_stat = 5; - ps++, icnt--; - break; - } - } /* break is missing intentionally */ - - case 2: { - unsigned int nbl; - - if (icnt <= 0) { - goto out; - } - nbl = (*ps >= 'A' ? *ps - 0x37 : *ps - 0x30); - - if (nbl > 15) { - err = PHP_CONV_ERR_INVALID_SEQ; - goto out; - } - next_char = (next_char << 4) | nbl; - - scan_stat++; - ps++, icnt--; - if (scan_stat != 3) { - break; - } - } /* break is missing intentionally */ - - case 3: { - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = next_char; - ocnt--; - scan_stat = 0; - } break; - - case 4: { - if (icnt <= 0) { - goto out; - } - if (lb_cnt < inst->lbchars_len && - *ps == (unsigned char)inst->lbchars[lb_cnt]) { - lb_cnt++; - scan_stat = 5; - } - if (*ps != '\t' && *ps != ' ') { - err = PHP_CONV_ERR_INVALID_SEQ; - goto out; - } - ps++, icnt--; - } break; - - case 5: { - if (lb_cnt >= inst->lbchars_len) { - /* soft line break */ - lb_cnt = lb_ptr = 0; - scan_stat = 0; - } else if (icnt > 0) { - if (*ps == (unsigned char)inst->lbchars[lb_cnt]) { - lb_cnt++; - ps++, icnt--; - } else { - scan_stat = 6; /* no break for short-cut */ - } - } else { - goto out; - } - } break; - - case 6: { - if (lb_ptr < lb_cnt) { - if (ocnt < 1) { - err = PHP_CONV_ERR_TOO_BIG; - goto out; - } - *(pd++) = inst->lbchars[lb_ptr++]; - ocnt--; - } else { - scan_stat = 0; - lb_cnt = lb_ptr = 0; - } - } break; - } - } -out: - *in_pp = (const char *)ps; - *in_left_p = icnt; - *out_pp = (char *)pd; - *out_left_p = ocnt; - inst->scan_stat = scan_stat; - inst->lb_ptr = lb_ptr; - inst->lb_cnt = lb_cnt; - inst->next_char = next_char; - - return err; -} -static php_conv_err_t php_conv_qprint_decode_ctor(php_conv_qprint_decode *inst, const char *lbchars, size_t lbchars_len, int lbchars_dup, int persistent) -{ - inst->_super.convert_op = (php_conv_convert_func) php_conv_qprint_decode_convert; - inst->_super.dtor = (php_conv_dtor_func) php_conv_qprint_decode_dtor; - inst->scan_stat = 0; - inst->next_char = 0; - inst->lb_ptr = inst->lb_cnt = 0; - if (lbchars != NULL) { - inst->lbchars = (lbchars_dup ? pestrdup(lbchars, persistent) : lbchars); - inst->lbchars_len = lbchars_len; - } else { - inst->lbchars = NULL; - inst->lbchars_len = 0; - } - inst->lbchars_dup = lbchars_dup; - inst->persistent = persistent; - return PHP_CONV_ERR_SUCCESS; -} -/* }}} */ - -typedef struct _php_convert_filter { - php_conv *cd; - int persistent; - char *filtername; -} php_convert_filter; - -#define PHP_CONV_BASE64_ENCODE 1 -#define PHP_CONV_BASE64_DECODE 2 -#define PHP_CONV_QPRINT_ENCODE 3 -#define PHP_CONV_QPRINT_DECODE 4 - -static php_conv_err_t php_conv_get_string_prop_ex(const HashTable *ht, char **pretval, size_t *pretval_len, char *field_name, size_t field_name_len, int persistent) -{ - zval **tmpval; - - *pretval = NULL; - *pretval_len = 0; - - if (zend_hash_find((HashTable *)ht, field_name, field_name_len, (void **)&tmpval) == SUCCESS) { - if (Z_TYPE_PP(tmpval) != IS_STRING) { - zval zt = **tmpval; - convert_to_string(&zt); - *pretval = pemalloc(Z_STRLEN(zt) + 1, persistent); - *pretval_len = Z_STRLEN(zt); - memcpy(*pretval, Z_STRVAL(zt), Z_STRLEN(zt) + 1); - zval_dtor(&zt); - } else { - *pretval = pemalloc(Z_STRLEN_PP(tmpval) + 1, persistent); - *pretval_len = Z_STRLEN_PP(tmpval); - memcpy(*pretval, Z_STRVAL_PP(tmpval), Z_STRLEN_PP(tmpval) + 1); - } - } else { - return PHP_CONV_ERR_NOT_FOUND; - } - return PHP_CONV_ERR_SUCCESS; -} - -static php_conv_err_t php_conv_get_long_prop_ex(const HashTable *ht, long *pretval, char *field_name, size_t field_name_len) -{ - zval **tmpval; - - *pretval = 0; - - if (zend_hash_find((HashTable *)ht, field_name, field_name_len, (void **)&tmpval) == SUCCESS) { - zval tmp, *ztval = *tmpval; - - if (Z_TYPE_PP(tmpval) != IS_LONG) { - tmp = *ztval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - ztval = &tmp; - } - *pretval = Z_LVAL_P(ztval); - } else { - return PHP_CONV_ERR_NOT_FOUND; - } - return PHP_CONV_ERR_SUCCESS; -} - -static php_conv_err_t php_conv_get_ulong_prop_ex(const HashTable *ht, unsigned long *pretval, char *field_name, size_t field_name_len) -{ - zval **tmpval; - - *pretval = 0; - - if (zend_hash_find((HashTable *)ht, field_name, field_name_len, (void **)&tmpval) == SUCCESS) { - zval tmp, *ztval = *tmpval; - - if (Z_TYPE_PP(tmpval) != IS_LONG) { - tmp = *ztval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - ztval = &tmp; - } - if (Z_LVAL_P(ztval) < 0) { - *pretval = 0; - } else { - *pretval = Z_LVAL_P(ztval); - } - } else { - return PHP_CONV_ERR_NOT_FOUND; - } - return PHP_CONV_ERR_SUCCESS; -} - -static php_conv_err_t php_conv_get_bool_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len) -{ - zval **tmpval; - - *pretval = 0; - - if (zend_hash_find((HashTable *)ht, field_name, field_name_len, (void **)&tmpval) == SUCCESS) { - zval tmp, *ztval = *tmpval; - - if (Z_TYPE_PP(tmpval) != IS_BOOL) { - tmp = *ztval; - zval_copy_ctor(&tmp); - convert_to_boolean(&tmp); - ztval = &tmp; - } - *pretval = Z_BVAL_P(ztval); - } else { - return PHP_CONV_ERR_NOT_FOUND; - } - return PHP_CONV_ERR_SUCCESS; -} - - -static int php_conv_get_int_prop_ex(const HashTable *ht, int *pretval, char *field_name, size_t field_name_len) -{ - long l; - php_conv_err_t err; - - *pretval = 0; - - if ((err = php_conv_get_long_prop_ex(ht, &l, field_name, field_name_len)) == PHP_CONV_ERR_SUCCESS) { - *pretval = l; - } - return err; -} - -static int php_conv_get_uint_prop_ex(const HashTable *ht, unsigned int *pretval, char *field_name, size_t field_name_len) -{ - long l; - php_conv_err_t err; - - *pretval = 0; - - if ((err = php_conv_get_ulong_prop_ex(ht, &l, field_name, field_name_len)) == PHP_CONV_ERR_SUCCESS) { - *pretval = l; - } - return err; -} - -#define GET_STR_PROP(ht, var, var_len, fldname, persistent) \ - php_conv_get_string_prop_ex(ht, &var, &var_len, fldname, sizeof(fldname), persistent) - -#define GET_INT_PROP(ht, var, fldname) \ - php_conv_get_int_prop_ex(ht, &var, fldname, sizeof(fldname)) - -#define GET_UINT_PROP(ht, var, fldname) \ - php_conv_get_uint_prop_ex(ht, &var, fldname, sizeof(fldname)) - -#define GET_BOOL_PROP(ht, var, fldname) \ - php_conv_get_bool_prop_ex(ht, &var, fldname, sizeof(fldname)) - -static php_conv *php_conv_open(int conv_mode, const HashTable *options, int persistent) -{ - /* FIXME: I'll have to replace this ugly code by something neat - (factories?) in the near future. */ - php_conv *retval = NULL; - - switch (conv_mode) { - case PHP_CONV_BASE64_ENCODE: { - unsigned int line_len = 0; - char *lbchars = NULL; - size_t lbchars_len; - - if (options != NULL) { - GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0); - GET_UINT_PROP(options, line_len, "line-length"); - if (line_len < 4) { - if (lbchars != NULL) { - pefree(lbchars, 0); - } - lbchars = NULL; - } else { - if (lbchars == NULL) { - lbchars = pestrdup("\r\n", 0); - lbchars_len = 2; - } - } - } - retval = pemalloc(sizeof(php_conv_base64_encode), persistent); - if (lbchars != NULL) { - if (php_conv_base64_encode_ctor((php_conv_base64_encode *)retval, line_len, lbchars, lbchars_len, 1, persistent)) { - if (lbchars != NULL) { - pefree(lbchars, 0); - } - goto out_failure; - } - pefree(lbchars, 0); - } else { - if (php_conv_base64_encode_ctor((php_conv_base64_encode *)retval, 0, NULL, 0, 0, persistent)) { - goto out_failure; - } - } - } break; - - case PHP_CONV_BASE64_DECODE: - retval = pemalloc(sizeof(php_conv_base64_decode), persistent); - if (php_conv_base64_decode_ctor((php_conv_base64_decode *)retval)) { - goto out_failure; - } - break; - - case PHP_CONV_QPRINT_ENCODE: { - unsigned int line_len = 0; - char *lbchars = NULL; - size_t lbchars_len; - int opts = 0; - - if (options != NULL) { - int opt_binary = 0; - int opt_force_encode_first = 0; - - GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0); - GET_UINT_PROP(options, line_len, "line-length"); - GET_BOOL_PROP(options, opt_binary, "binary"); - GET_BOOL_PROP(options, opt_force_encode_first, "force-encode-first"); - - if (line_len < 4) { - if (lbchars != NULL) { - pefree(lbchars, 0); - } - lbchars = NULL; - } else { - if (lbchars == NULL) { - lbchars = pestrdup("\r\n", 0); - lbchars_len = 2; - } - } - opts |= (opt_binary ? PHP_CONV_QPRINT_OPT_BINARY : 0); - opts |= (opt_force_encode_first ? PHP_CONV_QPRINT_OPT_FORCE_ENCODE_FIRST : 0); - } - retval = pemalloc(sizeof(php_conv_qprint_encode), persistent); - if (lbchars != NULL) { - if (php_conv_qprint_encode_ctor((php_conv_qprint_encode *)retval, line_len, lbchars, lbchars_len, 1, opts, persistent)) { - pefree(lbchars, 0); - goto out_failure; - } - pefree(lbchars, 0); - } else { - if (php_conv_qprint_encode_ctor((php_conv_qprint_encode *)retval, 0, NULL, 0, 0, opts, persistent)) { - goto out_failure; - } - } - } break; - - case PHP_CONV_QPRINT_DECODE: { - char *lbchars = NULL; - size_t lbchars_len; - - if (options != NULL) { - GET_STR_PROP(options, lbchars, lbchars_len, "line-break-chars", 0); - if (lbchars == NULL) { - lbchars = pestrdup("\r\n", 0); - lbchars_len = 2; - } - } - retval = pemalloc(sizeof(php_conv_qprint_decode), persistent); - if (lbchars != NULL) { - if (php_conv_qprint_decode_ctor((php_conv_qprint_decode *)retval, lbchars, lbchars_len, 1, persistent)) { - pefree(lbchars, 0); - goto out_failure; - } - pefree(lbchars, 0); - } else { - if (php_conv_qprint_decode_ctor((php_conv_qprint_decode *)retval, NULL, 0, 0, persistent)) { - goto out_failure; - } - } - } break; - - default: - retval = NULL; - break; - } - return retval; - -out_failure: - if (retval != NULL) { - pefree(retval, persistent); - } - return NULL; -} - -#undef GET_STR_PROP -#undef GET_INT_PROP -#undef GET_UINT_PROP -#undef GET_BOOL_PROP - -static int php_convert_filter_ctor(php_convert_filter *inst, - int conv_mode, HashTable *conv_opts, - const char *filtername, int persistent) -{ - inst->persistent = persistent; - inst->filtername = pestrdup(filtername, persistent); - - if ((inst->cd = php_conv_open(conv_mode, conv_opts, persistent)) == NULL) { - goto out_failure; - } - - return SUCCESS; - -out_failure: - if (inst->cd != NULL) { - php_conv_dtor(inst->cd); - pefree(inst->cd, persistent); - } - if (inst->filtername != NULL) { - pefree(inst->filtername, persistent); - } - return FAILURE; -} - -static void php_convert_filter_dtor(php_convert_filter *inst) -{ - if (inst->cd != NULL) { - php_conv_dtor(inst->cd); - pefree(inst->cd, inst->persistent); - } - - if (inst->filtername != NULL) { - pefree(inst->filtername, inst->persistent); - } -} - -static php_stream_filter_status_t strfilter_convert_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - php_stream_bucket *bucket = NULL, *new_bucket; - size_t consumed = 0; - php_conv_err_t err; - php_convert_filter *inst = (php_convert_filter *)thisfilter->abstract; - char *out_buf = NULL; - size_t out_buf_size; - char *pd; - size_t ocnt; - - if (buckets_in->head == NULL && buckets_in->tail == NULL) { - /* flush operation */ - - out_buf_size = 64; - out_buf = pemalloc(out_buf_size, inst->persistent); - ocnt = out_buf_size; - pd = out_buf; - - /* trying hard to reduce the number of buckets to hand to the - * next filter */ - - for (;;) { - err = php_conv_convert(inst->cd, NULL, NULL, &pd, &ocnt); - - switch (err) { - case PHP_CONV_ERR_UNKNOWN: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): unknown error", inst->filtername, err); - goto out_failure; - - case PHP_CONV_ERR_INVALID_SEQ: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): invalid base64 sequence", inst->filtername, err); - goto out_failure; - - case PHP_CONV_ERR_UNEXPECTED_EOS: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): unexpected end of stream", inst->filtername, err); - goto out_failure; - - default: - break; - } - - if (err != PHP_CONV_ERR_TOO_BIG) { - break; - } else { - char *new_out_buf; - size_t new_out_buf_size; - - new_out_buf_size = out_buf_size << 1; - - if (new_out_buf_size < out_buf_size) { - /* whoa! no bigger buckets are sold anywhere... */ - new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, inst->persistent TSRMLS_CC); - - php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC); - - out_buf_size = bucket->buflen; - out_buf = pemalloc(out_buf_size, inst->persistent); - ocnt = out_buf_size; - pd = out_buf; - } else { - new_out_buf = perealloc(out_buf, new_out_buf_size, inst->persistent); - pd = new_out_buf + (pd - out_buf); - ocnt += (new_out_buf_size - out_buf_size); - out_buf = new_out_buf; - out_buf_size = new_out_buf_size; - } - } - } - /* give output bucket to next in chain */ - if (out_buf_size - ocnt > 0) { - new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, inst->persistent TSRMLS_CC); - php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC); - } - } else { - while (buckets_in->head != NULL) { - const char *ps; - size_t icnt; - - bucket = buckets_in->head; - - php_stream_bucket_unlink(bucket TSRMLS_CC); - icnt = bucket->buflen; - ps = bucket->buf; - - out_buf_size = bucket->buflen; - out_buf = pemalloc(out_buf_size, inst->persistent); - ocnt = out_buf_size; - pd = out_buf; - - /* trying hard to reduce the number of buckets to hand to the - * next filter */ - - while (icnt > 0) { - err = php_conv_convert(inst->cd, &ps, &icnt, &pd, &ocnt); - - switch (err) { - case PHP_CONV_ERR_UNKNOWN: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): unknown error", inst->filtername, err); - goto out_failure; - - case PHP_CONV_ERR_INVALID_SEQ: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): invalid base64 sequence", inst->filtername, err); - goto out_failure; - - case PHP_CONV_ERR_UNEXPECTED_EOS: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): unexpected end of stream", inst->filtername, err); - goto out_failure; - - default: - break; - } - - if (err == PHP_CONV_ERR_TOO_BIG) { - char *new_out_buf; - size_t new_out_buf_size; - - new_out_buf_size = out_buf_size << 1; - - if (new_out_buf_size < out_buf_size) { - /* whoa! no bigger buckets are sold anywhere... */ - new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, inst->persistent TSRMLS_CC); - - php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC); - - out_buf_size = bucket->buflen; - out_buf = pemalloc(out_buf_size, inst->persistent); - ocnt = out_buf_size; - pd = out_buf; - } else { - new_out_buf = perealloc(out_buf, new_out_buf_size, inst->persistent); - pd = new_out_buf + (pd - out_buf); - ocnt += (new_out_buf_size - out_buf_size); - out_buf = new_out_buf; - out_buf_size = new_out_buf_size; - } - } - } - - /* update consumed by the number of bytes just used */ - consumed = bucket->buflen - icnt; - - /* give output bucket to next in chain */ - if (out_buf_size - ocnt > 0) { - new_bucket = php_stream_bucket_new(stream, out_buf, (out_buf_size - ocnt), 1, inst->persistent TSRMLS_CC); - php_stream_bucket_append(buckets_out, new_bucket TSRMLS_CC); - } - - php_stream_bucket_delref(bucket TSRMLS_CC); - } - } - - if (bytes_consumed) { - *bytes_consumed = consumed; - } - - return PSFS_PASS_ON; - -out_failure: - if (out_buf != NULL) { - pefree(out_buf, inst->persistent); - } - if (bucket != NULL) { - php_stream_bucket_delref(bucket TSRMLS_CC); - } - return PSFS_ERR_FATAL; -} - -static void strfilter_convert_dtor(php_stream_filter *thisfilter TSRMLS_DC) -{ - assert(thisfilter->abstract != NULL); - - php_convert_filter_dtor((php_convert_filter *)thisfilter->abstract); - pefree(thisfilter->abstract, ((php_convert_filter *)thisfilter->abstract)->persistent); -} - -static php_stream_filter_ops strfilter_convert_ops = { - strfilter_convert_filter, - strfilter_convert_dtor, - "convert.*" -}; - -static zval *strfilter_convert_parse_parameters(const char *param_str) -{ - zval *retval, *node; - const unsigned char *p; - char *node_name; - char *value; - size_t node_name_len, value_len; - int scan_stat; - char *buf; - size_t buf_size; - - static int scancode_tbl[256] = { - -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 3, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 - }; - - - MAKE_STD_ZVAL(retval); - array_init(retval); - - node = retval; - node_name = NULL; - node_name_len = 0; - value = NULL; - buf = NULL; - buf_size = 0; - - scan_stat = 0; - p = (const unsigned char *)param_str; - for (;;) { - int m = scancode_tbl[(unsigned int)*p]; - switch (m) { - case 2: /* '=' */ - switch (scan_stat) { - case 2: - node_name_len = (size_t)((char *)p - node_name); - scan_stat = 3; - break; - - case 3: - goto out_failure; - } - break; - - case 5: /* ',' */ - case -1: /* EOS */ - if (value == NULL) { - value = empty_string; - value_len = 0; - } else { - value_len = (size_t)((char *)p - value); - } - if (node_name != NULL) { - zval *new_val; - - if (buf_size <= node_name_len) { - char *new_buf; - - buf_size = node_name_len + 1; - new_buf = erealloc(buf, buf_size); - assert(new_buf != NULL); - buf = new_buf; - } - memcpy(buf, node_name, node_name_len); - buf[node_name_len] = '\0'; - - MAKE_STD_ZVAL(new_val); - ZVAL_STRINGL(new_val, value, (int)value_len, 1); - zend_hash_update(Z_ARRVAL_P(node), buf, node_name_len + 1, &new_val, sizeof(zval *), NULL); - node_name = NULL; - } - value = NULL; - node = retval; - scan_stat = 0; - if (m == -1) { - goto end_scan; - } - break; - - case 3: /* '.' */ - switch (scan_stat) { - case 0: case 1: - node_name = (char *)p; - case 2: { - zval **z_tmp; - - node_name_len = (size_t)((char *)p - node_name); - - if (buf_size <= node_name_len) { - char *new_buf; - - buf_size = node_name_len + 1; - new_buf = erealloc(buf, buf_size); - assert(new_buf != NULL); - buf = new_buf; - } - memcpy(buf, node_name, node_name_len); - buf[node_name_len] = '\0'; - - if (zend_hash_find(Z_ARRVAL_P(node), buf, node_name_len + 1, (void **)&z_tmp) != SUCCESS || Z_TYPE_PP(z_tmp) != IS_ARRAY) { - zval *new_node; - - MAKE_STD_ZVAL(new_node); - array_init(new_node); - zend_hash_update(Z_ARRVAL_P(node), buf, node_name_len + 1, &new_node, sizeof(zval *), NULL); - node = new_node; - } else { - node = *z_tmp; - } - scan_stat = 1; - } break; - - case 3: - value = (char *)p; - scan_stat = 4; - case 4: - break; - } - break; - - case 4: /* ' ' */ - switch (scan_stat) { - default: - goto out_failure; - - case 0: - scan_stat = 1; - break; - - case 1: - break; - - case 3: - value = (char *)p; - scan_stat = 4; - case 4: - break; - } - break; - - case 1: - switch (scan_stat) { - case 0: case 1: - node_name = (char *)p; - scan_stat = 2; - break; - - case 3: - value = (char *)p; - scan_stat = 4; - break; - } - break; - } - p++; - } -end_scan: - if (buf != NULL) { - efree(buf); - } - return retval; - -out_failure: - if (buf != NULL) { - efree(buf); - } - zval_dtor(retval); - FREE_ZVAL(retval); - return NULL; -} - -static php_stream_filter *strfilter_convert_create(const char *filtername, const char *filterparams, - int filterparamslen, int persistent TSRMLS_DC) -{ - php_convert_filter *inst; - php_stream_filter *retval = NULL; - char *dot; - zval *options = NULL; - int conv_mode; - - if ((dot = strchr(filtername, '.')) == NULL) { - return NULL; - } - ++dot; - - inst = pemalloc(sizeof(php_convert_filter), persistent); - - if (filterparams != NULL) { - options = strfilter_convert_parse_parameters(filterparams); - if (options == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "stream filter (%s): invalid filter parameter \"%s\"", filtername, filterparams); - } - } - - if (strcasecmp(dot, "base64-encode") == 0) { - conv_mode = PHP_CONV_BASE64_ENCODE; - } else if (strcasecmp(dot, "base64-decode") == 0) { - conv_mode = PHP_CONV_BASE64_DECODE; - } else if (strcasecmp(dot, "quoted-printable-encode") == 0) { - conv_mode = PHP_CONV_QPRINT_ENCODE; - } else if (strcasecmp(dot, "quoted-printable-decode") == 0) { - conv_mode = PHP_CONV_QPRINT_DECODE; - } - - if (php_convert_filter_ctor(inst, conv_mode, - (options != NULL ? Z_ARRVAL_P(options) : NULL), - filtername, persistent) != SUCCESS) { - goto out; - } - - retval = php_stream_filter_alloc(&strfilter_convert_ops, inst, persistent); -out: - if (retval == NULL) { - pefree(inst, persistent); - } - - if (options != NULL) { - zval_ptr_dtor(&options); - } - return retval; -} - -static php_stream_filter_factory strfilter_convert_factory = { - strfilter_convert_create -}; -/* }}} */ - -static const struct { - php_stream_filter_ops *ops; - php_stream_filter_factory *factory; -} standard_filters[] = { - { &strfilter_rot13_ops, &strfilter_rot13_factory }, - { &strfilter_toupper_ops, &strfilter_toupper_factory }, - { &strfilter_tolower_ops, &strfilter_tolower_factory }, - { &strfilter_strip_tags_ops, &strfilter_strip_tags_factory }, - { &strfilter_convert_ops, &strfilter_convert_factory }, - /* additional filters to go here */ - { NULL, NULL } -}; - -/* {{{ filter MINIT and MSHUTDOWN */ -PHP_MINIT_FUNCTION(standard_filters) -{ - int i; - - for (i = 0; standard_filters[i].ops; i++) { - if (FAILURE == php_stream_filter_register_factory( - standard_filters[i].ops->label, - standard_filters[i].factory - TSRMLS_CC)) { - return FAILURE; - } - } - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(standard_filters) -{ - int i; - - for (i = 0; standard_filters[i].ops; i++) { - php_stream_filter_unregister_factory(standard_filters[i].ops->label TSRMLS_CC); - } - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c deleted file mode 100644 index 776926e2f4..0000000000 --- a/ext/standard/flock_compat.c +++ /dev/null @@ -1,238 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include <errno.h> -#include "ext/standard/flock_compat.h" - -#if HAVE_STRUCT_FLOCK -#include <unistd.h> -#include <fcntl.h> -#include <sys/file.h> -#endif - -#ifdef PHP_WIN32 -#include <io.h> -#endif - -#ifdef NETWARE -#ifdef NEW_LIBC -#include <netinet/in.h> -#else -#include <sys/socket.h> -#endif -#endif - -#ifndef HAVE_FLOCK -PHPAPI int flock(int fd, int operation) -{ - return php_flock(fd, operation); -} -#endif /* !defined(HAVE_FLOCK) */ - -PHPAPI int php_flock(int fd, int operation) -#if HAVE_STRUCT_FLOCK -{ - struct flock flck; - int ret; - - flck.l_start = flck.l_len = 0; - flck.l_whence = SEEK_SET; - - if (operation & LOCK_SH) - flck.l_type = F_RDLCK; - else if (operation & LOCK_EX) - flck.l_type = F_WRLCK; - else if (operation & LOCK_UN) - flck.l_type = F_UNLCK; - else { - errno = EINVAL; - return -1; - } - - ret = fcntl(fd, operation & LOCK_NB ? F_SETLK : F_SETLKW, &flck); - - if (operation & LOCK_NB && ret == -1 && - (errno == EACCES || errno == EAGAIN)) - errno = EWOULDBLOCK; - - if (ret != -1) ret = 0; - - return ret; -} -#elif defined(PHP_WIN32) -/* - * Program: Unix compatibility routines - * - * Author: Mark Crispin - * Networks and Distributed Computing - * Computing & Communications - * University of Washington - * Administration Building, AG-44 - * Seattle, WA 98195 - * Internet: MRC@CAC.Washington.EDU - * - * Date: 14 September 1996 - * Last Edited: 14 August 1997 - * - * Copyright 1997 by the University of Washington - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appears in all copies and that both the - * above copyright notice and this permission notice appear in supporting - * documentation, and that the name of the University of Washington not be - * used in advertising or publicity pertaining to distribution of the software - * without specific, written prior permission. This software is made available - * "as is", and - * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, - * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN - * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT - * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -/* DEDICATION - - * This file is dedicated to my dog, Unix, also known as Yun-chan and - * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix - * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after - * a two-month bout with cirrhosis of the liver. - * - * He was a dear friend, and I miss him terribly. - * - * Lift a leg, Yunie. Luv ya forever!!!! - */ -{ - HANDLE hdl = (HANDLE) _get_osfhandle(fd); - DWORD low = 1, high = 0; - OVERLAPPED offset = - {0, 0, 0, 0, NULL}; - if (hdl < 0) - return -1; /* error in file descriptor */ - /* bug for bug compatible with Unix */ - UnlockFileEx(hdl, 0, low, high, &offset); - switch (operation & ~LOCK_NB) { /* translate to LockFileEx() op */ - case LOCK_EX: /* exclusive */ - if (LockFileEx(hdl, LOCKFILE_EXCLUSIVE_LOCK + - ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0), - 0, low, high, &offset)) - return 0; - break; - case LOCK_SH: /* shared */ - if (LockFileEx(hdl, ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0), - 0, low, high, &offset)) - return 0; - break; - case LOCK_UN: /* unlock */ - return 0; /* always succeeds */ - default: /* default */ - break; - } - /* Under Win32 MT library, errno is not a variable but a function call, - * which cannot be assigned to. - */ -#if !defined(PHP_WIN32) - errno = EINVAL; /* bad call */ -#endif - return -1; -} -#else -#warning no proper flock support for your site -{ - errno = 0; - return 0; -} -#endif - -#if !(HAVE_INET_ATON) -/* {{{ inet_aton - * Check whether "cp" is a valid ascii representation - * of an Internet address and convert to a binary address. - * Returns 1 if the address is valid, 0 if not. - * This replaces inet_addr, the return value from which - * cannot distinguish between failure and a local broadcast address. - */ -int inet_aton(const char *cp, struct in_addr *ap) -{ - int dots = 0; - register unsigned long acc = 0, addr = 0; - - do { - register char cc = *cp; - - switch (cc) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - acc = acc * 10 + (cc - '0'); - break; - - case '.': - if (++dots > 3) { - return 0; - } - /* Fall through */ - - case '\0': - if (acc > 255) { - return 0; - } - addr = addr << 8 | acc; - acc = 0; - break; - - default: - return 0; - } - } while (*cp++) ; - - /* Normalize the address */ - if (dots < 3) { - addr <<= 8 * (3 - dots) ; - } - - /* Store it if requested */ - if (ap) { - ap->s_addr = htonl(addr); - } - - return 1; -} -/* }}} */ -#endif /* !HAVE_INET_ATON */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/flock_compat.h b/ext/standard/flock_compat.h deleted file mode 100644 index 4088036e5b..0000000000 --- a/ext/standard/flock_compat.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef FLOCK_COMPAT_H -#define FLOCK_COMPAT_H - -/* php_flock internally uses fcntl whther or not flock is available - * This way our php_flock even works on NFS files. - * More info: /usr/src/linux/Documentation - */ -PHPAPI int php_flock(int fd, int operation); - -#ifndef HAVE_FLOCK -# define LOCK_SH 1 -# define LOCK_EX 2 -# define LOCK_NB 4 -# define LOCK_UN 8 -PHPAPI int flock(int fd, int operation); -#endif - -#ifdef PHP_WIN32 -#define EWOULDBLOCK WSAEWOULDBLOCK -# define fsync _commit -# define ftruncate(a, b) chsize(a, b) -#endif /* defined(PHP_WIN32) */ - -#if !HAVE_INET_ATON -#if HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif - -extern int inet_aton(const char *, struct in_addr *); -#endif - -#endif /* FLOCK_COMPAT_H */ diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c deleted file mode 100644 index 67915bed65..0000000000 --- a/ext/standard/formatted_print.c +++ /dev/null @@ -1,847 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <math.h> /* modf() */ -#include "php.h" -#include "ext/standard/head.h" -#include "php_string.h" -#include "zend_execute.h" -#include <stdio.h> - -#ifdef HAVE_LOCALE_H -#include <locale.h> -#endif - -#define ALIGN_LEFT 0 -#define ALIGN_RIGHT 1 -#define ADJ_WIDTH 1 -#define ADJ_PRECISION 2 -#define NUM_BUF_SIZE 500 -#define NDIG 80 -#define FLOAT_DIGITS 6 -#define FLOAT_PRECISION 6 -#define MAX_FLOAT_DIGITS 38 -#define MAX_FLOAT_PRECISION 40 - -#if 0 -/* trick to control varargs functions through cpp */ -# define PRINTF_DEBUG(arg) php_printf arg -#else -# define PRINTF_DEBUG(arg) -#endif - -static char hexchars[] = "0123456789abcdef"; -static char HEXCHARS[] = "0123456789ABCDEF"; - - -/* - * cvt.c - IEEE floating point formatting routines for FreeBSD - * from GNU libc-4.6.27 - */ - -/* - * php_convert_to_decimal converts to decimal - * the number of digits is specified by ndigit - * decpt is set to the position of the decimal point - * sign is set to 0 for positive, 1 for negative - */ -static char *php_convert_to_decimal(double arg, int ndigits, int *decpt, int *sign, int eflag) -{ - register int r2; - double fi, fj; - register char *p, *p1; - /*THREADX*/ -#ifndef THREAD_SAFE - static char cvt_buf[NDIG]; -#endif - - if (ndigits >= NDIG - 1) - ndigits = NDIG - 2; - r2 = 0; - *sign = 0; - p = &cvt_buf[0]; - if (arg < 0) { - *sign = 1; - arg = -arg; - } - arg = modf(arg, &fi); - p1 = &cvt_buf[NDIG]; - /* - * Do integer part - */ - if (fi != 0) { - p1 = &cvt_buf[NDIG]; - while (fi != 0) { - fj = modf(fi / 10, &fi); - *--p1 = (int) ((fj + .03) * 10) + '0'; - r2++; - } - while (p1 < &cvt_buf[NDIG]) - *p++ = *p1++; - } else if (arg > 0) { - while ((fj = arg * 10.0) < 0.9999999) { - arg = fj; - r2--; - } - } - p1 = &cvt_buf[ndigits]; - if (eflag == 0) - p1 += r2; - *decpt = r2; - if (p1 < &cvt_buf[0]) { - cvt_buf[0] = '\0'; - return (cvt_buf); - } - while (p <= p1 && p < &cvt_buf[NDIG]) { - arg *= 10; - arg = modf(arg, &fj); - *p++ = (int) fj + '0'; - } - if (p1 >= &cvt_buf[NDIG]) { - cvt_buf[NDIG - 1] = '\0'; - return (cvt_buf); - } - p = p1; - *p1 += 5; - while (*p1 > '9') { - *p1 = '0'; - if (p1 > cvt_buf) - ++ * --p1; - else { - *p1 = '1'; - (*decpt)++; - if (eflag == 0) { - if (p > cvt_buf) - *p = '0'; - p++; - } - } - } - *p = '\0'; - return (cvt_buf); -} - - -inline static void -php_sprintf_appendchar(char **buffer, int *pos, int *size, char add TSRMLS_DC) -{ - if ((*pos + 1) >= *size) { - *size <<= 1; - PRINTF_DEBUG(("%s(): ereallocing buffer to %d bytes\n", get_active_function_name(TSRMLS_C), *size)); - *buffer = erealloc(*buffer, *size); - } - PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos)); - (*buffer)[(*pos)++] = add; -} - - -inline static void -php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add, - int min_width, int max_width, char padding, - int alignment, int len, int sign, int expprec) -{ - register int npad; - int req_size; - int copy_len; - - copy_len = (expprec ? MIN(max_width, len) : len); - npad = min_width - copy_len; - - if (npad < 0) { - npad = 0; - } - - PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n", - *buffer, *pos, *size, add, min_width, padding, alignment)); - - req_size = *pos + MAX(min_width, copy_len) + 1; - - if (req_size > *size) { - while (req_size > *size) { - *size <<= 1; - } - PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size)); - *buffer = erealloc(*buffer, *size); - } - if (alignment == ALIGN_RIGHT) { - if (sign && padding=='0') { - (*buffer)[(*pos)++] = '-'; - add++; - len--; - } - while (npad-- > 0) { - (*buffer)[(*pos)++] = padding; - } - } - PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add)); - memcpy(&(*buffer)[*pos], add, copy_len + 1); - *pos += copy_len; - if (alignment == ALIGN_LEFT) { - while (npad--) { - (*buffer)[(*pos)++] = padding; - } - } -} - - -inline static void -php_sprintf_appendint(char **buffer, int *pos, int *size, long number, - int width, char padding, int alignment, - int always_sign) -{ - char numbuf[NUM_BUF_SIZE]; - register unsigned long magn, nmagn; - register unsigned int i = NUM_BUF_SIZE - 1, neg = 0; - - PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n", - *buffer, pos, size, number, width, padding, alignment)); - if (number < 0) { - neg = 1; - magn = ((unsigned long) -(number + 1)) + 1; - } else { - magn = (unsigned long) number; - } - - /* Can't right-pad 0's on integers */ - if(alignment==0 && padding=='0') padding=' '; - - numbuf[i] = '\0'; - - do { - nmagn = magn / 10; - - numbuf[--i] = (unsigned char)(magn - (nmagn * 10)) + '0'; - magn = nmagn; - } - while (magn > 0 && i > 0); - if (neg) { - numbuf[--i] = '-'; - } else if (always_sign) { - numbuf[--i] = '+'; - } - PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", - number, &numbuf[i], i)); - php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, - padding, alignment, (NUM_BUF_SIZE - 1) - i, - neg, 0); -} - -inline static void -php_sprintf_appenduint(char **buffer, int *pos, int *size, - unsigned long number, - int width, char padding, int alignment, int always_sign) -{ - char numbuf[NUM_BUF_SIZE]; - register unsigned long magn, nmagn; - register unsigned int i = NUM_BUF_SIZE - 1; - - PRINTF_DEBUG(("sprintf: appenduint(%x, %x, %x, %d, %d, '%c', %d)\n", - *buffer, pos, size, number, width, padding, alignment)); - magn = (unsigned int) number; - - /* Can't right-pad 0's on integers */ - if (alignment == 0 && padding == '0') padding = ' '; - - numbuf[i] = '\0'; - - do { - nmagn = magn / 10; - - numbuf[--i] = (unsigned char)(magn - (nmagn * 10)) + '0'; - magn = nmagn; - } while (magn > 0 && i > 0); - - if (always_sign) - numbuf[--i] = '+'; - PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", number, &numbuf[i], i)); - php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, - padding, alignment, (NUM_BUF_SIZE - 1) - i, 0, 0); -} - -inline static void -php_sprintf_appenddouble(char **buffer, int *pos, - int *size, double number, - int width, char padding, - int alignment, int precision, - int adjust, char fmt, - int always_sign - TSRMLS_DC) -{ - char numbuf[NUM_BUF_SIZE]; - char *cvt; - register int i = 0, j = 0; - int sign, decpt; - char decimal_point = EG(float_separator)[0]; - - PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n", - *buffer, pos, size, number, width, padding, alignment, fmt)); - if ((adjust & ADJ_PRECISION) == 0) { - precision = FLOAT_PRECISION; - } else if (precision > MAX_FLOAT_PRECISION) { - precision = MAX_FLOAT_PRECISION; - } - - if (zend_isnan(number)) { - sign = (number<0); - php_sprintf_appendstring(buffer, pos, size, "NaN", 3, 0, padding, - alignment, precision, sign, 0); - return; - } - - if (zend_isinf(number)) { - sign = (number<0); - php_sprintf_appendstring(buffer, pos, size, "INF", 3, 0, padding, - alignment, precision, sign, 0); - return; - } - - cvt = php_convert_to_decimal(number, precision, &decpt, &sign, (fmt == 'e')); - - if (sign) { - numbuf[i++] = '-'; - } else if (always_sign) { - numbuf[i++] = '+'; - } - - if (fmt == 'f') { - if (decpt <= 0) { - numbuf[i++] = '0'; - if (precision > 0) { - int k = precision; - numbuf[i++] = decimal_point; - while ((decpt++ < 0) && k--) { - numbuf[i++] = '0'; - } - } - } else { - while (decpt-- > 0) - numbuf[i++] = cvt[j++]; - if (precision > 0) - numbuf[i++] = decimal_point; - } - } else if (fmt == 'e' || fmt == 'E') { - char *exp_p; - int dec2; - - decpt--; - - numbuf[i++] = cvt[j++]; - numbuf[i++] = decimal_point; - - if (precision > 0) { - int k = precision; - - while (k-- && cvt[j]) { - numbuf[i++] = cvt[j++]; - } - } else { - numbuf[i++] = '0'; - } - - numbuf[i++] = fmt; - exp_p = php_convert_to_decimal(decpt, 0, &dec2, &sign, 0); - numbuf[i++] = sign ? '-' : '+'; - if (*exp_p) { - while (*exp_p) { - numbuf[i++] = *(exp_p++); - } - } else { - numbuf[i++] = '0'; - } - } else { - numbuf[i++] = cvt[j++]; - if (precision > 0) - numbuf[i++] = decimal_point; - } - - while (cvt[j]) { - numbuf[i++] = cvt[j++]; - } - - numbuf[i] = '\0'; - - if (precision > 0) { - width += (precision + 1); - } - php_sprintf_appendstring(buffer, pos, size, numbuf, width, 0, padding, - alignment, i, sign, 0); -} - - -inline static void -php_sprintf_append2n(char **buffer, int *pos, int *size, long number, - int width, char padding, int alignment, int n, - char *chartable, int expprec) -{ - char numbuf[NUM_BUF_SIZE]; - register unsigned long num; - register unsigned int i = NUM_BUF_SIZE - 1; - register int andbits = (1 << n) - 1; - - PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n", - *buffer, pos, size, number, width, padding, alignment, n, - chartable)); - PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits)); - - num = (unsigned long) number; - numbuf[i] = '\0'; - - do { - numbuf[--i] = chartable[(num & andbits)]; - num >>= n; - } - while (num > 0); - - php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, - padding, alignment, (NUM_BUF_SIZE - 1) - i, - 0, expprec); -} - - -inline static long -php_sprintf_getnumber(char *buffer, int *pos) -{ - char *endptr; - register long num = strtol(&buffer[*pos], &endptr, 10); - register int i = 0; - - if (endptr != NULL) { - i = (endptr - &buffer[*pos]); - } - PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i)); - *pos += i; - return num; -} - -/* {{{ php_formatted_print - * New sprintf implementation for PHP. - * - * Modifiers: - * - * " " pad integers with spaces - * "-" left adjusted field - * n field size - * "."n precision (floats only) - * "+" Always place a sign (+ or -) in front of a number - * - * Type specifiers: - * - * "%" literal "%", modifiers are ignored. - * "b" integer argument is printed as binary - * "c" integer argument is printed as a single character - * "d" argument is an integer - * "f" the argument is a float - * "o" integer argument is printed as octal - * "s" argument is a string - * "x" integer argument is printed as lowercase hexadecimal - * "X" integer argument is printed as uppercase hexadecimal - * - */ -static char * -php_formatted_print(int ht, int *len, int use_array, int format_offset TSRMLS_DC) -{ - zval ***args, **z_format; - int argc, size = 240, inpos = 0, outpos = 0, temppos; - int alignment, width, precision, currarg, adjusting, argnum; - char *format, *result, padding; - int always_sign; - - argc = ZEND_NUM_ARGS(); - - /* verify the number of args */ - if ((use_array && argc != (2 + format_offset)) - || (!use_array && argc < (1 + format_offset))) { - WRONG_PARAM_COUNT_WITH_RETVAL(NULL); - } - args = (zval ***)emalloc(argc * sizeof(zval *)); - - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT_WITH_RETVAL(NULL); - } - - if (use_array) { - int i = 1; - zval ***newargs; - zval **array; - - z_format = args[format_offset]; - array = args[1 + format_offset]; - - SEPARATE_ZVAL(array); - convert_to_array_ex(array); - - argc = 1 + zend_hash_num_elements(Z_ARRVAL_PP(array)); - newargs = (zval ***)emalloc(argc * sizeof(zval *)); - newargs[0] = z_format; - - for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array)); - zend_hash_get_current_data(Z_ARRVAL_PP(array), (void **)&newargs[i++]) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_PP(array))); - - efree(args); - args = newargs; - format_offset = 0; - } - - convert_to_string_ex(args[format_offset]); - format = Z_STRVAL_PP(args[format_offset]); - result = emalloc(size); - - currarg = 1; - - while (inpos<Z_STRLEN_PP(args[format_offset])) { - int expprec = 0; - - PRINTF_DEBUG(("sprintf: format[%d]='%c'\n", inpos, format[inpos])); - PRINTF_DEBUG(("sprintf: outpos=%d\n", outpos)); - if (format[inpos] != '%') { - php_sprintf_appendchar(&result, &outpos, &size, format[inpos++] TSRMLS_CC); - } else if (format[inpos + 1] == '%') { - php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC); - inpos += 2; - } else { - if (currarg >= argc && format[inpos + 1] != '%') { - efree(result); - efree(args); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); - return NULL; - } - /* starting a new format specifier, reset variables */ - alignment = ALIGN_RIGHT; - adjusting = 0; - padding = ' '; - always_sign = 0; - inpos++; /* skip the '%' */ - - PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n", - format[inpos], inpos)); - if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) { - /* first look for argnum */ - temppos = inpos; - while (isdigit((int)format[temppos])) temppos++; - if (format[temppos] == '$') { - argnum = php_sprintf_getnumber(format, &inpos); - - if (argnum == 0) { - efree(result); - efree(args); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zero is not a valid argument number"); - return NULL; - } - - inpos++; /* skip the '$' */ - } else { - argnum = currarg++; - } - - argnum += format_offset; - - if (argnum >= argc) { - efree(result); - efree(args); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Too few arguments"); - return NULL; - } - - /* after argnum comes modifiers */ - PRINTF_DEBUG(("sprintf: looking for modifiers\n" - "sprintf: now looking at '%c', inpos=%d\n", - format[inpos], inpos)); - for (;; inpos++) { - if (format[inpos] == ' ' || format[inpos] == '0') { - padding = format[inpos]; - } else if (format[inpos] == '-') { - alignment = ALIGN_LEFT; - /* space padding, the default */ - } else if (format[inpos] == '+') { - always_sign = 1; - } else if (format[inpos] == '\'') { - padding = format[++inpos]; - } else { - PRINTF_DEBUG(("sprintf: end of modifiers\n")); - break; - } - } - PRINTF_DEBUG(("sprintf: padding='%c'\n", padding)); - PRINTF_DEBUG(("sprintf: alignment=%s\n", - (alignment == ALIGN_LEFT) ? "left" : "right")); - - - /* after modifiers comes width */ - if (isdigit((int)format[inpos])) { - PRINTF_DEBUG(("sprintf: getting width\n")); - width = php_sprintf_getnumber(format, &inpos); - adjusting |= ADJ_WIDTH; - } else { - width = 0; - } - PRINTF_DEBUG(("sprintf: width=%d\n", width)); - - /* after width and argnum comes precision */ - if (format[inpos] == '.') { - inpos++; - PRINTF_DEBUG(("sprintf: getting precision\n")); - if (isdigit((int)format[inpos])) { - precision = php_sprintf_getnumber(format, &inpos); - adjusting |= ADJ_PRECISION; - expprec = 1; - } else { - precision = 0; - } - } else { - precision = 0; - } - PRINTF_DEBUG(("sprintf: precision=%d\n", precision)); - } else { - width = precision = 0; - argnum = currarg++ + format_offset; - } - - if (format[inpos] == 'l') { - inpos++; - } - PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos])); - /* now we expect to find a type specifier */ - switch (format[inpos]) { - case 's': - convert_to_string_ex(args[argnum]); - php_sprintf_appendstring(&result, &outpos, &size, - Z_STRVAL_PP(args[argnum]), - width, precision, padding, - alignment, - Z_STRLEN_PP(args[argnum]), - 0, expprec); - break; - - case 'd': - convert_to_long_ex(args[argnum]); - php_sprintf_appendint(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, - always_sign); - break; - - case 'u': - convert_to_long_ex(args[argnum]); - php_sprintf_appenduint(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, - always_sign); - break; - - case 'e': - case 'f': - /* XXX not done */ - convert_to_double_ex(args[argnum]); - php_sprintf_appenddouble(&result, &outpos, &size, - Z_DVAL_PP(args[argnum]), - width, padding, alignment, - precision, adjusting, - format[inpos], always_sign - TSRMLS_CC); - break; - - case 'c': - convert_to_long_ex(args[argnum]); - php_sprintf_appendchar(&result, &outpos, &size, - (char) Z_LVAL_PP(args[argnum]) TSRMLS_CC); - break; - - case 'o': - convert_to_long_ex(args[argnum]); - php_sprintf_append2n(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, 3, - hexchars, expprec); - break; - - case 'x': - convert_to_long_ex(args[argnum]); - php_sprintf_append2n(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, 4, - hexchars, expprec); - break; - - case 'X': - convert_to_long_ex(args[argnum]); - php_sprintf_append2n(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, 4, - HEXCHARS, expprec); - break; - - case 'b': - convert_to_long_ex(args[argnum]); - php_sprintf_append2n(&result, &outpos, &size, - Z_LVAL_PP(args[argnum]), - width, padding, alignment, 1, - hexchars, expprec); - break; - - case '%': - php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC); - - break; - default: - break; - } - inpos++; - } - } - - efree(args); - - /* possibly, we have to make sure we have room for the terminating null? */ - result[outpos]=0; - *len = outpos; - return result; -} -/* }}} */ - -/* {{{ proto string sprintf(string format [, mixed arg1 [, mixed ...]]) - Return a formatted string */ -PHP_FUNCTION(user_sprintf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht, &len, 0, 0 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - RETVAL_STRINGL(result, len, 0); -} -/* }}} */ - -/* {{{ proto string vsprintf(string format, array args) - Return a formatted string */ -PHP_FUNCTION(vsprintf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht, &len, 1, 0 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - RETVAL_STRINGL(result, len, 0); -} -/* }}} */ - -/* {{{ proto int printf(string format [, mixed arg1 [, mixed ...]]) - Output a formatted string */ -PHP_FUNCTION(user_printf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht, &len, 0, 0 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - PHPWRITE(result, len); - efree(result); -} -/* }}} */ - -/* {{{ proto int vprintf(string format, array args) - Output a formatted string */ -PHP_FUNCTION(vprintf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht, &len, 1, 0 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - PHPWRITE(result, len); - efree(result); -} -/* }}} */ - -/* {{{ proto int fprintf(resource stream, string format [, mixed arg1 [, mixed ...]]) - Output a formatted string into a stream */ -PHP_FUNCTION(fprintf) -{ - php_stream *stream; - zval **arg1; - char *result; - int len; - - if (ZEND_NUM_ARGS() < 2) { - WRONG_PARAM_COUNT; - } - - if (zend_get_parameters_ex(1, &arg1)==FAILURE) { - RETURN_FALSE; - } - - php_stream_from_zval(stream, arg1); - - if ((result=php_formatted_print(ht, &len, 0, 1 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - - php_stream_write(stream, result, len); - - efree(result); - - RETVAL_LONG(len - 1); -} - -/* {{{ proto int vfprintf(resource stream, string format, array args) - Output a formatted string into a stream */ -PHP_FUNCTION(vfprintf) -{ - php_stream *stream; - zval **arg1; - char *result; - int len; - - if (ZEND_NUM_ARGS() != 3) { - WRONG_PARAM_COUNT; - } - - if (zend_get_parameters_ex(1, &arg1)==FAILURE) { - RETURN_FALSE; - } - - php_stream_from_zval(stream, arg1); - - if ((result=php_formatted_print(ht, &len, 1, 1 TSRMLS_CC))==NULL) { - RETURN_FALSE; - } - - php_stream_write(stream, result, len); - - efree(result); - - RETVAL_LONG(len - 1); -} - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c deleted file mode 100644 index 8f41cf4d3f..0000000000 --- a/ext/standard/fsock.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - | Jim Winstead <jimw@php.net> | - | Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include <stdlib.h> -#include <stddef.h> -#include "php_network.h" -#include "file.h" - -/* {{{ php_fsockopen() */ - -static void php_fsockopen_stream(INTERNAL_FUNCTION_PARAMETERS, int persistent) -{ - char *host; - long host_len; - int port = -1; - zval *zerrno = NULL, *zerrstr = NULL; - double timeout = FG(default_socket_timeout); - unsigned long conv; - struct timeval tv; - char *hashkey = NULL; - php_stream *stream = NULL; - int err; - char *hostname = NULL; - long hostname_len; - char *errstr = NULL; - - RETVAL_FALSE; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lzzd", &host, &host_len, &port, &zerrno, &zerrstr, &timeout) == FAILURE) { - RETURN_FALSE; - } - - if (persistent) { - spprintf(&hashkey, 0, "pfsockopen__%s:%d", host, port); - } - - if (port > 0) { - hostname_len = spprintf(&hostname, 0, "%s:%d", host, port); - } else { - hostname_len = host_len; - hostname = host; - } - - /* prepare the timeout value for use */ - conv = (unsigned long) (timeout * 1000000.0); - tv.tv_sec = conv / 1000000; - tv.tv_usec = conv % 1000000; - - if (zerrno) { - zval_dtor(zerrno); - ZVAL_LONG(zerrno, 0); - } - if (zerrstr) { - zval_dtor(zerrstr); - ZVAL_STRING(zerrstr, "", 1); - } - - stream = php_stream_xport_create(hostname, hostname_len, ENFORCE_SAFE_MODE | REPORT_ERRORS, - STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, hashkey, &tv, NULL, &errstr, &err); - - if (port > 0) { - efree(hostname); - } - if (stream == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s:%d", host, port); - } - - if (hashkey) { - efree(hashkey); - } - - if (stream == NULL) { - if (zerrno) { - zval_dtor(zerrno); - ZVAL_LONG(zerrno, err); - } - if (zerrstr && errstr) { - /* no need to dup; we need to efree buf anyway */ - zval_dtor(zerrstr); - ZVAL_STRING(zerrstr, errstr, 0); - } - RETURN_FALSE; - } - - php_stream_to_zval(stream, return_value); -} - -/* }}} */ - -/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]]) - Open Internet or Unix domain socket connection */ -PHP_FUNCTION(fsockopen) -{ - php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ -/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]]) - Open persistent Internet or Unix domain socket connection */ -PHP_FUNCTION(pfsockopen) -{ - php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h deleted file mode 100644 index 7d263c31e1..0000000000 --- a/ext/standard/fsock.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - | Jim Winstead <jimw@php.net> | - | Wez Furlong | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */ - -#ifndef FSOCK_H -#define FSOCK_H - -#ifdef NETWARE -#ifdef NEW_LIBC -#include "sys/timeval.h" -#else -#include "netware/time_nw.h" /* For 'timeval' */ -#endif -#endif - -#include "file.h" - -#include "php_network.h" - -PHP_FUNCTION(fsockopen); -PHP_FUNCTION(pfsockopen); - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim: sw=4 ts=4 - */ -#endif /* FSOCK_H */ diff --git a/ext/standard/ftok.c b/ext/standard/ftok.c deleted file mode 100644 index 111c51b0a2..0000000000 --- a/ext/standard/ftok.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Andrew Sitnikov <sitnikov@infonet.ee> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" - -#include <sys/types.h> - -#ifdef HAVE_SYS_IPC_H -#include <sys/ipc.h> -#endif - -#if HAVE_FTOK -/* {{{ proto int ftok(string pathname, string proj) - Convert a pathname and a project identifier to a System V IPC key */ -PHP_FUNCTION(ftok) -{ - pval **pathname, **proj; - - key_t k; - - if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &pathname, &proj) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(pathname); - convert_to_string_ex(proj); - - if (Z_STRLEN_PP(pathname)==0){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "First argument invalid"); - RETURN_LONG(-1); - } - - if (Z_STRLEN_PP(proj)!=1){ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument invalid"); - RETURN_LONG(-1); - } - - k = ftok(Z_STRVAL_PP(pathname),Z_STRVAL_PP(proj)[0]); - - RETURN_LONG(k); -} -/* }}} */ -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c deleted file mode 100644 index 192786058d..0000000000 --- a/ext/standard/ftp_fopen_wrapper.c +++ /dev/null @@ -1,468 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - | Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_network.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#ifdef PHP_WIN32 -#include <winsock2.h> -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#elif defined(NETWARE) -/*#include <ws2nlm.h>*/ -/*#include <sys/socket.h>*/ -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#else -#include <sys/param.h> -#endif - -#include "php_standard.h" - -#include <sys/types.h> -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifdef PHP_WIN32 -#include <winsock2.h> -#elif defined(NETWARE) && defined(USE_WINSOCK) -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif - -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -#undef AF_UNIX -#endif - -#if defined(AF_UNIX) -#include <sys/un.h> -#endif - -#include "php_fopen_wrappers.h" - - -static inline int get_ftp_result(php_stream *stream, char *buffer, size_t buffer_size TSRMLS_DC) -{ - while (php_stream_gets(stream, buffer, buffer_size-1) && - !(isdigit((int) buffer[0]) && isdigit((int) buffer[1]) && - isdigit((int) buffer[2]) && buffer[3] == ' ')); - return strtol(buffer, NULL, 10); -} -#define GET_FTP_RESULT(stream) get_ftp_result((stream), tmp_line, sizeof(tmp_line) TSRMLS_CC) - -#define FTPS_ENCRYPT_DATA 1 - -static int php_stream_ftp_stream_stat(php_stream_wrapper *wrapper, - php_stream *stream, - php_stream_statbuf *ssb - TSRMLS_DC) -{ - /* For now, we return with a failure code to prevent the underlying - * file's details from being used instead. */ - return -1; -} - - -static int php_stream_ftp_stream_close(php_stream_wrapper *wrapper, - php_stream *stream - TSRMLS_DC) -{ - php_stream *controlstream = (php_stream *)stream->wrapperdata; - - if (controlstream) { - php_stream_write_string(controlstream, "QUIT\r\n"); - php_stream_close(controlstream); - stream->wrapperdata = NULL; - } - return 0; -} - - -static php_stream_wrapper_ops ftp_stream_wops = { - php_stream_url_wrap_ftp, - php_stream_ftp_stream_close, /* stream_close */ - php_stream_ftp_stream_stat, - NULL, /* stat_url */ - NULL, /* opendir */ - "FTP" -}; - -php_stream_wrapper php_stream_ftp_wrapper = { - &ftp_stream_wops, - NULL, - 1 /* is_url */ -}; - - -/* {{{ php_fopen_url_wrap_ftp - */ -php_stream * php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream=NULL, *datastream=NULL; - php_url *resource=NULL; - char tmp_line[512]; - char ip[sizeof("123.123.123.123")]; - unsigned short portno; - char *scratch; - int result; - int i, use_ssl; - int use_ssl_on_data=0; - php_stream *reuseid=NULL; - char *tpath, *ttpath, *hoststart=NULL; - size_t file_size = 0; - - tmp_line[0] = '\0'; - - if (strpbrk(mode, "a+")) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "FTP does not support simultaneous read/write connections."); - return NULL; - } - - resource = php_url_parse((char *) path); - if (resource == NULL || resource->path == NULL) - return NULL; - - use_ssl = resource->scheme && (strlen(resource->scheme) > 3) && resource->scheme[3] == 's'; - - /* use port 21 if one wasn't specified */ - if (resource->port == 0) - resource->port = 21; - - stream = php_stream_sock_open_host(resource->host, resource->port, SOCK_STREAM, NULL, 0); - if (stream == NULL) { - result = 0; /* silence */ - goto errexit; - } - - php_stream_context_set(stream, context); - php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); - - /* Start talking to ftp server */ - result = GET_FTP_RESULT(stream); - if (result > 299 || result < 200) { - php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE, tmp_line, result); - goto errexit; - } - - if (use_ssl) { - - /* send the AUTH TLS request name */ - php_stream_write_string(stream, "AUTH TLS\r\n"); - - /* get the response */ - result = GET_FTP_RESULT(stream); - if (result != 234) { - /* AUTH TLS not supported try AUTH SSL */ - php_stream_write_string(stream, "AUTH SSL\r\n"); - - /* get the response */ - result = GET_FTP_RESULT(stream); - if (result != 334) { - use_ssl = 0; - } else { - /* we must reuse the old SSL session id */ - /* if we talk to an old ftpd-ssl */ - reuseid = stream; - } - } else { - /* encrypt data etc */ - - - } - - } - - if (use_ssl) { - if (php_stream_xport_crypto_setup(stream, - STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 - || php_stream_xport_crypto_enable(stream, 1 TSRMLS_CC) < 0) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); - php_stream_close(stream); - stream = NULL; - goto errexit; - } - - /* set PBSZ to 0 */ - php_stream_write_string(stream, "PBSZ 0\r\n"); - - /* ignore the response */ - result = GET_FTP_RESULT(stream); - - /* set data connection protection level */ -#if FTPS_ENCRYPT_DATA - php_stream_write_string(stream, "PROT P\r\n"); - - /* get the response */ - result = GET_FTP_RESULT(stream); - use_ssl_on_data = (result >= 200 && result<=299) || reuseid; -#else - php_stream_write_string(stream, "PROT C\r\n"); - - /* get the response */ - result = GET_FTP_RESULT(stream); -#endif - } - - /* send the user name */ - php_stream_write_string(stream, "USER "); - if (resource->user != NULL) { - php_raw_url_decode(resource->user, strlen(resource->user)); - php_stream_write_string(stream, resource->user); - } else { - php_stream_write_string(stream, "anonymous"); - } - php_stream_write_string(stream, "\r\n"); - - /* get the response */ - result = GET_FTP_RESULT(stream); - - /* if a password is required, send it */ - if (result >= 300 && result <= 399) { - php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, tmp_line, 0); - - php_stream_write_string(stream, "PASS "); - if (resource->pass != NULL) { - php_raw_url_decode(resource->pass, strlen(resource->pass)); - php_stream_write_string(stream, resource->pass); - } else { - /* if the user has configured who they are, - send that as the password */ - if (cfg_get_string("from", &scratch) == SUCCESS) { - php_stream_write_string(stream, scratch); - } else { - php_stream_write_string(stream, "anonymous"); - } - } - php_stream_write_string(stream, "\r\n"); - - /* read the response */ - result = GET_FTP_RESULT(stream); - - if (result > 299 || result < 200) { - php_stream_notify_error(context, PHP_STREAM_NOTIFY_AUTH_RESULT, tmp_line, result); - } else { - php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_RESULT, tmp_line, result); - } - } - if (result > 299 || result < 200) - goto errexit; - - /* set the connection to be binary */ - php_stream_write_string(stream, "TYPE I\r\n"); - result = GET_FTP_RESULT(stream); - if (result > 299 || result < 200) - goto errexit; - - /* find out the size of the file (verifying it exists) */ - php_stream_write_string(stream, "SIZE "); - php_stream_write_string(stream, resource->path); - php_stream_write_string(stream, "\r\n"); - - /* read the response */ - result = GET_FTP_RESULT(stream); - if (mode[0] == 'r') { - char *sizestr; - - /* when reading file, it must exist */ - if (result > 299 || result < 200) { - errno = ENOENT; - goto errexit; - } - - sizestr = strchr(tmp_line, ' '); - if (sizestr) { - sizestr++; - file_size = atoi(sizestr); - php_stream_notify_file_size(context, file_size, tmp_line, result); - } - } else { - /* when writing file, it must NOT exist */ - if (result <= 299 && result >= 200) { - errno = EEXIST; - goto errexit; - } - } - - /* set up the passive connection */ - - /* We try EPSV first, needed for IPv6 and works on some IPv4 servers */ - php_stream_write_string(stream, "EPSV\r\n"); - result = GET_FTP_RESULT(stream); - - /* check if we got a 229 response */ - if (result != 229) { - /* EPSV failed, let's try PASV */ - php_stream_write_string(stream, "PASV\r\n"); - result = GET_FTP_RESULT(stream); - - /* make sure we got a 227 response */ - if (result != 227) - goto errexit; - - /* parse pasv command (129, 80, 95, 25, 13, 221) */ - tpath = tmp_line; - /* skip over the "227 Some message " part */ - for (tpath += 4; *tpath && !isdigit((int) *tpath); tpath++); - if (!*tpath) - goto errexit; - /* skip over the host ip, to get the port */ - hoststart = tpath; - for (i = 0; i < 4; i++) { - for (; isdigit((int) *tpath); tpath++); - if (*tpath != ',') - goto errexit; - *tpath='.'; - tpath++; - } - tpath[-1] = '\0'; - memcpy(ip, hoststart, sizeof(ip)); - ip[sizeof(ip)-1] = '\0'; - hoststart = ip; - - /* pull out the MSB of the port */ - portno = (unsigned short) strtoul(tpath, &ttpath, 10) * 256; - if (ttpath == NULL) { - /* didn't get correct response from PASV */ - goto errexit; - } - tpath = ttpath; - if (*tpath != ',') - goto errexit; - tpath++; - /* pull out the LSB of the port */ - portno += (unsigned short) strtoul(tpath, &ttpath, 10); - } else { - /* parse epsv command (|||6446|) */ - for (i = 0, tpath = tmp_line + 4; *tpath; tpath++) { - if (*tpath == '|') { - i++; - if (i == 3) - break; - } - } - if (i < 3) - goto errexit; - /* pull out the port */ - portno = (unsigned short) strtoul(tpath + 1, &ttpath, 10); - } - - if (ttpath == NULL) { - /* didn't get correct response from EPSV/PASV */ - goto errexit; - } - - if (mode[0] == 'r') { - /* retrieve file */ - php_stream_write_string(stream, "RETR "); - } else { - /* store file */ - php_stream_write_string(stream, "STOR "); - } - if (resource->path != NULL) { - php_stream_write_string(stream, resource->path); - } else { - php_stream_write_string(stream, "/"); - } - php_stream_write_string(stream, "\r\n"); - - /* open the data channel */ - if (hoststart == NULL) { - hoststart = resource->host; - } - datastream = php_stream_sock_open_host(hoststart, portno, SOCK_STREAM, 0, 0); - if (datastream == NULL) { - goto errexit; - } - - result = GET_FTP_RESULT(stream); - if (result != 150 && result != 125) { - /* Could not retrieve or send the file - * this data will only be sent to us after connection on the data port was initiated. - */ - php_stream_close(datastream); - datastream = NULL; - goto errexit; - } - - /* close control connection if not in ssl mode */ - if (!use_ssl) { - php_stream_write_string(stream, "QUIT\r\n"); - php_stream_close(stream); - stream = NULL; - } - - php_stream_context_set(datastream, context); - php_stream_notify_progress_init(context, 0, file_size); - - if (use_ssl_on_data && (php_stream_xport_crypto_setup(stream, - STREAM_CRYPTO_METHOD_SSLv23_CLIENT, NULL TSRMLS_CC) < 0 || - php_stream_xport_crypto_enable(stream, 1 TSRMLS_CC) < 0)) { - - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Unable to activate SSL mode"); - php_stream_close(datastream); - datastream = NULL; - goto errexit; - } - - /* remember control stream */ - datastream->wrapperdata = (zval *)stream; - - php_url_free(resource); - return datastream; - - errexit: - php_url_free(resource); - if (stream) { - php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE, tmp_line, result); - php_stream_close(stream); - } - if (tmp_line[0] != '\0') - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "FTP server reports %s", tmp_line); - return NULL; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/head.c b/ext/standard/head.c deleted file mode 100644 index 234468d5ed..0000000000 --- a/ext/standard/head.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> - -#if defined(NETWARE) && !defined(NEW_LIBC) -#include <sys/socket.h> -#endif - -#include "php.h" -#include "ext/standard/php_standard.h" -#include "SAPI.h" -#include "php_main.h" -#include "head.h" -#include "SAPI.h" -#ifdef TM_IN_SYS_TIME -#include <sys/time.h> -#else -#include <time.h> -#endif - -#include "php_globals.h" -#include "safe_mode.h" - - -/* Implementation of the language Header() function */ -/* {{{ proto void header(string header [, bool replace, [int http_response_code]]) - Sends a raw HTTP header */ -PHP_FUNCTION(header) -{ - zend_bool rep = 1; - sapi_header_line ctr = {0}; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bl", &ctr.line, - &ctr.line_len, &rep, &ctr.response_code) == FAILURE) - return; - - sapi_header_op(rep ? SAPI_HEADER_REPLACE:SAPI_HEADER_ADD, &ctr TSRMLS_CC); -} -/* }}} */ - -PHPAPI int php_header() -{ - TSRMLS_FETCH(); - - if (sapi_send_headers(TSRMLS_C)==FAILURE || SG(request_info).headers_only) { - return 0; /* don't allow output */ - } else { - return 1; /* allow output */ - } -} - - -PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure TSRMLS_DC) -{ - char *cookie, *encoded_value = NULL; - int len=sizeof("Set-Cookie: "); - time_t t; - char *dt; - sapi_header_line ctr = {0}; - int result; - - len += name_len; - if (value) { - int encoded_value_len; - - encoded_value = php_url_encode(value, value_len, &encoded_value_len); - len += encoded_value_len; - } - if (path) { - len += path_len; - } - if (domain) { - len += domain_len; - } - cookie = emalloc(len + 100); - - if (value && value_len == 0) { - /* - * MSIE doesn't delete a cookie when you set it to a null value - * so in order to force cookies to be deleted, even on MSIE, we - * pick an expiry date 1 year and 1 second in the past - */ - t = time(NULL) - 31536001; - dt = php_std_date(t); - sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", name, dt); - efree(dt); - } else { - sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : ""); - if (expires > 0) { - strcat(cookie, "; expires="); - dt = php_std_date(expires); - strcat(cookie, dt); - efree(dt); - } - } - - if (encoded_value) { - efree(encoded_value); - } - - if (path && path_len > 0) { - strcat(cookie, "; path="); - strcat(cookie, path); - } - if (domain && domain_len > 0) { - strcat(cookie, "; domain="); - strcat(cookie, domain); - } - if (secure) { - strcat(cookie, "; secure"); - } - - ctr.line = cookie; - ctr.line_len = strlen(cookie); - - result = sapi_header_op(SAPI_HEADER_ADD, &ctr TSRMLS_CC); - efree(cookie); - return result; -} - - -/* php_set_cookie(name, value, expires, path, domain, secure) */ -/* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure]]]]]) - Send a cookie */ -PHP_FUNCTION(setcookie) -{ - char *name, *value = NULL, *path = NULL, *domain = NULL; - time_t expires = 0; - zend_bool secure = 0; - int name_len, value_len, path_len, domain_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|slssb", &name, - &name_len, &value, &value_len, &expires, &path, - &path_len, &domain, &domain_len, &secure) == FAILURE) { - return; - } - - if (php_setcookie(name, name_len, value, value_len, expires, path, path_len, domain, domain_len, secure TSRMLS_CC) == SUCCESS) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } -} -/* }}} */ - - -/* {{{ proto bool headers_sent([string &$file [, int &$line]]) - Returns true if headers have already been sent, false otherwise */ -PHP_FUNCTION(headers_sent) -{ - zval *arg1, *arg2; - char *file=""; - int line=0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|zz", &arg1, &arg2) == FAILURE) - return; - - if (SG(headers_sent)) { - line = php_get_output_start_lineno(TSRMLS_C); - file = php_get_output_start_filename(TSRMLS_C); - } - - switch(ZEND_NUM_ARGS()) { - case 2: - zval_dtor(arg2); - ZVAL_LONG(arg2, line); - case 1: - zval_dtor(arg1); - if (file) { - ZVAL_STRING(arg1, file, 1); - } else { - ZVAL_STRING(arg1, "", 1); - } - break; - } - - if (SG(headers_sent)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 * End: - */ diff --git a/ext/standard/head.h b/ext/standard/head.h deleted file mode 100644 index 59b4b26f6b..0000000000 --- a/ext/standard/head.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef HEAD_H -#define HEAD_H - -extern PHP_RINIT_FUNCTION(head); -PHP_FUNCTION(header); -PHP_FUNCTION(setcookie); -PHP_FUNCTION(headers_sent); - -PHPAPI int php_header(void); -PHPAPI int php_setcookie(char *name, int name_len, char *value, int value_len, time_t expires, char *path, int path_len, char *domain, int domain_len, int secure TSRMLS_DC); - -#endif diff --git a/ext/standard/html.c b/ext/standard/html.c deleted file mode 100644 index be06b8dbef..0000000000 --- a/ext/standard/html.c +++ /dev/null @@ -1,954 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jaakko Hyvätti <jaakko.hyvatti@iki.fi> | - | Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#if PHP_WIN32 -#include "config.w32.h" -#elif defined NETWARE -#include "config.nw.h" -#else -#include "php_config.h" -#endif -#include "reg.h" -#include "html.h" -#include "php_string.h" -#include "SAPI.h" -#if HAVE_LOCALE_H -#include <locale.h> -#endif -#if HAVE_LANGINFO_H -#include <langinfo.h> -#endif - -#if HAVE_MBSTRING -# include "ext/mbstring/mbstring.h" -ZEND_EXTERN_MODULE_GLOBALS(mbstring) -#endif - -enum entity_charset { cs_terminator, cs_8859_1, cs_cp1252, - cs_8859_15, cs_utf_8, cs_big5, cs_gb2312, - cs_big5hkscs, cs_sjis, cs_eucjp}; -typedef const char *entity_table_t; - -/* codepage 1252 is a Windows extension to iso-8859-1. */ -static entity_table_t ent_cp_1252[] = { - "euro", NULL, "sbquo", "fnof", "bdquo", "hellip", "dagger", - "Dagger", "circ", "permil", "Scaron", "lsaquo", "OElig", - NULL, NULL, NULL, NULL, "lsquo", "rsquo", "ldquo", "rdquo", - "bull", "ndash", "mdash", "tilde", "trade", "scaron", "rsaquo", - "oelig", NULL, NULL, "Yuml" -}; - -static entity_table_t ent_iso_8859_1[] = { - "nbsp", "iexcl", "cent", "pound", "curren", "yen", "brvbar", - "sect", "uml", "copy", "ordf", "laquo", "not", "shy", "reg", - "macr", "deg", "plusmn", "sup2", "sup3", "acute", "micro", - "para", "middot", "cedil", "sup1", "ordm", "raquo", "frac14", - "frac12", "frac34", "iquest", "Agrave", "Aacute", "Acirc", - "Atilde", "Auml", "Aring", "AElig", "Ccedil", "Egrave", - "Eacute", "Ecirc", "Euml", "Igrave", "Iacute", "Icirc", - "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc", "Otilde", - "Ouml", "times", "Oslash", "Ugrave", "Uacute", "Ucirc", "Uuml", - "Yacute", "THORN", "szlig", "agrave", "aacute", "acirc", - "atilde", "auml", "aring", "aelig", "ccedil", "egrave", - "eacute", "ecirc", "euml", "igrave", "iacute", "icirc", - "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc", "otilde", - "ouml", "divide", "oslash", "ugrave", "uacute", "ucirc", - "uuml", "yacute", "thorn", "yuml" -}; - -static entity_table_t ent_iso_8859_15[] = { - "nbsp", "iexcl", "cent", "pound", "euro", "yen", "Scaron", - "sect", "scaron", "copy", "ordf", "laquo", "not", "shy", "reg", - "macr", "deg", "plusmn", "sup2", "sup3", NULL, /* Zcaron */ - "micro", "para", "middot", NULL, /* zcaron */ "sup1", "ordm", - "raquo", "OElig", "oelig", "Yuml", "iquest", "Agrave", "Aacute", - "Acirc", "Atilde", "Auml", "Aring", "AElig", "Ccedil", "Egrave", - "Eacute", "Ecirc", "Euml", "Igrave", "Iacute", "Icirc", - "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc", "Otilde", - "Ouml", "times", "Oslash", "Ugrave", "Uacute", "Ucirc", "Uuml", - "Yacute", "THORN", "szlig", "agrave", "aacute", "acirc", - "atilde", "auml", "aring", "aelig", "ccedil", "egrave", - "eacute", "ecirc", "euml", "igrave", "iacute", "icirc", - "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc", "otilde", - "ouml", "divide", "oslash", "ugrave", "uacute", "ucirc", - "uuml", "yacute", "thorn", "yuml" -}; - -static entity_table_t ent_uni_338_402[] = { - /* 338 */ - "OElig", "oelig", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - /* 352 */ - "Scaron", "scaron", - /* 354 - 375 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 376 */ - "Yuml", - /* 377 - 401 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 402 */ - "fnof" -}; - -static entity_table_t ent_uni_spacing[] = { - /* 710 */ - "circ", - /* 711 - 731 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 732 */ - "tilde", -}; - -static entity_table_t ent_uni_greek[] = { - /* 913 */ - "Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", - "Iota", "Kappa", "Lambda", "Mu", "Nu", "X1", "Omicron", "P1", "Rho", - NULL, "Sigma", "Tau", "Upsilon", "Ph1", "Ch1", "Ps1", "Omega", - /* 938 - 944 are not mapped */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", - "iota", "kappa", "lambda", "mu", "nu", "x1", "omicron", "p1", "rho", - "sigmaf", "sigma", "tau", "upsilon", "ph1", "ch1", "ps1", "omega", - /* 970 - 976 are not mapped */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "thetasym", "ups1h", - NULL, NULL, NULL, - "p1v" -}; - -static entity_table_t ent_uni_punct[] = { - /* 8194 */ - "ensp", "emsp", NULL, NULL, NULL, NULL, NULL, - "thinsp", NULL, NULL, "zwnj", "zwj", "lrm", "rlm", - NULL, NULL, NULL, "ndash", "mdash", NULL, NULL, NULL, - "lsquo", "rsquo", "sbquo", NULL, "ldquo", "rdquo", "bdquo", - "dagger", "Dagger", "bull", NULL, NULL, NULL, "hellip", - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "permil", NULL, - "prime", "Prime", NULL, NULL, NULL, NULL, NULL, "lsaquo", "rsaquo", - NULL, NULL, NULL, "oline", NULL, NULL, NULL, NULL, NULL, - "frasl" -}; - -static entity_table_t ent_uni_8465_8501[] = { - /* 8465 */ - "image", NULL, NULL, NULL, NULL, NULL, NULL, - /* 8472 */ - "weierp", NULL, NULL, NULL, - /* 8476 */ - "real", NULL, NULL, NULL, NULL, NULL, - /* 8482 */ - "trade", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 8501 */ - "alefsym", -}; - -static entity_table_t ent_uni_8592_9002[] = { - /* 8592 */ - "larr", "uarr", "rarr", "darr", "harr", - /* 8597 - 8628 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, - /* 8629 */ - "crarr", - /* 8630 - 8655 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - /* 8656 */ - "lArr", "uArr", "rArr", "dArr", "hArr", - /* 8661 - 8703 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, - /* 8704 */ - "forall", "part", "exist", NULL, "empty", NULL, "nabla", "isin", - "notin", NULL, "n1", NULL, NULL, NULL, "prod", NULL, "sum", "minus", - NULL, NULL, NULL, NULL, "lowast", NULL, NULL, "radic", NULL, NULL, - "prop", "infin", NULL, "ang", NULL, NULL, NULL, NULL, NULL, NULL, - "and", "or", "cap", "cup", "int", NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, "there4", NULL, NULL, NULL, NULL, NULL, NULL, - NULL, "sim", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - "cong", NULL, NULL, "asymp", - /* 8777 - 8799 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, - /* 8800 */ - "ne", "equiv", NULL, NULL, "le", "ge", - /* 8806 - 8833 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 8834 */ - "sub", "sup", "nsub", NULL, "sube", "supe", - /* 8840 - 8852 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 8853 */ - "oplus", NULL, "otimes", - /* 8856 - 8868 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 8869 */ - "perp", - /* 8870 - 8901 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, - /* 8901 */ - "sdot", - /* 8902 - 8967 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, - /* 8968 */ - "lceil", "rceil", "lfloor", "rfloor", - /* 8969 - 9000 */ - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, - /* 9001 */ - "lang", "rang", -}; - -static entity_table_t ent_uni_9674[] = { - /* 9674 */ - "loz" -}; - -static entity_table_t ent_uni_9824_9830[] = { - /* 9824 */ - "spades", NULL, NULL, "clubs", NULL, "hearts", "diams" -}; - -struct html_entity_map { - enum entity_charset charset; /* charset identifier */ - unsigned short basechar; /* char code at start of table */ - unsigned short endchar; /* last char code in the table */ - entity_table_t *table; /* the table of mappings */ -}; - -static const struct html_entity_map entity_map[] = { - { cs_cp1252, 0x80, 0x9f, ent_cp_1252 }, - { cs_cp1252, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_8859_1, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_8859_15, 0xa0, 0xff, ent_iso_8859_15 }, - { cs_utf_8, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_utf_8, 338, 402, ent_uni_338_402 }, - { cs_utf_8, 710, 732, ent_uni_spacing }, - { cs_utf_8, 913, 982, ent_uni_greek }, - { cs_utf_8, 8194, 8260, ent_uni_punct }, - { cs_utf_8, 8465, 8501, ent_uni_8465_8501 }, - { cs_utf_8, 8592, 9002, ent_uni_8592_9002 }, - { cs_utf_8, 9674, 9674, ent_uni_9674 }, - { cs_utf_8, 9824, 9830, ent_uni_9824_9830 }, - { cs_big5, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_gb2312, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_big5hkscs, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_sjis, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_eucjp, 0xa0, 0xff, ent_iso_8859_1 }, - { cs_terminator } -}; - -static const struct { - const char *codeset; - enum entity_charset charset; -} charset_map[] = { - { "ISO-8859-1", cs_8859_1 }, - { "ISO8859-1", cs_8859_1 }, - { "ISO-8859-15", cs_8859_15 }, - { "ISO8859-15", cs_8859_15 }, - { "utf-8", cs_utf_8 }, - { "cp1252", cs_cp1252 }, - { "Windows-1252", cs_cp1252 }, - { "1252", cs_cp1252 }, - { "BIG5", cs_big5 }, - { "950", cs_big5 }, - { "GB2312", cs_gb2312 }, - { "936", cs_gb2312 }, - { "BIG5-HKSCS", cs_big5hkscs }, - { "Shift_JIS", cs_sjis }, - { "SJIS", cs_sjis }, - { "932", cs_sjis }, - { "EUCJP", cs_eucjp }, - { "EUC-JP", cs_eucjp }, - { NULL } -}; - -static const struct { - unsigned short charcode; - char *entity; - int entitylen; - int flags; -} basic_entities[] = { - { '&', "&", 5, 0 }, - { '"', """, 6, ENT_HTML_QUOTE_DOUBLE }, - { '\'', "'", 6, ENT_HTML_QUOTE_SINGLE }, - { '<', "<", 4, 0 }, - { '>', ">", 4, 0 }, - { 0, NULL, 0, 0 } -}; - -#define MB_RETURN { \ - *newpos = pos; \ - mbseq[mbpos] = '\0'; \ - *mbseqlen = mbpos; \ - return this_char; } - -#define MB_WRITE(mbchar) { \ - mbspace--; \ - if (mbspace == 0) { \ - MB_RETURN; \ - } \ - mbseq[mbpos++] = (mbchar); } - -/* {{{ get_next_char - */ -inline static unsigned short get_next_char(enum entity_charset charset, - unsigned char * str, - int * newpos, - unsigned char * mbseq, - int * mbseqlen) -{ - int pos = *newpos; - int mbpos = 0; - int mbspace = *mbseqlen; - unsigned short this_char = str[pos++]; - - if (mbspace <= 0) { - *mbseqlen = 0; - return this_char; - } - - MB_WRITE((unsigned char)this_char); - - switch (charset) { - case cs_utf_8: - { - unsigned long utf = 0; - int stat = 0; - int more = 1; - - /* unpack utf-8 encoding into a wide char. - * Code stolen from the mbstring extension */ - - do { - if (this_char < 0x80) { - more = 0; - break; - } else if (this_char < 0xc0) { - switch (stat) { - case 0x10: /* 2, 2nd */ - case 0x21: /* 3, 3rd */ - case 0x32: /* 4, 4th */ - case 0x43: /* 5, 5th */ - case 0x54: /* 6, 6th */ - /* last byte in sequence */ - more = 0; - utf |= (this_char & 0x3f); - this_char = (unsigned short)utf; - break; - case 0x20: /* 3, 2nd */ - case 0x31: /* 4, 3rd */ - case 0x42: /* 5, 4th */ - case 0x53: /* 6, 5th */ - /* penultimate char */ - utf |= ((this_char & 0x3f) << 6); - stat++; - break; - case 0x30: /* 4, 2nd */ - case 0x41: /* 5, 3rd */ - case 0x52: /* 6, 4th */ - utf |= ((this_char & 0x3f) << 12); - stat++; - break; - case 0x40: /* 5, 2nd */ - case 0x51: - utf |= ((this_char & 0x3f) << 18); - stat++; - break; - case 0x50: /* 6, 2nd */ - utf |= ((this_char & 0x3f) << 24); - stat++; - default: - /* invalid */ - more = 0; - } - } - /* lead byte */ - else if (this_char < 0xe0) { - stat = 0x10; /* 2 byte */ - utf = (this_char & 0x1f) << 6; - } else if (this_char < 0xf0) { - stat = 0x20; /* 3 byte */ - utf = (this_char & 0xf) << 12; - } else if (this_char < 0xf8) { - stat = 0x30; /* 4 byte */ - utf = (this_char & 0x7) << 18; - } else if (this_char < 0xfc) { - stat = 0x40; /* 5 byte */ - utf = (this_char & 0x3) << 24; - } else if (this_char < 0xfe) { - stat = 0x50; /* 6 byte */ - utf = (this_char & 0x1) << 30; - } else { - /* invalid; bail */ - more = 0; - break; - } - - if (more) { - this_char = str[pos++]; - MB_WRITE((unsigned char)this_char); - } - } while (more); - } - break; - case cs_big5: - case cs_gb2312: - case cs_big5hkscs: - { - /* check if this is the first of a 2-byte sequence */ - if (this_char >= 0xa1 && this_char <= 0xf9) { - /* peek at the next char */ - unsigned char next_char = str[pos]; - if ((next_char >= 0x40 && next_char <= 0x73) || - (next_char >= 0xa1 && next_char <= 0xfe)) { - /* yes, this a wide char */ - this_char <<= 8; - MB_WRITE(next_char); - this_char |= next_char; - pos++; - } - - } - break; - } - case cs_sjis: - { - /* check if this is the first of a 2-byte sequence */ - if ( (this_char >= 0x81 && this_char <= 0x9f) || - (this_char >= 0xe0 && this_char <= 0xef) - ) { - /* peek at the next char */ - unsigned char next_char = str[pos]; - if ((next_char >= 0x40 && next_char <= 0x7e) || - (next_char >= 0x80 && next_char <= 0xfc)) - { - /* yes, this a wide char */ - this_char <<= 8; - MB_WRITE(next_char); - this_char |= next_char; - pos++; - } - - } - break; - } - case cs_eucjp: - { - /* check if this is the first of a multi-byte sequence */ - if (this_char >= 0xa1 && this_char <= 0xfe) { - /* peek at the next char */ - unsigned char next_char = str[pos]; - if (next_char >= 0xa1 && next_char <= 0xfe) { - /* yes, this a jis kanji char */ - this_char <<= 8; - MB_WRITE(next_char); - this_char |= next_char; - pos++; - } - - } else if (this_char == 0x8e) { - /* peek at the next char */ - unsigned char next_char = str[pos]; - if (next_char >= 0xa1 && next_char <= 0xdf) { - /* JIS X 0201 kana */ - this_char <<= 8; - MB_WRITE(next_char); - this_char |= next_char; - pos++; - } - - } else if (this_char == 0x8f) { - /* peek at the next two char */ - unsigned char next_char = str[pos]; - unsigned char next2_char = str[pos+1]; - if ((next_char >= 0xa1 && next_char <= 0xfe) && - (next2_char >= 0xa1 && next2_char <= 0xfe)) { - /* JIS X 0212 hojo-kanji */ - this_char <<= 8; - MB_WRITE(next_char); - this_char |= next_char; - pos++; - this_char <<= 8; - MB_WRITE(next2_char); - this_char |= next2_char; - pos++; - } - - } - break; - } - default: - break; - } - MB_RETURN; -} -/* }}} */ - -/* {{{ entity_charset determine_charset - * returns the charset identifier based on current locale or a hint. - * defaults to iso-8859-1 */ -static enum entity_charset determine_charset(char *charset_hint TSRMLS_DC) -{ - int i; - enum entity_charset charset = cs_8859_1; - int len = 0; - zval *uf_result = NULL; - - /* Guarantee default behaviour for backwards compatibility */ - if (charset_hint == NULL) - return cs_8859_1; - - if ((len = strlen(charset_hint)) != 0) { - goto det_charset; - } -#if HAVE_MBSTRING -#if !defined(COMPILE_DL_MBSTRING) - /* XXX: Ugly things. Why don't we look for a more sophisticated way? */ - switch (MBSTRG(current_internal_encoding)) { - case mbfl_no_encoding_8859_1: - return cs_8859_1; - - case mbfl_no_encoding_utf8: - return cs_utf_8; - - case mbfl_no_encoding_euc_jp: - case mbfl_no_encoding_eucjp_win: - return cs_eucjp; - - case mbfl_no_encoding_sjis: - case mbfl_no_encoding_sjis_win: - case mbfl_no_encoding_sjis_mac: - return cs_sjis; - - case mbfl_no_encoding_cp1252: - return cs_cp1252; - - case mbfl_no_encoding_8859_15: - return cs_8859_15; - - case mbfl_no_encoding_big5: - return cs_big5; - - case mbfl_no_encoding_euc_cn: - case mbfl_no_encoding_hz: - case mbfl_no_encoding_cp936: - return cs_gb2312; - } -#else - { - zval nm_mb_internal_encoding; - - ZVAL_STRING(&nm_mb_internal_encoding, "mb_internal_encoding", 0); - - if (call_user_function_ex(CG(function_table), NULL, &nm_mb_internal_encoding, &uf_result, 0, NULL, 1, NULL TSRMLS_CC) != FAILURE) { - - charset_hint = Z_STRVAL_P(uf_result); - len = Z_STRLEN_P(uf_result); - - goto det_charset; - } - } -#endif -#endif - - charset_hint = SG(default_charset); - if (charset_hint != NULL && (len=strlen(charset_hint)) != 0) { - goto det_charset; - } - - /* try to detect the charset for the locale */ -#if HAVE_NL_LANGINFO && HAVE_LOCALE_H && defined(CODESET) - charset_hint = nl_langinfo(CODESET); - if (charset_hint != NULL && (len=strlen(charset_hint)) != 0) { - goto det_charset; - } -#endif - -#if HAVE_LOCALE_H - /* try to figure out the charset from the locale */ - { - char *localename; - char *dot, *at; - - /* lang[_territory][.codeset][@modifier] */ - localename = setlocale(LC_CTYPE, NULL); - - dot = strchr(localename, '.'); - if (dot) { - dot++; - /* locale specifies a codeset */ - at = strchr(dot, '@'); - if (at) - len = at - dot; - else - len = strlen(dot); - charset_hint = dot; - } else { - /* no explicit name; see if the name itself - * is the charset */ - charset_hint = localename; - len = strlen(charset_hint); - } - } -#endif - -det_charset: - - if (charset_hint) { - int found = 0; - - /* now walk the charset map and look for the codeset */ - for (i = 0; charset_map[i].codeset; i++) { - if (strncasecmp(charset_hint, charset_map[i].codeset, len) == 0) { - charset = charset_map[i].charset; - found = 1; - break; - } - } - if (!found) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "charset `%s' not supported, assuming iso-8859-1", - charset_hint); - } - } - if (uf_result != NULL) { - zval_ptr_dtor(&uf_result); - } - return charset; -} -/* }}} */ - -/* {{{ php_unescape_html_entities - */ -PHPAPI char *php_unescape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char *hint_charset TSRMLS_DC) -{ - int retlen; - int j, k; - char *replaced, *ret; - enum entity_charset charset = determine_charset(hint_charset TSRMLS_CC); - unsigned char replacement[15]; - - ret = estrdup(old); - retlen = oldlen; - if (!retlen) { - goto empty_source; - } - - if (all) { - /* look for a match in the maps for this charset */ - for (j = 0; entity_map[j].charset != cs_terminator; j++) { - if (entity_map[j].charset != charset) - continue; - - for (k = entity_map[j].basechar; k <= entity_map[j].endchar; k++) { - unsigned char entity[32]; - int entity_length = 0; - - if (entity_map[j].table[k - entity_map[j].basechar] == NULL) - continue; - - - entity[0] = '&'; - entity_length = strlen(entity_map[j].table[k - entity_map[j].basechar]); - strncpy(&entity[1], entity_map[j].table[k - entity_map[j].basechar], sizeof(entity) - 2); - entity[entity_length+1] = ';'; - entity[entity_length+2] = '\0'; - entity_length += 2; - - /* When we have MBCS entities in the tables above, this will need to handle it */ - if (k > 0xff) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot yet handle MBCS!"); - } - replacement[0] = k; - replacement[1] = '\0'; - - replaced = php_str_to_str(ret, retlen, entity, entity_length, replacement, 1, &retlen); - efree(ret); - ret = replaced; - } - } - } - - for (j = 0; basic_entities[j].charcode != 0; j++) { - - if (basic_entities[j].flags && (quote_style & basic_entities[j].flags) == 0) - continue; - - replacement[0] = (unsigned char)basic_entities[j].charcode; - replacement[1] = '\0'; - - replaced = php_str_to_str(ret, retlen, basic_entities[j].entity, basic_entities[j].entitylen, replacement, 1, &retlen); - efree(ret); - ret = replaced; - } -empty_source: - *newlen = retlen; - return ret; -} -/* }}} */ - - - - -/* {{{ php_escape_html_entities - */ -PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char *hint_charset TSRMLS_DC) -{ - int i, j, maxlen, len; - char *replaced; - enum entity_charset charset = determine_charset(hint_charset TSRMLS_CC); - int matches_map; - - maxlen = 2 * oldlen; - if (maxlen < 128) - maxlen = 128; - replaced = emalloc (maxlen); - len = 0; - - i = 0; - while (i < oldlen) { - unsigned char mbsequence[16]; /* allow up to 15 characters in a multibyte sequence */ - int mbseqlen = sizeof(mbsequence); - unsigned short this_char = get_next_char(charset, old, &i, mbsequence, &mbseqlen); - - matches_map = 0; - - if (len + 9 > maxlen) - replaced = erealloc (replaced, maxlen += 128); - - if (all) { - /* look for a match in the maps for this charset */ - unsigned char *rep = NULL; - - - for (j = 0; entity_map[j].charset != cs_terminator; j++) { - if (entity_map[j].charset == charset - && this_char >= entity_map[j].basechar - && this_char <= entity_map[j].endchar) { - rep = (unsigned char*)entity_map[j].table[this_char - entity_map[j].basechar]; - if (rep == NULL) { - /* there is no entity for this position; fall through and - * just output the character itself */ - break; - } - - matches_map = 1; - break; - } - } - - if (matches_map) { - replaced[len++] = '&'; - strcpy(replaced + len, rep); - len += strlen(rep); - replaced[len++] = ';'; - } - } - if (!matches_map) { - int is_basic = 0; - - for (j = 0; basic_entities[j].charcode != 0; j++) { - if ((basic_entities[j].charcode != this_char) || - (basic_entities[j].flags && (quote_style & basic_entities[j].flags) == 0)) - continue; - - memcpy(replaced + len, basic_entities[j].entity, basic_entities[j].entitylen); - len += basic_entities[j].entitylen; - - is_basic = 1; - break; - - } - if (!is_basic) { - /* a wide char without a named entity; pass through the original sequence */ - if (mbseqlen > 1) { - memcpy(replaced + len, mbsequence, mbseqlen); - len += mbseqlen; - } else { - replaced[len++] = (unsigned char)this_char; - } - } - } - } - replaced[len] = '\0'; - *newlen = len; - - return replaced; - - -} -/* }}} */ - -/* {{{ php_html_entities - */ -static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) -{ - char *str, *hint_charset = NULL; - int str_len, hint_charset_len = 0; - int len; - long quote_style = ENT_COMPAT; - char *replaced; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, "e_style, &hint_charset, &hint_charset_len) == FAILURE) { - return; - } - - replaced = php_escape_html_entities(str, str_len, &len, all, quote_style, hint_charset TSRMLS_CC); - RETVAL_STRINGL(replaced, len, 0); -} -/* }}} */ - -#define HTML_SPECIALCHARS 0 -#define HTML_ENTITIES 1 - -/* {{{ register_html_constants - */ -void register_html_constants(INIT_FUNC_ARGS) -{ - REGISTER_LONG_CONSTANT("HTML_SPECIALCHARS", HTML_SPECIALCHARS, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("HTML_ENTITIES", HTML_ENTITIES, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("ENT_COMPAT", ENT_COMPAT, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("ENT_QUOTES", ENT_QUOTES, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("ENT_NOQUOTES", ENT_NOQUOTES, CONST_PERSISTENT|CONST_CS); -} -/* }}} */ - -/* {{{ proto string htmlspecialchars(string string [, int quote_style][, string charset]) - Convert special characters to HTML entities */ -PHP_FUNCTION(htmlspecialchars) -{ - php_html_entities(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string html_entity_decode(string string [, int quote_style][, string charset]) - Convert all HTML entities to their applicable characters */ -PHP_FUNCTION(html_entity_decode) -{ - char *str, *hint_charset = NULL; - int str_len, hint_charset_len, len, quote_style = ENT_COMPAT; - char *replaced; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls", &str, &str_len, - "e_style, &hint_charset, &hint_charset_len) == FAILURE) { - return; - } - - replaced = php_unescape_html_entities(str, str_len, &len, 1, quote_style, hint_charset TSRMLS_CC); - RETVAL_STRINGL(replaced, len, 0); -} -/* }}} */ - - -/* {{{ proto string htmlentities(string string [, int quote_style][, string charset]) - Convert all applicable characters to HTML entities */ -PHP_FUNCTION(htmlentities) -{ - php_html_entities(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto array get_html_translation_table([int table [, int quote_style]]) - Returns the internal translation table used by htmlspecialchars and htmlentities */ -PHP_FUNCTION(get_html_translation_table) -{ - int which = HTML_SPECIALCHARS, quote_style = ENT_COMPAT; - int i, j; - char ind[2]; - enum entity_charset charset = determine_charset(NULL TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &which, "e_style) == FAILURE) { - return; - } - - array_init(return_value); - - ind[1] = 0; - - switch (which) { - case HTML_ENTITIES: - for (j=0; entity_map[j].charset != cs_terminator; j++) { - if (entity_map[j].charset != charset) - continue; - for (i = 0; i <= entity_map[j].endchar - entity_map[j].basechar; i++) { - char buffer[16]; - - if (entity_map[j].table[i] == NULL) - continue; - /* what about wide chars here ?? */ - ind[0] = i + entity_map[j].basechar; - sprintf(buffer, "&%s;", entity_map[j].table[i]); - add_assoc_string(return_value, ind, buffer, 1); - - } - } - /* break thru */ - - case HTML_SPECIALCHARS: - for (j = 0; basic_entities[j].charcode != 0; j++) { - - if (basic_entities[j].flags && (quote_style & basic_entities[j].flags) == 0) - continue; - - ind[0] = (unsigned char)basic_entities[j].charcode; - add_assoc_string(return_value, ind, basic_entities[j].entity, 1); - } - break; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/html.h b/ext/standard/html.h deleted file mode 100644 index f47390e764..0000000000 --- a/ext/standard/html.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef HTML_H -#define HTML_H - -#define ENT_HTML_QUOTE_NONE 0 -#define ENT_HTML_QUOTE_SINGLE 1 -#define ENT_HTML_QUOTE_DOUBLE 2 - -#define ENT_COMPAT ENT_HTML_QUOTE_DOUBLE -#define ENT_QUOTES (ENT_HTML_QUOTE_DOUBLE | ENT_HTML_QUOTE_SINGLE) -#define ENT_NOQUOTES ENT_HTML_QUOTE_NONE - -void register_html_constants(INIT_FUNC_ARGS); - -PHP_FUNCTION(htmlspecialchars); -PHP_FUNCTION(htmlentities); -PHP_FUNCTION(html_entity_decode); -PHP_FUNCTION(get_html_translation_table); - -PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char *hint_charset TSRMLS_DC); - -#endif /* HTML_H */ diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c deleted file mode 100644 index dbe7340a9a..0000000000 --- a/ext/standard/http_fopen_wrapper.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - | Hartmut Holzgraefe <hholzgra@php.net> | - | Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include "php_globals.h" -#include "php_streams.h" -#include "php_network.h" -#include "php_ini.h" -#include "ext/standard/basic_functions.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> - -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#elif defined(NETWARE) -/*#include <ws2nlm.h>*/ -/*#include <sys/socket.h>*/ -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#else -#include <sys/param.h> -#endif - -#include "php_standard.h" - -#include <sys/types.h> -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifdef PHP_WIN32 -#include <winsock2.h> -#elif defined(NETWARE) && defined(USE_WINSOCK) -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#if HAVE_ARPA_INET_H -#include <arpa/inet.h> -#endif -#endif - -#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) -#undef AF_UNIX -#endif - -#if defined(AF_UNIX) -#include <sys/un.h> -#endif - -#include "php_fopen_wrappers.h" - -#define HTTP_HEADER_BLOCK_SIZE 1024 - -php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - php_stream *stream = NULL; - php_url *resource = NULL; - int use_ssl; - char *scratch = NULL; - char *tmp = NULL; - char *ua_str = NULL; - zval **ua_zval = NULL; - int scratch_len = 0; - int body = 0; - char location[HTTP_HEADER_BLOCK_SIZE]; - zval *response_header = NULL; - int reqok = 0; - char *http_header_line = NULL; - char tmp_line[128]; - size_t chunk_size = 0, file_size = 0; - int eol_detect; - char *transport_string, *errstr = NULL; - int transport_len; - - if (strpbrk(mode, "awx+")) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP wrapper does not support writeable connections."); - return NULL; - } - - resource = php_url_parse(path); - if (resource == NULL) - return NULL; - - use_ssl = resource->scheme && (strlen(resource->scheme) > 4) && resource->scheme[4] == 's'; - /* choose default ports */ - if (use_ssl && resource->port == 0) - resource->port = 443; - else if (resource->port == 0) - resource->port = 80; - - transport_len = spprintf(&transport_string, 0, "%s://%s:%d", use_ssl ? "ssl" : "tcp", resource->host, resource->port); - - stream = php_stream_xport_create(transport_string, transport_len, options, - STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT, - NULL, NULL, context, &errstr, NULL); - - if (errstr) { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr); - efree(errstr); - errstr = NULL; - } - - efree(transport_string); - - if (stream == NULL) - goto out; - - /* avoid buffering issues while reading header */ - if (options & STREAM_WILL_CAST) - chunk_size = php_stream_set_chunk_size(stream, 1); - - /* avoid problems with auto-detecting when reading the headers -> the headers - * are always in canonical \r\n format */ - eol_detect = stream->flags & (PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); - stream->flags &= ~(PHP_STREAM_FLAG_DETECT_EOL | PHP_STREAM_FLAG_EOL_MAC); - - php_stream_context_set(stream, context); - - php_stream_notify_info(context, PHP_STREAM_NOTIFY_CONNECT, NULL, 0); - - scratch_len = strlen(path) + 32; - scratch = emalloc(scratch_len); - - strcpy(scratch, "GET "); - - /* file */ - if (resource->path && *resource->path) - strlcat(scratch, resource->path, scratch_len); - else - strlcat(scratch, "/", scratch_len); - - /* query string */ - if (resource->query) { - strlcat(scratch, "?", scratch_len); - strlcat(scratch, resource->query, scratch_len); - } - - /* protocol version we are speaking */ - strlcat(scratch, " HTTP/1.0\r\n", scratch_len); - - /* send it */ - php_stream_write(stream, scratch, strlen(scratch)); - - /* auth header if it was specified */ - if (resource->user && resource->pass) { - /* decode the strings first */ - php_url_decode(resource->user, strlen(resource->user)); - php_url_decode(resource->pass, strlen(resource->pass)); - - /* scratch is large enough, since it was made large enough for the whole URL */ - strcpy(scratch, resource->user); - strcat(scratch, ":"); - strcat(scratch, resource->pass); - - tmp = php_base64_encode((unsigned char*)scratch, strlen(scratch), NULL); - - if (snprintf(scratch, scratch_len, "Authorization: Basic %s\r\n", tmp) > 0) { - php_stream_write(stream, scratch, strlen(scratch)); - php_stream_notify_info(context, PHP_STREAM_NOTIFY_AUTH_REQUIRED, NULL, 0); - } - - efree(tmp); - tmp = NULL; - } - - /* if the user has configured who they are, send a From: line */ - if (cfg_get_string("from", &tmp) == SUCCESS) { - if (snprintf(scratch, scratch_len, "From: %s\r\n", tmp) > 0) - php_stream_write(stream, scratch, strlen(scratch)); - } - - /* Send Host: header so name-based virtual hosts work */ - if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) { - if (snprintf(scratch, scratch_len, "Host: %s:%i\r\n", resource->host, resource->port) > 0) - php_stream_write(stream, scratch, strlen(scratch)); - } - else if (snprintf(scratch, scratch_len, "Host: %s\r\n", resource->host) > 0) - php_stream_write(stream, scratch, strlen(scratch)); - - if (context && - php_stream_context_get_option(context, "http", "user_agent", &ua_zval) == SUCCESS) { - ua_str = Z_STRVAL_PP(ua_zval); - } else if (FG(user_agent)) { - ua_str = FG(user_agent); - } - - if (ua_str) { -#define _UA_HEADER "User-Agent: %s\r\n" - char *ua; - size_t ua_len; - - ua_len = sizeof(_UA_HEADER) + strlen(ua_str); - - /* ensure the header is only sent if user_agent is not blank */ - if (ua_len > sizeof(_UA_HEADER)) { - ua = emalloc(ua_len + 1); - if ((ua_len = snprintf(ua, ua_len, _UA_HEADER, ua_str)) > 0) { - ua[ua_len] = 0; - php_stream_write(stream, ua, ua_len); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot construct User-agent header"); - } - - if (ua) { - efree(ua); - } - } - } - - php_stream_write(stream, "\r\n", sizeof("\r\n")-1); - - location[0] = '\0'; - - MAKE_STD_ZVAL(response_header); - array_init(response_header); - - if (!php_stream_eof(stream)) { - /* get response header */ - - if (php_stream_gets(stream, tmp_line, sizeof(tmp_line)-1) != NULL) { - zval *http_response; - int response_code; - - MAKE_STD_ZVAL(http_response); - response_code = atoi(tmp_line + 9); - switch(response_code) { - case 200: - case 302: - case 301: - reqok = 1; - break; - case 403: - php_stream_notify_error(context, PHP_STREAM_NOTIFY_AUTH_RESULT, - tmp_line, response_code); - break; - default: - php_stream_notify_error(context, PHP_STREAM_NOTIFY_FAILURE, - tmp_line, response_code); - } - - Z_STRLEN_P(http_response) = strlen(tmp_line); - Z_STRVAL_P(http_response) = estrndup(tmp_line, Z_STRLEN_P(http_response)); - if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\n') { - Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; - Z_STRLEN_P(http_response)--; - if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\r') { - Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0; - Z_STRLEN_P(http_response)--; - } - } - Z_TYPE_P(http_response) = IS_STRING; - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response, sizeof(zval *), NULL); - } - } - - if (reqok) { - /* read past HTTP headers */ - - http_header_line = emalloc(HTTP_HEADER_BLOCK_SIZE); - - while (!body && !php_stream_eof(stream)) { - - if (php_stream_gets(stream, http_header_line, HTTP_HEADER_BLOCK_SIZE-1) != NULL) { - char *p; - int found_eol = 0; - int http_header_line_length; - - http_header_line[HTTP_HEADER_BLOCK_SIZE-1] = '\0'; - p = http_header_line; - while(*p) { - while(*p == '\n' || *p == '\r') { - *p = '\0'; - p--; - found_eol = 1; - } - if (found_eol) - break; - p++; - } - http_header_line_length = p-http_header_line+1; - - if (!strncasecmp(http_header_line, "Location: ", 10)) { - strlcpy(location, http_header_line + 10, sizeof(location)); - } else if (!strncasecmp(http_header_line, "Content-Type: ", 14)) { - php_stream_notify_info(context, PHP_STREAM_NOTIFY_MIME_TYPE_IS, http_header_line + 14, 0); - } else if (!strncasecmp(http_header_line, "Content-Length: ", 16)) { - file_size = atoi(http_header_line + 16); - php_stream_notify_file_size(context, file_size, http_header_line, 0); - } - - if (http_header_line[0] == '\0') { - body = 1; - } else { - zval *http_header; - - MAKE_STD_ZVAL(http_header); - - ZVAL_STRINGL(http_header, http_header_line, http_header_line_length, 1); - - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_header, sizeof(zval *), NULL); - } - } else { - break; - } - } - } - - if (!reqok || location[0] != '\0') { - if (location[0] != '\0') - php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0); - - php_stream_close(stream); - stream = NULL; - - if (location[0] != '\0') { - - zval *entry, **entryp; - char new_path[HTTP_HEADER_BLOCK_SIZE]; - char loc_path[HTTP_HEADER_BLOCK_SIZE]; - - *new_path='\0'; - if (strlen(location)<8 || (strncasecmp(location, "http://", sizeof("http://")-1) && strncasecmp(location, "https://", sizeof("https://")-1))) { - if (*location != '/') { - if (*(location+1) != '\0' && resource->path) { - char *s = strrchr(resource->path, '/'); - if (!s) { - s = resource->path; - *s = '/'; - } - s[1] = '\0'; - if (resource->path && *(resource->path) == '/' && *(resource->path + 1) == '\0') { - snprintf(loc_path, sizeof(loc_path) - 1, "%s%s", resource->path, location); - } else { - snprintf(loc_path, sizeof(loc_path) - 1, "%s/%s", resource->path, location); - } - } else { - snprintf(loc_path, sizeof(loc_path) - 1, "/%s", location); - } - } else { - strlcpy(loc_path, location, sizeof(loc_path)); - } - if ((use_ssl && resource->port != 443) || (!use_ssl && resource->port != 80)) { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s:%d%s", resource->scheme, resource->host, resource->port, loc_path); - } else { - snprintf(new_path, sizeof(new_path) - 1, "%s://%s%s", resource->scheme, resource->host, loc_path); - } - } else { - strlcpy(new_path, location, sizeof(new_path)); - } - stream = php_stream_url_wrap_http(NULL, new_path, mode, options, opened_path, context STREAMS_CC TSRMLS_CC); - if (stream && stream->wrapperdata) { - entryp = &entry; - MAKE_STD_ZVAL(entry); - ZVAL_EMPTY_STRING(entry); - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL); - zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream->wrapperdata)); - while (zend_hash_get_current_data(Z_ARRVAL_P(stream->wrapperdata), (void **)&entryp) == SUCCESS) { - zval_add_ref(entryp); - zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL); - zend_hash_move_forward(Z_ARRVAL_P(stream->wrapperdata)); - } - zval_dtor(stream->wrapperdata); - FREE_ZVAL(stream->wrapperdata); - } else { - zval_dtor(response_header); - FREE_ZVAL(response_header); - } - } else { - zval_dtor(response_header); - FREE_ZVAL(response_header); - - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "HTTP request failed! %s", tmp_line); - } - } -out: - if (http_header_line) - efree(http_header_line); - if (scratch) - efree(scratch); - php_url_free(resource); - - if (stream) { - stream->wrapperdata = response_header; - php_stream_notify_progress_init(context, 0, file_size); - /* Restore original chunk size now that we're done with headers */ - if (options & STREAM_WILL_CAST) - php_stream_set_chunk_size(stream, chunk_size); - - /* restore the users auto-detect-line-endings setting */ - stream->flags |= eol_detect; - - /* as far as streams are concerned, we are now at the start of - * the stream */ - stream->position = 0; - } - - if (response_header) { - zval *sym; - MAKE_STD_ZVAL(sym); - *sym = *response_header; - zval_copy_ctor(sym); - ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", sym); - } - - return stream; -} - -static int php_stream_http_stream_stat(php_stream_wrapper *wrapper, - php_stream *stream, - php_stream_statbuf *ssb - TSRMLS_DC) -{ - /* one day, we could fill in the details based on Date: and Content-Length: - * headers. For now, we return with a failure code to prevent the underlying - * file's details from being used instead. */ - return -1; -} - -static php_stream_wrapper_ops http_stream_wops = { - php_stream_url_wrap_http, - NULL, /* stream_close */ - php_stream_http_stream_stat, - NULL, /* stat_url */ - NULL, /* opendir */ - "HTTP" -}; - -php_stream_wrapper php_stream_http_wrapper = { - &http_stream_wops, - NULL, - 1 /* is_url */ -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/image.c b/ext/standard/image.c deleted file mode 100644 index 7ee3be27d9..0000000000 --- a/ext/standard/image.c +++ /dev/null @@ -1,1285 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include <stdio.h> -#if defined(NETWARE) && !defined(NEW_LIBC) -#include <sys/socket.h> -#endif -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif -#include "fopen_wrappers.h" -#include "ext/standard/fsock.h" -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include "php_image.h" - -#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) -#include "zlib.h" -#endif - -/* file type markers */ -PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'}; -PHPAPI const char php_sig_psd[4] = {'8', 'B', 'P', 'S'}; -PHPAPI const char php_sig_bmp[2] = {'B', 'M'}; -PHPAPI const char php_sig_swf[3] = {'F', 'W', 'S'}; -PHPAPI const char php_sig_swc[3] = {'C', 'W', 'S'}; -PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff}; -PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47, - (char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a}; -PHPAPI const char php_sig_tif_ii[4] = {'I','I', (char)0x2A, (char)0x00}; -PHPAPI const char php_sig_tif_mm[4] = {'M','M', (char)0x00, (char)0x2A}; -PHPAPI const char php_sig_jpc[3] = {(char)0xff, (char)0x4f, (char)0xff}; -PHPAPI const char php_sig_jp2[12] = {(char)0x00, (char)0x00, (char)0x00, (char)0x0c, - (char)0x6a, (char)0x50, (char)0x20, (char)0x20, - (char)0x0d, (char)0x0a, (char)0x87, (char)0x0a}; -PHPAPI const char php_sig_iff[4] = {'F','O','R','M'}; - -/* REMEMBER TO ADD MIME-TYPE TO FUNCTION php_image_type_to_mime_type */ -/* PCX must check first 64bytes and byte 0=0x0a and byte2 < 0x06 */ - -/* return info as a struct, to make expansion easier */ - -struct gfxinfo { - unsigned int width; - unsigned int height; - unsigned int bits; - unsigned int channels; -}; - -/* {{{ PHP_MINIT_FUNCTION(imagetypes) - * Register IMAGETYPE_<xxx> constants used by GetImageSize(), image_type_to_mime_type, ext/exif */ -PHP_MINIT_FUNCTION(imagetypes) -{ - REGISTER_LONG_CONSTANT("IMAGETYPE_GIF", IMAGE_FILETYPE_GIF, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG", IMAGE_FILETYPE_JPEG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_PNG", IMAGE_FILETYPE_PNG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_SWF", IMAGE_FILETYPE_SWF, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_PSD", IMAGE_FILETYPE_PSD, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_BMP", IMAGE_FILETYPE_BMP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_II", IMAGE_FILETYPE_TIFF_II, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_MM", IMAGE_FILETYPE_TIFF_MM, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JPC", IMAGE_FILETYPE_JPC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JP2", IMAGE_FILETYPE_JP2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JPX", IMAGE_FILETYPE_JPX, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JB2", IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT); -#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) - REGISTER_LONG_CONSTANT("IMAGETYPE_SWC", IMAGE_FILETYPE_SWC, CONST_CS | CONST_PERSISTENT); -#endif - REGISTER_LONG_CONSTANT("IMAGETYPE_IFF", IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP", IMAGE_FILETYPE_WBMP, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC, CONST_CS | CONST_PERSISTENT); /* keep alias */ - REGISTER_LONG_CONSTANT("IMAGETYPE_XBM", IMAGE_FILETYPE_XBM, CONST_CS | CONST_PERSISTENT); - return SUCCESS; -} -/* }}} */ - -/* {{{ php_handle_gif - * routine to handle GIF files. If only everything were that easy... ;} */ -static struct gfxinfo *php_handle_gif (php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned char dim[5]; - - if (php_stream_seek(stream, 3, SEEK_CUR)) - return NULL; - - if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim)) - return NULL; - - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - result->width = (unsigned int)dim[0] | (((unsigned int)dim[1])<<8); - result->height = (unsigned int)dim[2] | (((unsigned int)dim[3])<<8); - result->bits = dim[4]&0x80 ? ((((unsigned int)dim[4])&0x07) + 1) : 0; - result->channels = 3; /* allways */ - - return result; -} -/* }}} */ - -/* {{{ php_handle_psd - */ -static struct gfxinfo *php_handle_psd (php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned char dim[8]; - - if (php_stream_seek(stream, 11, SEEK_CUR)) - return NULL; - - if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim)) - return NULL; - - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - result->height = (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]); - result->width = (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]); - - return result; -} -/* }}} */ - -/* {{{ php_handle_bmp - */ -static struct gfxinfo *php_handle_bmp (php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned char dim[12]; - - if (php_stream_seek(stream, 15, SEEK_CUR)) - return NULL; - - if (php_stream_read(stream, dim, sizeof(dim)) != sizeof(dim)) - return NULL; - - result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo)); - result->width = (((unsigned int)dim[ 3]) << 24) + (((unsigned int)dim[ 2]) << 16) + (((unsigned int)dim[ 1]) << 8) + ((unsigned int) dim[ 0]); - result->height = (((unsigned int)dim[ 7]) << 24) + (((unsigned int)dim[ 6]) << 16) + (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]); - result->bits = (((unsigned int)dim[11]) << 8) + ((unsigned int)dim[10]); - - return result; -} -/* }}} */ - -/* {{{ php_swf_get_bits - * routines to handle SWF files. */ -static unsigned long int php_swf_get_bits (unsigned char* buffer, unsigned int pos, unsigned int count) -{ - unsigned int loop; - unsigned long int result = 0; - - for (loop = pos; loop < pos + count; loop++) - { - result = result + - ((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1)); - } - return result; -} -/* }}} */ - -#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) -/* {{{ php_handle_swc - */ -static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - - long bits; - unsigned char a[64]; - unsigned long len=64, szlength; - int factor=1,maxfactor=16; - int slength, status=0; - char *b, *buf=NULL, *bufz=NULL; - - b = ecalloc (1, len + 1); - - if (php_stream_seek(stream, 5, SEEK_CUR)) - return NULL; - - if (php_stream_read(stream, a, sizeof(a)) != sizeof(a)) - return NULL; - - if (uncompress(b, &len, a, sizeof(a)) != Z_OK) { - /* failed to decompress the file, will try reading the rest of the file */ - if (php_stream_seek(stream, 8, SEEK_SET)) - return NULL; - - slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0); - - /* - * zlib::uncompress() wants to know the output data length - * if none was given as a parameter - * we try from input length * 2 up to input length * 2^8 - * doubling it whenever it wasn't big enough - * that should be eneugh for all real life cases - */ - - do { - szlength=slength*(1<<factor++); - buf = (char *) erealloc(buf,szlength); - status = uncompress(buf, &szlength, bufz, slength); - } while ((status==Z_BUF_ERROR)&&(factor<maxfactor)); - - if (bufz) { - pefree(bufz, 0); - } - - if (status == Z_OK) { - memcpy(b, buf, len); - } - - if (buf) { - efree(buf); - } - } - - if (!status) { - result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo)); - bits = php_swf_get_bits (b, 0, 5); - result->width = (php_swf_get_bits (b, 5 + bits, bits) - - php_swf_get_bits (b, 5, bits)) / 20; - result->height = (php_swf_get_bits (b, 5 + (3 * bits), bits) - - php_swf_get_bits (b, 5 + (2 * bits), bits)) / 20; - } else { - result = NULL; - } - - efree (b); - return result; -} -/* }}} */ -#endif - -/* {{{ php_handle_swf - */ -static struct gfxinfo *php_handle_swf (php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - long bits; - unsigned char a[32]; - - if (php_stream_seek(stream, 5, SEEK_CUR)) - return NULL; - - if (php_stream_read(stream, a, sizeof(a)) != sizeof(a)) - return NULL; - - result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo)); - bits = php_swf_get_bits (a, 0, 5); - result->width = (php_swf_get_bits (a, 5 + bits, bits) - - php_swf_get_bits (a, 5, bits)) / 20; - result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) - - php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20; - result->bits = 0; - result->channels = 0; - return result; -} -/* }}} */ - -/* {{{ php_handle_png - * routine to handle PNG files */ -static struct gfxinfo *php_handle_png (php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned char dim[9]; -/* Width: 4 bytes - * Height: 4 bytes - * Bit depth: 1 byte - * Color type: 1 byte - * Compression method: 1 byte - * Filter method: 1 byte - * Interlace method: 1 byte - */ - - if (php_stream_seek(stream, 8, SEEK_CUR)) - return NULL; - - if((php_stream_read(stream, dim, sizeof(dim))) < sizeof(dim)) - return NULL; - - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - result->width = (((unsigned int)dim[0]) << 24) + (((unsigned int)dim[1]) << 16) + (((unsigned int)dim[2]) << 8) + ((unsigned int)dim[3]); - result->height = (((unsigned int)dim[4]) << 24) + (((unsigned int)dim[5]) << 16) + (((unsigned int)dim[6]) << 8) + ((unsigned int)dim[7]); - result->bits = (unsigned int)dim[8]; - return result; -} -/* }}} */ - -/* routines to handle JPEG data */ - -/* some defines for the different JPEG block types */ -#define M_SOF0 0xC0 /* Start Of Frame N */ -#define M_SOF1 0xC1 /* N indicates which compression process */ -#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 -#define M_EOI 0xD9 /* End Of Image (end of datastream) */ -#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ -#define M_APP0 0xe0 -#define M_APP1 0xe1 -#define M_APP2 0xe2 -#define M_APP3 0xe3 -#define M_APP4 0xe4 -#define M_APP5 0xe5 -#define M_APP6 0xe6 -#define M_APP7 0xe7 -#define M_APP8 0xe8 -#define M_APP9 0xe9 -#define M_APP10 0xea -#define M_APP11 0xeb -#define M_APP12 0xec -#define M_APP13 0xed -#define M_APP14 0xee -#define M_APP15 0xef -#define M_COM 0xFE /* COMment */ - -#define M_PSEUDO 0xFFD8 /* pseudo marker for start of image(byte 0) */ - -/* {{{ php_read2 - */ -static unsigned short php_read2(php_stream * stream TSRMLS_DC) -{ - unsigned char a[2]; - - /* just return 0 if we hit the end-of-file */ - if((php_stream_read(stream, a, sizeof(a))) <= 0) return 0; - - return (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]); -} -/* }}} */ - -/* {{{ php_next_marker - * get next marker byte from file */ -static unsigned int php_next_marker(php_stream * stream, int last_marker, int comment_correction, int ff_read TSRMLS_DC) -{ - int a=0, marker; - - /* get marker byte, swallowing possible padding */ - if ( last_marker==M_COM && comment_correction) { - /* some software does not count the length bytes of COM section */ - /* one company doing so is very much envolved in JPEG... so we accept too */ - /* by the way: some of those companies changed their code now... */ - comment_correction = 2; - } else { - last_marker = 0; - comment_correction = 0; - } - if ( ff_read) { - a = 1; /* already read 0xff in filetype detection */ - } - do { - if ((marker = php_stream_getc(stream)) == EOF) - { - return M_EOI;/* we hit EOF */ - } - if ( last_marker==M_COM && comment_correction>0) - { - if ( marker != 0xFF) - { - marker = 0xff; - comment_correction--; - } else { - last_marker = M_PSEUDO; /* stop skipping non 0xff for M_COM */ - } - } - if ( ++a > 10) - { - /* who knows the maxim amount of 0xff? though 7 */ - /* but found other implementations */ - return M_EOI; - } - } while ( marker == 0xff); - if ( a < 2) - { - return M_EOI; /* at least one 0xff is needed before marker code */ - } - if ( last_marker==M_COM && comment_correction) - { - return M_EOI; /* ah illegal: char after COM section not 0xFF */ - } - return (unsigned int)marker; -} -/* }}} */ - -/* {{{ php_skip_variable - * skip over a variable-length block; assumes proper length marker */ -static void php_skip_variable(php_stream * stream TSRMLS_DC) -{ - off_t length = ((unsigned int)php_read2(stream TSRMLS_CC)); - - length = length-2; - if (length) - { - php_stream_seek(stream, (long)length, SEEK_CUR); - } -} -/* }}} */ - -/* {{{ php_read_APP - */ -static void php_read_APP(php_stream * stream, unsigned int marker, zval *info TSRMLS_DC) -{ - unsigned short length; - unsigned char *buffer; - unsigned char markername[ 16 ]; - zval *tmp; - - length = php_read2(stream TSRMLS_CC); - length -= 2; /* length includes itself */ - - buffer = emalloc(length); - - if (php_stream_read(stream, buffer, (long) length) <= 0) { - efree(buffer); - return; - } - - sprintf(markername, "APP%d", marker - M_APP0); - - if (zend_hash_find(Z_ARRVAL_P(info), markername, strlen(markername)+1, (void **) &tmp) == FAILURE) { - /* XXX we onyl catch the 1st tag of it's kind! */ - add_assoc_stringl(info, markername, buffer, length, 1); - } - - efree(buffer); -} -/* }}} */ - -/* {{{ php_handle_jpeg - main loop to parse JPEG structure */ -static struct gfxinfo *php_handle_jpeg (php_stream * stream, pval *info TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned int marker = M_PSEUDO; - unsigned short length, ff_read=1; - - for (;;) { - marker = php_next_marker(stream, marker, 1, ff_read TSRMLS_CC); - ff_read = 0; - switch (marker) { - case M_SOF0: - case M_SOF1: - case M_SOF2: - case M_SOF3: - case M_SOF5: - case M_SOF6: - case M_SOF7: - case M_SOF9: - case M_SOF10: - case M_SOF11: - case M_SOF13: - case M_SOF14: - case M_SOF15: - if (result == NULL) { - /* handle SOFn block */ - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - length = php_read2(stream TSRMLS_CC); - result->bits = php_stream_getc(stream); - result->height = php_read2(stream TSRMLS_CC); - result->width = php_read2(stream TSRMLS_CC); - result->channels = php_stream_getc(stream); - if (!info || length<8) /* if we don't want an extanded info -> return */ - return result; - if (php_stream_seek(stream, length-8, SEEK_CUR)) /* file error after info */ - return result; - } else { - php_skip_variable(stream TSRMLS_CC); - } - break; - - case M_APP0: - case M_APP1: - case M_APP2: - case M_APP3: - case M_APP4: - case M_APP5: - case M_APP6: - case M_APP7: - case M_APP8: - case M_APP9: - case M_APP10: - case M_APP11: - case M_APP12: - case M_APP13: - case M_APP14: - case M_APP15: - if (info) { - php_read_APP(stream, marker, info TSRMLS_CC); /* read all the app markes... */ - } else { - php_skip_variable(stream TSRMLS_CC); - } - break; - - case M_SOS: - case M_EOI: - return result; /* we're about to hit image data, or are at EOF. stop processing. */ - - default: - php_skip_variable(stream TSRMLS_CC); /* anything else isn't interesting */ - break; - } - } - - return result; /* perhaps image broken -> no info but size */ -} -/* }}} */ - -/* {{{ php_read4 - */ -static unsigned int php_read4(php_stream * stream TSRMLS_DC) -{ - unsigned char a[4]; - - /* just return 0 if we hit the end-of-file */ - if ((php_stream_read(stream, a, sizeof(a))) != sizeof(a)) return 0; - - return (((unsigned int)a[0]) << 24) - + (((unsigned int)a[1]) << 16) - + (((unsigned int)a[2]) << 8) - + (((unsigned int)a[3])); -} -/* }}} */ - -/* {{{ JPEG 2000 Marker Codes */ -#define JPEG2000_MARKER_PREFIX 0xFF /* All marker codes start with this */ -#define JPEG2000_MARKER_SOC 0x4F /* Start of Codestream */ -#define JPEG2000_MARKER_SOT 0x90 /* Start of Tile part */ -#define JPEG2000_MARKER_SOD 0x93 /* Start of Data */ -#define JPEG2000_MARKER_EOC 0xD9 /* End of Codestream */ -#define JPEG2000_MARKER_SIZ 0x51 /* Image and tile size */ -#define JPEG2000_MARKER_COD 0x52 /* Coding style default */ -#define JPEG2000_MARKER_COC 0x53 /* Coding style component */ -#define JPEG2000_MARKER_RGN 0x5E /* Region of interest */ -#define JPEG2000_MARKER_QCD 0x5C /* Quantization default */ -#define JPEG2000_MARKER_QCC 0x5D /* Quantization component */ -#define JPEG2000_MARKER_POC 0x5F /* Progression order change */ -#define JPEG2000_MARKER_TLM 0x55 /* Tile-part lengths */ -#define JPEG2000_MARKER_PLM 0x57 /* Packet length, main header */ -#define JPEG2000_MARKER_PLT 0x58 /* Packet length, tile-part header */ -#define JPEG2000_MARKER_PPM 0x60 /* Packed packet headers, main header */ -#define JPEG2000_MARKER_PPT 0x61 /* Packed packet headers, tile part header */ -#define JPEG2000_MARKER_SOP 0x91 /* Start of packet */ -#define JPEG2000_MARKER_EPH 0x92 /* End of packet header */ -#define JPEG2000_MARKER_CRG 0x63 /* Component registration */ -#define JPEG2000_MARKER_COM 0x64 /* Comment */ -/* }}} */ - -/* {{{ php_handle_jpc - Main loop to parse JPEG2000 raw codestream structure */ -static struct gfxinfo *php_handle_jpc(php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned short dummy_short; - int dummy_int, highest_bit_depth, bit_depth; - unsigned char first_marker_id; - unsigned int i; - - /* JPEG 2000 components can be vastly different from one another. - Each component can be sampled at a different resolution, use - a different colour space, have a seperate colour depth, and - be compressed totally differently! This makes giving a single - "bit depth" answer somewhat problematic. For this implementation - we'll use the highest depth encountered. */ - - /* Get the single byte that remains after the file type indentification */ - first_marker_id = php_stream_getc(stream); - - /* Ensure that this marker is SIZ (as is mandated by the standard) */ - if (first_marker_id != JPEG2000_MARKER_SIZ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "JPEG2000 codestream corrupt(Expected SIZ marker not found after SOC)"); - return NULL; - } - - result = (struct gfxinfo *)ecalloc(1, sizeof(struct gfxinfo)); - - dummy_short = php_read2(stream TSRMLS_CC); /* Lsiz */ - dummy_short = php_read2(stream TSRMLS_CC); /* Rsiz */ - result->height = php_read4(stream TSRMLS_CC); /* Xsiz */ - result->width = php_read4(stream TSRMLS_CC); /* Ysiz */ - - dummy_int = php_read4(stream TSRMLS_CC); /* XOsiz */ - dummy_int = php_read4(stream TSRMLS_CC); /* YOsiz */ - dummy_int = php_read4(stream TSRMLS_CC); /* XTsiz */ - dummy_int = php_read4(stream TSRMLS_CC); /* YTsiz */ - dummy_int = php_read4(stream TSRMLS_CC); /* XTOsiz */ - dummy_int = php_read4(stream TSRMLS_CC); /* YTOsiz */ - - result->channels = php_read2(stream TSRMLS_CC); /* Csiz */ - - /* Collect bit depth info */ - highest_bit_depth = bit_depth = 0; - for (i = 0; i < result->channels; i++) { - bit_depth = php_stream_getc(stream); /* Ssiz[i] */ - bit_depth++; - if (bit_depth > highest_bit_depth) { - highest_bit_depth = bit_depth; - } - - php_stream_getc(stream); /* XRsiz[i] */ - php_stream_getc(stream); /* YRsiz[i] */ - } - - result->bits = highest_bit_depth; - - return result; -} -/* }}} */ - -/* {{{ php_handle_jp2 - main loop to parse JPEG 2000 JP2 wrapper format structure */ -static struct gfxinfo *php_handle_jp2(php_stream *stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned int box_length; - unsigned int box_type; - char jp2c_box_id[] = {(char)0x6a, (char)0x70, (char)0x32, (char)0x63}; - - /* JP2 is a wrapper format for JPEG 2000. Data is contained within "boxes". - Boxes themselves can be contained within "super-boxes". Super-Boxes can - contain super-boxes which provides us with a hierarchical storage system. - - It is valid for a JP2 file to contain multiple individual codestreams. - We'll just look for the first codestream at the root of the box structure - and handle that. - */ - - for (;;) - { - box_length = php_read4(stream TSRMLS_CC); /* LBox */ - /* TBox */ - if (php_stream_read(stream, (void *)&box_type, sizeof(box_type)) != sizeof(box_type)) { - /* Use this as a general "out of stream" error */ - break; - } - - if (box_length == 1) { - /* We won't handle XLBoxes */ - return NULL; - } - - if (!memcmp(&box_type, jp2c_box_id, 4)) - { - /* Skip the first 3 bytes to emulate the file type examination */ - php_stream_seek(stream, 3, SEEK_CUR); - - result = php_handle_jpc(stream TSRMLS_CC); - break; - } - - /* Skip over LBox (Which includes both TBox and LBox itself */ - php_stream_seek(stream, box_length - 8, SEEK_CUR); - } - - if (result == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "JP2 file has no codestreams at root level"); - } - - return result; -} -/* }}} */ - -/* {{{ tiff constants - */ -PHPAPI const int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}; - -/* uncompressed only */ -#define TAG_IMAGEWIDTH 0x0100 -#define TAG_IMAGEHEIGHT 0x0101 -/* compressed images only */ -#define TAG_COMP_IMAGEWIDTH 0xA002 -#define TAG_COMP_IMAGEHEIGHT 0xA003 - -#define TAG_FMT_BYTE 1 -#define TAG_FMT_STRING 2 -#define TAG_FMT_USHORT 3 -#define TAG_FMT_ULONG 4 -#define TAG_FMT_URATIONAL 5 -#define TAG_FMT_SBYTE 6 -#define TAG_FMT_UNDEFINED 7 -#define TAG_FMT_SSHORT 8 -#define TAG_FMT_SLONG 9 -#define TAG_FMT_SRATIONAL 10 -#define TAG_FMT_SINGLE 11 -#define TAG_FMT_DOUBLE 12 -/* }}} */ - -/* {{{ php_ifd_get16u - * Convert a 16 bit unsigned value from file's native byte order */ -static int php_ifd_get16u(void *Short, int motorola_intel) -{ - if (motorola_intel) { - return (((unsigned char *)Short)[0] << 8) | ((unsigned char *)Short)[1]; - } else { - return (((unsigned char *)Short)[1] << 8) | ((unsigned char *)Short)[0]; - } -} -/* }}} */ - -/* {{{ php_ifd_get16s - * Convert a 16 bit signed value from file's native byte order */ -static signed short php_ifd_get16s(void *Short, int motorola_intel) -{ - return (signed short)php_ifd_get16u(Short, motorola_intel); -} -/* }}} */ - -/* {{{ php_ifd_get32s - * Convert a 32 bit signed value from file's native byte order */ -static int php_ifd_get32s(void *Long, int motorola_intel) -{ - if (motorola_intel) { - return ((( char *)Long)[0] << 24) | (((unsigned char *)Long)[1] << 16) - | (((unsigned char *)Long)[2] << 8 ) | (((unsigned char *)Long)[3] << 0 ); - } else { - return ((( char *)Long)[3] << 24) | (((unsigned char *)Long)[2] << 16) - | (((unsigned char *)Long)[1] << 8 ) | (((unsigned char *)Long)[0] << 0 ); - } -} -/* }}} */ - -/* {{{ php_ifd_get32u - * Convert a 32 bit unsigned value from file's native byte order */ -static unsigned php_ifd_get32u(void *Long, int motorola_intel) -{ - return (unsigned)php_ifd_get32s(Long, motorola_intel) & 0xffffffff; -} -/* }}} */ - -/* {{{ php_handle_tiff - main loop to parse TIFF structure */ -static struct gfxinfo *php_handle_tiff (php_stream * stream, pval *info, int motorola_intel TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - int i, num_entries; - unsigned char *dir_entry; - size_t ifd_size, dir_size, entry_value, width=0, height=0, ifd_addr; - int entry_tag , entry_type; - char *ifd_data, ifd_ptr[4]; - - if (php_stream_read(stream, ifd_ptr, 4) != 4) - return NULL; - ifd_addr = php_ifd_get32u(ifd_ptr, motorola_intel); - if (php_stream_seek(stream, ifd_addr-8, SEEK_CUR)) - return NULL; - ifd_size = 2; - ifd_data = emalloc(ifd_size); - if (php_stream_read(stream, ifd_data, 2) != 2) { - efree(ifd_data); - return NULL; - } - num_entries = php_ifd_get16u(ifd_data, motorola_intel); - dir_size = 2/*num dir entries*/ +12/*length of entry*/*num_entries +4/* offset to next ifd (points to thumbnail or NULL)*/; - ifd_size = dir_size; - ifd_data = erealloc(ifd_data,ifd_size); - if (php_stream_read(stream, ifd_data+2, dir_size-2) != dir_size-2) { - efree(ifd_data); - return NULL; - } - /* now we have the directory we can look how long it should be */ - ifd_size = dir_size; - for(i=0;i<num_entries;i++) { - dir_entry = ifd_data+2+i*12; - entry_tag = php_ifd_get16u(dir_entry+0, motorola_intel); - entry_type = php_ifd_get16u(dir_entry+2, motorola_intel); - switch(entry_type) { - case TAG_FMT_BYTE: - case TAG_FMT_SBYTE: - entry_value = (size_t)(dir_entry[8]); - break; - case TAG_FMT_USHORT: - entry_value = php_ifd_get16u(dir_entry+8, motorola_intel); - break; - case TAG_FMT_SSHORT: - entry_value = php_ifd_get16s(dir_entry+8, motorola_intel); - break; - case TAG_FMT_ULONG: - entry_value = php_ifd_get32u(dir_entry+8, motorola_intel); - break; - case TAG_FMT_SLONG: - entry_value = php_ifd_get32s(dir_entry+8, motorola_intel); - break; - default: - continue; - } - switch(entry_tag) { - case TAG_IMAGEWIDTH: - case TAG_COMP_IMAGEWIDTH: - width = entry_value; - break; - case TAG_IMAGEHEIGHT: - case TAG_COMP_IMAGEHEIGHT: - height = entry_value; - break; - } - } - efree(ifd_data); - if ( width && height) { - /* not the same when in for-loop */ - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - result->height = height; - result->width = width; - result->bits = 0; - result->channels = 0; - return result; - } - return NULL; -} -/* }}} */ - -/* {{{ php_handle_psd - */ -static struct gfxinfo *php_handle_iff(php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = NULL; - unsigned char a[10]; - int chunkId; - int size; - - if (php_stream_read(stream, a, 8) != 8) - return NULL; - if (strncmp(a+4, "ILBM", 4) && strncmp(a+4, "PBM ", 4)) - return NULL; - - result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - - /* loop chunks to find BMHD chunk */ - do { - if (php_stream_read(stream, a, 8) != 8) { - efree(result); - return NULL; - } - chunkId = php_ifd_get32s(a+0, 1); - size = php_ifd_get32s(a+4, 1); - if ((size & 1) == 1) { - size++; - } - if (chunkId == 0x424d4844) { /* BMHD chunk */ - if (php_stream_read(stream, a, 9) != 9) { - efree(result); - return NULL; - } - result->width = php_ifd_get16s(a+0, 1); - result->height = php_ifd_get16s(a+2, 1); - result->bits = a[8] & 0xff; - result->channels = 0; - if (result->width > 0 && result->height > 0 && result->bits > 0 && result->bits < 33) - return result; - } else { - if (php_stream_seek(stream, size, SEEK_CUR)) { - efree(result); - return NULL; - } - } - } while (1); -} -/* }}} */ - -/* {{{ php_get_wbmp - * int WBMP file format type - * byte Header Type - * byte Extended Header - * byte Header Data (type 00 = multibyte) - * byte Header Data (type 11 = name/pairs) - * int Number of columns - * int Number of rows - */ -static int php_get_wbmp(php_stream *stream, struct gfxinfo **result, int check TSRMLS_DC) -{ - int i, width = 0, height = 0; - - if (php_stream_rewind(stream)) { - return 0; - } - - /* get type */ - if (php_stream_getc(stream) != 0) { - return 0; - } - - /* skip header */ - do { - i = php_stream_getc(stream); - if (i < 0) { - return 0; - } - } while (i & 0x80); - - /* get width */ - do { - i = php_stream_getc(stream); - if (i < 0) { - return 0; - } - width = (width << 7) | (i & 0x7f); - } while (i & 0x80); - - /* get height */ - do { - i = php_stream_getc(stream); - if (i < 0) { - return 0; - } - height = (height << 7) | (i & 0x7f); - } while (i & 0x80); - - if (!check) { - (*result)->width = width; - (*result)->height = height; - } - - return IMAGE_FILETYPE_WBMP; -} -/* }}} */ - -/* {{{ php_handle_wbmp -*/ -static struct gfxinfo *php_handle_wbmp(php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - - if (!php_get_wbmp(stream, &result, 0 TSRMLS_CC)) { - efree(result); - return NULL; - } - - return result; -} -/* }}} */ - -/* {{{ php_get_xbm - */ -static int php_get_xbm(php_stream *stream, struct gfxinfo **result TSRMLS_DC) -{ - char *fline; - char *iname; - char *type; - int value; - unsigned int width = 0, height = 0; - - if (result) { - *result = NULL; - } - if (php_stream_rewind(stream)) { - return 0; - } - while ((fline=php_stream_gets(stream, NULL, 0)) != NULL) { - iname = estrdup(fline); /* simple way to get necessary buffer of required size */ - if (sscanf(fline, "#define %s %d", iname, &value) == 2) { - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } - - if (!strcmp("width", type)) { - width = (unsigned int) value; - if (height) { - efree(iname); - break; - } - } - if (!strcmp("height", type)) { - height = (unsigned int) value; - if (width) { - efree(iname); - break; - } - } - } - efree(fline); - efree(iname); - } - if (fline) { - efree(fline); - } - - if (width && height) { - if (result) { - *result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - (*result)->width = width; - (*result)->height = height; - } - return IMAGE_FILETYPE_XBM; - } - - return 0; -} -/* }}} */ - -/* {{{ php_handle_xbm - */ -static struct gfxinfo *php_handle_xbm(php_stream * stream TSRMLS_DC) -{ - struct gfxinfo *result; - php_get_xbm(stream, &result TSRMLS_CC); - return result; -} -/* }}} */ - -/* {{{ php_image_type_to_mime_type - * Convert internal image_type to mime type */ -PHPAPI const char * php_image_type_to_mime_type(int image_type) -{ - switch( image_type) { - case IMAGE_FILETYPE_GIF: - return "image/gif"; - case IMAGE_FILETYPE_JPEG: - return "image/jpeg"; - case IMAGE_FILETYPE_PNG: - return "image/png"; - case IMAGE_FILETYPE_SWF: - case IMAGE_FILETYPE_SWC: - return "application/x-shockwave-flash"; - case IMAGE_FILETYPE_PSD: - return "image/psd"; - case IMAGE_FILETYPE_BMP: - return "image/bmp"; - case IMAGE_FILETYPE_TIFF_II: - case IMAGE_FILETYPE_TIFF_MM: - return "image/tiff"; - case IMAGE_FILETYPE_IFF: - return "image/iff"; - case IMAGE_FILETYPE_WBMP: - return "image/vnd.wap.wbmp"; - case IMAGE_FILETYPE_JPC: - return "application/octet-stream"; - case IMAGE_FILETYPE_JP2: - return "image/jp2"; - case IMAGE_FILETYPE_XBM: - return "image/xbm"; - default: - case IMAGE_FILETYPE_UNKNOWN: - return "application/octet-stream"; /* suppose binary format */ - } -} -/* }}} */ - -/* {{{ proto string image_type_to_mime_type(int imagetype) - Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */ -PHP_FUNCTION(image_type_to_mime_type) -{ - zval **p_image_type; - int arg_c = ZEND_NUM_ARGS(); - - if ((arg_c!=1) || zend_get_parameters_ex(arg_c, &p_image_type) == FAILURE) { - RETVAL_FALSE; - WRONG_PARAM_COUNT; - } - convert_to_long_ex(p_image_type); - ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(Z_LVAL_PP(p_image_type)), 1); -} -/* }}} */ - -/* {{{ php_imagetype - detect filetype from first bytes */ -PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC) -{ - char tmp[12]; - - if ( !filetype) filetype = tmp; - if((php_stream_read(stream, filetype, 3)) != 3) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!"); - return IMAGE_FILETYPE_UNKNOWN; - } - -/* BYTES READ: 3 */ - if (!memcmp(filetype, php_sig_gif, 3)) { - return IMAGE_FILETYPE_GIF; - } else if (!memcmp(filetype, php_sig_jpg, 3)) { - return IMAGE_FILETYPE_JPEG; - } else if (!memcmp(filetype, php_sig_png, 3)) { - if (php_stream_read(stream, filetype+3, 5) != 5) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!"); - return IMAGE_FILETYPE_UNKNOWN; - } - if (!memcmp(filetype, php_sig_png, 8)) { - return IMAGE_FILETYPE_PNG; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "PNG file corrupted by ASCII conversion"); - return IMAGE_FILETYPE_UNKNOWN; - } - } else if (!memcmp(filetype, php_sig_swf, 3)) { - return IMAGE_FILETYPE_SWF; - } else if (!memcmp(filetype, php_sig_swc, 3)) { - return IMAGE_FILETYPE_SWC; - } else if (!memcmp(filetype, php_sig_psd, 3)) { - return IMAGE_FILETYPE_PSD; - } else if (!memcmp(filetype, php_sig_bmp, 2)) { - return IMAGE_FILETYPE_BMP; - } else if (!memcmp(filetype, php_sig_jpc, 3)) { - return IMAGE_FILETYPE_JPC; - } - - if (php_stream_read(stream, filetype+3, 1) != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!"); - return IMAGE_FILETYPE_UNKNOWN; - } -/* BYTES READ: 4 */ - if (!memcmp(filetype, php_sig_tif_ii, 4)) { - return IMAGE_FILETYPE_TIFF_II; - } else - if (!memcmp(filetype, php_sig_tif_mm, 4)) { - return IMAGE_FILETYPE_TIFF_MM; - } - if (!memcmp(filetype, php_sig_iff, 4)) { - return IMAGE_FILETYPE_IFF; - } - - if (php_stream_read(stream, filetype+4, 8) != 8) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Read error!"); - return IMAGE_FILETYPE_UNKNOWN; - } -/* BYTES READ: 12 */ - if (!memcmp(filetype, php_sig_jp2, 12)) { - return IMAGE_FILETYPE_JP2; - } - -/* AFTER ALL ABOVE FAILED */ - if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) { - return IMAGE_FILETYPE_WBMP; - } - if (php_get_xbm(stream, NULL TSRMLS_CC)) { - return IMAGE_FILETYPE_XBM; - } - return IMAGE_FILETYPE_UNKNOWN; -} -/* }}} */ - -/* {{{ proto array getimagesize(string imagefile [, array info]) - Get the size of an image as 4-element array */ -PHP_FUNCTION(getimagesize) -{ - zval **arg1, **info = NULL; - int itype = 0; - char *temp; - struct gfxinfo *result = NULL; - php_stream * stream = NULL; - - switch(ZEND_NUM_ARGS()) { - - case 1: - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - RETVAL_FALSE; - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - break; - - case 2: - if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) { - RETVAL_FALSE; - WRONG_PARAM_COUNT; - } - zval_dtor(*info); - - array_init(*info); - - convert_to_string_ex(arg1); - break; - - default: - RETVAL_FALSE; - WRONG_PARAM_COUNT; - } - - stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); - - if (!stream) { - RETURN_FALSE; - } - - itype = php_getimagetype(stream, NULL TSRMLS_CC); - switch( itype) { - case IMAGE_FILETYPE_GIF: - result = php_handle_gif (stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_JPEG: - if (info) { - result = php_handle_jpeg(stream, *info TSRMLS_CC); - } else { - result = php_handle_jpeg(stream, NULL TSRMLS_CC); - } - break; - case IMAGE_FILETYPE_PNG: - result = php_handle_png(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_SWF: - result = php_handle_swf(stream TSRMLS_CC); - break; -#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) - case IMAGE_FILETYPE_SWC: - result = php_handle_swc(stream TSRMLS_CC); - break; -#endif - case IMAGE_FILETYPE_PSD: - result = php_handle_psd(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_BMP: - result = php_handle_bmp(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_TIFF_II: - result = php_handle_tiff(stream, NULL, 0 TSRMLS_CC); - break; - case IMAGE_FILETYPE_TIFF_MM: - result = php_handle_tiff(stream, NULL, 1 TSRMLS_CC); - break; - case IMAGE_FILETYPE_JPC: - result = php_handle_jpc(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_JP2: - result = php_handle_jp2(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_IFF: - result = php_handle_iff(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_WBMP: - result = php_handle_wbmp(stream TSRMLS_CC); - break; - case IMAGE_FILETYPE_XBM: - result = php_handle_xbm(stream TSRMLS_CC); - break; - default: - case IMAGE_FILETYPE_UNKNOWN: - break; - } - - php_stream_close(stream); - - if (result) { - array_init(return_value); - add_index_long(return_value, 0, result->width); - add_index_long(return_value, 1, result->height); - add_index_long(return_value, 2, itype); - spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height); - add_index_string(return_value, 3, temp, 0); - - if (result->bits != 0) { - add_assoc_long(return_value, "bits", result->bits); - } - if (result->channels != 0) { - add_assoc_long(return_value, "channels", result->channels); - } - add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1); - efree(result); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c deleted file mode 100644 index c6f0234cad..0000000000 --- a/ext/standard/incomplete_class.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#include "php.h" -#include "basic_functions.h" -#include "php_incomplete_class.h" - -#define INCOMPLETE_CLASS_MSG \ - "The script tried to execute a method or " \ - "access a property of an incomplete object. " \ - "Please ensure that the class definition <b>%s</b> of the object " \ - "you are trying to operate on was loaded _before_ " \ - "the session was started" - - -/* {{{ incomplete_class_message - */ -static void incomplete_class_message(zend_property_reference *ref, int error_type) -{ - char buf[1024]; - char *class_name; - TSRMLS_FETCH(); - - class_name = php_lookup_class_name(ref->object, NULL, 0); - - if (!class_name) - class_name = estrdup("unknown"); - - snprintf(buf, sizeof(buf)-1, INCOMPLETE_CLASS_MSG, class_name); - - efree(class_name); - - php_error_docref(NULL TSRMLS_CC, error_type, "%s", buf); -} -/* }}} */ - -/* {{{ incomplete_class_call_func - */ -static void incomplete_class_call_func(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference) -{ - incomplete_class_message(property_reference, E_ERROR); -} -/* }}} */ - -/* {{{ incomplete_class_set_property - */ -static int incomplete_class_set_property(zend_property_reference *property_reference, zval *value) -{ - incomplete_class_message(property_reference, E_NOTICE); - - /* does not reach this point */ - return (0); -} -/* }}} */ - -/* {{{ incomplete_class_get_property - */ -static zval incomplete_class_get_property(zend_property_reference *property_reference) -{ - zval foo; - - incomplete_class_message(property_reference, E_NOTICE); - - /* does not reach this point */ - memset(&foo, 0, sizeof(zval)); /* shut warnings up */ - return (foo); -} -/* }}} */ - -/* {{{ php_create_incomplete_class - */ -zend_class_entry *php_create_incomplete_class(TSRMLS_D) -{ - zend_class_entry incomplete_class; - - INIT_OVERLOADED_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL, - incomplete_class_call_func, - incomplete_class_get_property, - incomplete_class_set_property); - - return zend_register_internal_class(&incomplete_class TSRMLS_CC); -} -/* }}} */ - -/* {{{ php_lookup_class_name - */ -char *php_lookup_class_name(zval *object, size_t *nlen, zend_bool del) -{ - zval **val; - char *retval = NULL; - HashTable *object_properties; - TSRMLS_FETCH(); - - object_properties = Z_OBJPROP_P(object); - - if (zend_hash_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER), (void **) &val) == SUCCESS) { - retval = estrndup(Z_STRVAL_PP(val), Z_STRLEN_PP(val)); - - if (nlen) - *nlen = Z_STRLEN_PP(val); - - if (del) - zend_hash_del(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER)); - } - - return (retval); -} -/* }}} */ - -/* {{{ php_store_class_name - */ -void php_store_class_name(zval *object, const char *name, size_t len) -{ - zval *val; - TSRMLS_FETCH(); - - MAKE_STD_ZVAL(val); - - Z_TYPE_P(val) = IS_STRING; - Z_STRVAL_P(val) = estrndup(name, len); - Z_STRLEN_P(val) = len; - - zend_hash_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER), &val, sizeof(val), NULL); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/info.c b/ext/standard/info.c deleted file mode 100644 index 43a100fe3b..0000000000 --- a/ext/standard/info.c +++ /dev/null @@ -1,1001 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - | Colin Viebrock <colin@easydns.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_ini.h" -#include "php_globals.h" -#include "ext/standard/head.h" -#include "ext/standard/html.h" -#include "info.h" -#include "credits.h" -#include "css.h" -#include "SAPI.h" -#include <time.h> -#include "php_main.h" -#include "zend_globals.h" /* needs ELS */ -#include "zend_extensions.h" -#include "zend_highlight.h" -#ifdef HAVE_SYS_UTSNAME_H -#include <sys/utsname.h> -#endif - -#if HAVE_MBSTRING -#include "ext/mbstring/mbstring.h" -ZEND_EXTERN_MODULE_GLOBALS(mbstring) -#endif - -#if HAVE_ICONV -#include "ext/iconv/php_iconv.h" -ZEND_EXTERN_MODULE_GLOBALS(iconv) -#endif - -#define SECTION(name) if (PG(html_errors)) { \ - PUTS("<h2>" name "</h2>\n"); \ - } else { \ - php_info_print_table_start(); \ - php_info_print_table_header(1, name); \ - php_info_print_table_end(); \ - } \ - -PHPAPI extern char *php_ini_opened_path; -PHPAPI extern char *php_ini_scanned_files; - -/* {{{ _display_module_info - */ -static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC) -{ - int show_info_func = *((int *) arg); - - if (show_info_func && module->info_func) { - if (PG(html_errors)) { - php_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", module->name, module->name); - } else { - php_info_print_table_start(); - php_info_print_table_header(1, module->name); - php_info_print_table_end(); - } - module->info_func(module TSRMLS_CC); - } else if (!show_info_func && !module->info_func) { - if (PG(html_errors)) { - php_printf("<tr>"); - php_printf("<td>"); - php_printf("%s", module->name); - php_printf("</td></tr>\n"); - } else { - php_printf(module->name); - php_printf("\n"); - } - } - return 0; -} -/* }}} */ - -/* {{{ php_print_gpcse_array - */ -static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC) -{ - zval **data, **tmp, tmp2; - char *string_key; - uint string_len; - ulong num_key; - char *elem_esc = NULL; - - if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE - && (Z_TYPE_PP(data)==IS_ARRAY)) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(data)); - while (zend_hash_get_current_data(Z_ARRVAL_PP(data), (void **) &tmp) == SUCCESS) { - if (PG(html_errors)) { - PUTS("<tr>"); - PUTS("<td class=\"e\">"); - - } - - PUTS(name); - PUTS("[\""); - - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(data), &string_key, &string_len, &num_key, 0, NULL)) { - case HASH_KEY_IS_STRING: - if (PG(html_errors)) { - elem_esc = php_info_html_esc(string_key TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } else { - PUTS(string_key); - } - break; - case HASH_KEY_IS_LONG: - php_printf("%ld", num_key); - break; - } - PUTS("\"]"); - if (PG(html_errors)) { - PUTS("</td><td class=\"v\">"); - } else { - PUTS(" => "); - } - if (Z_TYPE_PP(tmp) == IS_ARRAY) { - if (PG(html_errors)) { - PUTS("<pre>"); - } - zend_print_zval_r(*tmp, 0 TSRMLS_CC); - if (PG(html_errors)) { - PUTS("</pre>"); - } - } else if (Z_TYPE_PP(tmp) != IS_STRING) { - tmp2 = **tmp; - zval_copy_ctor(&tmp2); - convert_to_string(&tmp2); - if (PG(html_errors)) { - if (Z_STRLEN(tmp2) == 0) { - PUTS("<i>no value</i>"); - } else { - elem_esc = php_info_html_esc(Z_STRVAL(tmp2) TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } - } else { - PUTS(Z_STRVAL(tmp2)); - } - zval_dtor(&tmp2); - } else { - if (PG(html_errors)) { - if (Z_STRLEN_PP(tmp) == 0) { - PUTS("<i>no value</i>"); - } else { - elem_esc = php_info_html_esc(Z_STRVAL_PP(tmp) TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } - } else { - PUTS(Z_STRVAL_PP(tmp)); - } - } - if (PG(html_errors)) { - PUTS("</td></tr>\n"); - } else { - PUTS("\n"); - } - zend_hash_move_forward(Z_ARRVAL_PP(data)); - } - } -} -/* }}} */ - -/* {{{ php_info_print_style - */ -void php_info_print_style(void) -{ - php_printf("<style type=\"text/css\"><!--\n"); - php_info_print_css(); - php_printf("//--></style>\n"); -} -/* }}} */ - - -/* {{{ php_info_html_esc - */ -PHPAPI char *php_info_html_esc(char *string TSRMLS_DC) -{ - int new_len; - return php_escape_html_entities(string, strlen(string), &new_len, 0, ENT_NOQUOTES, NULL TSRMLS_CC); -} -/* }}} */ - - -/* {{{ php_get_uname - */ -PHPAPI char *php_get_uname(char mode) -{ - char *php_uname; - char tmp_uname[256]; -#ifdef PHP_WIN32 - DWORD dwBuild=0; - DWORD dwVersion = GetVersion(); - DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); - DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); - DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1; - char ComputerName[MAX_COMPUTERNAME_LENGTH + 1]; - SYSTEM_INFO SysInfo; - - GetComputerName(ComputerName, &dwSize); - GetSystemInfo(&SysInfo); - - if (mode == 's') { - if (dwVersion < 0x80000000) { - php_uname = "Windows NT"; - } else { - php_uname = "Windows 9x"; - } - } else if (mode == 'r') { - snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion); - php_uname = tmp_uname; - } else if (mode == 'n') { - php_uname = ComputerName; - } else if (mode == 'v') { - dwBuild = (DWORD)(HIWORD(dwVersion)); - snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild); - php_uname = tmp_uname; - } else if (mode == 'm') { - switch (SysInfo.wProcessorArchitecture) { - case PROCESSOR_ARCHITECTURE_INTEL : - snprintf(tmp_uname, sizeof(tmp_uname), "i%d", SysInfo.dwProcessorType); - php_uname = tmp_uname; - break; - case PROCESSOR_ARCHITECTURE_MIPS : - php_uname = "MIPS R4000"; - php_uname = tmp_uname; - break; - case PROCESSOR_ARCHITECTURE_ALPHA : - snprintf(tmp_uname, sizeof(tmp_uname), "Alpha %d", SysInfo.wProcessorLevel); - php_uname = tmp_uname; - break; - case PROCESSOR_ARCHITECTURE_PPC : - snprintf(tmp_uname, sizeof(tmp_uname), "PPC 6%02d", SysInfo.wProcessorLevel); - php_uname = tmp_uname; - break; - case PROCESSOR_ARCHITECTURE_IA64 : - php_uname = "IA64"; - break; -#if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64) - case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 : - php_uname = "IA32"; - break; -#endif -#if defined(PROCESSOR_ARCHITECTURE_AMD64) - case PROCESSOR_ARCHITECTURE_AMD64 : - php_uname = "AMD64"; - break; -#endif - case PROCESSOR_ARCHITECTURE_UNKNOWN : - default : - php_uname = "Unknown"; - break; - } - } else { /* assume mode == 'a' */ - /* Get build numbers for Windows NT or Win95 */ - if (dwVersion < 0x80000000){ - dwBuild = (DWORD)(HIWORD(dwVersion)); - snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d", - "Windows NT", ComputerName, - dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild); - } else { - snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d", - "Windows 9x", ComputerName, - dwWindowsMajorVersion, dwWindowsMinorVersion); - } - php_uname = tmp_uname; - } -#else -#ifdef HAVE_SYS_UTSNAME_H - struct utsname buf; - if (uname((struct utsname *)&buf) == -1) { - php_uname = PHP_UNAME; - } else { - if (mode == 's') { - php_uname = buf.sysname; - } else if (mode == 'r') { - php_uname = buf.release; - } else if (mode == 'n') { - php_uname = buf.nodename; - } else if (mode == 'v') { - php_uname = buf.version; - } else if (mode == 'm') { - php_uname = buf.machine; - } else { /* assume mode == 'a' */ - snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s", - buf.sysname, buf.nodename, buf.release, buf.version, - buf.machine); - php_uname = tmp_uname; - } - } -#else - php_uname = PHP_UNAME; -#endif -#endif - return estrdup(php_uname); -} -/* }}} */ - - -/* {{{ php_print_info_htmlhead - */ -PHPAPI void php_print_info_htmlhead(TSRMLS_D) -{ - -/*** none of this is needed now *** - - const char *charset = NULL; - - if (SG(default_charset)) { - charset = SG(default_charset); - } - -#if HAVE_MBSTRING - if (php_ob_handler_used("mb_output_handler" TSRMLS_CC)) { - if (MBSTRG(current_http_output_encoding) == mbfl_no_encoding_pass) { - charset = "US-ASCII"; - } else { - charset = mbfl_no2preferred_mime_name(MBSTRG(current_http_output_encoding)); - } - } -#endif - -#if HAVE_ICONV - if (php_ob_handler_used("ob_iconv_handler" TSRMLS_CC)) { - charset = ICONVG(output_encoding); - } -#endif - - if (!charset || !charset[0]) { - charset = "US-ASCII"; - } - -*** none of that is needed now ***/ - - - PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"); - PUTS("<html>"); - PUTS("<head>\n"); - php_info_print_style(); - PUTS("<title>phpinfo()</title>"); -/* - php_printf("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n", charset); -*/ - PUTS("</head>\n"); - PUTS("<body><div class=\"center\">\n"); -} -/* }}} */ - -/* {{{ module_name_cmp */ -static int module_name_cmp(const void *a, const void *b TSRMLS_DC) -{ - Bucket *f = *((Bucket **) a); - Bucket *s = *((Bucket **) b); - - return strcmp(((zend_module_entry *)f->pData)->name, - ((zend_module_entry *)s->pData)->name); -} -/* }}} */ - -/* {{{ php_print_info - */ -PHPAPI void php_print_info(int flag TSRMLS_DC) -{ - char **env, *tmp1, *tmp2; - char *php_uname; - int expose_php = INI_INT("expose_php"); - time_t the_time; - struct tm *ta, tmbuf; - - the_time = time(NULL); - ta = php_localtime_r(&the_time, &tmbuf); - - if (PG(html_errors)) { - php_print_info_htmlhead(TSRMLS_C); - } else { - PUTS("phpinfo()\n"); - } - - if (flag & PHP_INFO_GENERAL) { - char *zend_version = get_zend_version(); - char temp_api[9]; - - php_uname = php_get_uname('a'); - - if (PG(html_errors)) { - php_info_print_box_start(1); - } - - if (expose_php && PG(html_errors)) { - PUTS("<a href=\"http://www.php.net/\"><img border=\"0\" src=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - if ((ta->tm_mon==3) && (ta->tm_mday==1)) { - PUTS("?="PHP_EGG_LOGO_GUID"\" alt=\"Thies!\" /></a>"); - } else { - PUTS("?="PHP_LOGO_GUID"\" alt=\"PHP Logo\" /></a>"); - } - } - - if (PG(html_errors)) { - php_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION); - } else { - php_info_print_table_row(2, "PHP Version", PHP_VERSION); - } - php_info_print_box_end(); - php_info_print_table_start(); - php_info_print_table_row(2, "System", php_uname ); - php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__ ); -#ifdef CONFIGURE_COMMAND - php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND ); -#endif - if (sapi_module.pretty_name) { - php_info_print_table_row(2, "Server API", sapi_module.pretty_name ); - } - -#ifdef VIRTUAL_DIR - php_info_print_table_row(2, "Virtual Directory Support", "enabled" ); -#else - php_info_print_table_row(2, "Virtual Directory Support", "disabled" ); -#endif - - php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH); - - if (strlen(PHP_CONFIG_FILE_SCAN_DIR)) { - php_info_print_table_row(2, "Scan this dir for additional .ini files", PHP_CONFIG_FILE_SCAN_DIR); - if (php_ini_scanned_files) { - php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files); - } - } - - snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION); - php_info_print_table_row(2, "PHP API", temp_api); - - snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO); - php_info_print_table_row(2, "PHP Extension", temp_api); - - snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO); - php_info_print_table_row(2, "Zend Extension", temp_api); - -#if ZEND_DEBUG - php_info_print_table_row(2, "Debug Build", "yes" ); -#else - php_info_print_table_row(2, "Debug Build", "no" ); -#endif - -#ifdef ZTS - php_info_print_table_row(2, "Thread Safety", "enabled" ); -#else - php_info_print_table_row(2, "Thread Safety", "disabled" ); -#endif - - { - HashTable *url_stream_wrappers_hash; - char *stream_protocol, *stream_protocols_buf = NULL; - int stream_protocol_len, stream_protocols_buf_len = 0; - - if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) { - for (zend_hash_internal_pointer_reset(url_stream_wrappers_hash); - zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, NULL, 0, NULL) == HASH_KEY_IS_STRING; - zend_hash_move_forward(url_stream_wrappers_hash)) { - stream_protocols_buf = erealloc(stream_protocols_buf, stream_protocols_buf_len + stream_protocol_len + 2 + 1); - memcpy(stream_protocols_buf + stream_protocols_buf_len, stream_protocol, stream_protocol_len); - stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len] = ','; - stream_protocols_buf[stream_protocols_buf_len + stream_protocol_len + 1] = ' '; - stream_protocols_buf_len += stream_protocol_len + 2; - } - if (stream_protocols_buf) { - stream_protocols_buf[stream_protocols_buf_len - 2] = ' '; - stream_protocols_buf[stream_protocols_buf_len] = 0; - php_info_print_table_row(2, "Registered PHP Streams", stream_protocols_buf); - efree(stream_protocols_buf); - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "Registered PHP Streams", "no streams registered"); - } - } else { - /* Any chances we will ever hit this? */ - php_info_print_table_row(2, "PHP Streams", "disabled"); /* ?? */ - } - } - - php_info_print_table_end(); - - /* Zend Engine */ - php_info_print_box_start(0); - if (expose_php && PG(html_errors)) { - PUTS("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - PUTS("?="ZEND_LOGO_GUID"\" alt=\"Zend logo\" /></a>\n"); - } - PUTS("This program makes use of the Zend Scripting Language Engine:"); - PUTS(PG(html_errors)?"<br />":"\n"); - zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC); - php_info_print_box_end(); - efree(php_uname); - } - - if ((flag & PHP_INFO_CREDITS) && expose_php && PG(html_errors)) { - php_info_print_hr(); - PUTS("<h1><a href=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">"); - PUTS("PHP Credits"); - PUTS("</a></h1>\n"); - } - - zend_ini_sort_entries(TSRMLS_C); - - if (flag & PHP_INFO_CONFIGURATION) { - php_info_print_hr(); - if (PG(html_errors)) { - PUTS("<h1>Configuration</h1>\n"); - } else { - SECTION("Configuration"); - } - SECTION("PHP Core"); - display_ini_entries(NULL); - } - - if (flag & PHP_INFO_MODULES) { - int show_info_func; - HashTable sorted_registry; - zend_module_entry tmp; - - zend_hash_init(&sorted_registry, 50, NULL, NULL, 1); - zend_hash_copy(&sorted_registry, &module_registry, NULL, &tmp, sizeof(zend_module_entry)); - zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC); - - show_info_func = 1; - zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) _display_module_info, &show_info_func TSRMLS_CC); - - SECTION("Additional Modules"); - php_info_print_table_start(); - php_info_print_table_header(1, "Module Name"); - show_info_func = 0; - zend_hash_apply_with_argument(&sorted_registry, (apply_func_arg_t) _display_module_info, &show_info_func TSRMLS_CC); - php_info_print_table_end(); - - zend_hash_destroy(&sorted_registry); - } - - if (flag & PHP_INFO_ENVIRONMENT) { - SECTION("Environment"); - php_info_print_table_start(); - php_info_print_table_header(2, "Variable", "Value"); - for (env=environ; env!=NULL && *env !=NULL; env++) { - tmp1 = estrdup(*env); - if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */ - efree(tmp1); - continue; - } - *tmp2 = 0; - tmp2++; - php_info_print_table_row(2, tmp1, tmp2); - efree(tmp1); - } - php_info_print_table_end(); - } - - if (flag & PHP_INFO_VARIABLES) { - pval **data; - - SECTION("PHP Variables"); - - php_info_print_table_start(); - php_info_print_table_header(2, "Variable", "Value"); - if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_PP(data)); - } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_PP(data)); - } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_PP(data)); - } - if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) { - php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_PP(data)); - } - php_print_gpcse_array("_FORM", sizeof("_FORM")-1 TSRMLS_CC); - php_print_gpcse_array("_GET", sizeof("_GET")-1 TSRMLS_CC); - php_print_gpcse_array("_POST", sizeof("_POST")-1 TSRMLS_CC); - php_print_gpcse_array("_FILES", sizeof("_FILES")-1 TSRMLS_CC); - php_print_gpcse_array("_COOKIE", sizeof("_COOKIE")-1 TSRMLS_CC); - php_print_gpcse_array("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); - php_print_gpcse_array("_ENV", sizeof("_ENV")-1 TSRMLS_CC); - php_info_print_table_end(); - } - - if (flag & PHP_INFO_LICENSE) { - if (PG(html_errors)) { - SECTION("PHP License"); - php_info_print_box_start(0); - PUTS("<p>\n"); - PUTS("This program is free software; you can redistribute it and/or modify "); - PUTS("it under the terms of the PHP License as published by the PHP Group "); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("</p>\n"); - PUTS("<p>"); - PUTS("This program is distributed in the hope that it will be useful, "); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of "); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("</p>\n"); - PUTS("<p>"); - PUTS("If you did not receive a copy of the PHP license, or have any questions about "); - PUTS("PHP licensing, please contact license@php.net.\n"); - PUTS("</p>\n"); - php_info_print_box_end(); - } else { - PUTS("\nPHP License\n"); - PUTS("This program is free software; you can redistribute it and/or modify\n"); - PUTS("it under the terms of the PHP License as published by the PHP Group\n"); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("\n"); - PUTS("This program is distributed in the hope that it will be useful,\n"); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("\n"); - PUTS("If you did not receive a copy of the PHP license, or have any\n"); - PUTS("questions about PHP licensing, please contact license@php.net.\n"); - } - } - if (PG(html_errors)) { - PUTS("</div></body></html>"); - } -} -/* }}} */ - - -PHPAPI void php_info_print_table_start() -{ - TSRMLS_FETCH(); - - if (PG(html_errors)) { - php_printf("<table border=\"0\" cellpadding=\"3\" width=\"600\">\n"); - } else { - php_printf("\n"); - } -} - -PHPAPI void php_info_print_table_end() -{ - TSRMLS_FETCH(); - - if (PG(html_errors)) { - php_printf("</table><br />\n"); - } - -} - -PHPAPI void php_info_print_box_start(int flag) -{ - TSRMLS_FETCH(); - - php_info_print_table_start(); - if (flag) { - if (PG(html_errors)) { - php_printf("<tr class=\"h\"><td>\n"); - } - } else { - if (PG(html_errors)) { - php_printf("<tr class=\"v\"><td>\n"); - } else { - php_printf("\n"); - } - } -} - -PHPAPI void php_info_print_box_end() -{ - TSRMLS_FETCH(); - - if (PG(html_errors)) { - php_printf("</td></tr>\n"); - } - php_info_print_table_end(); -} - -PHPAPI void php_info_print_hr() -{ - TSRMLS_FETCH(); - - if (PG(html_errors)) { - php_printf("<hr />\n"); - } else { - php_printf("\n\n _______________________________________________________________________\n\n"); - } -} - -PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) -{ - int spaces; - - TSRMLS_FETCH(); - - if (PG(html_errors)) { - php_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header ); - } else { - spaces = (74 - strlen(header)); - php_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " "); - } -} - -/* {{{ php_info_print_table_header - */ -PHPAPI void php_info_print_table_header(int num_cols, ...) -{ - int i; - va_list row_elements; - char *row_element; - - TSRMLS_FETCH(); - - va_start(row_elements, num_cols); - if (PG(html_errors)) { - php_printf("<tr class=\"h\">"); - } - for (i=0; i<num_cols; i++) { - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - row_element = " "; - } - if (PG(html_errors)) { - PUTS("<th>"); - PUTS(row_element); - PUTS("</th>"); - } else { - PUTS(row_element); - if (i < num_cols-1) { - PUTS(" => "); - } else { - PUTS("\n"); - } - } - } - if (PG(html_errors)) { - php_printf("</tr>\n"); - } - - va_end(row_elements); -} -/* }}} */ - -/* {{{ php_info_print_table_row - */ -PHPAPI void php_info_print_table_row(int num_cols, ...) -{ - int i; - va_list row_elements; - char *row_element; - char *elem_esc = NULL; -/* - int elem_esc_len; -*/ - - TSRMLS_FETCH(); - - va_start(row_elements, num_cols); - if (PG(html_errors)) { - php_printf("<tr>"); - } - for (i=0; i<num_cols; i++) { - if (PG(html_errors)) { - php_printf("<td class=\"%s\">", - (i==0 ? "e" : "v" ) - ); - } - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - if (PG(html_errors)) { - PUTS( "<i>no value</i>" ); - } else { - PUTS( " " ); - } - } else { - if (PG(html_errors)) { - elem_esc = php_info_html_esc(row_element TSRMLS_CC); - PUTS(elem_esc); - efree(elem_esc); - } else { - PUTS(row_element); - if (i < num_cols-1) { - PUTS(" => "); - } - } - } - if (PG(html_errors)) { - php_printf(" </td>"); - } else if (i == (num_cols - 1)) { - PUTS("\n"); - } - } - if (PG(html_errors)) { - php_printf("</tr>\n"); - } - - va_end(row_elements); -} -/* }}} */ - -/* {{{ register_phpinfo_constants - */ -void register_phpinfo_constants(INIT_FUNC_ARGS) -{ - REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_GENERAL", PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_SAPI", PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_MODULES", PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_DOCS", PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE", PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_QA", PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS); - REGISTER_LONG_CONSTANT("CREDITS_ALL", PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS); -} -/* }}} */ - -/* {{{ proto void phpinfo([int what]) - Output a page of useful information about PHP and the current request */ -PHP_FUNCTION(phpinfo) -{ - int argc = ZEND_NUM_ARGS(); - long flag; - - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &flag) == FAILURE) { - return; - } - - if(!argc) { - flag = PHP_INFO_ALL; - } - - /* Andale! Andale! Yee-Hah! */ - php_start_ob_buffer(NULL, 4096, 0 TSRMLS_CC); - php_print_info(flag TSRMLS_CC); - php_end_ob_buffer(1, 0 TSRMLS_CC); - - RETURN_TRUE; -} - -/* }}} */ - -/* {{{ proto string phpversion([string extension]) - Return the current PHP version */ -PHP_FUNCTION(phpversion) -{ - zval **arg; - int argc = ZEND_NUM_ARGS(); - - if (argc == 0) { - RETURN_STRING(PHP_VERSION, 1); - } else if (argc == 1 && zend_get_parameters_ex(1, &arg) == SUCCESS) { - char *version; - convert_to_string_ex(arg); - version = zend_get_module_version(Z_STRVAL_PP(arg)); - if (version == NULL) { - RETURN_FALSE; - } - RETURN_STRING(version, 1); - } else { - WRONG_PARAM_COUNT; - } -} -/* }}} */ - -/* {{{ proto void phpcredits([int flag]) - Prints the list of people who've contributed to the PHP project */ -PHP_FUNCTION(phpcredits) -{ - int argc = ZEND_NUM_ARGS(); - long flag; - - if (zend_parse_parameters(argc TSRMLS_CC, "|l", &flag) == FAILURE) { - return; - } - - if(!argc) { - flag = PHP_CREDITS_ALL; - } - - php_print_credits(flag); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto string php_logo_guid(void) - Return the special ID used to request the PHP logo in phpinfo screens*/ -PHP_FUNCTION(php_logo_guid) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1); -} -/* }}} */ - -/* {{{ proto string php_egg_logo_guid(void) - Return the special ID used to request the PHP logo in phpinfo screens*/ -PHP_FUNCTION(php_egg_logo_guid) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1); -} -/* }}} */ - -/* {{{ proto string zend_logo_guid(void) - Return the special ID used to request the Zend logo in phpinfo screens*/ -PHP_FUNCTION(zend_logo_guid) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1); -} -/* }}} */ - -/* {{{ proto string php_sapi_name(void) - Return the current SAPI module name */ -PHP_FUNCTION(php_sapi_name) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - if (sapi_module.name) { - RETURN_STRING(sapi_module.name, 1); - } else { - RETURN_FALSE; - } -} - -/* }}} */ - -/* {{{ proto string php_uname(void) - Return information about the system PHP was built on */ -PHP_FUNCTION(php_uname) -{ - char *mode = "a"; - int modelen; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) { - return; - } - RETURN_STRING(php_get_uname(*mode), 0); -} - -/* }}} */ - -/* {{{ proto string php_ini_scanned_files(void) - Return comma-separated string of .ini files parsed from the additional ini dir */ -PHP_FUNCTION(php_ini_scanned_files) -{ - if (strlen(PHP_CONFIG_FILE_SCAN_DIR)) { - RETURN_STRING(php_ini_scanned_files, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/info.h b/ext/standard/info.h deleted file mode 100644 index 69b65b364b..0000000000 --- a/ext/standard/info.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef INFO_H -#define INFO_H - -#define PHP_ENTRY_NAME_COLOR "#ccccff" -#define PHP_CONTENTS_COLOR "#cccccc" -#define PHP_HEADER_COLOR "#9999cc" - -#define PHP_INFO_GENERAL (1<<0) -#define PHP_INFO_CREDITS (1<<1) -#define PHP_INFO_CONFIGURATION (1<<2) -#define PHP_INFO_MODULES (1<<3) -#define PHP_INFO_ENVIRONMENT (1<<4) -#define PHP_INFO_VARIABLES (1<<5) -#define PHP_INFO_LICENSE (1<<6) -#define PHP_INFO_ALL 0xFFFFFFFF - -#ifndef HAVE_CREDITS_DEFS -#define HAVE_CREDITS_DEFS - -#define PHP_CREDITS_GROUP (1<<0) -#define PHP_CREDITS_GENERAL (1<<1) -#define PHP_CREDITS_SAPI (1<<2) -#define PHP_CREDITS_MODULES (1<<3) -#define PHP_CREDITS_DOCS (1<<4) -#define PHP_CREDITS_FULLPAGE (1<<5) -#define PHP_CREDITS_QA (1<<6) -#define PHP_CREDITS_WEB (1<<7) -#define PHP_CREDITS_ALL 0xFFFFFFFF - -#endif /* HAVE_CREDITS_DEFS */ - -#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42" -#define PHP_EGG_LOGO_GUID "PHPE9568F36-D428-11d2-A769-00AA001ACF42" -#define ZEND_LOGO_GUID "PHPE9568F35-D428-11d2-A769-00AA001ACF42" -#define PHP_CREDITS_GUID "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000" - -PHP_FUNCTION(phpversion); -PHP_FUNCTION(phpinfo); -PHP_FUNCTION(phpcredits); -PHP_FUNCTION(php_logo_guid); -PHP_FUNCTION(zend_logo_guid); -PHP_FUNCTION(php_egg_logo_guid); -PHP_FUNCTION(php_sapi_name); -PHP_FUNCTION(php_uname); -PHP_FUNCTION(php_ini_scanned_files); -PHPAPI char *php_info_html_esc(char *string TSRMLS_DC); -PHPAPI void php_print_info_htmlhead(TSRMLS_D); -PHPAPI void php_print_info(int flag TSRMLS_DC); -PHPAPI void php_print_style(void); -PHPAPI void php_info_print_style(void); -PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header); -PHPAPI void php_info_print_table_header(int num_cols, ...); -PHPAPI void php_info_print_table_row(int num_cols, ...); -PHPAPI void php_info_print_table_start(void); -PHPAPI void php_info_print_table_end(void); -PHPAPI void php_info_print_box_start(int bg); -PHPAPI void php_info_print_box_end(void); -PHPAPI void php_info_print_hr(void); - -void register_phpinfo_constants(INIT_FUNC_ARGS); - -#endif /* INFO_H */ diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c deleted file mode 100644 index 1e69dfa79b..0000000000 --- a/ext/standard/iptc.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* - * Functions to parse & compse IPTC data. - * PhotoShop >= 3.0 can read and write textual data to JPEG files. - * ... more to come ..... - * - * i know, parts of this is now duplicated in image.c - * but in this case i think it's okay! - */ - -/* - * TODO: - * - add IPTC translation table - */ - -#include "php.h" -#include "php_iptc.h" -#include "ext/standard/head.h" - -#include <sys/stat.h> - - -/* some defines for the different JPEG block types */ -#define M_SOF0 0xC0 /* Start Of Frame N */ -#define M_SOF1 0xC1 /* N indicates which compression process */ -#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */ -#define M_SOF3 0xC3 -#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */ -#define M_SOF6 0xC6 -#define M_SOF7 0xC7 -#define M_SOF9 0xC9 -#define M_SOF10 0xCA -#define M_SOF11 0xCB -#define M_SOF13 0xCD -#define M_SOF14 0xCE -#define M_SOF15 0xCF -#define M_SOI 0xD8 -#define M_EOI 0xD9 /* End Of Image (end of datastream) */ -#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ -#define M_APP0 0xe0 -#define M_APP1 0xe1 -#define M_APP2 0xe2 -#define M_APP3 0xe3 -#define M_APP4 0xe4 -#define M_APP5 0xe5 -#define M_APP6 0xe6 -#define M_APP7 0xe7 -#define M_APP8 0xe8 -#define M_APP9 0xe9 -#define M_APP10 0xea -#define M_APP11 0xeb -#define M_APP12 0xec -#define M_APP13 0xed -#define M_APP14 0xee -#define M_APP15 0xef - -/* {{{ php_iptc_put1 - */ -static int php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf TSRMLS_DC) -{ - if (spool > 0) - PUTC(c); - - if (spoolbuf) *(*spoolbuf)++ = c; - - return c; -} -/* }}} */ - -/* {{{ php_iptc_get1 - */ -static int php_iptc_get1(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC) -{ - int c; - char cc; - - c = getc(fp); - - if (c == EOF) return EOF; - - if (spool > 0) { - cc = c; - PUTC(cc); - } - - if (spoolbuf) *(*spoolbuf)++ = c; - - return c; -} -/* }}} */ - -/* {{{ php_iptc_read_remaining - */ -static int php_iptc_read_remaining(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC) -{ - while (php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC) != EOF) continue; - - return M_EOI; -} -/* }}} */ - -/* {{{ php_iptc_skip_variable - */ -static int php_iptc_skip_variable(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC) -{ - unsigned int length; - int c1, c2; - - if ((c1 = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF) return M_EOI; - - if ((c2 = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF) return M_EOI; - - length = (((unsigned char) c1) << 8) + ((unsigned char) c2); - - length -= 2; - - while (length--) - if (php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC) == EOF) return M_EOI; - - return 0; -} -/* }}} */ - -/* {{{ php_iptc_next_marker - */ -static int php_iptc_next_marker(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC) -{ - int c; - - /* skip unimportant stuff */ - - c = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC); - - if (c == EOF) return M_EOI; - - while (c != 0xff) { - if ((c = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF) - return M_EOI; /* we hit EOF */ - } - - /* get marker byte, swallowing possible padding */ - do { - c = php_iptc_get1(fp, 0, 0 TSRMLS_CC); - if (c == EOF) - return M_EOI; /* we hit EOF */ - else - if (c == 0xff) - php_iptc_put1(fp, spool, (unsigned char)c, spoolbuf TSRMLS_CC); - } while (c == 0xff); - - return (unsigned int) c; -} -/* }}} */ - -static char psheader[] = "\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0"; - -/* {{{ proto array iptcembed(string iptcdata, string jpeg_file_name [, int spool]) - Embed binary IPTC data into a JPEG image. */ -PHP_FUNCTION(iptcembed) -{ - zval **iptcdata, **jpeg_file, **spool_flag; - FILE *fp; - unsigned int marker; - unsigned int spool = 0, done = 0, inx, len; - unsigned char *spoolbuf=0, *poi=0; - struct stat sb; - - switch(ZEND_NUM_ARGS()){ - case 3: - if (zend_get_parameters_ex(3, &iptcdata, &jpeg_file, &spool_flag) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(iptcdata); - convert_to_string_ex(jpeg_file); - convert_to_long_ex(spool_flag); - spool = Z_LVAL_PP(spool_flag); - break; - - case 2: - if (zend_get_parameters_ex(2, &iptcdata, &jpeg_file) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(iptcdata); - convert_to_string_ex(jpeg_file); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - if (php_check_open_basedir(Z_STRVAL_PP(jpeg_file) TSRMLS_CC)) { - RETURN_FALSE; - } - - if ((fp = VCWD_FOPEN(Z_STRVAL_PP(jpeg_file), "rb")) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open %s", Z_STRVAL_PP(jpeg_file)); - RETURN_FALSE; - } - - len = Z_STRLEN_PP(iptcdata); - - if (spool < 2) { - fstat(fileno(fp), &sb); - - poi = spoolbuf = emalloc(len + sizeof(psheader) + sb.st_size + 1024); - - if (! spoolbuf) { - fclose(fp); - RETURN_FALSE; - } - } - - if (php_iptc_get1(fp, spool, poi?&poi:0 TSRMLS_CC) != 0xFF) { - fclose(fp); - RETURN_FALSE; - } - - if (php_iptc_get1(fp, spool, poi?&poi:0 TSRMLS_CC) != 0xD8) { - fclose(fp); - RETURN_FALSE; - } - - while (!done) { - marker = php_iptc_next_marker(fp, spool, poi?&poi:0 TSRMLS_CC); - - if (marker == M_EOI) { /* EOF */ - break; - } else if (marker != M_APP13) { - php_iptc_put1(fp, spool, (unsigned char)marker, poi?&poi:0 TSRMLS_CC); - } - - switch (marker) { - case M_APP13: - /* we are going to write a new APP13 marker, so don't output the old one */ - php_iptc_skip_variable(fp, 0, 0 TSRMLS_CC); - php_iptc_read_remaining(fp, spool, poi?&poi:0 TSRMLS_CC); - done = 1; - break; - - case M_APP0: - /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */ - php_iptc_skip_variable(fp, spool, poi?&poi:0 TSRMLS_CC); - - if (len & 1) len++; /* make the length even */ - - psheader[ 2 ] = (len+28)>>8; - psheader[ 3 ] = (len+28)&0xff; - - for (inx = 0; inx < 28; inx++) - php_iptc_put1(fp, spool, psheader[inx], poi?&poi:0 TSRMLS_CC); - - php_iptc_put1(fp, spool, (unsigned char)(len>>8), poi?&poi:0 TSRMLS_CC); - php_iptc_put1(fp, spool, (unsigned char)(len&0xff), poi?&poi:0 TSRMLS_CC); - - for (inx = 0; inx < len; inx++) - php_iptc_put1(fp, spool, Z_STRVAL_PP(iptcdata)[inx], poi?&poi:0 TSRMLS_CC); - break; - - case M_SOS: - /* we hit data, no more marker-inserting can be done! */ - php_iptc_read_remaining(fp, spool, poi?&poi:0 TSRMLS_CC); - done = 1; - break; - - default: - php_iptc_skip_variable(fp, spool, poi?&poi:0 TSRMLS_CC); - break; - } - } - - fclose(fp); - - if (spool < 2) { - RETVAL_STRINGL(spoolbuf, poi - spoolbuf, 0); - } else { - RETURN_TRUE; - } -} -/* }}} */ - -/* {{{ proto array iptcparse(string iptcdata) - Parse binary IPTC-data into associative array */ -PHP_FUNCTION(iptcparse) -{ - unsigned int length, inx, len, tagsfound; - unsigned char *buffer; - unsigned char recnum, dataset; - unsigned char key[ 16 ]; - zval *values, **str, **element; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - inx = 0; - length = Z_STRLEN_PP(str); - buffer = Z_STRVAL_PP(str); - - tagsfound = 0; /* number of tags already found */ - - while (inx < length) { /* find 1st tag */ - if ((buffer[inx] == 0x1c) && (buffer[inx+1] == 0x02)){ - break; - } else { - inx++; - } - } - - while (inx < length) { - if (buffer[ inx++ ] != 0x1c) { - break; /* we ran against some data which does not conform to IPTC - stop parsing! */ - } - - if ((inx + 4) >= length) - break; - - dataset = buffer[ inx++ ]; - recnum = buffer[ inx++ ]; - - if (buffer[ inx ] & (unsigned char) 0x80) { /* long tag */ - len = (((long) buffer[ inx + 2 ]) << 24) + (((long) buffer[ inx + 3 ]) << 16) + - (((long) buffer[ inx + 4 ]) << 8) + (((long) buffer[ inx + 5 ])); - inx += 6; - } else { /* short tag */ - len = (((unsigned short) buffer[ inx ])<<8) | (unsigned short)buffer[ inx+1 ]; - inx += 2; - } - - sprintf(key, "%d#%03d", (unsigned int) dataset, (unsigned int) recnum); - - if ((len > length) || (inx + len) > length) - break; - - if (tagsfound == 0) { /* found the 1st tag - initialize the return array */ - array_init(return_value); - } - - if (zend_hash_find(Z_ARRVAL_P(return_value), key, strlen(key) + 1, (void **) &element) == FAILURE) { - ALLOC_ZVAL(values); - INIT_PZVAL(values); - array_init(values); - - zend_hash_update(Z_ARRVAL_P(return_value), key, strlen(key)+1, (void *) &values, sizeof(pval*), (void **) &element); - } - - add_next_index_stringl(*element, buffer+inx, len, 1); - - inx += len; - - tagsfound++; - } - - if (! tagsfound) { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c deleted file mode 100644 index 13b74816bb..0000000000 --- a/ext/standard/lcg.c +++ /dev/null @@ -1,132 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_lcg.h" - -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#ifdef PHP_WIN32 -#include "win32/time.h" -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/timeval.h> -#else -#include "netware/time_nw.h" -#endif -#else -#include <sys/time.h> -#endif - -#ifdef ZTS -int lcg_globals_id; -#else -static php_lcg_globals lcg_globals; -#endif - - -#ifdef PHP_WIN32 -#include <process.h> -#endif - -/* - * combinedLCG() returns a pseudo random number in the range of (0, 1). - * The function combines two CGs with periods of - * 2^31 - 85 and 2^31 - 249. The period of this function - * is equal to the product of both primes. - */ - -#define MODMULT(a, b, c, m, s) q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m - -PHPAPI double php_combined_lcg(TSRMLS_D) -{ - php_int32 q; - php_int32 z; - - MODMULT(53668, 40014, 12211, 2147483563L, LCG(s1)); - MODMULT(52774, 40692, 3791, 2147483399L, LCG(s2)); - - z = LCG(s1) - LCG(s2); - if (z < 1) { - z += 2147483562; - } - - return z * 4.656613e-10; -} - -static void lcg_seed(TSRMLS_D) -{ - struct timeval tv; - - if (gettimeofday(&tv, NULL) == 0) { - LCG(s1) = tv.tv_sec ^ (~tv.tv_usec); - } else { - LCG(s1) = 1; - } -#ifdef ZTS - LCG(s2) = (long) tsrm_thread_id(); -#else - LCG(s2) = (long) getpid(); -#endif - - LCG(seeded) = 1; -} - -static void lcg_init_globals(php_lcg_globals *lcg_globals_p TSRMLS_DC) -{ - LCG(seeded) = 0; -} - -PHP_MINIT_FUNCTION(lcg) -{ -#ifdef ZTS - ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL); -#else - lcg_init_globals(&lcg_globals); -#endif - return SUCCESS; -} - -PHP_RINIT_FUNCTION(lcg) -{ - if (!LCG(seeded)) { - lcg_seed(TSRMLS_C); - } - return SUCCESS; -} - -/* {{{ proto float lcg_value() - Returns a value from the combined linear congruential generator */ -PHP_FUNCTION(lcg_value) -{ - RETURN_DOUBLE(php_combined_lcg(TSRMLS_C)); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c deleted file mode 100644 index e4a91c5167..0000000000 --- a/ext/standard/levenshtein.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include <stdlib.h> -#include <errno.h> -#include <ctype.h> -#include "php_string.h" - -#define LEVENSHTEIN_MAX_LENTH 255 - -/* {{{ reference_levdist - * reference implementation, only optimized for memory usage, not speed */ -static int reference_levdist(const char *s1, int l1, - const char *s2, int l2, - int cost_ins, int cost_rep, int cost_del ) -{ - int *p1, *p2, *tmp; - int i1, i2, c0, c1, c2; - - if(l1==0) return l2*cost_ins; - if(l2==0) return l1*cost_del; - - if((l1>LEVENSHTEIN_MAX_LENTH)||(l2>LEVENSHTEIN_MAX_LENTH)) - return -1; - - if(!(p1=emalloc((l2+1)*sizeof(int)))) { - return -2; - } - if(!(p2=emalloc((l2+1)*sizeof(int)))) { - free(p1); - return -2; - } - - for(i2=0;i2<=l2;i2++) - p1[i2] = i2*cost_ins; - - for(i1=0;i1<l1;i1++) - { - p2[0]=p1[0]+cost_del; - for(i2=0;i2<l2;i2++) - { - c0=p1[i2]+((s1[i1]==s2[i2])?0:cost_rep); - c1=p1[i2+1]+cost_del; if(c1<c0) c0=c1; - c2=p2[i2]+cost_ins; if(c2<c0) c0=c2; - p2[i2+1]=c0; - } - tmp=p1; p1=p2; p2=tmp; - } - - c0=p1[l2]; - - efree(p1); - efree(p2); - - return c0; -} -/* }}} */ - -/* {{{ custom_levdist - */ -static int custom_levdist(char *str1, char *str2, char *callback_name) -{ - TSRMLS_FETCH(); - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The general Levenshtein support is not there yet"); - /* not there yet */ - - return -1; -} -/* }}} */ - -/* {{{ proto int levenshtein(string str1, string str2) - Calculate Levenshtein distance between two strings */ -PHP_FUNCTION(levenshtein) -{ - zval **str1, **str2, **cost_ins, **cost_rep, **cost_del, **callback_name; - int distance=-1; - - switch(ZEND_NUM_ARGS()) { - case 2: /* just two string: use maximum performance version */ - if (zend_get_parameters_ex(2, &str1, &str2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str1); - convert_to_string_ex(str2); - - distance = reference_levdist(Z_STRVAL_PP(str1), Z_STRLEN_PP(str1), - Z_STRVAL_PP(str2), Z_STRLEN_PP(str2), 1, 1, 1); - - break; - - case 5: /* more general version: calc cost by ins/rep/del weights */ - if (zend_get_parameters_ex(5, &str1, &str2, &cost_ins, &cost_rep, &cost_del) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str1); - convert_to_string_ex(str2); - convert_to_long_ex(cost_ins); - convert_to_long_ex(cost_rep); - convert_to_long_ex(cost_del); - - distance = reference_levdist(Z_STRVAL_PP(str1), Z_STRLEN_PP(str1), - Z_STRVAL_PP(str2), Z_STRLEN_PP(str2), - Z_LVAL_PP(cost_ins), Z_LVAL_PP(cost_rep), - Z_LVAL_PP(cost_del)); - - break; - - case 3: /* most general version: calc cost by user-supplied function */ - if (zend_get_parameters_ex(3, &str1, &str2, &callback_name) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str1); - convert_to_string_ex(str2); - convert_to_string_ex(callback_name); - - distance = custom_levdist(Z_STRVAL_PP(str1), Z_STRVAL_PP(str2), - Z_STRVAL_PP(callback_name)); - break; - - default: - WRONG_PARAM_COUNT; - } - - if(distance<0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument string(s) too long"); - } - - RETURN_LONG(distance); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/link.c b/ext/standard/link.c deleted file mode 100644 index b70e9e68bf..0000000000 --- a/ext/standard/link.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_filestat.h" -#include "php_globals.h" - -#ifdef HAVE_SYMLINK - -#include <stdlib.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> -#include <string.h> -#if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#elif defined(NETWARE) -#include "netware/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#if HAVE_GRP_H -#ifdef PHP_WIN32 -#include "win32/grp.h" -#else -#include <grp.h> -#endif -#endif -#include <errno.h> -#include <ctype.h> - -#include "safe_mode.h" -#include "php_link.h" - -/* {{{ proto string readlink(string filename) - Return the target of a symbolic link */ -PHP_FUNCTION(readlink) -{ - zval **filename; - char buff[MAXPATHLEN]; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - ret = readlink(Z_STRVAL_PP(filename), buff, MAXPATHLEN-1); - - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - /* Append NULL to the end of the string */ - buff[ret] = '\0'; - - RETURN_STRING(buff, 1); -} -/* }}} */ - -/* {{{ proto int linkinfo(string filename) - Returns the st_dev field of the UNIX C stat structure describing the link */ -PHP_FUNCTION(linkinfo) -{ - zval **filename; -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc sb; -#else - struct stat sb; -#endif - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - ret = VCWD_LSTAT(Z_STRVAL_PP(filename), &sb); - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_LONG(-1L); - } - - RETURN_LONG((long) sb.st_dev); -} -/* }}} */ - -/* {{{ proto int symlink(string target, string link) - Create a symbolic link */ -PHP_FUNCTION(symlink) -{ - zval **topath, **frompath; - int ret; - char source_p[MAXPATHLEN]; - char dest_p[MAXPATHLEN]; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &topath, &frompath) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(topath); - convert_to_string_ex(frompath); - - expand_filepath(Z_STRVAL_PP(frompath), source_p TSRMLS_CC); - expand_filepath(Z_STRVAL_PP(topath), dest_p TSRMLS_CC); - - if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) || - php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ) - { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to symlink to a URL"); - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(dest_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(source_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (php_check_open_basedir(dest_p TSRMLS_CC)) { - RETURN_FALSE; - } - - if (php_check_open_basedir(source_p TSRMLS_CC)) { - RETURN_FALSE; - } - -#ifndef ZTS - ret = symlink(Z_STRVAL_PP(topath), Z_STRVAL_PP(frompath)); -#else - ret = symlink(dest_p, source_p); -#endif - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int link(string target, string link) - Create a hard link */ -PHP_FUNCTION(link) -{ - zval **topath, **frompath; - int ret; - char source_p[MAXPATHLEN]; - char dest_p[MAXPATHLEN]; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &topath, &frompath) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(topath); - convert_to_string_ex(frompath); - - expand_filepath(Z_STRVAL_PP(frompath), source_p TSRMLS_CC); - expand_filepath(Z_STRVAL_PP(topath), dest_p TSRMLS_CC); - - if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) || - php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ) - { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to link to a URL"); - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(dest_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (PG(safe_mode) && !php_checkuid(source_p, NULL, CHECKUID_CHECK_FILE_AND_DIR)) { - RETURN_FALSE; - } - - if (php_check_open_basedir(dest_p TSRMLS_CC)) { - RETURN_FALSE; - } - - if (php_check_open_basedir(source_p TSRMLS_CC)) { - RETURN_FALSE; - } - -#ifndef ZTS - ret = link(Z_STRVAL_PP(topath), Z_STRVAL_PP(frompath)); -#else - ret = link(dest_p, source_p); -#endif - if (ret == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -#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/ext/standard/mail.c b/ext/standard/mail.c deleted file mode 100644 index 6b4f701734..0000000000 --- a/ext/standard/mail.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include "php.h" -#include "ext/standard/info.h" - -#if HAVE_SYSEXITS_H -#include <sysexits.h> -#endif -#if HAVE_SYS_SYSEXITS_H -#include <sys/sysexits.h> -#endif - -#include "php_mail.h" -#include "php_ini.h" -#include "safe_mode.h" -#include "exec.h" - -#if HAVE_SENDMAIL -#ifdef PHP_WIN32 -#include "win32/sendmail.h" -#endif - -#ifdef NETWARE -#include "netware/pipe.h" /* For popen(), pclose() */ -#include "netware/sysexits.h" /* For exit status codes like EX_OK */ -#endif - -#define SKIP_LONG_HEADER_SEP(str, pos) \ - if (str[pos] == '\r' && str[pos + 1] == '\n' && (str[pos + 2] == ' ' || str[pos + 2] == '\t')) { \ - pos += 3; \ - while (str[pos] == ' ' || str[pos] == '\t') { \ - pos++; \ - } \ - continue; \ - } \ - -/* {{{ proto int ezmlm_hash(string addr) - Calculate EZMLM list hash value. */ -PHP_FUNCTION(ezmlm_hash) -{ - char *str = NULL; - unsigned long h = 5381L; - int j, str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &str, &str_len) == FAILURE) { - return; - } - - for (j = 0; j < str_len; j++) { - h = (h + (h << 5)) ^ (unsigned long) (unsigned char) tolower(str[j]); - } - - h = (h % 53); - - RETURN_LONG((int) h); -} -/* }}} */ - -/* {{{ proto int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]]) - Send an email message */ -PHP_FUNCTION(mail) -{ - char *to=NULL, *message=NULL, *headers=NULL; - char *subject=NULL, *extra_cmd=NULL; - int to_len, message_len, headers_len; - int subject_len, extra_cmd_len, i; - char *force_extra_parameters = INI_STR("mail_force_extra_parameters"); - - if (PG(safe_mode) && (ZEND_NUM_ARGS() == 5)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "SAFE MODE Restriction in effect. The fifth parameter is disabled in SAFE MODE."); - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|ss", - &to, &to_len, - &subject, &subject_len, - &message, &message_len, - &headers, &headers_len, - &extra_cmd, &extra_cmd_len - ) == FAILURE) { - return; - } - - if (to_len > 0) { - for (; to_len; to_len--) { - if (!isspace((unsigned char) to[to_len - 1])) { - break; - } - to[to_len - 1] = '\0'; - } - for (i = 0; to[i]; i++) { - if (iscntrl((unsigned char) to[i])) { - /* According to RFC 822, section 3.1.1 long headers may be separated into - * parts using CRLF followed at least one linear-white-space character ('\t' or ' '). - * To prevent these separators from being replaced with a space, we use the - * SKIP_LONG_HEADER_SEP to skip over them. - */ - SKIP_LONG_HEADER_SEP(to, i); - to[i] = ' '; - } - } - } - - if (subject_len > 0) { - for (; subject_len; subject_len--) { - if (!isspace((unsigned char) subject[subject_len - 1])) { - break; - } - subject[subject_len - 1] = '\0'; - } - for(i = 0; subject[i]; i++) { - if (iscntrl((unsigned char) subject[i])) { - SKIP_LONG_HEADER_SEP(subject, i); - subject[i] = ' '; - } - } - } - - if (force_extra_parameters) { - extra_cmd = estrdup(force_extra_parameters); - } else if (extra_cmd) { - extra_cmd = php_escape_shell_cmd(extra_cmd); - } - - if (php_mail(to, subject, message, headers, extra_cmd TSRMLS_CC)) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } - - if (extra_cmd) { - efree (extra_cmd); - } -} -/* }}} */ - -/* {{{ php_mail - */ -PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC) -{ -#if (defined PHP_WIN32 || defined NETWARE) - int tsm_err; - char *tsm_errmsg = NULL; -#endif - FILE *sendmail; - int ret; - char *sendmail_path = INI_STR("sendmail_path"); - char *sendmail_cmd = NULL; - - if (!sendmail_path) { -#if (defined PHP_WIN32 || defined NETWARE) - /* handle old style win smtp sending */ - if (TSendMail(INI_STR("SMTP"), &tsm_err, &tsm_errmsg, headers, subject, to, message, NULL, NULL, NULL) == FAILURE) { - if (tsm_errmsg) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", tsm_errmsg); - efree(tsm_errmsg); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", GetSMErrorText(tsm_err)); - } - return 0; - } - return 1; -#else - return 0; -#endif - } - if (extra_cmd != NULL) { - sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2); - strcpy (sendmail_cmd, sendmail_path); - strcat (sendmail_cmd, " "); - strcat (sendmail_cmd, extra_cmd); - } else { - sendmail_cmd = sendmail_path; - } - -#ifdef PHP_WIN32 - sendmail = popen(sendmail_cmd, "wb"); -#else - /* Since popen() doesn't indicate if the internal fork() doesn't work - * (e.g. the shell can't be executed) we explicitely set it to 0 to be - * sure we don't catch any older errno value. */ - errno = 0; - sendmail = popen(sendmail_cmd, "w"); -#endif - if (extra_cmd != NULL) - efree (sendmail_cmd); - - if (sendmail) { -#ifndef PHP_WIN32 - if (EACCES == errno) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Permission denied: unable to execute shell to run mail delivery binary"); - pclose(sendmail); - return 0; - } -#endif - fprintf(sendmail, "To: %s\n", to); - fprintf(sendmail, "Subject: %s\n", subject); - if (headers != NULL) { - fprintf(sendmail, "%s\n", headers); - } - fprintf(sendmail, "\n%s\n", message); - ret = pclose(sendmail); -#ifdef PHP_WIN32 - if (ret == -1) -#else -#if defined(EX_TEMPFAIL) - if ((ret != EX_OK)&&(ret != EX_TEMPFAIL)) -#elif defined(EX_OK) - if (ret != EX_OK) -#else - if (ret != 0) -#endif -#endif - { - return 0; - } else { - return 1; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not execute mail delivery program"); - return 0; - } - - return 1; /* never reached */ -} -/* }}} */ - -/* {{{ PHP_MINFO_FUNCTION - */ -PHP_MINFO_FUNCTION(mail) -{ - char *sendmail_path = INI_STR("sendmail_path"); - -#ifdef PHP_WIN32 - if (!sendmail_path) { - php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled"); - } else { - php_info_print_table_row(2, "Path to sendmail", sendmail_path); - } -#else - php_info_print_table_row(2, "Path to sendmail", sendmail_path); -#endif -} -/* }}} */ - -#else - -PHP_FUNCTION(mail) {} -PHP_MINFO_FUNCTION(mail) {} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/math.c b/ext/standard/math.c deleted file mode 100644 index 137b228d96..0000000000 --- a/ext/standard/math.c +++ /dev/null @@ -1,1150 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Jim Winstead <jimw@php.net> | - | Stig Sæther Bakken <ssb@fast.no> | - | Zeev Suraski <zeev@zend.com> | - | PHP 4.0 patches by Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_math.h" - -#include <math.h> -#include <float.h> -#include <stdlib.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -/* {{{ proto int abs(int number) - Return the absolute value of the number */ - -PHP_FUNCTION(abs) -{ - zval **value; - - if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_scalar_to_number_ex(value); - - if (Z_TYPE_PP(value) == IS_DOUBLE) { - RETURN_DOUBLE(fabs(Z_DVAL_PP(value))); - } else if (Z_TYPE_PP(value) == IS_LONG) { - if (Z_LVAL_PP(value) == LONG_MIN) { - RETURN_DOUBLE(-(double)LONG_MIN); - } else { - RETURN_LONG(Z_LVAL_PP(value) < 0 ? -Z_LVAL_PP(value) : Z_LVAL_PP(value)); - } - } - - RETURN_FALSE; -} - -/* }}} */ -/* {{{ proto float ceil(float number) - Returns the next highest integer value of the number */ -PHP_FUNCTION(ceil) -{ - zval **value; - - if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_scalar_to_number_ex(value); - - if (Z_TYPE_PP(value) == IS_DOUBLE) { - RETURN_DOUBLE(ceil(Z_DVAL_PP(value))); - } else if (Z_TYPE_PP(value) == IS_LONG) { - convert_to_double_ex(value); - RETURN_DOUBLE(Z_DVAL_PP(value)); - } - - RETURN_FALSE; -} - -/* }}} */ -/* {{{ proto float floor(float number) - Returns the next lowest integer value from the number */ -PHP_FUNCTION(floor) -{ - zval **value; - - if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_scalar_to_number_ex(value); - - if (Z_TYPE_PP(value) == IS_DOUBLE) { - RETURN_DOUBLE(floor(Z_DVAL_PP(value))); - } else if (Z_TYPE_PP(value) == IS_LONG) { - convert_to_double_ex(value); - RETURN_DOUBLE(Z_DVAL_PP(value)); - } - - RETURN_FALSE; -} - -/* }}} */ - - -/* {{{ proto float round(float number [, int precision]) - Returns the number rounded to specified precision */ -PHP_FUNCTION(round) -{ - zval **value, **precision; - int places = 0; - double f, return_val; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &value, &precision) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(precision); - places = (int) Z_LVAL_PP(precision); - } - - convert_scalar_to_number_ex(value); - - switch (Z_TYPE_PP(value)) { - case IS_LONG: - /* Simple case - long that doesn't need to be rounded. */ - if (places >= 0) { - RETURN_DOUBLE((double) Z_LVAL_PP(value)); - } - /* break omitted intentionally */ - - case IS_DOUBLE: - return_val = (Z_TYPE_PP(value) == IS_LONG) ? - (double)Z_LVAL_PP(value) : Z_DVAL_PP(value); - - f = pow(10.0, (double) places); - - return_val *= f; - if (return_val >= 0.0) - return_val = floor(return_val + 0.5); - else - return_val = ceil(return_val - 0.5); - return_val /= f; - - RETURN_DOUBLE(return_val); - break; - - default: - RETURN_FALSE; - break; - } -} -/* }}} */ -/* {{{ proto float sin(float number) - Returns the sine of the number in radians */ - -PHP_FUNCTION(sin) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = sin(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float cos(float number) - Returns the cosine of the number in radians */ - -PHP_FUNCTION(cos) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = cos(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ -/* {{{ proto float tan(float number) - Returns the tangent of the number in radians */ -PHP_FUNCTION(tan) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = tan(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float asin(float number) - Returns the arc sine of the number in radians */ - -PHP_FUNCTION(asin) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = asin(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float acos(float number) - Return the arc cosine of the number in radians */ - -PHP_FUNCTION(acos) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = acos(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float atan(float number) - Returns the arc tangent of the number in radians */ - -PHP_FUNCTION(atan) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = atan(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float atan2(float y, float x) - Returns the arc tangent of y/x, with the resulting quadrant determined by the signs of y and x */ - -PHP_FUNCTION(atan2) -{ - zval **num1, **num2; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &num1, &num2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num1); - convert_to_double_ex(num2); - Z_DVAL_P(return_value) = atan2(Z_DVAL_PP(num1), Z_DVAL_PP(num2)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float sinh(float number) - Returns the hyperbolic sine of the number, defined as (exp(number) - exp(-number))/2 */ - -PHP_FUNCTION(sinh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = sinh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float cosh(float number) - Returns the hyperbolic cosine of the number, defined as (exp(number) + exp(-number))/2 */ - -PHP_FUNCTION(cosh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = cosh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ -/* {{{ proto float tanh(float number) - Returns the hyperbolic tangent of the number, defined as sinh(number)/cosh(number) */ -PHP_FUNCTION(tanh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = tanh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ - -#if !defined(PHP_WIN32) && !defined(NETWARE) -#ifdef HAVE_ASINH -/* {{{ proto float asinh(float number) - Returns the inverse hyperbolic sine of the number, i.e. the value whose hyperbolic sine is number */ -PHP_FUNCTION(asinh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = asinh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ -#endif /* HAVE_ASINH */ - -#ifdef HAVE_ACOSH -/* {{{ proto float acosh(float number) - Returns the inverse hyperbolic cosine of the number, i.e. the value whose hyperbolic cosine is number */ -PHP_FUNCTION(acosh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = acosh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ -#endif /* HAVE_ACOSH */ - -#ifdef HAVE_ATANH -/* {{{ proto float atanh(float number) - Returns the inverse hyperbolic tangent of the number, i.e. the value whose hyperbolic tangent is number */ -PHP_FUNCTION(atanh) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = atanh(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ -#endif /* HAVE_ATANH */ -#endif /* !defined(PHP_WIN32) && !defined(NETWARE) */ - - -/* {{{ proto float pi(void) - Returns an approximation of pi */ -PHP_FUNCTION(pi) -{ - Z_DVAL_P(return_value) = M_PI; - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ - - -/* {{{ proto bool is_finite(float val) - Returns whether argument is finite */ -PHP_FUNCTION(is_finite) -{ - double dval; - - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) { - return; - } - RETURN_BOOL(zend_finite(dval)); -} -/* }}} */ - -/* {{{ proto bool is_infinite(float val) - Returns whether argument is infinite */ -PHP_FUNCTION(is_infinite) -{ - double dval; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) { - return; - } - RETURN_BOOL(zend_isinf(dval)); -} -/* }}} */ - -/* {{{ proto bool is_nan(float val) - Returns whether argument is not a number */ -PHP_FUNCTION(is_nan) -{ - double dval; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dval) == FAILURE) { - return; - } - RETURN_BOOL(zend_isnan(dval)); -} -/* }}} */ - -/* {{{ proto number pow(number base, number exponent) - Returns base raised to the power of exponent. Returns integer result when possible */ -PHP_FUNCTION(pow) -{ - zval *zbase, *zexp; - double dval; - zend_bool wantlong; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z/", &zbase, &zexp) == FAILURE) { - return; - } - - /* make sure we're dealing with numbers */ - convert_scalar_to_number(zbase TSRMLS_CC); - convert_scalar_to_number(zexp TSRMLS_CC); - - /* if both base and exponent were longs, we'll try to get a long out */ - wantlong = Z_TYPE_P(zbase) == IS_LONG - && Z_TYPE_P(zexp ) == IS_LONG && Z_LVAL_P(zexp) >= 0; - - convert_to_double(zbase); - convert_to_double(zexp); - - /* go ahead and calculate things. */ - dval = pow(Z_DVAL_P(zbase),Z_DVAL_P(zexp)); - - /* if we wanted a long, and dval < LONG_MAX, it must be a long. */ - if (wantlong && zend_finite(dval) && dval <= (double)LONG_MAX) { - RETURN_LONG((long)dval); - } - - /* otherwise just return the double. */ - RETURN_DOUBLE(dval); -} -/* }}} */ - -/* {{{ proto float exp(float number) - Returns e raised to the power of the number */ - -PHP_FUNCTION(exp) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = exp(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ - - -#if !defined(PHP_WIN32) && !defined(NETWARE) -/* {{{ proto float expm1(float number) - Returns exp(number) - 1, computed in a way that accurate even when the value of number is close to zero */ - -/* - WARNING: this function is expermental: it could change its name or - disappear in the next version of PHP! -*/ - -PHP_FUNCTION(expm1) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = expm1(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float log1p(float number) - Returns log(1 + number), computed in a way that accurate even when the value of number is close to zero */ - -/* - WARNING: this function is expermental: it could change its name or - disappear in the next version of PHP! -*/ - -PHP_FUNCTION(log1p) -{ -#ifdef HAVE_LOG1P - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = log1p(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -#endif -} - -/* }}} */ - -#endif -/* {{{ proto float log(float number, [float base]) - Returns the natural logarithm of the number, or the base log if base is specified */ - -PHP_FUNCTION(log) -{ - zval **num, **base; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - RETURN_DOUBLE(log(Z_DVAL_PP(num))); - case 2: - if (zend_get_parameters_ex(2, &num, &base) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - convert_to_double_ex(base); - - if (Z_DVAL_PP(base) <= 0.0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "base must be greater than 0"); - RETURN_FALSE; - } - RETURN_DOUBLE(log(Z_DVAL_PP(num)) / log(Z_DVAL_PP(base))); - default: - WRONG_PARAM_COUNT; - } -} - -/* }}} */ -/* {{{ proto float log10(float number) - Returns the base-10 logarithm of the number */ - -PHP_FUNCTION(log10) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = log10(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto float sqrt(float number) - Returns the square root of the number */ - -PHP_FUNCTION(sqrt) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - Z_DVAL_P(return_value) = sqrt(Z_DVAL_PP(num)); - Z_TYPE_P(return_value) = IS_DOUBLE; -} - -/* }}} */ - - -/* {{{ proto float hypot(float num1, float num2) - Returns sqrt(num1*num1 + num2*num2) */ - -/* - WARNING: this function is expermental: it could change its name or - disappear in the next version of PHP! -*/ - -PHP_FUNCTION(hypot) -{ -#ifdef HAVE_HYPOT - zval **num1, **num2; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &num1, &num2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num1); - convert_to_double_ex(num2); - Z_DVAL_P(return_value) = hypot(Z_DVAL_PP(num1), Z_DVAL_PP(num2)); - Z_TYPE_P(return_value) = IS_DOUBLE; -#endif -} - -/* }}} */ - -/* {{{ proto float deg2rad(float number) - Converts the number in degrees to the radian equivalent */ - -PHP_FUNCTION(deg2rad) -{ - zval **deg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, °) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(deg); - RETVAL_DOUBLE((Z_DVAL_PP(deg) / 180.0) * M_PI); -} - -/* }}} */ -/* {{{ proto float rad2deg(float number) - Converts the radian number to the equivalent number in degrees */ - -PHP_FUNCTION(rad2deg) -{ - zval **rad; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &rad) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(rad); - RETVAL_DOUBLE((Z_DVAL_PP(rad) / M_PI) * 180); -} - -/* }}} */ -/* {{{ _php_math_basetolong */ - -/* - * Convert a string representation of a base(2-36) number to a long. - */ -PHPAPI long -_php_math_basetolong(zval *arg, int base) { - long num = 0, digit, onum; - int i; - char c, *s; - - if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) { - return 0; - } - - s = Z_STRVAL_P(arg); - - for (i = Z_STRLEN_P(arg); i > 0; i--) { - c = *s++; - - digit = (c >= '0' && c <= '9') ? c - '0' - : (c >= 'A' && c <= 'Z') ? c - 'A' + 10 - : (c >= 'a' && c <= 'z') ? c - 'a' + 10 - : base; - - if (digit >= base) { - continue; - } - - onum = num; - num = num * base + digit; - if (num > onum) - continue; - - { - TSRMLS_FETCH(); - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number '%s' is too big to fit in long", s); - return LONG_MAX; - } - } - - return num; -} - -/* }}} */ -/* {{{ _php_math_longtobase */ - -/* {{{ _php_math_basetozval */ - -/* - * Convert a string representation of a base(2-36) number to a zval. - */ -PHPAPI int -_php_math_basetozval(zval *arg, int base, zval *ret) { - long num = 0; - double fnum = 0; - int i; - int mode = 0; - char c, *s; - long cutoff; - int cutlim; - - if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) { - return FAILURE; - } - - s = Z_STRVAL_P(arg); - - cutoff = LONG_MAX / base; - cutlim = LONG_MAX % base; - - for (i = Z_STRLEN_P(arg); i > 0; i--) { - c = *s++; - - /* might not work for EBCDIC */ - if (c >= '0' && c <= '9') - c -= '0'; - else if (c >= 'A' && c <= 'Z') - c -= 'A' - 10; - else if (c >= 'a' && c <= 'z') - c -= 'a' - 10; - else - continue; - - if (c >= base) - continue; - - switch (mode) { - case 0: /* Integer */ - if (num < cutoff || (num == cutoff && c <= cutlim)) { - num = num * base + c; - break; - } else { - fnum = num; - mode = 1; - } - /* fall-through */ - case 1: /* Float */ - fnum = fnum * base + c; - } - } - - if (mode == 1) { - ZVAL_DOUBLE(ret, fnum); - } else { - ZVAL_LONG(ret, num); - } - return SUCCESS; -} - -/* }}} */ -/* {{{ _php_math_longtobase */ - -/* - * Convert a long to a string containing a base(2-36) representation of - * the number. - */ -PHPAPI char * -_php_math_longtobase(zval *arg, int base) -{ - static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - char buf[(sizeof(unsigned long) << 3) + 1]; - char *ptr, *end; - unsigned long value; - - if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) { - return empty_string; - } - - value = Z_LVAL_P(arg); - - end = ptr = buf + sizeof(buf) - 1; - *ptr = '\0'; - - do { - *--ptr = digits[value % base]; - value /= base; - } while (ptr > buf && value); - - return estrndup(ptr, end - ptr); -} - -/* }}} */ -/* {{{ _php_math_zvaltobase */ - -/* - * Convert a zval to a string containing a base(2-36) representation of - * the number. - */ -PHPAPI char * -_php_math_zvaltobase(zval *arg, int base TSRMLS_DC) -{ - static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - - if ((Z_TYPE_P(arg) != IS_LONG && Z_TYPE_P(arg) != IS_DOUBLE) || base < 2 || base > 36) { - return empty_string; - } - - if (Z_TYPE_P(arg) == IS_DOUBLE) { - double fvalue = floor(Z_DVAL_P(arg)); /* floor it just in case */ - char *ptr, *end; - char buf[(sizeof(double) << 3) + 1]; - - /* Don't try to convert +/- infinity */ - if (fvalue == HUGE_VAL || fvalue == -HUGE_VAL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number too large"); - return empty_string; - } - - end = ptr = buf + sizeof(buf) - 1; - *ptr = '\0'; - - do { - *--ptr = digits[(int) fmod(fvalue, base)]; - fvalue /= base; - } while (ptr > buf && fabs(fvalue) >= 1); - - return estrndup(ptr, end - ptr); - } - - return _php_math_longtobase(arg, base); -} - -/* }}} */ -/* {{{ proto int bindec(string binary_number) - Returns the decimal equivalent of the binary number */ - -PHP_FUNCTION(bindec) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - if(_php_math_basetozval(*arg, 2, return_value) != SUCCESS) { - RETURN_FALSE; - } -} - -/* }}} */ -/* {{{ proto int hexdec(string hexadecimal_number) - Returns the decimal equivalent of the hexadecimal number */ - -PHP_FUNCTION(hexdec) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - if(_php_math_basetozval(*arg, 16, return_value) != SUCCESS) { - RETURN_FALSE; - } -} - -/* }}} */ -/* {{{ proto int octdec(string octal_number) - Returns the decimal equivalent of an octal string */ - -PHP_FUNCTION(octdec) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - if(_php_math_basetozval(*arg, 8, return_value) != SUCCESS) { - RETURN_FALSE; - } -} - -/* }}} */ -/* {{{ proto string decbin(int decimal_number) - Returns a string containing a binary representation of the number */ - -PHP_FUNCTION(decbin) -{ - zval **arg; - char *result; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(arg); - - result = _php_math_longtobase(*arg, 2); - Z_TYPE_P(return_value) = IS_STRING; - Z_STRLEN_P(return_value) = strlen(result); - Z_STRVAL_P(return_value) = result; -} - -/* }}} */ -/* {{{ proto string decoct(int decimal_number) - Returns a string containing an octal representation of the given number */ - -PHP_FUNCTION(decoct) -{ - zval **arg; - char *result; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(arg); - - result = _php_math_longtobase(*arg, 8); - Z_TYPE_P(return_value) = IS_STRING; - Z_STRLEN_P(return_value) = strlen(result); - Z_STRVAL_P(return_value) = result; -} - -/* }}} */ -/* {{{ proto string dechex(int decimal_number) - Returns a string containing a hexadecimal representation of the given number */ - -PHP_FUNCTION(dechex) -{ - zval **arg; - char *result; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(arg); - - result = _php_math_longtobase(*arg, 16); - Z_TYPE_P(return_value) = IS_STRING; - Z_STRLEN_P(return_value) = strlen(result); - Z_STRVAL_P(return_value) = result; -} - -/* }}} */ -/* {{{ proto string base_convert(string number, int frombase, int tobase) - Converts a number in a string from any base <= 36 to any base <= 36 */ - -PHP_FUNCTION(base_convert) -{ - zval **number, **frombase, **tobase, temp; - char *result; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &number, &frombase, &tobase) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(number); - convert_to_long_ex(frombase); - convert_to_long_ex(tobase); - if (Z_LVAL_PP(frombase) < 2 || Z_LVAL_PP(frombase) > 36) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `from base' (%d)", Z_LVAL_PP(frombase)); - RETURN_FALSE; - } - if (Z_LVAL_PP(tobase) < 2 || Z_LVAL_PP(tobase) > 36) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid `to base' (%d)", Z_LVAL_PP(tobase)); - RETURN_FALSE; - } - - if(_php_math_basetozval(*number, Z_LVAL_PP(frombase), &temp) != SUCCESS) { - RETURN_FALSE; - } - result = _php_math_zvaltobase(&temp, Z_LVAL_PP(tobase) TSRMLS_CC); - RETVAL_STRING(result, 0); -} - -/* }}} */ -/* {{{ _php_math_number_format */ - -PHPAPI char *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep) -{ - char *tmpbuf = NULL, *resbuf; - char *s, *t; /* source, target */ - char *dp; - int integral; - int tmplen, reslen=0; - int count=0; - int is_negative=0; - - if (d < 0) { - is_negative = 1; - d = -d; - } - dec = MAX(0, dec); - - tmplen = spprintf(&tmpbuf, 0, "%.*f", dec, d); - - if (tmpbuf == NULL || !isdigit((int)tmpbuf[0])) { - return tmpbuf; - } - - /* calculate the length of the return buffer */ - dp = strchr(tmpbuf, '.'); - if (dp) { - integral = dp - tmpbuf; - } else { - /* no decimal point was found */ - integral = tmplen; - } - - /* allow for thousand separators */ - if (thousand_sep) { - integral += (integral-1) / 3; - } - - reslen = integral; - - if (dec) { - reslen += 1 + dec; - } - - /* add a byte for minus sign */ - if (is_negative) { - reslen++; - } - resbuf = (char *) emalloc(reslen+1); /* +1 for NUL terminator */ - - s = tmpbuf+tmplen-1; - t = resbuf+reslen; - *t-- = '\0'; - - /* copy the decimal places. - * Take care, as the sprintf implementation may return less places than - * we requested due to internal buffer limitations */ - if (dec) { - int declen = dp ? strlen(dp+1) : 0; - int topad = declen > 0 ? dec - declen : 0; - - /* pad with '0's */ - - while (topad--) { - *t-- = '0'; - } - - if (dp) { - /* now copy the chars after the point */ - memcpy(t - declen + 1, dp + 1, declen); - - t -= declen; - s -= declen; - } - - /* add decimal point */ - *t-- = dec_point; - s--; - } - - /* copy the numbers before the decimal place, adding thousand - * separator every three digits */ - while(s >= tmpbuf) { - *t-- = *s--; - if (thousand_sep && (++count%3)==0 && s>=tmpbuf) { - *t-- = thousand_sep; - } - } - - /* and a minus sign, if needed */ - if (is_negative) { - *t-- = '-'; - } - - efree(tmpbuf); - - return resbuf; -} - -/* }}} */ -/* {{{ proto string number_format(float number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]]) - Formats a number with grouped thousands */ - -PHP_FUNCTION(number_format) -{ - zval **num, **dec, **t_s, **d_p; - char thousand_sep=',', dec_point='.'; - - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &num)==FAILURE) { - RETURN_FALSE; - } - convert_to_double_ex(num); - RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), 0, dec_point, thousand_sep), 0); - break; - case 2: - if (zend_get_parameters_ex(2, &num, &dec)==FAILURE) { - RETURN_FALSE; - } - convert_to_double_ex(num); - convert_to_long_ex(dec); - RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep), 0); - break; - case 4: - if (zend_get_parameters_ex(4, &num, &dec, &d_p, &t_s)==FAILURE) { - RETURN_FALSE; - } - convert_to_double_ex(num); - convert_to_long_ex(dec); - convert_to_string_ex(d_p); - convert_to_string_ex(t_s); - if (Z_STRLEN_PP(d_p)==1) { - dec_point=Z_STRVAL_PP(d_p)[0]; - } - if (Z_STRLEN_PP(t_s)==1) { - thousand_sep=Z_STRVAL_PP(t_s)[0]; - } else if(Z_STRLEN_PP(t_s)==0) { - thousand_sep=0; - } - RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep), 0); - break; - default: - WRONG_PARAM_COUNT; - break; - } -} -/* }}} */ - -/* {{{ proto float fmod(float x, float y) - Returns the remainder of dividing x by y as a float */ -PHP_FUNCTION(fmod) -{ - double num1, num2; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd", &num1, &num2) == FAILURE) { - return; - } - - Z_DVAL_P(return_value) = fmod(num1, num2); - Z_TYPE_P(return_value) = IS_DOUBLE; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/standard/md5.c b/ext/standard/md5.c deleted file mode 100644 index c833e09048..0000000000 --- a/ext/standard/md5.c +++ /dev/null @@ -1,446 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Lachlan Roche | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - * md5.c - Copyright 1997 Lachlan Roche - * md5_file() added by Alessandro Astarita <aleast@capri.it> - */ - -#include <stdio.h> -#include "php.h" - -#include "md5.h" - -PHPAPI void make_digest(char *md5str, unsigned char *digest) -{ - int i; - - for (i = 0; i < 16; i++) { - sprintf(md5str, "%02x", digest[i]); - md5str += 2; - } - - *md5str = '\0'; -} - -/* {{{ proto string md5(string str, [ bool raw_output]) - Calculate the md5 hash of a string */ -PHP_NAMED_FUNCTION(php_if_md5) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char md5str[33]; - PHP_MD5_CTX context; - unsigned char digest[16]; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - md5str[0] = '\0'; - PHP_MD5Init(&context); - PHP_MD5Update(&context, arg, arg_len); - PHP_MD5Final(digest, &context); - if (raw_output) { - RETURN_STRINGL(digest, 16, 1); - } else { - make_digest(md5str, digest); - RETVAL_STRING(md5str, 1); - } - -} -/* }}} */ - -/* {{{ proto string md5_file(string filename [, bool raw_output]) - Calculate the md5 hash of given filename */ -PHP_NAMED_FUNCTION(php_if_md5_file) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char md5str[33]; - unsigned char buf[1024]; - unsigned char digest[16]; - PHP_MD5_CTX context; - int n; - FILE *fp; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(arg TSRMLS_CC)) { - RETURN_FALSE; - } - - if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); - RETURN_FALSE; - } - - PHP_MD5Init(&context); - - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) { - PHP_MD5Update(&context, buf, n); - } - - PHP_MD5Final(digest, &context); - - if (ferror(fp)) { - fclose(fp); - RETURN_FALSE; - } - - fclose(fp); - - if (raw_output) { - RETURN_STRINGL(digest, 16, 1); - } else { - make_digest(md5str, digest); - RETVAL_STRING(md5str, 1); - } -} -/* }}} */ - -/* - * The remaining code is the reference MD5 code (md5c.c) from rfc1321 - */ -/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - rights reserved. - - License to copy and use this software is granted provided that it - is identified as the "RSA Data Security, Inc. MD5 Message-Digest - Algorithm" in all material mentioning or referencing this software - or this function. - - License is also granted to make and use derivative works provided - that such works are identified as "derived from the RSA Data - Security, Inc. MD5 Message-Digest Algorithm" in all material - mentioning or referencing the derived work. - - RSA Data Security, Inc. makes no representations concerning either - the merchantability of this software or the suitability of this - software for any particular purpose. It is provided "as is" - without express or implied warranty of any kind. - - These notices must be retained in any copies of any part of this - documentation and/or software. - */ - -/* Constants for MD5Transform routine. - */ - - -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -static void MD5Transform(php_uint32[4], const unsigned char[64]); -static void Encode(unsigned char *, php_uint32 *, unsigned int); -static void Decode(php_uint32 *, const unsigned char *, unsigned int); - -static unsigned char PADDING[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* F, G, H and I are basic MD5 functions. - */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~z))) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - Rotation is separate from addition to prevent recomputation. - */ -#define FF(a, b, c, d, x, s, ac) { \ - (a) += F ((b), (c), (d)) + (x) + (php_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (php_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (php_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (php_uint32)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } - -/* {{{ PHP_MD5Init - * MD5 initialization. Begins an MD5 operation, writing a new context. - */ -PHPAPI void PHP_MD5Init(PHP_MD5_CTX * context) -{ - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; -} -/* }}} */ - -/* {{{ PHP_MD5Update - MD5 block update operation. Continues an MD5 message-digest - operation, processing another message block, and updating the - context. - */ -PHPAPI void PHP_MD5Update(PHP_MD5_CTX * context, const unsigned char *input, - unsigned int inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((php_uint32) inputLen << 3)) - < ((php_uint32) inputLen << 3)) - context->count[1]++; - context->count[1] += ((php_uint32) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); - MD5Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - MD5Transform(context->state, &input[i]); - - index = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], - inputLen - i); -} -/* }}} */ - -/* {{{ PHP_MD5Final - MD5 finalization. Ends an MD5 message-digest operation, writing the - the message digest and zeroizing the context. - */ -PHPAPI void PHP_MD5Final(unsigned char digest[16], PHP_MD5_CTX * context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - Encode(bits, context->count, 8); - - /* Pad out to 56 mod 64. - */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - PHP_MD5Update(context, PADDING, padLen); - - /* Append length (before padding) */ - PHP_MD5Update(context, bits, 8); - - /* Store state in digest */ - Encode(digest, context->state, 16); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -/* {{{ MD5Transform - * MD5 basic transformation. Transforms state based on block. - */ -static void MD5Transform(state, block) -php_uint32 state[4]; -const unsigned char block[64]; -{ - php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - - Decode(x, block, 64); - - /* Round 1 */ - FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */ - FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */ - FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */ - FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */ - FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */ - FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */ - FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */ - FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */ - FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */ - FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */ - FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */ - GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */ - GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */ - GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */ - GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */ - GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */ - GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */ - GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */ - GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */ - GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */ - GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */ - HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */ - HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */ - HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */ - HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */ - HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */ - HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */ - HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */ - HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */ - HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */ - II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */ - II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */ - II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */ - II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */ - II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */ - II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */ - II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */ - II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */ - II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - /* Zeroize sensitive information. */ - memset((unsigned char*) x, 0, sizeof(x)); -} -/* }}} */ - -/* {{{ Encode - Encodes input (php_uint32) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void Encode(output, input, len) -unsigned char *output; -php_uint32 *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char) (input[i] & 0xff); - output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff); - output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff); - output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff); - } -} -/* }}} */ - -/* {{{ Decode - Decodes input (unsigned char) into output (php_uint32). Assumes len is - a multiple of 4. - */ -static void Decode(output, input, len) -php_uint32 *output; -const unsigned char *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) | - (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/md5.h b/ext/standard/md5.h deleted file mode 100644 index f355ea7627..0000000000 --- a/ext/standard/md5.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef MD5_H -#define MD5_H -/* MD5.H - header file for MD5C.C - */ - -/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All - rights reserved. - - License to copy and use this software is granted provided that it - is identified as the "RSA Data Security, Inc. MD5 Message-Digest - Algorithm" in all material mentioning or referencing this software - or this function. - - License is also granted to make and use derivative works provided - that such works are identified as "derived from the RSA Data - Security, Inc. MD5 Message-Digest Algorithm" in all material - mentioning or referencing the derived work. - - RSA Data Security, Inc. makes no representations concerning either - the merchantability of this software or the suitability of this - software for any particular purpose. It is provided "as is" - without express or implied warranty of any kind. - - These notices must be retained in any copies of any part of this - documentation and/or software. - */ - -#include "ext/standard/basic_functions.h" - -/* MD5 context. */ -typedef struct { - php_uint32 state[4]; /* state (ABCD) */ - php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} PHP_MD5_CTX; - -PHPAPI void make_digest(char *md5str, unsigned char *digest); -PHPAPI void PHP_MD5Init(PHP_MD5_CTX *); -PHPAPI void PHP_MD5Update(PHP_MD5_CTX *, const unsigned char *, unsigned int); -PHPAPI void PHP_MD5Final(unsigned char[16], PHP_MD5_CTX *); - -PHP_NAMED_FUNCTION(php_if_md5); -PHP_NAMED_FUNCTION(php_if_md5_file); - -#endif diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c deleted file mode 100644 index 10e3396edf..0000000000 --- a/ext/standard/metaphone.c +++ /dev/null @@ -1,477 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - Based on CPANs "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com> -*/ - -#include "php.h" -#include "php_metaphone.h" - -static int metaphone(char *word, int word_len, int max_phonemes, char **phoned_word, int traditional); - -PHP_FUNCTION(metaphone); - -/* {{{ proto string metaphone(string text, int phones) - Break english phrases down into their phonemes */ -PHP_FUNCTION(metaphone) -{ - char *str; - char *result = 0; - int phones = 0, str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, - &phones) == FAILURE) { - return; - } - - if (metaphone(str, str_len, phones, &result, 1) == 0) { - RETVAL_STRING(result, 0); - } else { - if (result) { - efree(result); - } - RETURN_FALSE; - } -} -/* }}} */ - -/* - this is now the original code by Michael G Schwern: - i've changed it just a slightly bit (use emalloc, - get rid of includes etc) - - thies - 13.09.1999 -*/ - -/*----------------------------- */ -/* this used to be "metaphone.h" */ -/*----------------------------- */ - -/* Special encodings */ -#define SH 'X' -#define TH '0' - -/*----------------------------- */ -/* end of "metaphone.h" */ -/*----------------------------- */ - -/*----------------------------- */ -/* this used to be "metachar.h" */ -/*----------------------------- */ - -/* Metachar.h ... little bits about characters for metaphone */ -/*-- Character encoding array & accessing macros --*/ -/* Stolen directly out of the book... */ -char _codes[26] = -{ - 1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0 -/* a b c d e f g h i j k l m n o p q r s t u v w x y z */ -}; - - -#define ENCODE(c) (isalpha(c) ? _codes[((toupper(c)) - 'A')] : 0) - -#define isvowel(c) (ENCODE(c) & 1) /* AEIOU */ - -/* These letters are passed through unchanged */ -#define NOCHANGE(c) (ENCODE(c) & 2) /* FJMNR */ - -/* These form dipthongs when preceding H */ -#define AFFECTH(c) (ENCODE(c) & 4) /* CGPST */ - -/* These make C and G soft */ -#define MAKESOFT(c) (ENCODE(c) & 8) /* EIY */ - -/* These prevent GH from becoming F */ -#define NOGHTOF(c) (ENCODE(c) & 16) /* BDH */ - -/*----------------------------- */ -/* end of "metachar.h" */ -/*----------------------------- */ - -/* I suppose I could have been using a character pointer instead of - * accesssing the array directly... */ - -/* Look at the next letter in the word */ -#define Next_Letter (toupper(word[w_idx+1])) -/* Look at the current letter in the word */ -#define Curr_Letter (toupper(word[w_idx])) -/* Go N letters back. */ -#define Look_Back_Letter(n) (w_idx >= n ? toupper(word[w_idx-n]) : '\0') -/* Previous letter. I dunno, should this return null on failure? */ -#define Prev_Letter (Look_Back_Letter(1)) -/* Look two letters down. It makes sure you don't walk off the string. */ -#define After_Next_Letter (Next_Letter != '\0' ? toupper(word[w_idx+2]) \ - : '\0') -#define Look_Ahead_Letter(n) (toupper(Lookahead(word+w_idx, n))) - - -/* Allows us to safely look ahead an arbitrary # of letters */ -/* I probably could have just used strlen... */ -static char Lookahead(char *word, int how_far) -{ - char letter_ahead = '\0'; /* null by default */ - int idx; - for (idx = 0; word[idx] != '\0' && idx < how_far; idx++); - /* Edge forward in the string... */ - - letter_ahead = word[idx]; /* idx will be either == to how_far or - * at the end of the string - */ - return letter_ahead; -} - - -/* phonize one letter - * We don't know the buffers size in advance. On way to solve this is to just - * re-allocate the buffer size. We're using an extra of 2 characters (this - * could be one though; or more too). */ -#define Phonize(c) { \ - if (p_idx >= max_buffer_len) { \ - *phoned_word = erealloc(*phoned_word, max_buffer_len + 2); \ - max_buffer_len += 2; \ - } \ - (*phoned_word)[p_idx++] = c; \ - } -/* Slap a null character on the end of the phoned word */ -#define End_Phoned_Word {(*phoned_word)[p_idx] = '\0';} -/* How long is the phoned word? */ -#define Phone_Len (p_idx) - -/* Note is a letter is a 'break' in the word */ -#define Isbreak(c) (!isalpha(c)) - -/* {{{ metaphone - */ -static int metaphone(char *word, int word_len, int max_phonemes, char **phoned_word, int traditional) -{ - int w_idx = 0; /* point in the phonization we're at. */ - int p_idx = 0; /* end of the phoned phrase */ - int max_buffer_len = 0; /* maximum length of the destination buffer */ - -/*-- Parameter checks --*/ - /* Negative phoneme length is meaningless */ - - if (max_phonemes < 0) - return -1; - - /* Empty/null string is meaningless */ - /* Overly paranoid */ - /* assert(word != NULL && word[0] != '\0'); */ - - if (word == NULL) - return -1; - -/*-- Allocate memory for our phoned_phrase --*/ - if (max_phonemes == 0) { /* Assume largest possible */ - max_buffer_len = word_len; - *phoned_word = emalloc(sizeof(char) * word_len + 1); - } else { - max_buffer_len = max_phonemes; - *phoned_word = emalloc(sizeof(char) * max_phonemes + 1); - } - - -/*-- The first phoneme has to be processed specially. --*/ - /* Find our first letter */ - for (; !isalpha(Curr_Letter); w_idx++) { - /* On the off chance we were given nothing but crap... */ - if (Curr_Letter == '\0') { - End_Phoned_Word - return SUCCESS; /* For testing */ - } - } - - switch (Curr_Letter) { - /* AE becomes E */ - case 'A': - if (Next_Letter == 'E') { - Phonize('E'); - w_idx += 2; - } - /* Remember, preserve vowels at the beginning */ - else { - Phonize('A'); - w_idx++; - } - break; - /* [GKP]N becomes N */ - case 'G': - case 'K': - case 'P': - if (Next_Letter == 'N') { - Phonize('N'); - w_idx += 2; - } - break; - /* WH becomes H, - WR becomes R - W if followed by a vowel */ - case 'W': - if (Next_Letter == 'H' || - Next_Letter == 'R') { - Phonize(Next_Letter); - w_idx += 2; - } else if (isvowel(Next_Letter)) { - Phonize('W'); - w_idx += 2; - } - /* else ignore */ - break; - /* X becomes S */ - case 'X': - Phonize('S'); - w_idx++; - break; - /* Vowels are kept */ - /* We did A already - case 'A': - case 'a': - */ - case 'E': - case 'I': - case 'O': - case 'U': - Phonize(Curr_Letter); - w_idx++; - break; - default: - /* do nothing */ - break; - } - - - - /* On to the metaphoning */ - for (; Curr_Letter != '\0' && - (max_phonemes == 0 || Phone_Len < max_phonemes); - w_idx++) { - /* How many letters to skip because an eariler encoding handled - * multiple letters */ - unsigned short int skip_letter = 0; - - - /* THOUGHT: It would be nice if, rather than having things like... - * well, SCI. For SCI you encode the S, then have to remember - * to skip the C. So the phonome SCI invades both S and C. It would - * be better, IMHO, to skip the C from the S part of the encoding. - * Hell, I'm trying it. - */ - - /* Ignore non-alphas */ - if (!isalpha(Curr_Letter)) - continue; - - /* Drop duplicates, except CC */ - if (Curr_Letter == Prev_Letter && - Curr_Letter != 'C') - continue; - - switch (Curr_Letter) { - /* B -> B unless in MB */ - case 'B': - if (Prev_Letter != 'M') - Phonize('B'); - break; - /* 'sh' if -CIA- or -CH, but not SCH, except SCHW. - * (SCHW is handled in S) - * S if -CI-, -CE- or -CY- - * dropped if -SCI-, SCE-, -SCY- (handed in S) - * else K - */ - case 'C': - if (MAKESOFT(Next_Letter)) { /* C[IEY] */ - if (After_Next_Letter == 'A' && - Next_Letter == 'I') { /* CIA */ - Phonize(SH); - } - /* SC[IEY] */ - else if (Prev_Letter == 'S') { - /* Dropped */ - } else { - Phonize('S'); - } - } else if (Next_Letter == 'H') { - if ((!traditional) && (After_Next_Letter == 'R' || Prev_Letter == 'S')) { /* Christ, School */ - Phonize('K'); - } else { - Phonize(SH); - } - skip_letter++; - } else { - Phonize('K'); - } - break; - /* J if in -DGE-, -DGI- or -DGY- - * else T - */ - case 'D': - if (Next_Letter == 'G' && - MAKESOFT(After_Next_Letter)) { - Phonize('J'); - skip_letter++; - } else - Phonize('T'); - break; - /* F if in -GH and not B--GH, D--GH, -H--GH, -H---GH - * else dropped if -GNED, -GN, - * else dropped if -DGE-, -DGI- or -DGY- (handled in D) - * else J if in -GE-, -GI, -GY and not GG - * else K - */ - case 'G': - if (Next_Letter == 'H') { - if (!(NOGHTOF(Look_Back_Letter(3)) || - Look_Back_Letter(4) == 'H')) { - Phonize('F'); - skip_letter++; - } else { - /* silent */ - } - } else if (Next_Letter == 'N') { - if (Isbreak(After_Next_Letter) || - (After_Next_Letter == 'E' && - Look_Ahead_Letter(3) == 'D')) { - /* dropped */ - } else - Phonize('K'); - } else if (MAKESOFT(Next_Letter) && - Prev_Letter != 'G') { - Phonize('J'); - } else { - Phonize('K'); - } - break; - /* H if before a vowel and not after C,G,P,S,T */ - case 'H': - if (isvowel(Next_Letter) && - !AFFECTH(Prev_Letter)) - Phonize('H'); - break; - /* dropped if after C - * else K - */ - case 'K': - if (Prev_Letter != 'C') - Phonize('K'); - break; - /* F if before H - * else P - */ - case 'P': - if (Next_Letter == 'H') { - Phonize('F'); - } else { - Phonize('P'); - } - break; - /* K - */ - case 'Q': - Phonize('K'); - break; - /* 'sh' in -SH-, -SIO- or -SIA- or -SCHW- - * else S - */ - case 'S': - if (Next_Letter == 'I' && - (After_Next_Letter == 'O' || - After_Next_Letter == 'A')) { - Phonize(SH); - } else if (Next_Letter == 'H') { - Phonize(SH); - skip_letter++; - } else if ((!traditional) && (Next_Letter == 'C' && Look_Ahead_Letter(2) == 'H' && Look_Ahead_Letter(3) == 'W')) { - Phonize(SH); - skip_letter += 2; - } else { - Phonize('S'); - } - break; - /* 'sh' in -TIA- or -TIO- - * else 'th' before H - * else T - */ - case 'T': - if (Next_Letter == 'I' && - (After_Next_Letter == 'O' || - After_Next_Letter == 'A')) { - Phonize(SH); - } else if (Next_Letter == 'H') { - Phonize(TH); - skip_letter++; - } else { - Phonize('T'); - } - break; - /* F */ - case 'V': - Phonize('F'); - break; - /* W before a vowel, else dropped */ - case 'W': - if (isvowel(Next_Letter)) - Phonize('W'); - break; - /* KS */ - case 'X': - Phonize('K'); - Phonize('S'); - break; - /* Y if followed by a vowel */ - case 'Y': - if (isvowel(Next_Letter)) - Phonize('Y'); - break; - /* S */ - case 'Z': - Phonize('S'); - break; - /* No transformation */ - case 'F': - case 'J': - case 'L': - case 'M': - case 'N': - case 'R': - Phonize(Curr_Letter); - break; - default: - /* nothing */ - break; - } /* END SWITCH */ - - w_idx += skip_letter; - } /* END FOR */ - - End_Phoned_Word; - - return 0; -} /* END metaphone */ -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c deleted file mode 100644 index 414bd027dc..0000000000 --- a/ext/standard/microtime.c +++ /dev/null @@ -1,162 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Paul Panotzki - Bunyip Information Systems | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef PHP_WIN32 -#include "win32/time.h" -#elif defined(NETWARE) -#ifdef NEW_LIBC -#include <sys/timeval.h> -#else -#include "netware/time_nw.h" -#endif -#else -#include <sys/time.h> -#endif -#ifdef HAVE_SYS_RESOURCE_H -#include <sys/resource.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> - -#include "microtime.h" - -#define NUL '\0' -#define MICRO_IN_SEC 1000000.00 -#define SEC_IN_MIN 60 - -/* {{{ proto string microtime(void) - Returns a string containing the current time in seconds and microseconds */ -#ifdef HAVE_GETTIMEOFDAY -PHP_FUNCTION(microtime) -{ - struct timeval tp; - long sec = 0L; - double msec = 0.0; - char ret[100]; - - if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) { - msec = (double) (tp.tv_usec / MICRO_IN_SEC); - sec = tp.tv_sec; - - if (msec >= 1.0) msec -= (long) msec; - snprintf(ret, 100, "%.8f %ld", msec, sec); - RETVAL_STRING(ret,1); - } else { - RETURN_FALSE; - } -} -#endif -/* }}} */ - -/* {{{ proto array gettimeofday(void) - Returns the current time as array */ -#ifdef HAVE_GETTIMEOFDAY -PHP_FUNCTION(gettimeofday) -{ - struct timeval tp; - struct timezone tz; - - memset(&tp, 0, sizeof(tp)); - memset(&tz, 0, sizeof(tz)); - if(gettimeofday(&tp, &tz) == 0) { - array_init(return_value); - add_assoc_long(return_value, "sec", tp.tv_sec); - add_assoc_long(return_value, "usec", tp.tv_usec); -#ifdef PHP_WIN32 - add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest/SEC_IN_MIN); -#else - add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest); -#endif - add_assoc_long(return_value, "dsttime", tz.tz_dsttime); - return; - } else { - RETURN_FALSE; - } -} -#endif -/* }}} */ - -#ifdef HAVE_GETRUSAGE -/* {{{ proto array getrusage([int who]) - Returns an array of usage statistics */ -PHP_FUNCTION(getrusage) -{ - struct rusage usg; - int ac = ZEND_NUM_ARGS(); - pval **pwho; - int who = RUSAGE_SELF; - - if(ac == 1 && - zend_get_parameters_ex(ac, &pwho) != FAILURE) { - convert_to_long_ex(pwho); - if(Z_LVAL_PP(pwho) == 1) - who = RUSAGE_CHILDREN; - } - - memset(&usg, 0, sizeof(usg)); - if(getrusage(who, &usg) == -1) { - RETURN_FALSE; - } - - array_init(return_value); -#define PHP_RUSAGE_PARA(a) \ - add_assoc_long(return_value, #a, usg.a) -#if !defined( _OSD_POSIX) && !defined(__BEOS__) /* BS2000 has only a few fields in the rusage struct */ - PHP_RUSAGE_PARA(ru_oublock); - PHP_RUSAGE_PARA(ru_inblock); - PHP_RUSAGE_PARA(ru_msgsnd); - PHP_RUSAGE_PARA(ru_msgrcv); - PHP_RUSAGE_PARA(ru_maxrss); - PHP_RUSAGE_PARA(ru_ixrss); - PHP_RUSAGE_PARA(ru_idrss); - PHP_RUSAGE_PARA(ru_minflt); - PHP_RUSAGE_PARA(ru_majflt); - PHP_RUSAGE_PARA(ru_nsignals); - PHP_RUSAGE_PARA(ru_nvcsw); - PHP_RUSAGE_PARA(ru_nivcsw); -#endif /*_OSD_POSIX*/ - PHP_RUSAGE_PARA(ru_utime.tv_usec); - PHP_RUSAGE_PARA(ru_utime.tv_sec); - PHP_RUSAGE_PARA(ru_stime.tv_usec); - PHP_RUSAGE_PARA(ru_stime.tv_sec); -#undef PHP_RUSAGE_PARA -} -#endif /* HAVE_GETRUSAGE */ - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/microtime.h b/ext/standard/microtime.h deleted file mode 100644 index 5dcf6cd62a..0000000000 --- a/ext/standard/microtime.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Paul Panotzki - Bunyip Information Systems | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef MICROTIME_H -#define MICROTIME_H - -#ifdef HAVE_GETTIMEOFDAY -PHP_FUNCTION(microtime); -PHP_FUNCTION(gettimeofday); -#endif -#ifdef HAVE_GETRUSAGE -PHP_FUNCTION(getrusage); -#endif - -#endif /* MICROTIME_H */ diff --git a/ext/standard/pack.c b/ext/standard/pack.c deleted file mode 100644 index 3b855f8f77..0000000000 --- a/ext/standard/pack.c +++ /dev/null @@ -1,918 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Chris Schneider <cschneid@relog.ch> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#ifdef PHP_WIN32 -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#elif defined(NETWARE) -#ifdef USE_WINSOCK -/*#include <ws2nlm.h>*/ -#include <novsock2.h> -#else -#include <sys/socket.h> -#endif -#ifdef NEW_LIBC -#include <sys/param.h> -#else -#include "netware/param.h" -#endif -#else -#include <sys/param.h> -#endif -#include "ext/standard/head.h" -#include "safe_mode.h" -#include "php_string.h" -#include "pack.h" -#if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#elif defined(NETWARE) -#include "netware/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#include "fsock.h" -#if HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif - -/* Whether machine is little endian */ -char machine_little_endian; - -/* Mapping of byte from char (8bit) to long for machine endian */ -static int byte_map[1]; - -/* Mappings of bytes from int (machine dependant) to int for machine endian */ -static int int_map[sizeof(int)]; - -/* Mappings of bytes from shorts (16bit) for all endian environments */ -static int machine_endian_short_map[2]; -static int big_endian_short_map[2]; -static int little_endian_short_map[2]; - -/* Mappings of bytes from longs (32bit) for all endian environments */ -static int machine_endian_long_map[4]; -static int big_endian_long_map[4]; -static int little_endian_long_map[4]; - -/* {{{ php_pack - */ -static void php_pack(zval **val, int size, int *map, char *output) -{ - int i; - char *v; - - convert_to_long_ex(val); - v = (char *) &Z_LVAL_PP(val); - - for (i = 0; i < size; i++) { - *output++ = v[map[i]]; - } -} -/* }}} */ - -/* pack() idea stolen from Perl (implemented formats behave the same as there) - * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @. - */ -/* {{{ proto string pack(string format, mixed arg1 [, mixed arg2 [, mixed ...]]) - Takes one or more arguments and packs them into a binary string according to the format argument */ -PHP_FUNCTION(pack) -{ - zval ***argv; - int argc, i; - int currentarg; - char *format; - int formatlen; - char *formatcodes; - int *formatargs; - int formatcount = 0; - int outputpos = 0, outputsize = 0; - char *output; - - argc = ZEND_NUM_ARGS(); - - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - argv = emalloc(argc * sizeof(zval **)); - - if (zend_get_parameters_array_ex(argc, argv) == FAILURE) { - efree(argv); - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(argv[0]); - format = Z_STRVAL_PP(argv[0]); - formatlen = Z_STRLEN_PP(argv[0]); - - /* We have a maximum of <formatlen> format codes to deal with */ - formatcodes = emalloc(formatlen * sizeof(*formatcodes)); - formatargs = emalloc(formatlen * sizeof(*formatargs)); - currentarg = 1; - - /* Preprocess format into formatcodes and formatargs */ - for (i = 0; i < formatlen; formatcount++) { - char code = format[i++]; - int arg = 1; - - /* Handle format arguments if any */ - if (i < formatlen) { - char c = format[i]; - - if (c == '*') { - arg = -1; - i++; - } - else if (c >= '0' && c <= '9') { - arg = atoi(&format[i]); - - while (format[i] >= '0' && format[i] <= '9' && i < formatlen) { - i++; - } - } - } - - /* Handle special arg '*' for all codes and check argv overflows */ - switch ((int) code) { - /* Never uses any args */ - case 'x': - case 'X': - case '@': - if (arg < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: '*' ignored", code); - arg = 1; - } - break; - - /* Always uses one arg */ - case 'a': - case 'A': - case 'h': - case 'H': - if (currentarg >= argc) { - efree(argv); - efree(formatcodes); - efree(formatargs); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough arguments", code); - RETURN_FALSE; - } - - if (arg < 0) { - arg = Z_STRLEN_PP(argv[currentarg]); - } - - currentarg++; - break; - - /* Use as many args as specified */ - case 'c': - case 'C': - case 's': - case 'S': - case 'i': - case 'I': - case 'l': - case 'L': - case 'n': - case 'N': - case 'v': - case 'V': - case 'f': - case 'd': - if (arg < 0) { - arg = argc - currentarg; - } - - currentarg += arg; - - if (currentarg > argc) { - efree(argv); - efree(formatcodes); - efree(formatargs); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: too few arguments", code); - RETURN_FALSE; - } - break; - - default: - efree(argv); - efree(formatcodes); - efree(formatargs); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: unknown format code", code); - RETURN_FALSE; - } - - formatcodes[formatcount] = code; - formatargs[formatcount] = arg; - } - - if (currentarg < argc) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%d arguments unused", (argc - currentarg)); - } - - /* Calculate output length and upper bound while processing*/ - for (i = 0; i < formatcount; i++) { - int code = (int) formatcodes[i]; - int arg = formatargs[i]; - - switch ((int) code) { - case 'h': - case 'H': - outputpos += (arg + 1) / 2; /* 4 bit per arg */ - break; - - case 'a': - case 'A': - case 'c': - case 'C': - case 'x': - outputpos += arg; /* 8 bit per arg */ - break; - - case 's': - case 'S': - case 'n': - case 'v': - outputpos += arg * 2; /* 16 bit per arg */ - break; - - case 'i': - case 'I': - outputpos += arg * sizeof(int); - break; - - case 'l': - case 'L': - case 'N': - case 'V': - outputpos += arg * 4; /* 32 bit per arg */ - break; - - case 'f': - outputpos += arg * sizeof(float); - break; - - case 'd': - outputpos += arg * sizeof(double); - break; - - case 'X': - outputpos -= arg; - - if (outputpos < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of string", code); - outputpos = 0; - } - break; - - case '@': - outputpos = arg; - break; - } - - if (outputsize < outputpos) { - outputsize = outputpos; - } - } - - output = emalloc(outputsize + 1); - outputpos = 0; - currentarg = 1; - - /* Do actual packing */ - for (i = 0; i < formatcount; i++) { - int code = (int) formatcodes[i]; - int arg = formatargs[i]; - zval **val; - - switch ((int) code) { - case 'a': - case 'A': - memset(&output[outputpos], (code == 'a') ? '\0' : ' ', arg); - val = argv[currentarg++]; - convert_to_string_ex(val); - memcpy(&output[outputpos], Z_STRVAL_PP(val), - (Z_STRLEN_PP(val) < arg) ? Z_STRLEN_PP(val) : arg); - outputpos += arg; - break; - - case 'h': - case 'H': { - int nibbleshift = (code == 'h') ? 0 : 4; - int first = 1; - char *v; - - val = argv[currentarg++]; - convert_to_string_ex(val); - v = Z_STRVAL_PP(val); - outputpos--; - if(arg > Z_STRLEN_PP(val)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough characters in string", code); - arg = Z_STRLEN_PP(val); - } - - while (arg-- > 0) { - char n = *v++; - - if (n >= '0' && n <= '9') { - n -= '0'; - } else if (n >= 'A' && n <= 'F') { - n -= ('A' - 10); - } else if (n >= 'a' && n <= 'f') { - n -= ('a' - 10); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: illegal hex digit %c", code, n); - n = 0; - } - - if (first--) { - output[++outputpos] = 0; - } else { - first = 1; - } - - output[outputpos] |= (n << nibbleshift); - nibbleshift = (nibbleshift + 4) & 7; - } - - outputpos++; - break; - } - - case 'c': - case 'C': - while (arg-- > 0) { - php_pack(argv[currentarg++], 1, byte_map, &output[outputpos]); - outputpos++; - } - break; - - case 's': - case 'S': - case 'n': - case 'v': { - int *map = machine_endian_short_map; - - if (code == 'n') { - map = big_endian_short_map; - } else if (code == 'v') { - map = little_endian_short_map; - } - - while (arg-- > 0) { - php_pack(argv[currentarg++], 2, map, &output[outputpos]); - outputpos += 2; - } - break; - } - - case 'i': - case 'I': - while (arg-- > 0) { - php_pack(argv[currentarg++], sizeof(int), int_map, &output[outputpos]); - outputpos += sizeof(int); - } - break; - - case 'l': - case 'L': - case 'N': - case 'V': { - int *map = machine_endian_long_map; - - if (code == 'N') { - map = big_endian_long_map; - } else if (code == 'V') { - map = little_endian_long_map; - } - - while (arg-- > 0) { - php_pack(argv[currentarg++], 4, map, &output[outputpos]); - outputpos += 4; - } - break; - } - - case 'f': { - float v; - - while (arg-- > 0) { - val = argv[currentarg++]; - convert_to_double_ex(val); - v = (float) Z_DVAL_PP(val); - memcpy(&output[outputpos], &v, sizeof(v)); - outputpos += sizeof(v); - } - break; - } - - case 'd': { - double v; - - while (arg-- > 0) { - val = argv[currentarg++]; - convert_to_double_ex(val); - v = (double) Z_DVAL_PP(val); - memcpy(&output[outputpos], &v, sizeof(v)); - outputpos += sizeof(v); - } - break; - } - - case 'x': - memset(&output[outputpos], '\0', arg); - outputpos += arg; - break; - - case 'X': - outputpos -= arg; - - if (outputpos < 0) { - outputpos = 0; - } - break; - - case '@': - if (arg > outputpos) { - memset(&output[outputpos], '\0', arg - outputpos); - } - outputpos = arg; - break; - } - } - - efree(argv); - efree(formatcodes); - efree(formatargs); - output[outputpos] = '\0'; - RETVAL_STRINGL(output, outputpos, 1); - efree(output); -} -/* }}} */ - -/* {{{ php_unpack - */ -static long php_unpack(char *data, int size, int issigned, int *map) -{ - long result; - char *cresult = (char *) &result; - int i; - - result = issigned ? -1 : 0; - - for (i = 0; i < size; i++) { - cresult[map[i]] = *data++; - } - - return result; -} -/* }}} */ - -/* unpack() is based on Perl's unpack(), but is modified a bit from there. - * Rather than depending on error-prone ordered lists or syntactically - * unpleasant pass-by-reference, we return an object with named paramters - * (like *_fetch_object()). Syntax is "f[repeat]name/...", where "f" is the - * formatter char (like pack()), "[repeat]" is the optional repeater argument, - * and "name" is the name of the variable to use. - * Example: "c2chars/nints" will return an object with fields - * chars1, chars2, and ints. - * Numeric pack types will return numbers, a and A will return strings, - * f and d will return doubles. - * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @. - */ -/* {{{ proto array unpack(string format, string input) - Unpack binary string into named array elements according to format argument */ -PHP_FUNCTION(unpack) -{ - zval **formatarg; - zval **inputarg; - char *format; - char *input; - int formatlen; - int inputpos, inputlen; - int i; - - if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(2, &formatarg, &inputarg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(formatarg); - convert_to_string_ex(inputarg); - - format = Z_STRVAL_PP(formatarg); - formatlen = Z_STRLEN_PP(formatarg); - input = Z_STRVAL_PP(inputarg); - inputlen = Z_STRLEN_PP(inputarg); - inputpos = 0; - - array_init(return_value); - - while (formatlen-- > 0) { - char type = *(format++); - char c; - int arg = 1; - char *name; - int namelen; - int size=0; - - /* Handle format arguments if any */ - if (formatlen > 0) { - c = *format; - - if (c >= '0' && c <= '9') { - arg = atoi(format); - - while (formatlen > 0 && *format >= '0' && *format <= '9') { - format++; - formatlen--; - } - } else if (c == '*') { - arg = -1; - format++; - formatlen--; - } - } - - /* Get of new value in array */ - name = format; - - while (formatlen > 0 && *format != '/') { - formatlen--; - format++; - } - - namelen = format - name; - - if (namelen > 200) - namelen = 200; - - switch ((int) type) { - /* Never use any input */ - case 'X': - size = -1; - break; - - case '@': - size = 0; - break; - - case 'a': - case 'A': - size = arg; - arg = 1; - break; - - case 'h': - case 'H': - size = (arg > 0) ? arg / 2 : arg; - arg = 1; - break; - - /* Use 1 byte of input */ - case 'c': - case 'C': - case 'x': - size = 1; - break; - - /* Use 2 bytes of input */ - case 's': - case 'S': - case 'n': - case 'v': - size = 2; - break; - - /* Use sizeof(int) bytes of input */ - case 'i': - case 'I': - size = sizeof(int); - break; - - /* Use 4 bytes of input */ - case 'l': - case 'L': - case 'N': - case 'V': - size = 4; - break; - - /* Use sizeof(float) bytes of input */ - case 'f': - size = sizeof(float); - break; - - /* Use sizeof(double) bytes of input */ - case 'd': - size = sizeof(double); - break; - } - - /* Do actual unpacking */ - for (i = 0; i != arg; i++ ) { - /* Space for name + number, safe as namelen is ensured <= 200 */ - char n[256]; - - if (arg != 1) { - /* Need to add element number to name */ - sprintf(n, "%.*s%d", namelen, name, i + 1); - } else { - /* Truncate name to next format code or end of string */ - sprintf(n, "%.*s", namelen, name); - } - - if ((inputpos + size) <= inputlen) { - switch ((int) type) { - case 'a': - case 'A': { - char pad = (type == 'a') ? '\0' : ' '; - int len = inputlen - inputpos; /* Remaining string */ - - /* If size was given take minimum of len and size */ - if ((size >= 0) && (len > size)) { - len = size; - } - - size = len; - - /* Remove padding chars from unpacked data */ - while (--len >= 0) { - if (input[inputpos + len] != pad) - break; - } - - add_assoc_stringl(return_value, n, &input[inputpos], len + 1, 1); - break; - } - - case 'h': - case 'H': { - int len = (inputlen - inputpos) * 2; /* Remaining */ - int nibbleshift = (type == 'h') ? 0 : 4; - int first = 1; - char *buf; - int ipos, opos; - - /* If size was given take minimum of len and size */ - if (size >= 0 && len > (size * 2)) { - len = size * 2; - } - - buf = emalloc(len + 1); - - for (ipos = opos = 0; opos < len; opos++) { - char c = (input[inputpos + ipos] >> nibbleshift) & 0xf; - - if (c < 10) { - c += '0'; - } else { - c += 'a' - 10; - } - - buf[opos] = c; - nibbleshift = (nibbleshift + 4) & 7; - - if (first-- == 0) { - ipos++; - first = 1; - } - } - - buf[len] = '\0'; - add_assoc_stringl(return_value, n, buf, len, 1); - efree(buf); - break; - } - - case 'c': - case 'C': { - int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0; - long v = php_unpack(&input[inputpos], 1, issigned, byte_map); - add_assoc_long(return_value, n, v); - break; - } - - case 's': - case 'S': - case 'n': - case 'v': { - long v; - int issigned = 0; - int *map = machine_endian_short_map; - - if (type == 's') { - issigned = input[inputpos + (machine_little_endian ? 1 : 0)] & 0x80; - } else if (type == 'n') { - map = big_endian_short_map; - } else if (type == 'v') { - map = little_endian_short_map; - } - - v = php_unpack(&input[inputpos], 2, issigned, map); - add_assoc_long(return_value, n, v); - break; - } - - case 'i': - case 'I': { - long v; - int issigned = 0; - - if (type == 'i') { - issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80; - } - - v = php_unpack(&input[inputpos], sizeof(int), issigned, int_map); - add_assoc_long(return_value, n, v); - break; - } - - case 'l': - case 'L': - case 'N': - case 'V': { - int issigned = 0; - int *map = machine_endian_long_map; - long v; - - if (type == 'l') { - issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80; - } else if (type == 'N') { - map = big_endian_long_map; - } else if (type == 'V') { - map = little_endian_long_map; - } - - v = php_unpack(&input[inputpos], 4, issigned, map); - add_assoc_long(return_value, n, v); - break; - } - - case 'f': { - float v; - - memcpy(&v, &input[inputpos], sizeof(float)); - add_assoc_double(return_value, n, (double)v); - break; - } - - case 'd': { - double v; - - memcpy(&v, &input[inputpos], sizeof(double)); - add_assoc_double(return_value, n, v); - break; - } - - case 'x': - /* Do nothing with input, just skip it */ - break; - - case 'X': - if (inputpos < size) { - inputpos = -size; - i = arg - 1; /* Break out of for loop */ - - if (arg >= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of string", type); - } - } - break; - - case '@': - if (arg <= inputlen) { - inputpos = arg; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of string", type); - } - - i = arg - 1; /* Done, break out of for loop */ - break; - } - - inputpos += size; - } else if (arg < 0) { - /* Reached end of input for '*' repeater */ - break; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: not enough input, need %d, have %d", type, size, inputlen - inputpos); - zval_dtor(return_value); - RETURN_FALSE; - } - } - - formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */ - format++; - } -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(pack) -{ - int machine_endian_check = 1; - int i; - - machine_little_endian = ((char *)&machine_endian_check)[0]; - - if (machine_little_endian) { - /* Where to get lo to hi bytes from */ - byte_map[0] = 0; - - for (i = 0; i < sizeof(int); i++) { - int_map[i] = i; - } - - machine_endian_short_map[0] = 0; - machine_endian_short_map[1] = 1; - big_endian_short_map[0] = 1; - big_endian_short_map[1] = 0; - little_endian_short_map[0] = 0; - little_endian_short_map[1] = 1; - - machine_endian_long_map[0] = 0; - machine_endian_long_map[1] = 1; - machine_endian_long_map[2] = 2; - machine_endian_long_map[3] = 3; - big_endian_long_map[0] = 3; - big_endian_long_map[1] = 2; - big_endian_long_map[2] = 1; - big_endian_long_map[3] = 0; - little_endian_long_map[0] = 0; - little_endian_long_map[1] = 1; - little_endian_long_map[2] = 2; - little_endian_long_map[3] = 3; - } - else { - zval val; - int size = sizeof(Z_LVAL(val)); - Z_LVAL(val)=0; /*silence a warning*/ - - /* Where to get hi to lo bytes from */ - byte_map[0] = size - 1; - - for (i = 0; i < sizeof(int); i++) { - int_map[i] = size - (sizeof(int) - i); - } - - machine_endian_short_map[0] = size - 2; - machine_endian_short_map[1] = size - 1; - big_endian_short_map[0] = size - 2; - big_endian_short_map[1] = size - 1; - little_endian_short_map[0] = size - 1; - little_endian_short_map[1] = size - 2; - - machine_endian_long_map[0] = size - 4; - machine_endian_long_map[1] = size - 3; - machine_endian_long_map[2] = size - 2; - machine_endian_long_map[3] = size - 1; - big_endian_long_map[0] = size - 4; - big_endian_long_map[1] = size - 3; - big_endian_long_map[2] = size - 2; - big_endian_long_map[3] = size - 1; - little_endian_long_map[0] = size - 1; - little_endian_long_map[1] = size - 2; - little_endian_long_map[2] = size - 3; - little_endian_long_map[3] = size - 4; - } - - 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/ext/standard/pack.h b/ext/standard/pack.h deleted file mode 100644 index d3414e2aad..0000000000 --- a/ext/standard/pack.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PACK_H -#define PACK_H - -PHP_MINIT_FUNCTION(pack); -PHP_FUNCTION(pack); -PHP_FUNCTION(unpack); - -#endif /* PACK_H */ diff --git a/ext/standard/pageinfo.c b/ext/standard/pageinfo.c deleted file mode 100644 index 43e7b338fb..0000000000 --- a/ext/standard/pageinfo.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "pageinfo.h" -#include "SAPI.h" - -#include <stdio.h> -#include <stdlib.h> -#if HAVE_PWD_H -#ifdef PHP_WIN32 -#include "win32/pwd.h" -#elif defined(NETWARE) -#ifdef ZTS -extern int basic_globals_id; -#endif -#include "netware/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#if HAVE_GRP_H -# ifdef PHP_WIN32 -# include "win32/grp.h" -# else -# include <grp.h> -# endif -#endif -#ifdef PHP_WIN32 -#undef getgid -#define getgroups(a, b) 0 -#define getgid() 1 -#define getuid() 1 -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> -#include <sys/types.h> -#ifdef PHP_WIN32 -#include <process.h> -#endif - -#include "ext/standard/basic_functions.h" - -/* {{{ php_statpage - */ -PHPAPI void php_statpage(TSRMLS_D) -{ -#if defined(NETWARE) && defined(CLIB_STAT_PATCH) - struct stat_libc *pstat; -#else - struct stat *pstat; -#endif - - pstat = sapi_get_stat(TSRMLS_C); - - if (BG(page_uid)==-1 || BG(page_gid)==-1) { - if(pstat) { - BG(page_uid) = pstat->st_uid; - BG(page_gid) = pstat->st_gid; - BG(page_inode) = pstat->st_ino; -#if defined(NETWARE) && defined(NEW_LIBC) - BG(page_mtime) = (pstat->st_mtime).tv_nsec; -#else - BG(page_mtime) = pstat->st_mtime; -#endif - } else { /* handler for situations where there is no source file, ex. php -r */ - BG(page_uid) = getuid(); - BG(page_gid) = getgid(); - } - } -} -/* }}} */ - -/* {{{ php_getuid - */ -long php_getuid(void) -{ - TSRMLS_FETCH(); - - php_statpage(TSRMLS_C); - return (BG(page_uid)); -} -/* }}} */ - -long php_getgid(void) -{ - TSRMLS_FETCH(); - - php_statpage(TSRMLS_C); - return (BG(page_gid)); -} - -/* {{{ proto int getmyuid(void) - Get PHP script owner's UID */ -PHP_FUNCTION(getmyuid) -{ - long uid; - - uid = php_getuid(); - if (uid < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(uid); - } -} -/* }}} */ - -/* {{{ proto int getmygid(void) - Get PHP script owner's GID */ -PHP_FUNCTION(getmygid) -{ - long gid; - - gid = php_getgid(); - if (gid < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(gid); - } -} -/* }}} */ - -/* {{{ proto int getmypid(void) - Get current process ID */ -PHP_FUNCTION(getmypid) -{ - int pid; - - pid = getpid(); - if (pid < 0) { - RETURN_FALSE; - } else { - RETURN_LONG((long) pid); - } -} -/* }}} */ - -/* {{{ proto int getmyinode(void) - Get the inode of the current script being parsed */ -PHP_FUNCTION(getmyinode) -{ - php_statpage(TSRMLS_C); - if (BG(page_inode) < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(BG(page_inode)); - } -} -/* }}} */ - -PHPAPI long php_getlastmod(TSRMLS_D) -{ - php_statpage(TSRMLS_C); - return BG(page_mtime); -} - -/* {{{ proto int getlastmod(void) - Get time of last page modification */ -PHP_FUNCTION(getlastmod) -{ - long lm = php_getlastmod(TSRMLS_C); - if (lm < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(lm); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h deleted file mode 100644 index 93cc0f4e1c..0000000000 --- a/ext/standard/pageinfo.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PAGEINFO_H -#define PAGEINFO_H - -PHP_FUNCTION(getmyuid); -PHP_FUNCTION(getmygid); -PHP_FUNCTION(getmypid); -PHP_FUNCTION(getmyinode); -PHP_FUNCTION(getlastmod); - -PHPAPI void php_statpage(TSRMLS_D); -PHPAPI long php_getlastmod(TSRMLS_D); -extern long php_getuid(void); -extern long php_getgid(void); - -#endif diff --git a/ext/standard/parsedate.y b/ext/standard/parsedate.y deleted file mode 100644 index 70d140af31..0000000000 --- a/ext/standard/parsedate.y +++ /dev/null @@ -1,1043 +0,0 @@ -%{ -/* -** Originally written by Steven M. Bellovin <smb@research.att.com> while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990. -** -** This code is in the public domain and has no copyright. -*/ - -/* $Id$ */ - -#include "php.h" - -#ifdef PHP_WIN32 -#include <malloc.h> -#endif - -#include <stdio.h> -#include <sys/types.h> -#include <time.h> -#include <ctype.h> - -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif -#ifdef PHP_WIN32 -# include "win32/time.h" -#endif - -#include "php_parsedate.h" - -#if HAVE_STDLIB_H -# include <stdlib.h> /* for `free'; used by Bison 1.27 */ -#endif - -#if defined(_HPUX_SOURCE) -#include <alloca.h> -#endif - -#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII)) -# define IN_CTYPE_DOMAIN(c) 1 -#else -# define IN_CTYPE_DOMAIN(c) isascii(c) -#endif - -#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c)) -#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c)) -#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c)) -#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c)) - -/* ISDIGIT differs from ISDIGIT_LOCALE, as follows: - - Its arg may be any int or unsigned int; it need not be an unsigned char. - - It's guaranteed to evaluate its argument exactly once. - - It's typically faster. - Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that - only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless - it's important to use the locale's definition of `digit' even when the - host does not conform to Posix. */ -#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9) - -#if defined (STDC_HEADERS) || defined (USG) -# include <string.h> -#endif - -#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) -# define __attribute__(x) -#endif - -#ifndef ATTRIBUTE_UNUSED -# define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) -#endif - -/* Some old versions of bison generate parsers that use bcopy. - That loses on systems that don't provide the function, so we have - to redefine it here. */ -#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy) -# define bcopy(from, to, len) memcpy ((to), (from), (len)) -#endif - -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), - as well as gratuitiously global symbol names, so we can have multiple - yacc generated parsers in the same program. Note that these are only - the variables produced by yacc. If other parser generators (bison, - byacc, etc) produce additional global names that conflict at link time, - then those parser generators need to be fixed instead of adding those - names to this list. */ - -#define yymaxdepth php_gd_maxdepth -#define yyparse php_gd_parse -#define yylex php_gd_lex -#define yyerror php_gd_error -#define yylval php_gd_lval -#define yychar php_gd_char -#define yydebug php_gd_debug -#define yypact php_gd_pact -#define yyr1 php_gd_r1 -#define yyr2 php_gd_r2 -#define yydef php_gd_def -#define yychk php_gd_chk -#define yypgo php_gd_pgo -#define yyact php_gd_act -#define yyexca php_gd_exca -#define yyerrflag php_gd_errflag -#define yynerrs php_gd_nerrs -#define yyps php_gd_ps -#define yypv php_gd_pv -#define yys php_gd_s -#define yy_yys php_gd_yys -#define yystate php_gd_state -#define yytmp php_gd_tmp -#define yyv php_gd_v -#define yy_yyv php_gd_yyv -#define yyval php_gd_val -#define yylloc php_gd_lloc -#define yyreds php_gd_reds /* With YYDEBUG defined */ -#define yytoks php_gd_toks /* With YYDEBUG defined */ -#define yylhs php_gd_yylhs -#define yylen php_gd_yylen -#define yydefred php_gd_yydefred -#define yydgoto php_gd_yydgoto -#define yysindex php_gd_yysindex -#define yyrindex php_gd_yyrindex -#define yygindex php_gd_yygindex -#define yytable php_gd_yytable -#define yycheck php_gd_yycheck - -static int yylex (); -static int yyerror (); - -#define EPOCH 1970 -#define HOUR(x) ((x) * 60) - -#define MAX_BUFF_LEN 128 /* size of buffer to read the date into */ - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - const char *name; - int type; - int value; -} TABLE; - - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of these by using a good -** union as the yacc stack. (This routine was originally written before -** yacc had the %union construct.) Maybe someday; right now we only use -** the %union very rarely. -*/ -static const char *yyInput; -static int yyDayOrdinal; -static int yyDayNumber; -static int yyHaveDate; -static int yyHaveDay; -static int yyHaveRel; -static int yyHaveTime; -static int yyHaveZone; -static int yyTimezone; -static int yyDay; -static int yyHour; -static int yyMinutes; -static int yyMonth; -static int yySeconds; -static int yyYear; -static MERIDIAN yyMeridian; -static int yyRelDay; -static int yyRelHour; -static int yyRelMinutes; -static int yyRelMonth; -static int yyRelSeconds; -static int yyRelYear; - -%} - -/* This grammar has 14 shift/reduce conflicts. */ -%expect 14 - -%union { - int Number; - enum _MERIDIAN Meridian; -} - -%token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID -%token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT -%token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE - -%type <Number> tDAY tDAY_UNIT tDAYZONE tHOUR_UNIT tMINUTE_UNIT -%type <Number> tMONTH tMONTH_UNIT -%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE -%type <Meridian> tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; - } - | zone { - yyHaveZone++; - } - | date { - yyHaveDate++; - } - | day { - yyHaveDay++; - } - | rel { - yyHaveRel++; - } - | number - ; - -time : tUNUMBER tMERIDIAN { - yyHour = $1; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yyMeridian = MER24; - yyHaveZone++; - yyTimezone = ($4 < 0 - ? -$4 % 100 + (-$4 / 100) * 60 - : - ($4 % 100 + ($4 / 100) * 60)); - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER { - /* ISO 8601 format. hh:mm:ss[+-][0-9]{2}([0-9]{2})?. */ - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = MER24; - yyHaveZone++; - if ($6 <= -100 || $6 >= 100) { - yyTimezone = -$6 % 100 + (-$6 / 100) * 60; - } else { - yyTimezone = -$6 * 60; - } - } - ; - -zone : tZONE { - yyTimezone = $1; - } - | tDAYZONE { - yyTimezone = $1 - 60; - } - | - tZONE tDST { - yyTimezone = $1 - 60; - } - ; - -day : tDAY { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tDAY ',' { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tUNUMBER tDAY { - yyDayOrdinal = $1; - yyDayNumber = $2; - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY. - The goal in recognizing YYYY/MM/DD is solely to support legacy - machine-generated dates like those in an RCS log listing. If - you want portability, use the ISO 8601 format. */ - if ($1 >= 1000) - { - yyYear = $1; - yyMonth = $3; - yyDay = $5; - } - else - { - yyMonth = $1; - yyDay = $3; - yyYear = $5; - } - } - | tUNUMBER tSNUMBER tSNUMBER { - /* ISO 8601 format. yyyy-mm-dd. */ - yyYear = $1; - yyMonth = -$2; - yyDay = -$3; - } - | tUNUMBER tMONTH tSNUMBER { - /* e.g. 17-JUN-1992. */ - yyDay = $1; - yyMonth = $2; - yyYear = -$3; - } - | tMONTH tUNUMBER tUNUMBER { - yyMonth = $1; - yyDay = $2; - yyYear = $3; - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - yyYear = $4; - } - | tUNUMBER tMONTH { - yyMonth = $2; - yyDay = $1; - } - | tUNUMBER tMONTH tUNUMBER { - yyMonth = $2; - yyDay = $1; - yyYear = $3; - } - ; - -rel : relunit tAGO { - yyRelSeconds = -yyRelSeconds; - yyRelMinutes = -yyRelMinutes; - yyRelHour = -yyRelHour; - yyRelDay = -yyRelDay; - yyRelMonth = -yyRelMonth; - yyRelYear = -yyRelYear; - } - | relunit - ; - -relunit : tUNUMBER tYEAR_UNIT { - yyRelYear += $1 * $2; - } - | tSNUMBER tYEAR_UNIT { - yyRelYear += $1 * $2; - } - | tYEAR_UNIT { - yyRelYear += $1; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - | tUNUMBER tDAY_UNIT { - yyRelDay += $1 * $2; - } - | tSNUMBER tDAY_UNIT { - yyRelDay += $1 * $2; - } - | tDAY_UNIT { - yyRelDay += $1; - } - | tUNUMBER tHOUR_UNIT { - yyRelHour += $1 * $2; - } - | tSNUMBER tHOUR_UNIT { - yyRelHour += $1 * $2; - } - | tHOUR_UNIT { - yyRelHour += $1; - } - | tUNUMBER tMINUTE_UNIT { - yyRelMinutes += $1 * $2; - } - | tSNUMBER tMINUTE_UNIT { - yyRelMinutes += $1 * $2; - } - | tMINUTE_UNIT { - yyRelMinutes += $1; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tSNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tSEC_UNIT { - yyRelSeconds += $1; - } - ; - -number : tUNUMBER - { - if (yyHaveTime && yyHaveDate && !yyHaveRel) - yyYear = $1; - else - { - if ($1>10000) - { - yyHaveDate++; - yyDay= ($1)%100; - yyMonth= ($1/100)%100; - yyYear = $1/10000; - } - else - { - yyHaveTime++; - if ($1 < 100) - { - yyHour = $1; - yyMinutes = 0; - } - else - { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = MER24; - } - } - } - ; - -o_merid : /* NULL */ - { - $$ = MER24; - } - | tMERIDIAN - { - $$ = $1; - } - ; - -%% - -time_t get_date (char *p, time_t *now); - -#ifndef PHP_WIN32 -extern struct tm *gmtime(); -extern struct tm *localtime(); -extern time_t mktime(); -#endif - -/* Month and day table. */ -static TABLE const MonthDayTable[] = { - { "january", tMONTH, 1 }, - { "february", tMONTH, 2 }, - { "march", tMONTH, 3 }, - { "april", tMONTH, 4 }, - { "may", tMONTH, 5 }, - { "june", tMONTH, 6 }, - { "july", tMONTH, 7 }, - { "august", tMONTH, 8 }, - { "september", tMONTH, 9 }, - { "sept", tMONTH, 9 }, - { "october", tMONTH, 10 }, - { "november", tMONTH, 11 }, - { "december", tMONTH, 12 }, - { "sunday", tDAY, 0 }, - { "monday", tDAY, 1 }, - { "tuesday", tDAY, 2 }, - { "tues", tDAY, 2 }, - { "wednesday", tDAY, 3 }, - { "wednes", tDAY, 3 }, - { "thursday", tDAY, 4 }, - { "thur", tDAY, 4 }, - { "thurs", tDAY, 4 }, - { "friday", tDAY, 5 }, - { "saturday", tDAY, 6 }, - { NULL, 0, 0 } -}; - -/* Time units table. */ -static TABLE const UnitsTable[] = { - { "year", tYEAR_UNIT, 1 }, - { "month", tMONTH_UNIT, 1 }, - { "fortnight", tDAY_UNIT, 14 }, - { "week", tDAY_UNIT, 7 }, - { "day", tDAY_UNIT, 1 }, - { "hour", tHOUR_UNIT, 1 }, - { "minute", tMINUTE_UNIT, 1 }, - { "min", tMINUTE_UNIT, 1 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, - { NULL, 0, 0 } -}; - -/* Assorted relative-time words. */ -static TABLE const OtherTable[] = { - { "tomorrow", tDAY_UNIT, 1 }, - { "yesterday", tDAY_UNIT, -1 }, - { "today", tDAY_UNIT, 0 }, - { "now", tDAY_UNIT, 0 }, - { "last", tUNUMBER, -1 }, - { "this", tMINUTE_UNIT, 0 }, - { "next", tUNUMBER, 2 }, - { "first", tUNUMBER, 1 }, -/* { "second", tUNUMBER, 2 }, */ - { "third", tUNUMBER, 3 }, - { "fourth", tUNUMBER, 4 }, - { "fifth", tUNUMBER, 5 }, - { "sixth", tUNUMBER, 6 }, - { "seventh", tUNUMBER, 7 }, - { "eighth", tUNUMBER, 8 }, - { "ninth", tUNUMBER, 9 }, - { "tenth", tUNUMBER, 10 }, - { "eleventh", tUNUMBER, 11 }, - { "twelfth", tUNUMBER, 12 }, - { "ago", tAGO, 1 }, - { NULL, 0, 0 } -}; - -/* The timezone table. */ -static TABLE const TimezoneTable[] = { - { "gmt", tZONE, HOUR ( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */ - { "utc", tZONE, HOUR ( 0) }, - { "wet", tZONE, HOUR ( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR ( 0) }, /* British Summer */ - { "wat", tZONE, HOUR ( 1) }, /* West Africa */ - { "at", tZONE, HOUR ( 2) }, /* Azores */ -#if 0 - /* For completeness. BST is also British Summer, and GST is - * also Guam Standard. */ - { "bst", tZONE, HOUR ( 3) }, /* Brazil Standard */ - { "gst", tZONE, HOUR ( 3) }, /* Greenland Standard */ -#endif -#if 0 - { "nft", tZONE, HOUR (3.5) }, /* Newfoundland */ - { "nst", tZONE, HOUR (3.5) }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR (3.5) }, /* Newfoundland Daylight */ -#endif - { "ast", tZONE, HOUR ( 4) }, /* Atlantic Standard */ - { "adt", tDAYZONE, HOUR ( 4) }, /* Atlantic Daylight */ - { "est", tZONE, HOUR ( 5) }, /* Eastern Standard */ - { "edt", tDAYZONE, HOUR ( 5) }, /* Eastern Daylight */ - { "cst", tZONE, HOUR ( 6) }, /* Central Standard */ - { "cdt", tDAYZONE, HOUR ( 6) }, /* Central Daylight */ - { "mst", tZONE, HOUR ( 7) }, /* Mountain Standard */ - { "mdt", tDAYZONE, HOUR ( 7) }, /* Mountain Daylight */ - { "pst", tZONE, HOUR ( 8) }, /* Pacific Standard */ - { "pdt", tDAYZONE, HOUR ( 8) }, /* Pacific Daylight */ - { "yst", tZONE, HOUR ( 9) }, /* Yukon Standard */ - { "ydt", tDAYZONE, HOUR ( 9) }, /* Yukon Daylight */ - { "hst", tZONE, HOUR (10) }, /* Hawaii Standard */ - { "hdt", tDAYZONE, HOUR (10) }, /* Hawaii Daylight */ - { "cat", tZONE, HOUR (10) }, /* Central Alaska */ - { "akst", tZONE, HOUR (10) }, /* Alaska Standard */ - { "akdt", tZONE, HOUR (10) }, /* Alaska Daylight */ - { "ahst", tZONE, HOUR (10) }, /* Alaska-Hawaii Standard */ - { "nt", tZONE, HOUR (11) }, /* Nome */ - { "idlw", tZONE, HOUR (12) }, /* International Date Line West */ - { "cet", tZONE, -HOUR (1) }, /* Central European */ - { "met", tZONE, -HOUR (1) }, /* Middle European */ - { "mewt", tZONE, -HOUR (1) }, /* Middle European Winter */ - { "mest", tDAYZONE, -HOUR (1) }, /* Middle European Summer */ - { "mesz", tDAYZONE, -HOUR (1) }, /* Middle European Summer */ - { "swt", tZONE, -HOUR (1) }, /* Swedish Winter */ - { "sst", tDAYZONE, -HOUR (1) }, /* Swedish Summer */ - { "fwt", tZONE, -HOUR (1) }, /* French Winter */ - { "fst", tDAYZONE, -HOUR (1) }, /* French Summer */ - { "eet", tZONE, -HOUR (2) }, /* Eastern Europe, USSR Zone 1 */ - { "bt", tZONE, -HOUR (3) }, /* Baghdad, USSR Zone 2 */ -#if 0 - { "it", tZONE, -HOUR (3.5) },/* Iran */ -#endif - { "zp4", tZONE, -HOUR (4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR (5) }, /* USSR Zone 4 */ -#if 0 - { "ist", tZONE, -HOUR (5.5) },/* Indian Standard */ -#endif - { "zp6", tZONE, -HOUR (6) }, /* USSR Zone 5 */ -#if 0 - /* For completeness. NST is also Newfoundland Standard, and SST is - * also Swedish Summer. */ - { "nst", tZONE, -HOUR (6.5) },/* North Sumatra */ - { "sst", tZONE, -HOUR (7) }, /* South Sumatra, USSR Zone 6 */ -#endif /* 0 */ - { "wast", tZONE, -HOUR (7) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR (7) }, /* West Australian Daylight */ -#if 0 - { "jt", tZONE, -HOUR (7.5) },/* Java (3pm in Cronusland!) */ -#endif - { "cct", tZONE, -HOUR (8) }, /* China Coast, USSR Zone 7 */ - { "jst", tZONE, -HOUR (9) }, /* Japan Standard, USSR Zone 8 */ -#if 0 - { "cast", tZONE, -HOUR (9.5) },/* Central Australian Standard */ - { "cadt", tDAYZONE, -HOUR (9.5) },/* Central Australian Daylight */ -#endif - { "east", tZONE, -HOUR (10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR (10) }, /* Eastern Australian Daylight */ - { "gst", tZONE, -HOUR (10) }, /* Guam Standard, USSR Zone 9 */ - { "nzt", tZONE, -HOUR (12) }, /* New Zealand */ - { "nzst", tZONE, -HOUR (12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR (12) }, /* New Zealand Daylight */ - { "idle", tZONE, -HOUR (12) }, /* International Date Line East */ - { NULL, 0, 0 } -}; - -/* Military timezone table. */ -static TABLE const MilitaryTable[] = { - { "a", tZONE, HOUR ( 1) }, - { "b", tZONE, HOUR ( 2) }, - { "c", tZONE, HOUR ( 3) }, - { "d", tZONE, HOUR ( 4) }, - { "e", tZONE, HOUR ( 5) }, - { "f", tZONE, HOUR ( 6) }, - { "g", tZONE, HOUR ( 7) }, - { "h", tZONE, HOUR ( 8) }, - { "i", tZONE, HOUR ( 9) }, - { "k", tZONE, HOUR ( 10) }, - { "l", tZONE, HOUR ( 11) }, - { "m", tZONE, HOUR ( 12) }, - { "n", tZONE, HOUR (- 1) }, - { "o", tZONE, HOUR (- 2) }, - { "p", tZONE, HOUR (- 3) }, - { "q", tZONE, HOUR (- 4) }, - { "r", tZONE, HOUR (- 5) }, - { "s", tZONE, HOUR (- 6) }, - { "t", tZONE, HOUR (- 7) }, - { "u", tZONE, HOUR (- 8) }, - { "v", tZONE, HOUR (- 9) }, - { "w", tZONE, HOUR (-10) }, - { "x", tZONE, HOUR (-11) }, - { "y", tZONE, HOUR (-12) }, - { "z", tZONE, HOUR ( 0) }, - { NULL, 0, 0 } -}; - - - - -/* ARGSUSED */ -static int -yyerror (s) - char *s ATTRIBUTE_UNUSED; -{ - return 0; -} - -static int -ToHour (Hours, Meridian) - int Hours; - MERIDIAN Meridian; -{ - switch (Meridian) - { - case MER24: - if (Hours < 0 || Hours > 23) - return -1; - return Hours; - case MERam: - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - return Hours; - case MERpm: - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - return Hours + 12; - default: - abort (); - } - /* NOTREACHED */ -} - -static int -ToYear (Year) - int Year; -{ - if (Year < 0) - Year = -Year; - - /* XPG4 suggests that years 00-68 map to 2000-2068, and - years 69-99 map to 1969-1999. */ - if (Year < 69) - Year += 2000; - else if (Year < 100) - Year += 1900; - - return Year; -} - -static int -LookupWord (buff) - char *buff; -{ - register char *p; - register char *q; - register const TABLE *tp; - int i; - int abbrev; - - /* Make it lowercase. */ - for (p = buff; *p; p++) - if (ISUPPER ((unsigned char) *p)) - *p = tolower (*p); - - if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0) - { - yylval.Meridian = MERam; - return tMERIDIAN; - } - if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0) - { - yylval.Meridian = MERpm; - return tMERIDIAN; - } - - /* See if we have an abbreviation for a month. */ - if (strlen (buff) == 3) - abbrev = 1; - else if (strlen (buff) == 4 && buff[3] == '.') - { - abbrev = 1; - buff[3] = '\0'; - } - else - abbrev = 0; - - for (tp = MonthDayTable; tp->name; tp++) - { - if (abbrev) - { - if (strncmp (buff, tp->name, 3) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - } - else if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - } - - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - - if (strcmp (buff, "dst") == 0) - return tDST; - - for (tp = UnitsTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - i = strlen (buff) - 1; - if (buff[i] == 's') - { - buff[i] = '\0'; - for (tp = UnitsTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ - } - - for (tp = OtherTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - - /* Military timezones. */ - if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff)) - { - for (tp = MilitaryTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - } - - /* Drop out any periods and try the timezone table again. */ - for (i = 0, p = q = buff; *q; q++) - if (*q != '.') - *p++ = *q; - else - i++; - *p = '\0'; - if (i) - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp (buff, tp->name) == 0) - { - yylval.Number = tp->value; - return tp->type; - } - - return tID; -} - -static int -yylex () -{ - register unsigned char c; - register char *p; - char buff[20]; - int Count; - int sign; - - for (;;) - { - while (ISSPACE ((unsigned char) *yyInput)) - yyInput++; - - if (ISDIGIT (c = *yyInput) || c == '-' || c == '+') - { - if (c == '-' || c == '+') - { - sign = c == '-' ? -1 : 1; - if (!ISDIGIT (*++yyInput)) - /* skip the '-' sign */ - continue; - } - else - sign = 0; - for (yylval.Number = 0; ISDIGIT (c = *yyInput++);) - yylval.Number = 10 * yylval.Number + c - '0'; - yyInput--; - if (sign < 0) - yylval.Number = -yylval.Number; - /* Ignore ordinal suffixes on numbers */ - c = *yyInput; - if (c == 's' || c == 'n' || c == 'r' || c == 't') { - c = *++yyInput; - if (c == 't' || c == 'd' || c == 'h') { - yyInput++; - } else { - yyInput--; - } - } - return sign ? tSNUMBER : tUNUMBER; - } - if (ISALPHA (c)) - { - for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.';) - if (p < &buff[sizeof buff - 1]) - *p++ = c; - *p = '\0'; - yyInput--; - return LookupWord (buff); - } - if (c != '(') - return *yyInput++; - Count = 0; - do - { - c = *yyInput++; - if (c == '\0') - return c; - if (c == '(') - Count++; - else if (c == ')') - Count--; - } - while (Count > 0); - } -} - -#define TM_YEAR_ORIGIN 1900 - -/* Yield A - B, measured in seconds. */ -static long -difftm (struct tm *a, struct tm *b) -{ - int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); - int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - long days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay / 100 - by / 100) - + ((ay / 100 >> 2) - (by / 100 >> 2)) - /* + difference in years * 365 */ - + (long) (ay - by) * 365 - ); - return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec)); -} - -time_t php_parse_date(char *p, time_t *now) -{ - struct tm tm, tm0, *tmp; - time_t Start; - - yyInput = p; - Start = now ? *now : time ((time_t *) NULL); - tmp = localtime (&Start); - if (!tmp) - return -1; - yyYear = tmp->tm_year + TM_YEAR_ORIGIN; - yyMonth = tmp->tm_mon + 1; - yyDay = tmp->tm_mday; - yyHour = tmp->tm_hour; - yyMinutes = tmp->tm_min; - yySeconds = tmp->tm_sec; - tm.tm_isdst = tmp->tm_isdst; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMinutes = 0; - yyRelHour = 0; - yyRelDay = 0; - yyRelMonth = 0; - yyRelYear = 0; - yyHaveDate = 0; - yyHaveDay = 0; - yyHaveRel = 0; - yyHaveTime = 0; - yyHaveZone = 0; - - if (yyparse () - || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1) - return -1; - - tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear; - tm.tm_mon = yyMonth - 1 + yyRelMonth; - tm.tm_mday = yyDay + yyRelDay; - if (yyHaveTime || (yyHaveRel && !yyHaveDate && !yyHaveDay)) - { - tm.tm_hour = ToHour (yyHour, yyMeridian); - if (tm.tm_hour < 0) - return -1; - tm.tm_min = yyMinutes; - tm.tm_sec = yySeconds; - } - else - { - tm.tm_hour = tm.tm_min = tm.tm_sec = 0; - } - tm.tm_hour += yyRelHour; - tm.tm_min += yyRelMinutes; - tm.tm_sec += yyRelSeconds; - - /* Let mktime deduce tm_isdst if we have an absolute timestamp, - or if the relative timestamp mentions days, months, or years. */ - if (yyHaveDate | yyHaveDay | yyHaveTime | yyRelDay | yyRelMonth | yyRelYear) - tm.tm_isdst = -1; - - tm0 = tm; - - Start = mktime (&tm); - - if (Start == (time_t) -1) - { - - /* Guard against falsely reporting errors near the time_t boundaries - when parsing times in other time zones. For example, if the min - time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead - of UTC, then the min localtime value is 1970-01-01 08:00:00; if - we apply mktime to 1970-01-01 00:00:00 we will get an error, so - we apply mktime to 1970-01-02 08:00:00 instead and adjust the time - zone by 24 hours to compensate. This algorithm assumes that - there is no DST transition within a day of the time_t boundaries. */ - if (yyHaveZone) - { - tm = tm0; - if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN) - { - tm.tm_mday++; - yyTimezone -= 24 * 60; - } - else - { - tm.tm_mday--; - yyTimezone += 24 * 60; - } - Start = mktime (&tm); - } - - if (Start == (time_t) -1) - return Start; - } - - if (yyHaveDay && !yyHaveDate) - { - tm.tm_mday += ((yyDayNumber - tm.tm_wday + 7) % 7 - + 7 * (yyDayOrdinal - (0 < yyDayOrdinal))); - Start = mktime (&tm); - if (Start == (time_t) -1) - return Start; - } - - if (yyHaveZone) - { - long delta; - struct tm *gmt = gmtime (&Start); - if (!gmt) - return -1; - delta = yyTimezone * 60L + difftm (&tm, gmt); - if ((Start + delta < Start) != (delta < 0)) - return -1; /* time_t overflow */ - Start += delta; - } - - return Start; -} diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h deleted file mode 100644 index 8b0c0f1965..0000000000 --- a/ext/standard/php_array.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - | Rasmus Lerdorf <rasmus@php.net> | - | Andrei Zmievski <andrei@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_ARRAY_H -#define PHP_ARRAY_H - -PHP_MINIT_FUNCTION(array); -PHP_MSHUTDOWN_FUNCTION(array); - -PHP_FUNCTION(ksort); -PHP_FUNCTION(krsort); -PHP_FUNCTION(natsort); -PHP_FUNCTION(natcasesort); -PHP_FUNCTION(asort); -PHP_FUNCTION(arsort); -PHP_FUNCTION(sort); -PHP_FUNCTION(rsort); -PHP_FUNCTION(usort); -PHP_FUNCTION(uasort); -PHP_FUNCTION(uksort); -PHP_FUNCTION(array_walk); -PHP_FUNCTION(array_walk_recursive); -PHP_FUNCTION(count); -PHP_FUNCTION(end); -PHP_FUNCTION(prev); -PHP_FUNCTION(next); -PHP_FUNCTION(reset); -PHP_FUNCTION(current); -PHP_FUNCTION(key); -PHP_FUNCTION(min); -PHP_FUNCTION(max); -PHP_FUNCTION(in_array); -PHP_FUNCTION(array_search); -PHP_FUNCTION(extract); -PHP_FUNCTION(compact); -PHP_FUNCTION(array_fill); -PHP_FUNCTION(range); -PHP_FUNCTION(shuffle); -PHP_FUNCTION(array_multisort); -PHP_FUNCTION(array_push); -PHP_FUNCTION(array_pop); -PHP_FUNCTION(array_shift); -PHP_FUNCTION(array_unshift); -PHP_FUNCTION(array_splice); -PHP_FUNCTION(array_slice); -PHP_FUNCTION(array_merge); -PHP_FUNCTION(array_merge_recursive); -PHP_FUNCTION(array_keys); -PHP_FUNCTION(array_values); -PHP_FUNCTION(array_count_values); -PHP_FUNCTION(array_reverse); -PHP_FUNCTION(array_reduce); -PHP_FUNCTION(array_pad); -PHP_FUNCTION(array_flip); -PHP_FUNCTION(array_change_key_case); -PHP_FUNCTION(array_rand); -PHP_FUNCTION(array_unique); -PHP_FUNCTION(array_intersect); -PHP_FUNCTION(array_intersect_assoc); -PHP_FUNCTION(array_diff); -PHP_FUNCTION(array_diff_assoc); -PHP_FUNCTION(array_sum); -PHP_FUNCTION(array_filter); -PHP_FUNCTION(array_map); -PHP_FUNCTION(array_key_exists); -PHP_FUNCTION(array_chunk); -PHP_FUNCTION(array_combine); - -HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); -PHPAPI int php_array_merge(HashTable *dest, HashTable *src, int recursive TSRMLS_DC); -int multisort_compare(const void *a, const void *b TSRMLS_DC); - -typedef struct { - int *multisort_flags[2]; - int (*compare_func)(zval *result, zval *op1, zval *op2 TSRMLS_DC); -} php_array_globals; - -#ifdef ZTS -#define ARRAYG(v) TSRMG(array_globals_id, php_array_globals *, v) -extern int array_globals_id; -#else -#define ARRAYG(v) (array_globals.v) -extern php_array_globals array_globals; -#endif - -#endif /* PHP_ARRAY_H */ diff --git a/ext/standard/php_assert.h b/ext/standard/php_assert.h deleted file mode 100644 index 54900db991..0000000000 --- a/ext/standard/php_assert.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_ASSERT_H -#define PHP_ASSERT_H - -PHP_MINIT_FUNCTION(assert); -PHP_MSHUTDOWN_FUNCTION(assert); -PHP_RINIT_FUNCTION(assert); -PHP_RSHUTDOWN_FUNCTION(assert); -PHP_MINFO_FUNCTION(assert); -PHP_FUNCTION(assert); -PHP_FUNCTION(assert_options); - -#endif /* PHP_ASSERT_H */ diff --git a/ext/standard/php_browscap.h b/ext/standard/php_browscap.h deleted file mode 100644 index 5318fdaffb..0000000000 --- a/ext/standard/php_browscap.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_BROWSCAP_H -#define PHP_BROWSCAP_H - -PHP_MINIT_FUNCTION(browscap); -PHP_MSHUTDOWN_FUNCTION(browscap); - -PHP_FUNCTION(get_browser); - -#endif /* PHP_BROWSCAP_H */ diff --git a/ext/standard/php_crypt.h b/ext/standard/php_crypt.h deleted file mode 100644 index e4983015ba..0000000000 --- a/ext/standard/php_crypt.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Stig Bakken <ssb@gaurdian.no> | - | Zeev Suraski <zeev@zend.com> | - | Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_CRYPT_H -#define PHP_CRYPT_H - -PHP_FUNCTION(crypt); -#if HAVE_CRYPT -PHP_MINIT_FUNCTION(crypt); -PHP_RINIT_FUNCTION(crypt); -#endif - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/php_dir.h b/ext/standard/php_dir.h deleted file mode 100644 index 40c29ffd55..0000000000 --- a/ext/standard/php_dir.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_DIR_H -#define PHP_DIR_H - -/* directory functions */ -PHP_MINIT_FUNCTION(dir); -PHP_RINIT_FUNCTION(dir); -PHP_FUNCTION(opendir); -PHP_FUNCTION(closedir); -PHP_FUNCTION(chdir); -#if defined(HAVE_CHROOT) && !defined(ZTS) && ENABLE_CHROOT_FUNC -PHP_FUNCTION(chroot); -#endif -PHP_FUNCTION(getcwd); -PHP_FUNCTION(rewinddir); -PHP_NAMED_FUNCTION(php_if_readdir); -PHP_FUNCTION(getdir); -PHP_FUNCTION(glob); -PHP_FUNCTION(scandir); - -#endif /* PHP_DIR_H */ diff --git a/ext/standard/php_ext_syslog.h b/ext/standard/php_ext_syslog.h deleted file mode 100644 index 18f4667967..0000000000 --- a/ext/standard/php_ext_syslog.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_EXT_SYSLOG_H -#define PHP_EXT_SYSLOG_H - -#ifdef HAVE_SYSLOG_H - -#include "php_syslog.h" - -PHP_MINIT_FUNCTION(syslog); -PHP_RINIT_FUNCTION(syslog); -PHP_RSHUTDOWN_FUNCTION(syslog); - -PHP_FUNCTION(openlog); -PHP_FUNCTION(syslog); -PHP_FUNCTION(closelog); -PHP_FUNCTION(define_syslog_variables); - -#endif - -#endif /* PHP_EXT_SYSLOG_H */ diff --git a/ext/standard/php_filestat.h b/ext/standard/php_filestat.h deleted file mode 100644 index 39d08ecfc7..0000000000 --- a/ext/standard/php_filestat.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_FILESTAT_H -#define PHP_FILESTAT_H - -PHP_RINIT_FUNCTION(filestat); -PHP_RSHUTDOWN_FUNCTION(filestat); - -PHP_FUNCTION(clearstatcache); -PHP_FUNCTION(fileatime); -PHP_FUNCTION(filectime); -PHP_FUNCTION(filegroup); -PHP_FUNCTION(fileinode); -PHP_FUNCTION(filemtime); -PHP_FUNCTION(fileowner); -PHP_FUNCTION(fileperms); -PHP_FUNCTION(filesize); -PHP_FUNCTION(filetype); -PHP_FUNCTION(is_writable); -PHP_FUNCTION(is_readable); -PHP_FUNCTION(is_executable); -PHP_FUNCTION(is_file); -PHP_FUNCTION(is_dir); -PHP_FUNCTION(is_link); -PHP_FUNCTION(file_exists); -PHP_NAMED_FUNCTION(php_if_stat); -PHP_NAMED_FUNCTION(php_if_lstat); -PHP_FUNCTION(disk_total_space); -PHP_FUNCTION(disk_free_space); -PHP_FUNCTION(chown); -PHP_FUNCTION(chgrp); -PHP_FUNCTION(chmod); -#if HAVE_UTIME -PHP_FUNCTION(touch); -#endif -PHP_FUNCTION(clearstatcache); - -#define MAKE_LONG_ZVAL_INCREF(name, val)\ - MAKE_STD_ZVAL(name); \ - ZVAL_LONG(name, val); \ - name->refcount++; - -#ifdef PHP_WIN32 -#define S_IRUSR S_IREAD -#define S_IWUSR S_IWRITE -#define S_IXUSR S_IEXEC -#define S_IRGRP S_IREAD -#define S_IWGRP S_IWRITE -#define S_IXGRP S_IEXEC -#define S_IROTH S_IREAD -#define S_IWOTH S_IWRITE -#define S_IXOTH S_IEXEC - -#undef getgid -#define getgroups(a, b) 0 -#define getgid() 1 -#define getuid() 1 -#endif - -#endif /* PHP_FILESTAT_H */ diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c deleted file mode 100644 index d733279119..0000000000 --- a/ext/standard/php_fopen_wrapper.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - | Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include "php.h" -#include "php_globals.h" -#include "php_standard.h" -#include "php_fopen_wrappers.h" -#include "SAPI.h" - -static size_t php_stream_output_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - PHPWRITE(buf, count); - return count; -} - -static size_t php_stream_output_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - stream->eof = 1; - return 0; -} - -static int php_stream_output_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - return 0; -} - -static int php_stream_output_flush(php_stream *stream TSRMLS_DC) -{ - sapi_flush(TSRMLS_C); - return 0; -} - -php_stream_ops php_stream_output_ops = { - php_stream_output_write, - php_stream_output_read, - php_stream_output_close, - php_stream_output_flush, - "Output", - NULL, /* seek */ - NULL, /* cast */ - NULL, /* stat */ - NULL /* set_option */ -}; - -static size_t php_stream_input_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) -{ - return -1; -} - -static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) -{ - size_t read_bytes = 0; - if(!stream->eof) { - if(SG(request_info).raw_post_data) { /* data has already been read by a post handler */ - read_bytes = SG(request_info).raw_post_data_length - stream->position; - if(read_bytes <= count) { - stream->eof = 1; - } else { - read_bytes = count; - } - if(read_bytes) { - memcpy(buf, SG(request_info).raw_post_data + stream->position, read_bytes); - } - } else if(sapi_module.read_post) { - read_bytes = sapi_module.read_post(buf, count TSRMLS_CC); - if(read_bytes <= 0){ - stream->eof = 1; - read_bytes = 0; - } - } else { - stream->eof = 1; - } - } - - SG(read_post_bytes) += read_bytes; - return read_bytes; -} - -static int php_stream_input_close(php_stream *stream, int close_handle TSRMLS_DC) -{ - return 0; -} - -static int php_stream_input_flush(php_stream *stream TSRMLS_DC) -{ - return -1; -} - -php_stream_ops php_stream_input_ops = { - php_stream_input_write, - php_stream_input_read, - php_stream_input_close, - php_stream_input_flush, - "Input", - NULL, /* seek */ - NULL, /* cast */ - NULL, /* stat */ - NULL /* set_option */ -}; - -static void php_stream_apply_filter_list(php_stream *stream, char *filterlist, int read_chain, int write_chain TSRMLS_DC) { - char *p, *token; - php_stream_filter *temp_filter; - - p = php_strtok_r(filterlist, "|", &token); - while (p) { - if (read_chain) { - if (temp_filter = php_stream_filter_create(p, "", 0, php_stream_is_persistent(stream) TSRMLS_CC)) { - php_stream_filter_append(&stream->readfilters, temp_filter); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create filter (%s)\n", p); - } - } - if (write_chain) { - if (temp_filter = php_stream_filter_create(p, "", 0, php_stream_is_persistent(stream) TSRMLS_CC)) { - php_stream_filter_append(&stream->writefilters, temp_filter); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create filter (%s)\n", p); - } - } - p = php_strtok_r(NULL, "|", &token); - } -} - - -php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC) -{ - int fd = -1; - int mode_rw = 0; - php_stream * stream = NULL; - char *p, *token, *pathdup; - - if (!strncasecmp(path, "php://", 6)) - path += 6; - - if (!strcasecmp(path, "output")) { - return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb"); - } - - if (!strcasecmp(path, "input")) { - return php_stream_alloc(&php_stream_input_ops, NULL, 0, "rb"); - } - - if (!strcasecmp(path, "stdin")) { - fd = dup(STDIN_FILENO); - } else if (!strcasecmp(path, "stdout")) { - fd = dup(STDOUT_FILENO); - } else if (!strcasecmp(path, "stderr")) { - fd = dup(STDERR_FILENO); - } - - if (fd) { - stream = php_stream_fopen_from_fd(fd, mode); - if (stream == NULL) - close(fd); - } - - if (!strncasecmp(path, "filter/", 7)) { - /* Save time/memory when chain isn't specified */ - if (strchr(mode, 'r') || strchr(mode, '+')) { - mode_rw |= PHP_STREAM_FILTER_READ; - } - if (strchr(mode, 'w') || strchr(mode, '+') || strchr(mode, 'a')) { - mode_rw |= PHP_STREAM_FILTER_WRITE; - } - pathdup = estrndup(path + 6, strlen(path + 6)); - p = strstr(pathdup, "/resource="); - if (!p) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "No URL resource specified."); - efree(pathdup); - return NULL; - } - if (!(stream = php_stream_open_wrapper(p + 10, mode, options, opened_path))) { - efree(pathdup); - return NULL; - } - - *p = '\0'; - - p = php_strtok_r(pathdup + 1, "/", &token); - while (p) { - if (!strncasecmp(p, "read=", 5)) { - php_stream_apply_filter_list(stream, p + 5, 1, 0 TSRMLS_CC); - } else if (!strncasecmp(p, "write=", 6)) { - php_stream_apply_filter_list(stream, p + 6, 0, 1 TSRMLS_CC); - } else { - php_stream_apply_filter_list(stream, p, mode_rw & PHP_STREAM_FILTER_READ, mode_rw & PHP_STREAM_FILTER_WRITE TSRMLS_CC); - } - p = php_strtok_r(NULL, "/", &token); - } - efree(pathdup); - } - - return stream; -} - -static php_stream_wrapper_ops php_stdio_wops = { - php_stream_url_wrap_php, - NULL, /* close */ - NULL, /* fstat */ - NULL, /* stat */ - NULL, /* opendir */ - "PHP" -}; - -php_stream_wrapper php_stream_php_wrapper = { - &php_stdio_wops, - NULL, - 0, /* is_url */ -}; - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h deleted file mode 100644 index fe92880ed6..0000000000 --- a/ext/standard/php_fopen_wrappers.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - | Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_FOPEN_WRAPPERS_H -#define PHP_FOPEN_WRAPPERS_H - -php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -php_stream *php_stream_url_wrap_ftp(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); -extern php_stream_wrapper php_stream_http_wrapper; -extern php_stream_wrapper php_stream_ftp_wrapper; -extern php_stream_wrapper php_stream_php_wrapper; - -#endif diff --git a/ext/standard/php_ftok.h b/ext/standard/php_ftok.h deleted file mode 100644 index 69c0e8fa75..0000000000 --- a/ext/standard/php_ftok.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Andrew Sitnikov <sitnikov@infonet.ee> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_FTOK_H -#define PHP_FTOK_H - -#if HAVE_FTOK -PHP_FUNCTION(ftok); -#endif - -#endif /* PHP_FTOK_H */ diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h deleted file mode 100644 index 0b5cb0171f..0000000000 --- a/ext/standard/php_image.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_IMAGE_H -#define PHP_IMAGE_H - -PHP_FUNCTION(getimagesize); - -PHP_FUNCTION(image_type_to_mime_type); - -/* {{{ enum image_filetype - This enum is used to have ext/standard/image.c and ext/exif/exif.c use - the same constants for file types. -*/ -typedef enum -{ IMAGE_FILETYPE_UNKNOWN=0, - IMAGE_FILETYPE_GIF=1, - IMAGE_FILETYPE_JPEG, - IMAGE_FILETYPE_PNG, - IMAGE_FILETYPE_SWF, - IMAGE_FILETYPE_PSD, - IMAGE_FILETYPE_BMP, - IMAGE_FILETYPE_TIFF_II, /* intel */ - IMAGE_FILETYPE_TIFF_MM, /* motorola */ - IMAGE_FILETYPE_JPC, - IMAGE_FILETYPE_JP2, - IMAGE_FILETYPE_JPX, - IMAGE_FILETYPE_JB2, - IMAGE_FILETYPE_SWC, - IMAGE_FILETYPE_IFF, - IMAGE_FILETYPE_WBMP, - /* IMAGE_FILETYPE_JPEG2000 is a userland alias for IMAGE_FILETYPE_JPC */ - IMAGE_FILETYPE_XBM -/* WHEN EXTENDING: PLEASE ALSO REGISTER IN image.c:PHP_MINIT_FUNCTION(imagetypes) */ -} image_filetype; -/* }}} */ - -PHP_MINIT_FUNCTION(imagetypes); - -PHPAPI int php_getimagetype(php_stream *stream, char *filetype TSRMLS_DC); - -PHPAPI const char * php_image_type_to_mime_type(int image_type); - -#endif /* PHP_IMAGE_H */ diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h deleted file mode 100644 index e0f5a7875f..0000000000 --- a/ext/standard/php_incomplete_class.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_INCOMPLETE_CLASS_H -#define PHP_INCOMPLETE_CLASS_H - -#include "ext/standard/basic_functions.h" - -#define PHP_IC_ENTRY \ - BG(incomplete_class) - -#define PHP_SET_CLASS_ATTRIBUTES(struc) \ - /* OBJECTS_FIXME: Fix for new object model */ \ - if (Z_OBJCE_P(struc) == BG(incomplete_class)) { \ - class_name = php_lookup_class_name(struc, &name_len, 1); \ - free_class_name = 1; \ - } else { \ - class_name = Z_OBJCE_P(struc)->name; \ - name_len = Z_OBJCE_P(struc)->name_length; \ - } - -#define PHP_CLEANUP_CLASS_ATTRIBUTES() \ - if (free_class_name) efree(class_name) - -#define PHP_CLASS_ATTRIBUTES \ - char *class_name; \ - size_t name_len; \ - zend_bool free_class_name = 0 \ - -#define INCOMPLETE_CLASS "__PHP_Incomplete_Class" -#define MAGIC_MEMBER "__PHP_Incomplete_Class_Name" - -#ifdef __cplusplus -extern "C" { -#endif - -zend_class_entry *php_create_incomplete_class(TSRMLS_D); - -char *php_lookup_class_name(zval *object, size_t *nlen, zend_bool del); -void php_store_class_name(zval *object, const char *name, size_t len); - -#ifdef __cplusplus -}; -#endif - -#endif diff --git a/ext/standard/php_iptc.h b/ext/standard/php_iptc.h deleted file mode 100644 index d4a61a8660..0000000000 --- a/ext/standard/php_iptc.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_IPTC_H -#define PHP_IPTC_H - -PHP_FUNCTION(iptcparse); -PHP_FUNCTION(iptcembed); - -#endif /* PHP_IPTC_H */ diff --git a/ext/standard/php_lcg.h b/ext/standard/php_lcg.h deleted file mode 100644 index 746ec46d60..0000000000 --- a/ext/standard/php_lcg.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_LCG_H -#define PHP_LCG_H - -#include "ext/standard/basic_functions.h" - -typedef struct { - php_int32 s1; - php_int32 s2; - int seeded; -} php_lcg_globals; - -PHPAPI double php_combined_lcg(TSRMLS_D); -PHP_FUNCTION(lcg_value); - -PHP_MINIT_FUNCTION(lcg); -PHP_RINIT_FUNCTION(lcg); - -#ifdef ZTS -#define LCG(v) TSRMG(lcg_globals_id, php_lcg_globals *, v) -#else -#define LCG(v) (lcg_globals.v) -#endif - -#endif diff --git a/ext/standard/php_link.h b/ext/standard/php_link.h deleted file mode 100644 index f6c05ddde4..0000000000 --- a/ext/standard/php_link.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_LINK_H -#define PHP_LINK_H - -#ifdef HAVE_SYMLINK - -PHP_FUNCTION(link); -PHP_FUNCTION(readlink); -PHP_FUNCTION(linkinfo); -PHP_FUNCTION(symlink); - -#endif - -#endif /* PHP_LINK_H */ diff --git a/ext/standard/php_mail.h b/ext/standard/php_mail.h deleted file mode 100644 index b9d73047d6..0000000000 --- a/ext/standard/php_mail.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_MAIL_H -#define PHP_MAIL_H - -PHP_FUNCTION(mail); -PHP_MINFO_FUNCTION(mail); - -#if HAVE_SENDMAIL - -PHP_FUNCTION(ezmlm_hash); -PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd TSRMLS_DC); - -#endif - -#endif /* PHP_MAIL_H */ diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h deleted file mode 100644 index 12e8224a12..0000000000 --- a/ext/standard/php_math.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Jim Winstead <jimw@php.net> | - | Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_MATH_H -#define PHP_MATH_H - -PHPAPI char *_php_math_number_format(double, int, char , char); - -PHP_FUNCTION(sin); -PHP_FUNCTION(cos); -PHP_FUNCTION(tan); -PHP_FUNCTION(asin); -PHP_FUNCTION(acos); -PHP_FUNCTION(atan); -PHP_FUNCTION(atan2); -PHP_FUNCTION(pi); -PHP_FUNCTION(exp); -PHP_FUNCTION(log); -PHP_FUNCTION(log10); -PHP_FUNCTION(is_finite); -PHP_FUNCTION(is_infinite); -PHP_FUNCTION(is_nan); -PHP_FUNCTION(pow); -PHP_FUNCTION(sqrt); -PHP_FUNCTION(srand); -PHP_FUNCTION(rand); -PHP_FUNCTION(getrandmax); -PHP_FUNCTION(mt_srand); -PHP_FUNCTION(mt_rand); -PHP_FUNCTION(mt_getrandmax); -PHP_FUNCTION(abs); -PHP_FUNCTION(ceil); -PHP_FUNCTION(floor); -PHP_FUNCTION(round); -PHP_FUNCTION(decbin); -PHP_FUNCTION(dechex); -PHP_FUNCTION(decoct); -PHP_FUNCTION(bindec); -PHP_FUNCTION(hexdec); -PHP_FUNCTION(octdec); -PHP_FUNCTION(base_convert); -PHP_FUNCTION(number_format); -PHP_FUNCTION(fmod); -PHP_FUNCTION(deg2rad); -PHP_FUNCTION(rad2deg); - - /* - WARNING: these functions are expermental: they could change their names or - disappear in the next version of PHP! - */ -PHP_FUNCTION(hypot); -PHP_FUNCTION(expm1); -PHP_FUNCTION(log1p); - - -PHP_FUNCTION(sinh); -PHP_FUNCTION(cosh); -PHP_FUNCTION(tanh); - -#ifdef HAVE_ASINH -PHP_FUNCTION(asinh); -#endif -#ifdef HAVE_ACOSH -PHP_FUNCTION(acosh); -#endif -#ifdef HAVE_ATANH -PHP_FUNCTION(atanh); -#endif - -#include <math.h> - -#ifndef M_E -#define M_E 2.7182818284590452354 /* e */ -#endif - -#ifndef M_LOG2E -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#endif - -#ifndef M_LOG10E -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#endif - -#ifndef M_LN2 -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#endif - -#ifndef M_LN10 -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 /* pi */ -#endif - -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#endif - -#ifndef M_PI_4 -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#endif - -#ifndef M_1_PI -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#endif - -#ifndef M_2_PI -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#endif - -#ifndef M_SQRTPI -#define M_SQRTPI 1.77245385090551602729 /* sqrt(pi) */ -#endif - -#ifndef M_2_SQRTPI -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#endif - -#ifndef M_LNPI -#define M_LNPI 1.14472988584940017414 /* ln(pi) */ -#endif - -#ifndef M_EULER -#define M_EULER 0.57721566490153286061 /* Euler constant */ -#endif - -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#endif - -#ifndef M_SQRT1_2 -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ -#endif - -#ifndef M_SQRT3 -#define M_SQRT3 1.73205080756887729352 /* sqrt(3) */ -#endif - -#endif /* PHP_MATH_H */ diff --git a/ext/standard/php_metaphone.h b/ext/standard/php_metaphone.h deleted file mode 100644 index 37fea230fc..0000000000 --- a/ext/standard/php_metaphone.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Thies C. Arntzen <thies@thieso.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_METAPHONE_H -#define PHP_METAPHONE_H - -PHP_FUNCTION(metaphone); - -#endif diff --git a/ext/standard/php_parsedate.h b/ext/standard/php_parsedate.h deleted file mode 100644 index 883267cdd7..0000000000 --- a/ext/standard/php_parsedate.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_PARSEDATE_H -#define PHP_PARSEDATE_H - -#include <time.h> - -time_t php_parse_date(char *p, time_t *now); - -#endif diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h deleted file mode 100644 index 2b0a631d68..0000000000 --- a/ext/standard/php_rand.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - | Pedro Melo <melo@ip.pt> | - | Sterling Hughes <sterling@php.net> | - | | - | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef PHP_RAND_H -#define PHP_RAND_H - -#include <stdlib.h> -#include "basic_functions.h" - -/* System Rand functions */ -#ifndef RAND_MAX -#define RAND_MAX (1<<15) -#endif - -#if HAVE_LRAND48 -#define PHP_RAND_MAX 2147483647 -#else -#define PHP_RAND_MAX RAND_MAX -#endif - -#define RAND_RANGE(__n, __min, __max, __tmax) \ - (__n) = (__min) + (long) ((double) ((__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0))) - -/* MT Rand */ -#define PHP_MT_RAND_MAX ((long) (0x7FFFFFFF)) /* (1<<31) - 1 */ - -PHPAPI void php_srand(long seed TSRMLS_DC); -PHPAPI long php_rand(TSRMLS_D); -PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC); -PHPAPI php_uint32 php_mt_rand(TSRMLS_D); - -#endif /* PHP_RAND_H */ diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h deleted file mode 100644 index 47ef596eba..0000000000 --- a/ext/standard/php_smart_str.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_SMART_STR_H -#define PHP_SMART_STR_H - -#include "php_smart_str_public.h" - -#include <stdlib.h> -#include <zend.h> - -#define smart_str_0(x) do { if ((x)->c) { (x)->c[(x)->len] = '\0'; } } while (0) - -#ifndef SMART_STR_PREALLOC -#define SMART_STR_PREALLOC 128 -#endif - -#define smart_str_alloc(d, n, what) {\ - if (!d->c) d->len = d->a = 0; \ - newlen = d->len + n; \ - if (newlen >= d->a) {\ - d->c = perealloc(d->c, newlen + SMART_STR_PREALLOC + 1, what); \ - d->a = newlen + SMART_STR_PREALLOC; \ - }\ -} - -#define smart_str_appends_ex(dest, src, what) smart_str_appendl_ex(dest, src, strlen(src), what) -#define smart_str_appends(dest, src) smart_str_appendl(dest, src, strlen(src)) - -#define smart_str_appendc(dest, c) smart_str_appendc_ex(dest, c, 0) -#define smart_str_free(s) smart_str_free_ex(s, 0) -#define smart_str_appendl(dest, src, len) smart_str_appendl_ex(dest, src, len, 0) -#define smart_str_append(dest, src) smart_str_append_ex(dest, src, 0) -#define smart_str_append_long(dest, val) smart_str_append_long_ex(dest, val, 0) -#define smart_str_append_unsigned(dest, val) smart_str_append_unsigned_ex(dest, val, 0) - -static inline void smart_str_appendc_ex(smart_str *dest, unsigned char c, int what) -{ - size_t newlen; - - smart_str_alloc(dest, 1, what); - dest->len = newlen; - ((unsigned char *) dest->c)[dest->len - 1] = c; -} - - -static inline void smart_str_free_ex(smart_str *s, int what) -{ - if (s->c) { - pefree(s->c, what); - s->c = NULL; - } - s->a = s->len = 0; -} - -static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t len, int what) -{ - size_t newlen; - - smart_str_alloc(dest, len, what); - memcpy(dest->c + dest->len, src, len); - dest->len = newlen; -} - -/* buf points to the END of the buffer */ -static inline char *smart_str_print_unsigned(char *buf, unsigned long num) -{ - char *p = buf; - - *p = '\0'; - do { - *--p = (char)(num % 10) + '0'; - num /= 10; - } while (num > 0); - - return p; -} - -/* buf points to the END of the buffer */ -static inline char *smart_str_print_long(char *buf, long num) -{ - char *p; - - if (num < 0) { - /* this might cause problems when dealing with LONG_MIN - and machines which don't support long long. Works - flawlessly on 32bit x86 */ - p = smart_str_print_unsigned(buf, -num); - *--p = '-'; - } else { - p = smart_str_print_unsigned(buf, num); - } - - return p; -} - -static inline void smart_str_append_long_ex(smart_str *dest, long num, int type) -{ - char buf[32]; - char *p = smart_str_print_long(buf + sizeof(buf) - 1, num); - smart_str_appendl_ex(dest, p, (buf + sizeof(buf) - 1) - p, type); -} - -static inline void smart_str_append_unsigned_ex(smart_str *dest, long num, int type) -{ - char buf[32]; - char *p = smart_str_print_unsigned(buf + sizeof(buf) - 1, num); - smart_str_appendl_ex(dest, p, (buf + sizeof(buf) - 1) - p, type); -} - -static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what) -{ - smart_str_appendl_ex(dest, src->c, src->len, what); -} - -static inline void smart_str_setl(smart_str *dest, const char *src, size_t len) -{ - dest->len = len; - dest->a = len + 1; - dest->c = (char *) src; -} - -static inline void smart_str_sets(smart_str *dest, const char *src) -{ - smart_str_setl(dest, src, strlen(src)); -} - -#endif diff --git a/ext/standard/php_smart_str_public.h b/ext/standard/php_smart_str_public.h deleted file mode 100644 index 9eac1b7ad8..0000000000 --- a/ext/standard/php_smart_str_public.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_SMART_STR_PUBLIC_H -#define PHP_SMART_STR_PUBLIC_H - -#include <sys/types.h> - -typedef struct { - char *c; - size_t len; - size_t a; -} smart_str; - -#endif diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h deleted file mode 100644 index aaa52bd6cb..0000000000 --- a/ext/standard/php_standard.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "basic_functions.h" -#include "php_math.h" -#include "php_string.h" -#include "base64.h" -#include "php_dir.h" -#include "dns.h" -#include "reg.h" -#include "php_mail.h" -#include "md5.h" -#include "sha1.h" -#include "html.h" -#include "exec.h" -#include "file.h" -#include "php_ext_syslog.h" -#include "php_filestat.h" -#include "php_browscap.h" -#include "pack.h" -#include "datetime.h" -#include "microtime.h" -#include "url.h" -#include "pageinfo.h" -#include "cyr_convert.h" -#include "php_link.h" -#include "fsock.h" -#include "php_image.h" -#include "php_iptc.h" -#include "info.h" -#include "uniqid.h" -#include "php_var.h" -#include "quot_print.h" -#include "dl.h" -#include "php_crypt.h" -#include "head.h" -#include "php_lcg.h" -#include "php_metaphone.h" -#include "php_output.h" -#include "php_array.h" -#include "php_assert.h" -#include "php_versioning.h" -#include "php_ftok.h" -#include "php_type.h" -#include "aggregation.h" -#include "php_sunfuncs.h" - -#define phpext_standard_ptr basic_functions_module_ptr -PHP_MINIT_FUNCTION(standard_filters); -PHP_MSHUTDOWN_FUNCTION(standard_filters); - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h deleted file mode 100644 index 8b032847aa..0000000000 --- a/ext/standard/php_string.h +++ /dev/null @@ -1,172 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ - -#ifndef PHP_STRING_H -#define PHP_STRING_H - -PHP_FUNCTION(strspn); -PHP_FUNCTION(strcspn); -PHP_FUNCTION(str_replace); -PHP_FUNCTION(str_ireplace); -PHP_FUNCTION(rtrim); -PHP_FUNCTION(trim); -PHP_FUNCTION(ltrim); -PHP_FUNCTION(soundex); -PHP_FUNCTION(levenshtein); - -PHP_FUNCTION(count_chars); -PHP_FUNCTION(wordwrap); -PHP_FUNCTION(explode); -PHP_FUNCTION(implode); -PHP_FUNCTION(strtok); -PHP_FUNCTION(strtoupper); -PHP_FUNCTION(strtolower); -PHP_FUNCTION(basename); -PHP_FUNCTION(dirname); -PHP_FUNCTION(pathinfo); -PHP_FUNCTION(strstr); -PHP_FUNCTION(strpos); -PHP_FUNCTION(stripos); -PHP_FUNCTION(strrpos); -PHP_FUNCTION(strripos); -PHP_FUNCTION(strrchr); -PHP_FUNCTION(substr); -PHP_FUNCTION(quotemeta); -PHP_FUNCTION(ucfirst); -PHP_FUNCTION(ucwords); -PHP_FUNCTION(strtr); -PHP_FUNCTION(strrev); -PHP_FUNCTION(hebrev); -PHP_FUNCTION(hebrevc); -PHP_FUNCTION(user_sprintf); -PHP_FUNCTION(user_printf); -PHP_FUNCTION(vprintf); -PHP_FUNCTION(vsprintf); -PHP_FUNCTION(addcslashes); -PHP_FUNCTION(addslashes); -PHP_FUNCTION(stripcslashes); -PHP_FUNCTION(stripslashes); -PHP_FUNCTION(chr); -PHP_FUNCTION(ord); -PHP_FUNCTION(nl2br); -PHP_FUNCTION(setlocale); -PHP_FUNCTION(localeconv); -PHP_FUNCTION(nl_langinfo); -PHP_FUNCTION(stristr); -PHP_FUNCTION(chunk_split); -PHP_FUNCTION(parse_str); -PHP_FUNCTION(bin2hex); -PHP_FUNCTION(similar_text); -PHP_FUNCTION(strip_tags); -PHP_FUNCTION(str_repeat); -PHP_FUNCTION(substr_replace); -PHP_FUNCTION(strnatcmp); -PHP_FUNCTION(strnatcasecmp); -PHP_FUNCTION(substr_count); -PHP_FUNCTION(str_pad); -PHP_FUNCTION(sscanf); -PHP_FUNCTION(str_shuffle); -PHP_FUNCTION(str_word_count); -PHP_FUNCTION(str_split); -PHP_FUNCTION(strpbrk); -#ifdef HAVE_STRCOLL -PHP_FUNCTION(strcoll); -#endif -#if HAVE_STRFMON -PHP_FUNCTION(money_format); -#endif - -#if defined(HAVE_LOCALECONV) && defined(ZTS) -PHP_MINIT_FUNCTION(localeconv); -PHP_MSHUTDOWN_FUNCTION(localeconv); -#endif -#if HAVE_NL_LANGINFO -PHP_MINIT_FUNCTION(nl_langinfo); -#endif - -#define strnatcmp(a, b) \ - strnatcmp_ex(a, strlen(a), b, strlen(b), 0) -#define strnatcasecmp(a, b) \ - strnatcmp_ex(a, strlen(a), b, strlen(b), 1) -PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case); - -#ifdef HAVE_LOCALECONV -struct lconv *localeconv_r(struct lconv *out); -#endif - -PHPAPI char *php_strtoupper(char *s, size_t len); -PHPAPI char *php_strtolower(char *s, size_t len); -PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen); -PHPAPI char *php_addslashes(char *str, int length, int *new_length, int freeit TSRMLS_DC); -PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int freeit, char *what, int wlength TSRMLS_DC); -PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC); -PHPAPI void php_stripcslashes(char *str, int *len); -PHPAPI char *php_basename(char *str, size_t len , char *suffix, size_t sufflen); -PHPAPI void php_dirname(char *str, int len); -PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t t_len); -PHPAPI char *php_str_to_str_ex(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len, int *_new_length, int case_sensitivity); -PHPAPI char *php_str_to_str(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len, int *_new_length); -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC); -PHPAPI size_t php_strip_tags(char *rbuf, int len, int *state, char *allow, int allow_len); -PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result); -PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value); -PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit); - -static inline char * -php_memnstr(char *haystack, char *needle, int needle_len, char *end) -{ - char *p = haystack; - char ne = needle[needle_len-1]; - - end -= needle_len; - - while (p <= end) { - if ((p = memchr(p, *needle, (end-p+1))) && ne == p[needle_len-1]) { - if (!memcmp(needle, p, needle_len-1)) { - return p; - } - } - - if (p == NULL) { - return NULL; - } - - p++; - } - - return NULL; -} - -PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end); -PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end); - -#ifndef HAVE_STRERROR -PHPAPI char *php_strerror(int errnum); -#define strerror php_strerror -#endif - -void register_string_constants(INIT_FUNC_ARGS); - -#endif /* PHP_STRING_H */ diff --git a/ext/standard/php_sunfuncs.h b/ext/standard/php_sunfuncs.h deleted file mode 100644 index bb79c58094..0000000000 --- a/ext/standard/php_sunfuncs.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Moshe Doron <mosdoron@netvision.net.il> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_SUNFUNCS_H -#define PHP_SUNFUNCS_H - -/* default ini entries: */ -/* Jerusalem one. */ -#define DATE_DEFAULT_LATITUDE "31.7667" -#define DATE_DEFAULT_LONGITUDE "35.2333" - -/* on 90'50; common jewish sunset declaration (start of sun body appear) */ -#define DATE_SUNSET_ZENITH "90.83" - -/* on 90'50; common jewish sunrise declaration (sun body disappeared) */ -#define DATE_SUNRISE_ZENITH "90.83" - -#define SUNFUNCS_RET_TIMESTAMP 0 -#define SUNFUNCS_RET_STRING 1 -#define SUNFUNCS_RET_DOUBLE 2 - -PHP_FUNCTION(date_sunrise); -PHP_FUNCTION(date_sunset); - -#endif /* PHP_SUNFUNCS_H */ diff --git a/ext/standard/php_type.h b/ext/standard/php_type.h deleted file mode 100644 index e6f46fb3bb..0000000000 --- a/ext/standard/php_type.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_TYPE_H -#define PHP_TYPE_H - -PHP_FUNCTION(intval); -PHP_FUNCTION(floatval); -PHP_FUNCTION(strval); -PHP_FUNCTION(gettype); -PHP_FUNCTION(settype); -PHP_FUNCTION(is_null); -PHP_FUNCTION(is_resource); -PHP_FUNCTION(is_bool); -PHP_FUNCTION(is_long); -PHP_FUNCTION(is_float); -PHP_FUNCTION(is_numeric); -PHP_FUNCTION(is_string); -PHP_FUNCTION(is_array); -PHP_FUNCTION(is_object); -PHP_FUNCTION(is_scalar); -PHP_FUNCTION(is_callable); - -#endif diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h deleted file mode 100644 index 3ae0bb200f..0000000000 --- a/ext/standard/php_var.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jani Lehtimäki <jkl@njet.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_VAR_H -#define PHP_VAR_H - -#include "ext/standard/php_smart_str_public.h" - -PHP_FUNCTION(var_dump); -PHP_FUNCTION(var_export); -PHP_FUNCTION(debug_zval_dump); -PHP_FUNCTION(serialize); -PHP_FUNCTION(unserialize); -#if MEMORY_LIMIT -PHP_FUNCTION(memory_get_usage); -#endif - -void php_var_dump(zval **struc, int level TSRMLS_DC); -void php_var_export(zval **struc, int level TSRMLS_DC); -void php_debug_zval_dump(zval **struc, int level TSRMLS_DC); - -/* typdef HashTable php_serialize_data_t; */ -#define php_serialize_data_t HashTable - -struct php_unserialize_data { - void *first; -}; - -typedef struct php_unserialize_data php_unserialize_data_t; - -PHPAPI void php_var_serialize(smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC); -PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, php_unserialize_data_t *var_hash TSRMLS_DC); - -#define PHP_VAR_SERIALIZE_INIT(var_hash) \ - zend_hash_init(&(var_hash), 10, NULL, NULL, 0) -#define PHP_VAR_SERIALIZE_DESTROY(var_hash) \ - zend_hash_destroy(&(var_hash)) - -#define PHP_VAR_UNSERIALIZE_INIT(var_hash) \ - (var_hash).first = 0 -#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \ - var_destroy(&(var_hash)) - -PHPAPI void var_replace(php_unserialize_data_t *var_hash, zval *ozval, zval **nzval); -PHPAPI void var_destroy(php_unserialize_data_t *var_hash); - -#define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \ - var_replace((var_hash), (ozval), &(nzval)) - -PHPAPI zend_class_entry *php_create_empty_class(char *class_name, int len); - -#endif /* PHP_VAR_H */ diff --git a/ext/standard/php_versioning.h b/ext/standard/php_versioning.h deleted file mode 100644 index 2dfa543073..0000000000 --- a/ext/standard/php_versioning.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef PHP_VERSIONING_H -#define PHP_VERSIONING_H - -#include "ext/standard/basic_functions.h" - -PHPAPI char *php_canonicalize_version(const char *); -PHPAPI int php_version_compare(const char *, const char *); -PHP_FUNCTION(version_compare); - -#endif diff --git a/ext/standard/proc_open.c b/ext/standard/proc_open.c deleted file mode 100644 index 58f1c29ade..0000000000 --- a/ext/standard/proc_open.c +++ /dev/null @@ -1,819 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include <ctype.h> -#include "php_string.h" -#include "safe_mode.h" -#include "ext/standard/head.h" -#include "ext/standard/file.h" -#include "exec.h" -#include "php_globals.h" -#include "SAPI.h" - -#if HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif -#if HAVE_SIGNAL_H -#include <signal.h> -#endif - -#if HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#if HAVE_SYS_STAT_H -#include <sys/stat.h> -#endif -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif - -/* This symbol is defined in ext/standard/config.m4. - * Essentially, it is set if you HAVE_FORK || PHP_WIN32 - * Otherplatforms may modify that configure check and add suitable #ifdefs - * around the alternate code. - * */ -#ifdef PHP_CAN_SUPPORT_PROC_OPEN - -#include "proc_open.h" - -static int le_proc_open; - -/* {{{ _php_array_to_envp */ -static php_process_env_t _php_array_to_envp(zval *environment, int is_persistent TSRMLS_DC) -{ - zval **element; - php_process_env_t env; - char *string_key, *data; -#ifndef PHP_WIN32 - char **ep; -#endif - char *p; - uint string_length, cnt, l, sizeenv=0, el_len; - ulong num_key; - HashTable *target_hash; - HashPosition pos; - - memset(&env, 0, sizeof(env)); - - if (!environment) { - return env; - } - - cnt = zend_hash_num_elements(Z_ARRVAL_P(environment)); - - if (cnt < 1) { - return env; - } - - target_hash = HASH_OF(environment); - if (!target_hash) { - return env; - } - - /* first, we have to get the size of all the elements in the hash */ - for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); - zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; - zend_hash_move_forward_ex(target_hash, &pos)) { - - convert_to_string_ex(element); - el_len = Z_STRLEN_PP(element); - if (el_len == 0) { - continue; - } - - sizeenv += el_len+1; - - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - if (string_length == 0) { - continue; - } - sizeenv += string_length+1; - break; - } - } - -#ifndef PHP_WIN32 - ep = env.envarray = (char **) pecalloc(cnt + 1, sizeof(char *), is_persistent); -#endif - p = env.envp = (char *) pecalloc(sizeenv + 4, 1, is_persistent); - - for (zend_hash_internal_pointer_reset_ex(target_hash, &pos); - zend_hash_get_current_data_ex(target_hash, (void **) &element, &pos) == SUCCESS; - zend_hash_move_forward_ex(target_hash, &pos)) { - - convert_to_string_ex(element); - el_len = Z_STRLEN_PP(element); - - if (el_len == 0) { - continue; - } - - data = Z_STRVAL_PP(element); - switch (zend_hash_get_current_key_ex(target_hash, &string_key, &string_length, &num_key, 0, &pos)) { - case HASH_KEY_IS_STRING: - if (string_length == 0) { - continue; - } - l = string_length + el_len + 1; - memcpy(p, string_key, string_length); - strcat(p, "="); - strcat(p, data); - - if (PG(magic_quotes_gpc)) { - php_stripslashes(p, &l TSRMLS_CC); - } -#ifndef PHP_WIN32 - *ep = p; - ++ep; -#endif - p += l; - break; - case HASH_KEY_IS_LONG: - memcpy(p,data,el_len); - if (PG(magic_quotes_gpc)) { - php_stripslashes(p, &el_len TSRMLS_CC); - } -#ifndef PHP_WIN32 - *ep = p; - ++ep; -#endif - p += el_len + 1; - break; - case HASH_KEY_NON_EXISTANT: - break; - } - } - - assert(p - env.envp <= sizeenv); - - zend_hash_internal_pointer_reset_ex(target_hash, &pos); - - return env; -} -/* }}} */ - -/* {{{ _php_free_envp */ -static void _php_free_envp(php_process_env_t env, int is_persistent) -{ -#ifndef PHP_WIN32 - if (env.envarray) { - pefree(env.envarray, is_persistent); - } -#endif - if (env.envp) { - pefree(env.envp, is_persistent); - } -} -/* }}} */ - - -static void proc_open_rsrc_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) -{ - struct php_process_handle *proc = (struct php_process_handle*)rsrc->ptr; - int i; -#ifdef PHP_WIN32 - DWORD wstatus; -#elif HAVE_SYS_WAIT_H - int wstatus; - pid_t wait_pid; -#endif - - /* Close all handles to avoid a deadlock */ - for (i = 0; i < proc->npipes; i++) { - if (proc->pipes[i] != 0) { - zend_list_delete(proc->pipes[i]); - proc->pipes[i] = 0; - } - } - -#ifdef PHP_WIN32 - - WaitForSingleObject(proc->child, INFINITE); - GetExitCodeProcess(proc->child, &wstatus); - FG(pclose_ret) = wstatus; - -#elif HAVE_SYS_WAIT_H - - do { - wait_pid = waitpid(proc->child, &wstatus, 0); - } while (wait_pid == -1 && errno == EINTR); - - if (wait_pid == -1) - FG(pclose_ret) = -1; - else { - if (WIFEXITED(wstatus)) - wstatus = WEXITSTATUS(wstatus); - FG(pclose_ret) = wstatus; - } - -#else - FG(pclose_ret) = -1; -#endif - _php_free_envp(proc->env, proc->is_persistent); - pefree(proc->command, proc->is_persistent); - pefree(proc, proc->is_persistent); - -} - -/* {{{ php_make_safe_mode_command */ -static int php_make_safe_mode_command(char *cmd, char **safecmd, int is_persistent TSRMLS_DC) -{ - int lcmd, larg0, ldir, len, overflow_limit; - char *space, *sep, *arg0; - - if (!PG(safe_mode)) { - *safecmd = pestrdup(cmd, is_persistent); - return SUCCESS; - } - - lcmd = strlen(cmd); - ldir = strlen(PG(safe_mode_exec_dir)); - len = lcmd + ldir + 2; - overflow_limit = len; - - arg0 = emalloc(len); - - strcpy(arg0, cmd); - - space = strchr(arg0, ' '); - if (space) { - *space = '\0'; - } - larg0 = strlen(arg0); - - if (strstr(arg0, "..")) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "No '..' components allowed in path"); - efree(arg0); - return FAILURE; - } - - *safecmd = emalloc(len); - strcpy(*safecmd, PG(safe_mode_exec_dir)); - overflow_limit -= ldir; - - sep = strrchr(arg0, PHP_DIR_SEPARATOR); - if (sep) { - strcat(*safecmd, sep); - overflow_limit -= strlen(sep); - } else { - strcat(*safecmd, "/"); - strcat(*safecmd, arg0); - overflow_limit -= larg0 + 1; - } - if (space) { - strncat(*safecmd, cmd + larg0, overflow_limit); - } - efree(arg0); - arg0 = php_escape_shell_cmd(*safecmd); - efree(*safecmd); - if (is_persistent) { - *safecmd = pestrdup(arg0, 1); - efree(arg0); - } else { - *safecmd = arg0; - } - - return SUCCESS; -} -/* }}} */ - -PHP_MINIT_FUNCTION(proc_open) -{ - le_proc_open = zend_register_list_destructors_ex(proc_open_rsrc_dtor, NULL, "process", module_number); - return SUCCESS; -} - - -/* {{{ proto int proc_terminate(resource process [, long signal]) - kill a process opened by proc_open */ -PHP_FUNCTION(proc_terminate) -{ - zval *zproc; - struct php_process_handle *proc; - long sig_no = SIGTERM; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zproc, &sig_no) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open); - -#ifdef PHP_WIN32 - TerminateProcess(proc->child, 255); -#else - kill(proc->child, sig_no); -#endif - - zend_list_delete(Z_LVAL_P(zproc)); - RETURN_LONG(FG(pclose_ret)); -} -/* }}} */ - - -/* {{{ proto int proc_close(resource process) - close a process opened by proc_open */ -PHP_FUNCTION(proc_close) -{ - zval *zproc; - struct php_process_handle *proc; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open); - - zend_list_delete(Z_LVAL_P(zproc)); - RETURN_LONG(FG(pclose_ret)); -} -/* }}} */ - -/* {{{ proto array proc_get_status(resource process) - get information about a process opened by proc_open */ -PHP_FUNCTION(proc_get_status) -{ - zval *zproc; - struct php_process_handle *proc; -#ifdef PHP_WIN32 - DWORD wstatus; -#elif HAVE_SYS_WAIT_H - int wstatus; - pid_t wait_pid; -#endif - int running = 1, signaled = 0, stopped = 0; - int exitcode = -1, termsig = 0, stopsig = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zproc) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(proc, struct php_process_handle *, &zproc, -1, "process", le_proc_open); - - array_init(return_value); - - add_assoc_string(return_value, "command", proc->command, 1); - add_assoc_long(return_value, "pid", (long) proc->child); - -#ifdef PHP_WIN32 - - GetExitCodeProcess(proc->child, &wstatus); - - running = wstatus == STILL_ACTIVE; - exitcode == STILL_ACTIVE ? -1 : wstatus; - -#elif HAVE_SYS_WAIT_H - - errno = 0; - wait_pid = waitpid(proc->child, &wstatus, WNOHANG|WUNTRACED); - - if (wait_pid == proc->child) { - if (WIFEXITED(wstatus)) { - running = 0; - exitcode = WEXITSTATUS(wstatus); - } - if (WIFSIGNALED(wstatus)) { - signaled = 1; - termsig = WTERMSIG(wstatus); - } - if (WIFSTOPPED(wstatus)) { - stopped = 1; - stopsig = WSTOPSIG(wstatus); - } - } -#endif - - add_assoc_bool(return_value, "running", running); - add_assoc_bool(return_value, "signaled", signaled); - add_assoc_bool(return_value, "stopped", stopped); - add_assoc_long(return_value, "exitcode", exitcode); - add_assoc_long(return_value, "termsig", termsig); - add_assoc_long(return_value, "stopsig", stopsig); -} -/* }}} */ - -/* {{{ handy definitions for portability/readability */ -#ifdef PHP_WIN32 -# define pipe(pair) (CreatePipe(&pair[0], &pair[1], &security, 2048L) ? 0 : -1) - -# define COMSPEC_NT "cmd.exe" -# define COMSPEC_9X "command.com" - -static inline HANDLE dup_handle(HANDLE src, BOOL inherit, BOOL closeorig) -{ - HANDLE copy, self = GetCurrentProcess(); - - if (!DuplicateHandle(self, src, self, ©, 0, inherit, DUPLICATE_SAME_ACCESS | - (closeorig ? DUPLICATE_CLOSE_SOURCE : 0))) - return NULL; - return copy; -} - -static inline HANDLE dup_fd_as_handle(int fd) -{ - return dup_handle((HANDLE)_get_osfhandle(fd), TRUE, FALSE); -} - -# define close_descriptor(fd) CloseHandle(fd) -#else -# define close_descriptor(fd) close(fd) -#endif - -#define DESC_PIPE 1 -#define DESC_FILE 2 -#define DESC_PARENT_MODE_WRITE 8 - -struct php_proc_open_descriptor_item { - int index; /* desired fd number in child process */ - php_file_descriptor_t parentend, childend; /* fds for pipes in parent/child */ - int mode; /* mode for proc_open code */ - int mode_flags; /* mode flags for opening fds */ -}; -/* }}} */ - -/* {{{ proto resource proc_open(string command, array descriptorspec, array &pipes [, string cwd [, array env]]) - Run a process with more control over it's file descriptors */ -PHP_FUNCTION(proc_open) -{ - - char *command, *cwd=NULL; - long command_len, cwd_len; - zval *descriptorspec; - zval *pipes; - zval *environment = NULL; - php_process_env_t env; - int ndesc = 0; - int i; - zval **descitem = NULL; - HashPosition pos; - struct php_proc_open_descriptor_item descriptors[PHP_PROC_OPEN_MAX_DESCRIPTORS]; -#ifdef PHP_WIN32 - PROCESS_INFORMATION pi; - STARTUPINFO si; - BOOL newprocok; - SECURITY_ATTRIBUTES security; - char *command_with_cmd; -#endif - php_process_id_t child; - struct php_process_handle *proc; - int is_persistent = 0; /* TODO: ensure that persistent procs will work */ - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz/|s!a!", &command, - &command_len, &descriptorspec, &pipes, &cwd, &cwd_len, &environment) == FAILURE) { - RETURN_FALSE; - } - - if (FAILURE == php_make_safe_mode_command(command, &command, is_persistent TSRMLS_CC)) { - RETURN_FALSE; - } - - command_len = strlen(command); - - if (environment) { - env = _php_array_to_envp(environment, is_persistent TSRMLS_CC); - } else { - memset(&env, 0, sizeof(env)); - } - - memset(descriptors, 0, sizeof(descriptors)); - -#ifdef PHP_WIN32 - /* we use this to allow the child to inherit handles */ - memset(&security, 0, sizeof(security)); - security.nLength = sizeof(security); - security.bInheritHandle = TRUE; - security.lpSecurityDescriptor = NULL; -#endif - - /* walk the descriptor spec and set up files/pipes */ - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(descriptorspec), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(descriptorspec), (void **)&descitem, &pos) == SUCCESS) { - char *str_index; - ulong nindex; - zval **ztype; - - str_index = NULL; - zend_hash_get_current_key_ex(Z_ARRVAL_P(descriptorspec), &str_index, NULL, &nindex, 0, &pos); - - if (str_index) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "descriptor spec must be an integer indexed array"); - goto exit_fail; - } - - descriptors[ndesc].index = nindex; - - if (Z_TYPE_PP(descitem) == IS_RESOURCE) { - /* should be a stream - try and dup the descriptor */ - php_stream *stream; - int fd; - - php_stream_from_zval(stream, descitem); - - if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **)&fd, REPORT_ERRORS)) { - goto exit_fail; - } - -#ifdef PHP_WIN32 - descriptors[ndesc].childend = dup_fd_as_handle(fd); - if (descriptors[ndesc].childend == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to dup File-Handle for descriptor %d", nindex); - goto exit_fail; - } -#else - descriptors[ndesc].childend = dup(fd); - if (descriptors[ndesc].childend < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to dup File-Handle for descriptor %d - %s", nindex, strerror(errno)); - goto exit_fail; - } -#endif - descriptors[ndesc].mode = DESC_FILE; - - } else if (Z_TYPE_PP(descitem) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Descriptor item must be either an array or a File-Handle"); - goto exit_fail; - } else { - - if (zend_hash_index_find(Z_ARRVAL_PP(descitem), 0, (void **)&ztype) == SUCCESS) { - convert_to_string_ex(ztype); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing handle qualifier in array"); - goto exit_fail; - } - - if (strcmp(Z_STRVAL_PP(ztype), "pipe") == 0) { - php_file_descriptor_t newpipe[2]; - zval **zmode; - - if (zend_hash_index_find(Z_ARRVAL_PP(descitem), 1, (void **)&zmode) == SUCCESS) { - convert_to_string_ex(zmode); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing mode parameter for 'pipe'", Z_STRVAL_PP(ztype)); - goto exit_fail; - } - - descriptors[ndesc].mode = DESC_PIPE; - - if (0 != pipe(newpipe)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to create pipe %s", strerror(errno)); - goto exit_fail; - } - - if (strcmp(Z_STRVAL_PP(zmode), "w") != 0) { - descriptors[ndesc].parentend = newpipe[1]; - descriptors[ndesc].childend = newpipe[0]; - descriptors[ndesc].mode |= DESC_PARENT_MODE_WRITE; - } else { - descriptors[ndesc].parentend = newpipe[0]; - descriptors[ndesc].childend = newpipe[1]; - } -#ifdef PHP_WIN32 - /* don't let the child inherit the parent side of the pipe */ - descriptors[ndesc].parentend = dup_handle(descriptors[ndesc].parentend, FALSE, TRUE); -#endif - descriptors[ndesc].mode_flags = descriptors[ndesc].mode & DESC_PARENT_MODE_WRITE ? O_WRONLY : O_RDONLY; -#ifdef PHP_WIN32 - if (Z_STRLEN_PP(zmode) >= 2 && Z_STRVAL_PP(zmode)[1] == 'b') - descriptors[ndesc].mode_flags |= O_BINARY; -#endif - - - - } else if (strcmp(Z_STRVAL_PP(ztype), "file") == 0) { - zval **zfile, **zmode; - int fd; - php_stream *stream; - - descriptors[ndesc].mode = DESC_FILE; - - if (zend_hash_index_find(Z_ARRVAL_PP(descitem), 1, (void **)&zfile) == SUCCESS) { - convert_to_string_ex(zfile); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing file name parameter for 'file'", Z_STRVAL_PP(ztype)); - goto exit_fail; - } - - if (zend_hash_index_find(Z_ARRVAL_PP(descitem), 2, (void **)&zmode) == SUCCESS) { - convert_to_string_ex(zmode); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Missing mode parameter for 'file'", Z_STRVAL_PP(ztype)); - goto exit_fail; - } - - /* try a wrapper */ - stream = php_stream_open_wrapper(Z_STRVAL_PP(zfile), Z_STRVAL_PP(zmode), - ENFORCE_SAFE_MODE|REPORT_ERRORS|STREAM_WILL_CAST, NULL); - - /* force into an fd */ - if (stream == NULL || FAILURE == php_stream_cast(stream, - PHP_STREAM_CAST_RELEASE|PHP_STREAM_AS_FD, - (void **)&fd, REPORT_ERRORS)) { - goto exit_fail; - } - -#ifdef PHP_WIN32 - descriptors[ndesc].childend = (HANDLE)_get_osfhandle(fd); -#else - descriptors[ndesc].childend = fd; -#endif - - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s is not a valid descriptor spec/mode", Z_STRVAL_PP(ztype)); - goto exit_fail; - } - } - - zend_hash_move_forward_ex(Z_ARRVAL_P(descriptorspec), &pos); - if (++ndesc == PHP_PROC_OPEN_MAX_DESCRIPTORS) - break; - } - -#ifdef PHP_WIN32 - memset(&si, 0, sizeof(si)); - si.cb = sizeof(si); - si.dwFlags = STARTF_USESTDHANDLES; - - si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); - si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - si.hStdError = GetStdHandle(STD_ERROR_HANDLE); - - /* redirect stdin/stdout/stderr if requested */ - for (i = 0; i < ndesc; i++) { - switch(descriptors[i].index) { - case 0: - si.hStdInput = descriptors[i].childend; - break; - case 1: - si.hStdOutput = descriptors[i].childend; - break; - case 2: - si.hStdError = descriptors[i].childend; - break; - } - } - - - memset(&pi, 0, sizeof(pi)); - - command_with_cmd = emalloc(command_len + sizeof(COMSPEC_9X) + 1 + sizeof(" /c ")); - sprintf(command_with_cmd, "%s /c %s", GetVersion() < 0x80000000 ? COMSPEC_NT : COMSPEC_9X, command); - newprocok = CreateProcess(NULL, command_with_cmd, &security, &security, TRUE, NORMAL_PRIORITY_CLASS, env.envp, cwd, &si, &pi); - efree(command_with_cmd); - - if (FALSE == newprocok) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "CreateProcess failed"); - goto exit_fail; - } - - child = pi.hProcess; - CloseHandle(pi.hThread); - -#elif HAVE_FORK - /* the unix way */ - child = fork(); - - if (child == 0) { - /* this is the child process */ - - /* close those descriptors that we just opened for the parent stuff, - * dup new descriptors into required descriptors and close the original - * cruft */ - for (i = 0; i < ndesc; i++) { - switch (descriptors[i].mode & ~DESC_PARENT_MODE_WRITE) { - case DESC_PIPE: - close(descriptors[i].parentend); - break; - } - if (dup2(descriptors[i].childend, descriptors[i].index) < 0) - perror("dup2"); - if (descriptors[i].childend != descriptors[i].index) - close(descriptors[i].childend); - } - if (cwd) { - chdir(cwd); - } - - if (env.envarray) { - execle("/bin/sh", "sh", "-c", command, NULL, env.envarray); - } else { - execl("/bin/sh", "sh", "-c", command, NULL); - } - _exit(127); - - } else if (child < 0) { - /* failed to fork() */ - - /* clean up all the descriptors */ - for (i = 0; i < ndesc; i++) { - close(descriptors[i].childend); - close(descriptors[i].parentend); - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "fork failed - %s", strerror(errno)); - - goto exit_fail; - - } -#else -# error You lose (configure should not have let you get here) -#endif - /* we forked/spawned and this is the parent */ - - proc = (struct php_process_handle*)pemalloc(sizeof(struct php_process_handle), is_persistent); - proc->is_persistent = is_persistent; - proc->command = command; - proc->npipes = ndesc; - proc->child = child; - proc->env = env; - - array_init(pipes); - - /* clean up all the child ends and then open streams on the parent - * ends, where appropriate */ - for (i = 0; i < ndesc; i++) { - FILE *fp; - char *mode_string=NULL; - php_stream *stream; - - close_descriptor(descriptors[i].childend); - - switch (descriptors[i].mode & ~DESC_PARENT_MODE_WRITE) { - case DESC_PIPE: - switch(descriptors[i].mode_flags) { -#ifdef PHP_WIN32 - case O_WRONLY|O_BINARY: - mode_string = "wb"; - break; - case O_RDONLY|O_BINARY: - mode_string = "rb"; - break; -#endif - case O_WRONLY: - mode_string = "w"; - break; - case O_RDONLY: - mode_string = "r"; - break; - } -#ifdef PHP_WIN32 - fp = _fdopen(_open_osfhandle((long)descriptors[i].parentend, - descriptors[i].mode_flags), mode_string); -#else - fp = fdopen(descriptors[i].parentend, mode_string); -#endif - if (fp) { - stream = php_stream_fopen_from_file(fp, mode_string); - if (stream) { - zval *retfp; - - MAKE_STD_ZVAL(retfp); - php_stream_to_zval(stream, retfp); - add_index_zval(pipes, descriptors[i].index, retfp); - - proc->pipes[i] = Z_LVAL_P(retfp); - } - } - break; - default: - proc->pipes[i] = 0; - } - } - - ZEND_REGISTER_RESOURCE(return_value, proc, le_proc_open); - return; - -exit_fail: - _php_free_envp(env, is_persistent); - pefree(command, is_persistent); - RETURN_FALSE; - -} -/* }}} */ - -#endif /* PHP_CAN_SUPPORT_PROC_OPEN */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/proc_open.h b/ext/standard/proc_open.h deleted file mode 100644 index 26375054a5..0000000000 --- a/ext/standard/proc_open.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Wez Furlong <wez@thebrainroom.com> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifdef PHP_WIN32 -typedef HANDLE php_file_descriptor_t; -typedef HANDLE php_process_id_t; -#else -typedef int php_file_descriptor_t; -typedef pid_t php_process_id_t; -#endif - -#define PHP_PROC_OPEN_MAX_DESCRIPTORS 16 - -/* Environment block under win32 is a NUL terminated sequence of NUL terminated - * name=value strings. - * Under unix, it is an argv style array. - * */ -typedef struct _php_process_env { - char *envp; -#ifndef PHP_WIN32 - char **envarray; -#endif -} php_process_env_t; - -struct php_process_handle { - php_process_id_t child; - int npipes; - long pipes[PHP_PROC_OPEN_MAX_DESCRIPTORS]; - char *command; - int is_persistent; - php_process_env_t env; -}; - diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c deleted file mode 100644 index 1e3137e397..0000000000 --- a/ext/standard/quot_print.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Kirill Maximov <kir@actimind.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <string.h> -#include <errno.h> - -#include "php.h" -#include "quot_print.h" - -#include <stdio.h> - -/* -* Converting HEX char to INT value -*/ -static char php_hex2int(int c) -{ - if (isdigit(c)) { - return c - '0'; - } - else if (c >= 'A' && c <= 'F') { - return c - 'A' + 10; - } - else if (c >= 'a' && c <= 'f') { - return c - 'a' + 10; - } - else { - return -1; - } -} - -PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length) -{ - register unsigned int i; - register unsigned const char *p1; - register unsigned char *p2; - register unsigned int h_nbl, l_nbl; - - size_t decoded_len, buf_size; - unsigned char *retval; - - static unsigned int hexval_tbl[256] = { - 64, 64, 64, 64, 64, 64, 64, 64, 64, 32, 16, 64, 64, 16, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 32, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 64, 64, 64, 64, 64, 64, - 64, 10, 11, 12, 13, 14, 15, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 - }; - - i = length, p1 = str; buf_size = length; - - while (i > 1 && *p1 != '\0') { - if (*p1 == '=') { - buf_size -= 2; - p1++; - i--; - } - p1++; - i--; - } - - retval = emalloc(buf_size + 1); - i = length; p1 = str; p2 = retval; - decoded_len = 0; - - while (i > 0 && *p1 != '\0') { - if (*p1 == '=') { - i--, p1++; - if (i == 0 || *p1 == '\0') { - break; - } - h_nbl = hexval_tbl[*p1]; - if (h_nbl < 16) { - /* next char should be a hexadecimal digit */ - if ((--i) == 0 || (l_nbl = hexval_tbl[*(++p1)]) >= 16) { - efree(retval); - return NULL; - } - *(p2++) = (h_nbl << 4) | l_nbl, decoded_len++; - i--, p1++; - } else if (h_nbl < 64) { - /* soft line break */ - while (h_nbl == 32) { - if (--i == 0 || (h_nbl = hexval_tbl[*(++p1)]) == 64) { - efree(retval); - return NULL; - } - } - if (p1[0] == '\r' && i >= 2 && p1[1] == '\n') { - i--, p1++; - } - i--, p1++; - } else { - efree(retval); - return NULL; - } - } else { - *(p2++) = *p1; - i--, p1++, decoded_len++; - } - } - - *p2 = '\0'; - *ret_length = decoded_len; - return retval; -} - - -/* -* -* Decoding Quoted-printable string. -* -*/ -/* {{{ proto string quoted_printable_decode(string str) - Convert a quoted-printable string to an 8 bit string */ -PHP_FUNCTION(quoted_printable_decode) -{ - pval **arg1; - char *str_in, *str_out; - int i = 0, j = 0, k; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - - if (Z_STRLEN_PP(arg1) == 0) { - /* shortcut */ - RETURN_EMPTY_STRING(); - } - - str_in = Z_STRVAL_PP(arg1); - str_out = emalloc(Z_STRLEN_PP(arg1) + 1); - while (str_in[i]) { - switch (str_in[i]) { - case '=': - if (str_in[i + 1] && str_in[i + 2] && - isxdigit((int) str_in[i + 1]) && - isxdigit((int) str_in[i + 2])) - { - str_out[j++] = (php_hex2int((int) str_in[i + 1]) << 4) - + php_hex2int((int) str_in[i + 2]); - i += 3; - } else /* check for soft line break according to RFC 2045*/ { - k = 1; - while (str_in[i + k] && ((str_in[i + k] == 32) || (str_in[i + k] == 9))) { - /* Possibly, skip spaces/tabs at the end of line */ - k++; - } - if (!str_in[i + k]) { - /* End of line reached */ - i += k; - } - else if ((str_in[i + k] == 13) && (str_in[i + k + 1] == 10)) { - /* CRLF */ - i += k + 2; - } - else if ((str_in[i + k] == 13) || (str_in[i + k] == 10)) { - /* CR or LF */ - i += k + 1; - } - else { - str_out[j++] = str_in[i++]; - } - } - break; - default: - str_out[j++] = str_in[i++]; - } - } - str_out[j] = '\0'; - - RETVAL_STRINGL(str_out, j, 0); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/quot_print.h b/ext/standard/quot_print.h deleted file mode 100644 index 9ca350c6a2..0000000000 --- a/ext/standard/quot_print.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Kirill Maximov (kir@rus.net) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef QUOT_PRINT_H -#define QUOT_PRINT_H - -PHPAPI unsigned char *php_quot_print_decode(const unsigned char *str, size_t length, size_t *ret_length); - -PHP_FUNCTION(quoted_printable_decode); - -#endif /* QUOT_PRINT_H */ diff --git a/ext/standard/rand.c b/ext/standard/rand.c deleted file mode 100644 index 04f98b34f9..0000000000 --- a/ext/standard/rand.c +++ /dev/null @@ -1,409 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Zeev Suraski <zeev@zend.com> | - | Pedro Melo <melo@ip.pt> | - | Sterling Hughes <sterling@php.net> | - | | - | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdlib.h> - -#if defined(NETWARE) && !defined(NEW_LIBC) /* For getpid() used below */ -#include "netware/pwd.h" -#endif - -#include "php.h" -#include "php_math.h" -#include "php_rand.h" -#include "php_lcg.h" - -#include "basic_functions.h" - - -/* SYSTEM RAND FUNCTIONS */ - -/* {{{ php_srand - */ -PHPAPI void php_srand(long seed TSRMLS_DC) -{ -#ifdef ZTS - BG(rand_seed) = (unsigned int) seed; -#else -# if defined(HAVE_SRANDOM) - srandom((unsigned int) seed); -# elif defined(HAVE_SRAND48) - srand48(seed); -# else - srand((unsigned int) seed); -# endif -#endif -} -/* }}} */ - -/* {{{ php_rand - */ -PHPAPI long php_rand(TSRMLS_D) -{ - long ret; - -#ifdef ZTS - ret = php_rand_r(&BG(rand_seed)); -#else -# if defined(HAVE_RANDOM) - ret = random(); -# elif defined(HAVE_LRAND48) - ret = lrand48(); -# else - ret = rand(); -# endif -#endif - - return ret; -} -/* }}} */ - - -/* MT RAND FUNCTIONS */ - -/* - This is the ``Mersenne Twister'' random number generator MT19937, which - generates pseudorandom integers uniformly distributed in 0..(2^32 - 1) - starting from any odd seed in 0..(2^32 - 1). This version is a recode - by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by - Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in - July-August 1997). - - Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha - running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to - generate 300 million random numbers; after recoding: 24.0 sec. for the same - (i.e., 46.5% of original time), so speed is now about 12.5 million random - number generations per second on this machine. - - According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html> - (and paraphrasing a bit in places), the Mersenne Twister is ``designed - with consideration of the flaws of various existing generators,'' has - a period of 2^19937 - 1, gives a sequence that is 623-dimensionally - equidistributed, and ``has passed many stringent tests, including the - die-hard test of G. Marsaglia and the load test of P. Hellekalek and - S. Wegenkittl.'' It is efficient in memory usage (typically using 2506 - to 5012 bytes of static data, depending on data type sizes, and the code - is quite short as well). It generates random numbers in batches of 624 - at a time, so the caching and pipelining of modern systems is exploited. - It is also divide- and mod-free. - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation (either version 2 of the License or, at your - option, any later version). This library is distributed in the hope that - it will be useful, but WITHOUT ANY WARRANTY, without even the implied - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - the GNU Library General Public License for more details. You should have - received a copy of the GNU Library General Public License along with this - library; if not, write to the Free Software Foundation, Inc., 59 Temple - Place, Suite 330, Boston, MA 02111-1307, USA. - - The code as Shawn received it included the following notice: - - Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When - you use this, send an e-mail to <matumoto@math.keio.ac.jp> with - an appropriate reference to your work. - - It would be nice to CC: <Cokus@math.washington.edu> when you write. - - - - php_uint32 must be an unsigned integer type capable of holding at least 32 - bits; exactly 32 should be fastest, but 64 is better on an Alpha with - GCC at -O3 optimization so try your options and see what's best for you - - Melo: we should put some ifdefs here to catch those alphas... -*/ -#define N MT_N /* length of state vector */ -#define M (397) /* a period parameter */ -#define K (0x9908B0DFU) /* a magic constant */ -#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */ -#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */ -#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */ -#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */ - -/* {{{ php_mt_srand - */ -PHPAPI void php_mt_srand(php_uint32 seed TSRMLS_DC) -{ - /* - We initialize state[0..(N-1)] via the generator - - x_new = (69069 * x_old) mod 2^32 - - from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's - _The Art of Computer Programming_, Volume 2, 3rd ed. - - Notes (SJC): I do not know what the initial state requirements - of the Mersenne Twister are, but it seems this seeding generator - could be better. It achieves the maximum period for its modulus - (2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if - x_initial can be even, you have sequences like 0, 0, 0, ...; - 2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31, - 2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below. - - - Even if x_initial is odd, if x_initial is 1 mod 4 then - - the lowest bit of x is always 1, - the next-to-lowest bit of x is always 0, - the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... , - the 3rd-from-lowest bit of x 4-cycles ... 0 1 1 0 0 1 1 0 ... , - the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... , - ... - - and if x_initial is 3 mod 4 then - - the lowest bit of x is always 1, - the next-to-lowest bit of x is always 1, - the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... , - the 3rd-from-lowest bit of x 4-cycles ... 0 0 1 1 0 0 1 1 ... , - the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... , - ... - - The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is - 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It - also does well in the dimension 2..5 spectral tests, but it could be - better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth). - - Note that the random number user does not see the values generated - here directly since reloadMT() will always munge them first, so maybe - none of all of this matters. In fact, the seed values made here could - even be extra-special desirable if the Mersenne Twister theory says - so-- that's why the only change I made is to restrict to odd seeds. - */ - - register php_uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = BG(state); - register int j; - - for (BG(left) = 0, *s++ = x, j = N; --j; - *s++ = (x *= 69069U) & 0xFFFFFFFFU); -} -/* }}} */ - -/* {{{ php_mt_reload - */ -static php_uint32 php_mt_reload(TSRMLS_D) -{ - register php_uint32 *p0 = BG(state), *p2 = BG(state) + 2, *pM = BG(state) + M, s0, s1; - register int j; - - if (BG(left) < -1) - php_mt_srand(4357U TSRMLS_CC); - - BG(left) = N - 1, BG(next) = BG(state) + 1; - - for (s0 = BG(state)[0], s1 = BG(state)[1], j = N - M + 1; --j; s0 = s1, s1 = *p2++) - *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); - - for (pM = BG(state), j = M; --j; s0 = s1, s1 = *p2++) - *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); - - s1 = BG(state)[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); - s1 ^= (s1 >> 11); - s1 ^= (s1 << 7) & 0x9D2C5680U; - s1 ^= (s1 << 15) & 0xEFC60000U; - - return s1 ^ (s1 >> 18); -} -/* }}} */ - -/* {{{ php_mt_rand - */ -PHPAPI php_uint32 php_mt_rand(TSRMLS_D) -{ - php_uint32 y; - - if (--BG(left) < 0) - return php_mt_reload(TSRMLS_C); - - y = *BG(next)++; - y ^= (y >> 11); - y ^= (y << 7) & 0x9D2C5680U; - y ^= (y << 15) & 0xEFC60000U; - - return y ^ (y >> 18); -} -/* }}} */ - -#ifdef PHP_WIN32 -#define GENERATE_SEED() ((long) (time(0) * GetCurrentProcessId() * 1000000 * php_combined_lcg(TSRMLS_C))) -#else -#define GENERATE_SEED() ((long) (time(0) * getpid() * 1000000 * php_combined_lcg(TSRMLS_C))) -#endif - -/* {{{ proto void srand([int seed]) - Seeds random number generator */ -PHP_FUNCTION(srand) -{ - long seed; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) - return; - - if (ZEND_NUM_ARGS() == 0) - seed = GENERATE_SEED(); - - php_srand(seed TSRMLS_CC); - BG(rand_is_seeded) = 1; -} -/* }}} */ - -/* {{{ proto void mt_srand([int seed]) - Seeds Mersenne Twister random number generator */ -PHP_FUNCTION(mt_srand) -{ - long seed; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &seed) == FAILURE) - return; - - if (ZEND_NUM_ARGS() == 0) - seed = GENERATE_SEED(); - - php_mt_srand(seed TSRMLS_CC); - BG(mt_rand_is_seeded) = 1; -} -/* }}} */ - - -/* - * A bit of tricky math here. We want to avoid using a modulus because - * that simply tosses the high-order bits and might skew the distribution - * of random values over the range. Instead we map the range directly. - * - * We need to map the range from 0...M evenly to the range a...b - * Let n = the random number and n' = the mapped random number - * - * Then we have: n' = a + n(b-a)/M - * - * We have a problem here in that only n==M will get mapped to b which - # means the chances of getting b is much much less than getting any of - # the other values in the range. We can fix this by increasing our range - # artifically and using: - # - # n' = a + n(b-a+1)/M - * - # Now we only have a problem if n==M which would cause us to produce a - # number of b+1 which would be bad. So we bump M up by one to make sure - # this will never happen, and the final algorithm looks like this: - # - # n' = a + n(b-a+1)/(M+1) - * - * -RL - */ - -/* {{{ proto int rand([int min, int max]) - Returns a random number */ -PHP_FUNCTION(rand) -{ - long min; - long max; - long number; - int argc = ZEND_NUM_ARGS(); - - if (argc != 0 && zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) - return; - - if (!BG(rand_is_seeded)) { - php_srand(GENERATE_SEED() TSRMLS_CC); - } - - number = php_rand(TSRMLS_C); - if (argc == 2) { - RAND_RANGE(number, min, max, PHP_RAND_MAX); - } - - RETURN_LONG(number); -} -/* }}} */ - -/* {{{ proto int mt_rand([int min, int max]) - Returns a random number from Mersenne Twister */ -PHP_FUNCTION(mt_rand) -{ - long min; - long max; - long number; - int argc = ZEND_NUM_ARGS(); - - if (argc != 0 && zend_parse_parameters(argc TSRMLS_CC, "ll", &min, &max) == FAILURE) - return; - - if (!BG(mt_rand_is_seeded)) { - php_mt_srand(GENERATE_SEED() TSRMLS_CC); - } - - /* - * Melo: hmms.. randomMT() returns 32 random bits... - * Yet, the previous php_rand only returns 31 at most. - * So I put a right shift to loose the lsb. It *seems* - * better than clearing the msb. - * Update: - * I talked with Cokus via email and it won't ruin the algorithm - */ - number = (long) (php_mt_rand(TSRMLS_C) >> 1); - if (argc == 2) { - RAND_RANGE(number, min, max, PHP_MT_RAND_MAX); - } - - RETURN_LONG(number); -} -/* }}} */ - -/* {{{ proto int getrandmax(void) - Returns the maximum value a random number can have */ -PHP_FUNCTION(getrandmax) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - RETURN_LONG(PHP_RAND_MAX); -} -/* }}} */ - -/* {{{ proto int mt_getrandmax(void) - Returns the maximum value a random number from Mersenne Twister can have */ -PHP_FUNCTION(mt_getrandmax) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - /* - * Melo: it could be 2^^32 but we only use 2^^31 to maintain - * compatibility with the previous php_rand - */ - RETURN_LONG(PHP_MT_RAND_MAX); /* 2^^31 */ -} -/* }}} */ - -/* - * 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/ext/standard/reg.c b/ext/standard/reg.c deleted file mode 100644 index e76dee7c0d..0000000000 --- a/ext/standard/reg.c +++ /dev/null @@ -1,637 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Jim Winstead <jimw@php.net> | - | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include <ctype.h> -#include "php.h" -#include "php_string.h" -#include "reg.h" -#include "ext/standard/info.h" - -ZEND_DECLARE_MODULE_GLOBALS(reg) - -typedef struct { - regex_t preg; - int cflags; -} reg_cache; - -/* {{{ _php_regcomp - */ -static int _php_regcomp(regex_t *preg, const char *pattern, int cflags) -{ - int r = 0; - int patlen = strlen(pattern); - reg_cache *rc = NULL; - TSRMLS_FETCH(); - - if(zend_hash_find(®(ht_rc), (char *) pattern, patlen+1, (void **) &rc) == FAILURE || - rc->cflags != cflags) { - r = regcomp(preg, pattern, cflags); - if(!r) { - reg_cache rcp; - - rcp.cflags = cflags; - memcpy(&rcp.preg, preg, sizeof(*preg)); - zend_hash_update(®(ht_rc), (char *) pattern, patlen+1, - (void *) &rcp, sizeof(rcp), NULL); - } - } else { - memcpy(preg, &rc->preg, sizeof(*preg)); - } - - return r; -} -/* }}} */ - -static void _free_reg_cache(reg_cache *rc) -{ - regfree(&rc->preg); -} - -#undef regfree -#define regfree(a); -#undef regcomp -#define regcomp(a, b, c) _php_regcomp(a, b, c) - -static void php_reg_init_globals(zend_reg_globals *reg_globals TSRMLS_DC) -{ - zend_hash_init(®_globals->ht_rc, 0, NULL, (void (*)(void *)) _free_reg_cache, 1); -} - -static void php_reg_destroy_globals(zend_reg_globals *reg_globals TSRMLS_DC) -{ - zend_hash_destroy(®_globals->ht_rc); -} - -PHP_MINIT_FUNCTION(regex) -{ - ZEND_INIT_MODULE_GLOBALS(reg, php_reg_init_globals, php_reg_destroy_globals); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(regex) -{ -#ifndef ZTS - php_reg_destroy_globals(®_globals TSRMLS_CC); -#endif - - return SUCCESS; -} - -PHP_MINFO_FUNCTION(regex) -{ -#if HSREGEX - php_info_print_table_row(2, "Regex Library", "Bundled library enabled"); -#else - php_info_print_table_row(2, "Regex Library", "System library enabled"); -#endif -} - - -/* {{{ php_reg_eprint - * php_reg_eprint - convert error number to name - */ -static void php_reg_eprint(int err, regex_t *re) { - char *buf = NULL, *message = NULL; - size_t len; - size_t buf_len; - -#ifdef REG_ITOA - /* get the length of the message */ - buf_len = regerror(REG_ITOA | err, re, NULL, 0); - if (buf_len) { - buf = (char *)emalloc(buf_len * sizeof(char)); - if (!buf) return; /* fail silently */ - /* finally, get the error message */ - regerror(REG_ITOA | err, re, buf, buf_len); - } -#else - buf_len = 0; -#endif - len = regerror(err, re, NULL, 0); - if (len) { - TSRMLS_FETCH(); - - message = (char *)emalloc((buf_len + len + 2) * sizeof(char)); - if (!message) { - return; /* fail silently */ - } - if (buf_len) { - snprintf(message, buf_len, "%s: ", buf); - buf_len += 1; /* so pointer math below works */ - } - /* drop the message into place */ - regerror(err, re, message + buf_len, len); - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message); - } - - STR_FREE(buf); - STR_FREE(message); -} -/* }}} */ - -/* {{{ php_ereg - */ -static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase) -{ - pval **regex, /* Regular expression */ - **findin, /* String to apply expression to */ - **array = NULL; /* Optional register array */ - regex_t re; - regmatch_t *subs; - int err, match_len, string_len; - uint i; - int copts = 0; - off_t start, end; - char *buf = NULL; - char *string = NULL; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, ®ex, &findin, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (icase) - copts |= REG_ICASE; - - if (argc == 2) - copts |= REG_NOSUB; - - /* compile the regular expression from the supplied regex */ - if (Z_TYPE_PP(regex) == IS_STRING) { - err = regcomp(&re, Z_STRVAL_PP(regex), REG_EXTENDED | copts); - } else { - /* we convert numbers to integers and treat them as a string */ - if (Z_TYPE_PP(regex) == IS_DOUBLE) - convert_to_long_ex(regex); /* get rid of decimal places */ - convert_to_string_ex(regex); - /* don't bother doing an extended regex with just a number */ - err = regcomp(&re, Z_STRVAL_PP(regex), copts); - } - - if (err) { - php_reg_eprint(err, &re); - RETURN_FALSE; - } - - /* make a copy of the string we're looking in */ - convert_to_string_ex(findin); - string = estrndup(Z_STRVAL_PP(findin), Z_STRLEN_PP(findin)); - - /* allocate storage for (sub-)expression-matches */ - subs = (regmatch_t *)ecalloc(sizeof(regmatch_t),re.re_nsub+1); - - /* actually execute the regular expression */ - err = regexec(&re, string, re.re_nsub+1, subs, 0); - if (err && err != REG_NOMATCH) { - php_reg_eprint(err, &re); - regfree(&re); - efree(subs); - RETURN_FALSE; - } - match_len = 1; - - if (array && err != REG_NOMATCH) { - match_len = (int) (subs[0].rm_eo - subs[0].rm_so); - string_len = Z_STRLEN_PP(findin) + 1; - - buf = emalloc(string_len); - - zval_dtor(*array); /* start with clean array */ - array_init(*array); - - for (i = 0; i <= re.re_nsub; i++) { - start = subs[i].rm_so; - end = subs[i].rm_eo; - if (start != -1 && end > 0 && start < string_len && end < string_len && start < end) { - add_index_stringl(*array, i, string+start, end-start, 1); - } else { - add_index_bool(*array, i, 0); - } - } - efree(buf); - } - - efree(subs); - efree(string); - if (err == REG_NOMATCH) { - RETVAL_FALSE; - } else { - if (match_len == 0) - match_len = 1; - RETVAL_LONG(match_len); - } - regfree(&re); -} -/* }}} */ - -/* {{{ proto int ereg(string pattern, string string [, array registers]) - Regular expression match */ -PHP_FUNCTION(ereg) -{ - php_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int eregi(string pattern, string string [, array registers]) - Case-insensitive regular expression match */ -PHP_FUNCTION(eregi) -{ - php_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_reg_replace - * this is the meat and potatoes of regex replacement! */ -PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended) -{ - regex_t re; - regmatch_t *subs; - - char *buf, /* buf is where we build the replaced string */ - *nbuf, /* nbuf is used when we grow the buffer */ - *walkbuf; /* used to walk buf when replacing backrefs */ - const char *walk; /* used to walk replacement string for backrefs */ - int buf_len; - int pos, tmp, string_len, new_l; - int err, copts = 0; - - string_len = strlen(string); - - if (icase) { - copts = REG_ICASE; - } - if (extended) { - copts |= REG_EXTENDED; - } - - err = regcomp(&re, pattern, copts); - if (err) { - php_reg_eprint(err, &re); - return ((char *) -1); - } - - - /* allocate storage for (sub-)expression-matches */ - subs = (regmatch_t *)ecalloc(sizeof(regmatch_t),re.re_nsub+1); - - /* start with a buffer that is twice the size of the stringo - we're doing replacements in */ - buf_len = 2 * string_len + 1; - buf = emalloc(buf_len * sizeof(char)); - - err = pos = 0; - buf[0] = '\0'; - while (!err) { - err = regexec(&re, &string[pos], re.re_nsub+1, subs, (pos ? REG_NOTBOL : 0)); - - if (err && err != REG_NOMATCH) { - php_reg_eprint(err, &re); - efree(subs); - efree(buf); - regfree(&re); - return ((char *) -1); - } - - if (!err) { - /* backref replacement is done in two passes: - 1) find out how long the string will be, and allocate buf - 2) copy the part before match, replacement and backrefs to buf - - Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi> - */ - - new_l = strlen(buf) + subs[0].rm_so; /* part before the match */ - walk = replace; - while (*walk) { - if ('\\' == *walk && isdigit((unsigned char)walk[1]) && ((unsigned char)walk[1]) - '0' <= re.re_nsub) { - if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1) { - new_l += subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; - } - walk += 2; - } else { - new_l++; - walk++; - } - } - if (new_l + 1 > buf_len) { - buf_len = 1 + buf_len + 2 * new_l; - nbuf = emalloc(buf_len); - strcpy(nbuf, buf); - efree(buf); - buf = nbuf; - } - tmp = strlen(buf); - /* copy the part of the string before the match */ - strncat(buf, &string[pos], subs[0].rm_so); - - /* copy replacement and backrefs */ - walkbuf = &buf[tmp + subs[0].rm_so]; - walk = replace; - while (*walk) { - if ('\\' == *walk && isdigit(walk[1]) && walk[1] - '0' <= (int)re.re_nsub) { - if (subs[walk[1] - '0'].rm_so > -1 && subs[walk[1] - '0'].rm_eo > -1 - /* this next case shouldn't happen. it does. */ - && subs[walk[1] - '0'].rm_so <= subs[walk[1] - '0'].rm_eo) { - - tmp = subs[walk[1] - '0'].rm_eo - subs[walk[1] - '0'].rm_so; - memcpy (walkbuf, &string[pos + subs[walk[1] - '0'].rm_so], tmp); - walkbuf += tmp; - } - walk += 2; - } else { - *walkbuf++ = *walk++; - } - } - *walkbuf = '\0'; - - /* and get ready to keep looking for replacements */ - if (subs[0].rm_so == subs[0].rm_eo) { - if (subs[0].rm_so + pos >= string_len) { - break; - } - new_l = strlen (buf) + 1; - if (new_l + 1 > buf_len) { - buf_len = 1 + buf_len + 2 * new_l; - nbuf = emalloc(buf_len * sizeof(char)); - strcpy(nbuf, buf); - efree(buf); - buf = nbuf; - } - pos += subs[0].rm_eo + 1; - buf [new_l-1] = string [pos-1]; - buf [new_l] = '\0'; - } else { - pos += subs[0].rm_eo; - } - } else { /* REG_NOMATCH */ - new_l = strlen(buf) + strlen(&string[pos]); - if (new_l + 1 > buf_len) { - buf_len = new_l + 1; /* now we know exactly how long it is */ - nbuf = emalloc(buf_len * sizeof(char)); - strcpy(nbuf, buf); - efree(buf); - buf = nbuf; - } - /* stick that last bit of string on our output */ - strcat(buf, &string[pos]); - } - } - - /* don't want to leak memory .. */ - efree(subs); - regfree(&re); - - /* whew. */ - return (buf); -} -/* }}} */ - -/* {{{ php_ereg_replace - */ -static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase) -{ - pval **arg_pattern, - **arg_replace, - **arg_string; - char *pattern; - char *string; - char *replace; - char *ret; - - if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(arg_pattern) == IS_STRING) { - if (Z_STRVAL_PP(arg_pattern) && Z_STRLEN_PP(arg_pattern)) - pattern = estrndup(Z_STRVAL_PP(arg_pattern), Z_STRLEN_PP(arg_pattern)); - else - pattern = empty_string; - } else { - convert_to_long_ex(arg_pattern); - pattern = emalloc(2); - pattern[0] = (char) Z_LVAL_PP(arg_pattern); - pattern[1] = '\0'; - } - - if (Z_TYPE_PP(arg_replace) == IS_STRING) { - if (Z_STRVAL_PP(arg_replace) && Z_STRLEN_PP(arg_replace)) - replace = estrndup(Z_STRVAL_PP(arg_replace), Z_STRLEN_PP(arg_replace)); - else - replace = empty_string; - } else { - convert_to_long_ex(arg_replace); - replace = emalloc(2); - replace[0] = (char) Z_LVAL_PP(arg_replace); - replace[1] = '\0'; - } - - convert_to_string_ex(arg_string); - if (Z_STRVAL_PP(arg_string) && Z_STRLEN_PP(arg_string)) - string = estrndup(Z_STRVAL_PP(arg_string), Z_STRLEN_PP(arg_string)); - else - string = empty_string; - - /* do the actual work */ - ret = php_reg_replace(pattern, replace, string, icase, 1); - if (ret == (char *) -1) { - RETVAL_FALSE; - } else { - RETVAL_STRING(ret, 1); - STR_FREE(ret); - } - - STR_FREE(string); - STR_FREE(replace); - STR_FREE(pattern); -} -/* }}} */ - -/* {{{ proto string ereg_replace(string pattern, string replacement, string string) - Replace regular expression */ -PHP_FUNCTION(ereg_replace) -{ - php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string eregi_replace(string pattern, string replacement, string string) - Case insensitive replace regular expression */ -PHP_FUNCTION(eregi_replace) -{ - php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ php_split - */ -static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase) -{ - zval **spliton, **str, **arg_count = NULL; - regex_t re; - regmatch_t subs[1]; - char *strp, *endp; - int err, size, count = -1, copts = 0; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2 || argc > 3 || - zend_get_parameters_ex(argc, &spliton, &str, &arg_count) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (argc > 2) { - convert_to_long_ex(arg_count); - count = Z_LVAL_PP(arg_count); - } - - if (icase) - copts = REG_ICASE; - - convert_to_string_ex(spliton); - convert_to_string_ex(str); - - strp = Z_STRVAL_PP(str); - endp = strp + Z_STRLEN_PP(str); - - err = regcomp(&re, Z_STRVAL_PP(spliton), REG_EXTENDED | copts); - if (err) { - php_reg_eprint(err, &re); - RETURN_FALSE; - } - - array_init(return_value); - - /* churn through str, generating array entries as we go */ - while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) { - if (subs[0].rm_so == 0 && subs[0].rm_eo) { - /* match is at start of string, return empty string */ - add_next_index_stringl(return_value, empty_string, 0, 1); - /* skip ahead the length of the regex match */ - strp += subs[0].rm_eo; - } else if (subs[0].rm_so == 0 && subs[0].rm_eo == 0) { - /* No more matches */ - regfree(&re); - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid Regular Expression to split()"); - zend_hash_destroy(Z_ARRVAL_P(return_value)); - efree(Z_ARRVAL_P(return_value)); - RETURN_FALSE; - } else { - /* On a real match */ - - /* make a copy of the substring */ - size = subs[0].rm_so; - - /* add it to the array */ - add_next_index_stringl(return_value, strp, size, 1); - - /* point at our new starting point */ - strp = strp + subs[0].rm_eo; - } - - /* if we're only looking for a certain number of points, - stop looking once we hit it */ - if (count != -1) { - count--; - } - } - - /* see if we encountered an error */ - if (err && err != REG_NOMATCH) { - php_reg_eprint(err, &re); - regfree(&re); - zend_hash_destroy(Z_ARRVAL_P(return_value)); - efree(Z_ARRVAL_P(return_value)); - RETURN_FALSE; - } - - /* otherwise we just have one last element to add to the array */ - size = endp - strp; - - add_next_index_stringl(return_value, strp, size, 1); - - regfree(&re); -} -/* }}} */ - -/* {{{ proto array split(string pattern, string string [, int limit]) - Split string into array by regular expression */ -PHP_FUNCTION(split) -{ - php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto array spliti(string pattern, string string [, int limit]) - Split string into array by regular expression case-insensitive */ - -PHP_FUNCTION(spliti) -{ - php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -/* }}} */ - -/* {{{ proto string sql_regcase(string string) - Make regular expression for case insensitive match */ -PHPAPI PHP_FUNCTION(sql_regcase) -{ - zval **string; - char *tmp; - unsigned char c; - register int i, j; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &string)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(string); - - tmp = emalloc((Z_STRLEN_PP(string) * 4) + 1); - - for (i = j = 0; i < Z_STRLEN_PP(string); i++) { - c = (unsigned char) Z_STRVAL_PP(string)[i]; - if(isalpha(c)) { - tmp[j++] = '['; - tmp[j++] = toupper(c); - tmp[j++] = tolower(c); - tmp[j++] = ']'; - } else { - tmp[j++] = c; - } - } - tmp[j] = 0; - - RETVAL_STRINGL(tmp, j, 1); - efree(tmp); -} -/* }}} */ - -/* - * 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/ext/standard/reg.h b/ext/standard/reg.h deleted file mode 100644 index c2d9251c5f..0000000000 --- a/ext/standard/reg.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ -*/ - - -/* $Id$ */ - -#ifndef REG_H -#define REG_H - -PHPAPI char *php_reg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended); - -PHP_FUNCTION(ereg); -PHP_FUNCTION(eregi); -PHP_FUNCTION(eregi_replace); -PHP_FUNCTION(ereg_replace); -PHP_FUNCTION(split); -PHP_FUNCTION(spliti); -PHPAPI PHP_FUNCTION(sql_regcase); - -ZEND_BEGIN_MODULE_GLOBALS(reg) - HashTable ht_rc; -ZEND_END_MODULE_GLOBALS(reg) - -PHP_MINIT_FUNCTION(regex); -PHP_MSHUTDOWN_FUNCTION(regex); -PHP_MINFO_FUNCTION(regex); - - -#ifdef ZTS -#define REG(v) TSRMG(reg_globals_id, zend_reg_globals *, v) -#else -#define REG(v) (reg_globals.v) -#endif - -#endif /* REG_H */ diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c deleted file mode 100644 index 54723e1b0a..0000000000 --- a/ext/standard/scanf.c +++ /dev/null @@ -1,1259 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Clayton Collie <clcollie@mindspring.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - scanf.c -- - - This file contains the base code which implements sscanf and by extension - fscanf. Original code is from TCL8.3.0 and bears the following copyright - - - - This software is copyrighted by the Regents of the University of - California, Sun Microsystems, Inc., Scriptics Corporation, - and other parties. The following terms apply to all files associated - with the software unless explicitly disclaimed in individual files. - - The authors hereby grant permission to use, copy, modify, distribute, - and license this software and its documentation for any purpose, provided - that existing copyright notices are retained in all copies and that this - notice is included verbatim in any distributions. No written agreement, - license, or royalty fee is required for any of the authorized uses. - Modifications to this software may be copyrighted by their authors - and need not follow the licensing terms described here, provided that - the new terms are clearly indicated on the first page of each file where - they apply. - - IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY - FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY - DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - - THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE - IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE - NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR - MODIFICATIONS. - - GOVERNMENT USE: If you are acquiring this software on behalf of the - U.S. government, the Government shall have only "Restricted Rights" - in the software and related documentation as defined in the Federal - Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you - are acquiring the software on behalf of the Department of Defense, the - software shall be classified as "Commercial Computer Software" and the - Government shall have only "Restricted Rights" as defined in Clause - 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the - authors grant the U.S. Government and others acting in its behalf - permission to use and distribute the software in accordance with the - terms specified in this license. - - */ - -#include <stdio.h> -#include <limits.h> -#include <ctype.h> -#include "php.h" -#include "php_variables.h" -#ifdef HAVE_LOCALE_H -#include <locale.h> -#endif -#include "zend_execute.h" -#include "zend_operators.h" -#include "php_globals.h" -#include "basic_functions.h" -#include "scanf.h" - -/* - * Flag values used internally by [f|s]canf. - */ - -#define SCAN_NOSKIP 0x1 /* Don't skip blanks. */ -#define SCAN_SUPPRESS 0x2 /* Suppress assignment. */ -#define SCAN_UNSIGNED 0x4 /* Read an unsigned value. */ -#define SCAN_WIDTH 0x8 /* A width value was supplied. */ - -#define SCAN_SIGNOK 0x10 /* A +/- character is allowed. */ -#define SCAN_NODIGITS 0x20 /* No digits have been scanned. */ -#define SCAN_NOZERO 0x40 /* No zero digits have been scanned. */ -#define SCAN_XOK 0x80 /* An 'x' is allowed. */ -#define SCAN_PTOK 0x100 /* Decimal point is allowed. */ -#define SCAN_EXPOK 0x200 /* An exponent is allowed. */ - -#define UCHAR(x) (zend_uchar)(x) - - - -/* - * The following structure contains the information associated with - * a character set. - */ - -typedef struct CharSet { - int exclude; /* 1 if this is an exclusion set. */ - int nchars; - char *chars; - int nranges; - struct Range { - char start; - char end; - } *ranges; -} CharSet; - -/* - * Declarations for functions used only in this file. - */ - -static char *BuildCharSet(CharSet *cset, char *format); -static int CharInSet(CharSet *cset, int ch); -static void ReleaseCharSet(CharSet *cset); -static inline void scan_set_error_return(int numVars, pval **return_value); - - -/* {{{ BuildCharSet - *---------------------------------------------------------------------- - * - * BuildCharSet -- - * - * This function examines a character set format specification - * and builds a CharSet containing the individual characters and - * character ranges specified. - * - * Results: - * Returns the next format position. - * - * Side effects: - * Initializes the charset. - * - *---------------------------------------------------------------------- - */ -static char * BuildCharSet(CharSet *cset, char *format) -{ - char *ch, start; - int nranges; - char *end; - - memset(cset, 0, sizeof(CharSet)); - - ch = format; - if (*ch == '^') { - cset->exclude = 1; - ch = ++format; - } - end = format + 1; /* verify this - cc */ - - /* - * Find the close bracket so we can overallocate the set. - */ - - if (*ch == ']') { - ch = end++; - } - nranges = 0; - while (*ch != ']') { - if (*ch == '-') { - nranges++; - } - ch = end++; - } - - cset->chars = (char *) emalloc(sizeof(char) * (end - format - 1)); - if (nranges > 0) { - cset->ranges = (struct Range *) emalloc(sizeof(struct Range)*nranges); - } else { - cset->ranges = NULL; - } - - /* - * Now build the character set. - */ - - cset->nchars = cset->nranges = 0; - ch = format++; - start = *ch; - if (*ch == ']' || *ch == '-') { - cset->chars[cset->nchars++] = *ch; - ch = format++; - } - while (*ch != ']') { - if (*format == '-') { - /* - * This may be the first character of a range, so don't add - * it yet. - */ - - start = *ch; - } else if (*ch == '-') { - /* - * Check to see if this is the last character in the set, in which - * case it is not a range and we should add the previous character - * as well as the dash. - */ - - if (*format == ']') { - cset->chars[cset->nchars++] = start; - cset->chars[cset->nchars++] = *ch; - } else { - ch = format++; - - /* - * Check to see if the range is in reverse order. - */ - - if (start < *ch) { - cset->ranges[cset->nranges].start = start; - cset->ranges[cset->nranges].end = *ch; - } else { - cset->ranges[cset->nranges].start = *ch; - cset->ranges[cset->nranges].end = start; - } - cset->nranges++; - } - } else { - cset->chars[cset->nchars++] = *ch; - } - ch = format++; - } - return format; -} -/* }}} */ - -/* {{{ CharInSet - *---------------------------------------------------------------------- - * - * CharInSet -- - * - * Check to see if a character matches the given set. - * - * Results: - * Returns non-zero if the character matches the given set. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -static int CharInSet(CharSet *cset, int c) -{ - char ch = (char) c; - int i, match = 0; - - for (i = 0; i < cset->nchars; i++) { - if (cset->chars[i] == ch) { - match = 1; - break; - } - } - if (!match) { - for (i = 0; i < cset->nranges; i++) { - if ((cset->ranges[i].start <= ch) - && (ch <= cset->ranges[i].end)) { - match = 1; - break; - } - } - } - return (cset->exclude ? !match : match); -} -/* }}} */ - -/* {{{ ReleaseCharSet - *---------------------------------------------------------------------- - * - * ReleaseCharSet -- - * - * Free the storage associated with a character set. - * - * Results: - * None. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ -static void ReleaseCharSet(CharSet *cset) -{ - efree((char *)cset->chars); - if (cset->ranges) { - efree((char *)cset->ranges); - } -} -/* }}} */ - -/* {{{ ValidateFormat - *---------------------------------------------------------------------- - * - * ValidateFormat -- - * - * Parse the format string and verify that it is properly formed - * and that there are exactly enough variables on the command line. - * - * Results: - * FAILURE or SUCCESS. - * - * Side effects: - * May set php_error based on abnormal conditions. - * - * Parameters : - * format The format string. - * numVars The number of variables passed to the scan command. - * totalSubs The number of variables that will be required. - * - *---------------------------------------------------------------------- -*/ -PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs) -{ -#define STATIC_LIST_SIZE 16 - int gotXpg, gotSequential, value, i, flags; - char *end, *ch = NULL; - int staticAssign[STATIC_LIST_SIZE]; - int *nassign = staticAssign; - int objIndex, xpgSize, nspace = STATIC_LIST_SIZE; - TSRMLS_FETCH(); - - /* - * Initialize an array that records the number of times a variable - * is assigned to by the format string. We use this to detect if - * a variable is multiply assigned or left unassigned. - */ - - if (numVars > nspace) { - nassign = (int*)emalloc(sizeof(int) * numVars); - nspace = numVars; - } - for (i = 0; i < nspace; i++) { - nassign[i] = 0; - } - - xpgSize = objIndex = gotXpg = gotSequential = 0; - - while (*format != '\0') { - ch = format++; - flags = 0; - - if (*ch != '%') { - continue; - } - ch = format++; - if (*ch == '%') { - continue; - } - if (*ch == '*') { - flags |= SCAN_SUPPRESS; - ch = format++; - goto xpgCheckDone; - } - - if ( isdigit( (int)*ch ) ) { - /* - * Check for an XPG3-style %n$ specification. Note: there - * must not be a mixture of XPG3 specs and non-XPG3 specs - * in the same format string. - */ - - value = strtoul(format-1, &end, 10); - if (*end != '$') { - goto notXpg; - } - format = end+1; - ch = format++; - gotXpg = 1; - if (gotSequential) { - goto mixedXPG; - } - objIndex = value - 1; - if ((objIndex < 0) || (numVars && (objIndex >= numVars))) { - goto badIndex; - } else if (numVars == 0) { - /* - * In the case where no vars are specified, the user can - * specify %9999$ legally, so we have to consider special - * rules for growing the assign array. 'value' is - * guaranteed to be > 0. - */ - - /* set a lower artificial limit on this - * in the interest of security and resource friendliness - * 255 arguments should be more than enough. - cc - */ - if (value > SCAN_MAX_ARGS) { - goto badIndex; - } - - xpgSize = (xpgSize > value) ? xpgSize : value; - } - goto xpgCheckDone; - } - - notXpg: - gotSequential = 1; - if (gotXpg) { - mixedXPG: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot mix \"%\" and \"%n$\" conversion specifiers"); - goto error; - } - - xpgCheckDone: - /* - * Parse any width specifier. - */ - - if (isdigit(UCHAR(*ch))) { - value = strtoul(format-1, &format, 10); - flags |= SCAN_WIDTH; - ch = format++; - } - - /* - * Ignore size specifier. - */ - - if ((*ch == 'l') || (*ch == 'L') || (*ch == 'h')) { - ch = format++; - } - - if (!(flags & SCAN_SUPPRESS) && numVars && (objIndex >= numVars)) { - goto badIndex; - } - - /* - * Handle the various field types. - */ - - switch (*ch) { - case 'n': - case 'd': - case 'D': - case 'i': - case 'o': - case 'x': - case 'X': - case 'u': - case 'f': - case 'e': - case 'E': - case 'g': - case 's': - break; - case 'c': - /* we differ here with the TCL implementation in allowing for */ - /* a character width specification, to be more consistent with */ - /* ANSI. since Zend auto allocates space for vars, this is no */ - /* problem - cc */ - /* - if (flags & SCAN_WIDTH) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Field width may not be specified in %c conversion"); - goto error; - } - */ - break; - case '[': - if (*format == '\0') { - goto badSet; - } - ch = format++; - if (*ch == '^') { - if (*format == '\0') { - goto badSet; - } - ch = format++; - } - if (*ch == ']') { - if (*format == '\0') { - goto badSet; - } - ch = format++; - } - while (*ch != ']') { - if (*format == '\0') { - goto badSet; - } - ch = format++; - } - break; - badSet: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unmatched [ in format string"); - goto error; - default: - { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad scan conversion character \"%c\"", ch); - goto error; - } - } - if (!(flags & SCAN_SUPPRESS)) { - if (objIndex >= nspace) { - /* - * Expand the nassign buffer. If we are using XPG specifiers, - * make sure that we grow to a large enough size. xpgSize is - * guaranteed to be at least one larger than objIndex. - */ - value = nspace; - if (xpgSize) { - nspace = xpgSize; - } else { - nspace += STATIC_LIST_SIZE; - } - if (nassign == staticAssign) { - nassign = (void *)emalloc(nspace * sizeof(int)); - for (i = 0; i < STATIC_LIST_SIZE; ++i) { - nassign[i] = staticAssign[i]; - } - } else { - nassign = (void *)erealloc((void *)nassign, nspace * sizeof(int)); - } - for (i = value; i < nspace; i++) { - nassign[i] = 0; - } - } - nassign[objIndex]++; - objIndex++; - } - } /* while (*format != '\0') */ - - /* - * Verify that all of the variable were assigned exactly once. - */ - - if (numVars == 0) { - if (xpgSize) { - numVars = xpgSize; - } else { - numVars = objIndex; - } - } - if (totalSubs) { - *totalSubs = numVars; - } - for (i = 0; i < numVars; i++) { - if (nassign[i] > 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Variable is assigned by multiple \"%n$\" conversion specifiers"); - goto error; - } else if (!xpgSize && (nassign[i] == 0)) { - /* - * If the space is empty, and xpgSize is 0 (means XPG wasn't - * used, and/or numVars != 0), then too many vars were given - */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Variable is not assigned by any conversion specifiers"); - goto error; - } - } - - if (nassign != staticAssign) { - efree((char *)nassign); - } - return SCAN_SUCCESS; - -badIndex: - if (gotXpg) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "\"%n$\" argument index out of range"); - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Different numbers of variable names and field specifiers"); - } - -error: - if (nassign != staticAssign) { - efree((char *)nassign); - } - return SCAN_ERROR_INVALID_FORMAT; -#undef STATIC_LIST_SIZE -} -/* }}} */ - -/* {{{ php_sscanf_internal - * This is the internal function which does processing on behalf of - * both sscanf() and fscanf() - * - * parameters : - * string literal string to be processed - * format format string - * argCount total number of elements in the args array - * args arguments passed in from user function (f|s)scanf - * varStart offset (in args) of 1st variable passed in to (f|s)scanf - * return_value set with the results of the scan - */ - -PHPAPI int php_sscanf_internal( char *string, char *format, - int argCount, zval ***args, - int varStart, pval **return_value TSRMLS_DC) -{ - int numVars, nconversions, totalVars = -1; - int i, value, result; - int objIndex; - char *end, *baseString; - zval **current; - char op = 0; - int base = 0; - int underflow = 0; - size_t width; - long (*fn)() = NULL; - char *ch, sch; - int flags; - char buf[64]; /* Temporary buffer to hold scanned - * number strings before they are - * passed to strtoul. */ - - - /* do some sanity checking */ - if ((varStart > argCount) || (varStart < 0)){ - varStart = SCAN_MAX_ARGS + 1; - } - numVars = argCount - varStart; - if (numVars < 0) { - numVars = 0; - } - -#if 0 - zend_printf("<br>in sscanf_internal : <br> string is \"%s\", format = \"%s\"<br> NumVars = %d. VarStart = %d<br>-------------------------<br>", - string, format, numVars, varStart); -#endif - /* - * Check for errors in the format string. - */ - if (ValidateFormat(format, numVars, &totalVars) != SCAN_SUCCESS) { - scan_set_error_return( numVars, return_value ); - return SCAN_ERROR_INVALID_FORMAT; - } - - objIndex = numVars ? varStart : 0; - - /* - * If any variables are passed, make sure they are all passed by reference - */ - if (numVars) { - for (i = varStart;i < argCount;i++){ - if ( ! PZVAL_IS_REF( *args[ i ] ) ) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Parameter %d must be passed by reference", i); - scan_set_error_return(numVars, return_value); - return SCAN_ERROR_VAR_PASSED_BYVAL; - } - } - } - - - /* - * Allocate space for the result objects. Only happens when no variables - * are specified - */ - - if (!numVars) { - /* allocate an array for return */ - array_init(*return_value); - - for (i = 0; i < totalVars; i++) { - if (add_next_index_null(*return_value) == FAILURE) { - scan_set_error_return(0, return_value); - return FAILURE; - } - } - } - - baseString = string; - - /* - * Iterate over the format string filling in the result objects until - * we reach the end of input, the end of the format string, or there - * is a mismatch. - */ - - nconversions = 0; - /* note ! - we need to limit the loop for objIndex to keep it in bounds */ - - while (*format != '\0') { - - ch = format++; - - flags = 0; - - /* - * If we see whitespace in the format, skip whitespace in the string. - */ - - if ( isspace( (int)*ch ) ) { - sch = *string; - while ( isspace( (int)sch ) ) { - if (*string == '\0') { - goto done; - } - string++; - sch = *string; - } - continue; - } - - if (*ch != '%') { - literal: - if (*string == '\0') { - underflow = 1; - goto done; - } - sch = *string; - string++; - if (*ch != sch) { - goto done; - } - continue; - } - - ch = format++; - if (*ch == '%') { - goto literal; - } - - /* - * Check for assignment suppression ('*') or an XPG3-style - * assignment ('%n$'). - */ - - if (*ch == '*') { - flags |= SCAN_SUPPRESS; - ch = format++; - } else if ( isdigit(UCHAR(*ch))) { - value = strtoul(format-1, &end, 10); - if (*end == '$') { - format = end+1; - ch = format++; - objIndex = varStart + value; - } - } - - /* - * Parse any width specifier. - */ - - if ( isdigit(UCHAR(*ch))) { - width = strtoul(format-1, &format, 10); - ch = format++; - } else { - width = 0; - } - - /* - * Ignore size specifier. - */ - - if ((*ch == 'l') || (*ch == 'L') || (*ch == 'h')) { - ch = format++; - } - - /* - * Handle the various field types. - */ - - switch (*ch) { - case 'n': - if (!(flags & SCAN_SUPPRESS)) { - if (numVars) { - zend_uint refcount; - - current = args[objIndex++]; - refcount = (*current)->refcount; - zval_dtor( *current ); - ZVAL_LONG( *current, (long)(string - baseString) ); - (*current)->refcount = refcount; - (*current)->is_ref = 1; - } else { - add_index_long(*return_value, objIndex++, string - baseString); - } - } - nconversions++; - continue; - - case 'd': - case 'D': - op = 'i'; - base = 10; - fn = (long (*)())strtol; - break; - case 'i': - op = 'i'; - base = 0; - fn = (long (*)())strtol; - break; - case 'o': - op = 'i'; - base = 8; - fn = (long (*)())strtol; - break; - case 'x': - op = 'i'; - base = 16; - fn = (long (*)())strtol; - break; - case 'u': - op = 'i'; - base = 10; - flags |= SCAN_UNSIGNED; - fn = (long (*)())strtoul; - break; - - case 'f': - case 'e': - case 'E': - case 'g': - op = 'f'; - break; - - case 's': - op = 's'; - break; - - case 'c': - op = 's'; - flags |= SCAN_NOSKIP; - /*-cc-*/ - if (0 == width) { - width = 1; - } - /*-cc-*/ - break; - case '[': - op = '['; - flags |= SCAN_NOSKIP; - break; - } /* switch */ - - /* - * At this point, we will need additional characters from the - * string to proceed. - */ - - if (*string == '\0') { - underflow = 1; - goto done; - } - - /* - * Skip any leading whitespace at the beginning of a field unless - * the format suppresses this behavior. - */ - - if (!(flags & SCAN_NOSKIP)) { - while (*string != '\0') { - sch = *string; - if (! isspace((int)sch) ) { - break; - } - string++; - } - if (*string == '\0') { - underflow = 1; - goto done; - } - } - - /* - * Perform the requested scanning operation. - */ - - switch (op) { - case 'c': - case 's': - /* - * Scan a string up to width characters or whitespace. - */ - - if (width == 0) { - width = (size_t) ~0; - } - end = string; - while (*end != '\0') { - sch = *end; - if ( isspace( (int)sch ) ) { - break; - } - end++; - if (--width == 0) { - break; - } - } - if (!(flags & SCAN_SUPPRESS)) { - if (numVars) { - zend_uint refcount; - - current = args[objIndex++]; - refcount = (*current)->refcount; - zval_dtor( *current ); - ZVAL_STRINGL( *current, string, end-string, 1); - (*current)->refcount = refcount; - (*current)->is_ref = 1; - } else { - add_index_stringl( *return_value, objIndex++, string, end-string, 1); - } - } - string = end; - break; - - case '[': { - CharSet cset; - - if (width == 0) { - width = (size_t) ~0; - } - end = string; - - format = BuildCharSet(&cset, format); - while (*end != '\0') { - sch = *end; - if (!CharInSet(&cset, (int)sch)) { - break; - } - end++; - if (--width == 0) { - break; - } - } - ReleaseCharSet(&cset); - - if (string == end) { - /* - * Nothing matched the range, stop processing - */ - goto done; - } - if (!(flags & SCAN_SUPPRESS)) { - if (numVars) { - current = args[objIndex++]; - convert_to_string( *current ); - ZVAL_STRINGL( *current, string, end-string, 1); - } else { - add_index_stringl(*return_value, objIndex++, string, end-string, 1); - } - } - string = end; - - break; - } - /* - case 'c': - / Scan a single character./ - - sch = *string; - string++; - if (!(flags & SCAN_SUPPRESS)) { - if (numVars) { - char __buf[2]; - __buf[0] = sch; - __buf[1] = '\0';; - current = args[objIndex++]; - convert_to_string_ex( current ); - ZVAL_STRINGL( *current, __buf, 1, 1); - } else { - add_index_stringl(*return_value, objIndex++, &sch, 1, 1); - } - } - break; - */ - case 'i': - /* - * Scan an unsigned or signed integer. - */ - - /*-cc-*/ - buf[0] = '\0'; - /*-cc-*/ - if ((width == 0) || (width > sizeof(buf) - 1)) { - width = sizeof(buf) - 1; - } - - flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO; - for (end = buf; width > 0; width--) { - switch (*string) { - /* - * The 0 digit has special meaning at the beginning of - * a number. If we are unsure of the base, it - * indicates that we are in base 8 or base 16 (if it is - * followed by an 'x'). - */ - case '0': - /*-cc-*/ - if (base == 16) { - flags |= SCAN_XOK; - } - /*-cc-*/ - if (base == 0) { - base = 8; - flags |= SCAN_XOK; - } - if (flags & SCAN_NOZERO) { - flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO); - } else { - flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); - } - goto addToInt; - - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': - if (base == 0) { - base = 10; - } - flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); - goto addToInt; - - case '8': case '9': - if (base == 0) { - base = 10; - } - if (base <= 8) { - break; - } - flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); - goto addToInt; - - case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': - case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': - if (base <= 10) { - break; - } - flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS); - goto addToInt; - - case '+': case '-': - if (flags & SCAN_SIGNOK) { - flags &= ~SCAN_SIGNOK; - goto addToInt; - } - break; - - case 'x': case 'X': - if ((flags & SCAN_XOK) && (end == buf+1)) { - base = 16; - flags &= ~SCAN_XOK; - goto addToInt; - } - break; - } - - /* - * We got an illegal character so we are done accumulating. - */ - - break; - - addToInt: - /* - * Add the character to the temporary buffer. - */ - *end++ = *string++; - if (*string == '\0') { - break; - } - } - - /* - * Check to see if we need to back up because we only got a - * sign or a trailing x after a 0. - */ - - if (flags & SCAN_NODIGITS) { - if (*string == '\0') { - underflow = 1; - } - goto done; - } else if (end[-1] == 'x' || end[-1] == 'X') { - end--; - string--; - } - - - /* - * Scan the value from the temporary buffer. If we are - * returning a large unsigned value, we have to convert it back - * to a string since PHP only supports signed values. - */ - - if (!(flags & SCAN_SUPPRESS)) { - *end = '\0'; - value = (int) (*fn)(buf, NULL, base); - if ((flags & SCAN_UNSIGNED) && (value < 0)) { - sprintf(buf, "%u", value); /* INTL: ISO digit */ - if (numVars) { - /* change passed value type to string */ - current = args[objIndex++]; - convert_to_string( *current ); - ZVAL_STRING( *current, buf, 1 ); - } else { - add_index_string(*return_value, objIndex++, buf, 1); - } - } else { - if (numVars) { - current = args[objIndex++]; - convert_to_long( *current ); - Z_LVAL(**current) = value; - } else { - add_index_long(*return_value, objIndex++, value); - } - } - } - - break; - - case 'f': - /* - * Scan a floating point number - */ - buf[0] = '\0'; /* call me pedantic */ - if ((width == 0) || (width > sizeof(buf) - 1)) { - width = sizeof(buf) - 1; - } - flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_PTOK | SCAN_EXPOK; - for (end = buf; width > 0; width--) { - switch (*string) { - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - case '8': case '9': - flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS); - goto addToFloat; - case '+': case '-': - if (flags & SCAN_SIGNOK) { - flags &= ~SCAN_SIGNOK; - goto addToFloat; - } - break; - case '.': - if (flags & SCAN_PTOK) { - flags &= ~(SCAN_SIGNOK | SCAN_PTOK); - goto addToFloat; - } - break; - case 'e': case 'E': - /* - * An exponent is not allowed until there has - * been at least one digit. - */ - - if ((flags & (SCAN_NODIGITS | SCAN_EXPOK)) == SCAN_EXPOK) { - flags = (flags & ~(SCAN_EXPOK|SCAN_PTOK)) - | SCAN_SIGNOK | SCAN_NODIGITS; - goto addToFloat; - } - break; - } - - /* - * We got an illegal character so we are done accumulating. - */ - - break; - - addToFloat: - /* - * Add the character to the temporary buffer. - */ - - *end++ = *string++; - if (*string == '\0') { - break; - } - } - - /* - * Check to see if we need to back up because we saw a - * trailing 'e' or sign. - */ - - if (flags & SCAN_NODIGITS) { - if (flags & SCAN_EXPOK) { - /* - * There were no digits at all so scanning has - * failed and we are done. - */ - if (*string == '\0') { - underflow = 1; - } - goto done; - } - - /* - * We got a bad exponent ('e' and maybe a sign). - */ - - end--; - string--; - if (*end != 'e' && *end != 'E') { - end--; - string--; - } - } - - /* - * Scan the value from the temporary buffer. - */ - - if (!(flags & SCAN_SUPPRESS)) { - double dvalue; - *end = '\0'; - dvalue = strtod(buf, NULL); - if (numVars) { - current = args[objIndex++]; - convert_to_double( *current ); - Z_DVAL_PP( current ) = dvalue; - } else { - add_index_double( *return_value, objIndex++, dvalue ); - } - } - break; - } /* switch (op) */ - nconversions++; - } /* while (*format != '\0') */ - -done: - result = SCAN_SUCCESS; - - if (underflow && (0==nconversions)) { - scan_set_error_return( numVars, return_value ); - result = SCAN_ERROR_EOF; - } else if (numVars) { - convert_to_long( *return_value ); - Z_LVAL_PP(return_value) = nconversions; - } else if (nconversions < totalVars) { - /* to do : not all elements converted. we need to prune the list - cc - */ - } - - return result; -} -/* }}} */ - -/* the compiler choked when i tried to make this a macro */ -static inline void scan_set_error_return(int numVars, pval **return_value) -{ - if (numVars) { - Z_TYPE_PP(return_value) = IS_LONG; - Z_LVAL_PP(return_value) = SCAN_ERROR_EOF; /* EOF marker */ - } else { - /* pval_destructor( *return_value ); */ - /* convert_to_null calls destructor */ - convert_to_null( *return_value ); - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/scanf.h b/ext/standard/scanf.h deleted file mode 100644 index c18a961602..0000000000 --- a/ext/standard/scanf.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Clayton Collie <clcollie@mindspring.com> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef SCANF_H -#define SCANF_H - - -#define SCAN_MAX_ARGS 0xFF /* Maximum number of variable which can be */ - /* passed to (f|s)scanf. This is an artifical */ - /* upper limit to keep resources in check and */ - /* minimize the possibility of exploits */ - -#define SCAN_SUCCESS SUCCESS -#define SCAN_ERROR_EOF -1 /* indicates premature termination of scan */ - /* can be caused by bad parameters or format*/ - /* string. */ -#define SCAN_ERROR_INVALID_FORMAT (SCAN_ERROR_EOF - 1) -#define SCAN_ERROR_VAR_PASSED_BYVAL (SCAN_ERROR_INVALID_FORMAT - 1) -#define SCAN_ERROR_WRONG_PARAM_COUNT (SCAN_ERROR_VAR_PASSED_BYVAL - 1) -#define SCAN_ERROR_INTERNAL (SCAN_ERROR_WRONG_PARAM_COUNT - 1) - - -/* - * The following are here solely for the benefit of the scanf type functions - * e.g. fscanf - */ -PHPAPI int ValidateFormat(char *format, int numVars, int *totalVars); -PHPAPI int php_sscanf_internal(char *string,char *format,int argCount,zval ***args, - int varStart, pval **return_value TSRMLS_DC); - - -#endif /* SCANF_H */ diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c deleted file mode 100644 index 38027f247f..0000000000 --- a/ext/standard/sha1.c +++ /dev/null @@ -1,427 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stefan Esser <sesser@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include <stdio.h> -#include "php.h" - -/* This code is heavily based on the PHP md5 implementation */ - -#include "sha1.h" - -PHPAPI void make_sha1_digest(char *sha1str, unsigned char *digest) -{ - int i; - - for (i = 0; i < 20; i++) { - sprintf(sha1str, "%02x", digest[i]); - sha1str += 2; - } - - *sha1str = '\0'; -} - -/* {{{ proto string sha1(string str [, bool raw_output]) - Calculate the sha1 hash of a string */ -PHP_FUNCTION(sha1) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char sha1str[41]; - PHP_SHA1_CTX context; - unsigned char digest[20]; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - sha1str[0] = '\0'; - PHP_SHA1Init(&context); - PHP_SHA1Update(&context, arg, arg_len); - PHP_SHA1Final(digest, &context); - if (raw_output) { - RETURN_STRINGL(digest, 20, 1); - } else { - make_sha1_digest(sha1str, digest); - RETVAL_STRING(sha1str, 1); - } - -} - -/* }}} */ - -/* {{{ proto string sha1_file(string filename [, bool raw_output]) - Calculate the sha1 hash of given filename */ -PHP_FUNCTION(sha1_file) -{ - char *arg; - int arg_len; - zend_bool raw_output = 0; - char sha1str[41]; - unsigned char buf[1024]; - unsigned char digest[20]; - PHP_SHA1_CTX context; - int n; - FILE *fp; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { - return; - } - - if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(arg TSRMLS_CC)) { - RETURN_FALSE; - } - - if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); - RETURN_FALSE; - } - - PHP_SHA1Init(&context); - - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) { - PHP_SHA1Update(&context, buf, n); - } - - PHP_SHA1Final(digest, &context); - - if (ferror(fp)) { - fclose(fp); - RETURN_FALSE; - } - - fclose(fp); - - if (raw_output) { - RETURN_STRINGL(digest, 20, 1); - } else { - make_sha1_digest(sha1str, digest); - RETVAL_STRING(sha1str, 1); - } -} -/* }}} */ - - -static void SHA1Transform(php_uint32[5], const unsigned char[64]); -static void SHA1Encode(unsigned char *, php_uint32 *, unsigned int); -static void SHA1Decode(php_uint32 *, const unsigned char *, unsigned int); - -static unsigned char PADDING[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* F, G, H and I are basic SHA1 functions. - */ -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) ((x) ^ (y) ^ (z)) -#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define I(x, y, z) ((x) ^ (y) ^ (z)) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* W[i] - */ -#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ - (x[i&15]=ROTATE_LEFT(tmp, 1)) ) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - */ -#define FF(a, b, c, d, e, w) { \ - (e) += F ((b), (c), (d)) + (w) + (php_uint32)(0x5A827999); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define GG(a, b, c, d, e, w) { \ - (e) += G ((b), (c), (d)) + (w) + (php_uint32)(0x6ED9EBA1); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define HH(a, b, c, d, e, w) { \ - (e) += H ((b), (c), (d)) + (w) + (php_uint32)(0x8F1BBCDC); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define II(a, b, c, d, e, w) { \ - (e) += I ((b), (c), (d)) + (w) + (php_uint32)(0xCA62C1D6); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } - - -/* {{{ PHP_SHA1Init - * SHA1 initialization. Begins an SHA1 operation, writing a new context. - */ -PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX * context) -{ - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; - context->state[4] = 0xc3d2e1f0; -} -/* }}} */ - -/* {{{ PHP_SHA1Update - SHA1 block update operation. Continues an SHA1 message-digest - operation, processing another message block, and updating the - context. - */ -PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX * context, const unsigned char *input, - unsigned int inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((php_uint32) inputLen << 3)) - < ((php_uint32) inputLen << 3)) - context->count[1]++; - context->count[1] += ((php_uint32) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); - SHA1Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - SHA1Transform(context->state, &input[i]); - - index = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], - inputLen - i); -} -/* }}} */ - -/* {{{ PHP_SHA1Final - SHA1 finalization. Ends an SHA1 message-digest operation, writing the - the message digest and zeroizing the context. - */ -PHPAPI void PHP_SHA1Final(unsigned char digest[20], PHP_SHA1_CTX * context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - bits[7] = context->count[0] & 0xFF; - bits[6] = (context->count[0] >> 8) & 0xFF; - bits[5] = (context->count[0] >> 16) & 0xFF; - bits[4] = (context->count[0] >> 24) & 0xFF; - bits[3] = context->count[1] & 0xFF; - bits[2] = (context->count[1] >> 8) & 0xFF; - bits[1] = (context->count[1] >> 16) & 0xFF; - bits[0] = (context->count[1] >> 24) & 0xFF; - - /* Pad out to 56 mod 64. - */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - PHP_SHA1Update(context, PADDING, padLen); - - /* Append length (before padding) */ - PHP_SHA1Update(context, bits, 8); - - /* Store state in digest */ - SHA1Encode(digest, context->state, 20); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -/* {{{ SHA1Transform - * SHA1 basic transformation. Transforms state based on block. - */ -static void SHA1Transform(state, block) -php_uint32 state[5]; -const unsigned char block[64]; -{ - php_uint32 a = state[0], b = state[1], c = state[2]; - php_uint32 d = state[3], e = state[4], x[16], tmp; - - SHA1Decode(x, block, 64); - - /* Round 1 */ - FF(a, b, c, d, e, x[0]); /* 1 */ - FF(e, a, b, c, d, x[1]); /* 2 */ - FF(d, e, a, b, c, x[2]); /* 3 */ - FF(c, d, e, a, b, x[3]); /* 4 */ - FF(b, c, d, e, a, x[4]); /* 5 */ - FF(a, b, c, d, e, x[5]); /* 6 */ - FF(e, a, b, c, d, x[6]); /* 7 */ - FF(d, e, a, b, c, x[7]); /* 8 */ - FF(c, d, e, a, b, x[8]); /* 9 */ - FF(b, c, d, e, a, x[9]); /* 10 */ - FF(a, b, c, d, e, x[10]); /* 11 */ - FF(e, a, b, c, d, x[11]); /* 12 */ - FF(d, e, a, b, c, x[12]); /* 13 */ - FF(c, d, e, a, b, x[13]); /* 14 */ - FF(b, c, d, e, a, x[14]); /* 15 */ - FF(a, b, c, d, e, x[15]); /* 16 */ - FF(e, a, b, c, d, W(16)); /* 17 */ - FF(d, e, a, b, c, W(17)); /* 18 */ - FF(c, d, e, a, b, W(18)); /* 19 */ - FF(b, c, d, e, a, W(19)); /* 20 */ - - /* Round 2 */ - GG(a, b, c, d, e, W(20)); /* 21 */ - GG(e, a, b, c, d, W(21)); /* 22 */ - GG(d, e, a, b, c, W(22)); /* 23 */ - GG(c, d, e, a, b, W(23)); /* 24 */ - GG(b, c, d, e, a, W(24)); /* 25 */ - GG(a, b, c, d, e, W(25)); /* 26 */ - GG(e, a, b, c, d, W(26)); /* 27 */ - GG(d, e, a, b, c, W(27)); /* 28 */ - GG(c, d, e, a, b, W(28)); /* 29 */ - GG(b, c, d, e, a, W(29)); /* 30 */ - GG(a, b, c, d, e, W(30)); /* 31 */ - GG(e, a, b, c, d, W(31)); /* 32 */ - GG(d, e, a, b, c, W(32)); /* 33 */ - GG(c, d, e, a, b, W(33)); /* 34 */ - GG(b, c, d, e, a, W(34)); /* 35 */ - GG(a, b, c, d, e, W(35)); /* 36 */ - GG(e, a, b, c, d, W(36)); /* 37 */ - GG(d, e, a, b, c, W(37)); /* 38 */ - GG(c, d, e, a, b, W(38)); /* 39 */ - GG(b, c, d, e, a, W(39)); /* 40 */ - - /* Round 3 */ - HH(a, b, c, d, e, W(40)); /* 41 */ - HH(e, a, b, c, d, W(41)); /* 42 */ - HH(d, e, a, b, c, W(42)); /* 43 */ - HH(c, d, e, a, b, W(43)); /* 44 */ - HH(b, c, d, e, a, W(44)); /* 45 */ - HH(a, b, c, d, e, W(45)); /* 46 */ - HH(e, a, b, c, d, W(46)); /* 47 */ - HH(d, e, a, b, c, W(47)); /* 48 */ - HH(c, d, e, a, b, W(48)); /* 49 */ - HH(b, c, d, e, a, W(49)); /* 50 */ - HH(a, b, c, d, e, W(50)); /* 51 */ - HH(e, a, b, c, d, W(51)); /* 52 */ - HH(d, e, a, b, c, W(52)); /* 53 */ - HH(c, d, e, a, b, W(53)); /* 54 */ - HH(b, c, d, e, a, W(54)); /* 55 */ - HH(a, b, c, d, e, W(55)); /* 56 */ - HH(e, a, b, c, d, W(56)); /* 57 */ - HH(d, e, a, b, c, W(57)); /* 58 */ - HH(c, d, e, a, b, W(58)); /* 59 */ - HH(b, c, d, e, a, W(59)); /* 60 */ - - /* Round 4 */ - II(a, b, c, d, e, W(60)); /* 61 */ - II(e, a, b, c, d, W(61)); /* 62 */ - II(d, e, a, b, c, W(62)); /* 63 */ - II(c, d, e, a, b, W(63)); /* 64 */ - II(b, c, d, e, a, W(64)); /* 65 */ - II(a, b, c, d, e, W(65)); /* 66 */ - II(e, a, b, c, d, W(66)); /* 67 */ - II(d, e, a, b, c, W(67)); /* 68 */ - II(c, d, e, a, b, W(68)); /* 69 */ - II(b, c, d, e, a, W(69)); /* 70 */ - II(a, b, c, d, e, W(70)); /* 71 */ - II(e, a, b, c, d, W(71)); /* 72 */ - II(d, e, a, b, c, W(72)); /* 73 */ - II(c, d, e, a, b, W(73)); /* 74 */ - II(b, c, d, e, a, W(74)); /* 75 */ - II(a, b, c, d, e, W(75)); /* 76 */ - II(e, a, b, c, d, W(76)); /* 77 */ - II(d, e, a, b, c, W(77)); /* 78 */ - II(c, d, e, a, b, W(78)); /* 79 */ - II(b, c, d, e, a, W(79)); /* 80 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - /* Zeroize sensitive information. */ - memset((unsigned char*) x, 0, sizeof(x)); -} -/* }}} */ - -/* {{{ SHA1Encode - Encodes input (php_uint32) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void SHA1Encode(output, input, len) -unsigned char *output; -php_uint32 *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char) ((input[i] >> 24) & 0xff); - output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); - output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); - output[j + 3] = (unsigned char) (input[i] & 0xff); - } -} -/* }}} */ - -/* {{{ SHA1Decode - Decodes input (unsigned char) into output (php_uint32). Assumes len is - a multiple of 4. - */ -static void SHA1Decode(output, input, len) -php_uint32 *output; -const unsigned char *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((php_uint32) input[j + 3]) | (((php_uint32) input[j + 2]) << 8) | - (((php_uint32) input[j + 1]) << 16) | (((php_uint32) input[j]) << 24); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/sha1.h b/ext/standard/sha1.h deleted file mode 100644 index 73711bb7c8..0000000000 --- a/ext/standard/sha1.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stefan Esser <sesser@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef SHA1_H -#define SHA1_H - -#include "ext/standard/basic_functions.h" - -/* SHA1 context. */ -typedef struct { - php_uint32 state[5]; /* state (ABCD) */ - php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} PHP_SHA1_CTX; - -PHPAPI void PHP_SHA1Init(PHP_SHA1_CTX *); -PHPAPI void PHP_SHA1Update(PHP_SHA1_CTX *, const unsigned char *, unsigned int); -PHPAPI void PHP_SHA1Final(unsigned char[20], PHP_SHA1_CTX *); - -PHP_FUNCTION(sha1); -PHP_FUNCTION(sha1_file); - -#endif diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c deleted file mode 100644 index 7dc86b066f..0000000000 --- a/ext/standard/soundex.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include <stdlib.h> -#include <errno.h> -#include <ctype.h> -#include "php_string.h" - -/* Simple soundex algorithm as described by Knuth in TAOCP, vol 3 */ -/* {{{ proto string soundex(string str) - Calculate the soundex key of a string */ -PHP_FUNCTION(soundex) -{ - char *str; - int i, _small, str_len, code, last; - char soundex[4 + 1]; - - static char soundex_table[26] = - {0, /* A */ - '1', /* B */ - '2', /* C */ - '3', /* D */ - 0, /* E */ - '1', /* F */ - '2', /* G */ - 0, /* H */ - 0, /* I */ - '2', /* J */ - '2', /* K */ - '4', /* L */ - '5', /* M */ - '5', /* N */ - 0, /* O */ - '1', /* P */ - '2', /* Q */ - '6', /* R */ - '2', /* S */ - '3', /* T */ - 0, /* U */ - '1', /* V */ - 0, /* W */ - '2', /* X */ - 0, /* Y */ - '2'}; /* Z */ - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } - if (str_len == 0) { - RETURN_FALSE; - } - - /* build soundex string */ - last = -1; - for (i = 0, _small = 0; i < str_len && _small < 4; i++) { - /* convert chars to upper case and strip non-letter chars */ - /* BUG: should also map here accented letters used in non */ - /* English words or names (also found in English text!): */ - /* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */ - code = toupper(str[i]); - if (code >= 'A' && code <= 'Z') { - if (_small == 0) { - /* remember first valid char */ - soundex[_small++] = code; - last = soundex_table[code - 'A']; - } - else { - /* ignore sequences of consonants with same soundex */ - /* code in trail, and vowels unless they separate */ - /* consonant letters */ - code = soundex_table[code - 'A']; - if (code != last) { - if (code != 0) { - soundex[_small++] = code; - } - last = code; - } - } - } - } - /* pad with '0' and terminate with 0 ;-) */ - while (_small < 4) { - soundex[_small++] = '0'; - } - soundex[_small] = '\0'; - - RETURN_STRINGL(soundex, _small, 1); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/string.c b/ext/standard/string.c deleted file mode 100644 index e21cf53f06..0000000000 --- a/ext/standard/string.c +++ /dev/null @@ -1,4421 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@php.net> | - | Stig Sæther Bakken <ssb@fast.no> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ - -#include <stdio.h> -#include "php.h" -#include "reg.h" -#include "php_rand.h" -#include "php_string.h" -#include "php_variables.h" -#ifdef HAVE_LOCALE_H -# include <locale.h> -#endif -#ifdef HAVE_LANGINFO_H -# include <langinfo.h> -#endif -#ifdef HAVE_MONETARY_H -# include <monetary.h> -#endif - -#include <math.h> - -#include "scanf.h" -#include "zend_API.h" -#include "zend_execute.h" -#include "php_globals.h" -#include "basic_functions.h" -#include "php_smart_str.h" -#ifdef ZTS -#include "TSRM.h" -#endif - -#define STR_PAD_LEFT 0 -#define STR_PAD_RIGHT 1 -#define STR_PAD_BOTH 2 -#define PHP_PATHINFO_DIRNAME 1 -#define PHP_PATHINFO_BASENAME 2 -#define PHP_PATHINFO_EXTENSION 4 -#define PHP_PATHINFO_ALL (PHP_PATHINFO_DIRNAME | PHP_PATHINFO_BASENAME | PHP_PATHINFO_EXTENSION) - -#define STR_STRSPN 0 -#define STR_STRCSPN 1 - -/* {{{ register_string_constants - */ -void register_string_constants(INIT_FUNC_ARGS) -{ - REGISTER_LONG_CONSTANT("STR_PAD_LEFT", STR_PAD_LEFT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", STR_PAD_RIGHT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STR_PAD_BOTH", STR_PAD_BOTH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PATHINFO_DIRNAME", PHP_PATHINFO_DIRNAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT); - -#ifdef HAVE_LOCALECONV - /* If last members of struct lconv equal CHAR_MAX, no grouping is done */ - -/* This is bad, but since we are going to be hardcoding in the POSIX stuff anyway... */ -# ifndef HAVE_LIMITS_H -# define CHAR_MAX 127 -# endif - - REGISTER_LONG_CONSTANT("CHAR_MAX", CHAR_MAX, CONST_CS | CONST_PERSISTENT); -#endif - -#ifdef HAVE_LOCALE_H - REGISTER_LONG_CONSTANT("LC_CTYPE", LC_CTYPE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LC_NUMERIC", LC_NUMERIC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LC_TIME", LC_TIME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LC_COLLATE", LC_COLLATE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LC_MONETARY", LC_MONETARY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LC_ALL", LC_ALL, CONST_CS | CONST_PERSISTENT); -# ifdef LC_MESSAGES - REGISTER_LONG_CONSTANT("LC_MESSAGES", LC_MESSAGES, CONST_CS | CONST_PERSISTENT); -# endif -#endif - -} -/* }}} */ - -int php_tag_find(char *tag, int len, char *set); - -/* this is read-only, so it's ok */ -static char hexconvtab[] = "0123456789abcdef"; - -/* localeconv mutex */ -#ifdef ZTS -static MUTEX_T locale_mutex = NULL; -#endif - -/* {{{ php_bin2hex - */ -static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *newlen) -{ - register unsigned char *result = NULL; - size_t i, j; - - result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1); - - for (i = j = 0; i < oldlen; i++) { - result[j++] = hexconvtab[old[i] >> 4]; - result[j++] = hexconvtab[old[i] & 15]; - } - result[j] = '\0'; - - if (newlen) - *newlen = oldlen * 2 * sizeof(char); - - return result; -} -/* }}} */ - -#ifdef HAVE_LOCALECONV -/* {{{ localeconv_r - * glibc's localeconv is not reentrant, so lets make it so ... sorta */ -struct lconv *localeconv_r(struct lconv *out) -{ - struct lconv *res; - -# ifdef ZTS - tsrm_mutex_lock( locale_mutex ); -# endif - - /* localeconv doesn't return an error condition */ - res = localeconv(); - - *out = *res; - -# ifdef ZTS - tsrm_mutex_unlock( locale_mutex ); -# endif - - return out; -} -/* }}} */ - -# ifdef ZTS -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(localeconv) -{ - locale_mutex = tsrm_mutex_alloc(); - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION - */ -PHP_MSHUTDOWN_FUNCTION(localeconv) -{ - tsrm_mutex_free( locale_mutex ); - locale_mutex = NULL; - return SUCCESS; -} -/* }}} */ -# endif -#endif - -/* {{{ proto string bin2hex(string data) - Converts the binary representation of data to hex */ -PHP_FUNCTION(bin2hex) -{ - zval **data; - char *result; - size_t newlen; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(data); - - result = php_bin2hex(Z_STRVAL_PP(data), Z_STRLEN_PP(data), &newlen); - - if (!result) { - RETURN_FALSE; - } - - RETURN_STRINGL(result, newlen, 0); -} -/* }}} */ - -static void php_spn_common_handler(INTERNAL_FUNCTION_PARAMETERS, int behavior) -{ - char *s11, *s22; - int len1, len2, start, len; - - start = 0; - len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|ll", &s11, &len1, - &s22, &len2, &start, &len) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() < 4) { - len = len1; - } - - /* look at substr() function for more information */ - - if (start < 0) { - start += len1; - if (start < 0) { - start = 0; - } - } else if (start > len1) { - RETURN_FALSE; - } - - if (len < 0) { - len += (len1 - start); - if (len < 0) { - len = 0; - } - } - - if ((start + len) > len1) { - len = len1 - start; - } - - if (behavior == STR_STRSPN) { - RETURN_LONG(php_strspn(s11 + start /*str1_start*/, - s22 /*str2_start*/, - s11 + start + len /*str1_end*/, - s22 + len2 /*str2_end*/)); - } else if (behavior == STR_STRCSPN) { - RETURN_LONG(php_strcspn(s11 + start /*str1_start*/, - s22 /*str2_start*/, - s11 + start + len /*str1_end*/, - s22 + len2 /*str2_end*/)); - } - -} - -/* {{{ proto int strspn(string str, string mask [, start [, len]]) - Finds length of initial segment consisting entirely of characters found in mask. If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars) */ -PHP_FUNCTION(strspn) -{ - php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRSPN); -} -/* }}} */ - -/* {{{ proto int strcspn(string str, string mask [, start [, len]]) - Finds length of initial segment consisting entirely of characters not found in mask. If start or/and length is provide works like strcspn(substr($s,$start,$len),$bad_chars) */ -PHP_FUNCTION(strcspn) -{ - php_spn_common_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, STR_STRCSPN); -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(nl_langinfo) */ -#if HAVE_NL_LANGINFO -PHP_MINIT_FUNCTION(nl_langinfo) -{ -#define REGISTER_NL_LANGINFO_CONSTANT(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT) -#ifdef ABDAY_1 - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6); - REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7); -#endif -#ifdef DAY_1 - REGISTER_NL_LANGINFO_CONSTANT(DAY_1); - REGISTER_NL_LANGINFO_CONSTANT(DAY_2); - REGISTER_NL_LANGINFO_CONSTANT(DAY_3); - REGISTER_NL_LANGINFO_CONSTANT(DAY_4); - REGISTER_NL_LANGINFO_CONSTANT(DAY_5); - REGISTER_NL_LANGINFO_CONSTANT(DAY_6); - REGISTER_NL_LANGINFO_CONSTANT(DAY_7); -#endif -#ifdef ABMON_1 - REGISTER_NL_LANGINFO_CONSTANT(ABMON_1); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_2); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_3); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_4); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_5); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_6); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_7); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_8); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_9); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_10); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_11); - REGISTER_NL_LANGINFO_CONSTANT(ABMON_12); -#endif -#ifdef MON_1 - REGISTER_NL_LANGINFO_CONSTANT(MON_1); - REGISTER_NL_LANGINFO_CONSTANT(MON_2); - REGISTER_NL_LANGINFO_CONSTANT(MON_3); - REGISTER_NL_LANGINFO_CONSTANT(MON_4); - REGISTER_NL_LANGINFO_CONSTANT(MON_5); - REGISTER_NL_LANGINFO_CONSTANT(MON_6); - REGISTER_NL_LANGINFO_CONSTANT(MON_7); - REGISTER_NL_LANGINFO_CONSTANT(MON_8); - REGISTER_NL_LANGINFO_CONSTANT(MON_9); - REGISTER_NL_LANGINFO_CONSTANT(MON_10); - REGISTER_NL_LANGINFO_CONSTANT(MON_11); - REGISTER_NL_LANGINFO_CONSTANT(MON_12); -#endif -#ifdef AM_STR - REGISTER_NL_LANGINFO_CONSTANT(AM_STR); -#endif -#ifdef PM_STR - REGISTER_NL_LANGINFO_CONSTANT(PM_STR); -#endif -#ifdef D_T_FMT - REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT); -#endif -#ifdef D_FMT - REGISTER_NL_LANGINFO_CONSTANT(D_FMT); -#endif -#ifdef T_FMT - REGISTER_NL_LANGINFO_CONSTANT(T_FMT); -#endif -#ifdef T_FMT_AMPM - REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM); -#endif -#ifdef ERA - REGISTER_NL_LANGINFO_CONSTANT(ERA); -#endif -#ifdef ERA_YEAR - REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR); -#endif -#ifdef ERA_D_T_FMT - REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT); -#endif -#ifdef ERA_D_FMT - REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT); -#endif -#ifdef ERA_T_FMT - REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT); -#endif -#ifdef ALT_DIGITS - REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS); -#endif -#ifdef INT_CURR_SYMBOL - REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL); -#endif -#ifdef CURRENCY_SYMBOL - REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL); -#endif -#ifdef CRNCYSTR - REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR); -#endif -#ifdef MON_DECIMAL_POINT - REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT); -#endif -#ifdef MON_THOUSANDS_SEP - REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP); -#endif -#ifdef MON_GROUPING - REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING); -#endif -#ifdef POSITIVE_SIGN - REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN); -#endif -#ifdef NEGATIVE_SIGN - REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN); -#endif -#ifdef INT_FRAC_DIGITS - REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS); -#endif -#ifdef FRAC_DIGITS - REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS); -#endif -#ifdef P_CS_PRECEDES - REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES); -#endif -#ifdef P_SEP_BY_SPACE - REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE); -#endif -#ifdef N_CS_PRECEDES - REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES); -#endif -#ifdef N_SEP_BY_SPACE - REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE); -#endif -#ifdef P_SIGN_POSN - REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN); -#endif -#ifdef N_SIGN_POSN - REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN); -#endif -#ifdef DECIMAL_POINT - REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT); -#endif -#ifdef RADIXCHAR - REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR); -#endif -#ifdef THOUSANDS_SEP - REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP); -#endif -#ifdef THOUSEP - REGISTER_NL_LANGINFO_CONSTANT(THOUSEP); -#endif -#ifdef GROUPING - REGISTER_NL_LANGINFO_CONSTANT(GROUPING); -#endif -#ifdef YESEXPR - REGISTER_NL_LANGINFO_CONSTANT(YESEXPR); -#endif -#ifdef NOEXPR - REGISTER_NL_LANGINFO_CONSTANT(NOEXPR); -#endif -#ifdef YESSTR - REGISTER_NL_LANGINFO_CONSTANT(YESSTR); -#endif -#ifdef NOSTR - REGISTER_NL_LANGINFO_CONSTANT(NOSTR); -#endif -#ifdef CODESET - REGISTER_NL_LANGINFO_CONSTANT(CODESET); -#endif -#undef REGISTER_NL_LANGINFO_CONSTANT - return SUCCESS; -} -/* }}} */ - -/* {{{ proto string nl_langinfo(int item) - Query language and locale information */ -PHP_FUNCTION(nl_langinfo) -{ - zval **item; - char *value; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &item) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(item); - - value = nl_langinfo(Z_LVAL_PP(item)); - if (value == NULL) { - RETURN_FALSE; - } else { - RETURN_STRING(value, 1); - } -} -#endif -/* }}} */ - -#ifdef HAVE_STRCOLL -/* {{{ proto int strcoll(string str1, string str2) - Compares two strings using the current locale */ -PHP_FUNCTION(strcoll) -{ - zval **s1, **s2; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - - RETURN_LONG(strcoll((const char *) Z_STRVAL_PP(s1), - (const char *) Z_STRVAL_PP(s2))); -} -/* }}} */ -#endif - -/* {{{ php_charmask - * Fills a 256-byte bytemask with input. You can specify a range like 'a..z', - * it needs to be incrementing. - * Returns: FAILURE/SUCCESS wether the input was correct (i.e. no range errors) - */ -static inline int php_charmask(unsigned char *input, int len, char *mask TSRMLS_DC) -{ - unsigned char *end; - unsigned char c; - int result = SUCCESS; - - memset(mask, 0, 256); - for (end = input+len; input < end; input++) { - c=*input; - if ((input+3 < end) && input[1] == '.' && input[2] == '.' - && input[3] >= c) { - memset(mask+c, 1, input[3] - c + 1); - input+=3; - } else if ((input+1 < end) && input[0] == '.' && input[1] == '.') { - /* Error, try to be as helpful as possible: - (a range ending/starting with '.' won't be captured here) */ - if (end-len >= input) { /* there was no 'left' char */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range, no character to the left of '..'."); - result = FAILURE; - continue; - } - if (input+2 >= end) { /* there is no 'right' char */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range, no character to the right of '..'."); - result = FAILURE; - continue; - } - if (input[-1] > input[2]) { /* wrong order */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range, '..'-range needs to be incrementing."); - result = FAILURE; - continue; - } - /* FIXME: better error (a..b..c is the only left possibility?) */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range."); - result = FAILURE; - continue; - } else { - mask[c]=1; - } - } - return result; -} -/* }}} */ - -/* {{{ php_trim() - * mode 1 : trim left - * mode 2 : trim right - * mode 3 : trim left and right - * what indicates which chars are to be trimmed. NULL->default (' \t\n\r\v\0') - */ -PHPAPI char *php_trim(char *c, int len, char *what, int what_len, zval *return_value, int mode TSRMLS_DC) -{ - register int i; - int trimmed = 0; - char mask[256]; - - if (what) { - php_charmask(what, what_len, mask TSRMLS_CC); - } else { - php_charmask(" \n\r\t\v\0", 6, mask TSRMLS_CC); - } - - if (mode & 1) { - for (i = 0; i < len; i++) { - if (mask[(unsigned char)c[i]]) { - trimmed++; - } else { - break; - } - } - len -= trimmed; - c += trimmed; - } - if (mode & 2) { - for (i = len - 1; i >= 0; i--) { - if (mask[(unsigned char)c[i]]) { - len--; - } else { - break; - } - } - } - - if (return_value) { - RETVAL_STRINGL(c, len, 1); - } else { - return estrndup(c, len); - } - return ""; -} -/* }}} */ - -/* {{{ php_do_trim - * Base for trim(), rtrim() and ltrim() functions. - */ -static void php_do_trim(INTERNAL_FUNCTION_PARAMETERS, int mode) -{ - zval **str; - zval **what = NULL; - int argc = ZEND_NUM_ARGS(); - - if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &str, &what) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - - if (argc > 1) { - convert_to_string_ex(what); - php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str), Z_STRVAL_PP(what), Z_STRLEN_PP(what), return_value, mode TSRMLS_CC); - } else { - php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str), NULL, 0, return_value, mode TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto string trim(string str [, string character_mask]) - Strips whitespace from the beginning and end of a string */ -PHP_FUNCTION(trim) -{ - php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3); -} -/* }}} */ - -/* {{{ proto string rtrim(string str [, string character_mask]) - Removes trailing whitespace */ -PHP_FUNCTION(rtrim) -{ - php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2); -} -/* }}} */ - -/* {{{ proto string ltrim(string str [, string character_mask]) - Strips whitespace from the beginning of a string */ -PHP_FUNCTION(ltrim) -{ - php_do_trim(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto string wordwrap(string str [, int width [, string break [, int cut]]]) - Wraps buffer to selected number of characters using string break char */ -PHP_FUNCTION(wordwrap) -{ - const char *text, *breakchar = "\n"; - char *newtext; - int textlen, breakcharlen = 1, newtextlen, alloced, chk; - long current = 0, laststart = 0, lastspace = 0; - long linelength = 75; - zend_bool docut = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lsb", &text, &textlen, &linelength, &breakchar, &breakcharlen, &docut) == FAILURE) { - return; - } - - if (textlen == 0) - RETURN_FALSE; - - if (linelength == 0 && docut) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't force cut when width is zero."); - RETURN_FALSE; - } - - /* Special case for a single-character break as it needs no - additional storage space */ - if (breakcharlen == 1 && !docut) { - newtext = estrndup(text, textlen); - - laststart = lastspace = 0; - for (current = 0; current < textlen; current++) { - if (text[current] == breakchar[0]) { - laststart = lastspace = current; - } else if (text[current] == ' ') { - if (current - laststart >= linelength) { - newtext[current] = breakchar[0]; - laststart = current; - } - lastspace = current; - } else if (current - laststart >= linelength && laststart != lastspace) { - newtext[lastspace] = breakchar[0]; - laststart = lastspace; - } - } - - RETURN_STRINGL(newtext, textlen, 0); - } else { - /* Multiple character line break or forced cut */ - if (linelength > 0) { - chk = (int)(textlen/linelength + 1); - alloced = textlen + chk * breakcharlen + 1; - } else { - chk = textlen; - alloced = textlen * (breakcharlen + 1) + 1; - } - newtext = emalloc(alloced); - - /* now keep track of the actual new text length */ - newtextlen = 0; - - laststart = lastspace = 0; - for (current = 0; current < textlen; current++) { - if (chk <= 0) { - alloced += (int) (((textlen - current + 1)/linelength + 1) * breakcharlen) + 1; - newtext = erealloc(newtext, alloced); - chk = (int) ((textlen - current)/linelength) + 1; - } - /* when we hit an existing break, copy to new buffer, and - * fix up laststart and lastspace */ - if (text[current] == breakchar[0] - && current + breakcharlen < textlen - && !strncmp(text+current, breakchar, breakcharlen)) { - memcpy(newtext+newtextlen, text+laststart, current-laststart+breakcharlen); - newtextlen += current-laststart+breakcharlen; - current += breakcharlen - 1; - laststart = lastspace = current + 1; - chk--; - } - /* if it is a space, check if it is at the line boundary, - * copy and insert a break, or just keep track of it */ - else if (text[current] == ' ') { - if (current - laststart >= linelength) { - memcpy(newtext+newtextlen, text+laststart, current-laststart); - newtextlen += current - laststart; - memcpy(newtext+newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; - laststart = current + 1; - chk--; - } - lastspace = current; - } - /* if we are cutting, and we've accumulated enough - * characters, and we haven't see a space for this line, - * copy and insert a break. */ - else if (current - laststart >= linelength - && docut && laststart >= lastspace) { - memcpy(newtext+newtextlen, text+laststart, current-laststart); - newtextlen += current - laststart; - memcpy(newtext+newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; - laststart = lastspace = current; - chk--; - } - /* if the current word puts us over the linelength, copy - * back up until the last space, insert a break, and move - * up the laststart */ - else if (current - laststart >= linelength - && laststart < lastspace) { - memcpy(newtext+newtextlen, text+laststart, lastspace-laststart); - newtextlen += lastspace - laststart; - memcpy(newtext+newtextlen, breakchar, breakcharlen); - newtextlen += breakcharlen; - laststart = lastspace = lastspace + 1; - chk--; - } - } - - /* copy over any stragglers */ - if (laststart != current) { - memcpy(newtext+newtextlen, text+laststart, current-laststart); - newtextlen += current - laststart; - } - - newtext[newtextlen] = '\0'; - /* free unused memory */ - newtext = erealloc(newtext, newtextlen+1); - - RETURN_STRINGL(newtext, newtextlen, 0); - } -} -/* }}} */ - -/* {{{ php_explode - */ -PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit) -{ - char *p1, *p2, *endp; - - endp = Z_STRVAL_P(str) + Z_STRLEN_P(str); - - p1 = Z_STRVAL_P(str); - p2 = php_memnstr(Z_STRVAL_P(str), Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp); - - if (p2 == NULL) { - add_next_index_stringl(return_value, p1, Z_STRLEN_P(str), 1); - } else { - do { - add_next_index_stringl(return_value, p1, p2 - p1, 1); - p1 = p2 + Z_STRLEN_P(delim); - } while ((p2 = php_memnstr(p1, Z_STRVAL_P(delim), Z_STRLEN_P(delim), endp)) != NULL && - (limit == -1 || --limit > 1)); - - if (p1 <= endp) - add_next_index_stringl(return_value, p1, endp-p1, 1); - } -} -/* }}} */ - -/* {{{ proto array explode(string separator, string str [, int limit]) - Splits a string on string separator and return array of components */ -PHP_FUNCTION(explode) -{ - zval **str, **delim, **zlimit = NULL; - int limit = -1; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &delim, &str, &zlimit) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - convert_to_string_ex(delim); - - if (argc > 2) { - convert_to_long_ex(zlimit); - limit = Z_LVAL_PP(zlimit); - } - - if (! Z_STRLEN_PP(delim)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); - RETURN_FALSE; - } - - array_init(return_value); - - if (limit == 0 || limit == 1) { - add_index_stringl(return_value, 0, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - } else { - php_explode(*delim, *str, return_value, limit); - } -} -/* }}} */ - -/* {{{ proto string join(array src, string glue) - An alias for implode */ -/* }}} */ - -/* {{{ php_implode - */ -PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value) -{ - zval **tmp; - HashPosition pos; - smart_str implstr = {0}; - int numelems, i = 0; - - numelems = zend_hash_num_elements(Z_ARRVAL_P(arr)); - - if (numelems == 0) { - RETURN_EMPTY_STRING(); - } - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos); - - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, &pos) == SUCCESS) { - SEPARATE_ZVAL(tmp); - convert_to_string(*tmp); - - smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp)); - if (++i != numelems) { - smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim)); - } - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); - } - smart_str_0(&implstr); - - RETURN_STRINGL(implstr.c, implstr.len, 0); -} -/* }}} */ - -/* {{{ proto string implode([string glue,] array pieces) - Joins array elements placing glue string between items and return one string */ -PHP_FUNCTION(implode) -{ - zval **arg1 = NULL, **arg2 = NULL, *delim, *arr; - int argc = ZEND_NUM_ARGS(); - int arg1_separated = 0, arg2_separated = 0, delim_needs_dtor = 0; - - if (argc < 1 || argc > 2 || - zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (argc == 1) { - if (Z_TYPE_PP(arg1) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument to implode must be an array."); - return; - } - - MAKE_STD_ZVAL(delim); -#define _IMPL_EMPTY "" - ZVAL_STRINGL(delim, _IMPL_EMPTY, sizeof(_IMPL_EMPTY) - 1, 0); - - SEPARATE_ZVAL(arg1); - arg1_separated = 1; - delim_needs_dtor = 1; - arr = *arg1; - } else { - if (Z_TYPE_PP(arg1) == IS_ARRAY) { - SEPARATE_ZVAL(arg1); - arg1_separated = 1; - arr = *arg1; - convert_to_string_ex(arg2); - delim = *arg2; - } else if (Z_TYPE_PP(arg2) == IS_ARRAY) { - SEPARATE_ZVAL(arg2); - arg2_separated = 1; - arr = *arg2; - convert_to_string_ex(arg1); - delim = *arg1; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad arguments."); - return; - } - } - - php_implode(delim, arr, return_value); - - if (arg1 != NULL && arg1_separated) { - zval_ptr_dtor(arg1); - } - if (arg2 != NULL && arg2_separated) { - zval_ptr_dtor(arg2); - } - if (delim_needs_dtor) { - FREE_ZVAL(delim); - } -} -/* }}} */ - -#define STRTOK_TABLE(p) BG(strtok_table)[(unsigned char) *p] - -/* {{{ proto string strtok([string str,] string token) - Tokenize a string */ -PHP_FUNCTION(strtok) -{ - zval **args[2]; - zval **tok, **str; - char *token; - char *token_end; - char *p; - char *pe; - int skipped = 0; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (ZEND_NUM_ARGS()) { - case 1: - tok = args[0]; - break; - - default: - case 2: - str = args[0]; - tok = args[1]; - convert_to_string_ex(str); - - zval_add_ref(str); - if (BG(strtok_zval)) { - zval_ptr_dtor(&BG(strtok_zval)); - } - BG(strtok_zval) = *str; - BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str); - BG(strtok_len) = Z_STRLEN_PP(str); - break; - } - - p = BG(strtok_last); /* Where we start to search */ - pe = BG(strtok_string) + BG(strtok_len); - - if (!p || p >= pe) { - RETURN_FALSE; - } - - convert_to_string_ex(tok); - - token = Z_STRVAL_PP(tok); - token_end = token + Z_STRLEN_PP(tok); - - while (token < token_end) { - STRTOK_TABLE(token++) = 1; - } - - /* Skip leading delimiters */ - while (STRTOK_TABLE(p)) { - if (++p >= pe) { - /* no other chars left */ - BG(strtok_last) = NULL; - RETVAL_FALSE; - goto restore; - } - skipped++; - } - - /* We know at this place that *p is no delimiter, so skip it */ - while (++p < pe) { - if (STRTOK_TABLE(p)) { - goto return_token; - } - } - - if (p - BG(strtok_last)) { -return_token: - RETVAL_STRINGL(BG(strtok_last) + skipped, (p - BG(strtok_last)) - skipped, 1); - BG(strtok_last) = p + 1; - } else { - RETVAL_FALSE; - BG(strtok_last) = NULL; - } - - /* Restore table -- usually faster then memset'ing the table on every invocation */ -restore: - token = Z_STRVAL_PP(tok); - - while (token < token_end) { - STRTOK_TABLE(token++) = 0; - } -} -/* }}} */ - -/* {{{ php_strtoupper - */ -PHPAPI char *php_strtoupper(char *s, size_t len) -{ - unsigned char *c, *e; - - c = s; - e = c+len; - - while (c < e) { - *c = toupper(*c); - c++; - } - return s; -} -/* }}} */ - -/* {{{ proto string strtoupper(string str) - Makes a string uppercase */ -PHP_FUNCTION(strtoupper) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - *return_value = **arg; - zval_copy_ctor(return_value); - php_strtoupper(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value)); -} -/* }}} */ - -/* {{{ php_strtolower - */ -PHPAPI char *php_strtolower(char *s, size_t len) -{ - unsigned char *c, *e; - - c = s; - e = c+len; - - while (c < e) { - *c = tolower(*c); - c++; - } - return s; -} -/* }}} */ - -/* {{{ proto string strtolower(string str) - Makes a string lowercase */ -PHP_FUNCTION(strtolower) -{ - zval **str; - char *ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - *return_value = **str; - zval_copy_ctor(return_value); - ret = php_strtolower(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value)); -} -/* }}} */ - -/* {{{ php_basename - */ -PHPAPI char *php_basename(char *s, size_t len, char *suffix, size_t sufflen) -{ - char *ret=NULL, *c, *p=NULL, buf='\0', *p2=NULL, buf2='\0'; - c = s + len - 1; - - /* do suffix removal as the unix command does */ - if (suffix && (len > sufflen)) { - if (!strncmp(suffix, c-sufflen+1, sufflen)) { - c -= sufflen; - buf2 = *(c + 1); /* Save overwritten char */ - *(c + 1) = '\0'; /* overwrite char */ - p2 = c + 1; /* Save pointer to overwritten char */ - } - } - - /* strip trailing slashes */ - while (*c == '/' -#ifdef PHP_WIN32 - || (*c == '\\' && !IsDBCSLeadByte(*(c-1))) -#endif - ) { - c--; - } - - if (c < s+len-1) { - buf = *(c + 1); /* Save overwritten char */ - *(c + 1) = '\0'; /* overwrite char */ - p = c + 1; /* Save pointer to overwritten char */ - } - - if ((c = strrchr(s, '/')) -#ifdef PHP_WIN32 - || ((c = strrchr(s, '\\')) && !IsDBCSLeadByte(*(c-1))) -#endif - ) { - ret = estrdup(c + 1); - } else { - ret = estrdup(s); - } - if (buf) { - *p = buf; - } - if (buf2) { - *p2 = buf2; - } - return (ret); -} -/* }}} */ - -/* {{{ proto string basename(string path [, string suffix]) - Returns the filename component of the path */ -PHP_FUNCTION(basename) -{ - char *ret; - char *string, *suffix = NULL; - int string_len, suffix_len = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &string, &string_len, &suffix, &suffix_len) == FAILURE) { - return; - } - - ret = php_basename(string, string_len, suffix, suffix_len); - RETURN_STRING(ret, 0); -} -/* }}} */ - -/* {{{ php_dirname - Returns directory name component of path */ -PHPAPI void php_dirname(char *path, int len) -{ - register char *end = path + len - 1; - -#ifdef PHP_WIN32 - /* Note that on Win32 CWD is per drive (heritage from CP/M). - * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive. - */ - if ((2 <= len) && isalpha(path[0]) && (':' == path[1])) { - /* Skip over the drive spec (if any) so as not to change */ - path += 2; - if (2 == len) { - /* Return "c:" on Win32 for dirname("c:"). - * It would be more consistent to return "c:." - * but that would require making the string *longer*. - */ - return; - } - } -#endif - - if (len <= 0) { - /* Illegal use of this function */ - return; - } - - /* Strip trailing slashes */ - while (end >= path && IS_SLASH_P(end)) { - end--; - } - if (end < path) { - /* The path only contained slashes */ - path[0] = DEFAULT_SLASH; - path[1] = '\0'; - return; - } - - /* Strip filename */ - while (end >= path && !IS_SLASH_P(end)) { - end--; - } - if (end < path) { - /* No slash found, therefore return '.' */ - path[0] = '.'; - path[1] = '\0'; - return; - } - - /* Strip slashes which came before the file name */ - while (end >= path && IS_SLASH_P(end)) { - end--; - } - if (end < path) { - path[0] = DEFAULT_SLASH; - path[1] = '\0'; - return; - } - *(end+1) = '\0'; -} -/* }}} */ - -/* {{{ proto string dirname(string path) - Returns the directory name component of the path */ -PHP_FUNCTION(dirname) -{ - zval **str; - char *ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - ret = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); - php_dirname(ret, Z_STRLEN_PP(str)); - - RETURN_STRING(ret, 0); -} -/* }}} */ - -/* {{{ proto array pathinfo(string path) - Returns information about a certain string */ -PHP_FUNCTION(pathinfo) -{ - zval *tmp; - char *path, *ret = NULL; - int path_len; - int opt = PHP_PATHINFO_ALL; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &path_len, &opt) == FAILURE) { - return; - } - - MAKE_STD_ZVAL(tmp); - array_init(tmp); - - if ((opt & PHP_PATHINFO_DIRNAME) == PHP_PATHINFO_DIRNAME) { - ret = estrndup(path, path_len); - php_dirname(ret, path_len); - if (*ret) { - add_assoc_string(tmp, "dirname", ret, 1); - } - efree(ret); - } - - if ((opt & PHP_PATHINFO_BASENAME) == PHP_PATHINFO_BASENAME) { - ret = php_basename(path, path_len, NULL, 0); - add_assoc_string(tmp, "basename", ret, 0); - } - - if ((opt & PHP_PATHINFO_EXTENSION) == PHP_PATHINFO_EXTENSION) { - char *p; - int idx; - int ret_len; - int have_basename = ((opt & PHP_PATHINFO_BASENAME) == PHP_PATHINFO_BASENAME); - - /* Have we alrady looked up the basename? */ - if (!have_basename) { - ret = php_basename(path, path_len, NULL, 0); - } - - ret_len = strlen(ret); - - p = strrchr(ret, '.'); - - if (p) { - idx = p - ret; - add_assoc_stringl(tmp, "extension", ret + idx + 1, ret_len - idx - 1, 1); - } - - if (!have_basename) { - efree(ret); - } - } - - if (opt == PHP_PATHINFO_ALL) { - *return_value = *tmp; - } else { - zval **element; - if (zend_hash_get_current_data(Z_ARRVAL_P(tmp), (void **) &element) == SUCCESS) { - *return_value = **element; - } else { - ZVAL_EMPTY_STRING(return_value); - } - } - - zval_copy_ctor(return_value); - zval_dtor(tmp); - efree(tmp); -} -/* }}} */ - -/* {{{ php_stristr - case insensitve strstr */ -PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t t_len) -{ - php_strtolower(s, s_len); - php_strtolower(t, t_len); - return php_memnstr(s, t, t_len, s + s_len); -} -/* }}} */ - -/* {{{ php_strspn - */ -PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end) -{ - register const char *p = s1, *spanp; - register char c = *p; - -cont: - for (spanp = s2; p != s1_end && spanp != s2_end;) { - if (*spanp++ == c) { - c = *(++p); - goto cont; - } - } - return (p - s1); -} -/* }}} */ - -/* {{{ php_strcspn - */ -PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end) -{ - register const char *p, *spanp; - register char c = *s1; - - for (p = s1;;) { - spanp = s2; - do { - if (*spanp == c || p == s1_end) { - return p - s1; - } - } while (spanp++ < s2_end); - c = *++p; - } - /* NOTREACHED */ -} -/* }}} */ - -/* {{{ proto string stristr(string haystack, string needle) - Finds first occurrence of a string within another, case insensitive */ -PHP_FUNCTION(stristr) -{ - zval **haystack, **needle; - char *found = NULL; - int found_offset; - char *haystack_orig; - char needle_char[2]; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - - SEPARATE_ZVAL(haystack); - SEPARATE_ZVAL(needle); - - convert_to_string_ex(haystack); - - haystack_orig = estrndup(Z_STRVAL_PP(haystack), Z_STRLEN_PP(haystack)); - - if (Z_TYPE_PP(needle) == IS_STRING) { - if (!Z_STRLEN_PP(needle)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); - efree(haystack_orig); - zval_ptr_dtor(haystack); - zval_ptr_dtor(needle); - RETURN_FALSE; - } - - found = php_stristr(Z_STRVAL_PP(haystack), - Z_STRVAL_PP(needle), - Z_STRLEN_PP(haystack), - Z_STRLEN_PP(needle)); - } else { - convert_to_long_ex(needle); - needle_char[0] = (char) Z_LVAL_PP(needle); - needle_char[1] = 0; - - found = php_stristr(Z_STRVAL_PP(haystack), - needle_char, - Z_STRLEN_PP(haystack), - 1); - } - - if (found) { - found_offset = found - Z_STRVAL_PP(haystack); - RETVAL_STRINGL(haystack_orig + found_offset, Z_STRLEN_PP(haystack) - found_offset, 1); - } else { - RETVAL_FALSE; - } - - zval_ptr_dtor(haystack); - zval_ptr_dtor(needle); - efree(haystack_orig); -} -/* }}} */ - -/* {{{ proto string strstr(string haystack, string needle) - Finds first occurrence of a string within another */ -PHP_FUNCTION(strstr) -{ - zval **haystack, **needle; - char *found = NULL; - char needle_char[2]; - long found_offset; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(haystack); - - if (Z_TYPE_PP(needle) == IS_STRING) { - if (!Z_STRLEN_PP(needle)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); - RETURN_FALSE; - } - - found = php_memnstr(Z_STRVAL_PP(haystack), - Z_STRVAL_PP(needle), - Z_STRLEN_PP(needle), - Z_STRVAL_PP(haystack) + Z_STRLEN_PP(haystack)); - } else { - convert_to_long_ex(needle); - needle_char[0] = (char) Z_LVAL_PP(needle); - needle_char[1] = 0; - - found = php_memnstr(Z_STRVAL_PP(haystack), - needle_char, - 1, - Z_STRVAL_PP(haystack) + Z_STRLEN_PP(haystack)); - } - - if (found) { - found_offset = found - Z_STRVAL_PP(haystack); - RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string strchr(string haystack, string needle) - An alias for strstr */ -/* }}} */ - -/* {{{ proto int strpos(string haystack, string needle [, int offset]) - Finds position of first occurrence of a string within another */ -PHP_FUNCTION(strpos) -{ - zval **haystack, **needle, **z_offset; - char *found = NULL; - char needle_char[2]; - int offset = 0; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &haystack, &needle, &z_offset) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if (argc > 2) { - convert_to_long_ex(z_offset); - offset = Z_LVAL_PP(z_offset); - } - - if (offset < 0 || offset > Z_STRLEN_PP(haystack)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string."); - RETURN_FALSE; - } - - if (Z_TYPE_PP(needle) == IS_STRING) { - if (!Z_STRLEN_PP(needle)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty delimiter."); - RETURN_FALSE; - } - - found = php_memnstr(Z_STRVAL_PP(haystack) + offset, - Z_STRVAL_PP(needle), - Z_STRLEN_PP(needle), - Z_STRVAL_PP(haystack) + Z_STRLEN_PP(haystack)); - } else { - convert_to_long_ex(needle); - needle_char[0] = (char) Z_LVAL_PP(needle); - needle_char[1] = 0; - - found = php_memnstr(Z_STRVAL_PP(haystack) + offset, - needle_char, - 1, - Z_STRVAL_PP(haystack) + Z_STRLEN_PP(haystack)); - } - - if (found) { - RETURN_LONG(found - Z_STRVAL_PP(haystack)); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int stripos(string haystack, string needle [, int offset]) - Finds position of first occurrence of a string within another, case insensitive */ -PHP_FUNCTION(stripos) -{ - char *found = NULL; - char *haystack; - int haystack_len; - long offset = 0; - char *needle_dup = NULL, *haystack_dup; - char needle_char[2]; - zval *needle; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &haystack, &haystack_len, &needle, &offset) == FAILURE) { - return; - } - - if (offset < 0 || offset > haystack_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string."); - RETURN_FALSE; - } - - haystack_dup = estrndup(haystack, haystack_len); - php_strtolower(haystack_dup, haystack_len); - - if (Z_TYPE_P(needle) == IS_STRING) { - needle_dup = estrndup(Z_STRVAL_P(needle), Z_STRLEN_P(needle)); - php_strtolower(needle_dup, Z_STRLEN_P(needle)); - found = php_memnstr(haystack_dup + offset, needle_dup, Z_STRLEN_P(needle), haystack_dup + haystack_len); - } else { - switch (Z_TYPE_P(needle)) { - case IS_LONG: - case IS_BOOL: - needle_char[0] = tolower((char) Z_LVAL_P(needle)); - break; - case IS_DOUBLE: - needle_char[0] = tolower((char) Z_DVAL_P(needle)); - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "needle is not a string or an integer."); - efree(haystack_dup); - RETURN_FALSE; - break; - - } - needle_char[1] = '\0'; - found = php_memnstr(haystack_dup + offset, - needle_char, - sizeof(needle_char) - 1, - haystack_dup + haystack_len); - } - - efree(haystack_dup); - if (needle_dup) { - efree(needle_dup); - } - - if (found) { - RETURN_LONG(found - haystack_dup); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int strrpos(string haystack, string needle [, int offset]) - Finds position of last occurrence of a character in a string within another */ -PHP_FUNCTION(strrpos) -{ - zval **haystack, **needle, **offset; - char *found = NULL; - int argc = ZEND_NUM_ARGS(); - int off = 0; - - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &haystack, &needle, &offset) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if (argc == 3) { - convert_to_long_ex(offset); - if (Z_LVAL_PP(offset) < 0 || Z_LVAL_PP(offset) > Z_STRLEN_PP(haystack)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string."); - RETURN_FALSE; - } - off = Z_LVAL_PP(offset); - } - - if (Z_TYPE_PP(needle) == IS_STRING) { - found = strrchr(Z_STRVAL_PP(haystack) + off, *Z_STRVAL_PP(needle)); - } else { - convert_to_long_ex(needle); - found = strrchr(Z_STRVAL_PP(haystack) + off, (char) Z_LVAL_PP(needle)); - } - - if (found) { - RETURN_LONG(Z_STRLEN_PP(haystack) - strlen(found)); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto int strripos(string haystack, string needle [, int offset]) - Finds position of last occurrence of a character in a string within another, case insensitive */ -PHP_FUNCTION(strripos) -{ - zval **haystack, **needle, **offset; - char *found = NULL; - int argc = ZEND_NUM_ARGS(); - int off = 0; - char *haystack_dup; - char needle_dup; - - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &haystack, &needle, &offset) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if (argc == 3) { - convert_to_long_ex(offset); - if (Z_LVAL_PP(offset) < 0 || Z_LVAL_PP(offset) > Z_STRLEN_PP(haystack)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Offset not contained in string."); - RETURN_FALSE; - } - off = Z_LVAL_PP(offset); - } - - haystack_dup = estrndup(Z_STRVAL_PP(haystack), Z_STRLEN_PP(haystack)); - php_strtolower(haystack_dup, Z_STRLEN_PP(haystack)); - - if (Z_TYPE_PP(needle) == IS_STRING) { - needle_dup = *Z_STRVAL_PP(needle); - } else { - convert_to_long_ex(needle); - needle_dup = (char) Z_LVAL_PP(needle); - } - - found = strrchr(haystack_dup + off, tolower(needle_dup)); - - efree(haystack_dup); - - if (found) { - RETURN_LONG(Z_STRLEN_PP(haystack) - strlen(found)); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string strrchr(string haystack, string needle) - Finds the last occurrence of a character in a string within another */ -PHP_FUNCTION(strrchr) -{ - zval **haystack, **needle; - char *found = NULL; - long found_offset; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if (Z_TYPE_PP(needle) == IS_STRING) { - found = strrchr(Z_STRVAL_PP(haystack), *Z_STRVAL_PP(needle)); - } else { - convert_to_long_ex(needle); - found = strrchr(Z_STRVAL_PP(haystack), (char) Z_LVAL_PP(needle)); - } - - if (found) { - found_offset = found - Z_STRVAL_PP(haystack); - RETURN_STRINGL(found, Z_STRLEN_PP(haystack) - found_offset, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ php_chunk_split - */ -static char *php_chunk_split(char *src, int srclen, char *end, int endlen, int chunklen, int *destlen) -{ - char *dest; - char *p, *q; - int chunks; /* complete chunks! */ - int restlen; - - chunks = srclen / chunklen; - restlen = srclen - chunks * chunklen; /* srclen % chunklen */ - - dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char)); - - for (p = src, q = dest; p < (src + srclen - chunklen + 1); ) { - memcpy(q, p, chunklen); - q += chunklen; - memcpy(q, end, endlen); - q += endlen; - p += chunklen; - } - - if (restlen) { - memcpy(q, p, restlen); - q += restlen; - memcpy(q, end, endlen); - q += endlen; - } - - *q = '\0'; - if (destlen) { - *destlen = q - dest; - } - - return(dest); -} -/* }}} */ - -/* {{{ proto string chunk_split(string str [, int chunklen [, string ending]]) - Returns split line */ -PHP_FUNCTION(chunk_split) -{ - zval **p_str, **p_chunklen, **p_ending; - char *result; - char *end = "\r\n"; - int endlen = 2; - int chunklen = 76; - int result_len; - int argc = ZEND_NUM_ARGS(); - - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &p_str, &p_chunklen, &p_ending) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(p_str); - - if (argc > 1) { - convert_to_long_ex(p_chunklen); - chunklen = Z_LVAL_PP(p_chunklen); - } - - if (argc > 2) { - convert_to_string_ex(p_ending); - end = Z_STRVAL_PP(p_ending); - endlen = Z_STRLEN_PP(p_ending); - } - - if (chunklen <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Chunk length should be greater than zero."); - RETURN_FALSE; - } - - if (!Z_STRLEN_PP(p_str)) { - RETURN_EMPTY_STRING(); - } - - result = php_chunk_split(Z_STRVAL_PP(p_str), Z_STRLEN_PP(p_str), end, endlen, chunklen, &result_len); - - if (result) { - RETURN_STRINGL(result, result_len, 0); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string substr(string str, int start [, int length]) - Returns part of a string */ -PHP_FUNCTION(substr) -{ - zval **str, **from, **len; - int l; - int f; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &str, &from, &len) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - convert_to_long_ex(from); - - if (argc > 2) { - convert_to_long_ex(len); - l = Z_LVAL_PP(len); - } else { - l = Z_STRLEN_PP(str); - } - - f = Z_LVAL_PP(from); - - /* if "from" position is negative, count start position from the end - * of the string - */ - if (f < 0) { - f = Z_STRLEN_PP(str) + f; - if (f < 0) { - f = 0; - } - } - - /* if "length" position is negative, set it to the length - * needed to stop that many chars from the end of the string - */ - if (l < 0) { - l = (Z_STRLEN_PP(str) - f) + l; - if (l < 0) { - l = 0; - } - } - - if (f >= Z_STRLEN_PP(str)) { - RETURN_FALSE; - } - - if ((f + l) > Z_STRLEN_PP(str)) { - l = Z_STRLEN_PP(str) - f; - } - - RETURN_STRINGL(Z_STRVAL_PP(str) + f, l, 1); -} -/* }}} */ - -/* {{{ proto string substr_replace(string str, string repl, int start [, int length]) - Replaces part of a string with another string */ -PHP_FUNCTION(substr_replace) -{ - zval **str; - zval **from; - zval **len; - zval **repl; - char *result; - int result_len; - int l; - int f; - int argc = ZEND_NUM_ARGS(); - - if (argc < 3 || argc > 4 || zend_get_parameters_ex(argc, &str, &repl, &from, &len) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - convert_to_string_ex(repl); - convert_to_long_ex(from); - - if (argc > 3) { - convert_to_long_ex(len); - l = Z_LVAL_PP(len); - } else { - l = Z_STRLEN_PP(str); - } - - f = Z_LVAL_PP(from); - - /* if "from" position is negative, count start position from the end - * of the string - */ - if (f < 0) { - f = Z_STRLEN_PP(str) + f; - if (f < 0) { - f = 0; - } - } else if (f > Z_STRLEN_PP(str)) { - f = Z_STRLEN_PP(str); - } - - - /* if "length" position is negative, set it to the length - * needed to stop that many chars from the end of the string - */ - if (l < 0) { - l = (Z_STRLEN_PP(str) - f) + l; - if (l < 0) { - l = 0; - } - } - - if ((f + l) > Z_STRLEN_PP(str)) { - l = Z_STRLEN_PP(str) - f; - } - - result_len = Z_STRLEN_PP(str) - l + Z_STRLEN_PP(repl); - result = ecalloc(result_len + 1, sizeof(char *)); - - memcpy(result, Z_STRVAL_PP(str), f); - memcpy(&result[f], Z_STRVAL_PP(repl), Z_STRLEN_PP(repl)); - memcpy(&result[f + Z_STRLEN_PP(repl)], Z_STRVAL_PP(str) + f + l, Z_STRLEN_PP(str) - f - l); - - RETURN_STRINGL(result, result_len, 0); -} -/* }}} */ - -/* {{{ proto string quotemeta(string str) - Quotes meta characters */ -PHP_FUNCTION(quotemeta) -{ - zval **arg; - char *str, *old; - char *old_end; - char *p, *q; - char c; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - old = Z_STRVAL_PP(arg); - old_end = Z_STRVAL_PP(arg) + Z_STRLEN_PP(arg); - - if (old == old_end) { - RETURN_FALSE; - } - - str = emalloc(2 * Z_STRLEN_PP(arg) + 1); - - for (p = old, q = str; p != old_end; p++) { - c = *p; - switch (c) { - case '.': - case '\\': - case '+': - case '*': - case '?': - case '[': - case '^': - case ']': - case '$': - case '(': - case ')': - *q++ = '\\'; - /* break is missing _intentionally_ */ - default: - *q++ = c; - } - } - *q = 0; - - RETURN_STRINGL(erealloc(str, q - str + 1), q - str, 0); -} -/* }}} */ - -/* {{{ proto int ord(string character) - Returns ASCII value of character */ -PHP_FUNCTION(ord) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - RETURN_LONG((unsigned char) Z_STRVAL_PP(str)[0]); -} -/* }}} */ - -/* {{{ proto string chr(int ascii) - Converts ASCII code to a character */ -PHP_FUNCTION(chr) -{ - zval **num; - char temp[2]; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(num); - - temp[0] = (char) Z_LVAL_PP(num); - temp[1] = 0; - - RETVAL_STRINGL(temp, 1, 1); -} -/* }}} */ - -/* {{{ proto string ucfirst(string str) - Makes a string's first character uppercase */ -PHP_FUNCTION(ucfirst) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if (!Z_STRLEN_PP(str)) { - RETURN_EMPTY_STRING(); - } - - ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - *Z_STRVAL_P(return_value) = toupper((unsigned char) *Z_STRVAL_P(return_value)); -} -/* }}} */ - -/* {{{ proto string ucwords(string str) - Uppercase the first character of every word in a string */ -PHP_FUNCTION(ucwords) -{ - zval **str; - register char *r, *r_end; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if (!Z_STRLEN_PP(str)) { - RETURN_EMPTY_STRING(); - } - - ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - r = Z_STRVAL_P(return_value); - - *r = toupper((unsigned char) *r); - for (r_end = r + Z_STRLEN_P(return_value) - 1; r < r_end; ) { - if (isspace((int) *(unsigned char *)r++)) { - *r = toupper((unsigned char) *r); - } - } -} -/* }}} */ - -/* {{{ php_strtr - */ -PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen) -{ - int i; - unsigned char xlat[256]; - - if ((trlen < 1) || (len < 1)) { - return str; - } - - for (i = 0; i < 256; xlat[i] = i, i++); - - for (i = 0; i < trlen; i++) { - xlat[(unsigned char) str_from[i]] = str_to[i]; - } - - for (i = 0; i < len; i++) { - str[i] = xlat[(unsigned char) str[i]]; - } - - return str; -} -/* }}} */ - -/* {{{ php_strtr_array - */ -static void php_strtr_array(zval *return_value, char *str, int slen, HashTable *hash) -{ - zval **entry; - char *string_key; - uint string_key_len; - zval **trans; - zval ctmp; - ulong num_key; - int minlen = 128*1024; - int maxlen = 0, pos, len, found; - char *key; - HashPosition hpos; - smart_str result = {0}; - - zend_hash_internal_pointer_reset_ex(hash, &hpos); - while (zend_hash_get_current_data_ex(hash, (void **)&entry, &hpos) == SUCCESS) { - switch (zend_hash_get_current_key_ex(hash, &string_key, &string_key_len, &num_key, 0, &hpos)) { - case HASH_KEY_IS_STRING: - len = string_key_len-1; - if (len > maxlen) { - maxlen = len; - } - if (len < minlen) { - minlen = len; - } - break; - - case HASH_KEY_IS_LONG: - Z_TYPE(ctmp) = IS_LONG; - Z_LVAL(ctmp) = num_key; - - convert_to_string(&ctmp); - len = Z_STRLEN(ctmp); - zval_dtor(&ctmp); - - if (len > maxlen) { - maxlen = len; - } - if (len < minlen) { - minlen = len; - } - break; - } - zend_hash_move_forward_ex(hash, &hpos); - } - - key = emalloc(maxlen+1); - pos = 0; - - while (pos < slen) { - if ((pos + maxlen) > slen) { - maxlen = slen - pos; - } - - found = 0; - memcpy(key, str+pos, maxlen); - - for (len = maxlen; len >= minlen; len--) { - key[len] = 0; - - if (zend_hash_find(hash, key, len+1, (void**)&trans) == SUCCESS) { - char *tval; - int tlen; - zval tmp; - - if (Z_TYPE_PP(trans) != IS_STRING) { - tmp = **trans; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - tval = Z_STRVAL(tmp); - tlen = Z_STRLEN(tmp); - } else { - tval = Z_STRVAL_PP(trans); - tlen = Z_STRLEN_PP(trans); - } - - smart_str_appendl(&result, tval, tlen); - pos += len; - found = 1; - - if (Z_TYPE_PP(trans) != IS_STRING) { - zval_dtor(&tmp); - } - break; - } - } - - if (! found) { - smart_str_appendc(&result, str[pos++]); - } - } - - efree(key); - smart_str_0(&result); - RETVAL_STRINGL(result.c, result.len, 0); -} -/* }}} */ - -/* {{{ proto string strtr(string str, string from, string to) - Translates characters in str using given translation tables */ -PHP_FUNCTION(strtr) -{ - zval **str, **from, **to; - int ac = ZEND_NUM_ARGS(); - - if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &str, &from, &to) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (ac == 2 && Z_TYPE_PP(from) != IS_ARRAY) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument is not an array."); - RETURN_FALSE; - } - - convert_to_string_ex(str); - - /* shortcut for empty string */ - if (Z_STRLEN_PP(str) == 0) { - RETURN_EMPTY_STRING(); - } - - if (ac == 2) { - php_strtr_array(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), HASH_OF(*from)); - } else { - convert_to_string_ex(from); - convert_to_string_ex(to); - - ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - - php_strtr(Z_STRVAL_P(return_value), - Z_STRLEN_P(return_value), - Z_STRVAL_PP(from), - Z_STRVAL_PP(to), - MIN(Z_STRLEN_PP(from), - Z_STRLEN_PP(to))); - } -} -/* }}} */ - -/* {{{ proto string strrev(string str) - Reverse a string */ -PHP_FUNCTION(strrev) -{ - zval **str; - char *s, *e, *n, *p; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - n = emalloc(Z_STRLEN_PP(str)+1); - p = n; - - s = Z_STRVAL_PP(str); - e = s + Z_STRLEN_PP(str); - - while (--e>=s) { - *p++ = *e; - } - - *p = '\0'; - - RETVAL_STRINGL(n, Z_STRLEN_PP(str), 0); -} -/* }}} */ - -/* {{{ php_similar_str - */ -static void php_similar_str(const char *txt1, int len1, const char *txt2, int len2, int *pos1, int *pos2, int *max) -{ - char *p, *q; - char *end1 = (char *) txt1 + len1; - char *end2 = (char *) txt2 + len2; - int l; - - *max = 0; - for (p = (char *) txt1; p < end1; p++) { - for (q = (char *) txt2; q < end2; q++) { - for (l = 0; (p + l < end1) && (q + l < end2) && (p[l] == q[l]); l++); - if (l > *max) { - *max = l; - *pos1 = p - txt1; - *pos2 = q - txt2; - } - } - } -} -/* }}} */ - -/* {{{ php_similar_char - */ -static int php_similar_char(const char *txt1, int len1, const char *txt2, int len2) -{ - int sum; - int pos1, pos2, max; - - php_similar_str(txt1, len1, txt2, len2, &pos1, &pos2, &max); - if ((sum = max)) { - if (pos1 && pos2) { - sum += php_similar_char(txt1, pos1, - txt2, pos2); - } - if ((pos1 + max < len1) && (pos2 + max < len2)) { - sum += php_similar_char(txt1 + pos1 + max, len1 - pos1 - max, - txt2 + pos2 + max, len2 - pos2 - max); - } - } - - return sum; -} -/* }}} */ - -/* {{{ proto int similar_text(string str1, string str2 [, float percent]) - Calculates the similarity between two strings */ -PHP_FUNCTION(similar_text) -{ - zval **t1, **t2, **percent; - int ac = ZEND_NUM_ARGS(); - int sim; - - if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &t1, &t2, &percent) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(t1); - convert_to_string_ex(t2); - - if (ac > 2) { - convert_to_double_ex(percent); - } - - if (Z_STRLEN_PP(t1) + Z_STRLEN_PP(t2) == 0) { - if (ac > 2) { - Z_DVAL_PP(percent) = 0; - } - - RETURN_LONG(0); - } - - sim = php_similar_char(Z_STRVAL_PP(t1), Z_STRLEN_PP(t1), Z_STRVAL_PP(t2), Z_STRLEN_PP(t2)); - - if (ac > 2) { - Z_DVAL_PP(percent) = sim * 200.0 / (Z_STRLEN_PP(t1) + Z_STRLEN_PP(t2)); - } - - RETURN_LONG(sim); -} -/* }}} */ - -/* {{{ php_stripslashes - * - * be careful, this edits the string in-place */ -PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC) -{ - char *s, *t; - int l; - - if (len != NULL) { - l = *len; - } else { - l = strlen(str); - } - s = str; - t = str; - - if (PG(magic_quotes_sybase)) { - while (l > 0) { - if (*t == '\'') { - if ((l > 0) && (t[1] == '\'')) { - t++; - if (len != NULL) { - (*len)--; - } - l--; - } - *s++ = *t++; - } else if (*t == '\\' && l > 0 && t[1] == '0') { - *s++='\0'; - t += 2; - if (len != NULL) { - (*len)--; - } - l--; - } else { - *s++ = *t++; - } - l--; - } - *s = '\0'; - - return; - } - - while (l > 0) { - if (*t == '\\') { - t++; /* skip the slash */ - if (len != NULL) { - (*len)--; - } - l--; - if (l > 0) { - if (*t == '0') { - *s++='\0'; - t++; - } else { - *s++ = *t++; /* preserve the next character */ - } - l--; - } - } else { - if (s != t) { - *s++ = *t++; - } else { - s++; - t++; - } - l--; - } - } - if (s != t) { - *s = '\0'; - } -} -/* }}} */ - -/* {{{ proto string addcslashes(string str, string charlist) - Escapes all chars mentioned in charlist with backslash. It creates octal representations if asked to backslash characters with 8th bit set or with ASCII<32 (except '\n', '\r', '\t' etc...) */ -PHP_FUNCTION(addcslashes) -{ - zval **str, **what; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &str, &what) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - convert_to_string_ex(what); - - if (Z_STRLEN_PP(str) == 0) { - RETURN_EMPTY_STRING(); - } - - if (Z_STRLEN_PP(what) == 0) { - RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - } - - RETURN_STRING(php_addcslashes(Z_STRVAL_PP(str), - Z_STRLEN_PP(str), - &Z_STRLEN_P(return_value), 0, - Z_STRVAL_PP(what), - Z_STRLEN_PP(what) TSRMLS_CC), 0); -} -/* }}} */ - -/* {{{ proto string addslashes(string str) - Escapes single quote, double quotes and backslash characters in a string with backslashes */ -PHP_FUNCTION(addslashes) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if (Z_STRLEN_PP(str) == 0) { - RETURN_EMPTY_STRING(); - } - - RETURN_STRING(php_addslashes(Z_STRVAL_PP(str), - Z_STRLEN_PP(str), - &Z_STRLEN_P(return_value), 0 - TSRMLS_CC), 0); -} -/* }}} */ - -/* {{{ proto string stripcslashes(string str) - Strips backslashes from a string. Uses C-style conventions */ -PHP_FUNCTION(stripcslashes) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - php_stripcslashes(Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value)); -} -/* }}} */ - -/* {{{ proto string stripslashes(string str) - Strips backslashes from a string */ -PHP_FUNCTION(stripslashes) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - ZVAL_STRINGL(return_value, Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1); - php_stripslashes(Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value) TSRMLS_CC); -} -/* }}} */ - -#ifndef HAVE_STRERROR -/* {{{ php_strerror - */ -char *php_strerror(int errnum) -{ - extern int sys_nerr; - extern char *sys_errlist[]; - TSRMLS_FETCH(); - - if ((unsigned int) errnum < sys_nerr) { - return(sys_errlist[errnum]); - } - - (void) sprintf(BG(str_ebuf), "Unknown error: %d", errnum); - return(BG(str_ebuf)); -} -/* }}} */ -#endif - -/* {{{ php_stripcslashes - */ -PHPAPI void php_stripcslashes(char *str, int *len) -{ - char *source, *target, *end; - int nlen = *len, i; - char numtmp[4]; - - for (source=str, end=str+nlen, target=str; source < end; source++) { - if (*source == '\\' && source+1 < end) { - source++; - switch (*source) { - case 'n': *target++='\n'; nlen--; break; - case 'r': *target++='\r'; nlen--; break; - case 'a': *target++='\a'; nlen--; break; - case 't': *target++='\t'; nlen--; break; - case 'v': *target++='\v'; nlen--; break; - case 'b': *target++='\b'; nlen--; break; - case 'f': *target++='\f'; nlen--; break; - case '\\': *target++='\\'; nlen--; break; - case 'x': - if (source+1 < end && isxdigit((int)(*(source+1)))) { - numtmp[0] = *++source; - if (source+1 < end && isxdigit((int)(*(source+1)))) { - numtmp[1] = *++source; - numtmp[2] = '\0'; - nlen-=3; - } else { - numtmp[1] = '\0'; - nlen-=2; - } - *target++=(char)strtol(numtmp, NULL, 16); - break; - } - /* break is left intentionally */ - default: - i=0; - while (source < end && *source >= '0' && *source <= '7' && i<3) { - numtmp[i++] = *source++; - } - if (i) { - numtmp[i]='\0'; - *target++=(char)strtol(numtmp, NULL, 8); - nlen-=i; - source--; - } else { - *target++=*source; - nlen--; - } - } - } else { - *target++=*source; - } - } - - if (nlen != 0) { - *target='\0'; - } - - *len = nlen; -} -/* }}} */ - -/* {{{ php_addcslashes - */ -PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_free, char *what, int wlength TSRMLS_DC) -{ - char flags[256]; - char *new_str = emalloc((length?length:(length=strlen(str)))*4+1); - char *source, *target; - char *end; - char c; - int newlen; - - if (!wlength) { - wlength = strlen(what); - } - - if (!length) { - length = strlen(str); - } - - php_charmask(what, wlength, flags TSRMLS_CC); - - for (source = str, end = source + length, target = new_str; (c = *source) || (source < end); source++) { - if (flags[(unsigned char)c]) { - if ((unsigned char) c < 32 || (unsigned char) c > 126) { - *target++ = '\\'; - switch (c) { - case '\n': *target++ = 'n'; break; - case '\t': *target++ = 't'; break; - case '\r': *target++ = 'r'; break; - case '\a': *target++ = 'a'; break; - case '\v': *target++ = 'v'; break; - case '\b': *target++ = 'b'; break; - case '\f': *target++ = 'f'; break; - default: target += sprintf(target, "%03o", (unsigned char) c); - } - continue; - } - *target++ = '\\'; - } - *target++ = c; - } - *target = 0; - newlen = target - new_str; - if (target - new_str < length * 4) { - new_str = erealloc(new_str, newlen + 1); - } - if (new_length) { - *new_length = newlen; - } - if (should_free) { - STR_FREE(str); - } - return new_str; -} -/* }}} */ - -/* {{{ php_addslashes - */ -PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC) -{ - /* maximum string length, worst case situation */ - char *new_str; - char *source, *target; - char *end; - int local_new_length; - - if (!new_length) { - new_length = &local_new_length; - } - if (!str) { - *new_length = 0; - return str; - } - new_str = (char *) emalloc((length ? length : (length = strlen(str))) * 2 + 1); - source = str; - end = source + length; - target = new_str; - - if (PG(magic_quotes_sybase)) { - while (source < end) { - switch (*source) { - case '\0': - *target++ = '\\'; - *target++ = '0'; - break; - case '\'': - *target++ = '\''; - *target++ = '\''; - break; - default: - *target++ = *source; - break; - } - source++; - } - } else { - while (source < end) { - switch (*source) { - case '\0': - *target++ = '\\'; - *target++ = '0'; - break; - case '\'': - case '\"': - case '\\': - *target++ = '\\'; - /* break is missing *intentionally* */ - default: - *target++ = *source; - break; - } - - source++; - } - } - - *target = 0; - *new_length = target - new_str; - if (should_free) { - STR_FREE(str); - } - new_str = (char *) erealloc(new_str, *new_length + 1); - return new_str; -} -/* }}} */ - -#define _HEB_BLOCK_TYPE_ENG 1 -#define _HEB_BLOCK_TYPE_HEB 2 -#define isheb(c) (((((unsigned char) c) >= 224) && (((unsigned char) c) <= 250)) ? 1 : 0) -#define _isblank(c) (((((unsigned char) c) == ' ' || ((unsigned char) c) == '\t')) ? 1 : 0) -#define _isnewline(c) (((((unsigned char) c) == '\n' || ((unsigned char) c) == '\r')) ? 1 : 0) - -/* {{{ php_char_to_str - */ -PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result) -{ - int char_count = 0; - int replaced = 0; - char *source, *target, *tmp, *source_end=str+len, *tmp_end = NULL; - - for (source = str; source < source_end; source++) { - if (*source == from) { - char_count++; - } - } - - if (char_count == 0) { - ZVAL_STRINGL(result, str, len, 1); - return 0; - } - - Z_STRLEN_P(result) = len + (char_count * (to_len - 1)); - Z_STRVAL_P(result) = target = emalloc(Z_STRLEN_P(result) + 1); - Z_TYPE_P(result) = IS_STRING; - - for (source = str; source < source_end; source++) { - if (*source == from) { - replaced = 1; - for (tmp = to, tmp_end = tmp+to_len; tmp < tmp_end; tmp++) { - *target = *tmp; - target++; - } - } else { - *target = *source; - target++; - } - } - *target = 0; - return replaced; -} -/* }}} */ - -/* {{{ php_str_to_str_ex - */ -PHPAPI char *php_str_to_str_ex(char *haystack, int length, - char *needle, int needle_len, char *str, int str_len, int *_new_length, int case_sensitivity) -{ - char *new_str; - - if (needle_len < length) { - char *end, *haystack_dup, *needle_dup; - char *e, *s, *p, *r; - - if (needle_len == str_len) { - new_str = estrndup(haystack, length); - *_new_length = length; - - if (case_sensitivity) { - end = new_str + length; - for (p = new_str; (r = php_memnstr(p, needle, needle_len, end)); p = r + needle_len) { - memcpy(r, str, str_len); - } - } else { - haystack_dup = estrndup(haystack, length); - needle_dup = estrndup(needle, needle_len); - php_strtolower(haystack_dup, length); - php_strtolower(needle_dup, needle_len); - end = haystack_dup + length; - for (p = haystack_dup; (r = php_memnstr(p, needle_dup, needle_len, end)); p = r + needle_len) { - memcpy(new_str + (r - haystack_dup), str, str_len); - } - efree(haystack_dup); - efree(needle_dup); - } - return new_str; - } else { - if (str_len < needle_len) { - new_str = emalloc(length + 1); - } else { - new_str = emalloc((length / needle_len + 1) * str_len); - } - - e = s = new_str; - - if (case_sensitivity) { - end = haystack + length; - for (p = haystack; (r = php_memnstr(p, needle, needle_len, end)); p = r + needle_len) { - memcpy(e, p, r - p); - e += r - p; - memcpy(e, str, str_len); - e += str_len; - } - - if (p < end) { - memcpy(e, p, end - p); - e += end - p; - } - } else { - haystack_dup = estrndup(haystack, length); - needle_dup = estrndup(needle, needle_len); - php_strtolower(haystack_dup, length); - php_strtolower(needle_dup, needle_len); - - end = haystack_dup + length; - - for (p = haystack_dup; (r = php_memnstr(p, needle_dup, needle_len, end)); p = r + needle_len) { - memcpy(e, haystack + (p - haystack_dup), r - p); - e += r - p; - memcpy(e, str, str_len); - e += str_len; - } - - if (p < end) { - memcpy(e, haystack + (p - haystack_dup), end - p); - e += end - p; - } - efree(haystack_dup); - efree(needle_dup); - } - - *e = '\0'; - *_new_length = e - s; - - new_str = erealloc(new_str, *_new_length + 1); - return new_str; - } - } else if (needle_len > length) { -nothing_todo: - *_new_length = length; - new_str = estrndup(haystack, length); - return new_str; - } else { - if (case_sensitivity ? strncmp(haystack, needle, length) : strncasecmp(haystack, needle, length)) { - goto nothing_todo; - } else { - *_new_length = str_len; - new_str = estrndup(str, str_len); - return new_str; - } - } - -} -/* }}} */ - -/* {{{ php_str_to_str - */ -PHPAPI char *php_str_to_str(char *haystack, int length, - char *needle, int needle_len, char *str, int str_len, int *_new_length) -{ - return php_str_to_str_ex(haystack, length, needle, needle_len, str, str_len, _new_length, 1); -} -/* }}} - */ - -/* {{{ php_str_replace_in_subject - */ -static void php_str_replace_in_subject(zval *search, zval *replace, zval **subject, zval *result, int case_sensitivity) -{ - zval **search_entry, - **replace_entry = NULL, - temp_result; - char *replace_value = NULL; - int replace_len = 0; - - /* Make sure we're dealing with strings. */ - convert_to_string_ex(subject); - Z_TYPE_P(result) = IS_STRING; - if (Z_STRLEN_PP(subject) == 0) { - ZVAL_STRINGL(result, empty_string, 0, 1); - return; - } - - /* If search is an array */ - if (Z_TYPE_P(search) == IS_ARRAY) { - /* Duplicate subject string for repeated replacement */ - *result = **subject; - zval_copy_ctor(result); - INIT_PZVAL(result); - - zend_hash_internal_pointer_reset(Z_ARRVAL_P(search)); - - if (Z_TYPE_P(replace) == IS_ARRAY) { - zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace)); - } else { - /* Set replacement value to the passed one */ - replace_value = Z_STRVAL_P(replace); - replace_len = Z_STRLEN_P(replace); - } - - /* For each entry in the search array, get the entry */ - while (zend_hash_get_current_data(Z_ARRVAL_P(search), (void **) &search_entry) == SUCCESS) { - /* Make sure we're dealing with strings. */ - SEPARATE_ZVAL(search_entry); - convert_to_string(*search_entry); - if (Z_STRLEN_PP(search_entry) == 0) { - zend_hash_move_forward(Z_ARRVAL_P(search)); - continue; - } - - /* If replace is an array. */ - if (Z_TYPE_P(replace) == IS_ARRAY) { - /* Get current entry */ - if (zend_hash_get_current_data(Z_ARRVAL_P(replace), (void **)&replace_entry) == SUCCESS) { - /* Make sure we're dealing with strings. */ - convert_to_string_ex(replace_entry); - - /* Set replacement value to the one we got from array */ - replace_value = Z_STRVAL_PP(replace_entry); - replace_len = Z_STRLEN_PP(replace_entry); - - zend_hash_move_forward(Z_ARRVAL_P(replace)); - } else { - /* We've run out of replacement strings, so use an empty one. */ - replace_value = empty_string; - replace_len = 0; - } - } - - if (Z_STRLEN_PP(search_entry) == 1) { - php_char_to_str(Z_STRVAL_P(result), - Z_STRLEN_P(result), - Z_STRVAL_PP(search_entry)[0], - replace_value, - replace_len, - &temp_result); - } else if (Z_STRLEN_PP(search_entry) > 1) { - Z_STRVAL(temp_result) = php_str_to_str_ex(Z_STRVAL_P(result), Z_STRLEN_P(result), - Z_STRVAL_PP(search_entry), Z_STRLEN_PP(search_entry), - replace_value, replace_len, &Z_STRLEN(temp_result), case_sensitivity); - } - - efree(Z_STRVAL_P(result)); - Z_STRVAL_P(result) = Z_STRVAL(temp_result); - Z_STRLEN_P(result) = Z_STRLEN(temp_result); - - if (Z_STRLEN_P(result) == 0) { - return; - } - - zend_hash_move_forward(Z_ARRVAL_P(search)); - } - } else { - if (Z_STRLEN_P(search) == 1) { - php_char_to_str(Z_STRVAL_PP(subject), - Z_STRLEN_PP(subject), - Z_STRVAL_P(search)[0], - Z_STRVAL_P(replace), - Z_STRLEN_P(replace), - result); - } else if (Z_STRLEN_P(search) > 1) { - Z_STRVAL_P(result) = php_str_to_str_ex(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject), - Z_STRVAL_P(search), Z_STRLEN_P(search), - Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(result), case_sensitivity); - } else { - *result = **subject; - zval_copy_ctor(result); - INIT_PZVAL(result); - } - } -} -/* }}} */ - -/* {{{ php_str_replace_common - */ -static void php_str_replace_common(INTERNAL_FUNCTION_PARAMETERS, int case_sensitivity) -{ - zval **subject, **search, **replace, **subject_entry; - zval *result; - char *string_key; - uint string_key_len; - ulong num_key; - - if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &search, &replace, &subject) == FAILURE) { - WRONG_PARAM_COUNT; - } - - SEPARATE_ZVAL(search); - SEPARATE_ZVAL(replace); - SEPARATE_ZVAL(subject); - - /* Make sure we're dealing with strings and do the replacement. */ - if (Z_TYPE_PP(search) != IS_ARRAY) { - convert_to_string_ex(search); - convert_to_string_ex(replace); - } else if (Z_TYPE_PP(replace) != IS_ARRAY) { - convert_to_string_ex(replace); - } - - /* if subject is an array */ - if (Z_TYPE_PP(subject) == IS_ARRAY) { - array_init(return_value); - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(subject)); - - /* For each subject entry, convert it to string, then perform replacement - and add the result to the return_value array. */ - while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)&subject_entry) == SUCCESS) { - MAKE_STD_ZVAL(result); - php_str_replace_in_subject(*search, *replace, subject_entry, result, case_sensitivity); - /* Add to return array */ - switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), &string_key, - &string_key_len, &num_key, 0, NULL)) { - case HASH_KEY_IS_STRING: - add_assoc_zval_ex(return_value, string_key, string_key_len, result); - break; - - case HASH_KEY_IS_LONG: - add_index_zval(return_value, num_key, result); - break; - } - - zend_hash_move_forward(Z_ARRVAL_PP(subject)); - } - } else { /* if subject is not an array */ - php_str_replace_in_subject(*search, *replace, subject, return_value, case_sensitivity); - } -} -/* }}} */ - -/* {{{ proto mixed str_replace(mixed search, mixed replace, mixed subject) - Replaces all occurrences of search in haystack with replace */ -PHP_FUNCTION(str_replace) -{ - php_str_replace_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto mixed str_ireplace(mixed search, mixed replace, mixed subject) - Replaces all occurrences of search in haystack with replace / case-insensitive */ -PHP_FUNCTION(str_ireplace) -{ - php_str_replace_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ php_hebrev - * - * Converts Logical Hebrew text (Hebrew Windows style) to Visual text - * Cheers/complaints/flames - Zeev Suraski <zeev@php.net> - */ -static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines) -{ - zval **str, **max_chars_per_line; - char *heb_str, *tmp, *target, *broken_str; - int block_start, block_end, block_type, block_length, i; - long max_chars=0; - int begin, end, char_count, orig_begin; - - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &str) == FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &str, &max_chars_per_line) == FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(max_chars_per_line); - max_chars = Z_LVAL_PP(max_chars_per_line); - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string_ex(str); - - if (Z_STRLEN_PP(str) == 0) { - RETURN_FALSE; - } - - tmp = Z_STRVAL_PP(str); - block_start=block_end=0; - - heb_str = (char *) emalloc(Z_STRLEN_PP(str)+1); - target = heb_str+Z_STRLEN_PP(str); - *target = 0; - target--; - - block_length=0; - - if (isheb(*tmp)) { - block_type = _HEB_BLOCK_TYPE_HEB; - } else { - block_type = _HEB_BLOCK_TYPE_ENG; - } - - do { - if (block_type == _HEB_BLOCK_TYPE_HEB) { - while ((isheb((int)*(tmp+1)) || _isblank((int)*(tmp+1)) || ispunct((int)*(tmp+1)) || (int)*(tmp+1)=='\n' ) && block_end<Z_STRLEN_PP(str)-1) { - tmp++; - block_end++; - block_length++; - } - for (i = block_start; i<= block_end; i++) { - *target = Z_STRVAL_PP(str)[i]; - switch (*target) { - case '(': - *target = ')'; - break; - case ')': - *target = '('; - break; - case '[': - *target = ']'; - break; - case ']': - *target = '['; - break; - case '{': - *target = '}'; - break; - case '}': - *target = '{'; - break; - case '<': - *target = '>'; - break; - case '>': - *target = '<'; - break; - case '\\': - *target = '/'; - break; - case '/': - *target = '\\'; - break; - default: - break; - } - target--; - } - block_type = _HEB_BLOCK_TYPE_ENG; - } else { - while (!isheb(*(tmp+1)) && (int)*(tmp+1)!='\n' && block_end < Z_STRLEN_PP(str)-1) { - tmp++; - block_end++; - block_length++; - } - while ((_isblank((int)*tmp) || ispunct((int)*tmp)) && *tmp!='/' && *tmp!='-' && block_end > block_start) { - tmp--; - block_end--; - } - for (i = block_end; i >= block_start; i--) { - *target = Z_STRVAL_PP(str)[i]; - target--; - } - block_type = _HEB_BLOCK_TYPE_HEB; - } - block_start=block_end+1; - } while (block_end < Z_STRLEN_PP(str)-1); - - - broken_str = (char *) emalloc(Z_STRLEN_PP(str)+1); - begin=end=Z_STRLEN_PP(str)-1; - target = broken_str; - - while (1) { - char_count=0; - while ((!max_chars || char_count < max_chars) && begin > 0) { - char_count++; - begin--; - if (begin <= 0 || _isnewline(heb_str[begin])) { - while (begin > 0 && _isnewline(heb_str[begin-1])) { - begin--; - char_count++; - } - break; - } - } - if (char_count == max_chars) { /* try to avoid breaking words */ - int new_char_count=char_count, new_begin=begin; - - while (new_char_count > 0) { - if (_isblank(heb_str[new_begin]) || _isnewline(heb_str[new_begin])) { - break; - } - new_begin++; - new_char_count--; - } - if (new_char_count > 0) { - char_count=new_char_count; - begin=new_begin; - } - } - orig_begin=begin; - - if (_isblank(heb_str[begin])) { - heb_str[begin]='\n'; - } - while (begin <= end && _isnewline(heb_str[begin])) { /* skip leading newlines */ - begin++; - } - for (i = begin; i <= end; i++) { /* copy content */ - *target = heb_str[i]; - target++; - } - for (i = orig_begin; i <= end && _isnewline(heb_str[i]); i++) { - *target = heb_str[i]; - target++; - } - begin=orig_begin; - - if (begin <= 0) { - *target = 0; - break; - } - begin--; - end=begin; - } - efree(heb_str); - - if (convert_newlines) { - php_char_to_str(broken_str, Z_STRLEN_PP(str),'\n', "<br />\n", 7, return_value); - efree(broken_str); - } else { - Z_STRVAL_P(return_value) = broken_str; - Z_STRLEN_P(return_value) = Z_STRLEN_PP(str); - Z_TYPE_P(return_value) = IS_STRING; - } -} -/* }}} */ - -/* {{{ proto string hebrev(string str [, int max_chars_per_line]) - Converts logical Hebrew text to visual text */ -PHP_FUNCTION(hebrev) -{ - php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string hebrevc(string str [, int max_chars_per_line]) - Converts logical Hebrew text to visual text with newline conversion */ -PHP_FUNCTION(hebrevc) -{ - php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - - -/* {{{ proto string nl2br(string str) - Converts newlines to HTML line breaks */ -PHP_FUNCTION(nl2br) -{ - /* in brief this inserts <br /> before matched regexp \n\r?|\r\n? */ - zval **zstr; - char *tmp, *str; - int new_length; - char *end, *target; - int repl_cnt = 0; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &zstr) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(zstr); - - str = Z_STRVAL_PP(zstr); - end = str + Z_STRLEN_PP(zstr); - - /* it is really faster to scan twice and allocate mem once insted scanning once - and constantly reallocing */ - while (str < end) { - if (*str == '\r') { - if (*(str+1) == '\n') { - str++; - } - repl_cnt++; - } else if (*str == '\n') { - if (*(str+1) == '\r') { - str++; - } - repl_cnt++; - } - - str++; - } - - if (repl_cnt == 0) { - RETURN_STRINGL(Z_STRVAL_PP(zstr), Z_STRLEN_PP(zstr), 1); - } - - new_length = Z_STRLEN_PP(zstr) + repl_cnt * (sizeof("<br />") - 1); - tmp = target = emalloc(new_length + 1); - - str = Z_STRVAL_PP(zstr); - - while (str < end) { - switch (*str) { - case '\r': - case '\n': - *target++ = '<'; - *target++ = 'b'; - *target++ = 'r'; - *target++ = ' '; - *target++ = '/'; - *target++ = '>'; - - if ((*str == '\r' && *(str+1) == '\n') || (*str == '\n' && *(str+1) == '\r')) { - *target++ = *str++; - } - /* lack of a break; is intentional */ - default: - *target++ = *str; - } - - str++; - } - - *target = '\0'; - - RETURN_STRINGL(tmp, new_length, 0); -} -/* }}} */ - - -/* {{{ proto string strip_tags(string str [, string allowable_tags]) - Strips HTML and PHP tags from a string */ -PHP_FUNCTION(strip_tags) -{ - char *buf; - zval **str, **allow=NULL; - char *allowed_tags=NULL; - int allowed_tags_len=0; - size_t retval_len; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &str) == FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &str, &allow) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - allowed_tags = Z_STRVAL_PP(allow); - allowed_tags_len = Z_STRLEN_PP(allow); - break; - default: - WRONG_PARAM_COUNT; - break; - } - convert_to_string_ex(str); - buf = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str)); - retval_len = php_strip_tags(buf, Z_STRLEN_PP(str), NULL, allowed_tags, allowed_tags_len); - RETURN_STRINGL(buf, retval_len, 0); -} -/* }}} */ - -/* {{{ proto string setlocale(mixed category, string locale [, string ...]) - Set locale information */ -PHP_FUNCTION(setlocale) -{ - pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS()); - zval **pcategory, **plocale; - int i, cat, n_args=ZEND_NUM_ARGS(); - char *loc, *retval; - - if (zend_get_parameters_array_ex(n_args, args) == FAILURE || n_args < 2) { - efree(args); - WRONG_PARAM_COUNT; - } -#ifdef HAVE_SETLOCALE - pcategory = args[0]; - if (Z_TYPE_PP(pcategory) == IS_LONG) { - convert_to_long_ex(pcategory); - cat = Z_LVAL_PP(pcategory); - } else { /* FIXME: The following behaviour should be removed. */ - char *category; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passing locale category name as string is deprecated. Use the LC_* -constants instead."); - convert_to_string_ex(pcategory); - category = Z_STRVAL_P(*pcategory); - - if (!strcasecmp ("LC_ALL", category)) - cat = LC_ALL; - else if (!strcasecmp ("LC_COLLATE", category)) - cat = LC_COLLATE; - else if (!strcasecmp ("LC_CTYPE", category)) - cat = LC_CTYPE; -#ifdef LC_MESSAGES - else if (!strcasecmp ("LC_MESSAGES", category)) - cat = LC_MESSAGES; -#endif - else if (!strcasecmp ("LC_MONETARY", category)) - cat = LC_MONETARY; - else if (!strcasecmp ("LC_NUMERIC", category)) - cat = LC_NUMERIC; - else if (!strcasecmp ("LC_TIME", category)) - cat = LC_TIME; - else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid locale category name %s, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, or LC_TIME.", category); - efree(args); - RETURN_FALSE; - } - } - - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args[1])); - i=0; /* not needed in this case: only kill a compiler warning */ - } else { - i=1; - } - while (1) { - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - zend_hash_get_current_data(Z_ARRVAL_PP(args[1]),(void **)&plocale); - } else { - plocale = args[i]; - } - - convert_to_string_ex(plocale); - - if (!strcmp ("0", Z_STRVAL_PP(plocale))) { - loc = NULL; - } else { - loc = Z_STRVAL_PP(plocale); - } - - retval = setlocale (cat, loc); - if (retval) { - /* Remember if locale was changed */ - if (loc) { - STR_FREE(BG(locale_string)); - BG(locale_string) = estrdup(retval); - } - - efree(args); - RETVAL_STRING(retval, 1); - - if (cat == LC_NUMERIC || cat == LC_ALL) { - struct lconv lc; - localeconv_r(&lc); - - EG(float_separator)[0] = (lc.decimal_point)[0]; - - if ((lc.decimal_point)[0] != '.') { - /* set locale back to C */ - setlocale(LC_NUMERIC, "C"); - } - } - - return; - } - - if (Z_TYPE_PP(args[1]) == IS_ARRAY) { - if (zend_hash_move_forward(Z_ARRVAL_PP(args[1])) == FAILURE) break; - } else { - if (++i >= n_args) break; - } - } - -#endif - efree(args); - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto void parse_str(string encoded_string [, array result]) - Parses GET/POST/COOKIE data and sets global variables */ -PHP_FUNCTION(parse_str) -{ - zval **arg; - zval **arrayArg; - zval *sarg; - char *res = NULL; - int argCount; - int old_rg; - - argCount = ZEND_NUM_ARGS(); - if (argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - sarg = *arg; - if (Z_STRVAL_P(sarg) && *Z_STRVAL_P(sarg)) { - res = estrndup(Z_STRVAL_P(sarg), Z_STRLEN_P(sarg)); - } - - old_rg = PG(register_globals); - if (argCount == 1) { - PG(register_globals) = 1; - sapi_module.treat_data(PARSE_STRING, res, NULL TSRMLS_CC); - } else { - PG(register_globals) = 0; - /* Clear out the array that was passed in. */ - zval_dtor(*arrayArg); - array_init(*arrayArg); - - sapi_module.treat_data(PARSE_STRING, res, *arrayArg TSRMLS_CC); - } - PG(register_globals) = old_rg; -} -/* }}} */ - -#define PHP_TAG_BUF_SIZE 1023 - -/* {{{ php_tag_find - * - * Check if tag is in a set of tags - * - * states: - * - * 0 start tag - * 1 first non-whitespace char seen - */ -int php_tag_find(char *tag, int len, char *set) { - char c, *n, *t; - int state=0, done=0; - char *norm = emalloc(len+1); - - n = norm; - t = tag; - c = tolower(*t); - /* - normalize the tag removing leading and trailing whitespace - and turn any <a whatever...> into just <a> and any </tag> - into <tag> - */ - if (!len) { - return 0; - } - while (!done) { - switch (c) { - case '<': - *(n++) = c; - break; - case '>': - done =1; - break; - default: - if (!isspace((int)c)) { - if (state == 0) { - state=1; - if (c != '/') - *(n++) = c; - } else { - *(n++) = c; - } - } else { - if (state == 1) - done=1; - } - break; - } - c = tolower(*(++t)); - } - *(n++) = '>'; - *n = '\0'; - if (strstr(set, norm)) { - done=1; - } else { - done=0; - } - efree(norm); - return done; -} -/* }}} */ - -/* {{{ php_strip_tags - - A simple little state-machine to strip out html and php tags - - State 0 is the output state, State 1 means we are inside a - normal html tag and state 2 means we are inside a php tag. - - The state variable is passed in to allow a function like fgetss - to maintain state across calls to the function. - - lc holds the last significant character read and br is a bracket - counter. - - When an allow string is passed in we keep track of the string - in state 1 and when the tag is closed check it against the - allow string to see if we should allow it. - - swm: Added ability to strip <?xml tags without assuming it PHP - code. -*/ -PHPAPI size_t php_strip_tags(char *rbuf, int len, int *stateptr, char *allow, int allow_len) -{ - char *tbuf, *buf, *p, *tp, *rp, c, lc; - int br, i=0, depth=0; - int state = 0; - - if (stateptr) - state = *stateptr; - - buf = estrndup(rbuf, len); - c = *buf; - lc = '\0'; - p = buf; - rp = rbuf; - br = 0; - if (allow) { - php_strtolower(allow, allow_len); - tbuf = emalloc(PHP_TAG_BUF_SIZE+1); - tp = tbuf; - } else { - tbuf = tp = NULL; - } - - while (i < len) { - switch (c) { - case '<': - if (isspace(*(p + 1))) { - goto reg_char; - } - if (state == 0) { - lc = '<'; - state = 1; - if (allow) { - *(tp++) = '<'; - } - } else if (state == 1) { - depth++; - } - break; - - case '(': - if (state == 2) { - if (lc != '"' && lc != '\'') { - lc = '('; - br++; - } - } else if (allow && state == 1) { - *(tp++) = c; - } else if (state == 0) { - *(rp++) = c; - } - break; - - case ')': - if (state == 2) { - if (lc != '"' && lc != '\'') { - lc = ')'; - br--; - } - } else if (allow && state == 1) { - *(tp++) = c; - } else if (state == 0) { - *(rp++) = c; - } - break; - - case '>': - if (depth) { - depth--; - break; - } - - switch (state) { - case 1: /* HTML/XML */ - lc = '>'; - state = 0; - if (allow) { - *(tp++) = '>'; - *tp='\0'; - if (php_tag_find(tbuf, tp-tbuf, allow)) { - memcpy(rp, tbuf, tp-tbuf); - rp += tp-tbuf; - } - tp = tbuf; - } - break; - - case 2: /* PHP */ - if (!br && lc != '\"' && *(p-1) == '?') { - state = 0; - tp = tbuf; - } - break; - - case 3: /* JavaScript/CSS/etc... */ - if (*(p-1) == '-' && *(p-2) == '-') { - state = 0; - tp = tbuf; - } - break; - - default: - *(rp++) = c; - break; - } - break; - - case '"': - case '\'': - if (state == 2 && *(p-1) != '\\') { - if (lc == c) { - lc = '\0'; - } else if (lc != '\\') { - lc = c; - } - } else if (state == 0) { - *(rp++) = c; - } else if (allow && state == 1) { - *(tp++) = c; - } - break; - - case '!': - /* JavaScript & Other HTML scripting languages */ - if (state == 1 && *(p-1) == '<') { - state = 3; - lc = c; - } else { - if (state == 0) { - *(rp++) = c; - } else if (allow && state == 1) { - *(tp++) = c; - if ( (tp-tbuf) >= PHP_TAG_BUF_SIZE ) { - /* prevent buffer overflows */ - tp = tbuf; - } - } - } - break; - - case '?': - - if (state == 1 && *(p-1)=='<') { - br=0; - state=2; - break; - } - - case 'E': - case 'e': - /* !DOCTYPE exception */ - if (state==3 && p > buf+6 - && tolower(*(p-1)) == 'p' - && tolower(*(p-2)) == 'y' - && tolower(*(p-3)) == 't' - && tolower(*(p-4)) == 'c' - && tolower(*(p-5)) == 'o' - && tolower(*(p-6)) == 'd') { - state = 1; - break; - } - /* fall-through */ - - case 'l': - - /* swm: If we encounter '<?xml' then we shouldn't be in - * state == 2 (PHP). Switch back to HTML. - */ - - if (state == 2 && p > buf+2 && *(p-1) == 'm' && *(p-2) == 'x') { - state = 1; - break; - } - - /* fall-through */ - default: -reg_char: - if (state == 0) { - *(rp++) = c; - } else if (allow && state == 1) { - *(tp++) = c; - if ( (tp-tbuf) >= PHP_TAG_BUF_SIZE ) { /* no buffer overflows */ - tp = tbuf; - } - } - break; - } - c = *(++p); - i++; - } - if (rp < rbuf + len) { - *rp = '\0'; - } - efree(buf); - if (allow) - efree(tbuf); - if (stateptr) - *stateptr = state; - - return (size_t)(rp - rbuf); -} -/* }}} */ - -/* {{{ proto string str_repeat(string input, int mult) - Returns the input string repeat mult times */ -PHP_FUNCTION(str_repeat) -{ - zval **input_str; /* Input string */ - zval **mult; /* Multiplier */ - char *result; /* Resulting string */ - int result_len; /* Length of the resulting string */ - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &input_str, &mult) == FAILURE) { - WRONG_PARAM_COUNT; - } - - /* Make sure we're dealing with proper types */ - convert_to_string_ex(input_str); - convert_to_long_ex(mult); - - if (Z_LVAL_PP(mult) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Second argument has to be greater than or equal to 0."); - return; - } - - /* Don't waste our time if it's empty */ - if (Z_STRLEN_PP(input_str) == 0) - RETURN_STRINGL(empty_string, 0, 1); - - /* ... or if the multiplier is zero */ - if (Z_LVAL_PP(mult) == 0) - RETURN_STRINGL(empty_string, 0, 1); - - /* Initialize the result string */ - result_len = Z_STRLEN_PP(input_str) * Z_LVAL_PP(mult); - result = (char *)emalloc(result_len + 1); - - /* Heavy optimization for situations where input string is 1 byte long */ - if (Z_STRLEN_PP(input_str) == 1) { - memset(result, *(Z_STRVAL_PP(input_str)), Z_LVAL_PP(mult)); - } else { - char *s, *e, *ee; - int l=0; - memcpy(result, Z_STRVAL_PP(input_str), Z_STRLEN_PP(input_str)); - s = result; - e = result + Z_STRLEN_PP(input_str); - ee = result + result_len; - - while (e<ee) { - l = (e-s) < (ee-e) ? (e-s) : (ee-e); - memmove(e, s, l); - e += l; - } - } - - result[result_len] = '\0'; - - RETURN_STRINGL(result, result_len, 0); -} -/* }}} */ - -/* {{{ proto mixed count_chars(string input [, int mode]) - Returns info about what characters are used in input */ -PHP_FUNCTION(count_chars) -{ - zval **input, **mode; - int chars[256]; - int ac=ZEND_NUM_ARGS(); - int mymode=0; - unsigned char *buf; - int len, inx; - char retstr[256]; - int retlen=0; - - if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &input, &mode) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(input); - - if (ac == 2) { - convert_to_long_ex(mode); - mymode = Z_LVAL_PP(mode); - - if (mymode < 0 || mymode > 4) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown mode."); - RETURN_FALSE; - } - } - - len = Z_STRLEN_PP(input); - buf = (unsigned char *) Z_STRVAL_PP(input); - memset((void*) chars, 0, sizeof(chars)); - - while (len > 0) { - chars[*buf]++; - buf++; - len--; - } - - if (mymode < 3) { - array_init(return_value); - } - - for (inx = 0; inx < 256; inx++) { - switch (mymode) { - case 0: - add_index_long(return_value, inx, chars[inx]); - break; - case 1: - if (chars[inx] != 0) { - add_index_long(return_value, inx, chars[inx]); - } - break; - case 2: - if (chars[inx] == 0) { - add_index_long(return_value, inx, chars[inx]); - } - break; - case 3: - if (chars[inx] != 0) { - retstr[retlen++] = inx; - } - break; - case 4: - if (chars[inx] == 0) { - retstr[retlen++] = inx; - } - break; - } - } - - if (mymode >= 3 && mymode <= 4) { - RETURN_STRINGL(retstr, retlen, 1); - } -} -/* }}} */ - -/* {{{ php_strnatcmp - */ -static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case) -{ - zval **s1, **s2; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(s1); - convert_to_string_ex(s2); - - RETURN_LONG(strnatcmp_ex(Z_STRVAL_PP(s1), Z_STRLEN_PP(s1), - Z_STRVAL_PP(s2), Z_STRLEN_PP(s2), - fold_case)); -} -/* }}} */ - -/* {{{ proto int strnatcmp(string s1, string s2) - Returns the result of string comparison using 'natural' algorithm */ -PHP_FUNCTION(strnatcmp) -{ - php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto array localeconv(void) - Returns numeric formatting information based on the current locale */ -PHP_FUNCTION(localeconv) -{ - zval *grouping, *mon_grouping; - int len, i; - - /* We don't need no stinkin' parameters... */ - if (ZEND_NUM_ARGS() > 0) { - WRONG_PARAM_COUNT; - } - - MAKE_STD_ZVAL(grouping); - MAKE_STD_ZVAL(mon_grouping); - - array_init(return_value); - array_init(grouping); - array_init(mon_grouping); - -#ifdef HAVE_LOCALECONV - { - struct lconv currlocdata; - - localeconv_r( &currlocdata ); - - /* Grab the grouping data out of the array */ - len = strlen(currlocdata.grouping); - - for (i = 0; i < len; i++) { - add_index_long(grouping, i, currlocdata.grouping[i]); - } - - /* Grab the monetary grouping data out of the array */ - len = strlen(currlocdata.mon_grouping); - - for (i = 0; i < len; i++) { - add_index_long(mon_grouping, i, currlocdata.mon_grouping[i]); - } - - add_assoc_string(return_value, "decimal_point", currlocdata.decimal_point, 1); - add_assoc_string(return_value, "thousands_sep", currlocdata.thousands_sep, 1); - add_assoc_string(return_value, "int_curr_symbol", currlocdata.int_curr_symbol, 1); - add_assoc_string(return_value, "currency_symbol", currlocdata.currency_symbol, 1); - add_assoc_string(return_value, "mon_decimal_point", currlocdata.mon_decimal_point, 1); - add_assoc_string(return_value, "mon_thousands_sep", currlocdata.mon_thousands_sep, 1); - add_assoc_string(return_value, "positive_sign", currlocdata.positive_sign, 1); - add_assoc_string(return_value, "negative_sign", currlocdata.negative_sign, 1); - add_assoc_long( return_value, "int_frac_digits", currlocdata.int_frac_digits ); - add_assoc_long( return_value, "frac_digits", currlocdata.frac_digits ); - add_assoc_long( return_value, "p_cs_precedes", currlocdata.p_cs_precedes ); - add_assoc_long( return_value, "p_sep_by_space", currlocdata.p_sep_by_space ); - add_assoc_long( return_value, "n_cs_precedes", currlocdata.n_cs_precedes ); - add_assoc_long( return_value, "n_sep_by_space", currlocdata.n_sep_by_space ); - add_assoc_long( return_value, "p_sign_posn", currlocdata.p_sign_posn ); - add_assoc_long( return_value, "n_sign_posn", currlocdata.n_sign_posn ); - } -#else - /* Ok, it doesn't look like we have locale info floating around, so I guess it - wouldn't hurt to just go ahead and return the POSIX locale information? */ - - add_index_long(grouping, 0, -1); - add_index_long(mon_grouping, 0, -1); - - add_assoc_string(return_value, "decimal_point", "\x2E", 1); - add_assoc_string(return_value, "thousands_sep", "", 1); - add_assoc_string(return_value, "int_curr_symbol", "", 1); - add_assoc_string(return_value, "currency_symbol", "", 1); - add_assoc_string(return_value, "mon_decimal_point", "\x2E", 1); - add_assoc_string(return_value, "mon_thousands_sep", "", 1); - add_assoc_string(return_value, "positive_sign", "", 1); - add_assoc_string(return_value, "negative_sign", "", 1); - add_assoc_long( return_value, "int_frac_digits", CHAR_MAX ); - add_assoc_long( return_value, "frac_digits", CHAR_MAX ); - add_assoc_long( return_value, "p_cs_precedes", CHAR_MAX ); - add_assoc_long( return_value, "p_sep_by_space", CHAR_MAX ); - add_assoc_long( return_value, "n_cs_precedes", CHAR_MAX ); - add_assoc_long( return_value, "n_sep_by_space", CHAR_MAX ); - add_assoc_long( return_value, "p_sign_posn", CHAR_MAX ); - add_assoc_long( return_value, "n_sign_posn", CHAR_MAX ); -#endif - - zend_hash_update(Z_ARRVAL_P(return_value), "grouping", 9, &grouping, sizeof(zval *), NULL); - zend_hash_update(Z_ARRVAL_P(return_value), "mon_grouping", 13, &mon_grouping, sizeof(zval *), NULL); -} -/* }}} */ - -/* {{{ proto int strnatcasecmp(string s1, string s2) - Returns the result of case-insensitive string comparison using 'natural' algorithm */ -PHP_FUNCTION(strnatcasecmp) -{ - php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ proto int substr_count(string haystack, string needle) - Returns the number of times a substring occurs in the string */ -PHP_FUNCTION(substr_count) -{ - zval **haystack, **needle; - int count = 0; - char *p, *endp, cmp; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(haystack); - convert_to_string_ex(needle); - - if (Z_STRLEN_PP(needle) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty substring."); - RETURN_FALSE; - } - - p = Z_STRVAL_PP(haystack); - endp = p + Z_STRLEN_PP(haystack); - - if (Z_STRLEN_PP(needle) == 1) { - cmp = Z_STRVAL_PP(needle)[0]; - - while (p < endp) { - if (*(p++) == cmp) { - count++; - } - } - } else { - while ((p = php_memnstr(p, Z_STRVAL_PP(needle), Z_STRLEN_PP(needle), endp))) { - p += Z_STRLEN_PP(needle); - count++; - } - } - - RETURN_LONG(count); -} -/* }}} */ - -/* {{{ proto string str_pad(string input, int pad_length [, string pad_string [, int pad_type]]) - Returns input string padded on the left or right to specified length with pad_string */ -PHP_FUNCTION(str_pad) -{ - /* Input arguments */ - zval **input, /* Input string */ - **pad_length, /* Length to pad to */ - **pad_string, /* Padding string */ - **pad_type; /* Padding type (left/right/both) */ - - /* Helper variables */ - int num_pad_chars; /* Number of padding characters (total - input size) */ - char *result = NULL; /* Resulting string */ - int result_len = 0; /* Length of the resulting string */ - char *pad_str_val = " "; /* Pointer to padding string */ - int pad_str_len = 1; /* Length of the padding string */ - int pad_type_val = STR_PAD_RIGHT; /* The padding type value */ - int i, left_pad=0, right_pad=0; - - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 4 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &pad_length, &pad_string, &pad_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - - /* Perform initial conversion to expected data types. */ - convert_to_string_ex(input); - convert_to_long_ex(pad_length); - - num_pad_chars = Z_LVAL_PP(pad_length) - Z_STRLEN_PP(input); - - /* If resulting string turns out to be shorter than input string, - we simply copy the input and return. */ - if (num_pad_chars < 0) { - *return_value = **input; - zval_copy_ctor(return_value); - return; - } - - /* Setup the padding string values if specified. */ - if (ZEND_NUM_ARGS() > 2) { - convert_to_string_ex(pad_string); - if (Z_STRLEN_PP(pad_string) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Padding string cannot be empty."); - return; - } - pad_str_val = Z_STRVAL_PP(pad_string); - pad_str_len = Z_STRLEN_PP(pad_string); - - if (ZEND_NUM_ARGS() > 3) { - convert_to_long_ex(pad_type); - pad_type_val = Z_LVAL_PP(pad_type); - if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH."); - return; - } - } - } - - result = (char *)emalloc(Z_STRLEN_PP(input) + num_pad_chars + 1); - - /* We need to figure out the left/right padding lengths. */ - switch (pad_type_val) { - case STR_PAD_RIGHT: - left_pad = 0; - right_pad = num_pad_chars; - break; - - case STR_PAD_LEFT: - left_pad = num_pad_chars; - right_pad = 0; - break; - - case STR_PAD_BOTH: - left_pad = num_pad_chars / 2; - right_pad = num_pad_chars - left_pad; - break; - } - - /* First we pad on the left. */ - for (i = 0; i < left_pad; i++) - result[result_len++] = pad_str_val[i % pad_str_len]; - - /* Then we copy the input string. */ - memcpy(result + result_len, Z_STRVAL_PP(input), Z_STRLEN_PP(input)); - result_len += Z_STRLEN_PP(input); - - /* Finally, we pad on the right. */ - for (i = 0; i < right_pad; i++) - result[result_len++] = pad_str_val[i % pad_str_len]; - - result[result_len] = '\0'; - - RETURN_STRINGL(result, result_len, 0); -} -/* }}} */ - -/* {{{ proto mixed sscanf(string str, string format [, string ...]) - Implements an ANSI C compatible sscanf */ -PHP_FUNCTION(sscanf) -{ - zval ***args; - int result; - int argc = ZEND_NUM_ARGS(); - - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - args = (zval ***) emalloc(argc * sizeof(zval **)); - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(args[0]); - convert_to_string_ex(args[1]); - - result = php_sscanf_internal(Z_STRVAL_PP(args[0]), - Z_STRVAL_PP(args[1]), - argc, args, - 2, &return_value TSRMLS_CC); - efree(args); - - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { - WRONG_PARAM_COUNT; - } -} -/* }}} */ - -static char rot13_from[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static char rot13_to[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"; - -/* {{{ proto string str_rot13(string str) - Perform the rot13 transform on a string */ -PHP_FUNCTION(str_rot13) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - *return_value = **arg; - zval_copy_ctor(return_value); - - php_strtr(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), rot13_from, rot13_to, 52); -} -/* }}} */ - - -static void php_string_shuffle(char *str, long len TSRMLS_DC) -{ - long n_elems, rnd_idx, n_left; - char temp; - /* The implementation is stolen from array_data_shuffle */ - /* Thus the characteristics of the randomization are the same */ - n_elems = len; - - if (n_elems <= 1) { - return; - } - - n_left = n_elems; - - while (--n_left) { - rnd_idx = php_rand(TSRMLS_C); - RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX); - if (rnd_idx != n_left) { - temp = str[n_left]; - str[n_left] = str[rnd_idx]; - str[rnd_idx] = temp; - } - } -} - - -/* {{{ proto void str_shuffle(string str) - Shuffles string. One permutation of all possible is created */ -PHP_FUNCTION(str_shuffle) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - *return_value = **arg; - zval_copy_ctor(return_value); - if (Z_STRLEN_P(return_value) > 1) { - php_string_shuffle(Z_STRVAL_P(return_value), (long) Z_STRLEN_P(return_value) TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto void str_word_count(string str, [int format]) - Counts the number of words inside a string. If format of 1 is specified, - then the function will return an array containing all the words - found inside the string. If format of 2 is specified, then the function - will return an associated array where the position of the word is the key - and the word itself is the value. - - For the purpose of this function, 'word' is defined as a locale dependent - string containing alphabetic characters, which also may contain, but not start - with "'" and "-" characters. -*/ -PHP_FUNCTION(str_word_count) -{ - zval **str, **o_format; - char *s, *e, *p, *buf; - int word_count = 0; - int type = 0; - int n_args = ZEND_NUM_ARGS(); - - if (n_args > 2 || n_args < 1 || zend_get_parameters_ex(n_args, &str, &o_format) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (n_args == 2) { - convert_to_long_ex(o_format); - type = Z_LVAL_PP(o_format); - - if (type != 1 && type != 2) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified format parameter, '%d' is invalid.", type); - RETURN_FALSE; - } - } - - convert_to_string_ex(str); - - p = s = Z_STRVAL_PP(str); - e = Z_STRVAL_PP(str) + Z_STRLEN_PP(str); - - if (type == 1 || type == 2) { - array_init(return_value); - } - - while (p < e) { - if (isalpha(*p++)) { - s = p - 1; - while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1)))) { - p++; - } - - switch (type) - { - case 1: - buf = estrndup(s, (p-s)); - add_next_index_stringl(return_value, buf, (p-s), 1); - efree(buf); - break; - case 2: - buf = estrndup(s, (p-s)); - add_index_stringl(return_value, (s - Z_STRVAL_PP(str)), buf, p-s, 1); - efree(buf); - break; - default: - word_count++; - break; - } - } - } - - if (!type) { - RETURN_LONG(word_count); - } -} - -/* }}} */ - -#if HAVE_STRFMON -/* {{{ proto string money_format(string format , float value) - Convert monetary value(s) to string */ -PHP_FUNCTION(money_format) -{ - int format_len = 0, str_len; - char *format, *str; - double value; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &format, &format_len, &value) == FAILURE) { - return; - } - - str_len = format_len + 1024; - str = emalloc(str_len); - str_len = strfmon(str, str_len, format, value); - str[str_len] = 0; - - RETURN_STRINGL(erealloc(str, str_len + 1), str_len, 0); -} -/* }}} */ -#endif - -/* {{{ proto array str_split(string str [, int split_length]) - Convert a string to an array. If split_length is specified, break the string down into chunks each split_length characters long. */ -PHP_FUNCTION(str_split) -{ - char *str; - int str_len; - long split_length = 1; - char *p; - int n_reg_segments; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &split_length) == FAILURE) { - return; - } - - if (split_length <= 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The the length of each segment must be greater then zero."); - RETURN_FALSE; - } - - array_init(return_value); - - n_reg_segments = floor(str_len / split_length); - p = str; - - while (n_reg_segments-- > 0) { - add_next_index_stringl(return_value, p, split_length, 1); - p += split_length; - } - - if (p != (str + str_len)) { - add_next_index_stringl(return_value, p, (str + str_len - p), 1); - } -} -/* }}} */ - -/* {{{ proto array strpbrk(string haystack, string char_list) - Search a string for any of a set of characters */ -PHP_FUNCTION(strpbrk) -{ - char *haystack, *char_list; - int haystack_len, char_list_len; - char *p; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &haystack, &haystack_len, &char_list, &char_list_len) == FAILURE) { - RETURN_FALSE; - } - - if (!char_list_len) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The character list cannot be empty."); - RETURN_FALSE; - } - - if ((p = strpbrk(haystack, char_list))) { - RETURN_STRINGL(p, (haystack + haystack_len - p), 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * 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/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c deleted file mode 100644 index 4e5500be14..0000000000 --- a/ext/standard/strnatcmp.c +++ /dev/null @@ -1,175 +0,0 @@ -/* -*- mode: c; c-file-style: "k&r" -*- - - Modified for PHP by Andrei Zmievski <andrei@ispi.net> - - strnatcmp.c -- Perform 'natural order' comparisons of strings in C. - Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au> - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#include <ctype.h> -#include <string.h> -#include <assert.h> -#include <stdio.h> - -#include "php.h" -#include "php_string.h" - -#if defined(__GNUC__) -# define UNUSED __attribute__((__unused__)) -#else -# define UNUSED -#endif - -#if 0 -static char const *version UNUSED = - "$Id$"; -#endif -/* {{{ compare_right - */ -static int -compare_right(char const **a, char const *aend, char const **b, char const *bend) -{ - int bias = 0; - - /* The longest run of digits wins. That aside, the greatest - value wins, but we can't know that it will until we've scanned - both numbers to know that they have the same magnitude, so we - remember it in BIAS. */ - for(;; (*a)++, (*b)++) { - if ((*a == aend || !isdigit((int)**a)) && - (*b == bend || !isdigit((int)**b))) - return bias; - else if (*a == aend || !isdigit((int)**a)) - return -1; - else if (*b == bend || !isdigit((int)**b)) - return +1; - else if (**a < **b) { - if (!bias) - bias = -1; - } else if (**a > **b) { - if (!bias) - bias = +1; - } - } - - return 0; -} -/* }}} */ - -/* {{{ compare_left - */ -static int -compare_left(char const **a, char const *aend, char const **b, char const *bend) -{ - /* Compare two left-aligned numbers: the first to have a - different value wins. */ - for(;; (*a)++, (*b)++) { - if ((*a == aend || !isdigit((int)**a)) && - (*b == bend || !isdigit((int)**b))) - return 0; - else if (*a == aend || !isdigit((int)**a)) - return -1; - else if (*b == bend || !isdigit((int)**b)) - return +1; - else if (**a < **b) - return -1; - else if (**a > **b) - return +1; - } - - return 0; -} -/* }}} */ - -/* {{{ strnatcmp_ex - */ -PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case) -{ - char ca, cb; - char const *ap, *bp; - char const *aend = a + a_len, - *bend = b + b_len; - int fractional, result; - - if (a_len == 0 || b_len == 0) - return a_len - b_len; - - ap = a; - bp = b; - while (1) { - ca = *ap; cb = *bp; - - /* skip over leading spaces or zeros */ - while (isspace((int)ca)) - ca = *++ap; - - while (isspace((int)cb)) - cb = *++bp; - - /* process run of digits */ - if (isdigit((int)ca) && isdigit((int)cb)) { - fractional = (ca == '0' || cb == '0'); - - if (fractional) - result = compare_left(&ap, aend, &bp, bend); - else - result = compare_right(&ap, aend, &bp, bend); - - if (result != 0) - return result; - else if (ap == aend && bp == bend) - /* End of the strings. Let caller sort them out. */ - return 0; - else { - /* Keep on comparing from the current point. */ - ca = *ap; cb = *bp; - } - } - - if (fold_case) { - ca = toupper(ca); - cb = toupper(cb); - } - - if (ca < cb) - return -1; - else if (ca > cb) - return +1; - - ++ap; ++bp; - if (ap == aend && bp == bend) - /* The strings compare the same. Perhaps the caller - will want to call strcmp to break the tie. */ - return 0; - else if (ap == aend) - return -1; - else if (bp == bend) - return 1; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/sunfuncs.c b/ext/standard/sunfuncs.c deleted file mode 100644 index 58bab3258e..0000000000 --- a/ext/standard/sunfuncs.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Moshe Doron <mosdoron@netvision.net.il> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - The sun position algorithm taken from the 'US Naval Observatory's - Almanac for Computers', implemented by Ken Bloom <kekabloom@ucdavis.edu> - for the zmanim project <http://sourceforge.net/projects/zmanim/> - and finally converted to C by Moshe Doron <mosdoron@netvision.net.il>. -*/ - -#include "php.h" -#include "php_sunfuncs.h" -#include "datetime.h" -#include "php_ini.h" - -#include <assert.h> -#include <math.h> -#include <stdlib.h> - -/* {{{ macros and constants - */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#define to_rad(degrees) (degrees * M_PI / 180) -#define to_rad_with_min(degrees) (degrees + minutes / 60) -#define to_deg(rad) (rad * 180 / M_PI) -/* }}} */ - -/* {{{ php_sunrise_sunset - returns time in UTC */ -static double php_sunrise_sunset(long N, double latitude, double longitude, double zenith, int calc_sunset) -{ - double lngHour, t, M, L, Lx, RA, RAx, Lquadrant, RAquadrant, sinDec, cosDec, cosH, H, T, UT, UTx; - - /* step 1: First calculate the day of the year - int N = theday - date(1, 1, theday.year()) + 1; - */ - - /* step 2: convert the longitude to hour value and calculate an approximate time */ - lngHour = longitude / 15; - - /* use 18 for sunset instead of 6 */ - if (calc_sunset) { - t = (double) N + ((18 - lngHour) / 24); /* Sunset */ - } else { - t = (double) N + ((6 - lngHour) / 24); /* Sunrise */ - } - - /* step 3: calculate the sun's mean anomaly */ - M = (0.9856 * t) - 3.289; - - /* step 4: calculate the sun's true longitude */ - L = M + (1.916 * sin(to_rad(M))) + (0.020 * sin (to_rad(2 * M))) + 282.634; - - while (L < 0) { - Lx = L + 360; - assert (Lx != L); /* askingtheguru: realy needed? */ - L = Lx; - } - - while (L >= 360) { - Lx = L - 360; - assert (Lx != L); /* askingtheguru: realy needed? */ - L = Lx; - } - - /* step 5a: calculate the sun's right ascension */ - RA = to_deg(atan(0.91764 * tan(to_rad(L)))); - - while (RA < 0) { - RAx = RA + 360; - assert (RAx != RA); /* askingtheguru: realy needed? */ - RA = RAx; - } - - while (RA >= 360) { - RAx = RA - 360; - assert (RAx != RA); /* askingtheguru: realy needed? */ - RA = RAx; - } - - /* step 5b: right ascension value needs to be in the same quadrant as L */ - Lquadrant = floor(L / 90) * 90; - RAquadrant = floor(RA / 90) * 90; - RA = RA + (Lquadrant - RAquadrant); - - /* step 5c: right ascension value needs to be converted into hours */ - RA /= 15; - - /* step 6: calculate the sun's declination */ - sinDec = 0.39782 * sin(to_rad(L)); - cosDec = cos(asin(sinDec)); - - /* step 7a: calculate the sun's local hour angle */ - cosH = (cos(to_rad(zenith)) - (sinDec * sin(to_rad(latitude)))) / (cosDec * cos(to_rad(latitude))); - - /* XXX: What's the use of this block.. ? - * if (!calc_sunset && cosH > 1 || calc_sunset && cosH < -1) { - * throw doesnthappen(); - * } - */ - - /* step 7b: finish calculating H and convert into hours */ - if (calc_sunset) { - H = to_deg(acos(cosH)); /* Sunset */ - } else { - H = 360 - to_deg(acos(cosH)); /* Sunrise */ - } - H = H / 15; - - /* step 8: calculate local mean time */ - T = H + RA - (0.06571 * t) - 6.622; - - /* step 9: convert to UTC */ - UT = T - lngHour; - - while (UT < 0) { - UTx = UT + 24; - assert (UTx != UT); /* askingtheguru: realy needed? */ - UT = UTx; - } - - while (UT >= 24) { - UTx = UT - 24; - assert (UTx != UT); /* askingtheguru: realy needed? */ - UT = UTx; - } - - return UT; -} -/* }}} */ - -/* {{{ php_do_date_sunrise_sunset - * Common for date_sunrise() and date_sunset() functions - */ -static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset) -{ - zval *date; - double latitude, longitude, zenith, gmt_offset, ret; - int time, N, retformat; - char retstr[6]; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ldddd", &date, &retformat, &latitude, &longitude, &zenith, &gmt_offset) == FAILURE) { - RETURN_FALSE; - } - - switch (Z_TYPE_P(date)) { - case IS_LONG: - time = Z_LVAL_P(date); - break; - case IS_STRING: - /* todo: more user friendly format */ - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "date must be timestamp for now"); - RETURN_FALSE; - } - - N = php_idate('z', time, 0) + 1; - - switch (ZEND_NUM_ARGS()) { - case 1: - retformat = SUNFUNCS_RET_STRING; - case 2: - latitude = INI_FLT("date.default_latitude"); - case 3: - longitude = INI_FLT("date.default_longitude"); - case 4: - if (calc_sunset) { - zenith = INI_FLT("date.sunset_zenith"); - } else { - zenith = INI_FLT("date.sunrise_zenith"); - } - case 5: - gmt_offset = php_idate('Z', time, 0) / 3600; - default: - break; - } - - ret = php_sunrise_sunset(N, latitude, longitude, zenith, calc_sunset) + gmt_offset; - - switch (retformat) { - case SUNFUNCS_RET_TIMESTAMP: - RETURN_LONG((int) (time - (time % (24 * 3600))) + (int) (60 * ret)); - break; - case SUNFUNCS_RET_STRING: - N = (int) ret; - sprintf(retstr, "%02d:%02d", N, (int) (60 * (ret - (double) N))); - RETVAL_STRINGL(retstr, 5, 1); - break; - case SUNFUNCS_RET_DOUBLE: - RETURN_DOUBLE(ret); - break; - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid format"); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto mixed date_sunrise(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]]) - Returns time of sunrise for a given day & location */ -PHP_FUNCTION(date_sunrise) -{ - php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto mixed date_sunset(mixed time [, int format [, float latitude [, float longitude [, float zenith [, float gmt_offset]]]]]) - Returns time of sunset for a given day & location */ -PHP_FUNCTION(date_sunset) -{ - php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c deleted file mode 100644 index 14294fb3eb..0000000000 --- a/ext/standard/syslog.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#ifdef HAVE_SYSLOG_H -#include "php_ini.h" -#include "zend_globals.h" - -#include <stdlib.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <string.h> -#include <errno.h> - -#include <stdio.h> -#include "basic_functions.h" -#include "php_ext_syslog.h" - -static void start_syslog(TSRMLS_D); - -/* {{{ PHP_MINIT_FUNCTION - */ -PHP_MINIT_FUNCTION(syslog) -{ - /* error levels */ - REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */ - REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */ - REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */ - REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT); - /* facility: type of program logging the message */ - REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */ - REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */ - REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */ - REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT); -#ifdef LOG_NEWS - /* No LOG_NEWS on HP-UX */ - REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */ -#endif -#ifdef LOG_UUCP - /* No LOG_UUCP on HP-UX */ - REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef LOG_CRON - /* apparently some systems don't have this one */ - REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef LOG_AUTHPRIV - /* AIX doesn't have LOG_AUTHPRIV */ - REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT); -#endif -#if !defined(PHP_WIN32) && !defined(NETWARE) - REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT); -#endif - /* options */ - REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT); -#ifdef LOG_NOWAIT - REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT); -#endif -#ifdef LOG_PERROR - /* AIX doesn't have LOG_PERROR */ - REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/ -#endif - - return SUCCESS; -} -/* }}} */ - -PHP_RINIT_FUNCTION(syslog) -{ - if (INI_INT("define_syslog_variables")) { - start_syslog(TSRMLS_C); - } else { - BG(syslog_started)=0; - } - BG(syslog_device)=NULL; - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(syslog) -{ - if (BG(syslog_device)) { - efree(BG(syslog_device)); - } - return SUCCESS; -} - -/* {{{ start_syslog - */ -static void start_syslog(TSRMLS_D) -{ - /* error levels */ - SET_VAR_LONG("LOG_EMERG", LOG_EMERG); /* system unusable */ - SET_VAR_LONG("LOG_ALERT", LOG_ALERT); /* immediate action required */ - SET_VAR_LONG("LOG_CRIT", LOG_CRIT); /* critical conditions */ - SET_VAR_LONG("LOG_ERR", LOG_ERR); - SET_VAR_LONG("LOG_WARNING", LOG_WARNING); - SET_VAR_LONG("LOG_NOTICE", LOG_NOTICE); - SET_VAR_LONG("LOG_INFO", LOG_INFO); - SET_VAR_LONG("LOG_DEBUG", LOG_DEBUG); - /* facility: type of program logging the message */ - SET_VAR_LONG("LOG_KERN", LOG_KERN); - SET_VAR_LONG("LOG_USER", LOG_USER); /* generic user level */ - SET_VAR_LONG("LOG_MAIL", LOG_MAIL); /* log to email */ - SET_VAR_LONG("LOG_DAEMON", LOG_DAEMON); /* other system daemons */ - SET_VAR_LONG("LOG_AUTH", LOG_AUTH); - SET_VAR_LONG("LOG_SYSLOG", LOG_SYSLOG); - SET_VAR_LONG("LOG_LPR", LOG_LPR); -#ifdef LOG_NEWS - /* No LOG_NEWS on HP-UX */ - SET_VAR_LONG("LOG_NEWS", LOG_NEWS); /* usenet new */ -#endif -#ifdef LOG_UUCP - /* No LOG_UUCP on HP-UX */ - SET_VAR_LONG("LOG_UUCP", LOG_UUCP); -#endif -#ifdef LOG_CRON - /* apparently some systems don't have this one */ - SET_VAR_LONG("LOG_CRON", LOG_CRON); -#endif -#ifdef LOG_AUTHPRIV - /* AIX doesn't have LOG_AUTHPRIV */ - SET_VAR_LONG("LOG_AUTHPRIV", LOG_AUTHPRIV); -#endif -#if !defined(PHP_WIN32) && !defined(NETWARE) - SET_VAR_LONG("LOG_LOCAL0", LOG_LOCAL0); - SET_VAR_LONG("LOG_LOCAL1", LOG_LOCAL1); - SET_VAR_LONG("LOG_LOCAL2", LOG_LOCAL2); - SET_VAR_LONG("LOG_LOCAL3", LOG_LOCAL3); - SET_VAR_LONG("LOG_LOCAL4", LOG_LOCAL4); - SET_VAR_LONG("LOG_LOCAL5", LOG_LOCAL5); - SET_VAR_LONG("LOG_LOCAL6", LOG_LOCAL6); - SET_VAR_LONG("LOG_LOCAL7", LOG_LOCAL7); -#endif - /* options */ - SET_VAR_LONG("LOG_PID", LOG_PID); - SET_VAR_LONG("LOG_CONS", LOG_CONS); - SET_VAR_LONG("LOG_ODELAY", LOG_ODELAY); - SET_VAR_LONG("LOG_NDELAY", LOG_NDELAY); -#ifdef LOG_NOWAIT - /* BeOS doesn't have LOG_NOWAIT */ - SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT); -#endif -#ifdef LOG_PERROR - /* AIX doesn't have LOG_PERROR */ - SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/ -#endif - - BG(syslog_started)=1; -} -/* }}} */ - -/* {{{ proto void define_syslog_variables(void) - Initializes all syslog-related variables */ -PHP_FUNCTION(define_syslog_variables) -{ - if (ZEND_NUM_ARGS() != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects no parameters, %d given", ZEND_NUM_ARGS()); - return; - } - - if (!BG(syslog_started)) { - start_syslog(TSRMLS_C); - } -} -/* }}} */ - -/* {{{ proto bool openlog(string ident, int option, int facility) - Open connection to system logger */ -/* - ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1); - ** Syslog($LOG_EMERG, "help me!") - ** CloseLog(); - */ -PHP_FUNCTION(openlog) -{ - char *ident; - long option, facility; - int ident_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident, - &ident_len, &option, &facility) == FAILURE) { - return; - } - if (BG(syslog_device)) { - efree(BG(syslog_device)); - } - BG(syslog_device) = estrndup(ident, ident_len); - openlog(BG(syslog_device), option, facility); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool closelog(void) - Close connection to system logger */ -PHP_FUNCTION(closelog) -{ - if (ZEND_NUM_ARGS() != 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "expects no parameters, %d given", ZEND_NUM_ARGS()); - return; - } - - closelog(); - if (BG(syslog_device)) { - efree(BG(syslog_device)); - BG(syslog_device)=NULL; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool syslog(int priority, string message) - Generate a system log message */ -PHP_FUNCTION(syslog) -{ - long priority; - char *message; - int message_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority, - &message, &message_len) == FAILURE) { - return; - } - - /* - * CAVEAT: if the message contains patterns such as "%s", - * this will cause problems. - */ - - php_syslog(priority, "%.500s", message); - RETURN_TRUE; -} -/* }}} */ - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/tests/aggregation/aggregate.lib b/ext/standard/tests/aggregation/aggregate.lib deleted file mode 100644 index 3799285f75..0000000000 --- a/ext/standard/tests/aggregation/aggregate.lib +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -class simple { - var $simple_prop = 100; - - function simple() - { - print "I'm alive!\n"; - } -} - -class helper { - var $my_prop = 5; - var $your_prop = array('init' => PHP_VERSION); - var $our_prop = '****'; - var $_priv_prop = null; - - function helper() - { - print "just trying to help\n"; - } - - function do_this() - { - print "I'm helping!\n"; - } - - function do_that() - { - print "I'm aggregating!\n"; - } - - function just_another_method() - { - print "yep, that's me\n"; - } - - function _private() - { - print "Don't touch me!\n"; - } - - function __wakeup() - { - } -} - -class mixin { - var $simple_prop = true; - var $mix = true; - - function mix_it() - { - print "mixing\n"; - } -} - -class moby { - function mix_it() - { - print "I'm redundant!\n"; - } -} - -?> diff --git a/ext/standard/tests/aggregation/aggregate.phpt b/ext/standard/tests/aggregation/aggregate.phpt deleted file mode 100644 index 46aa9133b6..0000000000 --- a/ext/standard/tests/aggregation/aggregate.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -aggregating everything ---FILE-- -<?php - -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate($obj, 'helper'); -$obj->do_this(); -$obj->do_that(); -print $obj->our_prop; - -?> ---EXPECT-- -I'm alive! -I'm helping! -I'm aggregating! -**** diff --git a/ext/standard/tests/aggregation/aggregate_methods.phpt b/ext/standard/tests/aggregation/aggregate_methods.phpt deleted file mode 100644 index b612881c59..0000000000 --- a/ext/standard/tests/aggregation/aggregate_methods.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -aggregating all methods ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_methods($obj, 'mixin'); -$obj->mix_it(); -print $obj->simple_prop."\n"; -print implode(',', get_class_methods($obj))."\n"; -print implode(',', array_keys(get_object_vars($obj)))."\n"; -aggregate_methods($obj, 'moby'); -$obj->mix_it(); - -?> ---EXPECT-- -I'm alive! -mixing -100 -simple,mix_it -simple_prop -mixing diff --git a/ext/standard/tests/aggregation/aggregate_methods_by_list.phpt b/ext/standard/tests/aggregation/aggregate_methods_by_list.phpt deleted file mode 100644 index 312a57d1b2..0000000000 --- a/ext/standard/tests/aggregation/aggregate_methods_by_list.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -aggregating methods specified in the list ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_methods_by_list($obj, 'helper', array('just_another_method')); -print implode(',', get_class_methods($obj))."\n"; -$obj2 = new simple(); -aggregate_methods_by_list($obj2, 'helper', array('just_another_method'), true); -print implode(',', get_class_methods($obj2))."\n"; -$obj->just_another_method(); -?> ---EXPECT-- -I'm alive! -simple,just_another_method -I'm alive! -simple,do_this,do_that -yep, that's me diff --git a/ext/standard/tests/aggregation/aggregate_methods_by_regexp.phpt b/ext/standard/tests/aggregation/aggregate_methods_by_regexp.phpt deleted file mode 100644 index 6525e50cff..0000000000 --- a/ext/standard/tests/aggregation/aggregate_methods_by_regexp.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -aggregating methods matching regular expression ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_methods_by_regexp($obj, 'helper', '/^do/'); -print implode(',', get_class_methods($obj))."\n"; -$obj2 = new simple(); -aggregate_methods_by_regexp($obj2, 'helper', '/^do/', true); -print implode(',', get_class_methods($obj2))."\n"; -?> ---EXPECT-- -I'm alive! -simple,do_this,do_that -I'm alive! -simple,just_another_method diff --git a/ext/standard/tests/aggregation/aggregate_properties.phpt b/ext/standard/tests/aggregation/aggregate_properties.phpt deleted file mode 100644 index 2a976c71a7..0000000000 --- a/ext/standard/tests/aggregation/aggregate_properties.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -aggregating all default properties ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_properties($obj, 'mixin'); -print implode(',', array_keys(get_object_vars($obj)))."\n"; -print $obj->simple_prop."\n"; -print implode(',', get_class_methods($obj))."\n"; -?> ---EXPECT-- -I'm alive! -simple_prop,mix -100 -simple diff --git a/ext/standard/tests/aggregation/aggregate_properties_by_list.phpt b/ext/standard/tests/aggregation/aggregate_properties_by_list.phpt deleted file mode 100644 index fa12d36bcb..0000000000 --- a/ext/standard/tests/aggregation/aggregate_properties_by_list.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -aggregating default properties specified in the list ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_properties_by_list($obj, 'helper', array('my_prop', 'our_prop')); -print implode(',', array_keys(get_object_vars($obj)))."\n"; -$obj2 = new simple(); -aggregate_properties_by_list($obj2, 'helper', array('my_prop'), true); -print implode(',', array_keys(get_object_vars($obj2)))."\n"; -?> ---EXPECT-- -I'm alive! -simple_prop,my_prop,our_prop -I'm alive! -simple_prop,your_prop,our_prop diff --git a/ext/standard/tests/aggregation/aggregate_properties_by_regexp.phpt b/ext/standard/tests/aggregation/aggregate_properties_by_regexp.phpt deleted file mode 100644 index 9a74f5536d..0000000000 --- a/ext/standard/tests/aggregation/aggregate_properties_by_regexp.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -aggregating default properties matching regular expression ---SKIPIF-- -<?php if (!function_exists('aggregate_properties_by_regexp')) print "skip"; ?> ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate_properties_by_regexp($obj, 'helper', '/^my/'); -print implode(',', array_keys(get_object_vars($obj)))."\n"; -$obj2 = new simple(); -aggregate_properties_by_regexp($obj2, 'helper', '/^my/', true); -print implode(',', array_keys(get_object_vars($obj2)))."\n"; -?> ---EXPECT-- -I'm alive! -simple_prop,my_prop -I'm alive! -simple_prop,your_prop,our_prop diff --git a/ext/standard/tests/aggregation/aggregation_info.phpt b/ext/standard/tests/aggregation/aggregation_info.phpt deleted file mode 100644 index 8dd943cbcc..0000000000 --- a/ext/standard/tests/aggregation/aggregation_info.phpt +++ /dev/null @@ -1,31 +0,0 @@ ---TEST-- -retrieving aggregation info ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate($obj, 'mixin'); -print_r(aggregation_info($obj)); -?> ---EXPECT-- -I'm alive! -Array -( - [mixin] => Array - ( - [methods] => Array - ( - [0] => mix_it - ) - - [properties] => Array - ( - [0] => mix - ) - - ) - -) diff --git a/ext/standard/tests/aggregation/deaggregate.phpt b/ext/standard/tests/aggregation/deaggregate.phpt deleted file mode 100644 index 5c551d75bd..0000000000 --- a/ext/standard/tests/aggregation/deaggregate.phpt +++ /dev/null @@ -1,72 +0,0 @@ ---TEST-- -deaggreating ---POST-- ---GET-- ---FILE-- -<?php -include "ext/standard/tests/aggregation/aggregate.lib"; - -$obj = new simple(); -aggregate($obj, 'helper'); -aggregate($obj, 'mixin'); -print_r(aggregation_info($obj)); -deaggregate($obj, 'helper'); -print_r(aggregation_info($obj)); -deaggregate($obj); -var_dump(aggregation_info($obj)); -?> ---EXPECT-- -I'm alive! -Array -( - [helper] => Array - ( - [methods] => Array - ( - [0] => do_this - [1] => do_that - [2] => just_another_method - ) - - [properties] => Array - ( - [0] => my_prop - [1] => your_prop - [2] => our_prop - ) - - ) - - [mixin] => Array - ( - [methods] => Array - ( - [0] => mix_it - ) - - [properties] => Array - ( - [0] => mix - ) - - ) - -) -Array -( - [mixin] => Array - ( - [methods] => Array - ( - [0] => mix_it - ) - - [properties] => Array - ( - [0] => mix - ) - - ) - -) -bool(false) diff --git a/ext/standard/tests/array/001.phpt b/ext/standard/tests/array/001.phpt deleted file mode 100644 index 3917f46f25..0000000000 --- a/ext/standard/tests/array/001.phpt +++ /dev/null @@ -1,159 +0,0 @@ ---TEST-- -Test array_merge and array_walk ---POST-- ---GET-- ---INI-- -precision=14 ---FILE-- -<?php -require('ext/standard/tests/array/data.inc'); -/* -** Create sample arrays -** Test alpha, numeric (decimal, hex, octal) and special data -** -** -*/ - -/* Helper function to build testing arrays */ -function make_nested_array ($depth, $breadth, $function = NULL, $args = array ()) { - for ($x = 0; $x < $breadth; ++$x) { - if (NULL === $function) { - $array = array (0); - } else { - $array = array (call_user_func_array ($function, $args)); - } - for ($y = 1; $y < $depth; ++$y) { - $array[0] = array ($array[0]); - } - $temp[$x] = $array; - } - return $temp; -} - -/* Nested array */ -$data2 = make_nested_array (3, 3); -$data = array_merge($data, $data2); - -var_dump ($data); - -function echo_kv ($value, $key) { - var_dump ($key); - var_dump ($value); -} - -echo " -- Testing array_walk() -- \n"; -array_walk ($data, 'echo_kv'); - -?> ---EXPECT-- -array(11) { - [0]=> - string(3) "PHP" - [1]=> - string(27) "PHP: Hypertext Preprocessor" - [2]=> - string(4) "Test" - ["test"]=> - int(27) - [3]=> - string(4) "test" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [4]=> - string(6) "monkey" - [5]=> - float(-0.33333333333333) - [6]=> - array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } - } - [7]=> - array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } - } - [8]=> - array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } - } -} - -- Testing array_walk() -- -int(0) -string(3) "PHP" -int(1) -string(27) "PHP: Hypertext Preprocessor" -int(2) -string(4) "Test" -string(4) "test" -int(27) -int(3) -string(4) "test" -string(5) "-1000" -array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" -} -int(4) -string(6) "monkey" -int(5) -float(-0.33333333333333) -int(6) -array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } -} -int(7) -array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } -} -int(8) -array(1) { - [0]=> - array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } - } -} diff --git a/ext/standard/tests/array/002.phpt b/ext/standard/tests/array/002.phpt deleted file mode 100644 index 94e0b35c59..0000000000 --- a/ext/standard/tests/array/002.phpt +++ /dev/null @@ -1,644 +0,0 @@ ---TEST-- -Test arsort, asort, krsort, ksort, rsort, and sort ---INI-- -precision=14 ---FILE-- -<?php -require('ext/standard/tests/array/data.inc'); - -function test_sort ($sort_function, $data) { - echo "\n -- Testing $sort_function() -- \n"; - echo "No second argument:\n"; - $sort_function ($data); - var_dump ($data); - echo "Using SORT_REGULAR:\n"; - $sort_function ($data, SORT_REGULAR); - var_dump ($data); - echo "Using SORT_NUMERIC:\n"; - $sort_function ($data, SORT_NUMERIC); - var_dump ($data); - echo "Using SORT_STRING\n"; - $sort_function ($data, SORT_STRING); - var_dump ($data); -} - -echo "Unsorted data:\n"; -var_dump ($data); -foreach (array ('arsort', 'asort', 'krsort', 'ksort', 'rsort', 'sort') as $test_function) { - test_sort ($test_function, $data); -} - -?> ---EXPECT-- -Unsorted data: -array(8) { - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - ["test"]=> - int(27) - [1000]=> - string(4) "test" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) -} - - -- Testing arsort() -- -No second argument: -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [0]=> - string(3) "PHP" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_REGULAR: -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [0]=> - string(3) "PHP" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_NUMERIC: -array(8) { - ["test"]=> - int(27) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [1001]=> - string(6) "monkey" - [5]=> - string(4) "Test" - [1000]=> - string(4) "test" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_STRING -array(8) { - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [0]=> - string(3) "PHP" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) - [16777216]=> - float(-0.33333333333333) -} - - -- Testing asort() -- -No second argument: -array(8) { - [16777216]=> - float(-0.33333333333333) - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - ["test"]=> - int(27) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_REGULAR: -array(8) { - [16777216]=> - float(-0.33333333333333) - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - ["test"]=> - int(27) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_NUMERIC: -array(8) { - [16777216]=> - float(-0.33333333333333) - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [0]=> - string(3) "PHP" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) -} -Using SORT_STRING -array(8) { - [16777216]=> - float(-0.33333333333333) - ["test"]=> - int(27) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" -} - - -- Testing krsort() -- -No second argument: -array(8) { - [16777216]=> - float(-0.33333333333333) - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - ["test"]=> - int(27) - [0]=> - string(3) "PHP" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_REGULAR: -array(8) { - [16777216]=> - float(-0.33333333333333) - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [0]=> - string(3) "PHP" - ["test"]=> - int(27) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_NUMERIC: -array(8) { - [16777216]=> - float(-0.33333333333333) - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - ["test"]=> - int(27) - [0]=> - string(3) "PHP" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_STRING -array(8) { - ["test"]=> - int(27) - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [16777216]=> - float(-0.33333333333333) - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" - [0]=> - string(3) "PHP" - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} - - -- Testing ksort() -- -No second argument: -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - ["test"]=> - int(27) - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_REGULAR: -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) - [0]=> - string(3) "PHP" - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_NUMERIC: -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - ["test"]=> - int(27) - [5]=> - string(4) "Test" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) -} -Using SORT_STRING -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - ["test"]=> - int(27) -} - - -- Testing rsort() -- -No second argument: -array(8) { - [0]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [1]=> - int(27) - [2]=> - string(4) "test" - [3]=> - string(6) "monkey" - [4]=> - string(4) "Test" - [5]=> - string(27) "PHP: Hypertext Preprocessor" - [6]=> - string(3) "PHP" - [7]=> - float(-0.33333333333333) -} -Using SORT_REGULAR: -array(8) { - [0]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [1]=> - int(27) - [2]=> - string(4) "test" - [3]=> - string(6) "monkey" - [4]=> - string(4) "Test" - [5]=> - string(27) "PHP: Hypertext Preprocessor" - [6]=> - string(3) "PHP" - [7]=> - float(-0.33333333333333) -} -Using SORT_NUMERIC: -array(8) { - [0]=> - int(27) - [1]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [2]=> - string(3) "PHP" - [3]=> - string(27) "PHP: Hypertext Preprocessor" - [4]=> - string(6) "monkey" - [5]=> - string(4) "Test" - [6]=> - string(4) "test" - [7]=> - float(-0.33333333333333) -} -Using SORT_STRING -array(8) { - [0]=> - string(4) "test" - [1]=> - string(6) "monkey" - [2]=> - string(4) "Test" - [3]=> - string(27) "PHP: Hypertext Preprocessor" - [4]=> - string(3) "PHP" - [5]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [6]=> - int(27) - [7]=> - float(-0.33333333333333) -} - - -- Testing sort() -- -No second argument: -array(8) { - [0]=> - float(-0.33333333333333) - [1]=> - string(3) "PHP" - [2]=> - string(27) "PHP: Hypertext Preprocessor" - [3]=> - string(4) "Test" - [4]=> - string(6) "monkey" - [5]=> - string(4) "test" - [6]=> - int(27) - [7]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_REGULAR: -array(8) { - [0]=> - float(-0.33333333333333) - [1]=> - string(3) "PHP" - [2]=> - string(27) "PHP: Hypertext Preprocessor" - [3]=> - string(4) "Test" - [4]=> - string(6) "monkey" - [5]=> - string(4) "test" - [6]=> - int(27) - [7]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } -} -Using SORT_NUMERIC: -array(8) { - [0]=> - float(-0.33333333333333) - [1]=> - string(6) "monkey" - [2]=> - string(4) "test" - [3]=> - string(4) "Test" - [4]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(3) "PHP" - [6]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [7]=> - int(27) -} -Using SORT_STRING -array(8) { - [0]=> - float(-0.33333333333333) - [1]=> - int(27) - [2]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [3]=> - string(3) "PHP" - [4]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [6]=> - string(6) "monkey" - [7]=> - string(4) "test" -} diff --git a/ext/standard/tests/array/003.phpt b/ext/standard/tests/array/003.phpt deleted file mode 100644 index 9c61605900..0000000000 --- a/ext/standard/tests/array/003.phpt +++ /dev/null @@ -1,104 +0,0 @@ ---TEST-- -Test usort, uksort and uasort ---INI-- -precision=14 ---FILE-- -<?php -require('ext/standard/tests/array/data.inc'); - -function cmp ($a, $b) { - is_array ($a) - and $a = array_sum ($a); - is_array ($b) - and $b = array_sum ($b); - return strcmp ($a, $b); -} - -echo " -- Testing uasort() -- \n"; -uasort ($data, 'cmp'); -var_dump ($data); - - -echo "\n -- Testing uksort() -- \n"; -uksort ($data, 'cmp'); -var_dump ($data); - -echo "\n -- Testing usort() -- \n"; -usort ($data, 'cmp'); -var_dump ($data); -?> ---EXPECT-- --- Testing uasort() -- -array(8) { - [16777216]=> - float(-0.33333333333333) - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - ["test"]=> - int(27) - [0]=> - string(3) "PHP" - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [1001]=> - string(6) "monkey" - [1000]=> - string(4) "test" -} - - -- Testing uksort() -- -array(8) { - ["-1000"]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [0]=> - string(3) "PHP" - [1000]=> - string(4) "test" - [1001]=> - string(6) "monkey" - [16777216]=> - float(-0.33333333333333) - [17]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - ["test"]=> - int(27) -} - - -- Testing usort() -- -array(8) { - [0]=> - float(-0.33333333333333) - [1]=> - array(2) { - [0]=> - string(6) "banana" - [1]=> - string(6) "orange" - } - [2]=> - int(27) - [3]=> - string(3) "PHP" - [4]=> - string(27) "PHP: Hypertext Preprocessor" - [5]=> - string(4) "Test" - [6]=> - string(6) "monkey" - [7]=> - string(4) "test" -} diff --git a/ext/standard/tests/array/004.phpt b/ext/standard/tests/array/004.phpt deleted file mode 100644 index 1074134890..0000000000 --- a/ext/standard/tests/array/004.phpt +++ /dev/null @@ -1,59 +0,0 @@ ---TEST-- -Test natsort and natcasesort ---INI-- -precision=14 ---FILE-- -<?php -$data = array( - 'Test1', - 'teST2'=>0, - 5=>'test2', - 'abc'=>'test10', - 'test21' -); - -var_dump($data); - -natsort($data); -var_dump($data); - -natcasesort($data); -var_dump($data); -?> ---EXPECT-- -array(5) { - [0]=> - string(5) "Test1" - ["teST2"]=> - int(0) - [5]=> - string(5) "test2" - ["abc"]=> - string(6) "test10" - [6]=> - string(6) "test21" -} -array(5) { - ["teST2"]=> - int(0) - [0]=> - string(5) "Test1" - [5]=> - string(5) "test2" - ["abc"]=> - string(6) "test10" - [6]=> - string(6) "test21" -} -array(5) { - ["teST2"]=> - int(0) - [0]=> - string(5) "Test1" - [5]=> - string(5) "test2" - ["abc"]=> - string(6) "test10" - [6]=> - string(6) "test21" -}
\ No newline at end of file diff --git a/ext/standard/tests/array/005.phpt b/ext/standard/tests/array/005.phpt deleted file mode 100644 index cdf731827d..0000000000 --- a/ext/standard/tests/array/005.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Test array_shift behaviour ---FILE-- -<?php - -array_shift($GLOBALS); - -$a = array("foo", "bar", "fubar"); -$b = array("3" => "foo", "4" => "bar", "5" => "fubar"); -$c = array("a" => "foo", "b" => "bar", "c" => "fubar"); - -/* simple array */ -echo array_shift($a), "\n"; -var_dump($a); - -/* numerical assoc indices */ -echo array_shift($b), "\n"; -var_dump($b); - -/* assoc indices */ -echo array_shift($c), "\n"; -var_dump($c); - -?> ---EXPECT-- -foo -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(5) "fubar" -} -foo -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(5) "fubar" -} -foo -array(2) { - ["b"]=> - string(3) "bar" - ["c"]=> - string(5) "fubar" -} diff --git a/ext/standard/tests/array/006.phpt b/ext/standard/tests/array/006.phpt deleted file mode 100644 index 4893ad3f06..0000000000 --- a/ext/standard/tests/array/006.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -Test array_pop behaviour ---FILE-- -<?php - -array_pop($GLOBALS); - -$a = array("foo", "bar", "fubar"); -$b = array("3" => "foo", "4" => "bar", "5" => "fubar"); -$c = array("a" => "foo", "b" => "bar", "c" => "fubar"); - -/* simple array */ -echo array_pop($a), "\n"; -array_push($a, "foobar"); -var_dump($a); - -/* numerical assoc indices */ -echo array_pop($b), "\n"; -var_dump($b); - -/* assoc indices */ -echo array_pop($c), "\n"; -var_dump($c); - -?> ---EXPECT-- -fubar -array(3) { - [0]=> - string(3) "foo" - [1]=> - string(3) "bar" - [2]=> - string(6) "foobar" -} -fubar -array(2) { - [3]=> - string(3) "foo" - [4]=> - string(3) "bar" -} -fubar -array(2) { - ["a"]=> - string(3) "foo" - ["b"]=> - string(3) "bar" -} diff --git a/ext/standard/tests/array/007.phpt b/ext/standard/tests/array/007.phpt deleted file mode 100644 index 82f4edd4bd..0000000000 --- a/ext/standard/tests/array/007.phpt +++ /dev/null @@ -1,175 +0,0 @@ ---TEST-- -Test array_diff and array_diff_assoc behaviour ---FILE-- -<?php -$a = array(1,"big"=>2,3,6,3,5,3,3,3,3,3,3,3,3,3,3); -$b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3); -$c = array(-1,1); -echo '$a='.var_export($a,TRUE).";\n"; -echo '$b='.var_export($b,TRUE).";\n"; -echo '$c='.var_export($c,TRUE).";\n"; -var_dump(array_diff($a,$b,$c)); -var_dump(array_diff_assoc($a,$b,$c)); -$a = array( -'a'=>2, -'b'=>'some', -'c'=>'done', -'z'=>'foo', -'f'=>5, -'fan'=>'fen', -7=>18, -9=>25, -11=>42, -12=>42, -45=>42, -73=>'foo', -95=>'some', -'som3'=>'some', -'want'=>'wanna'); -$b = array( -'a'=>7, -7=>18, -9=>13, -11=>42, -45=>46, -'som3'=>'some', -'foo'=>'some', -'goo'=>'foo', -'f'=>5, -'z'=>'equal' -); -$c = array( -73=>'foo', -95=>'some'); -echo '$a='.var_export($a,TRUE).";\n"; -echo '$b='.var_export($b,TRUE).";\n"; -echo '$c='.var_export($c,TRUE).";\n"; -echo "Results:\n\n"; -var_dump(array_diff($a,$b,$c)); -var_dump(array_diff_assoc($a,$b,$c)); -?> ---EXPECT-- -$a=array ( - 0 => 1, - 'big' => 2, - 1 => 3, - 2 => 6, - 3 => 3, - 4 => 5, - 5 => 3, - 6 => 3, - 7 => 3, - 8 => 3, - 9 => 3, - 10 => 3, - 11 => 3, - 12 => 3, - 13 => 3, - 14 => 3, -); -$b=array ( - 0 => 2, - 1 => 2, - 2 => 3, - 3 => 3, - 4 => 3, - 5 => 3, - 6 => 3, - 7 => 3, - 8 => 3, - 9 => 3, - 10 => 3, - 11 => 3, - 12 => 3, - 13 => 3, - 14 => 3, -); -$c=array ( - 0 => -1, - 1 => 1, -); -array(2) { - [2]=> - int(6) - [4]=> - int(5) -} -array(5) { - [0]=> - int(1) - ["big"]=> - int(2) - [1]=> - int(3) - [2]=> - int(6) - [4]=> - int(5) -} -$a=array ( - 'a' => 2, - 'b' => 'some', - 'c' => 'done', - 'z' => 'foo', - 'f' => 5, - 'fan' => 'fen', - 7 => 18, - 9 => 25, - 11 => 42, - 12 => 42, - 45 => 42, - 73 => 'foo', - 95 => 'some', - 'som3' => 'some', - 'want' => 'wanna', -); -$b=array ( - 'a' => 7, - 7 => 18, - 9 => 13, - 11 => 42, - 45 => 46, - 'som3' => 'some', - 'foo' => 'some', - 'goo' => 'foo', - 'f' => 5, - 'z' => 'equal', -); -$c=array ( - 73 => 'foo', - 95 => 'some', -); -Results: - -array(5) { - ["a"]=> - int(2) - ["c"]=> - string(4) "done" - ["fan"]=> - string(3) "fen" - [9]=> - int(25) - ["want"]=> - string(5) "wanna" -} -array(9) { - ["a"]=> - int(2) - ["b"]=> - string(4) "some" - ["c"]=> - string(4) "done" - ["z"]=> - string(3) "foo" - ["fan"]=> - string(3) "fen" - [9]=> - int(25) - [12]=> - int(42) - [45]=> - int(42) - ["want"]=> - string(5) "wanna" -} diff --git a/ext/standard/tests/array/008.phpt b/ext/standard/tests/array/008.phpt deleted file mode 100644 index a3dde36296..0000000000 --- a/ext/standard/tests/array/008.phpt +++ /dev/null @@ -1,310 +0,0 @@ ---TEST-- -Test array_intersect and array_intersect_assoc behaviour ---FILE-- -<?php -//-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=- TEST 1 -=-=-=-=- -$a = array(1,"big"=>2,2,6,3,5,3,3,454,'some_string',3,3,3,3,3,3,3,3,17); -$b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,17,25,'some_string',7,8,9,109,78,17); -$c = array(-1,2,1,15,25,17); -echo str_repeat("-=",10)." TEST 1 ".str_repeat("-=",20)."\n"; -echo '$a='.var_export($a,TRUE).";\n"; -echo '$b='.var_export($b,TRUE).";\n"; -echo '$c='.var_export($c,TRUE).";\n"; - -echo 'array_intersect($a,$b,$c);'."\n"; -var_dump(array_intersect($a,$b,$c)); - -echo 'array_intersect_assoc($a,$b,$c);'."\n"; -var_dump(array_intersect_assoc($a,$b,$c)); - -echo 'array_intersect($a,$b);'."\n"; -var_dump(array_intersect($a,$b)); - -echo 'array_intersect_assoc($a,$b);'."\n"; -var_dump(array_intersect_assoc($a,$b)); - -//-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=- TEST 2 -=-=-=-=-=- -$a = array( -'a'=>2, -'b'=>'some', -'c'=>'done', -'z'=>'foo', -'f'=>5, -'fan'=>'fen', -'bad'=>'bed', -'gate'=>'web', -7=>18, -9=>25, -11=>42, -12=>42, -45=>42, -73=>'foo', -95=>'some', -'som3'=>'some', -'want'=>'wanna'); - - -$b = array( -'a'=>7, -7=>18, -9=>13, -11=>42, -45=>46, -'som3'=>'some', -'foo'=>'some', -'goo'=>'foo', -'f'=>5, -'z'=>'equal', -'gate'=>'web' -); -$c = array( -'gate'=>'web', -73=>'foo', -95=>'some' -); - -echo str_repeat("-=",10)." TEST 2 ".str_repeat("-=",20)."\n"; -echo '$a='.var_export($a,TRUE).";\n"; -echo '$b='.var_export($b,TRUE).";\n"; -echo '$c='.var_export($c,TRUE).";\n"; -echo "\n\nResults:\n\n"; - -echo 'array_intersect($a,$b,$c);'."\n"; -var_dump(array_intersect($a,$b,$c)); - -echo 'array_intersect_assoc($a,$b,$c);'."\n"; -var_dump(array_intersect_assoc($a,$b,$c)); - -echo 'array_intersect($a,$b);'."\n"; -var_dump(array_intersect($a,$b)); - -echo 'array_intersect_assoc($a,$b);'."\n"; -var_dump(array_intersect_assoc($a,$b)); -?> ---EXPECT-- --=-=-=-=-=-=-=-=-=-= TEST 1 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -$a=array ( - 0 => 1, - 'big' => 2, - 1 => 2, - 2 => 6, - 3 => 3, - 4 => 5, - 5 => 3, - 6 => 3, - 7 => 454, - 8 => 'some_string', - 9 => 3, - 10 => 3, - 11 => 3, - 12 => 3, - 13 => 3, - 14 => 3, - 15 => 3, - 16 => 3, - 17 => 17, -); -$b=array ( - 0 => 2, - 1 => 2, - 2 => 3, - 3 => 3, - 4 => 3, - 5 => 3, - 6 => 3, - 7 => 3, - 8 => 3, - 9 => 3, - 10 => 3, - 11 => 3, - 12 => 3, - 13 => 3, - 14 => 3, - 15 => 17, - 16 => 25, - 17 => 'some_string', - 18 => 7, - 19 => 8, - 20 => 9, - 21 => 109, - 22 => 78, - 23 => 17, -); -$c=array ( - 0 => -1, - 1 => 2, - 2 => 1, - 3 => 15, - 4 => 25, - 5 => 17, -); -array_intersect($a,$b,$c); -array(3) { - ["big"]=> - int(2) - [1]=> - int(2) - [17]=> - int(17) -} -array_intersect_assoc($a,$b,$c); -array(1) { - [1]=> - int(2) -} -array_intersect($a,$b); -array(15) { - ["big"]=> - int(2) - [1]=> - int(2) - [3]=> - int(3) - [5]=> - int(3) - [6]=> - int(3) - [8]=> - string(11) "some_string" - [9]=> - int(3) - [10]=> - int(3) - [11]=> - int(3) - [12]=> - int(3) - [13]=> - int(3) - [14]=> - int(3) - [15]=> - int(3) - [16]=> - int(3) - [17]=> - int(17) -} -array_intersect_assoc($a,$b); -array(10) { - [1]=> - int(2) - [3]=> - int(3) - [5]=> - int(3) - [6]=> - int(3) - [9]=> - int(3) - [10]=> - int(3) - [11]=> - int(3) - [12]=> - int(3) - [13]=> - int(3) - [14]=> - int(3) -} --=-=-=-=-=-=-=-=-=-= TEST 2 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -$a=array ( - 'a' => 2, - 'b' => 'some', - 'c' => 'done', - 'z' => 'foo', - 'f' => 5, - 'fan' => 'fen', - 'bad' => 'bed', - 'gate' => 'web', - 7 => 18, - 9 => 25, - 11 => 42, - 12 => 42, - 45 => 42, - 73 => 'foo', - 95 => 'some', - 'som3' => 'some', - 'want' => 'wanna', -); -$b=array ( - 'a' => 7, - 7 => 18, - 9 => 13, - 11 => 42, - 45 => 46, - 'som3' => 'some', - 'foo' => 'some', - 'goo' => 'foo', - 'f' => 5, - 'z' => 'equal', - 'gate' => 'web', -); -$c=array ( - 'gate' => 'web', - 73 => 'foo', - 95 => 'some', -); - - -Results: - -array_intersect($a,$b,$c); -array(6) { - ["b"]=> - string(4) "some" - ["z"]=> - string(3) "foo" - ["gate"]=> - string(3) "web" - [73]=> - string(3) "foo" - [95]=> - string(4) "some" - ["som3"]=> - string(4) "some" -} -array_intersect_assoc($a,$b,$c); -array(1) { - ["gate"]=> - string(3) "web" -} -array_intersect($a,$b); -array(11) { - ["b"]=> - string(4) "some" - ["z"]=> - string(3) "foo" - ["f"]=> - int(5) - ["gate"]=> - string(3) "web" - [7]=> - int(18) - [11]=> - int(42) - [12]=> - int(42) - [45]=> - int(42) - [73]=> - string(3) "foo" - [95]=> - string(4) "some" - ["som3"]=> - string(4) "some" -} -array_intersect_assoc($a,$b); -array(5) { - ["f"]=> - int(5) - ["gate"]=> - string(3) "web" - [7]=> - int(18) - [11]=> - int(42) - ["som3"]=> - string(4) "some" -} diff --git a/ext/standard/tests/array/array_change_key_case.phpt b/ext/standard/tests/array/array_change_key_case.phpt deleted file mode 100644 index 0cd1d8203a..0000000000 --- a/ext/standard/tests/array/array_change_key_case.phpt +++ /dev/null @@ -1,769 +0,0 @@ ---TEST-- -array_change_key_case() ---FILE-- -<?php -$arrays = array ( - array (), - array (0), - array (1), - array (-1), - array (0, 2, 3, 4, 5), - array (1, 2, 3, 4, 5), - array ("" => 1), - array ("a" => 1), - array ("Z" => 1), - array ("one" => 1), - array ("ONE" => 1), - array ("OnE" => 1), - array ("oNe" => 1), - array ("one" => 1, "two" => 2), - array ("ONE" => 1, "two" => 2), - array ("OnE" => 1, "two" => 2), - array ("oNe" => 1, "two" => 2), - array ("one" => 1, "TWO" => 2), - array ("ONE" => 1, "TWO" => 2), - array ("OnE" => 1, "TWO" => 2), - array ("oNe" => 1, "TWO" => 2), - array ("one" => 1, "TwO" => 2), - array ("ONE" => 1, "TwO" => 2), - array ("OnE" => 1, "TwO" => 2), - array ("oNe" => 1, "TwO" => 2), - array ("one" => 1, "tWo" => 2), - array ("ONE" => 1, "tWo" => 2), - array ("OnE" => 1, "tWo" => 2), - array ("oNe" => 1, "tWo" => 2), - array ("one" => 1, 2), - array ("ONE" => 1, 2), - array ("OnE" => 1, 2), - array ("oNe" => 1, 2), - array ("ONE" => 1, "TWO" => 2, "THREE" => 3, "FOUR" => "four"), - array ("one" => 1, "two" => 2, "three" => 3, "four" => "FOUR"), - array ("ONE" => 1, "TWO" => 2, "three" => 3, "four" => "FOUR"), - array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four") -); - -foreach ($arrays as $item) { - var_dump(array_change_key_case($item)); - var_dump(array_change_key_case($item, CASE_UPPER)); - var_dump(array_change_key_case($item, CASE_LOWER)); - echo "\n"; -} -echo "end\n"; -?> ---EXPECT-- -array(0) { -} -array(0) { -} -array(0) { -} - -array(1) { - [0]=> - int(0) -} -array(1) { - [0]=> - int(0) -} -array(1) { - [0]=> - int(0) -} - -array(1) { - [0]=> - int(1) -} -array(1) { - [0]=> - int(1) -} -array(1) { - [0]=> - int(1) -} - -array(1) { - [0]=> - int(-1) -} -array(1) { - [0]=> - int(-1) -} -array(1) { - [0]=> - int(-1) -} - -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} - -array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} - -array(1) { - [""]=> - int(1) -} -array(1) { - [""]=> - int(1) -} -array(1) { - [""]=> - int(1) -} - -array(1) { - ["a"]=> - int(1) -} -array(1) { - ["A"]=> - int(1) -} -array(1) { - ["a"]=> - int(1) -} - -array(1) { - ["z"]=> - int(1) -} -array(1) { - ["Z"]=> - int(1) -} -array(1) { - ["z"]=> - int(1) -} - -array(1) { - ["one"]=> - int(1) -} -array(1) { - ["ONE"]=> - int(1) -} -array(1) { - ["one"]=> - int(1) -} - -array(1) { - ["one"]=> - int(1) -} -array(1) { - ["ONE"]=> - int(1) -} -array(1) { - ["one"]=> - int(1) -} - -array(1) { - ["one"]=> - int(1) -} -array(1) { - ["ONE"]=> - int(1) -} -array(1) { - ["one"]=> - int(1) -} - -array(1) { - ["one"]=> - int(1) -} -array(1) { - ["ONE"]=> - int(1) -} -array(1) { - ["one"]=> - int(1) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - ["two"]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - ["one"]=> - int(1) - [0]=> - int(2) -} - -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "four" -} -array(4) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) - ["THREE"]=> - int(3) - ["FOUR"]=> - string(4) "four" -} -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "four" -} - -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "FOUR" -} -array(4) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) - ["THREE"]=> - int(3) - ["FOUR"]=> - string(4) "FOUR" -} -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "FOUR" -} - -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "FOUR" -} -array(4) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) - ["THREE"]=> - int(3) - ["FOUR"]=> - string(4) "FOUR" -} -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "FOUR" -} - -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "four" -} -array(4) { - ["ONE"]=> - int(1) - ["TWO"]=> - int(2) - ["THREE"]=> - int(3) - ["FOUR"]=> - string(4) "four" -} -array(4) { - ["one"]=> - int(1) - ["two"]=> - int(2) - ["three"]=> - int(3) - ["four"]=> - string(4) "four" -} - -end diff --git a/ext/standard/tests/array/array_chunk.phpt b/ext/standard/tests/array/array_chunk.phpt deleted file mode 100644 index 061c6994bf..0000000000 --- a/ext/standard/tests/array/array_chunk.phpt +++ /dev/null @@ -1,5326 +0,0 @@ ---TEST-- -array_chunk() ---FILE-- -<?php -$arrays = array ( - array (), - array (0), - array (1), - array (-1), - array (0, 2), - array (1, 2, 3), - - array (1 => 0), - array (2 => 1), - array (3 => -1), - - array (1 => 0, 2 => 2), - array (1 => 1, 2 => 2, 3 => 3), - array (0 => 0, 3 => 2), - array (1 => 1, 5 => 2, 8 => 3), - - array (1, 2), - array (0, 1, 2), - array (1, 2, 3), - array (0, 1, 2, 3), - array (1, 2, 3, 4), - array (0, 1, 2, 3, 4), - array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), - array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), - - array ("a" => 1), - array ("b" => 1, "c" => 2), - array ("p" => 1, "q" => 2, "r" => 3, "s" => 4, "u" => 5, "v" => 6), - - array ("a" => "A"), - array ("p" => "A", "q" => "B", "r" => "C", "s" => "D", "u" => "E", "v" => "F"), -); - -foreach ($arrays as $item) { - echo "===========================================\n"; - var_dump ($item); - echo "-------------------------------------------\n"; - for ($i = 0; $i < (sizeof($item) + 1); $i++) { - echo "[$i]\n"; - var_dump (@array_chunk ($item, $i)); - var_dump (@array_chunk ($item, $i, TRUE)); - var_dump (@array_chunk ($item, $i, FALSE)); - echo "\n"; - } - echo "\n"; -} -echo "end\n"; -?> ---EXPECT-- -=========================================== -array(0) { -} -------------------------------------------- -[0] -NULL -NULL -NULL - - -=========================================== -array(1) { - [0]=> - int(0) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } -} - - -=========================================== -array(1) { - [0]=> - int(1) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} - - -=========================================== -array(1) { - [0]=> - int(-1) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(-1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(-1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(-1) - } -} - - -=========================================== -array(2) { - [0]=> - int(0) - [1]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [1]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} - - -=========================================== -array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [1]=> - int(2) - } - [2]=> - array(1) { - [2]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [2]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} - -[3] -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} - - -=========================================== -array(1) { - [1]=> - int(0) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } -} -array(1) { - [0]=> - array(1) { - [1]=> - int(0) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(0) - } -} - - -=========================================== -array(1) { - [2]=> - int(1) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - [2]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} - - -=========================================== -array(1) { - [3]=> - int(-1) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(-1) - } -} -array(1) { - [0]=> - array(1) { - [3]=> - int(-1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(-1) - } -} - - -=========================================== -array(2) { - [1]=> - int(0) - [2]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [1]=> - int(0) - } - [1]=> - array(1) { - [2]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [1]=> - int(0) - [2]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} - - -=========================================== -array(3) { - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [1]=> - int(1) - } - [1]=> - array(1) { - [2]=> - int(2) - } - [2]=> - array(1) { - [3]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(1) { - [3]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} - -[3] -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} - - -=========================================== -array(2) { - [0]=> - int(0) - [3]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [3]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [3]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(2) - } -} - - -=========================================== -array(3) { - [1]=> - int(1) - [5]=> - int(2) - [8]=> - int(3) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [1]=> - int(1) - } - [1]=> - array(1) { - [5]=> - int(2) - } - [2]=> - array(1) { - [8]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [1]=> - int(1) - [5]=> - int(2) - } - [1]=> - array(1) { - [8]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} - -[3] -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [1]=> - int(1) - [5]=> - int(2) - [8]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} - - -=========================================== -array(2) { - [0]=> - int(1) - [1]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(2) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [1]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(1) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } -} - - -=========================================== -array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(3) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [1]=> - int(1) - } - [2]=> - array(1) { - [2]=> - int(2) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(1) { - [2]=> - int(2) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[3] -array(1) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } -} - - -=========================================== -array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [1]=> - int(2) - } - [2]=> - array(1) { - [2]=> - int(3) - } -} -array(3) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [2]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} - -[3] -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} -array(1) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } -} - - -=========================================== -array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(4) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } -} -array(4) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [1]=> - int(1) - } - [2]=> - array(1) { - [2]=> - int(2) - } - [3]=> - array(1) { - [3]=> - int(3) - } -} -array(4) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [2]=> - int(2) - [3]=> - int(3) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } -} - -[3] -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(1) { - [3]=> - int(3) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(1) { - [0]=> - int(3) - } -} - -[4] -array(1) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } -} -array(1) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } -} -array(1) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } -} - - -=========================================== -array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(4) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } -} -array(4) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [1]=> - int(2) - } - [2]=> - array(1) { - [2]=> - int(3) - } - [3]=> - array(1) { - [3]=> - int(4) - } -} -array(4) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } -} - -[2] -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [2]=> - int(3) - [3]=> - int(4) - } -} -array(2) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } -} - -[3] -array(2) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(1) { - [0]=> - int(4) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(1) { - [3]=> - int(4) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(1) { - [0]=> - int(4) - } -} - -[4] -array(1) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } -} -array(1) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } -} -array(1) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } -} - - -=========================================== -array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(5) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } - [4]=> - array(1) { - [0]=> - int(4) - } -} -array(5) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [1]=> - int(1) - } - [2]=> - array(1) { - [2]=> - int(2) - } - [3]=> - array(1) { - [3]=> - int(3) - } - [4]=> - array(1) { - [4]=> - int(4) - } -} -array(5) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } - [4]=> - array(1) { - [0]=> - int(4) - } -} - -[2] -array(3) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } - [2]=> - array(1) { - [0]=> - int(4) - } -} -array(3) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [2]=> - int(2) - [3]=> - int(3) - } - [2]=> - array(1) { - [4]=> - int(4) - } -} -array(3) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } - [2]=> - array(1) { - [0]=> - int(4) - } -} - -[3] -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(2) { - [3]=> - int(3) - [4]=> - int(4) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } -} - -[4] -array(2) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(1) { - [0]=> - int(4) - } -} -array(2) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(1) { - [4]=> - int(4) - } -} -array(2) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(1) { - [0]=> - int(4) - } -} - -[5] -array(1) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } -} -array(1) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } -} -array(1) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } -} - - -=========================================== -array(10) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(10) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } - [4]=> - array(1) { - [0]=> - int(5) - } - [5]=> - array(1) { - [0]=> - int(6) - } - [6]=> - array(1) { - [0]=> - int(7) - } - [7]=> - array(1) { - [0]=> - int(8) - } - [8]=> - array(1) { - [0]=> - int(9) - } - [9]=> - array(1) { - [0]=> - int(10) - } -} -array(10) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [1]=> - int(2) - } - [2]=> - array(1) { - [2]=> - int(3) - } - [3]=> - array(1) { - [3]=> - int(4) - } - [4]=> - array(1) { - [4]=> - int(5) - } - [5]=> - array(1) { - [5]=> - int(6) - } - [6]=> - array(1) { - [6]=> - int(7) - } - [7]=> - array(1) { - [7]=> - int(8) - } - [8]=> - array(1) { - [8]=> - int(9) - } - [9]=> - array(1) { - [9]=> - int(10) - } -} -array(10) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } - [4]=> - array(1) { - [0]=> - int(5) - } - [5]=> - array(1) { - [0]=> - int(6) - } - [6]=> - array(1) { - [0]=> - int(7) - } - [7]=> - array(1) { - [0]=> - int(8) - } - [8]=> - array(1) { - [0]=> - int(9) - } - [9]=> - array(1) { - [0]=> - int(10) - } -} - -[2] -array(5) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } - [2]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } - [3]=> - array(2) { - [0]=> - int(7) - [1]=> - int(8) - } - [4]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} -array(5) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [2]=> - int(3) - [3]=> - int(4) - } - [2]=> - array(2) { - [4]=> - int(5) - [5]=> - int(6) - } - [3]=> - array(2) { - [6]=> - int(7) - [7]=> - int(8) - } - [4]=> - array(2) { - [8]=> - int(9) - [9]=> - int(10) - } -} -array(5) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } - [2]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } - [3]=> - array(2) { - [0]=> - int(7) - [1]=> - int(8) - } - [4]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} - -[3] -array(4) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(3) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - } - [2]=> - array(3) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - } - [3]=> - array(1) { - [0]=> - int(10) - } -} -array(4) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(3) { - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } - [2]=> - array(3) { - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - } - [3]=> - array(1) { - [9]=> - int(10) - } -} -array(4) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(3) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - } - [2]=> - array(3) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - } - [3]=> - array(1) { - [0]=> - int(10) - } -} - -[4] -array(3) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } - [1]=> - array(4) { - [0]=> - int(5) - [1]=> - int(6) - [2]=> - int(7) - [3]=> - int(8) - } - [2]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} -array(3) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } - [1]=> - array(4) { - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - } - [2]=> - array(2) { - [8]=> - int(9) - [9]=> - int(10) - } -} -array(3) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } - [1]=> - array(4) { - [0]=> - int(5) - [1]=> - int(6) - [2]=> - int(7) - [3]=> - int(8) - } - [2]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} - -[5] -array(2) { - [0]=> - array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - } - [1]=> - array(5) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - [3]=> - int(9) - [4]=> - int(10) - } -} -array(2) { - [0]=> - array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - } - [1]=> - array(5) { - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} -array(2) { - [0]=> - array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - } - [1]=> - array(5) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - [3]=> - int(9) - [4]=> - int(10) - } -} - -[6] -array(2) { - [0]=> - array(6) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } - [1]=> - array(4) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - [3]=> - int(10) - } -} -array(2) { - [0]=> - array(6) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } - [1]=> - array(4) { - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} -array(2) { - [0]=> - array(6) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } - [1]=> - array(4) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - [3]=> - int(10) - } -} - -[7] -array(2) { - [0]=> - array(7) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - } - [1]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} -array(2) { - [0]=> - array(7) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - } - [1]=> - array(3) { - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} -array(2) { - [0]=> - array(7) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - } - [1]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} - -[8] -array(2) { - [0]=> - array(8) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - } - [1]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} -array(2) { - [0]=> - array(8) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - } - [1]=> - array(2) { - [8]=> - int(9) - [9]=> - int(10) - } -} -array(2) { - [0]=> - array(8) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - } - [1]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} - -[9] -array(2) { - [0]=> - array(9) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - } - [1]=> - array(1) { - [0]=> - int(10) - } -} -array(2) { - [0]=> - array(9) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - } - [1]=> - array(1) { - [9]=> - int(10) - } -} -array(2) { - [0]=> - array(9) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - } - [1]=> - array(1) { - [0]=> - int(10) - } -} - -[10] -array(1) { - [0]=> - array(10) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} -array(1) { - [0]=> - array(10) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} -array(1) { - [0]=> - array(10) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - } -} - - -=========================================== -array(11) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(11) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } - [4]=> - array(1) { - [0]=> - int(4) - } - [5]=> - array(1) { - [0]=> - int(5) - } - [6]=> - array(1) { - [0]=> - int(6) - } - [7]=> - array(1) { - [0]=> - int(7) - } - [8]=> - array(1) { - [0]=> - int(8) - } - [9]=> - array(1) { - [0]=> - int(9) - } - [10]=> - array(1) { - [0]=> - int(10) - } -} -array(11) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [1]=> - int(1) - } - [2]=> - array(1) { - [2]=> - int(2) - } - [3]=> - array(1) { - [3]=> - int(3) - } - [4]=> - array(1) { - [4]=> - int(4) - } - [5]=> - array(1) { - [5]=> - int(5) - } - [6]=> - array(1) { - [6]=> - int(6) - } - [7]=> - array(1) { - [7]=> - int(7) - } - [8]=> - array(1) { - [8]=> - int(8) - } - [9]=> - array(1) { - [9]=> - int(9) - } - [10]=> - array(1) { - [10]=> - int(10) - } -} -array(11) { - [0]=> - array(1) { - [0]=> - int(0) - } - [1]=> - array(1) { - [0]=> - int(1) - } - [2]=> - array(1) { - [0]=> - int(2) - } - [3]=> - array(1) { - [0]=> - int(3) - } - [4]=> - array(1) { - [0]=> - int(4) - } - [5]=> - array(1) { - [0]=> - int(5) - } - [6]=> - array(1) { - [0]=> - int(6) - } - [7]=> - array(1) { - [0]=> - int(7) - } - [8]=> - array(1) { - [0]=> - int(8) - } - [9]=> - array(1) { - [0]=> - int(9) - } - [10]=> - array(1) { - [0]=> - int(10) - } -} - -[2] -array(6) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } - [2]=> - array(2) { - [0]=> - int(4) - [1]=> - int(5) - } - [3]=> - array(2) { - [0]=> - int(6) - [1]=> - int(7) - } - [4]=> - array(2) { - [0]=> - int(8) - [1]=> - int(9) - } - [5]=> - array(1) { - [0]=> - int(10) - } -} -array(6) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [2]=> - int(2) - [3]=> - int(3) - } - [2]=> - array(2) { - [4]=> - int(4) - [5]=> - int(5) - } - [3]=> - array(2) { - [6]=> - int(6) - [7]=> - int(7) - } - [4]=> - array(2) { - [8]=> - int(8) - [9]=> - int(9) - } - [5]=> - array(1) { - [10]=> - int(10) - } -} -array(6) { - [0]=> - array(2) { - [0]=> - int(0) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(3) - } - [2]=> - array(2) { - [0]=> - int(4) - [1]=> - int(5) - } - [3]=> - array(2) { - [0]=> - int(6) - [1]=> - int(7) - } - [4]=> - array(2) { - [0]=> - int(8) - [1]=> - int(9) - } - [5]=> - array(1) { - [0]=> - int(10) - } -} - -[3] -array(4) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(3) { - [0]=> - int(3) - [1]=> - int(4) - [2]=> - int(5) - } - [2]=> - array(3) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - } - [3]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} -array(4) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(3) { - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - } - [2]=> - array(3) { - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - } - [3]=> - array(2) { - [9]=> - int(9) - [10]=> - int(10) - } -} -array(4) { - [0]=> - array(3) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - } - [1]=> - array(3) { - [0]=> - int(3) - [1]=> - int(4) - [2]=> - int(5) - } - [2]=> - array(3) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - } - [3]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} - -[4] -array(3) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(4) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - [3]=> - int(7) - } - [2]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} -array(3) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(4) { - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - } - [2]=> - array(3) { - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(3) { - [0]=> - array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - } - [1]=> - array(4) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - [3]=> - int(7) - } - [2]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} - -[5] -array(3) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } - [1]=> - array(5) { - [0]=> - int(5) - [1]=> - int(6) - [2]=> - int(7) - [3]=> - int(8) - [4]=> - int(9) - } - [2]=> - array(1) { - [0]=> - int(10) - } -} -array(3) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } - [1]=> - array(5) { - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - } - [2]=> - array(1) { - [10]=> - int(10) - } -} -array(3) { - [0]=> - array(5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - } - [1]=> - array(5) { - [0]=> - int(5) - [1]=> - int(6) - [2]=> - int(7) - [3]=> - int(8) - [4]=> - int(9) - } - [2]=> - array(1) { - [0]=> - int(10) - } -} - -[6] -array(2) { - [0]=> - array(6) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - } - [1]=> - array(5) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - [3]=> - int(9) - [4]=> - int(10) - } -} -array(2) { - [0]=> - array(6) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - } - [1]=> - array(5) { - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(2) { - [0]=> - array(6) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - } - [1]=> - array(5) { - [0]=> - int(6) - [1]=> - int(7) - [2]=> - int(8) - [3]=> - int(9) - [4]=> - int(10) - } -} - -[7] -array(2) { - [0]=> - array(7) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - } - [1]=> - array(4) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - [3]=> - int(10) - } -} -array(2) { - [0]=> - array(7) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - } - [1]=> - array(4) { - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(2) { - [0]=> - array(7) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - } - [1]=> - array(4) { - [0]=> - int(7) - [1]=> - int(8) - [2]=> - int(9) - [3]=> - int(10) - } -} - -[8] -array(2) { - [0]=> - array(8) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - } - [1]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} -array(2) { - [0]=> - array(8) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - } - [1]=> - array(3) { - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(2) { - [0]=> - array(8) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - } - [1]=> - array(3) { - [0]=> - int(8) - [1]=> - int(9) - [2]=> - int(10) - } -} - -[9] -array(2) { - [0]=> - array(9) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - } - [1]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} -array(2) { - [0]=> - array(9) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - } - [1]=> - array(2) { - [9]=> - int(9) - [10]=> - int(10) - } -} -array(2) { - [0]=> - array(9) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - } - [1]=> - array(2) { - [0]=> - int(9) - [1]=> - int(10) - } -} - -[10] -array(2) { - [0]=> - array(10) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - } - [1]=> - array(1) { - [0]=> - int(10) - } -} -array(2) { - [0]=> - array(10) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - } - [1]=> - array(1) { - [10]=> - int(10) - } -} -array(2) { - [0]=> - array(10) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - } - [1]=> - array(1) { - [0]=> - int(10) - } -} - -[11] -array(1) { - [0]=> - array(11) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(1) { - [0]=> - array(11) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} -array(1) { - [0]=> - array(11) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) - [4]=> - int(4) - [5]=> - int(5) - [6]=> - int(6) - [7]=> - int(7) - [8]=> - int(8) - [9]=> - int(9) - [10]=> - int(10) - } -} - - -=========================================== -array(1) { - ["a"]=> - int(1) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - ["a"]=> - int(1) - } -} -array(1) { - [0]=> - array(1) { - [0]=> - int(1) - } -} - - -=========================================== -array(2) { - ["b"]=> - int(1) - ["c"]=> - int(2) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(2) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - ["b"]=> - int(1) - } - [1]=> - array(1) { - ["c"]=> - int(2) - } -} -array(2) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } -} - -[2] -array(1) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - ["b"]=> - int(1) - ["c"]=> - int(2) - } -} -array(1) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } -} - - -=========================================== -array(6) { - ["p"]=> - int(1) - ["q"]=> - int(2) - ["r"]=> - int(3) - ["s"]=> - int(4) - ["u"]=> - int(5) - ["v"]=> - int(6) -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(6) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } - [4]=> - array(1) { - [0]=> - int(5) - } - [5]=> - array(1) { - [0]=> - int(6) - } -} -array(6) { - [0]=> - array(1) { - ["p"]=> - int(1) - } - [1]=> - array(1) { - ["q"]=> - int(2) - } - [2]=> - array(1) { - ["r"]=> - int(3) - } - [3]=> - array(1) { - ["s"]=> - int(4) - } - [4]=> - array(1) { - ["u"]=> - int(5) - } - [5]=> - array(1) { - ["v"]=> - int(6) - } -} -array(6) { - [0]=> - array(1) { - [0]=> - int(1) - } - [1]=> - array(1) { - [0]=> - int(2) - } - [2]=> - array(1) { - [0]=> - int(3) - } - [3]=> - array(1) { - [0]=> - int(4) - } - [4]=> - array(1) { - [0]=> - int(5) - } - [5]=> - array(1) { - [0]=> - int(6) - } -} - -[2] -array(3) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } - [2]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } -} -array(3) { - [0]=> - array(2) { - ["p"]=> - int(1) - ["q"]=> - int(2) - } - [1]=> - array(2) { - ["r"]=> - int(3) - ["s"]=> - int(4) - } - [2]=> - array(2) { - ["u"]=> - int(5) - ["v"]=> - int(6) - } -} -array(3) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(2) - } - [1]=> - array(2) { - [0]=> - int(3) - [1]=> - int(4) - } - [2]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } -} - -[3] -array(2) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(3) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - } -} -array(2) { - [0]=> - array(3) { - ["p"]=> - int(1) - ["q"]=> - int(2) - ["r"]=> - int(3) - } - [1]=> - array(3) { - ["s"]=> - int(4) - ["u"]=> - int(5) - ["v"]=> - int(6) - } -} -array(2) { - [0]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - [1]=> - array(3) { - [0]=> - int(4) - [1]=> - int(5) - [2]=> - int(6) - } -} - -[4] -array(2) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } - [1]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } -} -array(2) { - [0]=> - array(4) { - ["p"]=> - int(1) - ["q"]=> - int(2) - ["r"]=> - int(3) - ["s"]=> - int(4) - } - [1]=> - array(2) { - ["u"]=> - int(5) - ["v"]=> - int(6) - } -} -array(2) { - [0]=> - array(4) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - } - [1]=> - array(2) { - [0]=> - int(5) - [1]=> - int(6) - } -} - -[5] -array(2) { - [0]=> - array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - } - [1]=> - array(1) { - [0]=> - int(6) - } -} -array(2) { - [0]=> - array(5) { - ["p"]=> - int(1) - ["q"]=> - int(2) - ["r"]=> - int(3) - ["s"]=> - int(4) - ["u"]=> - int(5) - } - [1]=> - array(1) { - ["v"]=> - int(6) - } -} -array(2) { - [0]=> - array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - } - [1]=> - array(1) { - [0]=> - int(6) - } -} - -[6] -array(1) { - [0]=> - array(6) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } -} -array(1) { - [0]=> - array(6) { - ["p"]=> - int(1) - ["q"]=> - int(2) - ["r"]=> - int(3) - ["s"]=> - int(4) - ["u"]=> - int(5) - ["v"]=> - int(6) - } -} -array(1) { - [0]=> - array(6) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - } -} - - -=========================================== -array(1) { - ["a"]=> - string(1) "A" -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(1) { - [0]=> - array(1) { - [0]=> - string(1) "A" - } -} -array(1) { - [0]=> - array(1) { - ["a"]=> - string(1) "A" - } -} -array(1) { - [0]=> - array(1) { - [0]=> - string(1) "A" - } -} - - -=========================================== -array(6) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - ["r"]=> - string(1) "C" - ["s"]=> - string(1) "D" - ["u"]=> - string(1) "E" - ["v"]=> - string(1) "F" -} -------------------------------------------- -[0] -NULL -NULL -NULL - -[1] -array(6) { - [0]=> - array(1) { - [0]=> - string(1) "A" - } - [1]=> - array(1) { - [0]=> - string(1) "B" - } - [2]=> - array(1) { - [0]=> - string(1) "C" - } - [3]=> - array(1) { - [0]=> - string(1) "D" - } - [4]=> - array(1) { - [0]=> - string(1) "E" - } - [5]=> - array(1) { - [0]=> - string(1) "F" - } -} -array(6) { - [0]=> - array(1) { - ["p"]=> - string(1) "A" - } - [1]=> - array(1) { - ["q"]=> - string(1) "B" - } - [2]=> - array(1) { - ["r"]=> - string(1) "C" - } - [3]=> - array(1) { - ["s"]=> - string(1) "D" - } - [4]=> - array(1) { - ["u"]=> - string(1) "E" - } - [5]=> - array(1) { - ["v"]=> - string(1) "F" - } -} -array(6) { - [0]=> - array(1) { - [0]=> - string(1) "A" - } - [1]=> - array(1) { - [0]=> - string(1) "B" - } - [2]=> - array(1) { - [0]=> - string(1) "C" - } - [3]=> - array(1) { - [0]=> - string(1) "D" - } - [4]=> - array(1) { - [0]=> - string(1) "E" - } - [5]=> - array(1) { - [0]=> - string(1) "F" - } -} - -[2] -array(3) { - [0]=> - array(2) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - } - [1]=> - array(2) { - [0]=> - string(1) "C" - [1]=> - string(1) "D" - } - [2]=> - array(2) { - [0]=> - string(1) "E" - [1]=> - string(1) "F" - } -} -array(3) { - [0]=> - array(2) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - } - [1]=> - array(2) { - ["r"]=> - string(1) "C" - ["s"]=> - string(1) "D" - } - [2]=> - array(2) { - ["u"]=> - string(1) "E" - ["v"]=> - string(1) "F" - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - } - [1]=> - array(2) { - [0]=> - string(1) "C" - [1]=> - string(1) "D" - } - [2]=> - array(2) { - [0]=> - string(1) "E" - [1]=> - string(1) "F" - } -} - -[3] -array(2) { - [0]=> - array(3) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - } - [1]=> - array(3) { - [0]=> - string(1) "D" - [1]=> - string(1) "E" - [2]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(3) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - ["r"]=> - string(1) "C" - } - [1]=> - array(3) { - ["s"]=> - string(1) "D" - ["u"]=> - string(1) "E" - ["v"]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(3) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - } - [1]=> - array(3) { - [0]=> - string(1) "D" - [1]=> - string(1) "E" - [2]=> - string(1) "F" - } -} - -[4] -array(2) { - [0]=> - array(4) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - } - [1]=> - array(2) { - [0]=> - string(1) "E" - [1]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(4) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - ["r"]=> - string(1) "C" - ["s"]=> - string(1) "D" - } - [1]=> - array(2) { - ["u"]=> - string(1) "E" - ["v"]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(4) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - } - [1]=> - array(2) { - [0]=> - string(1) "E" - [1]=> - string(1) "F" - } -} - -[5] -array(2) { - [0]=> - array(5) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - [4]=> - string(1) "E" - } - [1]=> - array(1) { - [0]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(5) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - ["r"]=> - string(1) "C" - ["s"]=> - string(1) "D" - ["u"]=> - string(1) "E" - } - [1]=> - array(1) { - ["v"]=> - string(1) "F" - } -} -array(2) { - [0]=> - array(5) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - [4]=> - string(1) "E" - } - [1]=> - array(1) { - [0]=> - string(1) "F" - } -} - -[6] -array(1) { - [0]=> - array(6) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - [4]=> - string(1) "E" - [5]=> - string(1) "F" - } -} -array(1) { - [0]=> - array(6) { - ["p"]=> - string(1) "A" - ["q"]=> - string(1) "B" - ["r"]=> - string(1) "C" - ["s"]=> - string(1) "D" - ["u"]=> - string(1) "E" - ["v"]=> - string(1) "F" - } -} -array(1) { - [0]=> - array(6) { - [0]=> - string(1) "A" - [1]=> - string(1) "B" - [2]=> - string(1) "C" - [3]=> - string(1) "D" - [4]=> - string(1) "E" - [5]=> - string(1) "F" - } -} - - -end diff --git a/ext/standard/tests/array/array_count_values.phpt b/ext/standard/tests/array/array_count_values.phpt deleted file mode 100644 index d9a3ba3d5a..0000000000 --- a/ext/standard/tests/array/array_count_values.phpt +++ /dev/null @@ -1,95 +0,0 @@ ---TEST-- -array_count_values() ---FILE-- -<?php -$arrays = array ( - array (), - array (0), - array (1), - array (-1), - array (0, 0), - array (0, 1), - array (1, 1), - array (1, "hello", 1, "world", "hello"), - array ("hello", "world", "hello"), - array ("", "world", "", "hello", "world", "hello", "hello", "world", "hello"), - array (0, array (1, "hello", 1, "world", "hello")), - array (1, array (1, "hello", 1, "world", "hello"), array (1, "hello", 1, "world", "hello"), array (1, "hello", 1, "world", "hello")), -); - -foreach ($arrays as $item) { - var_dump (@array_count_values ($item)); - echo "\n"; -} -?> ---EXPECT-- -array(0) { -} - -array(1) { - [0]=> - int(1) -} - -array(1) { - [1]=> - int(1) -} - -array(1) { - [-1]=> - int(1) -} - -array(1) { - [0]=> - int(2) -} - -array(2) { - [0]=> - int(1) - [1]=> - int(1) -} - -array(1) { - [1]=> - int(2) -} - -array(3) { - [1]=> - int(2) - ["hello"]=> - int(2) - ["world"]=> - int(1) -} - -array(2) { - ["hello"]=> - int(2) - ["world"]=> - int(1) -} - -array(3) { - [""]=> - int(2) - ["world"]=> - int(3) - ["hello"]=> - int(4) -} - -array(1) { - [0]=> - int(1) -} - -array(1) { - [1]=> - int(1) -} - diff --git a/ext/standard/tests/array/array_search.phpt b/ext/standard/tests/array/array_search.phpt deleted file mode 100644 index 9c21de94e4..0000000000 --- a/ext/standard/tests/array/array_search.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -search_array and in_array (including bug 13567) ---FILE-- -<?php - -$arr1 = array('a','b','c'); -$arr2 = array(); -$arr3 = array('c','key'=>'d'); -$arr4 = array("a\0b"=>'e','key'=>'d', 'f'); - -$tests = <<<TESTS -FALSE === in_array(123, \$arr1) -FALSE === array_search(123, \$arr1) -TRUE === in_array('a', \$arr1) -0 === array_search('a', \$arr1) -"a\\0b"=== array_search('e', \$arr4) -'key'=== array_search('d', \$arr4) -TESTS; - -include('tests/quicktester.inc'); - ---EXPECT-- -OK diff --git a/ext/standard/tests/array/bug12776.phpt b/ext/standard/tests/array/bug12776.phpt deleted file mode 100644 index 54c6f6fceb..0000000000 --- a/ext/standard/tests/array/bug12776.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -Bug #12776 (array_walk crash) ---FILE-- -<?php - -function test($val,$key) -{ - global $globalArray; - $globalArray[]=$key; // this will end up crashing - $globalArray[]=(string)$key; // this will end up OK - print "val: $val; key: $key\n"; flush(); -} - -$arr=array('k'=>'v'); -array_walk($arr,'test'); - -print "First value: ".$globalArray[0]; - -print "\nDone\n"; - -?> ---EXPECT-- -val: v; key: k -First value: k -Done diff --git a/ext/standard/tests/array/bug20381.phpt b/ext/standard/tests/array/bug20381.phpt deleted file mode 100644 index 1adaa863b7..0000000000 --- a/ext/standard/tests/array/bug20381.phpt +++ /dev/null @@ -1,79 +0,0 @@ ---TEST-- -Bug #20381 (array_merge_recursive mangles input arrays) ---FILE-- -<?php -$a = array( - 'a1' => 1, - 'a2' => array( 1, 2, 3 ), - 'a3' => array( - 'a' => array( 10, 20, 30 ), - 'b' => 'b' - ) - ); -$b = array( 'a1' => 2, - 'a2' => array( 3, 4, 5 ), - 'a3' => array( - 'c' => 'cc', - 'a' => array( 10, 40 ) - ) - ); - -var_dump($a); -array_merge_recursive( $a, $b ); -var_dump($a); -?> ---EXPECT-- -array(3) { - ["a1"]=> - int(1) - ["a2"]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - ["a3"]=> - array(2) { - ["a"]=> - array(3) { - [0]=> - int(10) - [1]=> - int(20) - [2]=> - int(30) - } - ["b"]=> - string(1) "b" - } -} -array(3) { - ["a1"]=> - int(1) - ["a2"]=> - array(3) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - } - ["a3"]=> - array(2) { - ["a"]=> - array(3) { - [0]=> - int(10) - [1]=> - int(20) - [2]=> - int(30) - } - ["b"]=> - string(1) "b" - } -} diff --git a/ext/standard/tests/array/bug20865.phpt b/ext/standard/tests/array/bug20865.phpt deleted file mode 100644 index f1edbabab5..0000000000 --- a/ext/standard/tests/array/bug20865.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Bug #20865 (array_key_exists and NULL key) ---FILE-- -<?php - $ta = array(1, 2, 3); - $ta[NULL] = "Null Value"; - - var_dump(array_key_exists(NULL, $ta)); -?> ---EXPECT-- -bool(true) diff --git a/ext/standard/tests/array/bug21182.phpt b/ext/standard/tests/array/bug21182.phpt deleted file mode 100644 index af4602ab74..0000000000 --- a/ext/standard/tests/array/bug21182.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #21182 (range modifies arguments) ---FILE-- -<?php -$a = "20"; $b = "30"; -echo "a1: $a\n"; -$result = range($a, $b); -echo "a2: $a : type : " . gettype($a) . "\n"; -?> ---EXPECT-- -a1: 20 -a2: 20 : type : string diff --git a/ext/standard/tests/array/bug21998.phpt b/ext/standard/tests/array/bug21998.phpt deleted file mode 100644 index aa52dc590a..0000000000 --- a/ext/standard/tests/array/bug21998.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #21998 (array_pop() does not reset the current array position) ---FILE-- -<?php - -$a = array("a", "b", "c"); - -var_dump(key($a)); -var_dump(array_pop($a)); -var_dump(key($a)); -var_dump(array_pop($a)); -var_dump(key($a)); -var_dump(array_pop($a)); -var_dump(key($a)); - -?> ---EXPECT-- -int(0) -string(1) "c" -int(0) -string(1) "b" -int(0) -string(1) "a" -NULL diff --git a/ext/standard/tests/array/bug22088.phpt b/ext/standard/tests/array/bug22088.phpt deleted file mode 100644 index 4352cff914..0000000000 --- a/ext/standard/tests/array/bug22088.phpt +++ /dev/null @@ -1,33 +0,0 @@ ---TEST-- -Bug #22088 (array_shift() leaves next index to be +1 too much) ---FILE-- -<?php - -$a = array('a', 'b', 'c'); -$last = array_shift ($a); -$a[] = 'a'; -var_dump($a); - -$a = array('a' => 1, 'b' => 2, 'c' => 3); -$last = array_shift ($a); -$a[] = 'a'; -var_dump($a); - -?> ---EXPECT-- -array(3) { - [0]=> - string(1) "b" - [1]=> - string(1) "c" - [2]=> - string(1) "a" -} -array(3) { - ["b"]=> - int(2) - ["c"]=> - int(3) - [0]=> - string(1) "a" -} diff --git a/ext/standard/tests/array/count_recursive.phpt b/ext/standard/tests/array/count_recursive.phpt deleted file mode 100644 index e6824ab0e5..0000000000 --- a/ext/standard/tests/array/count_recursive.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -count ---FILE-- -<?php -print "Testing NULL...\n"; -$arr = NULL; -print "COUNT_NORMAL: should be 0, is ".count($arr, COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 0, is ".count($arr, COUNT_RECURSIVE)."\n"; - -print "Testing arrays...\n"; -$arr = array(1, array(3, 4, array(6, array(8)))); -print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 8, is ".count($arr, COUNT_RECURSIVE)."\n"; - -print "Testing hashes...\n"; -$arr = array("a" => 1, "b" => 2, array("c" => 3, array("d" => 5))); -print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 6, is ".count($arr, COUNT_RECURSIVE)."\n"; - -print "Testing strings...\n"; -print "COUNT_NORMAL: should be 1, is ".count("string", COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 1, is ".count("string", COUNT_RECURSIVE)."\n"; - -print "Testing various types with no second argument.\n"; -print "COUNT_NORMAL: should be 1, is ".count("string")."\n"; -print "COUNT_NORMAL: should be 2, is ".count(array("a", array("b")))."\n"; - -$arr = array('a'=>array(NULL, NULL, NULL), 1=>array(NULL=>1, 1=>NULL), - array(array(array(array(array(NULL)))))); -print "Testing really cool arrays ;)\n"; -print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n"; -print "COUNT_RECURSIVE: should be 13, is ".count($arr, COUNT_RECURSIVE)."\n"; -?> ---EXPECT-- -Testing NULL... -COUNT_NORMAL: should be 0, is 0 -COUNT_RECURSIVE: should be 0, is 0 -Testing arrays... -COUNT_NORMAL: should be 2, is 2 -COUNT_RECURSIVE: should be 8, is 8 -Testing hashes... -COUNT_NORMAL: should be 3, is 3 -COUNT_RECURSIVE: should be 6, is 6 -Testing strings... -COUNT_NORMAL: should be 1, is 1 -COUNT_RECURSIVE: should be 1, is 1 -Testing various types with no second argument. -COUNT_NORMAL: should be 1, is 1 -COUNT_NORMAL: should be 2, is 2 -Testing really cool arrays ;) -COUNT_NORMAL: should be 3, is 3 -COUNT_RECURSIVE: should be 13, is 13 diff --git a/ext/standard/tests/array/data.inc b/ext/standard/tests/array/data.inc deleted file mode 100644 index 2991274be8..0000000000 --- a/ext/standard/tests/array/data.inc +++ /dev/null @@ -1,13 +0,0 @@ -<?php -$tmp = pow(2,24); -$data = array( - 'PHP', - 17=>'PHP: Hypertext Preprocessor', - 5=>'Test', - 'test'=>27, - 1000=>'test', - "-1000"=>array('banana', 'orange'), - 'monkey', - $tmp=>-1/3 -); -?> diff --git a/ext/standard/tests/array/range.phpt b/ext/standard/tests/array/range.phpt deleted file mode 100644 index 23fb985f86..0000000000 --- a/ext/standard/tests/array/range.phpt +++ /dev/null @@ -1,1345 +0,0 @@ ---TEST-- -range() ---FILE-- -<?php - var_dump(range(1, 100)); - var_dump(range(100, 1)); - - var_dump(range("1", "100")); - var_dump(range("100", "1")); - - var_dump(range("a", "z")); - var_dump(range("z", "a")); - var_dump(range("q", "q")); - - var_dump(range(5, 5)); - - var_dump(range(5.1, 10.1)); - var_dump(range(10.1, 5.1)); - - var_dump(range("5.1", "10.1")); - var_dump(range("10.1", "5.1")); - - var_dump(range(1, 5, 0.1)); - var_dump(range(5, 1, 0.1)); - - var_dump(range(1, 5, "0.1")); - var_dump(range("1", "5", 0.1)); -?> ---EXPECT-- -array(100) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - [10]=> - int(11) - [11]=> - int(12) - [12]=> - int(13) - [13]=> - int(14) - [14]=> - int(15) - [15]=> - int(16) - [16]=> - int(17) - [17]=> - int(18) - [18]=> - int(19) - [19]=> - int(20) - [20]=> - int(21) - [21]=> - int(22) - [22]=> - int(23) - [23]=> - int(24) - [24]=> - int(25) - [25]=> - int(26) - [26]=> - int(27) - [27]=> - int(28) - [28]=> - int(29) - [29]=> - int(30) - [30]=> - int(31) - [31]=> - int(32) - [32]=> - int(33) - [33]=> - int(34) - [34]=> - int(35) - [35]=> - int(36) - [36]=> - int(37) - [37]=> - int(38) - [38]=> - int(39) - [39]=> - int(40) - [40]=> - int(41) - [41]=> - int(42) - [42]=> - int(43) - [43]=> - int(44) - [44]=> - int(45) - [45]=> - int(46) - [46]=> - int(47) - [47]=> - int(48) - [48]=> - int(49) - [49]=> - int(50) - [50]=> - int(51) - [51]=> - int(52) - [52]=> - int(53) - [53]=> - int(54) - [54]=> - int(55) - [55]=> - int(56) - [56]=> - int(57) - [57]=> - int(58) - [58]=> - int(59) - [59]=> - int(60) - [60]=> - int(61) - [61]=> - int(62) - [62]=> - int(63) - [63]=> - int(64) - [64]=> - int(65) - [65]=> - int(66) - [66]=> - int(67) - [67]=> - int(68) - [68]=> - int(69) - [69]=> - int(70) - [70]=> - int(71) - [71]=> - int(72) - [72]=> - int(73) - [73]=> - int(74) - [74]=> - int(75) - [75]=> - int(76) - [76]=> - int(77) - [77]=> - int(78) - [78]=> - int(79) - [79]=> - int(80) - [80]=> - int(81) - [81]=> - int(82) - [82]=> - int(83) - [83]=> - int(84) - [84]=> - int(85) - [85]=> - int(86) - [86]=> - int(87) - [87]=> - int(88) - [88]=> - int(89) - [89]=> - int(90) - [90]=> - int(91) - [91]=> - int(92) - [92]=> - int(93) - [93]=> - int(94) - [94]=> - int(95) - [95]=> - int(96) - [96]=> - int(97) - [97]=> - int(98) - [98]=> - int(99) - [99]=> - int(100) -} -array(100) { - [0]=> - int(100) - [1]=> - int(99) - [2]=> - int(98) - [3]=> - int(97) - [4]=> - int(96) - [5]=> - int(95) - [6]=> - int(94) - [7]=> - int(93) - [8]=> - int(92) - [9]=> - int(91) - [10]=> - int(90) - [11]=> - int(89) - [12]=> - int(88) - [13]=> - int(87) - [14]=> - int(86) - [15]=> - int(85) - [16]=> - int(84) - [17]=> - int(83) - [18]=> - int(82) - [19]=> - int(81) - [20]=> - int(80) - [21]=> - int(79) - [22]=> - int(78) - [23]=> - int(77) - [24]=> - int(76) - [25]=> - int(75) - [26]=> - int(74) - [27]=> - int(73) - [28]=> - int(72) - [29]=> - int(71) - [30]=> - int(70) - [31]=> - int(69) - [32]=> - int(68) - [33]=> - int(67) - [34]=> - int(66) - [35]=> - int(65) - [36]=> - int(64) - [37]=> - int(63) - [38]=> - int(62) - [39]=> - int(61) - [40]=> - int(60) - [41]=> - int(59) - [42]=> - int(58) - [43]=> - int(57) - [44]=> - int(56) - [45]=> - int(55) - [46]=> - int(54) - [47]=> - int(53) - [48]=> - int(52) - [49]=> - int(51) - [50]=> - int(50) - [51]=> - int(49) - [52]=> - int(48) - [53]=> - int(47) - [54]=> - int(46) - [55]=> - int(45) - [56]=> - int(44) - [57]=> - int(43) - [58]=> - int(42) - [59]=> - int(41) - [60]=> - int(40) - [61]=> - int(39) - [62]=> - int(38) - [63]=> - int(37) - [64]=> - int(36) - [65]=> - int(35) - [66]=> - int(34) - [67]=> - int(33) - [68]=> - int(32) - [69]=> - int(31) - [70]=> - int(30) - [71]=> - int(29) - [72]=> - int(28) - [73]=> - int(27) - [74]=> - int(26) - [75]=> - int(25) - [76]=> - int(24) - [77]=> - int(23) - [78]=> - int(22) - [79]=> - int(21) - [80]=> - int(20) - [81]=> - int(19) - [82]=> - int(18) - [83]=> - int(17) - [84]=> - int(16) - [85]=> - int(15) - [86]=> - int(14) - [87]=> - int(13) - [88]=> - int(12) - [89]=> - int(11) - [90]=> - int(10) - [91]=> - int(9) - [92]=> - int(8) - [93]=> - int(7) - [94]=> - int(6) - [95]=> - int(5) - [96]=> - int(4) - [97]=> - int(3) - [98]=> - int(2) - [99]=> - int(1) -} -array(100) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) - [5]=> - int(6) - [6]=> - int(7) - [7]=> - int(8) - [8]=> - int(9) - [9]=> - int(10) - [10]=> - int(11) - [11]=> - int(12) - [12]=> - int(13) - [13]=> - int(14) - [14]=> - int(15) - [15]=> - int(16) - [16]=> - int(17) - [17]=> - int(18) - [18]=> - int(19) - [19]=> - int(20) - [20]=> - int(21) - [21]=> - int(22) - [22]=> - int(23) - [23]=> - int(24) - [24]=> - int(25) - [25]=> - int(26) - [26]=> - int(27) - [27]=> - int(28) - [28]=> - int(29) - [29]=> - int(30) - [30]=> - int(31) - [31]=> - int(32) - [32]=> - int(33) - [33]=> - int(34) - [34]=> - int(35) - [35]=> - int(36) - [36]=> - int(37) - [37]=> - int(38) - [38]=> - int(39) - [39]=> - int(40) - [40]=> - int(41) - [41]=> - int(42) - [42]=> - int(43) - [43]=> - int(44) - [44]=> - int(45) - [45]=> - int(46) - [46]=> - int(47) - [47]=> - int(48) - [48]=> - int(49) - [49]=> - int(50) - [50]=> - int(51) - [51]=> - int(52) - [52]=> - int(53) - [53]=> - int(54) - [54]=> - int(55) - [55]=> - int(56) - [56]=> - int(57) - [57]=> - int(58) - [58]=> - int(59) - [59]=> - int(60) - [60]=> - int(61) - [61]=> - int(62) - [62]=> - int(63) - [63]=> - int(64) - [64]=> - int(65) - [65]=> - int(66) - [66]=> - int(67) - [67]=> - int(68) - [68]=> - int(69) - [69]=> - int(70) - [70]=> - int(71) - [71]=> - int(72) - [72]=> - int(73) - [73]=> - int(74) - [74]=> - int(75) - [75]=> - int(76) - [76]=> - int(77) - [77]=> - int(78) - [78]=> - int(79) - [79]=> - int(80) - [80]=> - int(81) - [81]=> - int(82) - [82]=> - int(83) - [83]=> - int(84) - [84]=> - int(85) - [85]=> - int(86) - [86]=> - int(87) - [87]=> - int(88) - [88]=> - int(89) - [89]=> - int(90) - [90]=> - int(91) - [91]=> - int(92) - [92]=> - int(93) - [93]=> - int(94) - [94]=> - int(95) - [95]=> - int(96) - [96]=> - int(97) - [97]=> - int(98) - [98]=> - int(99) - [99]=> - int(100) -} -array(100) { - [0]=> - int(100) - [1]=> - int(99) - [2]=> - int(98) - [3]=> - int(97) - [4]=> - int(96) - [5]=> - int(95) - [6]=> - int(94) - [7]=> - int(93) - [8]=> - int(92) - [9]=> - int(91) - [10]=> - int(90) - [11]=> - int(89) - [12]=> - int(88) - [13]=> - int(87) - [14]=> - int(86) - [15]=> - int(85) - [16]=> - int(84) - [17]=> - int(83) - [18]=> - int(82) - [19]=> - int(81) - [20]=> - int(80) - [21]=> - int(79) - [22]=> - int(78) - [23]=> - int(77) - [24]=> - int(76) - [25]=> - int(75) - [26]=> - int(74) - [27]=> - int(73) - [28]=> - int(72) - [29]=> - int(71) - [30]=> - int(70) - [31]=> - int(69) - [32]=> - int(68) - [33]=> - int(67) - [34]=> - int(66) - [35]=> - int(65) - [36]=> - int(64) - [37]=> - int(63) - [38]=> - int(62) - [39]=> - int(61) - [40]=> - int(60) - [41]=> - int(59) - [42]=> - int(58) - [43]=> - int(57) - [44]=> - int(56) - [45]=> - int(55) - [46]=> - int(54) - [47]=> - int(53) - [48]=> - int(52) - [49]=> - int(51) - [50]=> - int(50) - [51]=> - int(49) - [52]=> - int(48) - [53]=> - int(47) - [54]=> - int(46) - [55]=> - int(45) - [56]=> - int(44) - [57]=> - int(43) - [58]=> - int(42) - [59]=> - int(41) - [60]=> - int(40) - [61]=> - int(39) - [62]=> - int(38) - [63]=> - int(37) - [64]=> - int(36) - [65]=> - int(35) - [66]=> - int(34) - [67]=> - int(33) - [68]=> - int(32) - [69]=> - int(31) - [70]=> - int(30) - [71]=> - int(29) - [72]=> - int(28) - [73]=> - int(27) - [74]=> - int(26) - [75]=> - int(25) - [76]=> - int(24) - [77]=> - int(23) - [78]=> - int(22) - [79]=> - int(21) - [80]=> - int(20) - [81]=> - int(19) - [82]=> - int(18) - [83]=> - int(17) - [84]=> - int(16) - [85]=> - int(15) - [86]=> - int(14) - [87]=> - int(13) - [88]=> - int(12) - [89]=> - int(11) - [90]=> - int(10) - [91]=> - int(9) - [92]=> - int(8) - [93]=> - int(7) - [94]=> - int(6) - [95]=> - int(5) - [96]=> - int(4) - [97]=> - int(3) - [98]=> - int(2) - [99]=> - int(1) -} -array(26) { - [0]=> - string(1) "a" - [1]=> - string(1) "b" - [2]=> - string(1) "c" - [3]=> - string(1) "d" - [4]=> - string(1) "e" - [5]=> - string(1) "f" - [6]=> - string(1) "g" - [7]=> - string(1) "h" - [8]=> - string(1) "i" - [9]=> - string(1) "j" - [10]=> - string(1) "k" - [11]=> - string(1) "l" - [12]=> - string(1) "m" - [13]=> - string(1) "n" - [14]=> - string(1) "o" - [15]=> - string(1) "p" - [16]=> - string(1) "q" - [17]=> - string(1) "r" - [18]=> - string(1) "s" - [19]=> - string(1) "t" - [20]=> - string(1) "u" - [21]=> - string(1) "v" - [22]=> - string(1) "w" - [23]=> - string(1) "x" - [24]=> - string(1) "y" - [25]=> - string(1) "z" -} -array(26) { - [0]=> - string(1) "z" - [1]=> - string(1) "y" - [2]=> - string(1) "x" - [3]=> - string(1) "w" - [4]=> - string(1) "v" - [5]=> - string(1) "u" - [6]=> - string(1) "t" - [7]=> - string(1) "s" - [8]=> - string(1) "r" - [9]=> - string(1) "q" - [10]=> - string(1) "p" - [11]=> - string(1) "o" - [12]=> - string(1) "n" - [13]=> - string(1) "m" - [14]=> - string(1) "l" - [15]=> - string(1) "k" - [16]=> - string(1) "j" - [17]=> - string(1) "i" - [18]=> - string(1) "h" - [19]=> - string(1) "g" - [20]=> - string(1) "f" - [21]=> - string(1) "e" - [22]=> - string(1) "d" - [23]=> - string(1) "c" - [24]=> - string(1) "b" - [25]=> - string(1) "a" -} -array(1) { - [0]=> - string(1) "q" -} -array(1) { - [0]=> - int(5) -} -array(6) { - [0]=> - float(5.1) - [1]=> - float(6.1) - [2]=> - float(7.1) - [3]=> - float(8.1) - [4]=> - float(9.1) - [5]=> - float(10.1) -} -array(6) { - [0]=> - float(10.1) - [1]=> - float(9.1) - [2]=> - float(8.1) - [3]=> - float(7.1) - [4]=> - float(6.1) - [5]=> - float(5.1) -} -array(6) { - [0]=> - float(5.1) - [1]=> - float(6.1) - [2]=> - float(7.1) - [3]=> - float(8.1) - [4]=> - float(9.1) - [5]=> - float(10.1) -} -array(6) { - [0]=> - float(10.1) - [1]=> - float(9.1) - [2]=> - float(8.1) - [3]=> - float(7.1) - [4]=> - float(6.1) - [5]=> - float(5.1) -} -array(41) { - [0]=> - float(1) - [1]=> - float(1.1) - [2]=> - float(1.2) - [3]=> - float(1.3) - [4]=> - float(1.4) - [5]=> - float(1.5) - [6]=> - float(1.6) - [7]=> - float(1.7) - [8]=> - float(1.8) - [9]=> - float(1.9) - [10]=> - float(2) - [11]=> - float(2.1) - [12]=> - float(2.2) - [13]=> - float(2.3) - [14]=> - float(2.4) - [15]=> - float(2.5) - [16]=> - float(2.6) - [17]=> - float(2.7) - [18]=> - float(2.8) - [19]=> - float(2.9) - [20]=> - float(3) - [21]=> - float(3.1) - [22]=> - float(3.2) - [23]=> - float(3.3) - [24]=> - float(3.4) - [25]=> - float(3.5) - [26]=> - float(3.6) - [27]=> - float(3.7) - [28]=> - float(3.8) - [29]=> - float(3.9) - [30]=> - float(4) - [31]=> - float(4.1) - [32]=> - float(4.2) - [33]=> - float(4.3) - [34]=> - float(4.4) - [35]=> - float(4.5) - [36]=> - float(4.6) - [37]=> - float(4.7) - [38]=> - float(4.8) - [39]=> - float(4.9) - [40]=> - float(5) -} -array(41) { - [0]=> - float(5) - [1]=> - float(4.9) - [2]=> - float(4.8) - [3]=> - float(4.7) - [4]=> - float(4.6) - [5]=> - float(4.5) - [6]=> - float(4.4) - [7]=> - float(4.3) - [8]=> - float(4.2) - [9]=> - float(4.1) - [10]=> - float(4) - [11]=> - float(3.9) - [12]=> - float(3.8) - [13]=> - float(3.7) - [14]=> - float(3.6) - [15]=> - float(3.5) - [16]=> - float(3.4) - [17]=> - float(3.3) - [18]=> - float(3.2) - [19]=> - float(3.1) - [20]=> - float(3) - [21]=> - float(2.9) - [22]=> - float(2.8) - [23]=> - float(2.7) - [24]=> - float(2.6) - [25]=> - float(2.5) - [26]=> - float(2.4) - [27]=> - float(2.3) - [28]=> - float(2.2) - [29]=> - float(2.1) - [30]=> - float(2) - [31]=> - float(1.9) - [32]=> - float(1.8) - [33]=> - float(1.7) - [34]=> - float(1.6) - [35]=> - float(1.5) - [36]=> - float(1.4) - [37]=> - float(1.3) - [38]=> - float(1.2) - [39]=> - float(1.1) - [40]=> - float(1) -} -array(41) { - [0]=> - float(1) - [1]=> - float(1.1) - [2]=> - float(1.2) - [3]=> - float(1.3) - [4]=> - float(1.4) - [5]=> - float(1.5) - [6]=> - float(1.6) - [7]=> - float(1.7) - [8]=> - float(1.8) - [9]=> - float(1.9) - [10]=> - float(2) - [11]=> - float(2.1) - [12]=> - float(2.2) - [13]=> - float(2.3) - [14]=> - float(2.4) - [15]=> - float(2.5) - [16]=> - float(2.6) - [17]=> - float(2.7) - [18]=> - float(2.8) - [19]=> - float(2.9) - [20]=> - float(3) - [21]=> - float(3.1) - [22]=> - float(3.2) - [23]=> - float(3.3) - [24]=> - float(3.4) - [25]=> - float(3.5) - [26]=> - float(3.6) - [27]=> - float(3.7) - [28]=> - float(3.8) - [29]=> - float(3.9) - [30]=> - float(4) - [31]=> - float(4.1) - [32]=> - float(4.2) - [33]=> - float(4.3) - [34]=> - float(4.4) - [35]=> - float(4.5) - [36]=> - float(4.6) - [37]=> - float(4.7) - [38]=> - float(4.8) - [39]=> - float(4.9) - [40]=> - float(5) -} -array(41) { - [0]=> - float(1) - [1]=> - float(1.1) - [2]=> - float(1.2) - [3]=> - float(1.3) - [4]=> - float(1.4) - [5]=> - float(1.5) - [6]=> - float(1.6) - [7]=> - float(1.7) - [8]=> - float(1.8) - [9]=> - float(1.9) - [10]=> - float(2) - [11]=> - float(2.1) - [12]=> - float(2.2) - [13]=> - float(2.3) - [14]=> - float(2.4) - [15]=> - float(2.5) - [16]=> - float(2.6) - [17]=> - float(2.7) - [18]=> - float(2.8) - [19]=> - float(2.9) - [20]=> - float(3) - [21]=> - float(3.1) - [22]=> - float(3.2) - [23]=> - float(3.3) - [24]=> - float(3.4) - [25]=> - float(3.5) - [26]=> - float(3.6) - [27]=> - float(3.7) - [28]=> - float(3.8) - [29]=> - float(3.9) - [30]=> - float(4) - [31]=> - float(4.1) - [32]=> - float(4.2) - [33]=> - float(4.3) - [34]=> - float(4.4) - [35]=> - float(4.5) - [36]=> - float(4.6) - [37]=> - float(4.7) - [38]=> - float(4.8) - [39]=> - float(4.9) - [40]=> - float(5) -} diff --git a/ext/standard/tests/array/var_export.phpt b/ext/standard/tests/array/var_export.phpt deleted file mode 100644 index 7b9df14624..0000000000 --- a/ext/standard/tests/array/var_export.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -var_export() and objects with numeric indexes properties ---FILE-- -<?php -$a = (object) array (1, 3, "foo" => "bar"); -var_export($a); -?> ---EXPECT-- -class stdClass { - var $foo = 'bar'; -} diff --git a/ext/standard/tests/assert/assert.phpt b/ext/standard/tests/assert/assert.phpt deleted file mode 100644 index 21924902a8..0000000000 --- a/ext/standard/tests/assert/assert.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -assert() ---POST-- ---GET-- ---FILE-- -<?php -function a($file,$line,$myev) -{ - echo "assertion failed $line,\"$myev\"\n"; -} - -class a -{ - function assert($file,$line,$myev) - { - echo "class assertion failed $line,\"$myev\"\n"; - } -} - -assert_options(ASSERT_ACTIVE,1); -assert_options(ASSERT_QUIET_EVAL,1); -assert_options(ASSERT_WARNING,0); - -$a = 0; - -assert_options(ASSERT_CALLBACK,"a"); -assert('$a != 0'); - -assert_options(ASSERT_CALLBACK,array("a","assert")); -assert('$a != 0'); - -$obj = new a(); -assert_options(ASSERT_CALLBACK,array(&$obj,"assert")); -assert('$a != 0'); -?> ---EXPECT-- -assertion failed 22,"$a != 0" -class assertion failed 25,"$a != 0" -class assertion failed 29,"$a != 0" diff --git a/ext/standard/tests/file/001-win32.phpt b/ext/standard/tests/file/001-win32.phpt deleted file mode 100644 index d18ee325a6..0000000000 --- a/ext/standard/tests/file/001-win32.phpt +++ /dev/null @@ -1,127 +0,0 @@ ---TEST-- -File type functions ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - die('skip only for Windows'); -} -?> ---POST-- ---GET-- ---FILE-- -<?php -chdir(dirname(__FILE__)); -@unlink('test.file'); -@unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -fclose (fopen('test.file', 'w')); -chmod ('test.file', 0744); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -sleep (2); -if (file_exists('test.link')) { - echo "test.link exists\n"; -} else { - echo "test.link does not exist\n"; -} -if (is_link('test.file')) { - echo "test.file is a symlink\n"; -} else { - echo "test.file is not a symlink\n"; -} -if (is_link('test.link')) { - echo "test.link is a symlink\n"; -} else { - echo "test.link is not a symlink\n"; -} -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -$s = stat ('test.file'); -$ls = lstat ('test.file'); -for ($i = 0; $i <= 12; $i++) { - if ($ls[$i] != $s[$i]) { - echo "test.file lstat and stat differ at element $i\n"; - } -} -echo "test.file is " . filetype('test.file') . "\n"; -echo "test.link is " . filetype('test.link') . "\n"; -printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); -echo "test.file size is " . filesize('test.file') . "\n"; -if (is_writeable('test.file')) { - echo "test.file is writeable\n"; -} else { - echo "test.file is not writeable\n"; -} -if (is_readable('test.file')) { - echo "test.file is readable\n"; -} else { - echo "test.file is not readable\n"; -} -if (is_file('test.file')) { - echo "test.file is a regular file\n"; -} else { - echo "test.file is not a regular file\n"; -} -if (is_file('test.link')) { - echo "test.link is a regular file\n"; -} else { - echo "test.link is not a regular file\n"; -} -if (is_dir('test.link')) { - echo "test.link is a directory\n"; -} else { - echo "test.link is not a directory\n"; -} -if (is_dir('../file')) { - echo "../file is a directory\n"; -} else { - echo "../file is not a directory\n"; -} -if (is_dir('test.file')) { - echo "test.file is a directory\n"; -} else { - echo "test.file is not a directory\n"; -} -unlink('test.file'); -if (file_exists('test.file')) { - echo "test.file exists (cached)\n"; -} else { - echo "test.file does not exist\n"; -} -clearstatcache(); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -?> ---EXPECT-- -test.file does not exist -test.file exists -test.link does not exist -test.file is not a symlink -test.link is not a symlink -test.file exists -test.file is file -test.link is file -test.file permissions are 0666 -test.file size is 0 -test.file is writeable -test.file is readable -test.file is a regular file -test.link is not a regular file -test.link is not a directory -../file is a directory -test.file is not a directory -test.file does not exist -test.file does not exist diff --git a/ext/standard/tests/file/001.phpt b/ext/standard/tests/file/001.phpt deleted file mode 100644 index 2191fa23d6..0000000000 --- a/ext/standard/tests/file/001.phpt +++ /dev/null @@ -1,148 +0,0 @@ ---TEST-- -File type functions ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip no symlinks on Windows'); -} -?> ---POST-- ---GET-- ---FILE-- -<?php -chdir(dirname(__FILE__)); -@unlink('test.file'); -@unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -fclose (fopen('test.file', 'w')); -chmod ('test.file', 0744); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -sleep (2); -symlink('test.file','test.link'); -if (file_exists('test.link')) { - echo "test.link exists\n"; -} else { - echo "test.link does not exist\n"; -} -if (is_link('test.file')) { - echo "test.file is a symlink\n"; -} else { - echo "test.file is not a symlink\n"; -} -if (is_link('test.link')) { - echo "test.link is a symlink\n"; -} else { - echo "test.link is not a symlink\n"; -} -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -$s = stat ('test.file'); -$ls = lstat ('test.file'); -for ($i = 0; $i <= 12; $i++) { - if ($ls[$i] != $s[$i]) { - echo "test.file lstat and stat differ at element $i\n"; - } -} -$s = stat ('test.link'); -$ls = lstat ('test.link'); -for ($i = 0; $i <= 11; $i++) { - if ($ls[$i] != $s[$i]) { - if ($i != 6 && $i != 11) echo "test.link lstat and stat differ at element $i\n"; - } -} -echo "test.file is " . filetype('test.file') . "\n"; -echo "test.link is " . filetype('test.link') . "\n"; -printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file')); -echo "test.file size is " . filesize('test.file') . "\n"; -if (is_writeable('test.file')) { - echo "test.file is writeable\n"; -} else { - echo "test.file is not writeable\n"; -} -if (is_readable('test.file')) { - echo "test.file is readable\n"; -} else { - echo "test.file is not readable\n"; -} -if (is_executable('test.file')) { - echo "test.file is executable\n"; -} else { - echo "test.file is not executable\n"; -} -if (is_file('test.file')) { - echo "test.file is a regular file\n"; -} else { - echo "test.file is not a regular file\n"; -} -if (is_file('test.link')) { - echo "test.link is a regular file\n"; -} else { - echo "test.link is not a regular file\n"; -} -if (is_dir('test.link')) { - echo "test.link is a directory\n"; -} else { - echo "test.link is not a directory\n"; -} -if (is_dir('../file')) { - echo "../file is a directory\n"; -} else { - echo "../file is not a directory\n"; -} -if (is_dir('test.file')) { - echo "test.file is a directory\n"; -} else { - echo "test.file is not a directory\n"; -} -unlink('test.file'); -unlink('test.link'); -if (file_exists('test.file')) { - echo "test.file exists (cached)\n"; -} else { - echo "test.file does not exist\n"; -} -clearstatcache(); -if (file_exists('test.file')) { - echo "test.file exists\n"; -} else { - echo "test.file does not exist\n"; -} -?> ---EXPECT-- -test.file does not exist -test.file exists -test.link exists -test.file is not a symlink -test.link is a symlink -test.file exists -test.link lstat and stat differ at element 1 -test.link lstat and stat differ at element 2 -test.link lstat and stat differ at element 7 -test.link lstat and stat differ at element 8 -test.link lstat and stat differ at element 9 -test.link lstat and stat differ at element 10 -test.file is file -test.link is link -test.file permissions are 0744 -test.file size is 0 -test.file is writeable -test.file is readable -test.file is executable -test.file is a regular file -test.link is a regular file -test.link is not a directory -../file is a directory -test.file is not a directory -test.file does not exist -test.file does not exist diff --git a/ext/standard/tests/file/002.phpt b/ext/standard/tests/file/002.phpt deleted file mode 100644 index 4642bac366..0000000000 --- a/ext/standard/tests/file/002.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -File/Stream functions ---POST-- ---GET-- ---FILE-- -<?php - -$data = <<<EOD -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -EOD; - -$name = tempnam("./ext/standard/tests/file/", "php"); -$fp = fopen($name, "w"); -fwrite($fp, $data); -fclose($fp); - -//readfile($name); -echo file_get_contents($name); - -unlink($name); - -?> ---EXPECT-- -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah -blah blah blah blah blah blah blah diff --git a/ext/standard/tests/file/003.phpt b/ext/standard/tests/file/003.phpt deleted file mode 100644 index 2b75bdccee..0000000000 --- a/ext/standard/tests/file/003.phpt +++ /dev/null @@ -1,43 +0,0 @@ ---TEST-- -is_*() and file_exists() return values are boolean. ---POST-- ---GET-- ---FILE-- -<?php - -$funcs = array( - 'is_writable', - 'is_readable', - 'is_executable', - 'is_file', - 'file_exists', -); - -$filename=""; - -foreach ($funcs as $test) { - $bb = $test($filename); - echo gettype($bb)."\n"; - clearstatcache(); -} - -$filename="run-tests.php"; - -foreach ($funcs as $test) { - $bb = $test($filename); - echo gettype($bb)."\n"; - clearstatcache(); -} - -?> ---EXPECT-- -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean -boolean diff --git a/ext/standard/tests/file/bug12556.phpt b/ext/standard/tests/file/bug12556.phpt deleted file mode 100644 index 6d8763245f..0000000000 --- a/ext/standard/tests/file/bug12556.phpt +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -Bug #12556: fgetcvs ignores lengths when quotes not closed ---POST-- ---GET-- ---FILE-- -<?php -$fp = fopen(dirname(__FILE__)."/test.csv", "r"); -while($line = fgetcsv($fp, 24)) { - $line = str_replace("\x0d\x0a", "\x0a", $line); - var_dump($line); -} -fclose($fp); -?> ---EXPECT-- -array(4) { - [0]=> - string(1) "6" - [1]=> - string(1) "7" - [2]=> - string(1) "8" - [3]=> - string(5) "line1" -} -array(4) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - [2]=> - string(1) "3" - [3]=> - string(186) "line2 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -" -} diff --git a/ext/standard/tests/file/bug20424.phpt b/ext/standard/tests/file/bug20424.phpt deleted file mode 100644 index 0352d46f8e..0000000000 --- a/ext/standard/tests/file/bug20424.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #20424: stream_get_meta_data craches on a normal file stream ---POST-- ---GET-- ---FILE-- -<?php -$f = fopen("run-tests.php", "r"); -$dummy = var_export(stream_get_meta_data($f), TRUE); -echo "I'm alive!\n"; -?> ---EXPECT-- -I'm alive! diff --git a/ext/standard/tests/file/bug22382.phpt b/ext/standard/tests/file/bug22382.phpt deleted file mode 100644 index 5255eaf350..0000000000 --- a/ext/standard/tests/file/bug22382.phpt +++ /dev/null @@ -1,27 +0,0 @@ ---TEST-- -Bug #22382: fgetcvs does not handle escaped quotes correctly ---POST-- ---GET-- ---FILE-- -<?php -$fp = fopen(dirname(__FILE__)."/test2.csv", "r"); -while(($line = fgetcsv($fp, 1024))) { - var_dump($line); -} -fclose($fp); -?> ---EXPECT-- -array(6) { - [0]=> - string(3) "One" - [1]=> - string(7) "\"Two\"" - [2]=> - string(7) "Three\"" - [3]=> - string(4) "Four" - [4]=> - string(2) "\\" - [5]=> - string(28) "\\\\\\\\\\\\\\\\\\\\\\\"\\\\" -}
\ No newline at end of file diff --git a/ext/standard/tests/file/bug22414.phpt b/ext/standard/tests/file/bug22414.phpt deleted file mode 100644 index 809ce50014..0000000000 --- a/ext/standard/tests/file/bug22414.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -Bug #22414: passthru() does not read data correctly ---SKIPIF-- -<?php - $cat_path = @shell_exec("which cat"); - if (empty($cat_path)) { - die('skip cat binary needed for this test is not avaliable'); - } -?> ---POST-- ---GET-- ---FILE-- -<?php - $php = getenv('TEST_PHP_EXECUTABLE'); - $pwd = realpath(dirname(__FILE__)); - - /* Regular Data Test */ - passthru($php . ' -r " echo \"HELLO\"; "'); - - echo "\n"; - - /* Binary Data Test */ - @unlink($pwd . '/passthru_test'); - - $cmd = $php . ' -r \' passthru("cat ' . $php . '"); \' > ' . $pwd . '/passthru_test'; - exec($cmd); - - if (md5_file($php) == md5_file($pwd . '/passthru_test')) { - echo "Works\n"; - } else { - echo "Does not work\n"; - } - - @unlink($pwd . '/passthru_test'); -?> ---EXPECT-- -HELLO -Works diff --git a/ext/standard/tests/file/fopencookie.phpt b/ext/standard/tests/file/fopencookie.phpt deleted file mode 100644 index 4043f85f89..0000000000 --- a/ext/standard/tests/file/fopencookie.phpt +++ /dev/null @@ -1,86 +0,0 @@ ---TEST-- -fopencookie detected and working (or cast mechanism works) ---FILE-- -<?php -# vim600:syn=php: - -/* This test verifies that the casting mechanism is working correctly. - * On systems with fopencookie, a FILE* is created around the user - * stream and that is passed back to the ZE to include. - * On systems without fopencookie, the stream is fed into a temporary - * file, and that temporary file is passed back to the ZE. - * The important thing here is really fopencookie; the glibc people - * changed the binary interface, so if haven't detected it correctly, - * you can expect this test to segfault. - * - * FIXME: the test really needs something to fseek(3) on the FILE* - * used internally for this test to be really effective. - */ - -class userstream { - var $position = 0; - var $data = "If you can read this, it worked"; - - function stream_open($path, $mode, $options, &$opened_path) - { - return true; - } - - function stream_read($count) - { - $ret = substr($this->data, $this->position, $count); - $this->position += strlen($ret); - return $ret; - } - - function stream_tell() - { - return $this->position; - } - - function stream_eof() - { - return $this->position >= strlen($this->data); - } - - function stream_seek($offset, $whence) - { - switch($whence) { - case SEEK_SET: - if ($offset < strlen($this->data) && $offset >= 0) { - $this->position = $offset; - return true; - } else { - return false; - } - break; - case SEEK_CUR: - if ($offset >= 0) { - $this->position += $offset; - return true; - } else { - return false; - } - break; - case SEEK_END: - if (strlen($this->data) + $offset >= 0) { - $this->position = strlen($this->data) + $offset; - return true; - } else { - return false; - } - break; - default: - return false; - } - } - -} - -stream_register_wrapper("cookietest", "userstream"); - -include("cookietest://foo"); - -?> ---EXPECT-- -If you can read this, it worked diff --git a/ext/standard/tests/file/test.csv b/ext/standard/tests/file/test.csv deleted file mode 100644 index d99984c2ab..0000000000 --- a/ext/standard/tests/file/test.csv +++ /dev/null @@ -1,17 +0,0 @@ -6,7,8,line1 -1,2,3,"line2 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 -2,4,5,line3 diff --git a/ext/standard/tests/file/test2.csv b/ext/standard/tests/file/test2.csv deleted file mode 100644 index d816464170..0000000000 --- a/ext/standard/tests/file/test2.csv +++ /dev/null @@ -1 +0,0 @@ -"One","\"Two\"","Three\"","Four","\\","\\\\\\\\\\\\\\\\\\\\\\\"\\\\" diff --git a/ext/standard/tests/file/userfilters.phpt b/ext/standard/tests/file/userfilters.phpt deleted file mode 100644 index 9c42e8e7f6..0000000000 --- a/ext/standard/tests/file/userfilters.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -User-space filters ---FILE-- -<?php -# vim600:syn=php: - -class UpperCaseFilter extends php_user_filter { - function oncreate() - { - echo "oncreate:\n"; - var_dump($this->filtername); - var_dump($this->params); - } - - function flush($closing) - { - echo "flush:\n"; - } - - function onclose() - { - echo "onclose:\n"; - } - - function write($data) - { - echo "write:\n"; - $x = parent::write($data); - return strlen($data); - } - - function read($bytes) - { - echo "read:\n"; - $x = parent::read($bytes); - return strtoupper($x); - } -}; - -var_dump(stream_register_filter("string.uppercase", "UpperCaseFilter")); -$fp = tmpfile(); - -fwrite($fp, "hello there"); -rewind($fp); - -var_dump(stream_filter_prepend($fp, "string.uppercase")); -var_dump(fgets($fp)); -fclose($fp); -?> ---EXPECT-- -bool(true) -oncreate: -string(16) "string.uppercase" -NULL -bool(true) -read: -read: -string(11) "HELLO THERE" -flush: -onclose: diff --git a/ext/standard/tests/file/userstreams.phpt b/ext/standard/tests/file/userstreams.phpt deleted file mode 100644 index efc2880f9a..0000000000 --- a/ext/standard/tests/file/userstreams.phpt +++ /dev/null @@ -1,325 +0,0 @@ ---TEST-- -User-space streams ---FILE-- -<?php -# vim600:syn=php: - -/* This is a fairly aggressive test that looks at - * user streams and also gives the seek/gets/buffer - * layer of streams a thorough testing */ - -$lyrics = <<<EOD -...and the road becomes my bride -I have stripped of all but pride -so in her I do confide -and she keeps me satisfied -gives me all I need -...and with dust in throat I crave -to the game you stay a slave -rover wanderer -nomad vagabond -call me what you will - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill redefine anywhere - Anywhere I roam - Where I lay my head is home -...and the earth becomes my throne -I adapt to the unknown -under wandering stars Ive grown -by myself but not alone -I ask no one -...and my ties are severed clean -the less I have the more I gain -off the beaten path I reign -rover wanderer -nomad vagabond -call me what you will - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill never mind anywhere - Anywhere I roam - Where I lay my head is home - But Ill take my time anywhere - Free to speak my mind anywhere - and Ill take my find anywhere - Anywhere I roam - Where I lay my head is home - carved upon my stone - my body lie but still I roam - Wherever I may roam. - -Wherever I May Roam - -EOD; - -/* repeat the data a few times so that it grows larger than - * the default cache chunk size and that we have something - * to seek around... */ -$DATA = ""; -for ($i = 0; $i < 30; $i++) { - if ($i % 2 == 0) - $DATA .= str_rot13($lyrics); - else - $DATA .= $lyrics; -} - -/* store the data in a regular file so that we can compare - * the results */ -$tf = tmpfile(); -fwrite($tf, $DATA); -$n = ftell($tf); -rewind($tf) or die("failed to rewind tmp file!"); -if (ftell($tf) != 0) - die("tmpfile is not at start!"); -$DATALEN = strlen($DATA); -if ($n != $DATALEN) - die("tmpfile stored $n bytes; should be $DATALEN!"); - -class uselessstream -{ -} - -class mystream -{ - var $path; - var $mode; - var $options; - - var $position; - var $varname; - - function stream_open($path, $mode, $options, &$opened_path) - { - $this->path = $path; - $this->mode = $mode; - $this->options = $options; - - $split = parse_url($path); - $this->varname = $split["host"]; - - if (strchr($mode, 'a')) - $this->position = strlen($GLOBALS[$this->varname]); - else - $this->position = 0; - - return true; - } - - function stream_read($count) - { - $ret = substr($GLOBALS[$this->varname], $this->position, $count); - $this->position += strlen($ret); - return $ret; - } - - function stream_tell() - { - return $this->position; - } - - function stream_eof() - { - return $this->position >= strlen($GLOBALS[$this->varname]); - } - - function stream_seek($offset, $whence) - { - switch($whence) { - case SEEK_SET: - if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) { - $this->position = $offset; - return true; - } else { - return false; - } - break; - case SEEK_CUR: - if ($offset >= 0) { - $this->position += $offset; - return true; - } else { - return false; - } - break; - case SEEK_END: - if (strlen($GLOBALS[$this->varname]) + $offset >= 0) { - $this->position = strlen($GLOBALS[$this->varname]) + $offset; - return true; - } else { - return false; - } - break; - default: - return false; - } - } - -} - -if (@stream_register_wrapper("bogus", "class_not_exist")) { - die("Registered a non-existant class!!!???"); -} -echo "Not Registered\n"; - -if (!stream_register_wrapper("test", "mystream")) { - die("test wrapper registration failed"); -} -echo "Registered\n"; - -if (!stream_register_wrapper("bogon", "uselessstream")) { - die("bogon wrapper registration failed"); -} -echo "Registered\n"; - -$b = @fopen("bogon://url", "rb"); -if (is_resource($b)) { - die("Opened a bogon??"); -} - -$fp = fopen("test://DATA", "rb"); -if (!$fp || !is_resource($fp)) { - die("Failed to open resource"); -} - -/* some default seeks that will cause buffer/cache misses */ -$seeks = array( - array(SEEK_SET, 0, 0), - array(SEEK_CUR, 8450, 8450), - array(SEEK_CUR, -7904, 546), - array(SEEK_CUR, 12456, 13002), - - /* end up at BOF so that randomly generated seek offsets - * below will know where they are supposed to be */ - array(SEEK_SET, 0, 0) -); - -$whence_map = array( - SEEK_CUR, - SEEK_SET, - SEEK_END -); -$whence_names = array( - SEEK_CUR => "SEEK_CUR", - SEEK_SET => "SEEK_SET", - SEEK_END => "SEEK_END" - ); - -/* generate some random seek offsets */ -$position = 0; -for ($i = 0; $i < 256; $i++) { - $whence = $whence_map[array_rand($whence_map, 1)]; - switch($whence) { - case SEEK_SET: - $offset = rand(0, $DATALEN); - $position = $offset; - break; - case SEEK_END: - $offset = -rand(0, $DATALEN); - $position = $DATALEN + $offset; - break; - case SEEK_CUR: - $offset = rand(0, $DATALEN); - $offset -= $position; - $position += $offset; - break; - } - - $seeks[] = array($whence, $offset, $position); -} - -/* we compare the results of fgets using differing line lengths to - * test the fgets layer also */ -$line_lengths = array(1024, 256, 64, 16); -$fail_count = 0; - -ob_start(); -foreach($line_lengths as $line_length) { - /* now compare the real stream with the user stream */ - $j = 0; - rewind($tf); - rewind($fp); - foreach($seeks as $seekdata) { - list($whence, $offset, $position) = $seekdata; - - $rpb = ftell($tf); - $rr = (int)fseek($tf, $offset, $whence); - $rpa = ftell($tf); - $rline = fgets($tf, $line_length); - (int)fseek($tf, - strlen($rline), SEEK_CUR); - - $upb = ftell($fp); - $ur = (int)fseek($fp, $offset, $whence); - $upa = ftell($fp); - $uline = fgets($fp, $line_length); - (int)fseek($fp, - strlen($uline), SEEK_CUR); - - printf("\n--[%d] whence=%s offset=%d line_length=%d position_should_be=%d --\n", - $j, $whence_names[$whence], $offset, $line_length, $position); - printf("REAL: pos=(%d,%d,%d) ret=%d line[%d]=`%s'\n", $rpb, $rpa, ftell($tf), $rr, strlen($rline), $rline); - printf("USER: pos=(%d,%d,%d) ret=%d line[%d]=`%s'\n", $upb, $upa, ftell($fp), $ur, strlen($uline), $uline); - - if ($rr != $ur || $rline != $uline || $rpa != $position || $upa != $position) { - $fail_count++; - echo "###################################### FAIL!\n"; - $dat = stream_get_meta_data($fp); - var_dump($dat); - break; - } - - $j++; - } - if ($fail_count) - break; -} - -if ($fail_count == 0) { - ob_end_clean(); - echo "SEEK: OK\n"; -} else { - echo "SEEK: FAIL\n"; - ob_end_flush(); -} - -$fail_count = 0; - -fseek($fp, $DATALEN / 2, SEEK_SET); -fseek($tf, $DATALEN / 2, SEEK_SET); - -if (ftell($fp) != ftell($tf)) { - echo "SEEK: positions do not match!\n"; -} - -$n = 0; -while(!feof($fp)) { - $uline = fgets($fp, 1024); - $rline = fgets($tf, 1024); - - if ($uline != $rline) { - echo "FGETS: FAIL\niter=$n user=$uline [pos=" . ftell($fp) . "]\nreal=$rline [pos=" . ftell($tf) . "]\n"; - $fail_count++; - break; - } -} - -if ($fail_count == 0) { - echo "FGETS: OK\n"; -} - -/* One final test to see if the position is respected when opened for append */ -$fp = fopen("test://lyrics", "a+"); -rewind($fp); -var_dump(ftell($fp)); -$data = fgets($fp); -fclose($fp); -echo $data . "\n"; - -?> ---EXPECT-- -Not Registered -Registered -Registered -SEEK: OK -FGETS: OK -int(0) -...and the road becomes my bride diff --git a/ext/standard/tests/filters/basic.phpt b/ext/standard/tests/filters/basic.phpt deleted file mode 100644 index 702c1ddadd..0000000000 --- a/ext/standard/tests/filters/basic.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -basic stream filter tests ---FILE-- -<?php -# vim600:syn=php: - -$text = "Hello There!"; -$filters = array("string.rot13", "string.toupper", "string.tolower"); - -function filter_test($names) -{ - $fp = tmpfile(); - fwrite($fp, $GLOBALS["text"]); - rewind($fp); - foreach ($names as $name) { - echo "filter: $name\n"; - var_dump(stream_filter_prepend($fp, $name)); - } - var_dump(fgets($fp)); - fclose($fp); -} - -foreach ($filters as $filter) { - filter_test(array($filter)); -} - -filter_test(array($filters[0], $filters[1])); - -?> ---EXPECT-- -filter: string.rot13 -bool(true) -string(12) "Uryyb Gurer!" -filter: string.toupper -bool(true) -string(12) "HELLO THERE!" -filter: string.tolower -bool(true) -string(12) "hello there!" -filter: string.rot13 -bool(true) -filter: string.toupper -bool(true) -string(12) "URYYB GURER!" diff --git a/ext/standard/tests/general_functions/001.phpt b/ext/standard/tests/general_functions/001.phpt deleted file mode 100644 index e84622902c..0000000000 --- a/ext/standard/tests/general_functions/001.phpt +++ /dev/null @@ -1,69 +0,0 @@ ---TEST-- -sprintf() function ---POST-- ---GET-- ---FILE-- -<?php - -$agent = sprintf("%.5s", "James Bond, 007"); - -echo("sprintf string truncate test: "); -if ($agent == "James") { - echo("passed\n"); -} else { - echo("failed!\n"); -} - -echo("sprintf padding and align test: "); -$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33); -if ($test == "abc0020 fisketur !") { - echo("passed\n"); -} else { - echo("failed!\n"); -} - -echo("sprintf octal and hex test: "); -$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925); -if ($test == " 200 400 BFFF 0034c385") { - echo("passed\n"); -} else { - echo("failed!\n"); -} - -echo("sprintf octal binary test: "); -$test = sprintf("%b", 3457925); -if ($test == "1101001100001110000101") { - echo("passed\n"); -} else { - echo("failed!\n"); -} - -echo("sprintf float test: "); -$test = sprintf("%0"."06.2f", 10000/3.0); -if ($test == "003333.33") { - echo("passed\n"); -} else { - echo("failed!\n"); -} - -echo sprintf("%.2f\n", "99.00"); -echo sprintf("%.2f\n", 99.00); - -echo sprintf("%e\n", 1.234E-18); -echo sprintf("%e\n", 1.234E+18); -echo sprintf("%e\n", 9843243.12); -echo sprintf("%e\n", -9843243.12); - -?> ---EXPECT-- -sprintf string truncate test: passed -sprintf padding and align test: passed -sprintf octal and hex test: passed -sprintf octal binary test: passed -sprintf float test: passed -99.00 -99.00 -1.23400e-18 -1.23400e+18 -9.84324e+6 --9.84324e+6 diff --git a/ext/standard/tests/general_functions/002.phpt b/ext/standard/tests/general_functions/002.phpt deleted file mode 100644 index 8ab1a72f07..0000000000 --- a/ext/standard/tests/general_functions/002.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -quoted_printable_decode() function test ---POST-- ---GET-- ---FILE-- -<?php echo quoted_printable_decode("=FAwow-factor=C1=d0=D5=DD=C5=CE=CE=D9=C5=0A= -=20=D4=cf=D2=C7=CF=D7=D9=C5= -=20= -=D0= -=D2=CF=C5=CB=D4=D9"); ?> ---EXPECT-- -úwow-factorÁÐÕÝÅÎÎÙÅ - ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ diff --git a/ext/standard/tests/general_functions/003.phpt b/ext/standard/tests/general_functions/003.phpt deleted file mode 100644 index 141b4d7052..0000000000 --- a/ext/standard/tests/general_functions/003.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -levenshtein() function test ---POST-- ---GET-- ---FILE-- -<?php - -function test_me($title,$expect,$text1,$text2,$cost1=0,$cost2=0,$cost3=0) { - - if($cost1==0) - $result=levenshtein($text1,$text2); - else - $result=levenshtein($text1,$text2,$cost1,$cost2,$cost3); - - if($result==$expect) return 0; - - echo "$title: result is $result instead of $expect "; - echo "for '$text1'/'$text2' "; - if($cost1) echo "($cost1:$cost2:$cost3)"; - echo "\n"; - - return 1; -} - -$n=0; - -$n += test_me("equal" , 0, "12345", "12345"); -$n += test_me("1st empty" , 3, "", "xzy"); -$n += test_me("2nd empty" , 3, "xzy", ""); -$n += test_me("both empty" , 0, "", ""); -$n += test_me("1 char" , 1, "1", "2"); -$n += test_me("2 char swap", 2, "12", "21"); - -$n += test_me("inexpensive delete", 2, "2121", "11", 2, 1, 1); -$n += test_me("expensive delete" , 10, "2121", "11", 2, 1, 5); -$n += test_me("inexpensive insert", 2, "11", "2121", 1, 1, 1); -$n += test_me("expensive insert" , 10, "11", "2121", 5, 1, 1); - -$n += test_me("expensive replace" , 3, "111", "121", 2, 3, 2); -$n += test_me("very expensive replace", 4, "111", "121", 2, 9, 2); - -$n += test_me("bug #7368", 2, "13458", "12345"); -$n += test_me("bug #7368", 2, "1345", "1234"); - -$n += test_me("bug #6562", 1, "debugg", "debug"); -$n += test_me("bug #6562", 1, "ddebug", "debug"); -$n += test_me("bug #6562", 2, "debbbug", "debug"); -$n += test_me("bug #6562", 1, "debugging", "debuging"); - -$n += test_me("bug #16473", 2, "a", "bc"); -$n += test_me("bug #16473", 2, "xa", "xbc"); -$n += test_me("bug #16473", 2, "xax", "xbcx"); -$n += test_me("bug #16473", 2, "ax", "bcx"); - - -echo ($n==0)?"all passed\n":"$n failed\n"; - -?> ---EXPECT-- -all passed diff --git a/ext/standard/tests/general_functions/004.data b/ext/standard/tests/general_functions/004.data deleted file mode 100644 index 5dd0832842..0000000000 --- a/ext/standard/tests/general_functions/004.data +++ /dev/null @@ -1,4 +0,0 @@ -name value comment -true 1 boolean true -false 0 boolean false -empty nothing diff --git a/ext/standard/tests/general_functions/004.phpt b/ext/standard/tests/general_functions/004.phpt deleted file mode 100644 index 3bd1fb1eac..0000000000 --- a/ext/standard/tests/general_functions/004.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -fgetcsv() with tab delimited fields (BUG #8258) ---POST-- ---GET-- ---FILE-- -<?php -chdir(dirname(__FILE__)); -$fp=fopen("004.data","r"); -while($a=fgetcsv($fp,100,"\t")) { - echo join(",",$a)."\n"; -} -fclose($fp); -?> ---EXPECT-- -name,value,comment -true,1,boolean true -false,0,boolean false -empty,,nothing diff --git a/ext/standard/tests/general_functions/005.phpt b/ext/standard/tests/general_functions/005.phpt deleted file mode 100644 index 329d46e764..0000000000 --- a/ext/standard/tests/general_functions/005.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -is_scalar() function test ---POST-- ---GET-- ---FILE-- -<?php -class foo {} -var_dump (is_scalar (TRUE)); -var_dump (is_scalar (1)); -var_dump (is_scalar (1.0)); -var_dump (is_scalar ("Hi!")); -var_dump (is_scalar (NULL)); -var_dump (is_scalar (array ())); -var_dump (is_scalar (new foo())); -var_dump (is_scalar (opendir('.'))); -?> ---EXPECT-- -bool(true) -bool(true) -bool(true) -bool(true) -bool(false) -bool(false) -bool(false) -bool(false) - diff --git a/ext/standard/tests/general_functions/006.phpt b/ext/standard/tests/general_functions/006.phpt deleted file mode 100644 index 9db1ca3280..0000000000 --- a/ext/standard/tests/general_functions/006.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -quoted_printable_decode() function test with CR/LF ---POST-- ---GET-- ---FILE-- -<?php echo quoted_printable_decode("=FAwow-factor=C1=D0=D5=DD=C5=CE=CE=D9=C5=0A= -=20=D4=CF=D2=C7=CF=D7=D9=C5= -=20= -=D0= -=D2=CF=C5=CB=D4=D9"); ?> ---EXPECT-- -úwow-factorÁÐÕÝÅÎÎÙÅ - ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ diff --git a/ext/standard/tests/general_functions/007.phpt b/ext/standard/tests/general_functions/007.phpt deleted file mode 100644 index 422ff3d94f..0000000000 --- a/ext/standard/tests/general_functions/007.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -MD5 / Base64 ---POST-- ---GET-- ---FILE-- -<?php -function test($str) { - $res = md5(base64_decode(base64_encode($str)))."\n"; - return $res; -} -echo test(""); -echo test("a"); -echo test("abc"); -echo test("message digest"); -echo test("abcdefghijklmnopqrstuvwxyz"); -echo test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -echo test("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); -?> ---EXPECT-- -d41d8cd98f00b204e9800998ecf8427e -0cc175b9c0f1b6a831c399e269772661 -900150983cd24fb0d6963f7d28e17f72 -f96b697d7cb7938d525a2f31aaf161d0 -c3fcd3d76192e4007dfb496cca67e13b -d174ab98d277d9f5a5611c2c9f419d9f -57edf4a22be3c955ac49da2e2107b67a diff --git a/ext/standard/tests/general_functions/008.phpt b/ext/standard/tests/general_functions/008.phpt deleted file mode 100644 index bb633c334d..0000000000 --- a/ext/standard/tests/general_functions/008.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -var_dump float test ---INI-- -precision=12 ---FILE-- -<?php -// this checks f,g,G conversion for snprintf/spprintf -var_dump(array(ini_get('precision'),.012,-.012,.12,-.12,1.2,-1.2,12.,-12.,0.000123,.0000123,123456789012.0,1234567890123.0,12345678901234567890.0)); -?> ---EXPECT-- -array(14) { - [0]=> - string(2) "12" - [1]=> - float(0.012) - [2]=> - float(-0.012) - [3]=> - float(0.12) - [4]=> - float(-0.12) - [5]=> - float(1.2) - [6]=> - float(-1.2) - [7]=> - float(12) - [8]=> - float(-12) - [9]=> - float(0.000123) - [10]=> - float(1.23E-5) - [11]=> - float(123456789012) - [12]=> - float(1234567890120) - [13]=> - float(1.23456789012E+19) -}
\ No newline at end of file diff --git a/ext/standard/tests/general_functions/009.phpt b/ext/standard/tests/general_functions/009.phpt deleted file mode 100644 index 68c1f4d87b..0000000000 --- a/ext/standard/tests/general_functions/009.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -SHA1 ---POST-- ---GET-- ---FILE-- -<?php -function test($str) { - $res = sha1($str)."\n"; - return $res; -} -echo test(""); -echo test("a"); -echo test("abc"); -echo test("message digest"); -echo test("abcdefghijklmnopqrstuvwxyz"); -echo test("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); -echo test("12345678901234567890123456789012345678901234567890123456789012345678901234567890"); -?> ---EXPECT-- -da39a3ee5e6b4b0d3255bfef95601890afd80709 -86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -a9993e364706816aba3e25717850c26c9cd0d89d -c12252ceda8be8994d5fa0290a47231c1d16aae3 -32d10c7b8cf96570ca04ce37f2a19d84240d3a89 -761c457bf73b14d27e9e9265c46f4b4dda11f940 -50abf5706a150990a08b2c5ea40fa0e585554732 diff --git a/ext/standard/tests/general_functions/getopt.phpt b/ext/standard/tests/general_functions/getopt.phpt deleted file mode 100644 index 13a4fa558f..0000000000 --- a/ext/standard/tests/general_functions/getopt.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -getopt ---ARGS-- --v -h -d test -m 1234 -t -j ---SKIPIF-- -<?php - if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip getopt() is currently not available on Windows'); - } - if (!ini_get('register_argc_argv')) { - die("skip this test needs register_argc_argv to be enabled"); - } -?> ---FILE-- -<?php - var_dump(getopt("d:m:j:vht")); -?> ---EXPECT-- -array(5) { - ["v"]=> - bool(false) - ["h"]=> - bool(false) - ["d"]=> - string(4) "test" - ["m"]=> - string(4) "1234" - ["t"]=> - bool(false) -} diff --git a/ext/standard/tests/general_functions/proc_open.phpt b/ext/standard/tests/general_functions/proc_open.phpt deleted file mode 100644 index 0cd08bd6b2..0000000000 --- a/ext/standard/tests/general_functions/proc_open.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -proc_open ---SKIPIF-- -<?php # vim:syn=php -if (!is_executable("/bin/cat")) echo "skip"; -if (!function_exists("proc_open")) echo "skip proc_open() is not available"; -?> ---POST-- ---GET-- ---FILE-- -<?php -$ds = array( - 0 => array("pipe", "r"), - 1 => array("pipe", "w"), - 2 => array("pipe", "w") - ); - -$cat = proc_open( - "/bin/cat", - $ds, - $pipes - ); - -proc_close($cat); - -echo "I didn't segfault!\n"; - -?> ---EXPECT-- -I didn't segfault! diff --git a/ext/standard/tests/general_functions/sunfuncts.phpt b/ext/standard/tests/general_functions/sunfuncts.phpt deleted file mode 100644 index 9f3af6e7f9..0000000000 --- a/ext/standard/tests/general_functions/sunfuncts.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -date_sunrise() and date_sunset() functions ---INI-- -precision = 14 ---FILE-- -<? - -putenv ("TZ=Asia/Jerusalem"); - -for($a=1;$a<=12;$a++){ - echo date_sunrise(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_TIMESTAMP,31.76670,35.23330,90.83,2)." "; - echo date_sunrise(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_STRING,31.76670,35.23330,90.83,2)." "; - echo date_sunrise(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_DOUBLE,31.76670,35.23330,90.83,2)."\n"; - - echo date_sunset(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_TIMESTAMP,31.76670,35.23330,90.83,2)." "; - echo date_sunset(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_STRING,31.76670,35.23330,90.83,2)." "; - echo date_sunset(mktime(1,1,1,$a,1,2003),SUNFUNCS_RET_DOUBLE,31.76670,35.23330,90.83,2)."\n"; -} -?> ---EXPECT-- -1041293199 06:39 6.6524557618962 -1041293806 16:46 16.769374867459 -1043971592 06:32 6.5453702926602 -1043972233 17:13 17.217524708736 -1046390766 06:06 6.1156526756851 -1046391456 17:36 17.6108549623 -1049069128 05:28 5.4727420290691 -1049069878 17:58 17.972552584375 -1051661094 04:54 4.9012299828593 -1051661898 18:18 18.313688769483 -1054339474 04:34 4.5744292894498 -1054340319 18:39 18.656400943241 -1056931476 04:36 4.6161204505189 -1056932328 18:48 18.808871657766 -1059609894 04:54 4.9068825098365 -1059610715 18:35 18.599286002028 -1062288314 05:14 5.2368895570738 -1062289083 18:03 18.060541787879 -1064880332 05:32 5.542366581139 -1064881044 17:24 17.411505614917 -1067558754 05:54 5.9162088420581 -1067559410 16:50 16.833698570628 -1070150780 06:20 6.3462215520697 -1070151395 16:35 16.583589055537 diff --git a/ext/standard/tests/image/246x247.png b/ext/standard/tests/image/246x247.png Binary files differdeleted file mode 100644 index 648a64e0aa..0000000000 --- a/ext/standard/tests/image/246x247.png +++ /dev/null diff --git a/ext/standard/tests/image/384x385.png b/ext/standard/tests/image/384x385.png Binary files differdeleted file mode 100644 index 843ddfaf08..0000000000 --- a/ext/standard/tests/image/384x385.png +++ /dev/null diff --git a/ext/standard/tests/image/bug13213.jpg b/ext/standard/tests/image/bug13213.jpg Binary files differdeleted file mode 100644 index b90c7a4059..0000000000 --- a/ext/standard/tests/image/bug13213.jpg +++ /dev/null diff --git a/ext/standard/tests/image/bug13213.phpt b/ext/standard/tests/image/bug13213.phpt deleted file mode 100644 index c97b7016b4..0000000000 --- a/ext/standard/tests/image/bug13213.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Bug #13213 (GetImageSize and wrong JPEG Comments) ---FILE-- -<?php -var_dump(GetImageSize(dirname(__FILE__).'/bug13213.jpg')); -?> ---EXPECT-- -array(7) { - [0]=> - int(1) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> - int(3) - ["mime"]=> - string(10) "image/jpeg" -} diff --git a/ext/standard/tests/image/getimagesize.phpt b/ext/standard/tests/image/getimagesize.phpt deleted file mode 100644 index 46003cffac..0000000000 --- a/ext/standard/tests/image/getimagesize.phpt +++ /dev/null @@ -1,196 +0,0 @@ ---TEST-- -GetImageSize() ---SKIPIF-- -<?php - require_once('skipif_imagetype.inc'); -?> ---FILE-- -<?php - // Note: SWC requires zlib - $dir = opendir(dirname(__FILE__)) or die('cannot open directory: '.dirname(__FILE__)); - $result = array(); - $files = array(); - while (($file = readdir($dir)) !== FALSE) { - if (preg_match('/^test.+pix\./',$file) && $file != "test13pix.swf") { - $files[] = $file; - } - } - closedir($dir); - sort($files); - foreach($files as $file) { - $result[$file] = getimagesize(dirname(__FILE__)."/$file"); - } - var_dump($result); -?> ---EXPECT-- -array(11) { - ["test1pix.bmp"]=> - array(6) { - [0]=> - int(1) - [1]=> - int(1) - [2]=> - int(6) - [3]=> - string(20) "width="1" height="1"" - ["bits"]=> - int(24) - ["mime"]=> - string(9) "image/bmp" - } - ["test1pix.jp2"]=> - array(7) { - [0]=> - int(1) - [1]=> - int(1) - [2]=> - int(10) - [3]=> - string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> - int(3) - ["mime"]=> - string(9) "image/jp2" - } - ["test1pix.jpc"]=> - array(7) { - [0]=> - int(1) - [1]=> - int(1) - [2]=> - int(9) - [3]=> - string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> - int(3) - ["mime"]=> - string(24) "application/octet-stream" - } - ["test1pix.jpg"]=> - array(7) { - [0]=> - int(1) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> - int(3) - ["mime"]=> - string(10) "image/jpeg" - } - ["test2pix.gif"]=> - array(7) { - [0]=> - int(2) - [1]=> - int(1) - [2]=> - int(1) - [3]=> - string(20) "width="2" height="1"" - ["bits"]=> - int(1) - ["channels"]=> - int(3) - ["mime"]=> - string(9) "image/gif" - } - ["test4pix.gif"]=> - array(7) { - [0]=> - int(4) - [1]=> - int(1) - [2]=> - int(1) - [3]=> - string(20) "width="4" height="1"" - ["bits"]=> - int(2) - ["channels"]=> - int(3) - ["mime"]=> - string(9) "image/gif" - } - ["test4pix.iff"]=> - array(6) { - [0]=> - int(4) - [1]=> - int(1) - [2]=> - int(14) - [3]=> - string(20) "width="4" height="1"" - ["bits"]=> - int(4) - ["mime"]=> - string(9) "image/iff" - } - ["test4pix.png"]=> - array(6) { - [0]=> - int(4) - [1]=> - int(1) - [2]=> - int(3) - [3]=> - string(20) "width="4" height="1"" - ["bits"]=> - int(4) - ["mime"]=> - string(9) "image/png" - } - ["test4pix.psd"]=> - array(5) { - [0]=> - int(4) - [1]=> - int(1) - [2]=> - int(5) - [3]=> - string(20) "width="4" height="1"" - ["mime"]=> - string(9) "image/psd" - } - ["test4pix.swf"]=> - array(5) { - [0]=> - int(550) - [1]=> - int(400) - [2]=> - int(4) - [3]=> - string(24) "width="550" height="400"" - ["mime"]=> - string(29) "application/x-shockwave-flash" - } - ["test4pix.tif"]=> - array(5) { - [0]=> - int(4) - [1]=> - int(1) - [2]=> - int(7) - [3]=> - string(20) "width="4" height="1"" - ["mime"]=> - string(10) "image/tiff" - } -} diff --git a/ext/standard/tests/image/getimagesize_246x247.phpt b/ext/standard/tests/image/getimagesize_246x247.phpt deleted file mode 100644 index e5a0aea779..0000000000 --- a/ext/standard/tests/image/getimagesize_246x247.phpt +++ /dev/null @@ -1,42 +0,0 @@ ---TEST-- -GetImageSize() with 246x247 pixels ---SKIPIF-- -<?php - require_once('skipif_imagetype.inc'); -?> ---FILE-- -<?php - // Note: SWC requires zlib - $dir = opendir(dirname(__FILE__)) or die('cannot open directory: '.dirname(__FILE__)); - $result = array(); - $files = array(); - while (($file = readdir($dir)) !== FALSE) { - if (preg_match('/^246x247\./',$file)) { - $files[] = $file; - } - } - closedir($dir); - sort($files); - foreach($files as $file) { - $result[$file] = getimagesize(dirname(__FILE__)."/$file"); - } - var_dump($result); -?> ---EXPECT-- -array(1) { - ["246x247.png"]=> - array(6) { - [0]=> - int(246) - [1]=> - int(247) - [2]=> - int(3) - [3]=> - string(24) "width="246" height="247"" - ["bits"]=> - int(4) - ["mime"]=> - string(9) "image/png" - } -} diff --git a/ext/standard/tests/image/getimagesize_384x385.phpt b/ext/standard/tests/image/getimagesize_384x385.phpt deleted file mode 100644 index 0051df71e0..0000000000 --- a/ext/standard/tests/image/getimagesize_384x385.phpt +++ /dev/null @@ -1,42 +0,0 @@ ---TEST-- -GetImageSize() with 384x385 pixels ---SKIPIF-- -<?php - require_once('skipif_imagetype.inc'); -?> ---FILE-- -<?php - // Note: SWC requires zlib - $dir = opendir(dirname(__FILE__)) or die('cannot open directory: '.dirname(__FILE__)); - $result = array(); - $files = array(); - while (($file = readdir($dir)) !== FALSE) { - if (preg_match('/^384x385\./',$file)) { - $files[] = $file; - } - } - closedir($dir); - sort($files); - foreach($files as $file) { - $result[$file] = getimagesize(dirname(__FILE__)."/$file"); - } - var_dump($result); -?> ---EXPECT-- -array(1) { - ["384x385.png"]=> - array(6) { - [0]=> - int(384) - [1]=> - int(385) - [2]=> - int(3) - [3]=> - string(24) "width="384" height="385"" - ["bits"]=> - int(1) - ["mime"]=> - string(9) "image/png" - } -} diff --git a/ext/standard/tests/image/getimagesize_swc.phpt b/ext/standard/tests/image/getimagesize_swc.phpt deleted file mode 100644 index b9b83f4373..0000000000 --- a/ext/standard/tests/image/getimagesize_swc.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -GetImageSize() for compressed swf files ---SKIPIF-- -<?php - if (!defined("IMAGETYPE_SWC") || !extension_loaded('zlib')) { - die("skip zlib extension is not avaliable"); - } -?> ---FILE-- -<?php - var_dump(getimagesize(dirname(__FILE__) . "/test13pix.swf")); -?> ---EXPECT-- -array(5) { - [0]=> - int(550) - [1]=> - int(400) - [2]=> - int(13) - [3]=> - string(24) "width="550" height="400"" - ["mime"]=> - string(29) "application/x-shockwave-flash" -} diff --git a/ext/standard/tests/image/image_type_to_mime_type.phpt b/ext/standard/tests/image/image_type_to_mime_type.phpt deleted file mode 100644 index 94aabba0b9..0000000000 --- a/ext/standard/tests/image/image_type_to_mime_type.phpt +++ /dev/null @@ -1,51 +0,0 @@ ---TEST-- -image_type_to_mime_type() ---SKIPIF-- -<?php - if (!function_exists('image_type_to_mime_type')) die('skip image_type_to_mime_type() not available'); - require_once('skipif_imagetype.inc'); -?> ---FILE-- -<?php - // Note: SWC requires zlib - $dir = opendir(dirname(__FILE__)) or die('cannot open directory: '.dirname(__FILE__)); - $result = array(); - $files = array(); - while (($file = readdir($dir)) !== FALSE) { - if (preg_match('/^test.+pix\./',$file) && $file != "test13pix.swf") { - $files[] = $file; - } - } - closedir($dir); - sort($files); - foreach($files as $file) { - $result[$file] = getimagesize(dirname(__FILE__)."/$file"); - $result[$file] = image_type_to_mime_type($result[$file][2]); - } - var_dump($result); -?> ---EXPECT-- -array(11) { - ["test1pix.bmp"]=> - string(9) "image/bmp" - ["test1pix.jp2"]=> - string(9) "image/jp2" - ["test1pix.jpc"]=> - string(24) "application/octet-stream" - ["test1pix.jpg"]=> - string(10) "image/jpeg" - ["test2pix.gif"]=> - string(9) "image/gif" - ["test4pix.gif"]=> - string(9) "image/gif" - ["test4pix.iff"]=> - string(9) "image/iff" - ["test4pix.png"]=> - string(9) "image/png" - ["test4pix.psd"]=> - string(9) "image/psd" - ["test4pix.swf"]=> - string(29) "application/x-shockwave-flash" - ["test4pix.tif"]=> - string(10) "image/tiff" -}
\ No newline at end of file diff --git a/ext/standard/tests/image/skipif_imagetype.inc b/ext/standard/tests/image/skipif_imagetype.inc deleted file mode 100644 index 827f10c179..0000000000 --- a/ext/standard/tests/image/skipif_imagetype.inc +++ /dev/null @@ -1,15 +0,0 @@ -<?php -if (!defined('IMAGETYPE_GIF')) die('skip images of type GIF not supported'); -if (!defined('IMAGETYPE_JPEG')) die('skip images of type JPEG not supported'); -if (!defined('IMAGETYPE_PNG')) die('skip images of type PNG not supported'); -if (!defined('IMAGETYPE_SWF')) die('skip images of type SWF not supported'); -if (!defined('IMAGETYPE_PSD')) die('skip images of type PSD not supported'); -if (!defined('IMAGETYPE_BMP')) die('skip images of type BMP not supported'); -if (!defined('IMAGETYPE_TIFF_II')) die('skip images of type TIFF not supported'); -if (!defined('IMAGETYPE_TIFF_MM')) die('skip images of type TIFF not supported'); -if (!defined('IMAGETYPE_JPC')) die('skip images of type JPC not supported'); -//if (!defined('IMAGETYPE_JP2')) die('skip images of type JP2 not supported'); -//if (!defined('IMAGETYPE_JPX')) die('skip images of type JPX not supported'); -//if (!defined('IMAGETYPE_JB2')) die('skip images of type JB2 not supported'); -if (!defined('IMAGETYPE_IFF')) die('skip images of type IFF not supported'); -?> diff --git a/ext/standard/tests/image/test13pix.swf b/ext/standard/tests/image/test13pix.swf Binary files differdeleted file mode 100755 index 0d40cb743e..0000000000 --- a/ext/standard/tests/image/test13pix.swf +++ /dev/null diff --git a/ext/standard/tests/image/test1pix.bmp b/ext/standard/tests/image/test1pix.bmp Binary files differdeleted file mode 100644 index f3799d2d1e..0000000000 --- a/ext/standard/tests/image/test1pix.bmp +++ /dev/null diff --git a/ext/standard/tests/image/test1pix.jp2 b/ext/standard/tests/image/test1pix.jp2 Binary files differdeleted file mode 100644 index 8a1172e10d..0000000000 --- a/ext/standard/tests/image/test1pix.jp2 +++ /dev/null diff --git a/ext/standard/tests/image/test1pix.jpc b/ext/standard/tests/image/test1pix.jpc Binary files differdeleted file mode 100644 index ac11c6bc81..0000000000 --- a/ext/standard/tests/image/test1pix.jpc +++ /dev/null diff --git a/ext/standard/tests/image/test1pix.jpg b/ext/standard/tests/image/test1pix.jpg Binary files differdeleted file mode 100644 index 121decb65a..0000000000 --- a/ext/standard/tests/image/test1pix.jpg +++ /dev/null diff --git a/ext/standard/tests/image/test2pix.gif b/ext/standard/tests/image/test2pix.gif Binary files differdeleted file mode 100644 index c4d4483544..0000000000 --- a/ext/standard/tests/image/test2pix.gif +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.gif b/ext/standard/tests/image/test4pix.gif Binary files differdeleted file mode 100644 index a02ebe9784..0000000000 --- a/ext/standard/tests/image/test4pix.gif +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.iff b/ext/standard/tests/image/test4pix.iff Binary files differdeleted file mode 100644 index fe9daebbae..0000000000 --- a/ext/standard/tests/image/test4pix.iff +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.png b/ext/standard/tests/image/test4pix.png Binary files differdeleted file mode 100644 index 2b75ac5fb2..0000000000 --- a/ext/standard/tests/image/test4pix.png +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.psd b/ext/standard/tests/image/test4pix.psd Binary files differdeleted file mode 100644 index 4c378239d7..0000000000 --- a/ext/standard/tests/image/test4pix.psd +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.swf b/ext/standard/tests/image/test4pix.swf Binary files differdeleted file mode 100755 index b1d41c6766..0000000000 --- a/ext/standard/tests/image/test4pix.swf +++ /dev/null diff --git a/ext/standard/tests/image/test4pix.tif b/ext/standard/tests/image/test4pix.tif Binary files differdeleted file mode 100644 index 13367ee173..0000000000 --- a/ext/standard/tests/image/test4pix.tif +++ /dev/null diff --git a/ext/standard/tests/math/abs.phpt b/ext/standard/tests/math/abs.phpt deleted file mode 100644 index e4e5587897..0000000000 --- a/ext/standard/tests/math/abs.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Simple math tests ---POST-- ---GET-- ---FILE-- -<?php // $Id$ - -define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF); -define('LONG_MIN', -LONG_MAX - 1); -printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ), - is_int(LONG_MIN-1),is_int(LONG_MAX+1)); - -$tests = <<<TESTS - 1 === abs(-1) - 1.5 === abs(-1.5) - 1 === abs("-1") - 1.5 === abs("-1.5") --LONG_MIN+1 === abs(LONG_MIN-1) --LONG_MIN === abs(LONG_MIN) --(LONG_MIN+1) === abs(LONG_MIN+1) -TESTS; - -include('tests/quicktester.inc'); ---EXPECT-- -1,1,0,0 -OK diff --git a/ext/standard/tests/math/bug21523.phpt b/ext/standard/tests/math/bug21523.phpt deleted file mode 100644 index aaeb8e865c..0000000000 --- a/ext/standard/tests/math/bug21523.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Bug #21523 (number_format tries to allocate negative amount of memory) ---FILE-- -<?php // $Id$ vim600:syn=php - -var_dump(number_format(-2000, 2768)); -echo "OK"; -?> ---EXPECT-- -string(2775) "-2,000.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" -OK diff --git a/ext/standard/tests/math/floorceil.phpt b/ext/standard/tests/math/floorceil.phpt deleted file mode 100644 index 3ac2094610..0000000000 --- a/ext/standard/tests/math/floorceil.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -Tests for floor en ceil ---POST-- ---GET-- ---FILE-- -<?php - $a = ceil (-0); $b = ceil (-1); $c = ceil (-1.5); - $d = ceil (-1.8); $e = ceil (-2.7); - var_dump ($a, $b, $c, $d, $e); - - $a = ceil (0); $b = ceil (0.5); $c = ceil (1); - $d = ceil (1.5); $e = ceil (1.8); $f = ceil (2.7); - var_dump ($a, $b, $c, $d, $e, $f); - - $a = floor (-0); $b = floor (-0.5); $c = floor (-1); - $d = floor (-1.5); $e = floor (-1.8); $f = floor (-2.7); - var_dump ($a, $b, $c, $d, $e, $f); - - $a = floor (0); $b = floor (0.5); $c = floor (1); - $d = floor (1.5); $e = floor (1.8); $f = floor (2.7); - var_dump ($a, $b, $c, $d, $e, $f); -?> ---EXPECT-- -float(0) -float(-1) -float(-1) -float(-1) -float(-2) -float(0) -float(1) -float(1) -float(2) -float(2) -float(3) -float(0) -float(-1) -float(-1) -float(-2) -float(-2) -float(-3) -float(0) -float(0) -float(1) -float(1) -float(1) -float(2) diff --git a/ext/standard/tests/math/hexdec.phpt b/ext/standard/tests/math/hexdec.phpt deleted file mode 100644 index d8ff71f1ce..0000000000 --- a/ext/standard/tests/math/hexdec.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -overflow check for _php_math_basetozval ---FILE-- -<?php - -var_dump(hexdec("012345")); -var_dump(hexdec("12345")); -var_dump(hexdec("q12345")); -var_dump(hexdec("12345+?!")); -var_dump(hexdec("12345q")); -var_dump((float)hexdec("1234500001")); -var_dump((float)hexdec("17fffffff")); - -?> ---EXPECT-- -int(74565) -int(74565) -int(74565) -int(74565) -int(74565) -float(78187069441) -float(6442450943) diff --git a/ext/standard/tests/math/log.phpt b/ext/standard/tests/math/log.phpt deleted file mode 100644 index 285b19c853..0000000000 --- a/ext/standard/tests/math/log.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -log() tests ---POST-- ---GET-- ---FILE-- -<?php // $Id$ -echo "On failure, please mail result to php-dev@lists.php.net\n"; -for ($x = 0, $count= 0; $x < 200; $x++) { - $x2 = (int) exp(log($x)); - // e ^ log(x) should be close in range to x - if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) { - $count++; - } else { - print "$x : $x2\n"; - } -} -print $count . "\n"; - -// Now test the base form of log -for ($base = 2; $base < 11; $base++) { - for ($x = 0, $count= 0; $x < 50; $x++) { - $x2 = (int) pow($base, log($x, $base)); - // base ^ log(x) should be close in range to x - if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) { - $count++; - } else { - print "base $base: $x : $x2\n"; - } - } - print $count . "\n"; -} -?> ---EXPECT-- -On failure, please mail result to php-dev@lists.php.net -200 -50 -50 -50 -50 -50 -50 -50 -50 -50 diff --git a/ext/standard/tests/math/pow.phpt b/ext/standard/tests/math/pow.phpt deleted file mode 100644 index 12170f4f3a..0000000000 --- a/ext/standard/tests/math/pow.phpt +++ /dev/null @@ -1,151 +0,0 @@ ---TEST-- -Various pow() tests ---POST-- ---GET-- ---FILE-- -<?php // $Id$ - -define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF); -define('LONG_MIN', -LONG_MAX - 1); -printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ), - is_int(LONG_MIN-1),is_int(LONG_MAX+1)); - -$tests = <<<TESTS - 0.25 === pow(-2,-2) --0.5 === pow(-2,-1) - 1 === pow(-2, 0) --2 === pow(-2, 1) - 4 === pow(-2, 2) - 1.0 === pow(-1,-2) --1.0 === pow(-1,-1) - 1 === pow(-1, 0) --1 === pow(-1, 1) - 1 === pow(-1, 2) - TRUE === is_infinite(pow(0,-2)) - TRUE === is_infinite(pow(0,-1)) - 1 === pow( 0, 0) - 0 === pow( 0, 1) - 0 === pow( 0, 2) - 1.0 === pow( 1,-2) - 1.0 === pow( 1,-1) - 1 === pow( 1, 0) - 1 === pow( 1, 1) - 1 === pow( 1, 2) - 0.25 === pow( 2,-2) - 0.5 === pow( 2,-1) - 1 === pow( 2, 0) - 2 === pow( 2, 1) - 4 === pow( 2, 2) - 0.25 === pow(-2,-2.0) --0.5 === pow(-2,-1.0) - 1.0 === pow(-2, 0.0) --2.0 === pow(-2, 1.0) - 4.0 === pow(-2, 2.0) - 1.0 === pow(-1,-2.0) --1.0 === pow(-1,-1.0) - 1.0 === pow(-1, 0.0) --1.0 === pow(-1, 1.0) - 1.0 === pow(-1, 2.0) - TRUE === is_infinite(pow(0,-2.0)) - TRUE === is_infinite(pow(0,-1.0)) - 1.0 === pow( 0, 0.0) - 0.0 === pow( 0, 1.0) - 0.0 === pow( 0, 2.0) - 1.0 === pow( 1,-2.0) - 1.0 === pow( 1,-1.0) - 1.0 === pow( 1, 0.0) - 1.0 === pow( 1, 1.0) - 1.0 === pow( 1, 2.0) - 0.25 === pow( 2,-2.0) - 0.5 === pow( 2,-1.0) - 1.0 === pow( 2, 0.0) - 2.0 === pow( 2, 1.0) - 4.0 === pow( 2, 2.0) - 2147483648 === pow(2,31) --2147483648 ~== pow(-2,31) - 1000000000 === pow(10,9) - 100000000 === pow(-10,8) - 1 === pow(-1,1443279822) --1 === pow(-1,1443279821) -sqrt(2) ~== pow(2,1/2) - 0.25 === pow(-2.0,-2.0) --0.5 === pow(-2.0,-1.0) - 1.0 === pow(-2.0, 0.0) --2.0 === pow(-2.0, 1.0) - 4.0 === pow(-2.0, 2.0) - 1.0 === pow(-1.0,-2.0) --1.0 === pow(-1.0,-1.0) - 1.0 === pow(-1.0, 0.0) --1.0 === pow(-1.0, 1.0) - 1.0 === pow(-1.0, 2.0) - TRUE === is_infinite(pow(0.0,-2.0)) - TRUE === is_infinite(pow(0.0,-1.0)) - 1.0 === pow( 0.0, 0.0) - 0.0 === pow( 0.0, 1.0) - 0.0 === pow( 0.0, 2.0) - 1.0 === pow( 1.0,-2.0) - 1.0 === pow( 1.0,-1.0) - 1.0 === pow( 1.0, 0.0) - 1.0 === pow( 1.0, 1.0) - 1.0 === pow( 1.0, 2.0) - 0.25 === pow( 2.0,-2.0) - 0.5 === pow( 2.0,-1.0) - 1.0 === pow( 2.0, 0.0) - 2.0 === pow( 2.0, 1.0) - 4.0 === pow( 2.0, 2.0) - 0.25 === pow(-2.0,-2) --0.5 === pow(-2.0,-1) - 1.0 === pow(-2.0, 0) --2.0 === pow(-2.0, 1) - 4.0 === pow(-2.0, 2) - 1.0 === pow(-1.0,-2) --1.0 === pow(-1.0,-1) - 1.0 === pow(-1.0, 0) --1.0 === pow(-1.0, 1) - 1.0 === pow(-1.0, 2) - TRUE === is_infinite(pow( 0.0,-2)) - TRUE === is_infinite(pow( 0.0,-1)) - 1.0 === pow( 0.0, 0) - 0.0 === pow( 0.0, 1) - 0.0 === pow( 0.0, 2) - 1.0 === pow( 1.0,-2) - 1.0 === pow( 1.0,-1) - 1.0 === pow( 1.0, 0) - 1.0 === pow( 1.0, 1) - 1.0 === pow( 1.0, 2) - 0.25 === pow( 2.0,-2) - 0.5 === pow( 2.0,-1) - 1.0 === pow( 2.0, 0) - 2.0 === pow( 2.0, 1) - 4.0 === pow( 2.0, 2) - 2.0 === pow( 4, 0.5) - 2.0 === pow( 4.0, 0.5) - 3.0 === pow( 27, 1/3) - 3.0 === pow(27.0, 1/3) - 0.5 === pow( 4, -0.5) - 0.5 === pow( 4.0, -0.5) -LONG_MAX-1 === pow(LONG_MAX-1,1) -LONG_MIN+1 === pow(LONG_MIN+1,1) -(LONG_MAX-1)*(LONG_MAX-1) ~== pow(LONG_MAX-1,2) -(LONG_MIN+1)*(LONG_MIN+1) ~== pow(LONG_MIN+1,2) -(float)(LONG_MAX-1) === pow(LONG_MAX-1,1.0) -(float)(LONG_MIN+1) === pow(LONG_MIN+1,1.0) -(LONG_MAX-1)*(LONG_MAX-1) ~== pow(LONG_MAX-1,2.0) -(LONG_MIN+1)*(LONG_MIN+1) ~== pow(LONG_MIN+1,2.0) -LONG_MAX === pow(LONG_MAX,1) -LONG_MIN === pow(LONG_MIN,1) -LONG_MAX*LONG_MAX ~== pow(LONG_MAX,2) -LONG_MIN*LONG_MIN ~== pow(LONG_MIN,2) -(float)LONG_MAX === pow(LONG_MAX,1.0) -(float)LONG_MIN === pow(LONG_MIN,1.0) -LONG_MAX*LONG_MAX ~== pow(LONG_MAX,2.0) -LONG_MIN*LONG_MIN ~== pow(LONG_MIN,2.0) -TESTS; - - echo "On failure, please mail result to php-dev@lists.php.net\n"; - include('tests/quicktester.inc'); - ---EXPECT-- -1,1,0,0 -On failure, please mail result to php-dev@lists.php.net -OK diff --git a/ext/standard/tests/math/round.phpt b/ext/standard/tests/math/round.phpt deleted file mode 100644 index 49eabed606..0000000000 --- a/ext/standard/tests/math/round.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Simple math tests ---POST-- ---GET-- ---FILE-- -<?php // $Id$ - -define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF); -define('LONG_MIN', -LONG_MAX - 1); -printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ), - is_int(LONG_MIN-1),is_int(LONG_MAX+1)); - -$tests = <<<TESTS --1 ~== ceil(-1.5) - 2 ~== ceil( 1.5) --2 ~== floor(-1.5) - 1 ~== floor(1.5) - LONG_MIN ~== ceil(LONG_MIN - 0.5) - LONG_MIN+1 ~== ceil(LONG_MIN + 0.5) - LONG_MIN-1 ~== round(LONG_MIN - 0.6) - LONG_MIN ~== round(LONG_MIN - 0.4) - LONG_MIN ~== round(LONG_MIN + 0.4) - LONG_MIN+1 ~== round(LONG_MIN + 0.6) - LONG_MIN-1 ~== floor(LONG_MIN - 0.5) - LONG_MIN ~== floor(LONG_MIN + 0.5) - LONG_MAX ~== ceil(LONG_MAX - 0.5) - LONG_MAX+1 ~== ceil(LONG_MAX + 0.5) - LONG_MAX-1 ~== round(LONG_MAX - 0.6) - LONG_MAX ~== round(LONG_MAX - 0.4) - LONG_MAX ~== round(LONG_MAX + 0.4) - LONG_MAX+1 ~== round(LONG_MAX + 0.6) - LONG_MAX-1 ~== floor(LONG_MAX - 0.5) - LONG_MAX ~== floor(LONG_MAX + 0.5) -TESTS; - -include('tests/quicktester.inc'); ---EXPECT-- -1,1,0,0 -OK diff --git a/ext/standard/tests/network/bug20134.phpt b/ext/standard/tests/network/bug20134.phpt deleted file mode 100644 index e311f892f7..0000000000 --- a/ext/standard/tests/network/bug20134.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Bug #20134 (UDP reads from invalid ports) ---FILE-- -<?php -# vim600:syn=php: -$fp = fsockopen("udp://localhost", 65534, $errno, $errstr); -if (!$fp) { - /* UDP will never cause a connection error, as it is - * a connection-LESS protocol */ - echo "ERROR: $errno - $errstr<br>\n"; -} -else { - /* Likewise, writes will always appear to succeed */ - $x = fwrite($fp,"\n"); - var_dump($x); - /* But reads should always fail */ - $content = fread($fp, 40); - var_dump($content); - fclose($fp); -} -?> ---EXPECT-- -int(1) -string(0) "" diff --git a/ext/standard/tests/reg/001.phpt b/ext/standard/tests/reg/001.phpt deleted file mode 100644 index f63c252518..0000000000 --- a/ext/standard/tests/reg/001.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -RegReplace test 1 ---POST-- ---GET-- ---FILE-- -<?php $a="abc123"; - echo ereg_replace("123","def",$a)?> ---EXPECT-- -abcdef diff --git a/ext/standard/tests/reg/002.phpt b/ext/standard/tests/reg/002.phpt deleted file mode 100644 index a9b7aaa00a..0000000000 --- a/ext/standard/tests/reg/002.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -RegReplace test 2 ---POST-- ---GET-- ---FILE-- -<?php $a="abc123"; - echo ereg_replace("123","",$a)?> ---EXPECT-- -abc diff --git a/ext/standard/tests/reg/003.phpt b/ext/standard/tests/reg/003.phpt deleted file mode 100644 index edd9c05969..0000000000 --- a/ext/standard/tests/reg/003.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -ereg_replace single-quote test ---POST-- ---GET-- ---FILE-- -<?php $a="\\'test"; - echo ereg_replace("\\\\'","'",$a) -?> ---EXPECT-- -'test diff --git a/ext/standard/tests/reg/004.phpt b/ext/standard/tests/reg/004.phpt deleted file mode 100644 index 1f60ff4900..0000000000 --- a/ext/standard/tests/reg/004.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -simple ereg test ---POST-- ---GET-- ---FILE-- -<?php $a="This is a nice and simple string"; - if (ereg(".*nice and simple.*",$a)) { - echo "ok\n"; - } - if (!ereg(".*doesn't exist.*",$a)) { - echo "ok\n"; - } -?> ---EXPECT-- -ok -ok diff --git a/ext/standard/tests/reg/005.phpt b/ext/standard/tests/reg/005.phpt deleted file mode 100644 index 78c0a0912a..0000000000 --- a/ext/standard/tests/reg/005.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Test Regular expression register support in ereg ---POST-- ---GET-- ---FILE-- -<?php $a="This is a nice and simple string"; - echo ereg(".*(is).*(is).*",$a,$registers); - echo "\n"; - echo $registers[0]; - echo "\n"; - echo $registers[1]; - echo "\n"; - echo $registers[2]; - echo "\n"; -?> ---EXPECT-- -32 -This is a nice and simple string -is -is diff --git a/ext/standard/tests/reg/006.phpt b/ext/standard/tests/reg/006.phpt deleted file mode 100644 index 50b6dbfd3a..0000000000 --- a/ext/standard/tests/reg/006.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -Test ereg_replace of start-of-line ---POST-- ---GET-- ---FILE-- -<?php $a="This is a nice and simple string"; - echo ereg_replace("^This","That",$a); -?> ---EXPECT-- -That is a nice and simple string diff --git a/ext/standard/tests/reg/007.phpt b/ext/standard/tests/reg/007.phpt deleted file mode 100644 index b2646f842f..0000000000 --- a/ext/standard/tests/reg/007.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Test empty result buffer in reg_replace ---POST-- ---GET-- ---FILE-- -<?php - $a="abcd"; - $b=ereg_replace("abcd","",$a); - echo "strlen(\$b)=".strlen($b); -?> ---EXPECT-- -strlen($b)=0 diff --git a/ext/standard/tests/reg/008.phpt b/ext/standard/tests/reg/008.phpt deleted file mode 100644 index db61d1ca07..0000000000 --- a/ext/standard/tests/reg/008.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -Test back-references in regular expressions ---POST-- ---GET-- ---FILE-- -<?php - echo ereg_replace("([a-z]*)([-=+|]*)([0-9]+)","\\3 \\1 \\2\n","abc+-|=123"); -?> ---EXPECT-- -123 abc +-|= diff --git a/ext/standard/tests/reg/009.phpt b/ext/standard/tests/reg/009.phpt deleted file mode 100644 index 4996ef4c97..0000000000 --- a/ext/standard/tests/reg/009.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Test split() ---POST-- ---GET-- ---FILE-- -<?php - $a=split("[[:space:]]","this is a -test"); - echo count($a) . "\n"; - for ($i = 0; $i < count($a); $i++) { - echo $a[$i] . "\n"; - } -?> ---EXPECT-- -4 -this -is -a -test diff --git a/ext/standard/tests/reg/010.phpt b/ext/standard/tests/reg/010.phpt deleted file mode 100644 index 30d28fd02f..0000000000 --- a/ext/standard/tests/reg/010.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Long back references ---POST-- ---GET-- ---FILE-- -<?php $a="abc122222222223"; - echo ereg_replace("1(2*)3","\\1def\\1",$a)?> ---EXPECT-- -abc2222222222def2222222222 diff --git a/ext/standard/tests/reg/011.phpt b/ext/standard/tests/reg/011.phpt deleted file mode 100644 index 4eda774f58..0000000000 --- a/ext/standard/tests/reg/011.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -\0 back reference ---POST-- ---GET-- ---FILE-- -<?php $a="abc123"; - echo ereg_replace("123","def\\0ghi",$a)?> ---EXPECT-- -abcdef123ghi diff --git a/ext/standard/tests/reg/012.phpt b/ext/standard/tests/reg/012.phpt deleted file mode 100644 index d5342c7436..0000000000 --- a/ext/standard/tests/reg/012.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -nonexisting back reference ---POST-- ---GET-- ---FILE-- -<?php $a="abc123"; - echo ereg_replace("123",'def\1ghi',$a)?> ---EXPECT-- -abcdef\1ghi diff --git a/ext/standard/tests/reg/013.phpt b/ext/standard/tests/reg/013.phpt deleted file mode 100644 index ec3329fa7c..0000000000 --- a/ext/standard/tests/reg/013.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -escapes in replace string ---POST-- ---GET-- ---FILE-- -<?php $a="abc123"; - echo ereg_replace("123","def\\g\\\\hi\\",$a)?> ---EXPECT-- -abcdef\g\\hi\ diff --git a/ext/standard/tests/reg/014.phpt b/ext/standard/tests/reg/014.phpt deleted file mode 100644 index ec4d19ed0e..0000000000 --- a/ext/standard/tests/reg/014.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -backreferences not replaced recursively ---POST-- ---GET-- ---FILE-- -<?php $a="a\\2bxc"; - echo ereg_replace("a(.*)b(.*)c","\\1",$a)?> ---EXPECT-- -\2 diff --git a/ext/standard/tests/reg/015.phpt b/ext/standard/tests/reg/015.phpt deleted file mode 100644 index 961a60fa76..0000000000 --- a/ext/standard/tests/reg/015.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -replace empty matches ---POST-- ---GET-- ---FILE-- -<?php echo ereg_replace("^","z","abc123")?> ---EXPECT-- -zabc123 diff --git a/ext/standard/tests/reg/016.phpt b/ext/standard/tests/reg/016.phpt deleted file mode 100644 index a24816f182..0000000000 --- a/ext/standard/tests/reg/016.phpt +++ /dev/null @@ -1,8 +0,0 @@ ---TEST-- -test backslash handling in regular expressions ---POST-- ---GET-- ---FILE-- -<?php echo ereg_replace('\?',"abc","?123?")?> ---EXPECT-- -abc123abc diff --git a/ext/standard/tests/serialize/001.phpt b/ext/standard/tests/serialize/001.phpt deleted file mode 100644 index ab8ac99c53..0000000000 --- a/ext/standard/tests/serialize/001.phpt +++ /dev/null @@ -1,115 +0,0 @@ ---TEST-- -serialize()/unserialize()/var_dump() ---POST-- ---GET-- ---FILE-- -<?php -class t -{ - function t() - { - $this->a = "hallo"; - } -} - -class s -{ - function s() - { - $this->a = "hallo"; - $this->b = "php"; - $this->c = "world"; - } - - function __sleep() - { - echo "__sleep called\n"; - return array("a","c"); - } - - function __wakeup() - { - echo "__wakeup called\n"; - } -} - - -echo serialize(NULL)."\n"; -echo serialize((bool) true)."\n"; -echo serialize((bool) false)."\n"; -echo serialize(1)."\n"; -echo serialize(0)."\n"; -echo serialize(-1)."\n"; -echo serialize(2147483647)."\n"; -echo serialize(-2147483647)."\n"; -echo serialize(1.123456789)."\n"; -echo serialize(1.0)."\n"; -echo serialize(0.0)."\n"; -echo serialize(-1.0)."\n"; -echo serialize(-1.123456789)."\n"; -echo serialize("hallo")."\n"; -echo serialize(array(1,1.1,"hallo",NULL,true,array()))."\n"; - -$t = new t(); -$data = serialize($t); -echo "$data\n"; -$t = unserialize($data); -var_dump($t); - -$t = new s(); -$data = serialize($t); -echo "$data\n"; -$t = unserialize($data); -var_dump($t); - -$a = array("a" => "test"); -$a[ "b" ] = &$a[ "a" ]; -var_dump($a); -$data = serialize($a); -echo "$data\n"; -$a = unserialize($data); -var_dump($a); -?> ---EXPECT-- -N; -b:1; -b:0; -i:1; -i:0; -i:-1; -i:2147483647; -i:-2147483647; -d:1.123456789; -d:1; -d:0; -d:-1; -d:-1.123456789; -s:5:"hallo"; -a:6:{i:0;i:1;i:1;d:1.1;i:2;s:5:"hallo";i:3;N;i:4;b:1;i:5;a:0:{}} -O:1:"t":1:{s:1:"a";s:5:"hallo";} -object(t)(1) { - ["a"]=> - string(5) "hallo" -} -__sleep called -O:1:"s":2:{s:1:"a";s:5:"hallo";s:1:"c";s:5:"world";} -__wakeup called -object(s)(2) { - ["a"]=> - string(5) "hallo" - ["c"]=> - string(5) "world" -} -array(2) { - ["a"]=> - &string(4) "test" - ["b"]=> - &string(4) "test" -} -a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;} -array(2) { - ["a"]=> - &string(4) "test" - ["b"]=> - &string(4) "test" -} diff --git a/ext/standard/tests/serialize/003.phpt b/ext/standard/tests/serialize/003.phpt deleted file mode 100644 index 43e9077382..0000000000 --- a/ext/standard/tests/serialize/003.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -unserialize() floats with E notation (#18654) ---POST-- ---GET-- ---FILE-- -<?php -foreach(array(1e2, 5.2e25, 85.29e-23, 9e-9) AS $value) { - echo ($ser = serialize($value))."\n"; - var_dump(unserialize($ser)); - echo "\n"; -} -?> ---EXPECT-- -d:100; -float(100) - -d:5.2E+25; -float(5.2E+25) - -d:8.529E-22; -float(8.529E-22) - -d:9E-09; -float(9.E-9) diff --git a/ext/standard/tests/serialize/bug14293.phpt b/ext/standard/tests/serialize/bug14293.phpt deleted file mode 100644 index 1d716ebcab..0000000000 --- a/ext/standard/tests/serialize/bug14293.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -Bug #14293 (serialize() and __sleep()) ---FILE-- -<?php -class t -{ - function t() - { - $this->a = 'hello'; - } - - function __sleep() - { - echo "__sleep called\n"; - return array('a','b'); - } -} - -$t = new t(); -$data = serialize($t); -echo "$data\n"; -$t = unserialize($data); -var_dump($t); - -?> ---EXPECT-- -__sleep called -O:1:"t":2:{s:1:"a";s:5:"hello";s:1:"b";N;} -object(t)(2) { - ["a"]=> - string(5) "hello" - ["b"]=> - NULL -} diff --git a/ext/standard/tests/strings/004.phpt b/ext/standard/tests/strings/004.phpt deleted file mode 100644 index b9904c614a..0000000000 --- a/ext/standard/tests/strings/004.phpt +++ /dev/null @@ -1,84 +0,0 @@ ---TEST-- -Testing randomization of shuffle() and str_shuffle(). ---FILE-- -<?php -function stats($f, $a) { - $times = 90000; - print "$f\n"; - ksort($a); - foreach($a as $k => $v) - print "$k: $v: " . sprintf('%0.3f', $v / $times) . "\n"; -} -$a = array(); -$times = 90000; -for ($i = 0; $i < $times; $i++) { - $p = range(1,4); - shuffle($p); - $s = join('', $p); - if (empty($a[$s])) $a[$s] = 0; - $a[$s]++; -} - -stats('shuffle', $a); -$a = array(); -$times = 90000; -for ($i = 0; $i < $times; $i++) { - $p = '1234'; - $s = str_shuffle($p); - if (empty($a[$s])) $a[$s] = 0; - $a[$s]++; -} - -stats('str_shuffle', $a); -?> ---EXPECTREGEX-- -shuffle -1234: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1243: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1324: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1342: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1423: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1432: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2134: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2143: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2314: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2341: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2413: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2431: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3124: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3142: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3214: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3241: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3412: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3421: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4123: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4132: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4213: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4231: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4312: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4321: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -str_shuffle -1234: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1243: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1324: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1342: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1423: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -1432: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2134: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2143: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2314: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2341: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2413: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -2431: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3124: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3142: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3214: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3241: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3412: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -3421: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4123: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4132: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4213: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4231: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4312: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] -4321: 3[0-9][0-9][0-9]: 0.0[3-4][0-9] diff --git a/ext/standard/tests/strings/add-and-stripcslashes.phpt b/ext/standard/tests/strings/add-and-stripcslashes.phpt deleted file mode 100644 index f231156e88..0000000000 --- a/ext/standard/tests/strings/add-and-stripcslashes.phpt +++ /dev/null @@ -1,28 +0,0 @@ ---TEST-- -addcslashes() and stripcslashes() function ---POST-- ---GET-- ---FILE-- -<?php -echo addcslashes("", "")."\n"; -echo addcslashes("", "burp")."\n"; -echo addcslashes("kaboemkara!", "")."\n"; -echo addcslashes("foobarbaz", 'bar')."\n"; -echo addcslashes('foo[ ]', 'A..z')."\n"; -echo @addcslashes("zoo['.']", 'z..A')."\n"; -echo addcslashes('abcdefghijklmnopqrstuvwxyz', "a\145..\160z")."\n"; -echo "\n\r" == stripcslashes('\n\r'),"\n"; -echo stripcslashes('\065\x64')."\n"; -echo stripcslashes('')."\n"; -?> ---EXPECT-- - - -kaboemkara! -foo\b\a\r\b\az -\f\o\o\[ \] -\zoo['\.'] -\abcd\e\f\g\h\i\j\k\l\m\n\o\pqrstuvwxy\z -1 -5d - diff --git a/ext/standard/tests/strings/add-and-stripslashes.phpt b/ext/standard/tests/strings/add-and-stripslashes.phpt deleted file mode 100644 index 1c65aefda6..0000000000 --- a/ext/standard/tests/strings/add-and-stripslashes.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -addslashes() and stripslashes() functions, normal and sybase-style ---POST-- ---GET-- ---FILE-- -<?php - -$input = ''; -for($i=0; $i<512; $i++) { - $input .= chr($i%256); -} - -echo "Normal: "; -ini_set('magic_quotes_sybase', 0); -if($input === stripslashes(addslashes($input))) { - echo "OK\n"; -} else { - echo "FAILED\n"; -} - -echo "Sybase: "; -ini_set('magic_quotes_sybase', 1); -if($input === stripslashes(addslashes($input))) { - echo "OK\n"; -} else { - echo "FAILED\n"; -} - -?> ---EXPECT-- -Normal: OK -Sybase: OK diff --git a/ext/standard/tests/strings/bin2hex.phpt b/ext/standard/tests/strings/bin2hex.phpt deleted file mode 100644 index 5753a74dc0..0000000000 --- a/ext/standard/tests/strings/bin2hex.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -bin2hex() function ---POST-- ---GET-- ---FILE-- -<?php -$s = ''; -for($i=0; $i<256; $i++) { - $s .= chr($i); -} -echo bin2hex($s)."\n"; -echo bin2hex("abc")."\n"; -?> ---EXPECT-- -000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff -616263 diff --git a/ext/standard/tests/strings/bug20108.phpt b/ext/standard/tests/strings/bug20108.phpt deleted file mode 100644 index 0993412500..0000000000 --- a/ext/standard/tests/strings/bug20108.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Bug #20108 (Segfault on printf statement) ---SKIPIF-- ---FILE-- -<?php - $a = "boo"; - $z = sprintf("%580.58s\n", $a); - var_dump($z); -?> ---EXPECT-- -string(581) " boo -" diff --git a/ext/standard/tests/strings/bug20169.phpt b/ext/standard/tests/strings/bug20169.phpt deleted file mode 100644 index c606578677..0000000000 --- a/ext/standard/tests/strings/bug20169.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -Bug #20169 (implode() clobbers first argument) ---FILE-- -<?php - @set_time_limit(5); - $delimiter = "|"; - - echo "delimiter: $delimiter\n"; - implode($delimiter, array("foo", "bar")); - echo "delimiter: $delimiter\n"; -?> ---EXPECT-- -delimiter: | -delimiter: | diff --git a/ext/standard/tests/strings/bug20261.phpt b/ext/standard/tests/strings/bug20261.phpt deleted file mode 100644 index 163e905a4a..0000000000 --- a/ext/standard/tests/strings/bug20261.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug #20261 (str_rot13() changes too much) ---FILE-- -<?php - $first = "boo"; - $second = $first; - $rot = ""; - - echo "1: ".$first."\n"; - echo "2: ".$second."\n"; - echo "3: ".$rot."\n"; - - $rot = str_rot13($second); - - echo "1: ".$first."\n"; - echo "2: ".$second."\n"; - echo "3: ".$rot."\n"; -?> ---EXPECT-- -1: boo -2: boo -3: -1: boo -2: boo -3: obb - diff --git a/ext/standard/tests/strings/bug20927.phpt b/ext/standard/tests/strings/bug20927.phpt deleted file mode 100644 index 5b7c904c65..0000000000 --- a/ext/standard/tests/strings/bug20927.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Bug #20927 (Segfault on wordwrap statement) ---SKIPIF-- ---FILE-- -<?php -$string = str_repeat("1234567890 X ", 10); -$break = str_repeat("a-very-long-break-string-to-clobber-the-heap", 8); -$linelength = 10; - -echo "Length of original string: ".strlen($string)."\n"; -echo "Length of break string: ".strlen($break)."\n"; - -var_dump(wordwrap($string, $linelength, $break, 1)); -?> ---EXPECT-- -Length of original string: 130 -Length of break string: 352 -string(6799) "1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapXa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heap1234567890a-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapa-very-long-break-string-to-clobber-the-heapX " diff --git a/ext/standard/tests/strings/bug20934.phpt b/ext/standard/tests/strings/bug20934.phpt deleted file mode 100644 index 0d95081d54..0000000000 --- a/ext/standard/tests/strings/bug20934.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Bug #20934 (htmlspecialchars returns latin1 from UTF-8) ---SKIPIF-- -<?php -if (!function_exists("utf8_encode") || !function_exists("utf8_decode")) { - die("SKIP Neither utf8_encode() nor utf8_decode() are available"); -} -?> ---FILE-- -<?php -$str = utf8_encode("\xe0\xe1"); -var_dump(utf8_decode($str)); -var_dump(utf8_decode(htmlspecialchars($str, ENT_COMPAT, "UTF-8"))); -?> ---EXPECT-- -string(2) "àá" -string(2) "àá" diff --git a/ext/standard/tests/strings/bug21338.phpt b/ext/standard/tests/strings/bug21338.phpt deleted file mode 100644 index c84576563e..0000000000 --- a/ext/standard/tests/strings/bug21338.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -Bug #20934 (html_entity_decode() crash when "" is passed) ---FILE-- -<?php - var_dump(html_entity_decode(NULL)); - var_dump(html_entity_decode("")); -?> ---EXPECT-- -string(0) "" -string(0) "" diff --git a/ext/standard/tests/strings/bug21453.phpt b/ext/standard/tests/strings/bug21453.phpt deleted file mode 100644 index 40d89dd1b4..0000000000 --- a/ext/standard/tests/strings/bug21453.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Bug #21453 (handling of non-encoded <) ---FILE-- -<?php -$test = " -<table> - <tr><td>first cell before < first cell after</td></tr> - <tr><td>second cell before < second cell after</td></tr> -</table>"; - - var_dump(strip_tags($test)); -?> ---EXPECT-- -string(80) " - - first cell before < first cell after - second cell before < second cell after -" diff --git a/ext/standard/tests/strings/bug21730.phpt b/ext/standard/tests/strings/bug21730.phpt deleted file mode 100644 index 8d40e204ce..0000000000 --- a/ext/standard/tests/strings/bug21730.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -Bug #21730 (*scanf "%n" conversion flag gives string instead of integer) ---FILE-- -<?php -$foo = "ABC = DEF"; -$fmt = "%s = %s %n"; -$res_a = array(); - -/* $res_a[2] is supposed to be a integer value that - * represents the number of characters consumed so far - */ -sscanf($foo, $fmt, $res_a[0], $res_a[1], $res_a[2]); - -$res_b = sscanf($foo, $fmt); - -var_dump($res_a); -var_dump($res_b); -?> ---EXPECT-- -array(3) { - [0]=> - string(3) "ABC" - [1]=> - string(3) "DEF" - [2]=> - int(9) -} -array(3) { - [0]=> - string(3) "ABC" - [1]=> - string(3) "DEF" - [2]=> - int(9) -} diff --git a/ext/standard/tests/strings/bug21744.phpt b/ext/standard/tests/strings/bug21744.phpt deleted file mode 100644 index 925dac3fa0..0000000000 --- a/ext/standard/tests/strings/bug21744.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Bug #21744 (strip_tags misses exclamation marks in alt text) ---FILE-- -<?php -$test = <<< HERE -<a href="test?test\\!!!test">test</a> -<!-- test --> -HERE; - -print strip_tags($test, ''); -print strip_tags($test, '<a>'); -?> ---EXPECT-- -test -<a href="test?test\!!!test">test</a> diff --git a/ext/standard/tests/strings/bug22187.phpt b/ext/standard/tests/strings/bug22187.phpt deleted file mode 100644 index dccaccc04d..0000000000 --- a/ext/standard/tests/strings/bug22187.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -Bug #22187 (possible crash in number_format() function) ---FILE-- -<?php - var_dump(number_format(0.0001, 1)); - var_dump(number_format(0.0001, 0)); -?> ---EXPECT-- -string(3) "0.0" -string(1) "0" diff --git a/ext/standard/tests/strings/bug22207.phpt b/ext/standard/tests/strings/bug22207.phpt deleted file mode 100644 index 1623fb8e41..0000000000 --- a/ext/standard/tests/strings/bug22207.phpt +++ /dev/null @@ -1,11 +0,0 @@ ---TEST-- -Bug #22207 (missing 0 when using the e notation in *printf functions) ---FILE-- -<?php - printf("%10.5e\n", 1.1); - var_dump(sprintf("%10.5e\n", 1.1)); -?> ---EXPECT-- -1.1000e+0 -string(17) " 1.1000e+0 -" diff --git a/ext/standard/tests/strings/bug22224.phpt b/ext/standard/tests/strings/bug22224.phpt deleted file mode 100644 index fea9455654..0000000000 --- a/ext/standard/tests/strings/bug22224.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Bug #22224 (implode changes object references in array) ---INI-- -error_reporting=0 ---FILE-- -<?php -class foo { -} - - -$a = new foo(); - -$arr = array(0=>&$a, 1=>&$a); -var_dump(implode(",",$arr)); -var_dump($arr) -?> ---EXPECT-- -string(13) "Object,Object" -array(2) { - [0]=> - &object(foo)(0) { - } - [1]=> - &object(foo)(0) { - } -} diff --git a/ext/standard/tests/strings/bug22227.phpt b/ext/standard/tests/strings/bug22227.phpt deleted file mode 100644 index eb980f9865..0000000000 --- a/ext/standard/tests/strings/bug22227.phpt +++ /dev/null @@ -1,9 +0,0 @@ ---TEST-- -Bug #22227 (printf() field limiters broke between 4.2.3 and 4.3.0) ---FILE-- -<?php -printf("%-3.3s", "abcdef"); -print "\n"; -?> ---EXPECT-- -abc diff --git a/ext/standard/tests/strings/chr_ord.phpt b/ext/standard/tests/strings/chr_ord.phpt deleted file mode 100644 index 266f61be04..0000000000 --- a/ext/standard/tests/strings/chr_ord.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -chr() and ord() functions ---POST-- ---GET-- ---FILE-- -<?php -echo "Testing ord() & chr()..."; -for($i=0; $i<256; $i++) echo !ord(chr($i)) == $i; -echo " done"; -?> ---EXPECT-- -Testing ord() & chr()... done diff --git a/ext/standard/tests/strings/chunk_split.phpt b/ext/standard/tests/strings/chunk_split.phpt deleted file mode 100644 index 6c0f3fac84..0000000000 --- a/ext/standard/tests/strings/chunk_split.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -chunk_split() function ---POST-- ---GET-- ---FILE-- -<?php -echo chunk_split('abc', 1, '-')."\n"; -echo chunk_split('foooooooooooooooo', 5)."\n"; -echo chunk_split(str_repeat('X', 2*76))."\n"; -?> ---EXPECT-- -a-b-c- -foooo -ooooo -ooooo -oo - -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX diff --git a/ext/standard/tests/strings/count_chars.phpt b/ext/standard/tests/strings/count_chars.phpt deleted file mode 100644 index 0006b4232f..0000000000 --- a/ext/standard/tests/strings/count_chars.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -count_chars() function ---POST-- ---GET-- ---FILE-- -<?php -$s = "het leven is net erwtensoep - je kunt er geen touw aan vastknopen"; -for($i=0; $i<3; $i++) { - echo implode(count_chars($s, $i))."\n"; -} -echo $a = count_chars($s, 3), "\n"; -echo (int) strlen(count_chars($s, 4)) == 256-strlen($a),"\n"; - -?> ---EXPECT-- -000000000000000000000000000000001200000000000010000000000000000000000000000000000000000000000000003000120111121083202362220000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -121312111121832236222 -000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 - -aeghijklnoprstuvw -1 diff --git a/ext/standard/tests/strings/crc32.phpt b/ext/standard/tests/strings/crc32.phpt deleted file mode 100644 index 8074c5e6f9..0000000000 --- a/ext/standard/tests/strings/crc32.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -crc32() function ---POST-- ---GET-- ---FILE-- -<?php -$input = array("foo", "bar", "baz", "grldsajkopallkjasd"); -foreach($input AS $i) { - printf("%u\n", crc32($i)); -} -?> ---EXPECT-- -2356372769 -1996459178 -2015626392 -824412087 diff --git a/ext/standard/tests/strings/crypt.phpt b/ext/standard/tests/strings/crypt.phpt deleted file mode 100644 index 06f3e941b9..0000000000 --- a/ext/standard/tests/strings/crypt.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -crypt() function ---FILE-- -<?php - -$str = 'rasmuslerdorf'; -$salt1 = 'rl'; -$res_1 = 'rl.3StKT.4T8M'; -$salt2 = '_J9..rasm'; -$res_2 = '_J9..rasmBYk8r9AiWNc'; -$salt3 = '$1$rasmusle$'; -$res_3 = '$1$rasmusle$rISCgZzpwk3UhDidwXvin0'; -$salt4 = '$2a$07$rasmuslerd............'; -$res_4 = '$2a$07$rasmuslerd............nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra'; - -echo (CRYPT_STD_DES) ? ((crypt($str, $salt1) === $res_1) ? 'STD' : 'STD - ERROR') : 'STD', "\n"; -echo (CRYPT_EXT_DES) ? ((crypt($str, $salt2) === $res_2) ? 'EXT' : 'EXT - ERROR') : 'EXT', "\n"; -echo (CRYPT_MD5) ? ((crypt($str, $salt3) === $res_3) ? 'MD5' : 'MD5 - ERROR') : 'MD5', "\n"; -echo (CRYPT_BLOWFISH) ? ((crypt($str, $salt4) === $res_4) ? 'BLO' : 'BLO - ERROR') : 'BLO', "\n"; - -?> ---EXPECT-- -STD -EXT -MD5 -BLO diff --git a/ext/standard/tests/strings/explode.phpt b/ext/standard/tests/strings/explode.phpt deleted file mode 100644 index 94d947fc4f..0000000000 --- a/ext/standard/tests/strings/explode.phpt +++ /dev/null @@ -1,116 +0,0 @@ ---TEST-- -explode() function ---POST-- ---GET-- ---INI-- -error_reporting=2047 ---FILE-- -<?php -/* From http://bugs.php.net/19865 */ -echo md5(var_export(explode("\1", "a". chr(1). "b". chr(0). "d" . chr(1) . "f" . chr(1). "1" . chr(1) . "d"), TRUE)); -echo "\n"; -var_dump(@explode("", "")); -var_dump(@explode("", NULL)); -var_dump(@explode(NULL, "")); -var_dump(@explode("a", "")); -var_dump(@explode("a", "a")); -var_dump(@explode("a", NULL)); -var_dump(@explode(NULL, a)); -var_dump(@explode("abc", "acb")); -var_dump(@explode("somestring", "otherstring")); -var_dump(@explode("a", "aaaaaa")); -var_dump(@explode("==", str_repeat("-=".ord(0)."=-", 10))); -var_dump(@explode("=", str_repeat("-=".ord(0)."=-", 10))); -?> ---EXPECTF-- -26d4e18734cb2582df5055e2175223df -bool(false) -bool(false) -bool(false) -array(1) { - [0]=> - string(0) "" -} -array(2) { - [0]=> - string(0) "" - [1]=> - string(0) "" -} -array(1) { - [0]=> - string(0) "" -} -bool(false) -array(1) { - [0]=> - string(3) "acb" -} -array(1) { - [0]=> - string(11) "otherstring" -} -array(7) { - [0]=> - string(0) "" - [1]=> - string(0) "" - [2]=> - string(0) "" - [3]=> - string(0) "" - [4]=> - string(0) "" - [5]=> - string(0) "" - [6]=> - string(0) "" -} -array(1) { - [0]=> - string(60) "-=48=--=48=--=48=--=48=--=48=--=48=--=48=--=48=--=48=--=48=-" -} -array(21) { - [0]=> - string(1) "-" - [1]=> - string(2) "48" - [2]=> - string(2) "--" - [3]=> - string(2) "48" - [4]=> - string(2) "--" - [5]=> - string(2) "48" - [6]=> - string(2) "--" - [7]=> - string(2) "48" - [8]=> - string(2) "--" - [9]=> - string(2) "48" - [10]=> - string(2) "--" - [11]=> - string(2) "48" - [12]=> - string(2) "--" - [13]=> - string(2) "48" - [14]=> - string(2) "--" - [15]=> - string(2) "48" - [16]=> - string(2) "--" - [17]=> - string(2) "48" - [18]=> - string(2) "--" - [19]=> - string(2) "48" - [20]=> - string(1) "-" -} diff --git a/ext/standard/tests/strings/htmlentities.phpt b/ext/standard/tests/strings/htmlentities.phpt deleted file mode 100644 index 743651ecad..0000000000 --- a/ext/standard/tests/strings/htmlentities.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -HTML entities ---INI-- -output_handler= ---FILE-- -<?php -setlocale (LC_CTYPE, "C"); -$sc_encoded = htmlspecialchars ("<>\"&åÄ\n"); -echo $sc_encoded; -$ent_encoded = htmlentities ("<>\"&åÄ\n"); -echo $ent_encoded; -echo html_entity_decode($sc_encoded); -echo html_entity_decode($ent_encoded); -?> ---EXPECT-- -<>"&åÄ -<>"&åÄ -<>"&åÄ -<>"&åÄ diff --git a/ext/standard/tests/strings/htmlentities01.phpt b/ext/standard/tests/strings/htmlentities01.phpt deleted file mode 100644 index 4ab49472d1..0000000000 --- a/ext/standard/tests/strings/htmlentities01.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -htmlentities() test 1 (cp1252) ---INI-- -output_handler= -mbstring.internal_encoding=pass ---FILE-- -<?php - var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, 'cp1252')); - var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, 'cp1252')); -?> ---EXPECT-- -string(28) "‚†™Ÿ" -string(32) "€¢£¤¥" diff --git a/ext/standard/tests/strings/htmlentities02.phpt b/ext/standard/tests/strings/htmlentities02.phpt deleted file mode 100644 index 3158cf44c6..0000000000 --- a/ext/standard/tests/strings/htmlentities02.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -htmlentities() test 2 (setlocale / fr_FR.ISO-8859-15) ---SKIPIF-- -<?php -$result = (bool)setlocale(LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15"); -if (!$result || preg_match('/ISO/i', setlocale(LC_CTYPE, 0)) == 0) { - die("skip setlocale() failed\n"); -} -?> ---INI-- -output_handler= -default_charset= -mbstring.internal_encoding=none ---FILE-- -<?php - setlocale( LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15" ); - var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, '')); -?> ---EXPECT-- -string(20) "ŒœŸ" diff --git a/ext/standard/tests/strings/htmlentities03.phpt b/ext/standard/tests/strings/htmlentities03.phpt deleted file mode 100644 index 7e933544fe..0000000000 --- a/ext/standard/tests/strings/htmlentities03.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -htmlentities() test 3 (setlocale / de_DE.ISO-8859-1) ---SKIPIF-- -<?php -$result = (bool)setlocale(LC_CTYPE, "de_DE.ISO-8859-1", "de_DE.ISO8859-1"); -if (!$result || preg_match('/ISO/i', setlocale(LC_CTYPE, 0)) == 0) { - die("skip setlocale() failed\n"); -} -?> ---INI-- -output_handler= -default_charset= -mbstring.internal_encoding=none ---FILE-- -<?php - setlocale( LC_CTYPE, "de_DE.ISO-8859-1", "de_DE.ISO8859-1"); - var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, '')); -?> ---EXPECT-- -string(18) "äöü" diff --git a/ext/standard/tests/strings/htmlentities04.phpt b/ext/standard/tests/strings/htmlentities04.phpt deleted file mode 100644 index 8e362d073c..0000000000 --- a/ext/standard/tests/strings/htmlentities04.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -htmlentities() test 4 (setlocale / ja_JP.EUC-JP) ---SKIPIF-- -<?php -$result = (bool)setlocale(LC_CTYPE, "ja_JP.EUC-JP", "ja_JP.eucJP"); -if (!$result || preg_match('/EUC[^a-zA-Z]*JP/i', setlocale(LC_CTYPE, 0)) == 0) { - die("skip setlocale() failed\n"); -} -?> ---INI-- -output_handler= -default_charset= -mbstring.internal_encoding=none ---FILE-- -<?php - setlocale( LC_CTYPE, "ja_JP.EUC-JP", "ja_JP.eucJP" ); - var_dump(htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, '')); -?> ---EXPECT-- -string(6) "¡¢¡£¡€" diff --git a/ext/standard/tests/strings/htmlentities05.phpt b/ext/standard/tests/strings/htmlentities05.phpt deleted file mode 100644 index 779cf289b0..0000000000 --- a/ext/standard/tests/strings/htmlentities05.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -htmlentities() test 5 (mbstring / cp1252) ---INI-- -output_handler= ---SKIPIF-- -<?php - extension_loaded("mbstring") or die("skip mbstring not available\n"); - mb_internal_encoding('cp1252'); - $php_errormsg = NULL; - @htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, ''); - if ($php_errormsg) { - die("skip cp1252 chracter set is not supported on this platform.\n"); - } -?> ---FILE-- -<?php - mb_internal_encoding('cp1252'); - print mb_internal_encoding()."\n"; - var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, '')); - var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, '')); -?> ---EXPECT-- -Windows-1252 -string(28) "‚†™Ÿ" -string(32) "€¢£¤¥" diff --git a/ext/standard/tests/strings/htmlentities06.phpt b/ext/standard/tests/strings/htmlentities06.phpt deleted file mode 100644 index 44d1466da9..0000000000 --- a/ext/standard/tests/strings/htmlentities06.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -htmlentities() test 6 (mbstring / ISO-8859-15) ---INI-- -output_handler= ---SKIPIF-- -<?php - extension_loaded("mbstring") or die("skip mbstring not available\n"); - @mb_internal_encoding('ISO-8859-15'); - @htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ''); - if (@$php_errormsg) { - die("skip ISO-8859-15 chracter set is not supported on this platform.\n"); - } -?> ---FILE-- -<?php - mb_internal_encoding('ISO-8859-15'); - print mb_internal_encoding()."\n"; - var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, '')); -?> ---EXPECT-- -ISO-8859-15 -string(20) "ŒœŸ" diff --git a/ext/standard/tests/strings/htmlentities07.phpt b/ext/standard/tests/strings/htmlentities07.phpt deleted file mode 100644 index efd06f08ad..0000000000 --- a/ext/standard/tests/strings/htmlentities07.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -htmlentities() test 7 (mbstring / ISO-8859-1) ---INI-- -output_handler= ---SKIPIF-- -<?php - extension_loaded("mbstring") or die("skip mbstring not available\n"); - mb_internal_encoding('ISO-8859-1'); - $php_errormsg = NULL; - @htmlentities("\xe4\xf6\xfc", ENT_QUOTES, ''); - if ($php_errormsg) { - die("skip ISO-8859-1 chracter set is not supported on this platform.\n"); - } -?> ---FILE-- -<?php - mb_internal_encoding('ISO-8859-1'); - print mb_internal_encoding()."\n"; - var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, '')); -?> ---EXPECT-- -ISO-8859-1 -string(18) "äöü" diff --git a/ext/standard/tests/strings/htmlentities08.phpt b/ext/standard/tests/strings/htmlentities08.phpt deleted file mode 100644 index 0f8f912f27..0000000000 --- a/ext/standard/tests/strings/htmlentities08.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -htmlentities() test 8 (mbstring / EUC-JP) ---INI-- -output_handler= ---SKIPIF-- -<?php - extension_loaded("mbstring") or die("skip mbstring not available\n"); - mb_internal_encoding('EUC-JP'); - $php_errormsg = NULL; - @htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, ''); - if ($php_errormsg) { - die("skip EUC-JP chracter set is not supported on this platform.\n"); - } -?> ---FILE-- -<?php - mb_internal_encoding('EUC-JP'); - print mb_internal_encoding()."\n"; - var_dump(htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, '')); -?> ---EXPECT-- -EUC-JP -string(6) "¡¢¡£¡€" diff --git a/ext/standard/tests/strings/htmlentities09.phpt b/ext/standard/tests/strings/htmlentities09.phpt deleted file mode 100644 index 4c6ef60c74..0000000000 --- a/ext/standard/tests/strings/htmlentities09.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -htmlentities() test 9 (mbstring / Shift_JIS) ---INI-- -output_handler= ---SKIPIF-- -<?php - extension_loaded("mbstring") or die("skip mbstring not available\n"); - mb_internal_encoding('Shift_JIS'); - $php_errormsg = NULL; - @htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, ''); - if ($php_errormsg) { - die("skip Shift_JIS chracter set is not supported on this platform.\n"); - } -?> ---FILE-- -<?php - mb_internal_encoding('Shift_JIS'); - print mb_internal_encoding()."\n"; - var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, '')); -?> ---EXPECT-- -SJIS -string(6) "ABC" diff --git a/ext/standard/tests/strings/htmlentities10.phpt b/ext/standard/tests/strings/htmlentities10.phpt deleted file mode 100644 index ee5099cf34..0000000000 --- a/ext/standard/tests/strings/htmlentities10.phpt +++ /dev/null @@ -1,16 +0,0 @@ ---TEST-- -htmlentities() test 10 (default_charset / cp1252) ---INI-- -output_handler= -mbstring.internal_encoding=pass -default_charset=cp1252 ---FILE-- -<?php - print ini_get('default_charset')."\n"; - var_dump(htmlentities("\x82\x86\x99\x9f", ENT_QUOTES, '')); - var_dump(htmlentities("\x80\xa2\xa3\xa4\xa5", ENT_QUOTES, '')); -?> ---EXPECT-- -cp1252 -string(28) "‚†™Ÿ" -string(32) "€¢£¤¥" diff --git a/ext/standard/tests/strings/htmlentities11.phpt b/ext/standard/tests/strings/htmlentities11.phpt deleted file mode 100644 index 62b6aec7c8..0000000000 --- a/ext/standard/tests/strings/htmlentities11.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -htmlentities() test 11 (default_charset / ISO-8859-15) ---INI-- -output_handler= -mbstring.internal_encoding=pass -default_charset=ISO-8859-15 ---FILE-- -<?php - print ini_get('default_charset')."\n"; - var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, '')); -?> ---EXPECT-- -ISO-8859-15 -string(20) "ŒœŸ" diff --git a/ext/standard/tests/strings/htmlentities12.phpt b/ext/standard/tests/strings/htmlentities12.phpt deleted file mode 100644 index 826706680d..0000000000 --- a/ext/standard/tests/strings/htmlentities12.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -htmlentities() test 12 (default_charset / ISO-8859-1) ---INI-- -output_handler= -mbstring.internal_encoding=pass -default_charset=ISO-8859-1 ---FILE-- -<?php - print ini_get('default_charset')."\n"; - var_dump(htmlentities("\xe4\xf6\xfc", ENT_QUOTES, '')); -?> ---EXPECT-- -ISO-8859-1 -string(18) "äöü" diff --git a/ext/standard/tests/strings/htmlentities13.phpt b/ext/standard/tests/strings/htmlentities13.phpt deleted file mode 100644 index 2c559916e9..0000000000 --- a/ext/standard/tests/strings/htmlentities13.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -htmlentities() test 13 (default_charset / EUC-JP) ---INI-- -output_handler= -mbstring.internal_encoding=pass -default_charset=EUC-JP ---FILE-- -<?php - print ini_get('default_charset')."\n"; - var_dump(htmlentities("\xa1\xa2\xa1\xa3\xa1\xa4", ENT_QUOTES, '')); -?> ---EXPECT-- -EUC-JP -string(6) "¡¢¡£¡€" diff --git a/ext/standard/tests/strings/htmlentities14.phpt b/ext/standard/tests/strings/htmlentities14.phpt deleted file mode 100644 index 9190d26515..0000000000 --- a/ext/standard/tests/strings/htmlentities14.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -htmlentities() test 14 (default_charset / Shift_JIS) ---INI-- -output_handler= -mbstring.internal_encoding=pass -default_charset=Shift_JIS ---FILE-- -<?php - print ini_get('default_charset')."\n"; - var_dump(htmlentities("\x81\x41\x81\x42\x81\x43", ENT_QUOTES, '')); -?> ---EXPECT-- -Shift_JIS -string(6) "ABC" diff --git a/ext/standard/tests/strings/implode.phpt b/ext/standard/tests/strings/implode.phpt deleted file mode 100644 index 66d6c435ae..0000000000 --- a/ext/standard/tests/strings/implode.phpt +++ /dev/null @@ -1,25 +0,0 @@ ---TEST-- -implode() function ---POST-- ---GET-- ---INI-- -error_reporting=2047 -log_errors=0 -display_errors=0 -track_errors=1 ---FILE-- -<?php -echo implode(array())."\n"; -echo implode('nothing', array())."\n"; -echo implode(array('foo', 'bar', 'baz'))."\n"; -echo implode(':', array('foo', 'bar', 'baz'))."\n"; -echo implode(':', array('foo', array('bar', 'baz'), 'burp'))."\n"; -echo $php_errormsg."\n"; -?> ---EXPECTF-- - - -foobarbaz -foo:bar:baz -foo:Array:burp -Array to string conversion diff --git a/ext/standard/tests/strings/md5.phpt b/ext/standard/tests/strings/md5.phpt deleted file mode 100644 index 32dba03609..0000000000 --- a/ext/standard/tests/strings/md5.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -md5() with ASCII output ---FILE-- -<?php -echo md5("")."\n"; -echo md5("a")."\n"; -echo md5("abc")."\n"; -echo md5("message digest")."\n"; -echo md5("abcdefghijklmnopqrstuvwxyz")."\n"; -echo md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")."\n"; -echo md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890")."\n"; -?> ---EXPECT-- -d41d8cd98f00b204e9800998ecf8427e -0cc175b9c0f1b6a831c399e269772661 -900150983cd24fb0d6963f7d28e17f72 -f96b697d7cb7938d525a2f31aaf161d0 -c3fcd3d76192e4007dfb496cca67e13b -d174ab98d277d9f5a5611c2c9f419d9f -57edf4a22be3c955ac49da2e2107b67a diff --git a/ext/standard/tests/strings/md5raw.phpt b/ext/standard/tests/strings/md5raw.phpt deleted file mode 100644 index 8f71ea6d0e..0000000000 --- a/ext/standard/tests/strings/md5raw.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -md5() with RAW output ---FILE-- -<?php -echo bin2hex(md5("", TRUE))."\n"; -echo bin2hex(md5("a", TRUE))."\n"; -echo bin2hex(md5("abc", TRUE))."\n"; -echo bin2hex(md5("message digest", TRUE))."\n"; -echo bin2hex(md5("abcdefghijklmnopqrstuvwxyz", TRUE))."\n"; -echo bin2hex(md5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", TRUE))."\n"; -echo bin2hex(md5("12345678901234567890123456789012345678901234567890123456789012345678901234567890", TRUE))."\n"; -?> ---EXPECT-- -d41d8cd98f00b204e9800998ecf8427e -0cc175b9c0f1b6a831c399e269772661 -900150983cd24fb0d6963f7d28e17f72 -f96b697d7cb7938d525a2f31aaf161d0 -c3fcd3d76192e4007dfb496cca67e13b -d174ab98d277d9f5a5611c2c9f419d9f -57edf4a22be3c955ac49da2e2107b67a diff --git a/ext/standard/tests/strings/nl2br.phpt b/ext/standard/tests/strings/nl2br.phpt deleted file mode 100644 index 63801afb66..0000000000 --- a/ext/standard/tests/strings/nl2br.phpt +++ /dev/null @@ -1,62 +0,0 @@ ---TEST-- -nl2br() function ---POST-- ---GET-- ---FILE-- -<?php - var_dump(nl2br("test")); - var_dump(nl2br("")); - var_dump(nl2br(NULL)); - var_dump(nl2br("\r\n")); - var_dump(nl2br("\n")); - var_dump(nl2br("\r")); - var_dump(nl2br("\n\r")); - - var_dump(nl2br("\n\r\r\n\r\r\r\r")); - var_dump(nl2br("\n\r\n\n\r\n\r\r\n\r\n")); - var_dump(nl2br("\n\r\n\n\n\n\r\r\r\r\n\r")); - -?> ---EXPECT-- -string(4) "test" -string(0) "" -string(0) "" -string(8) "<br /> -" -string(7) "<br /> -" -string(7) "<br /> -" -string(8) "<br /> - -" -string(44) "<br /> - -<br /> -<br /> -<br /> -<br /> -<br /> -" -string(47) "<br /> - -<br /> -<br /> - -<br /> - -<br /> -<br /> -" -string(66) "<br /> - -<br /> -<br /> -<br /> -<br /> - -<br /> -<br /> -<br /> -<br /> -" diff --git a/ext/standard/tests/strings/sha1.phpt b/ext/standard/tests/strings/sha1.phpt deleted file mode 100644 index c405eedde5..0000000000 --- a/ext/standard/tests/strings/sha1.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -sha1() with ASCII output ---FILE-- -<?php -echo sha1("abc")."\n"; -echo sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")."\n"; -echo sha1("a")."\n"; -echo sha1("0123456701234567012345670123456701234567012345670123456701234567")."\n"; -?> ---EXPECT-- -a9993e364706816aba3e25717850c26c9cd0d89d -84983e441c3bd26ebaae4aa1f95129e5e54670f1 -86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -e0c094e867ef46c350ef54a7f59dd60bed92ae83 diff --git a/ext/standard/tests/strings/sha1raw.phpt b/ext/standard/tests/strings/sha1raw.phpt deleted file mode 100644 index 6777cab3ee..0000000000 --- a/ext/standard/tests/strings/sha1raw.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -sha1() with RAW output ---FILE-- -<?php -echo bin2hex(sha1("abc", TRUE))."\n"; -echo bin2hex(sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", TRUE))."\n"; -echo bin2hex(sha1("a", TRUE))."\n"; -echo bin2hex(sha1("0123456701234567012345670123456701234567012345670123456701234567", TRUE))."\n"; -?> ---EXPECT-- -a9993e364706816aba3e25717850c26c9cd0d89d -84983e441c3bd26ebaae4aa1f95129e5e54670f1 -86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 -e0c094e867ef46c350ef54a7f59dd60bed92ae83 diff --git a/ext/standard/tests/strings/str_repeat.phpt b/ext/standard/tests/strings/str_repeat.phpt deleted file mode 100644 index 406e811af7..0000000000 --- a/ext/standard/tests/strings/str_repeat.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -str_repeat() function ---POST-- ---GET-- ---FILE-- -<?php -$input = array('a', 'foo', 'barbazbax'); -foreach($input AS $i) { - for($n=0; $n<5; $n++) { - echo str_repeat($i, $n)."\n"; - } -} -?> ---EXPECT-- - -a -aa -aaa -aaaa - -foo -foofoo -foofoofoo -foofoofoofoo - -barbazbax -barbazbaxbarbazbax -barbazbaxbarbazbaxbarbazbax -barbazbaxbarbazbaxbarbazbaxbarbazbax diff --git a/ext/standard/tests/strings/str_shuffle.phpt b/ext/standard/tests/strings/str_shuffle.phpt deleted file mode 100644 index cf6a07304b..0000000000 --- a/ext/standard/tests/strings/str_shuffle.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Testing str_shuffle. ---FILE-- -<?php -/* Do not change this test it is a REATME.TESTING example. */ -$s = '123'; -var_dump(str_shuffle($s)); -var_dump($s); -?> ---EXPECTF-- -string(3) %s -string(3) "123"
\ No newline at end of file diff --git a/ext/standard/tests/strings/strcspn.phpt b/ext/standard/tests/strings/strcspn.phpt deleted file mode 100644 index 88bcee5c19..0000000000 --- a/ext/standard/tests/strings/strcspn.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Test strcspn() behavior ---FILE-- -<?php -$a = "22222222aaaa bbb1111 cccc"; -$b = "1234"; -var_dump($a); -var_dump($b); -var_dump(strcspn($a,$b)); -var_dump(strcspn($a,$b,9)); -var_dump(strcspn($a,$b,9,6)); -?> ---EXPECT-- -string(25) "22222222aaaa bbb1111 cccc" -string(4) "1234" -int(0) -int(7) -int(6) diff --git a/ext/standard/tests/strings/strings001.phpt b/ext/standard/tests/strings/strings001.phpt deleted file mode 100644 index 87f8489b8a..0000000000 --- a/ext/standard/tests/strings/strings001.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -Test whether strstr() and strrchr() are binary safe. ---FILE-- -<?php -/* Do not change this test it is a README.TESTING example. */ -$s = "alabala nica".chr(0)."turska panica"; -var_dump(strstr($s, "nic")); -var_dump(strrchr($s," nic")); -?> ---EXPECTREGEX-- -string\(18\) \"nica\x00turska panica\" -string\(19\) \" nica\x00turska panica\" diff --git a/ext/standard/tests/strings/strip_tags.phpt b/ext/standard/tests/strings/strip_tags.phpt deleted file mode 100644 index 9c55bc6465..0000000000 --- a/ext/standard/tests/strings/strip_tags.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -strip_tags() function ---POST-- ---GET-- ---FILE-- -<?php - echo strip_tags('NEAT <? cool < blah ?> STUFF'); - echo "\n"; - echo strip_tags('NEAT <? cool > blah ?> STUFF'); - echo "\n"; - echo strip_tags('NEAT <!-- cool < blah --> STUFF'); - echo "\n"; - echo strip_tags('NEAT <!-- cool > blah --> STUFF'); - echo "\n"; - echo strip_tags('NEAT <? echo \"\\\"\"?> STUFF'); - echo "\n"; - echo strip_tags('NEAT <? echo \'\\\'\'?> STUFF'); - echo "\n"; - echo strip_tags('TESTS ?!!?!?!!!?!!'); - echo "\n"; -?> ---EXPECT-- -NEAT STUFF -NEAT STUFF -NEAT STUFF -NEAT STUFF -NEAT STUFF -NEAT STUFF -TESTS ?!!?!?!!!?!! diff --git a/ext/standard/tests/strings/strpos.phpt b/ext/standard/tests/strings/strpos.phpt deleted file mode 100644 index 7a9af70940..0000000000 --- a/ext/standard/tests/strings/strpos.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -strpos() function ---POST-- ---GET-- ---FILE-- -<?php - var_dump(strpos("test string", "test")); - var_dump(strpos("test string", "string")); - var_dump(strpos("test string", "strin")); - var_dump(strpos("test string", "t s")); - var_dump(strpos("test string", "g")); - var_dump(strpos("te".chr(0)."st", chr(0))); - var_dump(strpos("tEst", "test")); - var_dump(strpos("teSt", "test")); - var_dump(@strpos("", "")); - var_dump(@strpos("a", "")); - var_dump(@strpos("", "a")); - var_dump(@strpos("\\\\a", "\\a")); -?> ---EXPECT-- -int(0) -int(5) -int(5) -int(3) -int(10) -int(2) -bool(false) -bool(false) -bool(false) -bool(false) -bool(false) -int(1) diff --git a/ext/standard/tests/strings/strrev.phpt b/ext/standard/tests/strings/strrev.phpt deleted file mode 100644 index 6eb892b135..0000000000 --- a/ext/standard/tests/strings/strrev.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -strrev() function ---POST-- ---GET-- ---FILE-- -<?php - $i = 0; - $str = ''; - - while ($i<256) { - $str .= chr($i++); - } - - var_dump(md5(strrev($str))); - var_dump(strrev(NULL)); - var_dump(strrev("")); -?> ---EXPECT-- -string(32) "ec6df70f2569891eae50321a9179eb82" -string(0) "" -string(0) "" diff --git a/ext/standard/tests/strings/strspn.phpt b/ext/standard/tests/strings/strspn.phpt deleted file mode 100644 index 9f498b84d6..0000000000 --- a/ext/standard/tests/strings/strspn.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Test strspn() behavior ---FILE-- -<?php -$a = "22222222aaaa bbb1111 cccc"; -$b = "1234"; -var_dump($a); -var_dump($b); -var_dump(strspn($a,$b)); -var_dump(strspn($a,$b,2)); -var_dump(strspn($a,$b,2,3)); -?> ---EXPECT-- -string(25) "22222222aaaa bbb1111 cccc" -string(4) "1234" -int(8) -int(6) -int(3) diff --git a/ext/standard/tests/strings/strstr.phpt b/ext/standard/tests/strings/strstr.phpt deleted file mode 100644 index 29cd30a2a9..0000000000 --- a/ext/standard/tests/strings/strstr.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -strstr() function ---POST-- ---GET-- ---FILE-- -<?php - var_dump(strstr("test string", "test")); - var_dump(strstr("test string", "string")); - var_dump(strstr("test string", "strin")); - var_dump(strstr("test string", "t s")); - var_dump(strstr("test string", "g")); - var_dump(md5(strstr("te".chr(0)."st", chr(0)))); - var_dump(strstr("tEst", "test")); - var_dump(strstr("teSt", "test")); - var_dump(@strstr("", "")); - var_dump(@strstr("a", "")); - var_dump(@strstr("", "a")); - var_dump(md5(@strstr("\\\\a\\", "\\a"))); -?> ---EXPECT-- -string(11) "test string" -string(6) "string" -string(6) "string" -string(8) "t string" -string(1) "g" -string(32) "7272696018bdeb2c9a3f8d01fc2a9273" -bool(false) -bool(false) -bool(false) -bool(false) -bool(false) -string(32) "6ec19f52f0766c463f3bb240f4396913" diff --git a/ext/standard/tests/strings/strtoupper.phpt b/ext/standard/tests/strings/strtoupper.phpt deleted file mode 100644 index 41bc5e6080..0000000000 --- a/ext/standard/tests/strings/strtoupper.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Test strtoupper on non-ASCII characters ---SKIPIF-- -<?php -if (!setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1")) { - die("skip locale needed for this test is not supported on this platform"); -} -?> ---FILE-- -<?php -$chars = "äöü"; -// Not sure which is most portable. BSD's answer to -// this one. A small array based on PHP_OS should -// cover a majority of systems and makes the problem -// of locales transparent for the end user. -setlocale(LC_CTYPE, "de_DE", "de", "german", "ge", "de_DE.ISO8859-1", "ISO8859-1"); -echo strtoupper($chars)."\n"; -?> ---EXPECT-- -ÄÖÜ diff --git a/ext/standard/tests/strings/strtr.phpt b/ext/standard/tests/strings/strtr.phpt deleted file mode 100644 index 7d9bd31d14..0000000000 --- a/ext/standard/tests/strings/strtr.phpt +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -strtr() function ---FILE-- -<?php -/* Do not change this test it is a REATME.TESTING example. */ -$trans = array("hello"=>"hi", "hi"=>"hello", "a"=>"A", "world"=>"planet"); -var_dump(strtr("# hi all, I said hello world! #", $trans)); -?> ---EXPECT-- -string(32) "# hello All, I sAid hi planet! #"
\ No newline at end of file diff --git a/ext/standard/tests/strings/substr_count.phpt b/ext/standard/tests/strings/substr_count.phpt deleted file mode 100644 index 29f43dfae2..0000000000 --- a/ext/standard/tests/strings/substr_count.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -substr_count() function ---POST-- ---GET-- ---FILE-- -<?php - var_dump(@substr_count("", "")); - var_dump(@substr_count("a", "")); - var_dump(@substr_count("", "a")); - var_dump(@substr_count("", "a")); - var_dump(@substr_count("", chr(0))); - - $a = str_repeat("abcacba", 100); - var_dump(@substr_count($a, "bca")); - - $a = str_repeat("abcacbabca", 100); - var_dump(@substr_count($a, "bca")); -?> ---EXPECT-- -bool(false) -bool(false) -int(0) -int(0) -int(0) -int(100) -int(200) diff --git a/ext/standard/tests/strings/trim.phpt b/ext/standard/tests/strings/trim.phpt deleted file mode 100644 index 881064d7e4..0000000000 --- a/ext/standard/tests/strings/trim.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -trim(), rtrim() and ltrim() functions ---POST-- ---GET-- ---FILE-- -<?php - -$tests = <<<TESTS -'ABC' === trim('ABC') -'ABC' === ltrim('ABC') -'ABC' === rtrim('ABC') -'ABC' === trim(" \\0\\t\\nABC \\0\\t\\n") -"ABC \\0\\t\\n" === ltrim(" \\0\\t\\nABC \\0\\t\\n") -" \\0\\t\\nABC" === rtrim(" \\0\\t\\nABC \\0\\t\\n") -" \\0\\t\\nABC \\0\\t\\n" === trim(" \\0\\t\\nABC \\0\\t\\n",'') -" \\0\\t\\nABC \\0\\t\\n" === ltrim(" \\0\\t\\nABC \\0\\t\\n",'') -" \\0\\t\\nABC \\0\\t\\n" === rtrim(" \\0\\t\\nABC \\0\\t\\n",'') -"ABC\\x50\\xC1" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC0") -"ABC\\x50" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC1") -"ABC" === trim("ABC\\x50\\xC1\\x60\\x90","\\x50..\\xC1") -"ABC\\x50\\xC1" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC0") -"ABC\\x50" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC1") -"ABC" === trim("ABC\\x50\\xC1\\x60\\x90","\\x50..\\xC1") -TESTS; - -include('tests/quicktester.inc'); - ---EXPECT-- -OK diff --git a/ext/standard/tests/strings/url_t.phpt b/ext/standard/tests/strings/url_t.phpt deleted file mode 100644 index 78a6706f54..0000000000 --- a/ext/standard/tests/strings/url_t.phpt +++ /dev/null @@ -1,618 +0,0 @@ ---TEST-- -parse_url() function ---POST-- ---GET-- ---FILE-- -<?php -$sample_urls = array ( -'', -'64.246.30.37', -'http://64.246.30.37', -'http://64.246.30.37/', -'64.246.30.37/', -'64.246.30.37:80/', -'php.net', -'php.net/', -'http://php.net', -'http://php.net/', -'www.php.net', -'www.php.net/', -'http://www.php.net', -'http://www.php.net/', -'www.php.net:80', -'http://www.php.net:80', -'http://www.php.net:80/', -'http://www.php.net/index.php', -'www.php.net/?', -'www.php.net:80/?', -'http://www.php.net/?', -'http://www.php.net:80/?', -'http://www.php.net:80/index.php', -'http://www.php.net:80/foo/bar/index.php', -'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php', -'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php?lots=1&of=2¶meters=3&too=4&here=5', -'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/', -'http://www.php.net:80/this/is/a/very/deep/directory/structure/and/file.php', -'http://www.php.net:80/this/../a/../deep/directory', -'http://www.php.net:80/this/../a/../deep/directory/', -'http://www.php.net:80/this/is/a/very/deep/directory/../file.php', -'http://www.php.net:80/index.php', -'http://www.php.net:80/index.php?', -'http://www.php.net:80/#foo', -'http://www.php.net:80/?#', -'http://www.php.net:80/?test=1', -'http://www.php.net/?test=1&', -'http://www.php.net:80/?&', -'http://www.php.net:80/index.php?test=1&', -'http://www.php.net/index.php?&', -'http://www.php.net:80/index.php?foo&', -'http://www.php.net/index.php?&foo', -'http://www.php.net:80/index.php?test=1&test2=char&test3=mixesCI', -'www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://secret@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://secret:@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://:hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://secret:hideout@www.php.net/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://secret@hideout@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'http://secret:hid:out@www.php.net:80/index.php?test=1&test2=char&test3=mixesCI#some_page_ref123', -'nntp://news.php.net', -'ftp://ftp.gnu.org/gnu/glic/glibc.tar.gz', -'zlib:http://foo@bar', -'zlib:filename.txt', -'zlib:/path/to/my/file/file.txt', -'foo://foo@bar', -'mailto:me@mydomain.com', -'/foo.php?a=b&c=d', -'foo.php?a=b&c=d', -'http://user:passwd@www.example.com:8080?bar=1&boom=0' -); - - foreach ($sample_urls as $url) { - var_dump(@parse_url($url)); - } -?> ---EXPECT-- -array(1) { - ["path"]=> - string(0) "" -} -array(1) { - ["path"]=> - string(12) "64.246.30.37" -} -array(2) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(12) "64.246.30.37" -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(12) "64.246.30.37" - ["path"]=> - string(1) "/" -} -array(1) { - ["path"]=> - string(13) "64.246.30.37/" -} -array(3) { - ["host"]=> - string(12) "64.246.30.37" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" -} -array(1) { - ["path"]=> - string(7) "php.net" -} -array(1) { - ["path"]=> - string(8) "php.net/" -} -array(2) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(7) "php.net" -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(7) "php.net" - ["path"]=> - string(1) "/" -} -array(1) { - ["path"]=> - string(11) "www.php.net" -} -array(1) { - ["path"]=> - string(12) "www.php.net/" -} -array(2) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(1) "/" -} -array(2) { - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(10) "/index.php" -} -array(1) { - ["path"]=> - string(12) "www.php.net/" -} -array(3) { - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" -} -array(3) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(1) "/" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(18) "/foo/bar/index.php" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(53) "/this/is/a/very/deep/directory/structure/and/file.php" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(53) "/this/is/a/very/deep/directory/structure/and/file.php" - ["query"]=> - string(37) "lots=1&of=2¶meters=3&too=4&here=5" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(45) "/this/is/a/very/deep/directory/structure/and/" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(53) "/this/is/a/very/deep/directory/structure/and/file.php" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(28) "/this/../a/../deep/directory" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(29) "/this/../a/../deep/directory/" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(42) "/this/is/a/very/deep/directory/../file.php" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" - ["fragment"]=> - string(3) "foo" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" - ["query"]=> - string(6) "test=1" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(1) "/" - ["query"]=> - string(7) "test=1&" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(1) "/" - ["query"]=> - string(1) "&" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(7) "test=1&" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(1) "&" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(4) "foo&" -} -array(4) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(4) "&foo" -} -array(5) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" -} -array(5) { - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(7) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["user"]=> - string(6) "secret" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(6) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["user"]=> - string(6) "secret" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(7) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["pass"]=> - string(7) "hideout" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(7) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["user"]=> - string(6) "secret" - ["pass"]=> - string(7) "hideout" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(7) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(19) "hideout@www.php.net" - ["port"]=> - int(80) - ["user"]=> - string(6) "secret" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(8) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(11) "www.php.net" - ["port"]=> - int(80) - ["user"]=> - string(6) "secret" - ["pass"]=> - string(7) "hid:out" - ["path"]=> - string(10) "/index.php" - ["query"]=> - string(31) "test=1&test2=char&test3=mixesCI" - ["fragment"]=> - string(16) "some_page_ref123" -} -array(2) { - ["scheme"]=> - string(4) "nntp" - ["host"]=> - string(12) "news.php.net" -} -array(3) { - ["scheme"]=> - string(3) "ftp" - ["host"]=> - string(11) "ftp.gnu.org" - ["path"]=> - string(22) "/gnu/glic/glibc.tar.gz" -} -array(2) { - ["scheme"]=> - string(4) "zlib" - ["path"]=> - string(14) "http://foo@bar" -} -array(2) { - ["scheme"]=> - string(4) "zlib" - ["path"]=> - string(12) "filename.txt" -} -array(2) { - ["scheme"]=> - string(4) "zlib" - ["path"]=> - string(25) "/path/to/my/file/file.txt" -} -array(3) { - ["scheme"]=> - string(3) "foo" - ["host"]=> - string(3) "bar" - ["user"]=> - string(3) "foo" -} -array(2) { - ["scheme"]=> - string(6) "mailto" - ["path"]=> - string(15) "me@mydomain.com" -} -array(2) { - ["path"]=> - string(8) "/foo.php" - ["query"]=> - string(7) "a=b&c=d" -} -array(2) { - ["path"]=> - string(7) "foo.php" - ["query"]=> - string(7) "a=b&c=d" -} -array(6) { - ["scheme"]=> - string(4) "http" - ["host"]=> - string(15) "www.example.com" - ["port"]=> - int(8080) - ["user"]=> - string(4) "user" - ["pass"]=> - string(6) "passwd" - ["query"]=> - string(12) "bar=1&boom=0" -} diff --git a/ext/standard/tests/strings/wordwrap.phpt b/ext/standard/tests/strings/wordwrap.phpt deleted file mode 100644 index 3fc8f1d880..0000000000 --- a/ext/standard/tests/strings/wordwrap.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -wordwrap() function ---POST-- ---GET-- ---FILE-- -<?php - -$tests = <<<TESTS -"12345 12345 12345 12345" === wordwrap("12345 12345 12345 12345") -"12345 12345\\n1234567890\\n1234567890" === wordwrap("12345 12345 1234567890 1234567890",12) -"12345\\n12345\\n12345\\n12345" === wordwrap("12345 12345 12345 12345",0) -"12345ab12345ab12345ab12345" === wordwrap("12345 12345 12345 12345",0,"ab") -"12345 12345ab1234567890ab1234567890" === wordwrap("12345 12345 1234567890 1234567890",12,"ab") -"123ab123ab123" === wordwrap("123ab123ab123", 3, "ab") -"123ab123ab123" === wordwrap("123ab123ab123", 5, "ab") -"123ab 123ab123" === wordwrap("123 123ab123", 3, "ab") -"123ab123ab123" === wordwrap("123 123ab123", 5, "ab") -"123 123ab123" === wordwrap("123 123 123", 10, "ab") - -"123ab123ab123" === wordwrap("123ab123ab123", 3, "ab", 1) -"123ab123ab123" === wordwrap("123ab123ab123", 5, "ab", 1) -"123ab 12ab3ab123" === wordwrap("123 123ab123", 3, "ab", 1) -"123 ab123ab123" === wordwrap("123 123ab123", 5, "ab", 1) -"123 123ab 123" === wordwrap("123 123 123", 8, "ab", 1) -"123 ab12345 ab123" === wordwrap("123 12345 123", 8, "ab", 1) -"1ab2ab3ab4" === wordwrap("1234", 1, "ab", 1) - -"12345|12345|67890" === wordwrap("12345 1234567890", 5, "|", 1) - -"123|==1234567890|==123" === wordwrap("123 1234567890 123", 10, "|==", 1) - -TESTS; - -include('tests/quicktester.inc'); - ---EXPECT-- -OK diff --git a/ext/standard/tests/time/001.phpt b/ext/standard/tests/time/001.phpt deleted file mode 100644 index e1a422957c..0000000000 --- a/ext/standard/tests/time/001.phpt +++ /dev/null @@ -1,31 +0,0 @@ ---TEST-- -microtime() function ---SKIPIF-- -<?php if (!function_exists('microtime')) die('skip microtime() not available'); ?> ---FILE-- -<?php -$passed = 0; -$failed = 0; -$last_m = 0; -$last_t = 0; -$result = ''; - -set_time_limit(0); - -for ($i=1;$i<=100000;$i++) { - list($micro,$time)=explode(" ",microtime()); - if ($time > $last_t || ($time == $last_t && $micro > $last_m)) { - $passed++; - } else if ($failed++ <=10) { - $result .= sprintf('%06d', $i).": $time $micro < $last_t $last_m\n"; - } - $last_m = $micro; - $last_t = $time; -} -echo "Passed: $passed\n"; -echo "Failed: $failed\n"; -echo $result; -?> ---EXPECT-- -Passed: 100000 -Failed: 0 diff --git a/ext/standard/tests/time/002-win32.phpt b/ext/standard/tests/time/002-win32.phpt deleted file mode 100644 index 1d7ef57153..0000000000 --- a/ext/standard/tests/time/002-win32.phpt +++ /dev/null @@ -1,66 +0,0 @@ ---TEST-- -strtotime() function ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) != 'WIN') { - print 'skip test for win32 only'; -} -if (!@putenv("TZ=GST-1GDT") || getenv("TZ") != 'GST-1GDT') { - die("skip unable to change TZ enviroment variable\n"); -} -?> ---FILE-- -<?php - $dates = array ( - "1999-10-13", - "Oct 13 1999", - "2000-01-19", - "Jan 19 2000", - "2001-12-21", - "Dec 21 2001", - "2001-12-21 12:16", - "Dec 21 2001 12:16", - "2001-10-22 21:19:58", - "2001-10-22 21:19:58-02", - "2001-10-22 21:19:58-0213", - "2001-10-22 21:19:58+02", - "2001-10-22 21:19:58+0213" - ); - - putenv ("TZ=GMT"); - foreach ($dates as $date) { - echo date("Y-m-d H:i:s\n", strtotime ($date)); - } - - putenv ("TZ=GST-1GDT"); - foreach ($dates as $date) { - echo date("Y-m-d H:i:s\n", strtotime ($date)); - } -?> ---EXPECT-- -1999-10-13 00:00:00 -1999-10-13 00:00:00 -2000-01-19 00:00:00 -2000-01-19 00:00:00 -2001-12-21 00:00:00 -2001-12-21 00:00:00 -2001-12-21 12:16:00 -2001-12-21 12:16:00 -2001-10-22 21:19:58 -2001-10-22 23:19:58 -2001-10-22 23:32:58 -2001-10-22 19:19:58 -2001-10-22 19:06:58 -1999-10-13 00:00:00 -1999-10-13 00:00:00 -2000-01-19 00:00:00 -2000-01-19 00:00:00 -2001-12-21 00:00:00 -2001-12-21 00:00:00 -2001-12-21 12:16:00 -2001-12-21 12:16:00 -2001-10-22 21:19:58 -2001-10-23 01:19:58 -2001-10-23 01:32:58 -2001-10-22 21:19:58 -2001-10-22 21:06:58 diff --git a/ext/standard/tests/time/002.phpt b/ext/standard/tests/time/002.phpt deleted file mode 100644 index fa33634bc8..0000000000 --- a/ext/standard/tests/time/002.phpt +++ /dev/null @@ -1,69 +0,0 @@ ---TEST-- -strtotime() function ---SKIPIF-- -<?php -if (substr(PHP_OS, 0, 3) == 'WIN') { - die('skip Windows does not support dates prior to midnight (00:00:00), January 1, 1970'); -} -if (!@putenv("TZ=Europe/Amsterdam") || getenv("TZ") != 'Europe/Amsterdam') { - die("skip unable to change TZ enviroment variable\n"); -} -?> ---FILE-- -<?php - $dates = array ( - "1999-10-13", - "Oct 13 1999", - "2000-01-19", - "Jan 19 2000", - "2001-12-21", - "Dec 21 2001", - "2001-12-21 12:16", - "Dec 21 2001 12:16", - "Dec 21 12:16", - "2001-10-22 21:19:58", - "2001-10-22 21:19:58-02", - "2001-10-22 21:19:58-0213", - "2001-10-22 21:19:58+02", - "2001-10-22 21:19:58+0213" - ); - - putenv ("TZ=GMT"); - foreach ($dates as $date) { - echo date ("Y-m-d H:i:s\n", strtotime ($date)); - } - - putenv ("TZ=Europe/Amsterdam"); - foreach ($dates as $date) { - echo date ("Y-m-d H:i:s\n", strtotime ($date)); - } -?> ---EXPECT-- -1999-10-13 00:00:00 -1999-10-13 00:00:00 -2000-01-19 00:00:00 -2000-01-19 00:00:00 -2001-12-21 00:00:00 -2001-12-21 00:00:00 -2001-12-21 12:16:00 -2001-12-21 12:16:00 -1969-12-31 23:59:59 -2001-10-22 21:19:58 -2001-10-22 23:19:58 -2001-10-22 23:32:58 -2001-10-22 19:19:58 -2001-10-22 19:06:58 -1999-10-13 00:00:00 -1999-10-13 00:00:00 -2000-01-19 00:00:00 -2000-01-19 00:00:00 -2001-12-21 00:00:00 -2001-12-21 00:00:00 -2001-12-21 12:16:00 -2001-12-21 12:16:00 -1970-01-01 00:59:59 -2001-10-22 21:19:58 -2001-10-23 01:19:58 -2001-10-23 01:32:58 -2001-10-22 21:19:58 -2001-10-22 21:06:58 diff --git a/ext/standard/tests/time/003.phpt b/ext/standard/tests/time/003.phpt deleted file mode 100644 index 2da8121b6a..0000000000 --- a/ext/standard/tests/time/003.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Check for mktime with out-of-range parameters ---SKIPIF-- ---POST-- ---GET-- ---FILE-- -<?php - # MacOS/X libc implementation doesn't treat out-of-range values - # the same way other unices do (Bug# 10686) so some extra code - # was added to datetime.c to take care of this - echo date("Y-m-d", mktime( 12, 0, 0, 3, 0, 2000)) ."\n"; - echo date("Y-m-d", mktime( 12, 0, 0, 3, -1, 2000)) ."\n"; - echo date("Y-m-d", mktime( 12, 0, 0, 2, 29, 2000)) ."\n"; - echo date("Y-m-d", mktime( 12, 0, 0, 3, 0, 2001)) ."\n"; - echo date("Y-m-d", mktime( 12, 0, 0, 2, 29, 2001)) ."\n"; - echo date("Y-m-d", mktime( 12, 0, 0, 0, 0, 2000)) ."\n"; - - putenv("TZ=GST-1GDT"); - echo date("Y-m-d H:i:s", mktime(12,0,0,3,+90,2000,-1))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,3,+90,2000,0))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,3,+90,2000,1))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-90,2000,-1))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-90,2000,0))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-90,2000,1))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-1,2000,-1))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-1,2000,0))."\n"; - echo date("Y-m-d H:i:s", mktime(12,0,0,5,-1,2000,1))."\n"; -?> ---EXPECT-- -2000-02-29 -2000-02-28 -2000-02-29 -2001-02-28 -2001-03-01 -1999-11-30 -2000-05-29 12:00:00 -2000-05-29 13:00:00 -2000-05-29 12:00:00 -2000-01-31 12:00:00 -2000-01-31 12:00:00 -2000-01-31 11:00:00 -2000-04-29 12:00:00 -2000-04-29 13:00:00 -2000-04-29 12:00:00 diff --git a/ext/standard/tests/time/idate.phpt b/ext/standard/tests/time/idate.phpt deleted file mode 100644 index 403ec6bdbb..0000000000 --- a/ext/standard/tests/time/idate.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -idate() function ---FILE-- -<?php -putenv ("TZ=GMT"); - -$tmp = "UYzymndjHGhgistwLBIW"; -for($a = 0;$a < strlen($tmp); $a++){ - echo $tmp{$a}, ': ', idate($tmp{$a}, 1043324459)."\n"; -} -?> ---EXPECT-- -U: 1043324459 -Y: 2003 -z: 22 -y: 3 -m: 1 -n: 1 -d: 23 -j: 23 -H: 12 -G: 12 -h: 12 -g: 12 -i: 20 -s: 59 -t: 31 -w: 4 -L: 0 -B: 556 -I: 0 -W: 4 diff --git a/ext/standard/tests/time/mktime.phpt b/ext/standard/tests/time/mktime.phpt deleted file mode 100644 index e0b1fd3f9f..0000000000 --- a/ext/standard/tests/time/mktime.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -mktime() ---FILE-- -<?php -$timezones = array( - 'GMT', - 'GST-1GDT' -); - -foreach($timezones as $timezone) -{ - putenv('TZ='.$timezone); - - /* status of daylight saving time unknown */ - var_dump(mktime(0, 0, 0, 1, 1, 2002)); - /* status of daylight saving time unknown */ - var_dump(mktime(0, 0, 0, 1, 1, 2002, -1)); - /* daylight saving time is not in affect */ - var_dump(mktime(0, 0, 0, 1, 1, 2002, 0)); - /* daylight saving time is in affect */ - var_dump(mktime(0, 0, 0, 1, 1, 2002, 1)); - - /* status of daylight saving time unknown */ - var_dump(mktime(0, 0, 0, 7, 1, 2002)); - /* status of daylight saving time unknown */ - var_dump(mktime(0, 0, 0, 7, 1, 2002, -1)); - /* daylight saving time is not in affect */ - var_dump(mktime(0, 0, 0, 7, 1, 2002, 0)); - /* daylight saving time is in affect */ - var_dump(mktime(0, 0, 0, 7, 1, 2002, 1)); -} -?> ---EXPECT-- -int(1009843200) -int(1009843200) -int(1009843200) -int(1009843200) -int(1025481600) -int(1025481600) -int(1025481600) -int(1025481600) -int(1009839600) -int(1009839600) -int(1009839600) -int(1009836000) -int(1025474400) -int(1025474400) -int(1025478000) -int(1025474400) diff --git a/ext/standard/tests/versioning/version_compare.phpt b/ext/standard/tests/versioning/version_compare.phpt deleted file mode 100644 index 6ef49ba777..0000000000 --- a/ext/standard/tests/versioning/version_compare.phpt +++ /dev/null @@ -1,600 +0,0 @@ ---TEST-- -version_compare test ---FILE-- -<?php - -print "TESTING COMPARE\n"; -$special_forms = array("-dev", "a1", "b1", "RC1", "", "pl1"); -$operators = array( - "lt", "<", - "le", "<=", - "gt", ">", - "ge", ">=", - "eq", "=", "==", - "ne", "<>", "!=" -); -test("1", "2"); -test("10", "2"); -test("1.0", "1.1"); -test("1.2", "1.0.1"); -foreach ($special_forms as $f1) { - foreach ($special_forms as $f2) { - test("1.0$f1", "1.0$f2"); - } -} -print "TESTING OPERATORS\n"; -foreach ($special_forms as $f1) { - foreach ($special_forms as $f2) { - foreach ($operators as $op) { - $v1 = "1.0$f1"; - $v2 = "1.0$f2"; - $test = version_compare($v1, $v2, $op) ? "true" : "false"; - printf("%7s %2s %-7s : %s\n", $v1, $op, $v2, $test); - } - } -} - -function test($v1, $v2) { - $compare = version_compare($v1, $v2); - switch ($compare) { - case -1: - print "$v1 < $v2\n"; - break; - case 1: - print "$v1 > $v2\n"; - break; - case 0: - default: - print "$v1 = $v2\n"; - break; - } -} - -?> ---EXPECT-- -TESTING COMPARE -1 < 2 -10 > 2 -1.0 < 1.1 -1.2 > 1.0.1 -1.0-dev = 1.0-dev -1.0-dev < 1.0a1 -1.0-dev < 1.0b1 -1.0-dev < 1.0RC1 -1.0-dev < 1.0 -1.0-dev < 1.0pl1 -1.0a1 > 1.0-dev -1.0a1 = 1.0a1 -1.0a1 < 1.0b1 -1.0a1 < 1.0RC1 -1.0a1 < 1.0 -1.0a1 < 1.0pl1 -1.0b1 > 1.0-dev -1.0b1 > 1.0a1 -1.0b1 = 1.0b1 -1.0b1 < 1.0RC1 -1.0b1 < 1.0 -1.0b1 < 1.0pl1 -1.0RC1 > 1.0-dev -1.0RC1 > 1.0a1 -1.0RC1 > 1.0b1 -1.0RC1 = 1.0RC1 -1.0RC1 < 1.0 -1.0RC1 < 1.0pl1 -1.0 > 1.0-dev -1.0 > 1.0a1 -1.0 > 1.0b1 -1.0 > 1.0RC1 -1.0 = 1.0 -1.0 < 1.0pl1 -1.0pl1 > 1.0-dev -1.0pl1 > 1.0a1 -1.0pl1 > 1.0b1 -1.0pl1 > 1.0RC1 -1.0pl1 > 1.0 -1.0pl1 = 1.0pl1 -TESTING OPERATORS -1.0-dev lt 1.0-dev : false -1.0-dev < 1.0-dev : false -1.0-dev le 1.0-dev : true -1.0-dev <= 1.0-dev : true -1.0-dev gt 1.0-dev : false -1.0-dev > 1.0-dev : false -1.0-dev ge 1.0-dev : true -1.0-dev >= 1.0-dev : true -1.0-dev eq 1.0-dev : true -1.0-dev = 1.0-dev : true -1.0-dev == 1.0-dev : true -1.0-dev ne 1.0-dev : false -1.0-dev <> 1.0-dev : false -1.0-dev != 1.0-dev : false -1.0-dev lt 1.0a1 : true -1.0-dev < 1.0a1 : true -1.0-dev le 1.0a1 : true -1.0-dev <= 1.0a1 : true -1.0-dev gt 1.0a1 : false -1.0-dev > 1.0a1 : false -1.0-dev ge 1.0a1 : false -1.0-dev >= 1.0a1 : false -1.0-dev eq 1.0a1 : false -1.0-dev = 1.0a1 : false -1.0-dev == 1.0a1 : false -1.0-dev ne 1.0a1 : true -1.0-dev <> 1.0a1 : true -1.0-dev != 1.0a1 : true -1.0-dev lt 1.0b1 : true -1.0-dev < 1.0b1 : true -1.0-dev le 1.0b1 : true -1.0-dev <= 1.0b1 : true -1.0-dev gt 1.0b1 : false -1.0-dev > 1.0b1 : false -1.0-dev ge 1.0b1 : false -1.0-dev >= 1.0b1 : false -1.0-dev eq 1.0b1 : false -1.0-dev = 1.0b1 : false -1.0-dev == 1.0b1 : false -1.0-dev ne 1.0b1 : true -1.0-dev <> 1.0b1 : true -1.0-dev != 1.0b1 : true -1.0-dev lt 1.0RC1 : true -1.0-dev < 1.0RC1 : true -1.0-dev le 1.0RC1 : true -1.0-dev <= 1.0RC1 : true -1.0-dev gt 1.0RC1 : false -1.0-dev > 1.0RC1 : false -1.0-dev ge 1.0RC1 : false -1.0-dev >= 1.0RC1 : false -1.0-dev eq 1.0RC1 : false -1.0-dev = 1.0RC1 : false -1.0-dev == 1.0RC1 : false -1.0-dev ne 1.0RC1 : true -1.0-dev <> 1.0RC1 : true -1.0-dev != 1.0RC1 : true -1.0-dev lt 1.0 : true -1.0-dev < 1.0 : true -1.0-dev le 1.0 : true -1.0-dev <= 1.0 : true -1.0-dev gt 1.0 : false -1.0-dev > 1.0 : false -1.0-dev ge 1.0 : false -1.0-dev >= 1.0 : false -1.0-dev eq 1.0 : false -1.0-dev = 1.0 : false -1.0-dev == 1.0 : false -1.0-dev ne 1.0 : true -1.0-dev <> 1.0 : true -1.0-dev != 1.0 : true -1.0-dev lt 1.0pl1 : true -1.0-dev < 1.0pl1 : true -1.0-dev le 1.0pl1 : true -1.0-dev <= 1.0pl1 : true -1.0-dev gt 1.0pl1 : false -1.0-dev > 1.0pl1 : false -1.0-dev ge 1.0pl1 : false -1.0-dev >= 1.0pl1 : false -1.0-dev eq 1.0pl1 : false -1.0-dev = 1.0pl1 : false -1.0-dev == 1.0pl1 : false -1.0-dev ne 1.0pl1 : true -1.0-dev <> 1.0pl1 : true -1.0-dev != 1.0pl1 : true - 1.0a1 lt 1.0-dev : false - 1.0a1 < 1.0-dev : false - 1.0a1 le 1.0-dev : false - 1.0a1 <= 1.0-dev : false - 1.0a1 gt 1.0-dev : true - 1.0a1 > 1.0-dev : true - 1.0a1 ge 1.0-dev : true - 1.0a1 >= 1.0-dev : true - 1.0a1 eq 1.0-dev : false - 1.0a1 = 1.0-dev : false - 1.0a1 == 1.0-dev : false - 1.0a1 ne 1.0-dev : true - 1.0a1 <> 1.0-dev : true - 1.0a1 != 1.0-dev : true - 1.0a1 lt 1.0a1 : false - 1.0a1 < 1.0a1 : false - 1.0a1 le 1.0a1 : true - 1.0a1 <= 1.0a1 : true - 1.0a1 gt 1.0a1 : false - 1.0a1 > 1.0a1 : false - 1.0a1 ge 1.0a1 : true - 1.0a1 >= 1.0a1 : true - 1.0a1 eq 1.0a1 : true - 1.0a1 = 1.0a1 : true - 1.0a1 == 1.0a1 : true - 1.0a1 ne 1.0a1 : false - 1.0a1 <> 1.0a1 : false - 1.0a1 != 1.0a1 : false - 1.0a1 lt 1.0b1 : true - 1.0a1 < 1.0b1 : true - 1.0a1 le 1.0b1 : true - 1.0a1 <= 1.0b1 : true - 1.0a1 gt 1.0b1 : false - 1.0a1 > 1.0b1 : false - 1.0a1 ge 1.0b1 : false - 1.0a1 >= 1.0b1 : false - 1.0a1 eq 1.0b1 : false - 1.0a1 = 1.0b1 : false - 1.0a1 == 1.0b1 : false - 1.0a1 ne 1.0b1 : true - 1.0a1 <> 1.0b1 : true - 1.0a1 != 1.0b1 : true - 1.0a1 lt 1.0RC1 : true - 1.0a1 < 1.0RC1 : true - 1.0a1 le 1.0RC1 : true - 1.0a1 <= 1.0RC1 : true - 1.0a1 gt 1.0RC1 : false - 1.0a1 > 1.0RC1 : false - 1.0a1 ge 1.0RC1 : false - 1.0a1 >= 1.0RC1 : false - 1.0a1 eq 1.0RC1 : false - 1.0a1 = 1.0RC1 : false - 1.0a1 == 1.0RC1 : false - 1.0a1 ne 1.0RC1 : true - 1.0a1 <> 1.0RC1 : true - 1.0a1 != 1.0RC1 : true - 1.0a1 lt 1.0 : true - 1.0a1 < 1.0 : true - 1.0a1 le 1.0 : true - 1.0a1 <= 1.0 : true - 1.0a1 gt 1.0 : false - 1.0a1 > 1.0 : false - 1.0a1 ge 1.0 : false - 1.0a1 >= 1.0 : false - 1.0a1 eq 1.0 : false - 1.0a1 = 1.0 : false - 1.0a1 == 1.0 : false - 1.0a1 ne 1.0 : true - 1.0a1 <> 1.0 : true - 1.0a1 != 1.0 : true - 1.0a1 lt 1.0pl1 : true - 1.0a1 < 1.0pl1 : true - 1.0a1 le 1.0pl1 : true - 1.0a1 <= 1.0pl1 : true - 1.0a1 gt 1.0pl1 : false - 1.0a1 > 1.0pl1 : false - 1.0a1 ge 1.0pl1 : false - 1.0a1 >= 1.0pl1 : false - 1.0a1 eq 1.0pl1 : false - 1.0a1 = 1.0pl1 : false - 1.0a1 == 1.0pl1 : false - 1.0a1 ne 1.0pl1 : true - 1.0a1 <> 1.0pl1 : true - 1.0a1 != 1.0pl1 : true - 1.0b1 lt 1.0-dev : false - 1.0b1 < 1.0-dev : false - 1.0b1 le 1.0-dev : false - 1.0b1 <= 1.0-dev : false - 1.0b1 gt 1.0-dev : true - 1.0b1 > 1.0-dev : true - 1.0b1 ge 1.0-dev : true - 1.0b1 >= 1.0-dev : true - 1.0b1 eq 1.0-dev : false - 1.0b1 = 1.0-dev : false - 1.0b1 == 1.0-dev : false - 1.0b1 ne 1.0-dev : true - 1.0b1 <> 1.0-dev : true - 1.0b1 != 1.0-dev : true - 1.0b1 lt 1.0a1 : false - 1.0b1 < 1.0a1 : false - 1.0b1 le 1.0a1 : false - 1.0b1 <= 1.0a1 : false - 1.0b1 gt 1.0a1 : true - 1.0b1 > 1.0a1 : true - 1.0b1 ge 1.0a1 : true - 1.0b1 >= 1.0a1 : true - 1.0b1 eq 1.0a1 : false - 1.0b1 = 1.0a1 : false - 1.0b1 == 1.0a1 : false - 1.0b1 ne 1.0a1 : true - 1.0b1 <> 1.0a1 : true - 1.0b1 != 1.0a1 : true - 1.0b1 lt 1.0b1 : false - 1.0b1 < 1.0b1 : false - 1.0b1 le 1.0b1 : true - 1.0b1 <= 1.0b1 : true - 1.0b1 gt 1.0b1 : false - 1.0b1 > 1.0b1 : false - 1.0b1 ge 1.0b1 : true - 1.0b1 >= 1.0b1 : true - 1.0b1 eq 1.0b1 : true - 1.0b1 = 1.0b1 : true - 1.0b1 == 1.0b1 : true - 1.0b1 ne 1.0b1 : false - 1.0b1 <> 1.0b1 : false - 1.0b1 != 1.0b1 : false - 1.0b1 lt 1.0RC1 : true - 1.0b1 < 1.0RC1 : true - 1.0b1 le 1.0RC1 : true - 1.0b1 <= 1.0RC1 : true - 1.0b1 gt 1.0RC1 : false - 1.0b1 > 1.0RC1 : false - 1.0b1 ge 1.0RC1 : false - 1.0b1 >= 1.0RC1 : false - 1.0b1 eq 1.0RC1 : false - 1.0b1 = 1.0RC1 : false - 1.0b1 == 1.0RC1 : false - 1.0b1 ne 1.0RC1 : true - 1.0b1 <> 1.0RC1 : true - 1.0b1 != 1.0RC1 : true - 1.0b1 lt 1.0 : true - 1.0b1 < 1.0 : true - 1.0b1 le 1.0 : true - 1.0b1 <= 1.0 : true - 1.0b1 gt 1.0 : false - 1.0b1 > 1.0 : false - 1.0b1 ge 1.0 : false - 1.0b1 >= 1.0 : false - 1.0b1 eq 1.0 : false - 1.0b1 = 1.0 : false - 1.0b1 == 1.0 : false - 1.0b1 ne 1.0 : true - 1.0b1 <> 1.0 : true - 1.0b1 != 1.0 : true - 1.0b1 lt 1.0pl1 : true - 1.0b1 < 1.0pl1 : true - 1.0b1 le 1.0pl1 : true - 1.0b1 <= 1.0pl1 : true - 1.0b1 gt 1.0pl1 : false - 1.0b1 > 1.0pl1 : false - 1.0b1 ge 1.0pl1 : false - 1.0b1 >= 1.0pl1 : false - 1.0b1 eq 1.0pl1 : false - 1.0b1 = 1.0pl1 : false - 1.0b1 == 1.0pl1 : false - 1.0b1 ne 1.0pl1 : true - 1.0b1 <> 1.0pl1 : true - 1.0b1 != 1.0pl1 : true - 1.0RC1 lt 1.0-dev : false - 1.0RC1 < 1.0-dev : false - 1.0RC1 le 1.0-dev : false - 1.0RC1 <= 1.0-dev : false - 1.0RC1 gt 1.0-dev : true - 1.0RC1 > 1.0-dev : true - 1.0RC1 ge 1.0-dev : true - 1.0RC1 >= 1.0-dev : true - 1.0RC1 eq 1.0-dev : false - 1.0RC1 = 1.0-dev : false - 1.0RC1 == 1.0-dev : false - 1.0RC1 ne 1.0-dev : true - 1.0RC1 <> 1.0-dev : true - 1.0RC1 != 1.0-dev : true - 1.0RC1 lt 1.0a1 : false - 1.0RC1 < 1.0a1 : false - 1.0RC1 le 1.0a1 : false - 1.0RC1 <= 1.0a1 : false - 1.0RC1 gt 1.0a1 : true - 1.0RC1 > 1.0a1 : true - 1.0RC1 ge 1.0a1 : true - 1.0RC1 >= 1.0a1 : true - 1.0RC1 eq 1.0a1 : false - 1.0RC1 = 1.0a1 : false - 1.0RC1 == 1.0a1 : false - 1.0RC1 ne 1.0a1 : true - 1.0RC1 <> 1.0a1 : true - 1.0RC1 != 1.0a1 : true - 1.0RC1 lt 1.0b1 : false - 1.0RC1 < 1.0b1 : false - 1.0RC1 le 1.0b1 : false - 1.0RC1 <= 1.0b1 : false - 1.0RC1 gt 1.0b1 : true - 1.0RC1 > 1.0b1 : true - 1.0RC1 ge 1.0b1 : true - 1.0RC1 >= 1.0b1 : true - 1.0RC1 eq 1.0b1 : false - 1.0RC1 = 1.0b1 : false - 1.0RC1 == 1.0b1 : false - 1.0RC1 ne 1.0b1 : true - 1.0RC1 <> 1.0b1 : true - 1.0RC1 != 1.0b1 : true - 1.0RC1 lt 1.0RC1 : false - 1.0RC1 < 1.0RC1 : false - 1.0RC1 le 1.0RC1 : true - 1.0RC1 <= 1.0RC1 : true - 1.0RC1 gt 1.0RC1 : false - 1.0RC1 > 1.0RC1 : false - 1.0RC1 ge 1.0RC1 : true - 1.0RC1 >= 1.0RC1 : true - 1.0RC1 eq 1.0RC1 : true - 1.0RC1 = 1.0RC1 : true - 1.0RC1 == 1.0RC1 : true - 1.0RC1 ne 1.0RC1 : false - 1.0RC1 <> 1.0RC1 : false - 1.0RC1 != 1.0RC1 : false - 1.0RC1 lt 1.0 : true - 1.0RC1 < 1.0 : true - 1.0RC1 le 1.0 : true - 1.0RC1 <= 1.0 : true - 1.0RC1 gt 1.0 : false - 1.0RC1 > 1.0 : false - 1.0RC1 ge 1.0 : false - 1.0RC1 >= 1.0 : false - 1.0RC1 eq 1.0 : false - 1.0RC1 = 1.0 : false - 1.0RC1 == 1.0 : false - 1.0RC1 ne 1.0 : true - 1.0RC1 <> 1.0 : true - 1.0RC1 != 1.0 : true - 1.0RC1 lt 1.0pl1 : true - 1.0RC1 < 1.0pl1 : true - 1.0RC1 le 1.0pl1 : true - 1.0RC1 <= 1.0pl1 : true - 1.0RC1 gt 1.0pl1 : false - 1.0RC1 > 1.0pl1 : false - 1.0RC1 ge 1.0pl1 : false - 1.0RC1 >= 1.0pl1 : false - 1.0RC1 eq 1.0pl1 : false - 1.0RC1 = 1.0pl1 : false - 1.0RC1 == 1.0pl1 : false - 1.0RC1 ne 1.0pl1 : true - 1.0RC1 <> 1.0pl1 : true - 1.0RC1 != 1.0pl1 : true - 1.0 lt 1.0-dev : false - 1.0 < 1.0-dev : false - 1.0 le 1.0-dev : false - 1.0 <= 1.0-dev : false - 1.0 gt 1.0-dev : true - 1.0 > 1.0-dev : true - 1.0 ge 1.0-dev : true - 1.0 >= 1.0-dev : true - 1.0 eq 1.0-dev : false - 1.0 = 1.0-dev : false - 1.0 == 1.0-dev : false - 1.0 ne 1.0-dev : true - 1.0 <> 1.0-dev : true - 1.0 != 1.0-dev : true - 1.0 lt 1.0a1 : false - 1.0 < 1.0a1 : false - 1.0 le 1.0a1 : false - 1.0 <= 1.0a1 : false - 1.0 gt 1.0a1 : true - 1.0 > 1.0a1 : true - 1.0 ge 1.0a1 : true - 1.0 >= 1.0a1 : true - 1.0 eq 1.0a1 : false - 1.0 = 1.0a1 : false - 1.0 == 1.0a1 : false - 1.0 ne 1.0a1 : true - 1.0 <> 1.0a1 : true - 1.0 != 1.0a1 : true - 1.0 lt 1.0b1 : false - 1.0 < 1.0b1 : false - 1.0 le 1.0b1 : false - 1.0 <= 1.0b1 : false - 1.0 gt 1.0b1 : true - 1.0 > 1.0b1 : true - 1.0 ge 1.0b1 : true - 1.0 >= 1.0b1 : true - 1.0 eq 1.0b1 : false - 1.0 = 1.0b1 : false - 1.0 == 1.0b1 : false - 1.0 ne 1.0b1 : true - 1.0 <> 1.0b1 : true - 1.0 != 1.0b1 : true - 1.0 lt 1.0RC1 : false - 1.0 < 1.0RC1 : false - 1.0 le 1.0RC1 : false - 1.0 <= 1.0RC1 : false - 1.0 gt 1.0RC1 : true - 1.0 > 1.0RC1 : true - 1.0 ge 1.0RC1 : true - 1.0 >= 1.0RC1 : true - 1.0 eq 1.0RC1 : false - 1.0 = 1.0RC1 : false - 1.0 == 1.0RC1 : false - 1.0 ne 1.0RC1 : true - 1.0 <> 1.0RC1 : true - 1.0 != 1.0RC1 : true - 1.0 lt 1.0 : false - 1.0 < 1.0 : false - 1.0 le 1.0 : true - 1.0 <= 1.0 : true - 1.0 gt 1.0 : false - 1.0 > 1.0 : false - 1.0 ge 1.0 : true - 1.0 >= 1.0 : true - 1.0 eq 1.0 : true - 1.0 = 1.0 : true - 1.0 == 1.0 : true - 1.0 ne 1.0 : false - 1.0 <> 1.0 : false - 1.0 != 1.0 : false - 1.0 lt 1.0pl1 : true - 1.0 < 1.0pl1 : true - 1.0 le 1.0pl1 : true - 1.0 <= 1.0pl1 : true - 1.0 gt 1.0pl1 : false - 1.0 > 1.0pl1 : false - 1.0 ge 1.0pl1 : false - 1.0 >= 1.0pl1 : false - 1.0 eq 1.0pl1 : false - 1.0 = 1.0pl1 : false - 1.0 == 1.0pl1 : false - 1.0 ne 1.0pl1 : true - 1.0 <> 1.0pl1 : true - 1.0 != 1.0pl1 : true - 1.0pl1 lt 1.0-dev : false - 1.0pl1 < 1.0-dev : false - 1.0pl1 le 1.0-dev : false - 1.0pl1 <= 1.0-dev : false - 1.0pl1 gt 1.0-dev : true - 1.0pl1 > 1.0-dev : true - 1.0pl1 ge 1.0-dev : true - 1.0pl1 >= 1.0-dev : true - 1.0pl1 eq 1.0-dev : false - 1.0pl1 = 1.0-dev : false - 1.0pl1 == 1.0-dev : false - 1.0pl1 ne 1.0-dev : true - 1.0pl1 <> 1.0-dev : true - 1.0pl1 != 1.0-dev : true - 1.0pl1 lt 1.0a1 : false - 1.0pl1 < 1.0a1 : false - 1.0pl1 le 1.0a1 : false - 1.0pl1 <= 1.0a1 : false - 1.0pl1 gt 1.0a1 : true - 1.0pl1 > 1.0a1 : true - 1.0pl1 ge 1.0a1 : true - 1.0pl1 >= 1.0a1 : true - 1.0pl1 eq 1.0a1 : false - 1.0pl1 = 1.0a1 : false - 1.0pl1 == 1.0a1 : false - 1.0pl1 ne 1.0a1 : true - 1.0pl1 <> 1.0a1 : true - 1.0pl1 != 1.0a1 : true - 1.0pl1 lt 1.0b1 : false - 1.0pl1 < 1.0b1 : false - 1.0pl1 le 1.0b1 : false - 1.0pl1 <= 1.0b1 : false - 1.0pl1 gt 1.0b1 : true - 1.0pl1 > 1.0b1 : true - 1.0pl1 ge 1.0b1 : true - 1.0pl1 >= 1.0b1 : true - 1.0pl1 eq 1.0b1 : false - 1.0pl1 = 1.0b1 : false - 1.0pl1 == 1.0b1 : false - 1.0pl1 ne 1.0b1 : true - 1.0pl1 <> 1.0b1 : true - 1.0pl1 != 1.0b1 : true - 1.0pl1 lt 1.0RC1 : false - 1.0pl1 < 1.0RC1 : false - 1.0pl1 le 1.0RC1 : false - 1.0pl1 <= 1.0RC1 : false - 1.0pl1 gt 1.0RC1 : true - 1.0pl1 > 1.0RC1 : true - 1.0pl1 ge 1.0RC1 : true - 1.0pl1 >= 1.0RC1 : true - 1.0pl1 eq 1.0RC1 : false - 1.0pl1 = 1.0RC1 : false - 1.0pl1 == 1.0RC1 : false - 1.0pl1 ne 1.0RC1 : true - 1.0pl1 <> 1.0RC1 : true - 1.0pl1 != 1.0RC1 : true - 1.0pl1 lt 1.0 : false - 1.0pl1 < 1.0 : false - 1.0pl1 le 1.0 : false - 1.0pl1 <= 1.0 : false - 1.0pl1 gt 1.0 : true - 1.0pl1 > 1.0 : true - 1.0pl1 ge 1.0 : true - 1.0pl1 >= 1.0 : true - 1.0pl1 eq 1.0 : false - 1.0pl1 = 1.0 : false - 1.0pl1 == 1.0 : false - 1.0pl1 ne 1.0 : true - 1.0pl1 <> 1.0 : true - 1.0pl1 != 1.0 : true - 1.0pl1 lt 1.0pl1 : false - 1.0pl1 < 1.0pl1 : false - 1.0pl1 le 1.0pl1 : true - 1.0pl1 <= 1.0pl1 : true - 1.0pl1 gt 1.0pl1 : false - 1.0pl1 > 1.0pl1 : false - 1.0pl1 ge 1.0pl1 : true - 1.0pl1 >= 1.0pl1 : true - 1.0pl1 eq 1.0pl1 : true - 1.0pl1 = 1.0pl1 : true - 1.0pl1 == 1.0pl1 : true - 1.0pl1 ne 1.0pl1 : false - 1.0pl1 <> 1.0pl1 : false - 1.0pl1 != 1.0pl1 : false diff --git a/ext/standard/type.c b/ext/standard/type.c deleted file mode 100644 index b6fdd65a03..0000000000 --- a/ext/standard/type.c +++ /dev/null @@ -1,378 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Rasmus Lerdorf <rasmus@php.net> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#include "php.h" -#include "php_incomplete_class.h" - -/* {{{ proto string gettype(mixed var) - Returns the type of the variable */ -PHP_FUNCTION(gettype) -{ - pval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (Z_TYPE_PP(arg)) { - case IS_NULL: - RETVAL_STRING("NULL", 1); - break; - - case IS_BOOL: - RETVAL_STRING("boolean", 1); - break; - - case IS_LONG: - RETVAL_STRING("integer", 1); - break; - - case IS_RESOURCE: - RETVAL_STRING("resource", 1); - break; - - case IS_DOUBLE: - RETVAL_STRING("double", 1); - break; - - case IS_STRING: - RETVAL_STRING("string", 1); - break; - - case IS_ARRAY: - RETVAL_STRING("array", 1); - break; - - case IS_OBJECT: - RETVAL_STRING("object", 1); - /* - { - char *result; - int res_len; - - res_len = sizeof("object of type ")-1 + Z_OBJCE_P(arg)->name_length; - result = (char *) emalloc(res_len+1); - sprintf(result, "object of type %s", Z_OBJCE_P(arg)->name); - RETVAL_STRINGL(result, res_len, 0); - } - */ - break; - - default: - RETVAL_STRING("unknown type", 1); - } -} -/* }}} */ - -/* {{{ proto bool settype(mixed var, string type) - Set the type of the variable */ -PHP_FUNCTION(settype) -{ - pval **var, **type; - char *new_type; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &var, &type) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(type); - new_type = Z_STRVAL_PP(type); - - if (!strcasecmp(new_type, "integer")) { - convert_to_long(*var); - } else if (!strcasecmp(new_type, "int")) { - convert_to_long(*var); - } else if (!strcasecmp(new_type, "float")) { - convert_to_double(*var); - } else if (!strcasecmp(new_type, "double")) { /* deprecated */ - convert_to_double(*var); - } else if (!strcasecmp(new_type, "string")) { - convert_to_string(*var); - } else if (!strcasecmp(new_type, "array")) { - convert_to_array(*var); - } else if (!strcasecmp(new_type, "object")) { - convert_to_object(*var); - } else if (!strcasecmp(new_type, "bool")) { - convert_to_boolean(*var); - } else if (!strcasecmp(new_type, "boolean")) { - convert_to_boolean(*var); - } else if (!strcasecmp(new_type, "null")) { - convert_to_null(*var); - } else if (!strcasecmp(new_type, "resource")) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot convert to resource type"); - RETURN_FALSE; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid type"); - RETURN_FALSE; - } - RETVAL_TRUE; -} -/* }}} */ - -/* {{{ proto int intval(mixed var [, int base]) - Get the integer value of a variable using the optional base for the conversion */ -PHP_FUNCTION(intval) -{ - pval **num, **arg_base; - int base; - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - base = 10; - break; - - case 2: - if (zend_get_parameters_ex(2, &num, &arg_base) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg_base); - base = Z_LVAL_PP(arg_base); - break; - - default: - WRONG_PARAM_COUNT; - } - - *return_value = **num; - zval_copy_ctor(return_value); - convert_to_long_base(return_value, base); -} -/* }}} */ - -/* {{{ proto float floatval(mixed var) - Get the float value of a variable */ -PHP_FUNCTION(floatval) -{ - pval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - - *return_value = **num; - zval_copy_ctor(return_value); - convert_to_double(return_value); -} -/* }}} */ - -/* {{{ proto string strval(mixed var) - Get the string value of a variable */ -PHP_FUNCTION(strval) -{ - pval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - - *return_value = **num; - zval_copy_ctor(return_value); - convert_to_string(return_value); -} -/* }}} */ - -static void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type) -{ - pval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Only one argument expected"); - RETURN_FALSE; - } - - if (Z_TYPE_PP(arg) == type) { - if (type == IS_OBJECT) { - zend_class_entry *ce; - ce = Z_OBJCE_PP(arg); - if (!strcmp(ce->name, INCOMPLETE_CLASS)) { - RETURN_FALSE; - } - } - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} - - -/* {{{ proto bool is_null(mixed var) - Returns true if variable is null */ -PHP_FUNCTION(is_null) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL); -} -/* }}} */ - -/* {{{ proto bool is_resource(mixed var) - Returns true if variable is a resource */ -PHP_FUNCTION(is_resource) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE); -} -/* }}} */ - -/* {{{ proto bool is_bool(mixed var) - Returns true if variable is a boolean */ -PHP_FUNCTION(is_bool) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_BOOL); -} -/* }}} */ - -/* {{{ proto bool is_long(mixed var) - Returns true if variable is a long (integer) */ -PHP_FUNCTION(is_long) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG); -} -/* }}} */ - -/* {{{ proto bool is_float(mixed var) - Returns true if variable is float point*/ -PHP_FUNCTION(is_float) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE); -} -/* }}} */ - -/* {{{ proto bool is_string(mixed var) - Returns true if variable is a string */ -PHP_FUNCTION(is_string) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING); -} -/* }}} */ - -/* {{{ proto bool is_array(mixed var) - Returns true if variable is an array */ -PHP_FUNCTION(is_array) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY); -} -/* }}} */ - -/* {{{ proto bool is_object(mixed var) - Returns true if variable is an object */ -PHP_FUNCTION(is_object) -{ - php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT); -} -/* }}} */ - -/* {{{ proto bool is_numeric(mixed value) - Returns true if value is a number or a numeric string */ -PHP_FUNCTION(is_numeric) -{ - zval **arg; - int result; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (Z_TYPE_PP(arg)) { - case IS_LONG: - case IS_DOUBLE: - RETURN_TRUE; - break; - - case IS_STRING: - result = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0); - if (result == IS_LONG || result == IS_DOUBLE) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - break; - - default: - RETURN_FALSE; - break; - } -} -/* }}} */ - -/* {{{ proto bool is_scalar(mixed value) - Returns true if value is a scalar */ -PHP_FUNCTION(is_scalar) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (Z_TYPE_PP(arg)) { - case IS_BOOL: - case IS_DOUBLE: - case IS_LONG: - case IS_STRING: - RETURN_TRUE; - break; - - default: - RETURN_FALSE; - break; - } -} -/* }}} */ - -/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name]]) - Returns true if var is callable. */ -PHP_FUNCTION(is_callable) -{ - zval **var, **syntax_only, **callable_name; - char *name; - zend_bool retval; - zend_bool syntax = 0; - int argc=ZEND_NUM_ARGS(); - - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &var, &syntax_only, &callable_name) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (argc > 1) { - convert_to_boolean_ex(syntax_only); - syntax = Z_BVAL_PP(syntax_only); - } - - if (argc > 2) { - retval = zend_is_callable(*var, syntax, &name); - zval_dtor(*callable_name); - ZVAL_STRING(*callable_name, name, 0); - } else { - retval = zend_is_callable(*var, syntax, NULL); - } - - RETURN_BOOL(retval); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c deleted file mode 100644 index 9a9c7f7f74..0000000000 --- a/ext/standard/uniqid.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#include <stdlib.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <string.h> -#include <errno.h> - -#include <stdio.h> -#ifdef PHP_WIN32 -#include "win32/time.h" -#else -#include <sys/time.h> -#endif - -#include "php_lcg.h" -#include "uniqid.h" - -/* {{{ proto string uniqid([string prefix , bool more_entropy]) - Generates a unique ID */ -#ifdef HAVE_GETTIMEOFDAY -PHP_FUNCTION(uniqid) -{ - char *prefix = ""; -#if defined(__CYGWIN__) - zend_bool more_entropy = 1; -#else - zend_bool more_entropy = 0; -#endif - char *uniqid; - int sec, usec, argc, prefix_len = 0; - struct timeval tv; - - argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "|sb", &prefix, &prefix_len, - &more_entropy)) { - return; - } - -#if HAVE_USLEEP && !defined(PHP_WIN32) - if (!more_entropy) { -#if defined(__CYGWIN__) - php_error_docref(NULL TSRMLS_CC, E_ERROR, "You must use 'more entropy' under CYGWIN."); - return; -#else - usleep(1); -#endif - } -#endif - gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); - sec = (int) tv.tv_sec; - usec = (int) (tv.tv_usec % 0x100000); - - /* The max value usec can have is 0xF423F, so we use only five hex - * digits for usecs. - */ - if (more_entropy) { - spprintf(&uniqid, 0, "%s%08x%05x%.8f", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10); - } else { - spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec); - } - - RETURN_STRING(uniqid, 0); -} -#endif -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/uniqid.h b/ext/standard/uniqid.h deleted file mode 100644 index 36e94aa2cb..0000000000 --- a/ext/standard/uniqid.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef UNIQID_H -#define UNIQID_H - -#ifdef HAVE_GETTIMEOFDAY -PHP_FUNCTION(uniqid); -#endif - -#endif /* UNIQID_H */ diff --git a/ext/standard/url.c b/ext/standard/url.c deleted file mode 100644 index 8bbb599e5b..0000000000 --- a/ext/standard/url.c +++ /dev/null @@ -1,622 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <sys/types.h> - -#include "php.h" - -#include "url.h" -#ifdef _OSD_POSIX -#ifndef APACHE -#error On this EBCDIC platform, PHP is only supported as an Apache module. -#else /*APACHE*/ -#ifndef CHARSET_EBCDIC -#define CHARSET_EBCDIC /* this machine uses EBCDIC, not ASCII! */ -#endif -#include "ebcdic.h" -#endif /*APACHE*/ -#endif /*_OSD_POSIX*/ - -/* {{{ free_url - */ -PHPAPI void php_url_free(php_url *theurl) -{ - if (theurl->scheme) - efree(theurl->scheme); - if (theurl->user) - efree(theurl->user); - if (theurl->pass) - efree(theurl->pass); - if (theurl->host) - efree(theurl->host); - if (theurl->path) - efree(theurl->path); - if (theurl->query) - efree(theurl->query); - if (theurl->fragment) - efree(theurl->fragment); - efree(theurl); -} -/* }}} */ - -/* {{{ php_replace_controlchars - */ -PHPAPI char *php_replace_controlchars(char *str) -{ - unsigned char *s = (unsigned char *)str; - - if (!str) { - return (NULL); - } - - while (*s) { - - if (iscntrl(*s)) { - *s='_'; - } - s++; - } - - return (str); -} -/* }}} */ - - -/* {{{ php_url_parse - */ -PHPAPI php_url *php_url_parse(char *str) -{ - int length = strlen(str); - char port_buf[5]; - php_url *ret = ecalloc(1, sizeof(php_url)); - char *s, *e, *p, *pp, *ue; - - s = str; - ue = s + length; - - /* parse scheme */ - if ((e = strchr(s, ':')) && (e-s)) { - /* - * certain schemas like mailto: and zlib: may not have any / after them - * this check ensures we support those. - */ - if (*(e+1) != '/') { - /* check if the data we get is a port this allows us to - * correctly parse things like a.com:80 - */ - p = e + 1; - while (isdigit(*p)) { - p++; - } - - if ((*p) == '\0' || *p == '/') { - goto parse_port; - } - - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars(ret->scheme); - - length -= ++e - s; - s = e; - goto just_path; - } else { - ret->scheme = estrndup(s, (e-s)); - php_replace_controlchars(ret->scheme); - - if (*(e+2) == '/') { - s = e + 3; - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { - goto nohost; - } - } else { - s = e + 1; - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { - goto nohost; - } else { - length -= ++e - s; - s = e; - goto just_path; - } - } - } - } else if (e) { /* no scheme, look for port */ - parse_port: - p = e + 1; - pp = p; - - while (pp-p < 6 && isdigit(*pp)) { - pp++; - } - - if (pp-p < 6 && (*pp == '/' || *pp == '\0')) { - memcpy(port_buf, p, (pp-p)); - port_buf[pp-p] = '\0'; - ret->port = atoi(port_buf); - } else { - goto just_path; - } - } else { - just_path: - ue = s + length; - goto nohost; - } - - e = ue; - - if (!(p = strchr(s, '/'))) { - if ((p = strchr(s, '?'))) { - e = p; - } - } else { - e = p; - } - - /* check for login and password */ - if ((p = memchr(s, '@', (e-s)))) { - if ((pp = memchr(s, ':', (p-s)))) { - if ((pp-s) > 0) { - ret->user = estrndup(s, (pp-s)); - php_replace_controlchars(ret->user); - } - - pp++; - if (p-pp > 0) { - ret->pass = estrndup(pp, (p-pp)); - php_replace_controlchars(ret->pass); - } - } else { - ret->user = estrndup(s, (p-s)); - php_replace_controlchars(ret->user); - } - - s = p + 1; - } - - /* check for port */ - if ((p = memchr(s, ':', (e-s)))) { - if (!ret->port) { - p++; - if ( e-p > 5 || e-p < 1 ) { /* port cannot be longer then 5 characters */ - STR_FREE(ret->scheme); - STR_FREE(ret->user); - STR_FREE(ret->pass); - efree(ret); - return NULL; - } - - memcpy(port_buf, p, (e-p)); - port_buf[e-p] = '\0'; - ret->port = atoi(port_buf); - p--; - } - } else { - p = e; - } - - /* check if we have a valid host, if we don't reject the string as url */ - if ((p-s) < 1) { - STR_FREE(ret->scheme); - STR_FREE(ret->user); - STR_FREE(ret->pass); - efree(ret); - return NULL; - } - - ret->host = estrndup(s, (p-s)); - php_replace_controlchars(ret->host); - - if (e == ue) { - return ret; - } - - s = e; - - nohost: - - if ((p = strchr(s, '?'))) { - pp = strchr(s, '#'); - - if (pp && pp < p) { - p = pp; - pp = strchr(pp+2, '#'); - } - - if (p - s) { - ret->path = estrndup(s, (p-s)); - php_replace_controlchars(ret->path); - } - - if (pp) { - if (pp - ++p) { - ret->query = estrndup(p, (pp-p)); - php_replace_controlchars(ret->query); - } - p = pp; - goto label_parse; - } else if (++p - ue) { - ret->query = estrndup(p, (ue-p)); - php_replace_controlchars(ret->query); - } - } else if ((p = strchr(s, '#'))) { - if (p - s) { - ret->path = estrndup(s, (p-s)); - php_replace_controlchars(ret->path); - } - - label_parse: - p++; - - if (ue - p) { - ret->fragment = estrndup(p, (ue-p)); - php_replace_controlchars(ret->fragment); - } - } else { - ret->path = estrndup(s, (ue-s)); - php_replace_controlchars(ret->path); - } - - return ret; -} -/* }}} */ - -/* {{{ proto array parse_url(string url) - Parse a URL and return its components */ -PHP_FUNCTION(parse_url) -{ - char *str; - int str_len; - php_url *resource; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &str_len) == FAILURE) { - return; - } - - resource = php_url_parse(str); - if (resource == NULL) { - php_error_docref1(NULL TSRMLS_CC, str, E_WARNING, "Unable to parse url"); - RETURN_FALSE; - } - - /* allocate an array for return */ - array_init(return_value); - - /* add the various elements to the array */ - if (resource->scheme != NULL) - add_assoc_string(return_value, "scheme", resource->scheme, 1); - if (resource->host != NULL) - add_assoc_string(return_value, "host", resource->host, 1); - if (resource->port != 0) - add_assoc_long(return_value, "port", resource->port); - if (resource->user != NULL) - add_assoc_string(return_value, "user", resource->user, 1); - if (resource->pass != NULL) - add_assoc_string(return_value, "pass", resource->pass, 1); - if (resource->path != NULL) - add_assoc_string(return_value, "path", resource->path, 1); - if (resource->query != NULL) - add_assoc_string(return_value, "query", resource->query, 1); - if (resource->fragment != NULL) - add_assoc_string(return_value, "fragment", resource->fragment, 1); - - php_url_free(resource); -} -/* }}} */ - -/* {{{ php_htoi - */ -static int php_htoi(char *s) -{ - int value; - int c; - - c = s[0]; - if (isupper(c)) - c = tolower(c); - value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; - - c = s[1]; - if (isupper(c)) - c = tolower(c); - value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; - - return (value); -} -/* }}} */ - -/* rfc1738: - - ...The characters ";", - "/", "?", ":", "@", "=" and "&" are the characters which may be - reserved for special meaning within a scheme... - - ...Thus, only alphanumerics, the special characters "$-_.+!*'(),", and - reserved characters used for their reserved purposes may be used - unencoded within a URL... - - For added safety, we only leave -_. unencoded. - */ - -static unsigned char hexchars[] = "0123456789ABCDEF"; - -/* {{{ php_url_encode - */ -PHPAPI char *php_url_encode(char *s, int len, int *new_length) -{ - register int x, y; - unsigned char *str; - - str = (unsigned char *) emalloc(3 * len + 1); - for (x = 0, y = 0; len--; x++, y++) { - str[y] = (unsigned char) s[x]; - if (str[y] == ' ') { - str[y] = '+'; -#ifndef CHARSET_EBCDIC - } else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') || - (str[y] < 'A' && str[y] > '9') || - (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') || - (str[y] > 'z')) { - str[y++] = '%'; - str[y++] = hexchars[(unsigned char) s[x] >> 4]; - str[y] = hexchars[(unsigned char) s[x] & 15]; - } -#else /*CHARSET_EBCDIC*/ - } else if (!isalnum(str[y]) && strchr("_-.", str[y]) == NULL) { - /* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */ - str[y++] = '%'; - str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4]; - str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F]; - } -#endif /*CHARSET_EBCDIC*/ - } - str[y] = '\0'; - if (new_length) { - *new_length = y; - } - return ((char *) str); -} -/* }}} */ - -/* {{{ proto string urlencode(string str) - URL-encodes string */ -PHP_FUNCTION(urlencode) -{ - char *in_str, *out_str; - int in_str_len, out_str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in_str, - &in_str_len) == FAILURE) { - return; - } - - out_str = php_url_encode(in_str, in_str_len, &out_str_len); - RETURN_STRINGL(out_str, out_str_len, 0); -} -/* }}} */ - -/* {{{ proto string urldecode(string str) - Decodes URL-encoded string */ -PHP_FUNCTION(urldecode) -{ - char *in_str, *out_str; - int in_str_len, out_str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in_str, - &in_str_len) == FAILURE) { - return; - } - - out_str = estrndup(in_str, in_str_len); - out_str_len = php_url_decode(out_str, in_str_len); - - RETURN_STRINGL(out_str, out_str_len, 0); -} -/* }}} */ - -/* {{{ php_url_decode - */ -PHPAPI int php_url_decode(char *str, int len) -{ - char *dest = str; - char *data = str; - - while (len--) { - if (*data == '+') - *dest = ' '; - else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { -#ifndef CHARSET_EBCDIC - *dest = (char) php_htoi(data + 1); -#else - *dest = os_toebcdic[(char) php_htoi(data + 1)]; -#endif - data += 2; - len -= 2; - } else - *dest = *data; - data++; - dest++; - } - *dest = '\0'; - return dest - str; -} -/* }}} */ - -/* {{{ php_raw_url_encode - */ -PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length) -{ - register int x, y; - unsigned char *str; - - str = (unsigned char *) emalloc(3 * len + 1); - for (x = 0, y = 0; len--; x++, y++) { - str[y] = (unsigned char) s[x]; -#ifndef CHARSET_EBCDIC - if ((str[y] < '0' && str[y] != '-' && str[y] != '.') || - (str[y] < 'A' && str[y] > '9') || - (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') || - (str[y] > 'z')) { - str[y++] = '%'; - str[y++] = hexchars[(unsigned char) s[x] >> 4]; - str[y] = hexchars[(unsigned char) s[x] & 15]; -#else /*CHARSET_EBCDIC*/ - if (!isalnum(str[y]) && strchr("_-.", str[y]) != NULL) { - str[y++] = '%'; - str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4]; - str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 15]; -#endif /*CHARSET_EBCDIC*/ - } - } - str[y] = '\0'; - if (new_length) { - *new_length = y; - } - return ((char *) str); -} -/* }}} */ - -/* {{{ proto string rawurlencode(string str) - URL-encodes string */ -PHP_FUNCTION(rawurlencode) -{ - char *in_str, *out_str; - int in_str_len, out_str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in_str, - &in_str_len) == FAILURE) { - return; - } - - out_str = php_raw_url_encode(in_str, in_str_len, &out_str_len); - RETURN_STRINGL(out_str, out_str_len, 0); -} -/* }}} */ - -/* {{{ proto string rawurldecode(string str) - Decodes URL-encodes string */ -PHP_FUNCTION(rawurldecode) -{ - char *in_str, *out_str; - int in_str_len, out_str_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &in_str, - &in_str_len) == FAILURE) { - return; - } - - out_str = estrndup(in_str, in_str_len); - out_str_len = php_raw_url_decode(out_str, in_str_len); - - RETURN_STRINGL(out_str, out_str_len, 0); -} -/* }}} */ - -/* {{{ php_raw_url_decode - */ -PHPAPI int php_raw_url_decode(char *str, int len) -{ - char *dest = str; - char *data = str; - - while (len--) { - if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { -#ifndef CHARSET_EBCDIC - *dest = (char) php_htoi(data + 1); -#else - *dest = os_toebcdic[(char) php_htoi(data + 1)]; -#endif - data += 2; - len -= 2; - } else - *dest = *data; - data++; - dest++; - } - *dest = '\0'; - return dest - str; -} -/* }}} */ - -/* {{{ proto array get_headers(string url) - fetches all the headers sent by the server in response to a HTTP request */ -PHP_FUNCTION(get_headers) -{ - char *url, *url_len; - php_stream_context *context = NULL; - php_stream *stream; - zval **prev_val, **hdr = NULL; - HashPosition pos; - long format = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &url, &url_len, &format) == FAILURE) { - return; - } - - if (!(stream = php_stream_open_wrapper_ex(url, "r", REPORT_ERRORS | STREAM_USE_URL | STREAM_ONLY_GET_HEADERS, NULL, context))) { - RETURN_FALSE; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset_ex(HASH_OF(stream->wrapperdata), &pos); - while (zend_hash_get_current_data_ex(HASH_OF(stream->wrapperdata), (void**)&hdr, &pos) != FAILURE) { - if (!format) { -no_name_header: - add_next_index_stringl(return_value, Z_STRVAL_PP(hdr), Z_STRLEN_PP(hdr), 1); - } else { - char c; - char *s, *p; - - if ((p = strchr(Z_STRVAL_PP(hdr), ':'))) { - c = *p; - *p = '\0'; - s = p + 1; - while (isspace(*s)) { - s++; - } - - if (zend_hash_find(HASH_OF(return_value), Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), (void **) &prev_val) == FAILURE) { - add_assoc_stringl_ex(return_value, Z_STRVAL_PP(hdr), (p - Z_STRVAL_PP(hdr) + 1), s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); - } else { /* some headers may occur more then once, therefor we need to remake the string into an array */ - convert_to_array(*prev_val); - add_next_index_stringl(*prev_val, s, (Z_STRLEN_PP(hdr) - (s - Z_STRVAL_PP(hdr))), 1); - } - - *p = c; - } else { - goto no_name_header; - } - } - zend_hash_move_forward_ex(HASH_OF(stream->wrapperdata), &pos); - } - - php_stream_close(stream); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/url.h b/ext/standard/url.h deleted file mode 100644 index 2a3b980be0..0000000000 --- a/ext/standard/url.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef URL_H -#define URL_H - -typedef struct php_url { - char *scheme; - char *user; - char *pass; - char *host; - unsigned short port; - char *path; - char *query; - char *fragment; -} php_url; - -PHPAPI void php_url_free(php_url *theurl); -PHPAPI php_url *php_url_parse(char *str); -PHPAPI int php_url_decode(char *str, int len); /* return value: length of decoded string */ -PHPAPI int php_raw_url_decode(char *str, int len); /* return value: length of decoded string */ -PHPAPI char *php_url_encode(char *s, int len, int *new_length); -PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length); - -PHP_FUNCTION(parse_url); -PHP_FUNCTION(urlencode); -PHP_FUNCTION(urldecode); -PHP_FUNCTION(rawurlencode); -PHP_FUNCTION(rawurldecode); -PHP_FUNCTION(get_headers); - -#endif /* URL_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/url_scanner.c b/ext/standard/url_scanner.c deleted file mode 100644 index 32a59ea7d5..0000000000 --- a/ext/standard/url_scanner.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Hartmut Holzgraefe <hholzgra@php.net> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" - -#include "php_globals.h" - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "basic_functions.h" -#include "url_scanner.h" - -#ifndef BUFSIZE -#define BUFSIZE 256 -#endif - -int php_url_scanner_activate(TSRMLS_D) -{ - url_adapt(NULL,0,NULL,NULL); - return SUCCESS; -} - - -int php_url_scanner_deactivate(TSRMLS_D) -{ - url_adapt(NULL,0,NULL,NULL); - return SUCCESS; -} - -/* {{{ url_attr_addon - */ -static char *url_attr_addon(const char *tag,const char *attr,const char *val,const char *buf) -{ - int flag = 0; - TSRMLS_FETCH(); - - if(!strcasecmp(tag,"a") && !strcasecmp(attr,"href")) { - flag = 1; - } else if(!strcasecmp(tag,"area" ) && !strcasecmp(attr,"href" )) { - flag = 1; - } else if(!strcasecmp(tag,"form" ) && !strcasecmp(attr,"action" )) { - flag = 1; - } else if(!strcasecmp(tag,"frame") && !strcasecmp(attr,"source" )) { - flag = 1; - } else if(!strcasecmp(tag,"img" ) && !strcasecmp(attr,"action" )) { - flag = 1; - } - if(flag) { - if(!strstr(val,buf)&&!strchr(val,':')) - { - char *result = (char *)emalloc(strlen(buf)+strlen(PG(arg_separator).output)+1); - int n; - - if(strchr(val,'?')) { - strcpy(result,PG(arg_separator).output); - n=strlen(PG(arg_separator).output); - } else { - *result='?'; - n=1; - } - strcpy(result+n,buf); - return result; - } - } - return NULL; -} -/* }}} */ - -#define US BG(url_adapt_state) - -/* {{{ url_adapt_ext - */ -char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *val, size_t *newlen) -{ - char buf[1024]; - - snprintf(buf, sizeof(buf)-1, "%s=%s", name, val); - - return url_adapt(src, srclen, buf, newlen); -} -/* }}} */ - -/* {{{ url_adapt - */ -char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen) -{ - char *out,*outp; - int maxl,n; - TSRMLS_FETCH(); - - if(src==NULL) { - US.state=STATE_NORMAL; - if(US.tag) { efree(US.tag); US.tag =NULL; } - if(US.attr) { efree(US.attr); US.attr=NULL; } - if(US.val) { efree(US.val); US.val =NULL; } - return NULL; - } - - if(srclen==0) - srclen=strlen(src); - - out=malloc(srclen+1); - maxl=srclen; - n=srclen; - - *newlen=0; - outp=out; - - while(n--) { - switch(US.state) { - case STATE_NORMAL: - if(*src=='<') - US.state=STATE_TAG_START; - break; - - case STATE_TAG_START: - if(! isalnum(*src)) - US.state=STATE_NORMAL; - US.state=STATE_TAG; - US.ml=BUFSIZE; - US.p=US.tag=erealloc(US.tag,US.ml); - *(US.p)++=*src; - US.l=1; - break; - - case STATE_TAG: - if(isalnum(*src)) { - *(US.p)++ = *src; - US.l++; - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.tag=erealloc(US.tag,US.ml); - US.p = US.tag+US.l; - } - } else if (isspace(*src)) { - US.state = STATE_IN_TAG; - *US.p='\0'; - US.tag=erealloc(US.tag,US.l); - } else { - US.state = STATE_NORMAL; - efree(US.tag); - US.tag=NULL; - } - break; - - case STATE_IN_TAG: - if(isalnum(*src)) { - US.state=STATE_TAG_ATTR; - US.ml=BUFSIZE; - US.p=US.attr=erealloc(US.attr,US.ml); - *(US.p)++=*src; - US.l=1; - } else if (! isspace(*src)) { - US.state = STATE_NORMAL; - efree(US.tag); - US.tag=NULL; - } - break; - - case STATE_TAG_ATTR: - if(isalnum(*src)) { - *US.p++=*src; - ++US.l; - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.attr=erealloc(US.attr,US.ml); - US.p = US.attr+US.l; - } - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.attr=erealloc(US.attr,US.ml); - US.p = US.attr+US.l; - } - } else if(isspace(*src)||(*src=='=')){ - US.state=STATE_TAG_IS; - *US.p=0; - US.attr=erealloc(US.attr,US.l); - } else if(*src=='>') { - US.state=STATE_NORMAL; - } else { - efree(US.attr); - US.attr=NULL; - US.state=STATE_IN_TAG; - } - break; - - case STATE_TAG_IS: - case STATE_TAG_IS2: - if(*src=='>'){ - US.state=STATE_NORMAL; - if(! (US.attr_done)) { - char *p; - p=url_attr_addon(US.tag,US.attr,"",data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - } else if(*src=='#') { - if(! (US.attr_done)) { - char *p; - US.attr_done=1; - p=url_attr_addon(US.tag,US.attr,"#",data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - } else if(!isspace(*src)&&(*src!='=')) { - US.ml=BUFSIZE; - US.p=US.val=erealloc(US.val,US.ml); - US.l=0; - US.attr_done=0; - if((*src=='"')||(*src=='\'')) { - US.state=STATE_TAG_QVAL2; - US.delim=*src; - } else { - US.state=STATE_TAG_VAL; - *US.p++=*src; - US.l++; - } - } - break; - - - case STATE_TAG_QVAL2: - if(*src=='#') { - if(! (US.attr_done)) { - char *p; - US.attr_done=1; - *US.p='\0'; - p=url_attr_addon(US.tag,US.attr,US.val,data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - } else if(*src==US.delim) { - US.state=STATE_IN_TAG; - *US.p='\0'; - if(! (US.attr_done)) { - char *p; - p=url_attr_addon(US.tag,US.attr,US.val,data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - break; - } else if(*src=='\\') { - US.state=STATE_TAG_QVAL2b; - } else if (*src=='>') { - US.state=STATE_NORMAL; - } - - *US.p++=*src; - ++US.l; - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.val=erealloc(US.val,US.ml); - US.p = US.val+US.l; - } - - break; - - case STATE_TAG_QVAL2b: - US.state=STATE_TAG_QVAL2; - *US.p++=*src; - ++US.l; - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.val=erealloc(US.val,US.ml); - US.p = US.val+US.l; - } - break; - - case STATE_TAG_VAL: - case STATE_TAG_VAL2: - if(*src=='#') { - if(! (US.attr_done)) { - char *p; - US.attr_done=1; - *US.p='\0'; - p=url_attr_addon(US.tag,US.attr,US.val,data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - } else if(isspace(*src)||(*src=='>')) { - US.state=(*src=='>')?STATE_NORMAL:STATE_IN_TAG; - *US.p='\0'; - if(! (US.attr_done)) { - char *p; - p=url_attr_addon(US.tag,US.attr,US.val,data); - if(p) { - int l= strlen(p); - maxl+=l; - out=realloc(out,maxl); - outp=out+*newlen; - strcpy(outp,p); - outp+=l; - *newlen+=l; - efree(p); - } - } - } else { - *US.p++=*src; - US.l++; - if(US.l==US.ml) { - US.ml+=BUFSIZE; - US.val=erealloc(US.val,US.ml); - US.p = US.val+US.l; - } - } - break; - default: - break; - } - - *outp++=*src++; - *newlen+=1; - } - *outp='\0'; - return out; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/url_scanner.h b/ext/standard/url_scanner.h deleted file mode 100644 index daf78a0778..0000000000 --- a/ext/standard/url_scanner.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef URI_SCANNER_H -#define URI_SCANNER_H - -int php_url_scanner_activate(TSRMLS_D); -int php_url_scanner_deactivate(TSRMLS_D); - -char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen); - -enum url_state { - STATE_NORMAL, - STATE_TAG_START, - STATE_TAG, - STATE_IN_TAG, - STATE_TAG_ATTR, - STATE_TAG_IS, - STATE_TAG_IS2, - STATE_TAG_VAL, - STATE_TAG_VAL2, - STATE_TAG_QVAL1, - STATE_TAG_QVAL2, - STATE_TAG_QVAL2b -}; - -typedef struct url_adapt_struct { - enum url_state state; - char *tag; - char *attr; - char *val; - char delim; - char *p; - int l, ml; - int attr_done; -} url_adapt_state_t; - -#endif diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c deleted file mode 100644 index c03597c70f..0000000000 --- a/ext/standard/url_scanner_ex.c +++ /dev/null @@ -1,1008 +0,0 @@ -/* Generated by re2c 0.5 on Wed Feb 12 09:54:41 2003 */ -#line 1 "/home/rei/PHP_CVS/php5/ext/standard/url_scanner_ex.re" -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "php_ini.h" -#include "php_globals.h" -#define STATE_TAG SOME_OTHER_STATE_TAG -#include "basic_functions.h" -#include "url.h" -#undef STATE_TAG - -#define url_scanner url_scanner_ex - -#include "php_smart_str.h" - -static PHP_INI_MH(OnUpdateTags) -{ - url_adapt_state_ex_t *ctx; - char *key; - char *lasts; - char *tmp; - - ctx = &BG(url_adapt_state_ex); - - tmp = estrndup(new_value, new_value_length); - - if (ctx->tags) - zend_hash_destroy(ctx->tags); - else - ctx->tags = malloc(sizeof(HashTable)); - - zend_hash_init(ctx->tags, 0, NULL, NULL, 1); - - for (key = php_strtok_r(tmp, ",", &lasts); - key; - key = php_strtok_r(NULL, ",", &lasts)) { - char *val; - - val = strchr(key, '='); - if (val) { - char *q; - int keylen; - - *val++ = '\0'; - for (q = key; *q; q++) - *q = tolower(*q); - keylen = q - key; - /* key is stored withOUT NUL - val is stored WITH NUL */ - zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL); - } - } - - efree(tmp); - - return SUCCESS; -} - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=,fieldset=", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals) -PHP_INI_END() - -#line 92 - - -#define YYFILL(n) goto done -#define YYCTYPE unsigned char -#define YYCURSOR p -#define YYLIMIT q -#define YYMARKER r - -static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) -{ - register const char *p, *q; - const char *bash = NULL; - const char *sep = "?"; - - q = (p = url->c) + url->len; - -scan: -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 0, 128, 128, 128, 128, 0, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - }; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yybm[0+yych] & 128) goto yy8; - if(yych <= '9') goto yy6; - if(yych >= ';') goto yy4; -yy2: yych = *++YYCURSOR; -yy3: -#line 110 - { smart_str_append(dest, url); return; } -yy4: yych = *++YYCURSOR; -yy5: -#line 111 - { sep = separator; goto scan; } -yy6: yych = *++YYCURSOR; -yy7: -#line 112 - { bash = p - 1; goto done; } -yy8: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy9: if(yybm[0+yych] & 128) goto yy8; -yy10: -#line 113 - { goto scan; } -} -#line 114 - -done: - - /* Don't modify URLs of the format "#mark" */ - if (bash && bash - url->c == 0) { - smart_str_append(dest, url); - return; - } - - if (bash) - smart_str_appendl(dest, url->c, bash - url->c); - else - smart_str_append(dest, url); - - smart_str_appends(dest, sep); - smart_str_append(dest, url_app); - - if (bash) - smart_str_appendl(dest, bash, q - bash); -} - - -#undef YYFILL -#undef YYCTYPE -#undef YYCURSOR -#undef YYLIMIT -#undef YYMARKER - -static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSRMLS_DC) -{ - char f = 0; - - if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0) - f = 1; - - if (quotes) - smart_str_appendc(&ctx->result, type); - if (f) { - append_modified_url(&ctx->val, &ctx->result, &ctx->url_app, PG(arg_separator).output); - } else { - smart_str_append(&ctx->result, &ctx->val); - } - if (quotes) - smart_str_appendc(&ctx->result, type); -} - -enum { - STATE_PLAIN = 0, - STATE_TAG, - STATE_NEXT_ARG, - STATE_ARG, - STATE_BEFORE_VAL, - STATE_VAL -}; - -#define YYFILL(n) goto stop -#define YYCTYPE unsigned char -#define YYCURSOR xp -#define YYLIMIT end -#define YYMARKER q -#define STATE ctx->state - -#define STD_PARA url_adapt_state_ex_t *ctx, char *start, char *YYCURSOR TSRMLS_DC -#define STD_ARGS ctx, start, xp TSRMLS_CC - -#if SCANNER_DEBUG -#define scdebug(x) printf x -#else -#define scdebug(x) -#endif - -static inline void passthru(STD_PARA) -{ - scdebug(("appending %d chars, starting with %c\n", YYCURSOR-start, *start)); - smart_str_appendl(&ctx->result, start, YYCURSOR - start); -} - -/* - * This function appends a hidden input field after a <form> or - * <fieldset>. The latter is important for XHTML. - */ - -static void handle_form(STD_PARA) -{ - int doit = 0; - - if (ctx->form_app.len > 0) { - switch (ctx->tag.len) { - -#define RECOGNIZE(x) do { \ - case sizeof(x)-1: \ - if (strncasecmp(ctx->tag.c, x, sizeof(x)-1) == 0) \ - doit = 1; \ - break; \ -} while (0) - - RECOGNIZE("form"); - RECOGNIZE("fieldset"); - } - - if (doit) - smart_str_append(&ctx->result, &ctx->form_app); - } -} - - - -/* - * HANDLE_TAG copies the HTML Tag and checks whether we - * have that tag in our table. If we might modify it, - * we continue to scan the tag, otherwise we simply copy the complete - * HTML stuff to the result buffer. - */ - -static inline void handle_tag(STD_PARA) -{ - int ok = 0; - int i; - - ctx->tag.len = 0; - smart_str_appendl(&ctx->tag, start, YYCURSOR - start); - for (i = 0; i < ctx->tag.len; i++) - ctx->tag.c[i] = tolower(ctx->tag.c[i]); - if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS) - ok = 1; - STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; -} - -static inline void handle_arg(STD_PARA) -{ - ctx->arg.len = 0; - smart_str_appendl(&ctx->arg, start, YYCURSOR - start); -} - -static inline void handle_val(STD_PARA, char quotes, char type) -{ - smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2); - tag_arg(ctx, quotes, type TSRMLS_CC); -} - -static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size_t newlen TSRMLS_DC) -{ - char *end, *q; - char *xp; - char *start; - int rest; - - smart_str_appendl(&ctx->buf, newdata, newlen); - - YYCURSOR = ctx->buf.c; - YYLIMIT = ctx->buf.c + ctx->buf.len; - - switch (STATE) { - case STATE_PLAIN: goto state_plain; - case STATE_TAG: goto state_tag; - case STATE_NEXT_ARG: goto state_next_arg; - case STATE_ARG: goto state_arg; - case STATE_BEFORE_VAL: goto state_before_val; - case STATE_VAL: goto state_val; - } - - -state_plain_begin: - STATE = STATE_PLAIN; - -state_plain: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 0, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - }; - goto yy11; -yy12: ++YYCURSOR; -yy11: - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if(yybm[0+yych] & 128) goto yy15; -yy13: yych = *++YYCURSOR; -yy14: -#line 282 - { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } -yy15: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy16: if(yybm[0+yych] & 128) goto yy15; -yy17: -#line 283 - { passthru(STD_ARGS); goto state_plain; } -} -#line 284 - - -state_tag: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - goto yy18; -yy19: ++YYCURSOR; -yy18: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '@') goto yy22; - if(yych <= 'Z') goto yy20; - if(yych <= '`') goto yy22; - if(yych >= '{') goto yy22; -yy20: yych = *++YYCURSOR; - goto yy25; -yy21: -#line 289 - { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } -yy22: yych = *++YYCURSOR; -yy23: -#line 290 - { passthru(STD_ARGS); goto state_plain_begin; } -yy24: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy25: if(yybm[0+yych] & 128) goto yy24; - goto yy21; -} -#line 291 - - -state_next_arg_begin: - STATE = STATE_NEXT_ARG; - -state_next_arg: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - goto yy26; -yy27: ++YYCURSOR; -yy26: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '='){ - if(yych <= '\v'){ - if(yych <= '\b') goto yy34; - goto yy30; - } else { - if(yych == ' ') goto yy30; - goto yy34; - } - } else { - if(yych <= 'Z'){ - if(yych <= '>') goto yy28; - if(yych <= '@') goto yy34; - goto yy32; - } else { - if(yych <= '`') goto yy34; - if(yych <= 'z') goto yy32; - goto yy34; - } - } -yy28: yych = *++YYCURSOR; -yy29: -#line 299 - { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } -yy30: yych = *++YYCURSOR; - goto yy37; -yy31: -#line 300 - { passthru(STD_ARGS); goto state_next_arg; } -yy32: yych = *++YYCURSOR; -yy33: -#line 301 - { --YYCURSOR; STATE = STATE_ARG; goto state_arg; } -yy34: yych = *++YYCURSOR; -yy35: -#line 302 - { passthru(STD_ARGS); goto state_plain_begin; } -yy36: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy37: if(yybm[0+yych] & 128) goto yy36; - goto yy31; -} -#line 303 - - -state_arg: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 128, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - goto yy38; -yy39: ++YYCURSOR; -yy38: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych <= '@') goto yy42; - if(yych <= 'Z') goto yy40; - if(yych <= '`') goto yy42; - if(yych >= '{') goto yy42; -yy40: yych = *++YYCURSOR; - goto yy45; -yy41: -#line 308 - { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } -yy42: yych = *++YYCURSOR; -yy43: -#line 309 - { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; } -yy44: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy45: if(yybm[0+yych] & 128) goto yy44; - goto yy41; -} -#line 310 - - -state_before_val: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - goto yy46; -yy47: ++YYCURSOR; -yy46: - if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if(yych == ' ') goto yy48; - if(yych == '=') goto yy50; - goto yy52; -yy48: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ' ') goto yy55; - if(yych == '=') goto yy53; -yy49: -#line 316 - { --YYCURSOR; goto state_next_arg_begin; } -yy50: yych = *++YYCURSOR; - goto yy54; -yy51: -#line 315 - { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } -yy52: yych = *++YYCURSOR; - goto yy49; -yy53: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy54: if(yybm[0+yych] & 128) goto yy53; - goto yy51; -yy55: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy56: if(yych == ' ') goto yy55; - if(yych == '=') goto yy53; -yy57: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy49; - } -} -#line 317 - - - -state_val: - start = YYCURSOR; -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 160, 160, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 160, 248, 56, 248, 248, 248, 248, 200, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 0, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - 248, 248, 248, 248, 248, 248, 248, 248, - }; - goto yy58; -yy59: ++YYCURSOR; -yy58: - if((YYLIMIT - YYCURSOR) < 3) YYFILL(3); - yych = *YYCURSOR; - if(yych <= '!'){ - if(yych <= '\n'){ - if(yych <= '\b') goto yy63; - goto yy64; - } else { - if(yych == ' ') goto yy64; - goto yy63; - } - } else { - if(yych <= '\''){ - if(yych <= '"') goto yy60; - if(yych <= '&') goto yy63; - goto yy62; - } else { - if(yych == '>') goto yy64; - goto yy63; - } - } -yy60: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - goto yy77; -yy61: -#line 325 - { handle_val(STD_ARGS, 0, '\0'); goto state_next_arg_begin; } -yy62: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - goto yy69; -yy63: yych = *++YYCURSOR; - goto yy67; -yy64: yych = *++YYCURSOR; -yy65: -#line 326 - { passthru(STD_ARGS); goto state_next_arg_begin; } -yy66: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy67: if(yybm[0+yych] & 8) goto yy66; - goto yy61; -yy68: yyaccept = 0; - YYMARKER = ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy69: if(yybm[0+yych] & 16) goto yy68; - if(yych <= '&') goto yy72; - if(yych >= '(') goto yy61; -yy70: yych = *++YYCURSOR; - if(yybm[0+yych] & 8) goto yy66; -yy71: -#line 324 - { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } -yy72: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy73: if(yybm[0+yych] & 32) goto yy72; - if(yych <= '=') goto yy75; -yy74: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy61; - } -yy75: yych = *++YYCURSOR; - goto yy71; -yy76: yyaccept = 0; - YYMARKER = ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy77: if(yybm[0+yych] & 64) goto yy76; - if(yych <= '!') goto yy80; - if(yych >= '#') goto yy61; -yy78: yych = *++YYCURSOR; - if(yybm[0+yych] & 8) goto yy66; -yy79: -#line 323 - { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } -yy80: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy81: if(yybm[0+yych] & 128) goto yy80; - if(yych >= '>') goto yy74; -yy82: yych = *++YYCURSOR; - goto yy79; -} -#line 327 - - -stop: - rest = YYLIMIT - start; - scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); - /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ - if (rest < 0) rest = 0; - - if (rest) memmove(ctx->buf.c, start, rest); - ctx->buf.len = rest; -} - -char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC) -{ - smart_str surl = {0}; - smart_str buf = {0}; - smart_str url_app = {0}; - - smart_str_setl(&surl, url, urllen); - - smart_str_appends(&url_app, name); - smart_str_appendc(&url_app, '='); - smart_str_appends(&url_app, value); - - append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output); - - smart_str_0(&buf); - if (newlen) *newlen = buf.len; - - smart_str_free(&url_app); - - return buf.c; -} - - -static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_bool do_flush TSRMLS_DC) -{ - url_adapt_state_ex_t *ctx; - char *retval; - - ctx = &BG(url_adapt_state_ex); - - xx_mainloop(ctx, src, srclen TSRMLS_CC); - - *newlen = ctx->result.len; - if (!ctx->result.c) { - smart_str_appendl(&ctx->result, "", 0); - } - smart_str_0(&ctx->result); - if (do_flush) { - smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len); - *newlen += ctx->buf.len; - smart_str_free(&ctx->buf); - } - retval = ctx->result.c; - ctx->result.c = NULL; - ctx->result.len = 0; - return retval; -} - -int php_url_scanner_ex_activate(TSRMLS_D) -{ - url_adapt_state_ex_t *ctx; - - ctx = &BG(url_adapt_state_ex); - - memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags)); - - return SUCCESS; -} - -int php_url_scanner_ex_deactivate(TSRMLS_D) -{ - url_adapt_state_ex_t *ctx; - - ctx = &BG(url_adapt_state_ex); - - smart_str_free(&ctx->result); - smart_str_free(&ctx->buf); - smart_str_free(&ctx->tag); - smart_str_free(&ctx->arg); - - return SUCCESS; -} - -static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) -{ - if (BG(url_adapt_state_ex).url_app.len != 0) { - *handled_output = url_adapt_ext(output, output_len, handled_output_len, (zend_bool) (mode&PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); - } else { - *handled_output = NULL; - } -} - -int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC) -{ - char *encoded; - int encoded_len; - smart_str val; - - if (! BG(url_adapt_state_ex).active) { - php_url_scanner_ex_activate(TSRMLS_C); - php_ob_set_internal_handler(php_url_scanner_output_handler, 0, "URL-Rewriter", 1 TSRMLS_CC); - BG(url_adapt_state_ex).active = 1; - } - - - if (BG(url_adapt_state_ex).url_app.len != 0) { - smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output); - } - - if (urlencode) { - encoded = php_url_encode(value, value_len, &encoded_len); - smart_str_setl(&val, encoded, encoded_len); - } else { - smart_str_setl(&val, value, value_len); - } - - smart_str_appendl(&BG(url_adapt_state_ex).url_app, name, name_len); - smart_str_appendc(&BG(url_adapt_state_ex).url_app, '='); - smart_str_append(&BG(url_adapt_state_ex).url_app, &val); - - smart_str_appends(&BG(url_adapt_state_ex).form_app, "<input type=\"hidden\" name=\""); - smart_str_appendl(&BG(url_adapt_state_ex).form_app, name, name_len); - smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" value=\""); - smart_str_append(&BG(url_adapt_state_ex).form_app, &val); - smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />"); - - if (urlencode) - efree(encoded); - - return SUCCESS; -} - -int php_url_scanner_reset_vars(TSRMLS_D) -{ - BG(url_adapt_state_ex).form_app.len = 0; - BG(url_adapt_state_ex).url_app.len = 0; - - return FAILURE; -} - -PHP_MINIT_FUNCTION(url_scanner) -{ - BG(url_adapt_state_ex).tags = NULL; - - BG(url_adapt_state_ex).form_app.c = BG(url_adapt_state_ex).url_app.c = 0; - BG(url_adapt_state_ex).form_app.len = BG(url_adapt_state_ex).url_app.len = 0; - - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(url_scanner) -{ - UNREGISTER_INI_ENTRIES(); - zend_hash_destroy(BG(url_adapt_state_ex).tags); - free(BG(url_adapt_state_ex).tags); - - return SUCCESS; -} - -PHP_RINIT_FUNCTION(url_scanner) -{ - BG(url_adapt_state_ex).active = 0; - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(url_scanner) -{ - if (BG(url_adapt_state_ex).active) { - php_url_scanner_ex_deactivate(TSRMLS_C); - BG(url_adapt_state_ex).active = 0; - } - - smart_str_free(&BG(url_adapt_state_ex).form_app); - smart_str_free(&BG(url_adapt_state_ex).url_app); - - return SUCCESS; -} diff --git a/ext/standard/url_scanner_ex.h b/ext/standard/url_scanner_ex.h deleted file mode 100644 index e35743baf3..0000000000 --- a/ext/standard/url_scanner_ex.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#ifndef URL_SCANNER_EX_H -#define URL_SCANNER_EX_H - -PHP_MINIT_FUNCTION(url_scanner_ex); -PHP_MSHUTDOWN_FUNCTION(url_scanner_ex); - -PHP_RINIT_FUNCTION(url_scanner_ex); -PHP_RSHUTDOWN_FUNCTION(url_scanner_ex); - -char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC); - -int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC); -int php_url_scanner_reset_vars(TSRMLS_D); - -int php_url_scanner_ex_activate(TSRMLS_D); -int php_url_scanner_ex_deactivate(TSRMLS_D); - -#include "php_smart_str_public.h" - -typedef struct { - /* Used by the mainloop of the scanner */ - smart_str tag; /* read only */ - smart_str arg; /* read only */ - smart_str val; /* read only */ - smart_str buf; - - /* The result buffer */ - smart_str result; - - /* The data which is appended to each relative URL/FORM */ - smart_str form_app, url_app; - - int active; - - char *lookup_data; - int state; - - /* Everything above is zeroed in RINIT */ - HashTable *tags; -} url_adapt_state_ex_t; - -typedef struct { - smart_str var; - smart_str val; -} url_adapt_var_t; - -#endif diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re deleted file mode 100644 index f3c638863e..0000000000 --- a/ext/standard/url_scanner_ex.re +++ /dev/null @@ -1,507 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include "php_ini.h" -#include "php_globals.h" -#define STATE_TAG SOME_OTHER_STATE_TAG -#include "basic_functions.h" -#include "url.h" -#undef STATE_TAG - -#define url_scanner url_scanner_ex - -#include "php_smart_str.h" - -static PHP_INI_MH(OnUpdateTags) -{ - url_adapt_state_ex_t *ctx; - char *key; - char *lasts; - char *tmp; - - ctx = &BG(url_adapt_state_ex); - - tmp = estrndup(new_value, new_value_length); - - if (ctx->tags) - zend_hash_destroy(ctx->tags); - else - ctx->tags = malloc(sizeof(HashTable)); - - zend_hash_init(ctx->tags, 0, NULL, NULL, 1); - - for (key = php_strtok_r(tmp, ",", &lasts); - key; - key = php_strtok_r(NULL, ",", &lasts)) { - char *val; - - val = strchr(key, '='); - if (val) { - char *q; - int keylen; - - *val++ = '\0'; - for (q = key; *q; q++) - *q = tolower(*q); - keylen = q - key; - /* key is stored withOUT NUL - val is stored WITH NUL */ - zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL); - } - } - - efree(tmp); - - return SUCCESS; -} - -PHP_INI_BEGIN() - STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=,fieldset=", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals) -PHP_INI_END() - -/*!re2c -any = [\000-\377]; -N = (any\[<]); -alpha = [a-zA-Z]; -alphadash = ([a-zA-Z] | "-"); -*/ - -#define YYFILL(n) goto done -#define YYCTYPE unsigned char -#define YYCURSOR p -#define YYLIMIT q -#define YYMARKER r - -static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator) -{ - register const char *p, *q; - const char *bash = NULL; - const char *sep = "?"; - - q = (p = url->c) + url->len; - -scan: -/*!re2c - ":" { smart_str_append(dest, url); return; } - "?" { sep = separator; goto scan; } - "#" { bash = p - 1; goto done; } - (any\[:?#])+ { goto scan; } -*/ -done: - - /* Don't modify URLs of the format "#mark" */ - if (bash && bash - url->c == 0) { - smart_str_append(dest, url); - return; - } - - if (bash) - smart_str_appendl(dest, url->c, bash - url->c); - else - smart_str_append(dest, url); - - smart_str_appends(dest, sep); - smart_str_append(dest, url_app); - - if (bash) - smart_str_appendl(dest, bash, q - bash); -} - - -#undef YYFILL -#undef YYCTYPE -#undef YYCURSOR -#undef YYLIMIT -#undef YYMARKER - -static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSRMLS_DC) -{ - char f = 0; - - if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0) - f = 1; - - if (quotes) - smart_str_appendc(&ctx->result, type); - if (f) { - append_modified_url(&ctx->val, &ctx->result, &ctx->url_app, PG(arg_separator).output); - } else { - smart_str_append(&ctx->result, &ctx->val); - } - if (quotes) - smart_str_appendc(&ctx->result, type); -} - -enum { - STATE_PLAIN = 0, - STATE_TAG, - STATE_NEXT_ARG, - STATE_ARG, - STATE_BEFORE_VAL, - STATE_VAL -}; - -#define YYFILL(n) goto stop -#define YYCTYPE unsigned char -#define YYCURSOR xp -#define YYLIMIT end -#define YYMARKER q -#define STATE ctx->state - -#define STD_PARA url_adapt_state_ex_t *ctx, char *start, char *YYCURSOR TSRMLS_DC -#define STD_ARGS ctx, start, xp TSRMLS_CC - -#if SCANNER_DEBUG -#define scdebug(x) printf x -#else -#define scdebug(x) -#endif - -static inline void passthru(STD_PARA) -{ - scdebug(("appending %d chars, starting with %c\n", YYCURSOR-start, *start)); - smart_str_appendl(&ctx->result, start, YYCURSOR - start); -} - -/* - * This function appends a hidden input field after a <form> or - * <fieldset>. The latter is important for XHTML. - */ - -static void handle_form(STD_PARA) -{ - int doit = 0; - - if (ctx->form_app.len > 0) { - switch (ctx->tag.len) { - -#define RECOGNIZE(x) do { \ - case sizeof(x)-1: \ - if (strncasecmp(ctx->tag.c, x, sizeof(x)-1) == 0) \ - doit = 1; \ - break; \ -} while (0) - - RECOGNIZE("form"); - RECOGNIZE("fieldset"); - } - - if (doit) - smart_str_append(&ctx->result, &ctx->form_app); - } -} - - - -/* - * HANDLE_TAG copies the HTML Tag and checks whether we - * have that tag in our table. If we might modify it, - * we continue to scan the tag, otherwise we simply copy the complete - * HTML stuff to the result buffer. - */ - -static inline void handle_tag(STD_PARA) -{ - int ok = 0; - int i; - - ctx->tag.len = 0; - smart_str_appendl(&ctx->tag, start, YYCURSOR - start); - for (i = 0; i < ctx->tag.len; i++) - ctx->tag.c[i] = tolower(ctx->tag.c[i]); - if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS) - ok = 1; - STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; -} - -static inline void handle_arg(STD_PARA) -{ - ctx->arg.len = 0; - smart_str_appendl(&ctx->arg, start, YYCURSOR - start); -} - -static inline void handle_val(STD_PARA, char quotes, char type) -{ - smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2); - tag_arg(ctx, quotes, type TSRMLS_CC); -} - -static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size_t newlen TSRMLS_DC) -{ - char *end, *q; - char *xp; - char *start; - int rest; - - smart_str_appendl(&ctx->buf, newdata, newlen); - - YYCURSOR = ctx->buf.c; - YYLIMIT = ctx->buf.c + ctx->buf.len; - - switch (STATE) { - case STATE_PLAIN: goto state_plain; - case STATE_TAG: goto state_tag; - case STATE_NEXT_ARG: goto state_next_arg; - case STATE_ARG: goto state_arg; - case STATE_BEFORE_VAL: goto state_before_val; - case STATE_VAL: goto state_val; - } - - -state_plain_begin: - STATE = STATE_PLAIN; - -state_plain: - start = YYCURSOR; -/*!re2c - "<" { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; } - N+ { passthru(STD_ARGS); goto state_plain; } -*/ - -state_tag: - start = YYCURSOR; -/*!re2c - alpha+ { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; } - any { passthru(STD_ARGS); goto state_plain_begin; } -*/ - -state_next_arg_begin: - STATE = STATE_NEXT_ARG; - -state_next_arg: - start = YYCURSOR; -/*!re2c - ">" { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; } - [ \v\t\n]+ { passthru(STD_ARGS); goto state_next_arg; } - alpha { --YYCURSOR; STATE = STATE_ARG; goto state_arg; } - any { passthru(STD_ARGS); goto state_plain_begin; } -*/ - -state_arg: - start = YYCURSOR; -/*!re2c - alpha alphadash* { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; } - any { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; } -*/ - -state_before_val: - start = YYCURSOR; -/*!re2c - [ ]* "=" [ ]* { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; } - any { --YYCURSOR; goto state_next_arg_begin; } -*/ - - -state_val: - start = YYCURSOR; -/*!re2c - ["] (any\[">])* ["] { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; } - ['] (any\['>])* ['] { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; } - (any\[ \t\n>])+ { handle_val(STD_ARGS, 0, '\0'); goto state_next_arg_begin; } - any { passthru(STD_ARGS); goto state_next_arg_begin; } -*/ - -stop: - rest = YYLIMIT - start; - scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); - /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ - if (rest < 0) rest = 0; - - if (rest) memmove(ctx->buf.c, start, rest); - ctx->buf.len = rest; -} - -char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC) -{ - smart_str surl = {0}; - smart_str buf = {0}; - smart_str url_app = {0}; - - smart_str_setl(&surl, url, urllen); - - smart_str_appends(&url_app, name); - smart_str_appendc(&url_app, '='); - smart_str_appends(&url_app, value); - - append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output); - - smart_str_0(&buf); - if (newlen) *newlen = buf.len; - - smart_str_free(&url_app); - - return buf.c; -} - - -static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_bool do_flush TSRMLS_DC) -{ - url_adapt_state_ex_t *ctx; - char *retval; - - ctx = &BG(url_adapt_state_ex); - - xx_mainloop(ctx, src, srclen TSRMLS_CC); - - *newlen = ctx->result.len; - if (!ctx->result.c) { - smart_str_appendl(&ctx->result, "", 0); - } - smart_str_0(&ctx->result); - if (do_flush) { - smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len); - *newlen += ctx->buf.len; - smart_str_free(&ctx->buf); - } - retval = ctx->result.c; - ctx->result.c = NULL; - ctx->result.len = 0; - return retval; -} - -int php_url_scanner_ex_activate(TSRMLS_D) -{ - url_adapt_state_ex_t *ctx; - - ctx = &BG(url_adapt_state_ex); - - memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags)); - - return SUCCESS; -} - -int php_url_scanner_ex_deactivate(TSRMLS_D) -{ - url_adapt_state_ex_t *ctx; - - ctx = &BG(url_adapt_state_ex); - - smart_str_free(&ctx->result); - smart_str_free(&ctx->buf); - smart_str_free(&ctx->tag); - smart_str_free(&ctx->arg); - - return SUCCESS; -} - -static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) -{ - if (BG(url_adapt_state_ex).url_app.len != 0) { - *handled_output = url_adapt_ext(output, output_len, handled_output_len, (zend_bool) (mode&PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); - } else { - *handled_output = NULL; - } -} - -int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC) -{ - char *encoded; - int encoded_len; - smart_str val; - - if (! BG(url_adapt_state_ex).active) { - php_url_scanner_ex_activate(TSRMLS_C); - php_ob_set_internal_handler(php_url_scanner_output_handler, 0, "URL-Rewriter", 1 TSRMLS_CC); - BG(url_adapt_state_ex).active = 1; - } - - - if (BG(url_adapt_state_ex).url_app.len != 0) { - smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output); - } - - if (urlencode) { - encoded = php_url_encode(value, value_len, &encoded_len); - smart_str_setl(&val, encoded, encoded_len); - } else { - smart_str_setl(&val, value, value_len); - } - - smart_str_appendl(&BG(url_adapt_state_ex).url_app, name, name_len); - smart_str_appendc(&BG(url_adapt_state_ex).url_app, '='); - smart_str_append(&BG(url_adapt_state_ex).url_app, &val); - - smart_str_appends(&BG(url_adapt_state_ex).form_app, "<input type=\"hidden\" name=\""); - smart_str_appendl(&BG(url_adapt_state_ex).form_app, name, name_len); - smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" value=\""); - smart_str_append(&BG(url_adapt_state_ex).form_app, &val); - smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />"); - - if (urlencode) - efree(encoded); - - return SUCCESS; -} - -int php_url_scanner_reset_vars(TSRMLS_D) -{ - BG(url_adapt_state_ex).form_app.len = 0; - BG(url_adapt_state_ex).url_app.len = 0; - - return FAILURE; -} - -PHP_MINIT_FUNCTION(url_scanner) -{ - BG(url_adapt_state_ex).tags = NULL; - - BG(url_adapt_state_ex).form_app.c = BG(url_adapt_state_ex).url_app.c = 0; - BG(url_adapt_state_ex).form_app.len = BG(url_adapt_state_ex).url_app.len = 0; - - REGISTER_INI_ENTRIES(); - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(url_scanner) -{ - UNREGISTER_INI_ENTRIES(); - zend_hash_destroy(BG(url_adapt_state_ex).tags); - free(BG(url_adapt_state_ex).tags); - - return SUCCESS; -} - -PHP_RINIT_FUNCTION(url_scanner) -{ - BG(url_adapt_state_ex).active = 0; - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(url_scanner) -{ - if (BG(url_adapt_state_ex).active) { - php_url_scanner_ex_deactivate(TSRMLS_C); - BG(url_adapt_state_ex).active = 0; - } - - smart_str_free(&BG(url_adapt_state_ex).form_app); - smart_str_free(&BG(url_adapt_state_ex).url_app); - - return SUCCESS; -} diff --git a/ext/standard/user_filters.c b/ext/standard/user_filters.c deleted file mode 100644 index db9f650565..0000000000 --- a/ext/standard/user_filters.c +++ /dev/null @@ -1,511 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: | - | Wez Furlong (wez@thebrainroom.com) | - | Sara Golemon (pollita@php.net) | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* - * TODO: Rewrite for buckets. - * Concept: - * The user defined filter class should implement a method named - * "filter" with the following proto: - * long filter(object brigade_in, object brigade_out, long &consumed, long flags); - * - * brigade_in and brigade_out are overloaded objects that wrap around - * the php_stream_bucket_brigades passed to the underlying filter method. - * The brigades have methods for retrieving the head of the brigade as - * an overloaded bucket object, a method for appending a - * bucket object to the end of the brigade, and a method for creating a new - * bucket at the end of the brigade. - * - * The bucket object has methods to unlink it from it's containing brigade, - * split into two buckets, and retrieve the buffer from a bucket. - * - * This approach means that there doesn't need to be very much magic between - * userspace and the real C interface. - */ - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/basic_functions.h" -#include "ext/standard/file.h" - -#define PHP_STREAM_BRIGADE_RES_NAME "userfilter.bucket brigade" -#define PHP_STREAM_BUCKET_RES_NAME "userfilter.bucket" -#define PHP_STREAM_FILTER_RES_NAME "userfilter.filter" -#define PHP_STREAM_RES_NAME "userfilter.stream" - -struct php_user_filter_data { - zend_class_entry *ce; - /* variable length; this *must* be last in the structure */ - char classname[1]; -}; - -/* to provide context for calling into the next filter from user-space */ -static int le_userfilters; -static int le_bucket_brigade; -static int le_bucket; -static int le_stream; - -#define GET_FILTER_FROM_OBJ() { \ - zval **tmp; \ - if (FAILURE == zend_hash_index_find(Z_OBJPROP_P(this_ptr), 0, (void**)&tmp)) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "filter property vanished"); \ - RETURN_FALSE; \ - } \ - ZEND_FETCH_RESOURCE(filter, php_stream_filter*, tmp, -1, "filter", le_userfilters); \ -} - -/* define the base filter class */ - -PHP_FUNCTION(user_filter_nop) -{ -} - -static zend_function_entry user_filter_class_funcs[] = { - PHP_NAMED_FE(filter, PHP_FN(user_filter_nop), NULL) - PHP_NAMED_FE(oncreate, PHP_FN(user_filter_nop), NULL) - PHP_NAMED_FE(onclose, PHP_FN(user_filter_nop), NULL) - { NULL, NULL, NULL } -}; - -static zend_class_entry user_filter_class_entry; - -PHP_MINIT_FUNCTION(user_filters) -{ - /* init the filter class ancestor */ - INIT_CLASS_ENTRY(user_filter_class_entry, "php_user_filter", user_filter_class_funcs); - if (NULL == zend_register_internal_class(&user_filter_class_entry TSRMLS_CC)) { - return FAILURE; - } - - /* init the filter resource; it has no dtor, as streams will always clean it up - * at the correct time */ - le_userfilters = zend_register_list_destructors_ex(NULL, NULL, PHP_STREAM_FILTER_RES_NAME, 0); - - if (le_userfilters == FAILURE) { - return FAILURE; - } - - le_bucket_brigade = zend_register_list_destructors_ex(NULL, NULL, PHP_STREAM_BRIGADE_RES_NAME, module_number); - le_bucket = zend_register_list_destructors_ex(NULL, NULL, PHP_STREAM_BUCKET_RES_NAME, module_number); - le_stream = zend_register_list_destructors_ex(NULL, NULL, PHP_STREAM_RES_NAME, module_number); - - if (le_bucket_brigade == FAILURE) { - return FAILURE; - } - - REGISTER_LONG_CONSTANT("PSFS_PASS_ON", PSFS_PASS_ON, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PSFS_FEED_ME", PSFS_FEED_ME, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PSFS_ERR_FATAL", PSFS_ERR_FATAL, CONST_CS | CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("PSFS_FLAG_NORMAL", PSFS_FLAG_NORMAL, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PSFS_FLAG_FLUSH_INC", PSFS_FLAG_FLUSH_INC, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("PSFS_FLAG_FLUSH_CLOSE", PSFS_FLAG_FLUSH_CLOSE, CONST_CS | CONST_PERSISTENT); - - return SUCCESS; -} - -static void userfilter_dtor(php_stream_filter *thisfilter TSRMLS_DC) -{ - zval *obj = (zval*)thisfilter->abstract; - zval func_name; - zval *retval = NULL; - zval **tmp; - - ZVAL_STRINGL(&func_name, "onclose", sizeof("onclose")-1, 0); - - call_user_function_ex(NULL, - &obj, - &func_name, - &retval, - 0, NULL, - 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); - - if (SUCCESS == zend_hash_find(Z_OBJPROP_P(obj), "filter", 6, (void**)&tmp)) { - zend_list_delete(Z_LVAL_PP(tmp)); - FREE_ZVAL(*tmp); - } - - /* kill the object */ - zval_ptr_dtor(&obj); -} - -php_stream_filter_status_t userfilter_filter( - php_stream *stream, - php_stream_filter *thisfilter, - php_stream_bucket_brigade *buckets_in, - php_stream_bucket_brigade *buckets_out, - size_t *bytes_consumed, - int flags - TSRMLS_DC) -{ - int ret = PSFS_ERR_FATAL; - zval *obj = (zval*)thisfilter->abstract; - zval func_name; - zval *retval = NULL; - zval **args[4]; - zval *zclosing, *zconsumed, *zin, *zout, *zstream; - int call_result; - - if (FAILURE == zend_hash_find(Z_OBJPROP_P(obj), "stream", 6, (void**)&zstream)) { - /* Give the userfilter class a hook back to the stream */ - ALLOC_ZVAL(zstream); - ZEND_REGISTER_RESOURCE(zstream, stream, le_stream); - add_property_zval(obj, "stream", zstream); - } - - ZVAL_STRINGL(&func_name, "filter", sizeof("filter")-1, 0); - - /* Setup calling arguments */ - ALLOC_ZVAL(zin); - ZEND_REGISTER_RESOURCE(zin, buckets_in, le_bucket_brigade); - args[0] = &zin; - - ALLOC_ZVAL(zout); - ZEND_REGISTER_RESOURCE(zout, buckets_out, le_bucket_brigade); - args[1] = &zout; - - ALLOC_INIT_ZVAL(zconsumed); - if (bytes_consumed) { - ZVAL_LONG(zconsumed, *bytes_consumed); - } else { - ZVAL_NULL(zconsumed); - } - args[2] = &zconsumed; - - ALLOC_INIT_ZVAL(zclosing); - ZVAL_BOOL(zclosing, flags & PSFS_FLAG_FLUSH_CLOSE); - args[3] = &zclosing; - - call_result = call_user_function_ex(NULL, - &obj, - &func_name, - &retval, - 4, args, - 0, NULL TSRMLS_CC); - - if (call_result == SUCCESS && retval != NULL) { - convert_to_long(retval); - ret = Z_LVAL_P(retval); - } else if (call_result == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to call filter function"); - } - - if (bytes_consumed) { - *bytes_consumed = Z_LVAL_P(zconsumed); - } - - if (retval) - zval_ptr_dtor(&retval); - zval_ptr_dtor(&zclosing); - zval_ptr_dtor(&zconsumed); - zval_ptr_dtor(&zout); - zval_ptr_dtor(&zin); - - return ret; -} - -static php_stream_filter_ops userfilter_ops = { - userfilter_filter, - userfilter_dtor, - "user-filter" -}; - -static php_stream_filter *user_filter_factory_create(const char *filtername, - const char *filterparams, int filterparamslen, int persistent TSRMLS_DC) -{ - struct php_user_filter_data *fdat = NULL; - php_stream_filter *filter; - zval *obj, *zfilter; - zval func_name; - zval *retval = NULL; - - /* some sanity checks */ - if (persistent) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "cannot use a user-space filter with a persistent stream"); - return NULL; - } - - /* determine the classname/class entry */ - if (FAILURE == zend_hash_find(BG(user_filter_map), (char*)filtername, - strlen(filtername), (void**)&fdat)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Err, filter \"%s\" is not in the user-filter map, but somehow the user-filter-factory was invoked for it!?", filtername); - return NULL; - } - - /* bind the classname to the actual class */ - if (fdat->ce == NULL) { - if (FAILURE == zend_hash_find(EG(class_table), fdat->classname, strlen(fdat->classname)+1, - (void **)&fdat->ce)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "user-filter \"%s\" requires class \"%s\", but that class is not defined", - filtername, fdat->classname); - return NULL; - } -#ifdef ZEND_ENGINE_2 - fdat->ce = *(zend_class_entry**)fdat->ce; -#endif - - } - - filter = php_stream_filter_alloc(&userfilter_ops, NULL, 0); - if (filter == NULL) { - return NULL; - } - - ALLOC_INIT_ZVAL(zfilter); - ZEND_REGISTER_RESOURCE(zfilter, filter, le_userfilters); - - /* create the object */ - ALLOC_ZVAL(obj); - object_init_ex(obj, fdat->ce); - ZVAL_REFCOUNT(obj) = 1; - PZVAL_IS_REF(obj) = 1; - - /* set the filter property */ - filter->abstract = obj; - - add_property_zval(obj, "filter", zfilter); - - /* filtername */ - add_property_string(obj, "filtername", (char*)filtername, 1); - - /* and the parameters, if any */ - if (filterparams) { - add_property_stringl(obj, "params", (char*)filterparams, filterparamslen, 1); - } else { - add_property_null(obj, "params"); - } - - /* invoke the constructor */ - ZVAL_STRINGL(&func_name, "oncreate", sizeof("oncreate")-1, 0); - - call_user_function_ex(NULL, - &obj, - &func_name, - &retval, - 0, NULL, - 0, NULL TSRMLS_CC); - - if (retval) - zval_ptr_dtor(&retval); - return filter; -} - -static php_stream_filter_factory user_filter_factory = { - user_filter_factory_create -}; - -static void filter_item_dtor(struct php_user_filter_data *fdat) -{ -} - -/* {{{ proto resource stream_bucket_make_writeable(resource brigade) - Return a bucket from the brigade for operating on */ -PHP_FUNCTION(stream_bucket_make_writeable) -{ - zval *zbrigade; - php_stream_bucket_brigade *brigade; - php_stream_bucket *bucket; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zbrigade) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(brigade, php_stream_bucket_brigade *, &zbrigade, -1, PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade); - - ZVAL_NULL(return_value); - - if (brigade->head && (bucket = php_stream_bucket_make_writeable(brigade->head TSRMLS_CC))) { - ZEND_REGISTER_RESOURCE(return_value, bucket, le_bucket); - } -} -/* }}} */ - -/* {{{ php_stream_bucket_attach */ -static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS) -{ - zval *zbrigade, *zbucket; - php_stream_bucket_brigade *brigade; - php_stream_bucket *bucket; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &zbrigade, &zbucket) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(brigade, php_stream_bucket_brigade *, &zbrigade, -1, PHP_STREAM_BRIGADE_RES_NAME, le_bucket_brigade); - ZEND_FETCH_RESOURCE(bucket, php_stream_bucket *, &zbucket, -1, PHP_STREAM_BUCKET_RES_NAME, le_bucket); - - if (append) { - php_stream_bucket_append(brigade, bucket TSRMLS_CC); - } else { - php_stream_bucket_prepend(brigade, bucket TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto void stream_bucket_prepend(resource brigade, resource bucket) - Prepend bucket to brigade */ -PHP_FUNCTION(stream_bucket_prepend) -{ - php_stream_bucket_attach(0, INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto void stream_bucket_append(resource brigade, resource bucket) - Append bucket to brigade */ -PHP_FUNCTION(stream_bucket_append) -{ - php_stream_bucket_attach(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto resource stream_bucket_new(resource stream, string buffer) - Create a new bucket for use on the current stream */ -PHP_FUNCTION(stream_bucket_new) -{ - zval *zstream; - php_stream *stream; - char *buffer; - char *pbuffer; - int buffer_len; - php_stream_bucket *bucket; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &zstream, &buffer, &buffer_len) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(stream, php_stream *, &zstream, -1, PHP_STREAM_RES_NAME, le_stream); - - if (!(pbuffer = pemalloc(buffer_len, php_stream_is_persistent(stream)))) { - RETURN_FALSE; - } - - memcpy(pbuffer, buffer, buffer_len); - - bucket = php_stream_bucket_new(stream, pbuffer, buffer_len, 1, php_stream_is_persistent(stream) TSRMLS_CC); - - ZEND_REGISTER_RESOURCE(return_value, bucket, le_bucket); -} -/* }}} */ - -/* {{{ proto string stream_bucket(resource bucket[, string buffer]) - Get/Set Bucket Contents */ -PHP_FUNCTION(stream_bucket) -{ - char *buffer = NULL; - int buffer_len = 0; - zval *zbucket; - php_stream_bucket *bucket; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &zbucket, &buffer, &buffer_len) == FAILURE) { - RETURN_FALSE; - } - - ZEND_FETCH_RESOURCE(bucket, php_stream_bucket *, &zbucket, -1, PHP_STREAM_BUCKET_RES_NAME, le_bucket); - - if (buffer) { - if (bucket->buf && bucket->own_buf) { - pefree(bucket->buf, bucket->is_persistent); - } - bucket->buf = pemalloc(buffer_len, bucket->is_persistent); - memcpy(bucket->buf, buffer, buffer_len); - bucket->buflen = buffer_len; - bucket->own_buf = 1; - } - RETURN_STRINGL(bucket->buf, bucket->buflen, 1); -} -/* }}} */ - -/* {{{ proto array stream_get_filters(void) - Returns a list of registered filters */ -PHP_FUNCTION(stream_get_filters) -{ - char *filter_name; - int key_flags, filter_name_len = 0; - HashTable *filters_hash; - - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - array_init(return_value); - - filters_hash = php_get_stream_filters_hash(); - - if (filters_hash) { - for(zend_hash_internal_pointer_reset(filters_hash); - (key_flags = zend_hash_get_current_key_ex(filters_hash, &filter_name, &filter_name_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT; - zend_hash_move_forward(filters_hash)) - if (key_flags == HASH_KEY_IS_STRING) - add_next_index_stringl(return_value, filter_name, filter_name_len, 1); - } - /* It's okay to return an empty array if no filters are registered */ -} -/* }}} */ - -/* {{{ proto bool stream_register_filter(string filtername, string classname) - Registers a custom filter handler class */ -PHP_FUNCTION(stream_register_filter) -{ - char *filtername, *classname; - int filtername_len, classname_len; - struct php_user_filter_data *fdat; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &filtername, &filtername_len, - &classname, &classname_len) == FAILURE) { - RETURN_FALSE; - } - - RETVAL_FALSE; - - if (!BG(user_filter_map)) { - BG(user_filter_map) = (HashTable*) emalloc(sizeof(HashTable)); - zend_hash_init(BG(user_filter_map), 5, NULL, (dtor_func_t) filter_item_dtor, 0); - } - - fdat = ecalloc(1, sizeof(*fdat) + classname_len); - memcpy(fdat->classname, classname, classname_len); - zend_str_tolower(fdat->classname, classname_len); - - if (zend_hash_add(BG(user_filter_map), filtername, filtername_len, (void*)fdat, - sizeof(*fdat) + classname_len, NULL) == SUCCESS && - php_stream_filter_register_factory(filtername, &user_filter_factory TSRMLS_CC) == SUCCESS) { - RETVAL_TRUE; - } - - efree(fdat); -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/var.c b/ext/standard/var.c deleted file mode 100644 index 1a88d70f93..0000000000 --- a/ext/standard/var.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Jani Lehtimäki <jkl@njet.net> | - | Thies C. Arntzen <thies@thieso.net> | - | Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - - -/* {{{ includes -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "php.h" -#include "php_string.h" -#include "php_var.h" -#include "php_smart_str.h" -#include "basic_functions.h" -#include "php_incomplete_class.h" - -#define COMMON ((*struc)->is_ref ? "&" : "") -#define Z_REFCOUNT_PP(a) ((*a)->refcount) - -/* }}} */ -/* {{{ php_var_dump */ - -static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) -{ - int level; - TSRMLS_FETCH(); - - level = va_arg(args, int); - - if (hash_key->nKeyLength==0) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h); - } else { /* string key */ - php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey); - } - php_var_dump(zv, level + 2 TSRMLS_CC); - return 0; -} - -void php_var_dump(zval **struc, int level TSRMLS_DC) -{ - HashTable *myht = NULL; - char *class_name; - zend_uint class_name_len; - - if (level > 1) { - php_printf("%*c", level - 1, ' '); - } - - switch (Z_TYPE_PP(struc)) { - case IS_BOOL: - php_printf("%sbool(%s)\n", COMMON, Z_LVAL_PP(struc)?"true":"false"); - break; - case IS_NULL: - php_printf("%sNULL\n", COMMON); - break; - case IS_LONG: - php_printf("%sint(%ld)\n", COMMON, Z_LVAL_PP(struc)); - break; - case IS_DOUBLE: - php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc)); - break; - case IS_STRING: - php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc)); - PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc)); - PUTS("\"\n"); - break; - case IS_ARRAY: - myht = Z_ARRVAL_PP(struc); - if (myht->nApplyCount > 1) { - PUTS("*RECURSION*\n"); - return; - } - php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht)); - goto head_done; - case IS_OBJECT: - myht = Z_OBJPROP_PP(struc); - if (myht && myht->nApplyCount > 1) { - PUTS("*RECURSION*\n"); - return; - } - - Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC); - - php_printf("%sobject(%s)(%d) {\n", COMMON, class_name, myht ? zend_hash_num_elements(myht) : 0); -head_done: - if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level); - } - if (level > 1) { - php_printf("%*c", level-1, ' '); - } - PUTS("}\n"); - break; - case IS_RESOURCE: { - char *type_name; - - type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC); - php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown"); - break; - } - default: - php_printf("%sUNKNOWN:0\n", COMMON); - break; - } -} - -/* }}} */ - - - -/* {{{ proto void var_dump(mixed var) - Dumps a string representation of variable to output */ -PHP_FUNCTION(var_dump) -{ - zval ***args; - int argc; - int i; - - argc = ZEND_NUM_ARGS(); - - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - for (i=0; i<argc; i++) - php_var_dump(args[i], 1 TSRMLS_CC); - - efree(args); -} -/* }}} */ - -/* {{{ debug_zval_dump */ - -static int zval_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) -{ - int level; - TSRMLS_FETCH(); - - level = va_arg(args, int); - - if (hash_key->nKeyLength==0) { /* numeric key */ - php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h); - } else { /* string key */ - php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey); - } - php_debug_zval_dump(zv, level + 2 TSRMLS_CC); - return 0; -} - -void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) -{ - HashTable *myht = NULL; - char *class_name; - zend_uint class_name_len; - - if (level > 1) { - php_printf("%*c", level - 1, ' '); - } - - switch (Z_TYPE_PP(struc)) { - case IS_BOOL: - php_printf("%sbool(%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc)?"true":"false", Z_REFCOUNT_PP(struc)); - break; - case IS_NULL: - php_printf("%sNULL refcount(%u)\n", COMMON, Z_REFCOUNT_PP(struc)); - break; - case IS_LONG: - php_printf("%slong(%ld) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), Z_REFCOUNT_PP(struc)); - break; - case IS_DOUBLE: - php_printf("%sdouble(%.*G) refcount(%u)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc), Z_REFCOUNT_PP(struc)); - break; - case IS_STRING: - php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc)); - PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc)); - php_printf("\" refcount(%u)\n", Z_REFCOUNT_PP(struc)); - break; - case IS_ARRAY: - myht = Z_ARRVAL_PP(struc); - php_printf("%sarray(%d) refcount(%u){\n", COMMON, zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc)); - goto head_done; - case IS_OBJECT: - myht = Z_OBJPROP_PP(struc); - Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC); - php_printf("%sobject(%s)(%d) refcount(%u){\n", COMMON, class_name, myht ? zend_hash_num_elements(myht) : 0, Z_REFCOUNT_PP(struc)); -head_done: - if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) zval_array_element_dump, 1, level); - } - if (level > 1) { - php_printf("%*c", level-1, ' '); - } - PUTS("}\n"); - break; - case IS_RESOURCE: { - char *type_name; - - type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC); - php_printf("%sresource(%ld) of type (%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown", Z_REFCOUNT_PP(struc)); - break; - } - default: - php_printf("%sUNKNOWN:0\n", COMMON); - break; - } -} - -/* }}} */ - -/* {{{ proto void debug_zval_dump(mixed var) - Dumps a string representation of an internal zend value to output. */ -PHP_FUNCTION(debug_zval_dump) -{ - zval ***args; - int argc; - int i; - - argc = ZEND_NUM_ARGS(); - - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - for (i=0; i<argc; i++) - php_debug_zval_dump(args[i], 1 TSRMLS_CC); - - efree(args); -} -/* }}} */ - - -/* {{{ php_var_export */ - -static int php_array_element_export(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) -{ - int level; - TSRMLS_FETCH(); - - level = va_arg(args, int); - - if (hash_key->nKeyLength==0) { /* numeric key */ - php_printf("%*c%ld => ", level + 1, ' ', hash_key->h); - } else { /* string key */ - php_printf("%*c'%s' => ", level + 1, ' ', hash_key->arKey); - } - php_var_export(zv, level + 2 TSRMLS_CC); - PUTS (",\n"); - return 0; -} - -static int php_object_element_export(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) -{ - int level; - TSRMLS_FETCH(); - - level = va_arg(args, int); - - if (hash_key->nKeyLength != 0) { - php_printf("%*cvar $%s = ", level + 1, ' ', hash_key->arKey); - php_var_export(zv, level + 2 TSRMLS_CC); - PUTS (";\n"); - } - return 0; -} - -void php_var_export(zval **struc, int level TSRMLS_DC) -{ - HashTable *myht; - char* tmp_str; - int tmp_len; - char *class_name; - zend_uint class_name_len; - - switch (Z_TYPE_PP(struc)) { - case IS_BOOL: - php_printf("%s", Z_LVAL_PP(struc) ? "true" : "false"); - break; - case IS_NULL: - php_printf("NULL"); - break; - case IS_LONG: - php_printf("%ld", Z_LVAL_PP(struc)); - break; - case IS_DOUBLE: - php_printf("%.*G", (int) EG(precision), Z_DVAL_PP(struc)); - break; - case IS_STRING: - tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\", 2 TSRMLS_CC); - PUTS ("'"); - PHPWRITE(tmp_str, tmp_len); - PUTS ("'"); - efree (tmp_str); - break; - case IS_ARRAY: - myht = Z_ARRVAL_PP(struc); - if (level > 1) { - php_printf("\n%*c", level - 1, ' '); - } - PUTS ("array (\n"); - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_export, 1, level); - if (level > 1) { - php_printf("%*c", level - 1, ' '); - } - PUTS(")"); - break; - case IS_OBJECT: - myht = Z_OBJPROP_PP(struc); - if (level > 1) { - php_printf("\n%*c", level - 1, ' '); - } - Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC); - php_printf ("class %s {\n", class_name); - if (myht) { - zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_object_element_export, 1, level); - } - if (level > 1) { - php_printf("%*c", level - 1, ' '); - } - PUTS("}"); - break; - default: - PUTS ("NULL"); - break; - } -} - -/* }}} */ - - -/* {{{ proto mixed var_export(mixed var [, bool return]) - Outputs or returns a string representation of a variable */ -PHP_FUNCTION(var_export) -{ - zval *var; - zend_bool return_output = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &return_output) == FAILURE) { - return; - } - - if (return_output) { - php_start_ob_buffer (NULL, 0, 1 TSRMLS_CC); - } - - php_var_export(&var, 1 TSRMLS_CC); - - if (return_output) { - php_ob_get_buffer (return_value TSRMLS_CC); - php_end_ob_buffer (0, 0 TSRMLS_CC); - } -} -/* }}} */ - - - -/* {{{ php_var_serialize */ - -static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC); - -static inline int php_add_var_hash(HashTable *var_hash, zval *var, void *var_old) -{ - ulong var_no; - char id[32], *p; - register int len; - - /* relies on "(long)" being a perfect hash function for data pointers */ - p = smart_str_print_long(id + sizeof(id) - 1, (long) var); - len = id + sizeof(id) - 1 - p; - - if (var_old && zend_hash_find(var_hash, p, len, var_old) == SUCCESS) { - if (!var->is_ref) { - /* we still need to bump up the counter, since non-refs will - be counted separately by unserializer */ - var_no = -1; - zend_hash_next_index_insert(var_hash, &var_no, sizeof(var_no), NULL); - } - return FAILURE; - } - - /* +1 because otherwise hash will think we are trying to store NULL pointer */ - var_no = zend_hash_num_elements(var_hash) + 1; - zend_hash_add(var_hash, p, len, &var_no, sizeof(var_no), NULL); - return SUCCESS; -} - -static inline void php_var_serialize_long(smart_str *buf, long val) -{ - smart_str_appendl(buf, "i:", 2); - smart_str_append_long(buf, val); - smart_str_appendc(buf, ';'); -} - -static inline void php_var_serialize_string(smart_str *buf, char *str, int len) -{ - smart_str_appendl(buf, "s:", 2); - smart_str_append_long(buf, len); - smart_str_appendl(buf, ":\"", 2); - smart_str_appendl(buf, str, len); - smart_str_appendl(buf, "\";", 2); -} - -static inline void php_var_serialize_class_name(smart_str *buf, zval **struc TSRMLS_DC) -{ - PHP_CLASS_ATTRIBUTES; - - PHP_SET_CLASS_ATTRIBUTES(*struc); - smart_str_appendl(buf, "O:", 2); - smart_str_append_long(buf, name_len); - smart_str_appendl(buf, ":\"", 2); - smart_str_appendl(buf, class_name, name_len); - smart_str_appendl(buf, "\":", 2); - PHP_CLEANUP_CLASS_ATTRIBUTES(); -} - -static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_ptr, HashTable *var_hash TSRMLS_DC) -{ - int count; - - php_var_serialize_class_name(buf, struc TSRMLS_CC); - /* count after serializing name, since php_var_serialize_class_name - changes the count if the variable is incomplete class */ - count = zend_hash_num_elements(HASH_OF(retval_ptr)); - smart_str_append_long(buf, count); - smart_str_appendl(buf, ":{", 2); - - if (count > 0) { - char *key; - zval **d, **name; - ulong index; - HashPosition pos; - int i; - zval nval, *nvalp; - - ZVAL_NULL(&nval); - nvalp = &nval; - - zend_hash_internal_pointer_reset_ex(HASH_OF(retval_ptr), &pos); - - for (;; zend_hash_move_forward_ex(HASH_OF(retval_ptr), &pos)) { - i = zend_hash_get_current_key_ex(HASH_OF(retval_ptr), &key, NULL, - &index, 0, &pos); - - if (i == HASH_KEY_NON_EXISTANT) - break; - - zend_hash_get_current_data_ex(HASH_OF(retval_ptr), - (void **) &name, &pos); - - if (Z_TYPE_PP(name) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only " - "containing the names of instance-variables to " - "serialize."); - /* we should still add element even if it's not OK, - since we already wrote the length of the array before */ - smart_str_appendl(buf,"s:0:\"\";N;", 9); - continue; - } - - php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name)); - - if (zend_hash_find(Z_OBJPROP_PP(struc), Z_STRVAL_PP(name), - Z_STRLEN_PP(name) + 1, (void *) &d) == SUCCESS) { - php_var_serialize_intern(buf, d, var_hash TSRMLS_CC); - } else { - php_var_serialize_intern(buf, &nvalp, var_hash TSRMLS_CC); - } - } - } - smart_str_appendc(buf, '}'); -} - - -static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC) -{ - int i; - ulong *var_already; - HashTable *myht; - - if(var_hash - && php_add_var_hash(var_hash, *struc, (void *) &var_already) == FAILURE - && (*struc)->is_ref) { - smart_str_appendl(buf, "R:", 2); - smart_str_append_long(buf, *var_already); - smart_str_appendc(buf, ';'); - return; - } - - switch (Z_TYPE_PP(struc)) { - case IS_BOOL: - smart_str_appendl(buf, "b:", 2); - smart_str_append_long(buf, Z_LVAL_PP(struc)); - smart_str_appendc(buf, ';'); - return; - - case IS_NULL: - smart_str_appendl(buf, "N;", 2); - return; - - case IS_LONG: - php_var_serialize_long(buf, Z_LVAL_PP(struc)); - return; - - case IS_DOUBLE: { - char s[256]; - ulong slen; - - slen = sprintf(s, "d:%.*G;", (int) EG(precision), Z_DVAL_PP(struc)); - smart_str_appendl(buf, s, slen); - return; - } - - case IS_STRING: - php_var_serialize_string(buf, Z_STRVAL_PP(struc), Z_STRLEN_PP(struc)); - return; - - case IS_OBJECT: { - zval *retval_ptr = NULL; - zval fname; - int res; - - INIT_PZVAL(&fname); - ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0); - res = call_user_function_ex(CG(function_table), struc, &fname, - &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - - if (res == SUCCESS) { - if (retval_ptr) { - if (HASH_OF(retval_ptr)) { - php_var_serialize_class(buf, struc, retval_ptr, - var_hash TSRMLS_CC); - } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only " - "containing the names of instance-variables to " - "serialize."); - } - - zval_ptr_dtor(&retval_ptr); - } - return; - } - if (retval_ptr) - zval_ptr_dtor(&retval_ptr); - /* fall-through */ - } - case IS_ARRAY: - myht = HASH_OF(*struc); - if (Z_TYPE_PP(struc) == IS_ARRAY) { - smart_str_appendl(buf, "a:", 2); - } else { - php_var_serialize_class_name(buf, struc TSRMLS_CC); - } - /* count after serializing name, since php_var_serialize_class_name - changes the count if the variable is incomplete class */ - i = zend_hash_num_elements(myht); - smart_str_append_long(buf, i); - smart_str_appendl(buf, ":{", 2); - if (i > 0) { - char *key; - zval **data; - ulong index; - uint key_len; - HashPosition pos; - - zend_hash_internal_pointer_reset_ex(myht, &pos); - for (;; zend_hash_move_forward_ex(myht, &pos)) { - i = zend_hash_get_current_key_ex(myht, &key, &key_len, - &index, 0, &pos); - if (i == HASH_KEY_NON_EXISTANT) - break; - - switch (i) { - case HASH_KEY_IS_LONG: - php_var_serialize_long(buf, index); - break; - case HASH_KEY_IS_STRING: - php_var_serialize_string(buf, key, key_len - 1); - break; - } - - /* we should still add element even if it's not OK, - since we already wrote the length of the array before */ - if (zend_hash_get_current_data_ex(myht, - (void **) &data, &pos) != SUCCESS - || !data - || data == struc) { - smart_str_appendl(buf, "N;", 2); - } else { - php_var_serialize_intern(buf, data, var_hash TSRMLS_CC); - } - } - } - smart_str_appendc(buf, '}'); - return; - default: - smart_str_appendl(buf, "i:0;", 4); - return; - } -} - -PHPAPI void php_var_serialize(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC) -{ - php_var_serialize_intern(buf, struc, var_hash TSRMLS_CC); - smart_str_0(buf); -} - -/* }}} */ - -/* {{{ proto string serialize(mixed variable) - Returns a string representation of variable (which can later be unserialized) */ -PHP_FUNCTION(serialize) -{ - zval **struc; - php_serialize_data_t var_hash; - smart_str buf = {0}; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &struc) == FAILURE) { - WRONG_PARAM_COUNT; - } - - Z_TYPE_P(return_value) = IS_STRING; - Z_STRVAL_P(return_value) = NULL; - Z_STRLEN_P(return_value) = 0; - - PHP_VAR_SERIALIZE_INIT(var_hash); - php_var_serialize(&buf, struc, &var_hash TSRMLS_CC); - PHP_VAR_SERIALIZE_DESTROY(var_hash); - - if (buf.c) { - RETURN_STRINGL(buf.c, buf.len, 0); - } else { - RETURN_NULL(); - } -} - -/* }}} */ -/* {{{ proto mixed unserialize(string variable_representation) - Takes a string representation of variable and recreates it */ - - -PHP_FUNCTION(unserialize) -{ - zval **buf; - php_unserialize_data_t var_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buf) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (Z_TYPE_PP(buf) == IS_STRING) { - const char *p = Z_STRVAL_PP(buf); - - if (Z_STRLEN_PP(buf) == 0) { - RETURN_FALSE; - } - - PHP_VAR_UNSERIALIZE_INIT(var_hash); - if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_PP(buf), &var_hash TSRMLS_CC)) { - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - zval_dtor(return_value); - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %d of %d bytes", p - Z_STRVAL_PP(buf), Z_STRLEN_PP(buf)); - RETURN_FALSE; - } - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - } else { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Argument is not an string"); - RETURN_FALSE; - } -} - -/* }}} */ - -#if MEMORY_LIMIT -/* {{{ proto int memory_get_usage() - Returns the allocated by PHP memory */ -PHP_FUNCTION(memory_get_usage) { - RETURN_LONG(AG(allocated_memory)); -} -/* }}} */ -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/ext/standard/var_unserializer.c b/ext/standard/var_unserializer.c deleted file mode 100644 index 16a9561a77..0000000000 --- a/ext/standard/var_unserializer.c +++ /dev/null @@ -1,787 +0,0 @@ -/* Generated by re2c 0.5 on Fri Jan 24 11:25:29 2003 */ -#line 1 "/home/rei/PHP_CVS/php5/ext/standard/var_unserializer.re" -#include "php.h" -#include "ext/standard/php_var.h" -#include "php_incomplete_class.h" - -/* {{{ reference-handling for unserializer: var_* */ -#define VAR_ENTRIES_MAX 1024 - -typedef struct { - zval *data[VAR_ENTRIES_MAX]; - int used_slots; - void *next; -} var_entries; - -static inline void var_push(php_unserialize_data_t *var_hashx, zval **rval) -{ - var_entries *var_hash = var_hashx->first, *prev = NULL; - - while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { - prev = var_hash; - var_hash = var_hash->next; - } - - if (!var_hash) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!var_hashx->first) - var_hashx->first = var_hash; - else - prev->next = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; -} - -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) -{ - int i; - var_entries *var_hash = var_hashx->first; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - if (var_hash->data[i] == ozval) { - var_hash->data[i] = *nzval; - return; - } - } - var_hash = var_hash->next; - } -} - -static int var_access(php_unserialize_data_t *var_hashx, int id, zval ***store) -{ - var_entries *var_hash = var_hashx->first; - - while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = var_hash->next; - id -= VAR_ENTRIES_MAX; - } - - if (!var_hash) return !SUCCESS; - - if (id >= var_hash->used_slots) return !SUCCESS; - - *store = &var_hash->data[id]; - - return SUCCESS; -} - -PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) -{ - void *next; - var_entries *var_hash = var_hashx->first; - - while (var_hash) { - next = var_hash->next; - efree(var_hash); - var_hash = next; - } -} - -/* }}} */ - -#define YYFILL(n) do { } while (0) -#define YYCTYPE unsigned char -#define YYCURSOR cursor -#define YYLIMIT limit -#define YYMARKER marker - - -#line 97 - - - - -static inline int parse_iv2(const char *p, const char **q) -{ - char cursor; - int result = 0; - int neg = 0; - - switch (*p) { - case '-': - neg++; - /* fall-through */ - case '+': - p++; - } - - while (1) { - cursor = *p; - if (cursor >= '0' && cursor <= '9') { - result = result * 10 + cursor - '0'; - } else { - break; - } - p++; - } - if (q) *q = p; - if (neg) return -result; - return result; -} - -static inline int parse_iv(const char *p) -{ - return parse_iv2(p, NULL); -} - -#define UNSERIALIZE_PARAMETER zval **rval, const char **p, const char *max, php_unserialize_data_t *var_hash TSRMLS_DC -#define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC - -static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, int elements) -{ - while (elements-- > 0) { - zval *key, *data; - - ALLOC_INIT_ZVAL(key); - - if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - return 0; - } - - ALLOC_INIT_ZVAL(data); - - if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - zval_dtor(data); - FREE_ZVAL(data); - return 0; - } - - switch (Z_TYPE_P(key)) { - case IS_LONG: - zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); - break; - case IS_STRING: - zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); - break; - - } - - zval_dtor(key); - FREE_ZVAL(key); - } - - return 1; -} - -static inline int finish_nested_data(UNSERIALIZE_PARAMETER) -{ - if (*((*p)++) == '}') - return 1; - -#if SOMETHING_NEW_MIGHT_LEAD_TO_CRASH_ENABLE_IF_YOU_ARE_BRAVE - zval_ptr_dtor(rval); -#endif - return 0; -} - -static inline int object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) -{ - int elements; - - elements = parse_iv2((*p) + 2, p); - - (*p) += 2; - - object_init_ex(*rval, ce); - return elements; -} - -static inline int object_common2(UNSERIALIZE_PARAMETER, int elements) -{ - zval *retval_ptr = NULL; - zval fname; - - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements)) { - return 0; - } - - INIT_PZVAL(&fname); - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0); - call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - - if (retval_ptr) - zval_ptr_dtor(&retval_ptr); - - return finish_nested_data(UNSERIALIZE_PASSTHRU); - -} - -PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) -{ - const unsigned char *cursor, *limit, *marker, *start; - zval **rval_ref; - - limit = cursor = *p; - - if (var_hash && cursor[0] != 'R') { - var_push(var_hash, rval); - } - - start = cursor; - - - -{ - YYCTYPE yych; - unsigned int yyaccept; - static unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if((YYLIMIT - YYCURSOR) < 5) YYFILL(5); - yych = *YYCURSOR; - if(yych <= 'd'){ - if(yych <= 'R'){ - if(yych <= 'N'){ - if(yych <= 'M') goto yy15; - goto yy5; - } else { - if(yych <= 'O') goto yy12; - if(yych <= 'Q') goto yy15; - goto yy3; - } - } else { - if(yych <= 'a'){ - if(yych <= '`') goto yy15; - goto yy10; - } else { - if(yych <= 'b') goto yy6; - if(yych <= 'c') goto yy15; - goto yy8; - } - } - } else { - if(yych <= 'r'){ - if(yych <= 'i'){ - if(yych <= 'h') goto yy15; - goto yy7; - } else { - if(yych == 'o') goto yy11; - goto yy15; - } - } else { - if(yych <= '|'){ - if(yych <= 's') goto yy9; - goto yy15; - } else { - if(yych <= '}') goto yy13; - if(yych <= '\277') goto yy15; - } - } - } -yy2: YYCURSOR = YYMARKER; - switch(yyaccept){ - case 0: goto yy4; - } -yy3: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy75; -yy4: -#line 410 - { return 0; } -yy5: yych = *++YYCURSOR; - if(yych == ';') goto yy73; - goto yy4; -yy6: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy67; - goto yy4; -yy7: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy61; - goto yy4; -yy8: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy44; - goto yy4; -yy9: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy37; - goto yy4; -yy10: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy30; - goto yy4; -yy11: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy23; - goto yy4; -yy12: yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - if(yych == ':') goto yy16; - goto yy4; -yy13: yych = *++YYCURSOR; -yy14: -#line 404 - { - /* this is the case where we have less data than planned */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data"); - return 0; /* not sure if it should be 0 or 1 here? */ -} -yy15: yych = *++YYCURSOR; - goto yy4; -yy16: yych = *++YYCURSOR; - if(yybm[0+yych] & 128) goto yy18; - if(yych == '+') goto yy17; - if(yych != '-') goto yy2; -yy17: yych = *++YYCURSOR; - if(yybm[0+yych] & 128) goto yy18; - goto yy2; -yy18: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy19: if(yybm[0+yych] & 128) goto yy18; - if(yych != ':') goto yy2; -yy20: yych = *++YYCURSOR; - if(yych != '"') goto yy2; -yy21: yych = *++YYCURSOR; -yy22: -#line 330 - { - int len; - int elements; - int len2; - char *class_name; - zend_class_entry *ce; - int incomplete_class = 0; - - zval *user_func; - zval *retval_ptr; - zval **args[1]; - zval *arg_func_name; - - INIT_PZVAL(*rval); - len2 = len = parse_iv(start + 2); - if (len == 0) - return 0; - - class_name = estrndup(YYCURSOR, len); - YYCURSOR += len; - - while (len-- > 0) { - if (class_name[len] >= 'A' && class_name[len] <= 'Z') { - class_name[len] = class_name[len] - 'A' + 'a'; - } - } - - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { - if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { - MAKE_STD_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - - args[0] = &arg_func_name; - MAKE_STD_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); - - if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s) hasn't defined the class it was called for", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } - } - } - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } - - *p = YYCURSOR; - elements = object_common1(UNSERIALIZE_PASSTHRU, ce); - - if (incomplete_class) { - php_store_class_name(*rval, class_name, len2); - efree(class_name); - } - - return object_common2(UNSERIALIZE_PASSTHRU, elements); -} -yy23: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy24; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy25; - goto yy2; - } -yy24: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy25: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy26: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy25; - if(yych >= ';') goto yy2; -yy27: yych = *++YYCURSOR; - if(yych != '"') goto yy2; -yy28: yych = *++YYCURSOR; -yy29: -#line 322 - { - - INIT_PZVAL(*rval); - - return object_common2(UNSERIALIZE_PASSTHRU, - object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR)); -} -yy30: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy31; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy32; - goto yy2; - } -yy31: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy32: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy33: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy32; - if(yych >= ';') goto yy2; -yy34: yych = *++YYCURSOR; - if(yych != '{') goto yy2; -yy35: yych = *++YYCURSOR; -yy36: -#line 304 - { - int elements = parse_iv(start + 2); - - *p = YYCURSOR; - - INIT_PZVAL(*rval); - Z_TYPE_PP(rval) = IS_ARRAY; - ALLOC_HASHTABLE(Z_ARRVAL_PP(rval)); - - zend_hash_init(Z_ARRVAL_PP(rval), elements + 1, NULL, ZVAL_PTR_DTOR, 0); - - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements)) { - return 0; - } - - return finish_nested_data(UNSERIALIZE_PASSTHRU); -} -yy37: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy38; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy39; - goto yy2; - } -yy38: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy39: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy40: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy39; - if(yych >= ';') goto yy2; -yy41: yych = *++YYCURSOR; - if(yych != '"') goto yy2; -yy42: yych = *++YYCURSOR; -yy43: -#line 284 - { - int len; - char *str; - - len = parse_iv(start + 2); - - if (len == 0) { - str = empty_string; - } else { - str = estrndup(YYCURSOR, len); - } - - YYCURSOR += len + 2; - *p = YYCURSOR; - - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 0); - return 1; -} -yy44: yych = *++YYCURSOR; - if(yych <= '-'){ - if(yych == '+') goto yy45; - if(yych <= ',') goto yy2; - } else { - if(yych <= '.') goto yy48; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy46; - goto yy2; - } -yy45: yych = *++YYCURSOR; - if(yych == '.') goto yy48; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy46: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy47: if(yych <= ':'){ - if(yych <= '.'){ - if(yych <= '-') goto yy2; - goto yy58; - } else { - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy46; - goto yy2; - } - } else { - if(yych <= 'E'){ - if(yych <= ';') goto yy51; - if(yych <= 'D') goto yy2; - goto yy53; - } else { - if(yych == 'e') goto yy53; - goto yy2; - } - } -yy48: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy49: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy50: if(yych <= ';'){ - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy49; - if(yych <= ':') goto yy2; - } else { - if(yych <= 'E'){ - if(yych <= 'D') goto yy2; - goto yy53; - } else { - if(yych == 'e') goto yy53; - goto yy2; - } - } -yy51: yych = *++YYCURSOR; -yy52: -#line 277 - { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_DOUBLE(*rval, atof(start + 2)); - return 1; -} -yy53: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy54; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy55; - goto yy2; - } -yy54: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych == '+') goto yy57; - goto yy2; - } else { - if(yych <= '-') goto yy57; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; - } -yy55: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy56: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy55; - if(yych == ';') goto yy51; - goto yy2; -yy57: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy55; - goto yy2; -yy58: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy59: ++YYCURSOR; - if((YYLIMIT - YYCURSOR) < 4) YYFILL(4); - yych = *YYCURSOR; -yy60: if(yych <= ';'){ - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy59; - if(yych <= ':') goto yy2; - goto yy51; - } else { - if(yych <= 'E'){ - if(yych <= 'D') goto yy2; - goto yy53; - } else { - if(yych == 'e') goto yy53; - goto yy2; - } - } -yy61: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy62; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy63; - goto yy2; - } -yy62: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy63: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy64: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy63; - if(yych != ';') goto yy2; -yy65: yych = *++YYCURSOR; -yy66: -#line 270 - { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_LONG(*rval, parse_iv(start + 2)); - return 1; -} -yy67: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy68; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy69; - goto yy2; - } -yy68: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy69: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy70: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy69; - if(yych != ';') goto yy2; -yy71: yych = *++YYCURSOR; -yy72: -#line 263 - { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_BOOL(*rval, parse_iv(start + 2)); - return 1; -} -yy73: yych = *++YYCURSOR; -yy74: -#line 256 - { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_NULL(*rval); - return 1; -} -yy75: yych = *++YYCURSOR; - if(yych <= ','){ - if(yych != '+') goto yy2; - } else { - if(yych <= '-') goto yy76; - if(yych <= '/') goto yy2; - if(yych <= '9') goto yy77; - goto yy2; - } -yy76: yych = *++YYCURSOR; - if(yych <= '/') goto yy2; - if(yych >= ':') goto yy2; -yy77: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy78: if(yych <= '/') goto yy2; - if(yych <= '9') goto yy77; - if(yych != ';') goto yy2; -yy79: yych = *++YYCURSOR; -yy80: -#line 237 - { - int id; - - *p = YYCURSOR; - if (!var_hash) return 0; - - id = parse_iv(start + 2) - 1; - if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) { - return 0; - } - - zval_ptr_dtor(rval); - *rval = *rval_ref; - (*rval)->refcount++; - (*rval)->is_ref = 1; - - return 1; -} -} -#line 412 - - - return 0; -} diff --git a/ext/standard/var_unserializer.re b/ext/standard/var_unserializer.re deleted file mode 100644 index 0ef2425faf..0000000000 --- a/ext/standard/var_unserializer.re +++ /dev/null @@ -1,415 +0,0 @@ -#include "php.h" -#include "ext/standard/php_var.h" -#include "php_incomplete_class.h" - -/* {{{ reference-handling for unserializer: var_* */ -#define VAR_ENTRIES_MAX 1024 - -typedef struct { - zval *data[VAR_ENTRIES_MAX]; - int used_slots; - void *next; -} var_entries; - -static inline void var_push(php_unserialize_data_t *var_hashx, zval **rval) -{ - var_entries *var_hash = var_hashx->first, *prev = NULL; - - while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { - prev = var_hash; - var_hash = var_hash->next; - } - - if (!var_hash) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!var_hashx->first) - var_hashx->first = var_hash; - else - prev->next = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; -} - -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) -{ - int i; - var_entries *var_hash = var_hashx->first; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - if (var_hash->data[i] == ozval) { - var_hash->data[i] = *nzval; - return; - } - } - var_hash = var_hash->next; - } -} - -static int var_access(php_unserialize_data_t *var_hashx, int id, zval ***store) -{ - var_entries *var_hash = var_hashx->first; - - while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = var_hash->next; - id -= VAR_ENTRIES_MAX; - } - - if (!var_hash) return !SUCCESS; - - if (id >= var_hash->used_slots) return !SUCCESS; - - *store = &var_hash->data[id]; - - return SUCCESS; -} - -PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) -{ - void *next; - var_entries *var_hash = var_hashx->first; - - while (var_hash) { - next = var_hash->next; - efree(var_hash); - var_hash = next; - } -} - -/* }}} */ - -#define YYFILL(n) do { } while (0) -#define YYCTYPE unsigned char -#define YYCURSOR cursor -#define YYLIMIT limit -#define YYMARKER marker - - -/*!re2c -iv = [+-]? [0-9]+; -nv = [+-]? ([0-9]* "." [0-9]+|[0-9]+ "." [0-9]+); -nvexp = (iv | nv) [eE] [+-]? iv; -any = [\000-\277]; -*/ - - - -static inline int parse_iv2(const char *p, const char **q) -{ - char cursor; - int result = 0; - int neg = 0; - - switch (*p) { - case '-': - neg++; - /* fall-through */ - case '+': - p++; - } - - while (1) { - cursor = *p; - if (cursor >= '0' && cursor <= '9') { - result = result * 10 + cursor - '0'; - } else { - break; - } - p++; - } - if (q) *q = p; - if (neg) return -result; - return result; -} - -static inline int parse_iv(const char *p) -{ - return parse_iv2(p, NULL); -} - -#define UNSERIALIZE_PARAMETER zval **rval, const char **p, const char *max, php_unserialize_data_t *var_hash TSRMLS_DC -#define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC - -static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, int elements) -{ - while (elements-- > 0) { - zval *key, *data; - - ALLOC_INIT_ZVAL(key); - - if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - return 0; - } - - ALLOC_INIT_ZVAL(data); - - if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) { - zval_dtor(key); - FREE_ZVAL(key); - zval_dtor(data); - FREE_ZVAL(data); - return 0; - } - - switch (Z_TYPE_P(key)) { - case IS_LONG: - zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL); - break; - case IS_STRING: - zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL); - break; - - } - - zval_dtor(key); - FREE_ZVAL(key); - } - - return 1; -} - -static inline int finish_nested_data(UNSERIALIZE_PARAMETER) -{ - if (*((*p)++) == '}') - return 1; - -#if SOMETHING_NEW_MIGHT_LEAD_TO_CRASH_ENABLE_IF_YOU_ARE_BRAVE - zval_ptr_dtor(rval); -#endif - return 0; -} - -static inline int object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce) -{ - int elements; - - elements = parse_iv2((*p) + 2, p); - - (*p) += 2; - - object_init_ex(*rval, ce); - return elements; -} - -static inline int object_common2(UNSERIALIZE_PARAMETER, int elements) -{ - zval *retval_ptr = NULL; - zval fname; - - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements)) { - return 0; - } - - INIT_PZVAL(&fname); - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0); - call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC); - - if (retval_ptr) - zval_ptr_dtor(&retval_ptr); - - return finish_nested_data(UNSERIALIZE_PASSTHRU); - -} - -PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER) -{ - const unsigned char *cursor, *limit, *marker, *start; - zval **rval_ref; - - limit = cursor = *p; - - if (var_hash && cursor[0] != 'R') { - var_push(var_hash, rval); - } - - start = cursor; - - - -/*!re2c - -"R:" iv ";" { - int id; - - *p = YYCURSOR; - if (!var_hash) return 0; - - id = parse_iv(start + 2) - 1; - if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) { - return 0; - } - - zval_ptr_dtor(rval); - *rval = *rval_ref; - (*rval)->refcount++; - (*rval)->is_ref = 1; - - return 1; -} - -"N;" { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_NULL(*rval); - return 1; -} - -"b:" iv ";" { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_BOOL(*rval, parse_iv(start + 2)); - return 1; -} - -"i:" iv ";" { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_LONG(*rval, parse_iv(start + 2)); - return 1; -} - -"d:" (iv | nv | nvexp) ";" { - *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_DOUBLE(*rval, atof(start + 2)); - return 1; -} - -"s:" iv ":" ["] { - int len; - char *str; - - len = parse_iv(start + 2); - - if (len == 0) { - str = empty_string; - } else { - str = estrndup(YYCURSOR, len); - } - - YYCURSOR += len + 2; - *p = YYCURSOR; - - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 0); - return 1; -} - -"a:" iv ":" "{" { - int elements = parse_iv(start + 2); - - *p = YYCURSOR; - - INIT_PZVAL(*rval); - Z_TYPE_PP(rval) = IS_ARRAY; - ALLOC_HASHTABLE(Z_ARRVAL_PP(rval)); - - zend_hash_init(Z_ARRVAL_PP(rval), elements + 1, NULL, ZVAL_PTR_DTOR, 0); - - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements)) { - return 0; - } - - return finish_nested_data(UNSERIALIZE_PASSTHRU); -} - -"o:" iv ":" ["] { - - INIT_PZVAL(*rval); - - return object_common2(UNSERIALIZE_PASSTHRU, - object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR)); -} - -"O:" iv ":" ["] { - int len; - int elements; - int len2; - char *class_name; - zend_class_entry *ce; - int incomplete_class = 0; - - zval *user_func; - zval *retval_ptr; - zval **args[1]; - zval *arg_func_name; - - INIT_PZVAL(*rval); - len2 = len = parse_iv(start + 2); - if (len == 0) - return 0; - - class_name = estrndup(YYCURSOR, len); - YYCURSOR += len; - - while (len-- > 0) { - if (class_name[len] >= 'A' && class_name[len] <= 'Z') { - class_name[len] = class_name[len] - 'A' + 'a'; - } - } - - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { - if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { - MAKE_STD_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - - args[0] = &arg_func_name; - MAKE_STD_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); - - if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { - if (zend_hash_find(CG(class_table), class_name, len2 + 1, (void **) &ce) != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "(%s) hasn't defined the class it was called for", user_func->value.str.val); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } - } - } - } else { -#ifdef ZEND_ENGINE_2 - ce = *(zend_class_entry **)ce; /* Bad hack, TBF! */ -#endif - efree(class_name); - } - - *p = YYCURSOR; - elements = object_common1(UNSERIALIZE_PASSTHRU, ce); - - if (incomplete_class) { - php_store_class_name(*rval, class_name, len2); - efree(class_name); - } - - return object_common2(UNSERIALIZE_PASSTHRU, elements); -} - -"}" { - /* this is the case where we have less data than planned */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data"); - return 0; /* not sure if it should be 0 or 1 here? */ -} - -any { return 0; } - -*/ - - return 0; -} diff --git a/ext/standard/versioning.c b/ext/standard/versioning.c deleted file mode 100644 index f611a8bc81..0000000000 --- a/ext/standard/versioning.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 4 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.02 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.php.net/license/2_02.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdio.h> -#include <sys/types.h> -#include <ctype.h> -#include <stdlib.h> -#include <string.h> -#include "php.h" -#include "php_versioning.h" - -#define sign(n) ((n)<0?-1:((n)>0?1:0)) - -/* {{{ php_canonicalize_version() */ - -PHPAPI char * -php_canonicalize_version(const char *version) -{ - int len = strlen(version); - char *buf = emalloc(len * 2 + 1), *q, lp, lq; - const char *p; - - if (len == 0) { - *buf = '\0'; - return buf; - } - - p = version; - q = buf; - *q++ = lp = *p++; - lq = '\0'; - while (*p) { -/* s/[-_+]/./g; - * s/([^\d\.])([^\D\.])/$1.$2/g; - * s/([^\D\.])([^\d\.])/$1.$2/g; - */ -#define isdig(x) (isdigit(x)&&(x)!='.') -#define isndig(x) (!isdigit(x)&&(x)!='.') -#define isspecialver(x) ((x)=='-'||(x)=='_'||(x)=='+') - - lq = *(q - 1); - if (isspecialver(*p)) { - if (lq != '.') { - lq = *q++ = '.'; - } - } else if ((isndig(lp) && isdig(*p)) || (isdig(lp) && isndig(*p))) { - if (lq != '.') { - *q++ = '.'; - } - lq = *q++ = *p; - } else if (!isalnum(*p)) { - if (lq != '.') { - lq = *q++ = '.'; - } - } else { - lq = *q++ = *p; - } - lp = *p++; - } - *q++ = '\0'; - return buf; -} - -/* }}} */ -/* {{{ compare_special_version_forms() */ - -typedef struct { - const char *name; - int order; -} special_forms_t; - -static int -compare_special_version_forms(char *form1, char *form2) -{ - int found1 = -1, found2 = -1; - special_forms_t special_forms[9] = { - {"dev", 0}, - {"alpha", 1}, - {"a", 1}, - {"beta", 2}, - {"b", 2}, - {"RC", 3}, - {"#", 4}, - {"pl", 5}, - {NULL, 0}, - }; - special_forms_t *pp; - - for (pp = special_forms; pp && pp->name; pp++) { - if (strncmp(form1, pp->name, strlen(pp->name)) == 0) { - found1 = pp->order; - break; - } - } - for (pp = special_forms; pp && pp->name; pp++) { - if (strncmp(form2, pp->name, strlen(pp->name)) == 0) { - found2 = pp->order; - break; - } - } - return sign(found1 - found2); -} - -/* }}} */ -/* {{{ php_version_compare() */ - -PHPAPI int -php_version_compare(const char *orig_ver1, const char *orig_ver2) -{ - char *ver1; - char *ver2; - char *p1, *p2, *n1, *n2; - long l1, l2; - int compare = 0; - - if (!*orig_ver1 || !*orig_ver2) { - if (!*orig_ver1 && !*orig_ver2) { - return 0; - } else { - return *orig_ver1 ? 1 : -1; - } - } - if (orig_ver1[0] == '#') { - ver1 = estrdup(orig_ver1); - } else { - ver1 = php_canonicalize_version(orig_ver1); - } - if (orig_ver2[0] == '#') { - ver2 = estrdup(orig_ver2); - } else { - ver2 = php_canonicalize_version(orig_ver2); - } - p1 = n1 = ver1; - p2 = n2 = ver2; - while (*p1 && *p2 && n1 && n2) { - if ((n1 = strchr(p1, '.')) != NULL) { - *n1 = '\0'; - } - if ((n2 = strchr(p2, '.')) != NULL) { - *n2 = '\0'; - } - if (isdigit(*p1) && isdigit(*p2)) { - /* compare element numerically */ - l1 = strtol(p1, NULL, 10); - l2 = strtol(p2, NULL, 10); - compare = sign(l1 - l2); - } else if (!isdigit(*p1) && !isdigit(*p2)) { - /* compare element names */ - compare = compare_special_version_forms(p1, p2); - } else { - /* mix of names and numbers */ - if (isdigit(*p1)) { - compare = compare_special_version_forms("#N#", p2); - } else { - compare = compare_special_version_forms(p1, "#N#"); - } - } - if (compare != 0) { - break; - } - if (n1 != NULL) { - p1 = n1 + 1; - } - if (n2 != NULL) { - p2 = n2 + 1; - } - } - if (compare == 0) { - if (n1 != NULL) { - if (isdigit(*p1)) { - compare = 1; - } else { - compare = php_version_compare(p1, "#N#"); - } - } else if (n2 != NULL) { - if (isdigit(*p2)) { - compare = -1; - } else { - compare = php_version_compare("#N#", p2); - } - } - } - efree(ver1); - efree(ver2); - return compare; -} - -/* }}} */ -/* {{{ do_version_compare() */ - -/* {{{ proto int version_compare(string ver1, string ver2 [, string oper]) - Compares two "PHP-standardized" version number strings */ - -PHP_FUNCTION(version_compare) -{ - char *v1, *v2, *op; - int v1_len, v2_len, op_len; - int compare, argc; - - argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "ss|s", &v1, &v1_len, &v2, - &v2_len, &op, &op_len) == FAILURE) { - return; - } - compare = php_version_compare(v1, v2); - if (argc == 2) { - RETURN_LONG(compare); - } - if (!strncmp(op, "<", op_len) || !strncmp(op, "lt", op_len)) { - RETURN_BOOL(compare == -1); - } - if (!strncmp(op, "<=", op_len) || !strncmp(op, "le", op_len)) { - RETURN_BOOL(compare != 1); - } - if (!strncmp(op, ">", op_len) || !strncmp(op, "gt", op_len)) { - RETURN_BOOL(compare == 1); - } - if (!strncmp(op, ">=", op_len) || !strncmp(op, "ge", op_len)) { - RETURN_BOOL(compare != -1); - } - if (!strncmp(op, "==", op_len) || !strncmp(op, "=", op_len) || !strncmp(op, "eq", op_len)) { - RETURN_BOOL(compare == 0); - } - if (!strncmp(op, "!=", op_len) || !strncmp(op, "<>", op_len) || !strncmp(op, "ne", op_len)) { - RETURN_BOOL(compare != 0); - } - RETURN_NULL(); -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * indent-tabs-mode: t - * End: - */ |