diff options
Diffstat (limited to 'ext/standard')
95 files changed, 0 insertions, 28623 deletions
diff --git a/ext/standard/Makefile.in b/ext/standard/Makefile.in deleted file mode 100644 index 4d48fd63a2..0000000000 --- a/ext/standard/Makefile.in +++ /dev/null @@ -1,17 +0,0 @@ - -LTLIBRARY_NAME = libstandard.la -LTLIBRARY_SOURCES=\ - array.c base64.c basic_functions.c browscap.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 output.c assert.c \ - strnatcmp.c levenshtein.c - -include $(top_srcdir)/build/dynlib.mk - -parsedate.c: $(srcdir)/parsedate.y - -$(srcdir)/url_scanner.c: $(srcdir)/url_scanner.re - -re2c $< > $@.new && mv $@.new $@ diff --git a/ext/standard/array.c b/ext/standard/array.c deleted file mode 100644 index 7819046a51..0000000000 --- a/ext/standard/array.c +++ /dev/null @@ -1,2416 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@ispi.net> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_ini.h" -#include "zend_operators.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" - -#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 SORT_DESC -1 -#define SORT_ASC 1 - -#define SORT_REGULAR 0 -#define SORT_NUMERIC 1 -#define SORT_STRING 2 - -PHP_MINIT_FUNCTION(array) -{ -#ifdef ZTS - array_globals_id = ts_allocate_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("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); - - 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) -{ - ARRAYLS_FETCH(); - - 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) -{ - Bucket *f; - Bucket *s; - pval result; - pval first; - pval second; - ARRAYLS_FETCH(); - - f = *((Bucket **) a); - s = *((Bucket **) b); - - if (f->nKeyLength == 0) { - first.type = IS_LONG; - first.value.lval = f->h; - } else { - first.type = IS_STRING; - first.value.str.val = f->arKey; - first.value.str.len = f->nKeyLength; - } - - if (s->nKeyLength == 0) { - second.type = IS_LONG; - second.value.lval = s->h; - } else { - second.type = IS_STRING; - second.value.str.val = s->arKey; - second.value.str.len = s->nKeyLength; - } - - if (ARRAYG(compare_func)(&result, &first, &second) == FAILURE) { - return 0; - } - - if (result.type == IS_DOUBLE) { - if (result.value.dval < 0) { - return -1; - } else if (result.value.dval > 0) { - return 1; - } else { - return 0; - } - } - - convert_to_long(&result); - - if (result.value.lval < 0) { - return -1; - } else if (result.value.lval > 0) { - return 1; - } - - return 0; -} - -static int array_reverse_key_compare(const void *a, const void *b) -{ - return array_key_compare(a,b)*-1; -} - -/* {{{ proto int krsort(array array_arg) - Sort an array reverse by key */ -PHP_FUNCTION(krsort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in krsort() call"); - return; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_reverse_key_compare, 0) == FAILURE) { - return; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int ksort(array array_arg) - Sort an array by key */ -PHP_FUNCTION(ksort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in ksort() call"); - return; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_key_compare,0) == FAILURE) { - return; - } - RETURN_TRUE; -} - -/* {{{ proto int count(mixed var) - Count the number of elements in a variable (usually an array) */ -PHP_FUNCTION(count) -{ - pval **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) { - if ((*array)->type == IS_NULL) { - RETURN_LONG(0); - } else { - RETURN_LONG(1); - } - } - - RETURN_LONG(zend_hash_num_elements(target_hash)); -} -/* }}} */ - -/* 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. - */ -static int array_data_compare(const void *a, const void *b) -{ - Bucket *f; - Bucket *s; - pval result; - pval *first; - pval *second; - ARRAYLS_FETCH(); - - f = *((Bucket **) a); - s = *((Bucket **) b); - - first = *((pval **) f->pData); - second = *((pval **) s->pData); - - if (ARRAYG(compare_func)(&result, first, second) == FAILURE) { - return 0; - } - - if (result.type == IS_DOUBLE) { - if (result.value.dval < 0) { - return -1; - } else if (result.value.dval > 0) { - return 1; - } else { - return 0; - } - } - - convert_to_long(&result); - - if (result.value.lval < 0) { - return -1; - } else if (result.value.lval > 0) { - return 1; - } - - return 0; -} - -static int array_reverse_data_compare(const void *a, const void *b) -{ - return array_data_compare(a,b)*-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 (fval->type != IS_STRING) { - zval_copy_ctor(&first); - convert_to_string(&first); - } - if (sval->type != IS_STRING) { - zval_copy_ctor(&first); - convert_to_string(&second); - } - - result = strnatcmp_ex(first.value.str.val, first.value.str.len, - second.value.str.val, second.value.str.len, fold_case); - - if (fval->type != IS_STRING) - zval_dtor(&first); - if (sval->type != IS_STRING) - zval_dtor(&second); - - return result; -} - -static int array_natural_compare(const void *a, const void *b) -{ - return array_natural_general_compare(a, b, 0); -} - -static int array_natural_case_compare(const void *a, const void *b) -{ - 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(E_WARNING, "Wrong datatype in %s() call", - get_active_function_name()); - return; - } - - if (fold_case) { - if (zend_hash_sort(target_hash, qsort, array_natural_case_compare, 0) == FAILURE) { - return; - } - } else { - if (zend_hash_sort(target_hash, qsort, array_natural_compare, 0) == 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 void asort(array array_arg) - Sort an array and maintain index association */ -PHP_FUNCTION(asort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in asort() call"); - return; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_data_compare,0) == FAILURE) { - return; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void arsort(array array_arg) - Sort an array in reverse order and maintain index association */ -PHP_FUNCTION(arsort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in arsort() call"); - RETURN_FALSE; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare,0) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void sort(array array_arg) - Sort an array */ -PHP_FUNCTION(sort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in sort() call"); - RETURN_FALSE; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_data_compare,1) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void rsort(array array_arg) - Sort an array in reverse order */ -PHP_FUNCTION(rsort) -{ - zval **array, **sort_type; - int sort_type_val = SORT_REGULAR; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in rsort() call"); - RETURN_FALSE; - } - if (ZEND_NUM_ARGS() == 2) { - convert_to_long_ex(sort_type); - sort_type_val = Z_LVAL_PP(sort_type); - } - set_compare_func(sort_type_val); - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare,1) == FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} - - -static int array_user_compare(const void *a, const void *b) -{ - Bucket *f; - Bucket *s; - pval **args[2]; - pval *retval_ptr; - CLS_FETCH(); - BLS_FETCH(); - - f = *((Bucket **) a); - s = *((Bucket **) b); - - args[0] = (pval **) f->pData; - args[1] = (pval **) s->pData; - - if (call_user_function_ex(CG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0)==SUCCESS - && retval_ptr) { - long retval; - - convert_to_long_ex(&retval_ptr); - retval = retval_ptr->value.lval; - zval_ptr_dtor(&retval_ptr); - return retval; - } else { - return 0; - } -} - -/* {{{ proto void usort(array array_arg, string cmp_function) - Sort an array by values using a user-defined comparison function */ -PHP_FUNCTION(usort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - 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(E_WARNING, "Wrong datatype in usort() call"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto void uasort(array array_arg, string cmp_function) - Sort an array with a user-defined comparison function and maintain index association */ -PHP_FUNCTION(uasort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - 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(E_WARNING, "Wrong datatype in uasort() call"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == 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) -{ - Bucket *f; - Bucket *s; - pval key1, key2; - pval *args[2]; - pval retval; - int status; - CLS_FETCH(); - BLS_FETCH(); - - args[0] = &key1; - args[1] = &key2; - INIT_PZVAL(&key1); - INIT_PZVAL(&key2); - - f = *((Bucket **) a); - s = *((Bucket **) b); - - if (f->nKeyLength) { - key1.value.str.val = estrndup(f->arKey, f->nKeyLength); - key1.value.str.len = f->nKeyLength-1; - key1.type = IS_STRING; - } else { - key1.value.lval = f->h; - key1.type = IS_LONG; - } - if (s->nKeyLength) { - key2.value.str.val = estrndup(s->arKey, s->nKeyLength); - key2.value.str.len = s->nKeyLength-1; - key2.type = IS_STRING; - } else { - key2.value.lval = s->h; - key2.type = IS_LONG; - } - - status = call_user_function(CG(function_table), NULL, *BG(user_compare_func_name), &retval, 2, args); - - zval_dtor(&key1); - zval_dtor(&key2); - - if (status==SUCCESS) { - convert_to_long(&retval); - return retval.value.lval; - } else { - return 0; - } -} - -/* {{{ proto void uksort(array array_arg, string cmp_function) - Sort an array by keys using a user-defined comparison function */ -PHP_FUNCTION(uksort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - 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(E_WARNING, "Wrong datatype in uksort() call"); - BG(user_compare_func_name) = old_compare_func; - RETURN_FALSE; - } - if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == 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(E_WARNING, "Variable passed to end() 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(E_WARNING, "Variable passed to prev() 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(E_WARNING, "Variable passed to next() 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(E_WARNING, "Variable passed to reset() 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(E_WARNING, "Variable passed to current() 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; - 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(E_WARNING, "Variable passed to key() is not an array or object"); - RETURN_FALSE; - } - switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - return_value->value.str.val = string_key; - return_value->value.str.len = strlen(string_key); - return_value->type = IS_STRING; - break; - case HASH_KEY_IS_LONG: - return_value->type = IS_LONG; - return_value->value.lval = num_key; - break; - case HASH_KEY_NON_EXISTANT: - return; - } -} -/* }}} */ - -/* {{{ proto mixed min(mixed arg1 [, mixed arg2 [, ...]]) - 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(E_WARNING, "min: must be passed at least 1 value"); - RETURN_NULL(); - } - set_compare_func(SORT_REGULAR); - if (argc == 1) { - pval **arr; - - if (zend_get_parameters_ex(1, &arr) == FAILURE || (*arr)->type != IS_ARRAY) { - WRONG_PARAM_COUNT; - } - if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 0, (void **) &result)==SUCCESS) { - *return_value = **result; - zval_copy_ctor(return_value); - } else { - php_error(E_WARNING, "min: array must contain at least 1 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); - if (result.value.lval == 1) { - min = args[i]; - } - } - - *return_value = **min; - zval_copy_ctor(return_value); - - efree(args); - } -} -/* }}} */ - -/* {{{ proto mixed max(mixed arg1 [, mixed arg2 [, ...]]) - 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(E_WARNING, "max: must be passed at least 1 value"); - RETURN_NULL(); - } - set_compare_func(SORT_REGULAR); - if (argc == 1) { - pval **arr; - - if (zend_get_parameters_ex(1, &arr) == FAILURE || (*arr)->type != IS_ARRAY) { - WRONG_PARAM_COUNT; - } - if (zend_hash_minmax((*arr)->value.ht, array_data_compare, 1, (void **) &result)==SUCCESS) { - *return_value = **result; - zval_copy_ctor(return_value); - } else { - php_error(E_WARNING, "max: array must contain at least 1 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); - if (result.value.lval == 0) { - max = args[i]; - } - } - - *return_value = **max; - zval_copy_ctor(return_value); - - efree(args); - } -} -/* }}} */ - -static int php_array_walk(HashTable *target_hash, zval **userdata) -{ - zval **args[3], /* Arguments to userland function */ - *retval_ptr, /* Return value - unused */ - *key; /* Entry key */ - char *string_key; - ulong num_key; - CLS_FETCH(); - BLS_FETCH(); - - /* Allocate space for key */ - MAKE_STD_ZVAL(key); - - /* Set up known arguments */ - args[1] = &key; - args[2] = userdata; - - zend_hash_internal_pointer_reset(target_hash); - - /* Iterate through hash */ - while(zend_hash_get_current_data(target_hash, (void **)&args[0]) == SUCCESS) { - /* Set up the key */ - if (zend_hash_get_current_key(target_hash, &string_key, &num_key) == HASH_KEY_IS_LONG) { - key->type = IS_LONG; - key->value.lval = num_key; - } else { - key->type = IS_STRING; - key->value.str.val = string_key; - key->value.str.len = strlen(string_key); - } - - /* Call the userland function */ - if (call_user_function_ex(CG(function_table), NULL, *BG(array_walk_func_name), - &retval_ptr, userdata ? 3 : 2, args, 0) == SUCCESS) { - - zval_ptr_dtor(&retval_ptr); - } else - php_error(E_WARNING,"Unable to call %s() - function does not exist", - (*BG(array_walk_func_name))->value.str.val); - - /* Clean up the key */ - if (zend_hash_get_current_key_type(target_hash) == HASH_KEY_IS_STRING) - efree(key->value.str.val); - - zend_hash_move_forward(target_hash); - } - efree(key); - - return 0; -} - -/* {{{ proto int 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; - BLS_FETCH(); - - 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(E_WARNING, "Wrong datatype in array_walk() call"); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_FALSE; - } - convert_to_string_ex(BG(array_walk_func_name)); - php_array_walk(target_hash, userdata); - BG(array_walk_func_name) = old_walk_func_name; - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto bool in_array(mixed needle, array haystack [, bool strict]) - Checks if the given value exists in the array */ -PHP_FUNCTION(in_array) -{ - 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 */ - int (*compare_func)(zval *, zval *, zval *) = 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; - } - - if ((*value)->type == IS_ARRAY || (*value)->type == IS_OBJECT) { - php_error(E_WARNING, "Wrong datatype for first argument in call to in_array()"); - RETURN_FALSE; - } - - if ((*array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype for second argument in call to in_array()"); - RETURN_FALSE; - } - - if (ZEND_NUM_ARGS() == 3) { - convert_to_boolean_ex(strict); - if (Z_LVAL_PP(strict) == 1) - compare_func = is_identical_function; - } - - target_hash = HASH_OF(*array); - zend_hash_internal_pointer_reset(target_hash); - while(zend_hash_get_current_data(target_hash, (void **)&entry) == SUCCESS) { - compare_func(&res, *value, *entry); - if (Z_LVAL(res) == 1) { - RETURN_TRUE; - } - - zend_hash_move_forward(target_hash); - } - - RETURN_FALSE; -} -/* }}} */ - - -/* {{{ int _valid_var_name(char *varname) */ -static int _valid_var_name(char *varname) -{ - int len, i; - - if (!varname) - return 0; - - len = strlen(varname); - - if (!isalpha((int)varname[0]) && varname[0] != '_') - return 0; - - if (len > 1) { - for(i=1; i<len; i++) { - if (!isalnum((int)varname[i]) && varname[i] != '_') { - return 0; - } - } - } - - return 1; -} -/* }}} */ - - -/* {{{ proto void extract(array var_array, int extract_type [, string prefix]) - Imports variables into symbol table from an array */ -PHP_FUNCTION(extract) -{ - zval **var_array, **etype, **prefix; - zval **entry, *data; - char *varname, *finalname; - ulong lkey; - int res, extype; - - switch(ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &var_array) == FAILURE) { - WRONG_PARAM_COUNT; - } - extype = EXTR_OVERWRITE; - break; - - case 2: - if (zend_get_parameters_ex(2, &var_array, &etype) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(etype); - extype = (*etype)->value.lval; - if (extype > EXTR_SKIP && extype <= EXTR_PREFIX_ALL) { - WRONG_PARAM_COUNT; - } - break; - - case 3: - if (zend_get_parameters_ex(3, &var_array, &etype, &prefix) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(etype); - extype = (*etype)->value.lval; - convert_to_string_ex(prefix); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - if (extype < EXTR_OVERWRITE || extype > EXTR_PREFIX_ALL) { - php_error(E_WARNING, "Wrong argument in call to extract()"); - RETURN_FALSE; - } - - if ((*var_array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype in call to extract()"); - RETURN_FALSE; - } - - zend_hash_internal_pointer_reset((*var_array)->value.ht); - while(zend_hash_get_current_data((*var_array)->value.ht, (void **)&entry) == SUCCESS) { - - if (zend_hash_get_current_key((*var_array)->value.ht, &varname, &lkey) == HASH_KEY_IS_STRING) { - - if (_valid_var_name(varname)) { - finalname = NULL; - - res = zend_hash_exists(EG(active_symbol_table), varname, strlen(varname)+1); - switch (extype) { - case EXTR_OVERWRITE: - finalname = estrdup(varname); - break; - - case EXTR_PREFIX_SAME: - if (!res) - finalname = estrdup(varname); - /* break omitted intentionally */ - - case EXTR_PREFIX_ALL: - if (!finalname) { - finalname = emalloc(strlen(varname) + (*prefix)->value.str.len + 2); - strcpy(finalname, (*prefix)->value.str.val); - strcat(finalname, "_"); - strcat(finalname, varname); - } - break; - - default: - if (!res) - finalname = estrdup(varname); - break; - } - - if (finalname) { - MAKE_STD_ZVAL(data); - *data = **entry; - zval_copy_ctor(data); - - ZEND_SET_SYMBOL(EG(active_symbol_table), finalname, data); - efree(finalname); - } - } - - efree(varname); - } - - zend_hash_move_forward((*var_array)->value.ht); - } -} -/* }}} */ - - -/* {{{ void _compact_var(HashTable *eg_active_symbol_table, zval *return_value, zval *entry) */ -static void _compact_var(HashTable *eg_active_symbol_table, zval *return_value, zval *entry) -{ - zval **value_ptr, *value, *data; - - if (entry->type == IS_STRING) { - if (zend_hash_find(eg_active_symbol_table, entry->value.str.val, - entry->value.str.len+1, (void **)&value_ptr) != FAILURE) { - value = *value_ptr; - ALLOC_ZVAL(data); - *data = *value; - zval_copy_ctor(data); - INIT_PZVAL(data); - - zend_hash_update(return_value->value.ht, entry->value.str.val, - entry->value.str.len+1, &data, sizeof(zval *), NULL); - } - } - else if (entry->type == IS_ARRAY) { - zend_hash_internal_pointer_reset(entry->value.ht); - - while(zend_hash_get_current_data(entry->value.ht, (void**)&value_ptr) == SUCCESS) { - value = *value_ptr; - - _compact_var(eg_active_symbol_table, return_value, value); - zend_hash_move_forward(entry->value.ht); - } - } -} -/* }}} */ - - -/* {{{ proto array compact(mixed var_names [, ... ]) - 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++) - { - _compact_var(EG(active_symbol_table), return_value, *args[i]); - } - - efree(args); -} -/* }}} */ - -/* {{{ proto array range(int low, int high) - Create an array containing the range of integers from low to high (inclusive) */ -PHP_FUNCTION(range) -{ - zval **zlow, **zhigh; - int low, high; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2,&zlow,&zhigh) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(zlow); - convert_to_long_ex(zhigh); - low = (*zlow)->value.lval; - high = (*zhigh)->value.lval; - - /* allocate an array for return */ - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - for (; low <= high; low++) { - add_next_index_long(return_value, low); - } -} -/* }}} */ - - -static int array_data_shuffle(const void *a, const void*b) { - return ( - /* This is just a little messy. */ -#ifdef HAVE_LRAND48 - lrand48() -#else -#ifdef HAVE_RANDOM - random() -#else - rand() -#endif -#endif - % 2) ? 1 : -1; -} - - -/* {{{ proto int shuffle(array array_arg) - Randomly shuffle the contents of an array */ -PHP_FUNCTION(shuffle) -{ - zval **array; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if ((*array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype in shuffle() call"); - RETURN_FALSE; - } - if (zend_hash_sort((*array)->value.ht, (sort_func_t)mergesort, array_data_shuffle, 1) == FAILURE) { - RETURN_FALSE; - } - 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 */ - out_hash = (HashTable *)emalloc(sizeof(HashTable)); - 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]; - 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 [, ...]) - 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 (stack->type != IS_ARRAY) { - php_error(E_WARNING, "First argument to array_push() needs to be an array"); - 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(stack->value.ht, &new_var, sizeof(zval *), NULL); - } - - /* Clean up and return the number of values in the stack */ - efree(args); - RETVAL_LONG(zend_hash_num_elements(stack->value.ht)); -} -/* }}} */ - - -/* {{{ 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 */ - HashTable *new_hash; /* New stack */ - - /* Get the arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &stack) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*stack)->type != IS_ARRAY) { - php_error(E_WARNING, "The argument needs to be an array"); - return; - } - - if (zend_hash_num_elements((*stack)->value.ht) == 0) { - return; - } - - /* Get the first or last value and copy it into the return value */ - if (off_the_end) - zend_hash_internal_pointer_end((*stack)->value.ht); - else - zend_hash_internal_pointer_reset((*stack)->value.ht); - zend_hash_get_current_data((*stack)->value.ht, (void **)&val); - *return_value = **val; - zval_copy_ctor(return_value); - INIT_PZVAL(return_value); - - /* Delete the first or last value */ - new_hash = php_splice((*stack)->value.ht, (off_the_end) ? -1 : 0, 1, NULL, 0, NULL); - zend_hash_destroy((*stack)->value.ht); - efree((*stack)->value.ht); - (*stack)->value.ht = new_hash; -} -/* }}} */ - - -/* {{{ 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 [, ...]) - 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 (stack->type != IS_ARRAY) { - php_error(E_WARNING, "First argument to array_unshift() needs to be an array"); - RETURN_FALSE; - } - - /* Use splice to insert the elements at the beginning. Destroy old - hashtable and replace it with new one */ - new_hash = php_splice(stack->value.ht, 0, 0, &args[1], argc-1, NULL); - zend_hash_destroy(stack->value.ht); - efree(stack->value.ht); - stack->value.ht = new_hash; - - /* Clean up and return the number of elements in the stack */ - efree(args); - RETVAL_LONG(zend_hash_num_elements(stack->value.ht)); -} -/* }}} */ - - -/* {{{ 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 (array->type != IS_ARRAY) { - php_error(E_WARNING, "First argument to array_splice() 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 = (*args[1])->value.lval; - if (argc > 2) { - convert_to_long_ex(args[2]); - length = (*args[2])->value.lval; - } else - length = zend_hash_num_elements(array->value.ht); - - 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((*args[3])->value.ht); - repl = (zval ***)emalloc(repl_num * sizeof(zval **)); - for (p=(*args[3])->value.ht->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(array->value.ht, offset, length, - repl, repl_num, - &return_value->value.ht); - - /* Replace input array's hashtable with the new one */ - zend_hash_destroy(array->value.ht); - efree(array->value.ht); - array->value.ht = 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; - ulong num_key; - - - /* 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 ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "First argument to array_slice() 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 = (*offset)->value.lval; - if (argc == 3) { - convert_to_long_ex(length); - length_val = (*length)->value.lval; - } else - length_val = zend_hash_num_elements((*input)->value.ht); - - /* Initialize returned array */ - array_init(return_value); - - /* Get number of entries in the input hash */ - num_in = zend_hash_num_elements((*input)->value.ht); - - /* 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((*input)->value.ht); - while(pos < offset_val && - zend_hash_get_current_data((*input)->value.ht, (void **)&entry) == SUCCESS) { - pos++; - zend_hash_move_forward((*input)->value.ht); - } - - /* Copy elements from input array to the one that's returned */ - while(pos < offset_val+length_val && - zend_hash_get_current_data((*input)->value.ht, (void **)&entry) == SUCCESS) { - - (*entry)->refcount++; - - switch (zend_hash_get_current_key((*input)->value.ht, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - zend_hash_update(return_value->value.ht, string_key, strlen(string_key)+1, - entry, sizeof(zval *), NULL); - efree(string_key); - break; - - case HASH_KEY_IS_LONG: - zend_hash_next_index_insert(return_value->value.ht, - entry, sizeof(zval *), NULL); - break; - } - pos++; - zend_hash_move_forward((*input)->value.ht); - } -} -/* }}} */ - - -static void php_array_merge_impl(HashTable *dest, HashTable *src, int recursive) -{ - zval **src_entry, - **dest_entry; - char *string_key; - ulong num_key; - - zend_hash_internal_pointer_reset(src); - while(zend_hash_get_current_data(src, (void **)&src_entry) == SUCCESS) { - switch (zend_hash_get_current_key(src, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - if (recursive && - zend_hash_find(dest, string_key, strlen(string_key) + 1, - (void **)&dest_entry) == SUCCESS) { - convert_to_array_ex(dest_entry); - convert_to_array_ex(src_entry); - php_array_merge_impl(Z_ARRVAL_PP(dest_entry), - Z_ARRVAL_PP(src_entry), recursive); - } else { - (*src_entry)->refcount++; - - zend_hash_update(dest, string_key, strlen(string_key)+1, - src_entry, sizeof(zval *), NULL); - } - efree(string_key); - 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(src); - } -} - -static void php_array_merge(INTERNAL_FUNCTION_PARAMETERS, int recursive) -{ - zval ***args = NULL; - int argc, - i; - - /* 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; - } - - array_init(return_value); - - for (i=0; i<argc; i++) { - convert_to_array_ex(args[i]); - php_array_merge_impl(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive); - } - - efree(args); -} - - -/* {{{ proto array array_merge(array arr1, array arr2 [, ...]) - Merges elements from passed arrays into one array */ -PHP_FUNCTION(array_merge) -{ - php_array_merge(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - - -/* {{{ proto array array_merge(array arr1, array arr2 [, ...]) - Recursively merges elements from passed arrays into one array */ -PHP_FUNCTION(array_merge_recursive) -{ - php_array_merge(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 */ - ulong num_key; /* Numeric key */ - - 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 ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "First argument to array_keys() 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((*input)->value.ht); - while(zend_hash_get_current_data((*input)->value.ht, (void **)&entry) == SUCCESS) { - if (search_value != NULL) { - is_equal_function(&res, *search_value, *entry); - add_key = zval_is_true(&res); - } - - if (add_key) { - MAKE_STD_ZVAL(new_val); - - switch (zend_hash_get_current_key((*input)->value.ht, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - new_val->type = IS_STRING; - new_val->value.str.val = string_key; - new_val->value.str.len = strlen(string_key); - zend_hash_next_index_insert(return_value->value.ht, &new_val, - sizeof(zval *), NULL); - break; - - case HASH_KEY_IS_LONG: - new_val->type = IS_LONG; - new_val->value.lval = num_key; - zend_hash_next_index_insert(return_value->value.ht, &new_val, - sizeof(zval *), NULL); - break; - } - } - - zend_hash_move_forward((*input)->value.ht); - } -} -/* }}} */ - - -/* {{{ 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 */ - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "Argument to array_values() 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((*input)->value.ht); - while(zend_hash_get_current_data((*input)->value.ht, (void **)&entry) == SUCCESS) { - - (*entry)->refcount++; - zend_hash_next_index_insert(return_value->value.ht, entry, - sizeof(zval *), NULL); - - zend_hash_move_forward((*input)->value.ht); - } -} -/* }}} */ - - -/* {{{ 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; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "Argument to array_count_values() should be an array"); - return; - } - - /* Initialize return array */ - array_init(return_value); - - /* Go through input array and add values to the return array */ - myht = (*input)->value.ht; - zend_hash_internal_pointer_reset(myht); - while (zend_hash_get_current_data(myht, (void **)&entry) == SUCCESS) { - if ((*entry)->type == IS_LONG) { - if (zend_hash_index_find(return_value->value.ht, - (*entry)->value.lval, - (void**)&tmp) == FAILURE) { - zval *data; - MAKE_STD_ZVAL(data); - data->type = IS_LONG; - data->value.lval = 1; - zend_hash_index_update(return_value->value.ht,(*entry)->value.lval, &data, sizeof(data), NULL); - } else { - (*tmp)->value.lval++; - } - } else if ((*entry)->type == IS_STRING) { - if (zend_hash_find(return_value->value.ht, - (*entry)->value.str.val, - (*entry)->value.str.len+1, - (void**)&tmp) == FAILURE) { - zval *data; - MAKE_STD_ZVAL(data); - data->type = IS_LONG; - data->value.lval = 1; - zend_hash_update(return_value->value.ht,(*entry)->value.str.val,(*entry)->value.str.len + 1, &data, sizeof(data), NULL); - } else { - (*tmp)->value.lval++; - } - } else { - php_error(E_WARNING, "Can only count STRING and INTEGER values!"); - } - - zend_hash_move_forward(myht); - } -} -/* }}} */ - - -/* {{{ proto array array_reverse(array input) - Return input as a new array with the order of the entries reversed */ -PHP_FUNCTION(array_reverse) -{ - zval **input, /* Input array */ - **entry; /* An entry in the input array */ - char *string_key; - ulong num_key; - - /* Get arguments and do error-checking */ - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &input) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "Argument to array_reverse() should be an array"); - return; - } - - /* Initialize return array */ - array_init(return_value); - - zend_hash_internal_pointer_end((*input)->value.ht); - while(zend_hash_get_current_data((*input)->value.ht, (void **)&entry) == SUCCESS) { - (*entry)->refcount++; - - switch (zend_hash_get_current_key((*input)->value.ht, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - zend_hash_update(return_value->value.ht, string_key, strlen(string_key)+1, - entry, sizeof(zval *), NULL); - efree(string_key); - break; - - case HASH_KEY_IS_LONG: - zend_hash_next_index_insert(return_value->value.ht, - entry, sizeof(zval *), NULL); - break; - } - - zend_hash_move_backwards((*input)->value.ht); - } -} -/* }}} */ - - -/* {{{ 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 ((*input)->type != IS_ARRAY) { - php_error(E_WARNING, "Argument to %s() should be an array", - get_active_function_name()); - return; - } - convert_to_long_ex(pad_size); - - /* Do some initial calculations */ - input_size = zend_hash_num_elements((*input)->value.ht); - pad_size_abs = abs((*pad_size)->value.lval); - 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 ((*pad_size)->value.lval > 0) - new_hash = php_splice(return_value->value.ht, input_size, 0, pads, num_pads, NULL); - else - new_hash = php_splice(return_value->value.ht, 0, 0, pads, num_pads, NULL); - - - /* Copy the result hash into return value */ - zend_hash_destroy(return_value->value.ht); - efree(return_value->value.ht); - return_value->value.ht = 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; - ulong num_key; - - 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(E_WARNING, "Wrong datatype in array_flip() call"); - RETURN_FALSE; - } - - array_init(return_value); - - zend_hash_internal_pointer_reset(target_hash); - while (zend_hash_get_current_data(target_hash, (void **)&entry) == SUCCESS) { - MAKE_STD_ZVAL(data); - switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - data->value.str.val = string_key; - data->value.str.len = strlen(string_key); - data->type = IS_STRING; - break; - case HASH_KEY_IS_LONG: - data->type = IS_LONG; - data->value.lval = num_key; - break; - } - - if ((*entry)->type == IS_LONG) { - zend_hash_index_update(return_value->value.ht,(*entry)->value.lval, &data, sizeof(data), NULL); - } else if ((*entry)->type == IS_STRING) { - zend_hash_update(return_value->value.ht,(*entry)->value.str.val,(*entry)->value.str.len + 1, &data, sizeof(data), NULL); - } else { - zval_dtor(data); - php_error(E_WARNING, "Can only flip STRING and INTEGER values!"); - } - - zend_hash_move_forward(target_hash); - } -} -/* }}} */ - -int multisort_compare(const void *a, const void *b) -{ - Bucket** ab = *(Bucket ***)a; - Bucket** bb = *(Bucket ***)b; - int r; - int result = 0; - zval temp; - ARRAYLS_FETCH(); - - r = 0; - do { - ARRAYG(compare_func)(&temp, *((zval **)ab[r]->pData), *((zval **)bb[r]->pData)); - result = ARRAYG(multisort_flags)[r] * temp.value.lval; - if (result != 0) - return result; - r++; - } while (ab[r] != NULL); - return result; -} - -#define MULTISORT_ABORT \ - efree(ARRAYG(multisort_flags)); \ - efree(arrays); \ - efree(args); \ - RETURN_FALSE; - -/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC] [, array ar2 [, SORT_ASC|SORT_DESC], ...]) - 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 = 0; /* 0 - flag not allowed - 1 - flag allowed */ - int sort_order = SORT_ASC; - int i, k; - ARRAYLS_FETCH(); - - /* 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 **)); - ARRAYG(multisort_flags) = (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 order flag which follows an array. If - not specified, the sort order flag defaults to SORT_ASC. There can't - be two sort order flags in a row, and the very first argument has - to be an array. - */ - for (i = 0; i < argc; i++) { - if ((*args[i])->type == IS_ARRAY) { - /* We see the next array so update the sort order of - the previous array and reset the sort order */ - if (i > 0) { - ARRAYG(multisort_flags)[num_arrays-1] = sort_order; - sort_order = SORT_ASC; - } - arrays[num_arrays++] = args[i]; - - /* next one may be array or sort flag */ - parse_state = 1; - } else if ((*args[i])->type == IS_LONG) { - /* flag allowed here */ - if (parse_state == 1) { - if ((*args[i])->value.lval == SORT_ASC || (*args[i])->value.lval == SORT_DESC) { - /* Save the flag and make sure then next arg is not a flag */ - sort_order = (*args[i])->value.lval; - parse_state = 0; - } else { - php_error(E_WARNING, "Argument %i to %s() is an unknown sort flag", i+1, - get_active_function_name()); - MULTISORT_ABORT; - } - } else { - php_error(E_WARNING, "Argument %i to %s() is expected to be an array", i+1, - get_active_function_name()); - MULTISORT_ABORT; - } - } else { - php_error(E_WARNING, "Argument %i to %s() is expected to be an array or a sort flag", i+1, - get_active_function_name()); - MULTISORT_ABORT; - } - } - /* Take care of the last array sort flag */ - ARRAYG(multisort_flags)[num_arrays-1] = sort_order; - - /* Make sure the arrays are of the same size */ - array_size = zend_hash_num_elements((*arrays[0])->value.ht); - for (i = 0; i < num_arrays; i++) { - if (zend_hash_num_elements((*arrays[i])->value.ht) != array_size) { - php_error(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) { - efree(ARRAYG(multisort_flags)); - 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 = (*arrays[i])->value.ht->pListHead; p; p = p->pListNext, k++) { - indirect[k][i] = p; - } - } - for (k = 0; k < array_size; k++) - indirect[k][num_arrays] = NULL; - - /* For now, assume it's always regular sort. */ - set_compare_func(SORT_REGULAR); - - /* Do the actual sort magic - bada-bim, bada-boom */ - qsort(indirect, array_size, sizeof(Bucket **), multisort_compare); - - /* Restructure the arrays based on sorted indirect - this is mostly - take from zend_hash_sort() function. */ - HANDLE_BLOCK_INTERRUPTIONS(); - for (i = 0; i < num_arrays; i++) { - hash = (*arrays[i])->value.ht; - 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); - efree(ARRAYG(multisort_flags)); - 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; - ulong num_key; - - 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) { - zend_error(E_WARNING, "Argument to %s() has to be an array", - get_active_function_name()); - 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) { - zend_error(E_WARNING, "Second argument to %s() has to be between 1 and the number of elements in the array", get_active_function_name()); - 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(Z_ARRVAL_PP(input)); - while (num_req_val && (key_type = zend_hash_get_current_key(Z_ARRVAL_PP(input), &string_key, &num_key)) != HASH_KEY_NON_EXISTANT) { - -#ifdef HAVE_LRAND48 - randval = lrand48(); -#else -#ifdef HAVE_RANDOM - randval = random(); -#else - randval = rand(); -#endif -#endif - - 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_STRING(string_key, 0); - } else { - RETURN_LONG(num_key); - } - } else { - /* Append the result to the return value. */ - if (key_type == HASH_KEY_IS_STRING) - add_next_index_string(return_value, string_key, 0); - else - add_next_index_long(return_value, num_key); - } - num_req_val--; - } else if (key_type == HASH_KEY_IS_STRING) - efree(string_key); - - num_avail--; - zend_hash_move_forward(Z_ARRVAL_PP(input)); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/assert.c b/ext/standard/assert.c deleted file mode 100644 index b6ea74abe2..0000000000 --- a/ext/standard/assert.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $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; - char *default_callback; - char *callback; -} php_assert_globals; - -#ifdef ZTS -#define ASSERTLS_D php_assert_globals *assert_globals -#define ASSERTLS_DC , ASSERTLS_D -#define ASSERTLS_C assert_globals -#define ASSERTLS_CC , ASSERTLS_CC -#define ASSERT(v) (assert_globals->v) -#define ASSERTLS_FETCH() php_assert_globals *assert_globals = ts_resource(assert_globals_id) -int assert_globals_id; -#else -#define ASSERTLS_D -#define ASSERTLS_DC -#define ASSERTLS_C -#define ASSERTLS_CC -#define ASSERT(v) (assert_globals.v) -#define ASSERTLS_FETCH() -php_assert_globals assert_globals; -#endif - -#define SAFE_STRING(s) ((s)?(s):"") - -#define ASSERT_ACTIVE 1 -#define ASSERT_CALLBACK 2 -#define ASSERT_BAIL 3 -#define ASSERT_WARNING 4 -#define ASSERT_QUIET_EVAL 5 - -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) - STD_PHP_INI_ENTRY("assert.callback", NULL, PHP_INI_ALL, OnUpdateString, default_callback, php_assert_globals, assert_globals) - 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(ASSERTLS_D) -{ - ASSERT(callback) = 0; -} - -PHP_MINIT_FUNCTION(assert) -{ - -#ifdef ZTS - assert_globals_id = ts_allocate_id(sizeof(php_assert_globals), (ts_allocate_ctor) php_assert_init_globals, NULL); -#else - php_assert_init_globals(ASSERTLS_C); -#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) -{ - return SUCCESS; -} - -PHP_RINIT_FUNCTION(assert) -{ - ASSERTLS_FETCH(); - - if (ASSERT(callback)) { - efree(ASSERT(callback)); - ASSERT(callback) = NULL; - } - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(assert) -{ - ASSERTLS_FETCH(); - - if (ASSERT(callback)) { - efree(ASSERT(callback)); - ASSERT(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) -{ - pval **assertion; - int val; - char *myeval = NULL; - char *cbfunc; - CLS_FETCH(); - ASSERTLS_FETCH(); - - if (! ASSERT(active)) { - RETURN_TRUE; - } - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &assertion) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*assertion)->type == IS_STRING) { - zval retval; - int old_error_reporting = 0; /* shut up gcc! */ - - myeval = (*assertion)->value.str.val; - - if (ASSERT(quiet_eval)) { - old_error_reporting = EG(error_reporting); - EG(error_reporting) = 0; - } - - if (zend_eval_string(myeval, &retval CLS_CC ELS_CC) == FAILURE) { - zend_error(E_ERROR, "Failure evaluating code:\n%s\n", myeval); - /* zend_error() does not return in this case. */ - } - - if (ASSERT(quiet_eval)) { - EG(error_reporting) = old_error_reporting; - } - - convert_to_boolean(&retval); - val = retval.value.lval; - } else { - convert_to_boolean_ex(assertion); - val = (*assertion)->value.lval; - } - - if (val) { - RETURN_TRUE; - } - - if (ASSERT(callback)) { - cbfunc = ASSERT(callback); - } else if (ASSERT(default_callback)) { - cbfunc = ASSERT(default_callback); - } else { - cbfunc = NULL; - } - - if (cbfunc) { - zval *args[5]; - zval *retval; - int i; - uint lineno = zend_get_executed_lineno(ELS_C); - char *filename = zend_get_executed_filename(ELS_C); - /* - char *function = get_active_function_name(); - */ - - MAKE_STD_ZVAL(args[0]); - MAKE_STD_ZVAL(args[1]); - MAKE_STD_ZVAL(args[2]); - MAKE_STD_ZVAL(args[3]); - /* - MAKE_STD_ZVAL(args[4]); - */ - - args[0]->type = IS_STRING; args[0]->value.str.val = estrdup(SAFE_STRING(cbfunc)); args[0]->value.str.len = strlen(args[0]->value.str.val); - args[1]->type = IS_STRING; args[1]->value.str.val = estrdup(SAFE_STRING(filename)); args[1]->value.str.len = strlen(args[1]->value.str.val); - args[2]->type = IS_LONG; args[2]->value.lval = lineno; - args[3]->type = IS_STRING; args[3]->value.str.val = estrdup(SAFE_STRING(myeval)); args[3]->value.str.len = strlen(args[3]->value.str.val); - /* - this is always "assert" so it's useless - args[4]->type = IS_STRING; args[4]->value.str.val = estrdup(SAFE_STRING(function)); args[4]->value.str.len = strlen(args[4]->value.str.val); - */ - - MAKE_STD_ZVAL(retval); - retval->type = IS_BOOL; - retval->value.lval = 0; - - /* XXX do we want to check for error here? */ - call_user_function(CG(function_table), NULL, args[0], retval, 3, args+1); - - for (i = 0; i < 4; i++) { - zval_del_ref(&(args[i])); - } - zval_del_ref(&retval); - } - - if (ASSERT(warning)) { - if (myeval) { - php_error(E_WARNING,"Assertion \"%s\" failed",myeval); - } else { - php_error(E_WARNING,"Assertion failed"); - } - } - - if (ASSERT(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; - char *oldstr; - int ac = ZEND_NUM_ARGS(); - ASSERTLS_FETCH(); - - if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &what, &value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(what); - - switch ((*what)->value.lval) { - case ASSERT_ACTIVE: - oldint = ASSERT(active); - if (ac == 2) { - convert_to_long_ex(value); - ASSERT(active) = (*value)->value.lval; - } - RETURN_LONG(oldint); - break; - - case ASSERT_BAIL: - oldint = ASSERT(bail); - if (ac == 2) { - convert_to_long_ex(value); - ASSERT(bail) = (*value)->value.lval; - } - RETURN_LONG(oldint); - break; - - case ASSERT_QUIET_EVAL: - oldint = ASSERT(quiet_eval); - if (ac == 2) { - convert_to_long_ex(value); - ASSERT(quiet_eval) = (*value)->value.lval; - } - RETURN_LONG(oldint); - break; - - case ASSERT_WARNING: - oldint = ASSERT(warning); - if (ac == 2) { - convert_to_long_ex(value); - ASSERT(warning) = (*value)->value.lval; - } - RETURN_LONG(oldint); - break; - - case ASSERT_CALLBACK: - oldstr = ASSERT(callback); - RETVAL_STRING(SAFE_STRING(oldstr),1); - - if (ac == 2) { - convert_to_string_ex(value); - ASSERT(callback) = estrndup((*value)->value.str.val,(*value)->value.str.len); - } - if (oldstr) { - efree(oldstr); - } - return; - break; - - default: - php_error(E_WARNING,"Unknown value %d.",(*what)->value.lval); - break; - } - - RETURN_FALSE; -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/base64.c b/ext/standard/base64.c deleted file mode 100644 index c8f037654c..0000000000 --- a/ext/standard/base64.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 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 char base64_pad = '='; - -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; -} - -/* as above, but backwards. :) */ -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 */ - static short reverse_table[256]; - static int table_built; - unsigned char *result; - - if (++table_built == 1) { - char *chp; - for(ch = 0; ch < 256; ch++) { - chp = strchr(base64_table, ch); - if(chp) { - reverse_table[ch] = chp - base64_table; - } else { - reverse_table[ch] = -1; - } - } - } - - result = (unsigned char *)emalloc(length + 1); - if (result == NULL) { - return NULL; - } - - /* run through the whole string, converting as we go */ - while ((ch = *current++) != '\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 = 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[k] = '\0'; - return result; -} - -/* {{{ proto string base64_encode(string str) - Encodes string using MIME base64 algorithm */ -PHP_FUNCTION(base64_encode) { - pval **str; - unsigned char *result; - int ret_length; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1,&str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - result = php_base64_encode((*str)->value.str.val, (*str)->value.str.len, &ret_length); - if (result != NULL) { - return_value->value.str.val = result; - return_value->value.str.len = ret_length; - return_value->type = IS_STRING; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto string base64_decode(string str) - Decodes string using MIME base64 algorithm */ -PHP_FUNCTION(base64_decode) { - pval **str; - unsigned char *result; - int ret_length; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1,&str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - result = php_base64_decode((*str)->value.str.val, (*str)->value.str.len, &ret_length); - if (result != NULL) { - return_value->value.str.val = result; - return_value->value.str.len = ret_length; - return_value->type = IS_STRING; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/base64.h b/ext/standard/base64.h deleted file mode 100644 index 0352b4ab36..0000000000 --- a/ext/standard/base64.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead (jimw@php.net) | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef _BASE64_h -#define _BASE64_h - -PHP_FUNCTION(base64_decode); -PHP_FUNCTION(base64_encode); - -extern unsigned char *php_base64_encode(const unsigned char *, int, int *); -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 c8dd78d971..0000000000 --- a/ext/standard/basic_functions.c +++ /dev/null @@ -1,2029 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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> | - +----------------------------------------------------------------------+ - */ - - -#include "php.h" -#include "php_main.h" -#include "php_ini.h" -#include "internal_functions_registry.h" -#include "php_standard.h" -#include "phpmath.h" -#include "ext/standard/info.h" -#include "zend_operators.h" -#include <stdarg.h> -#include <stdlib.h> -#include <math.h> -#include <time.h> -#include <stdio.h> -#include <netdb.h> -#include <arpa/inet.h> -#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 -#include "safe_mode.h" -#ifdef PHP_WIN32 -#include "win32/unistd.h" -#endif -#include "zend_globals.h" - -#include "php_globals.h" -#include "SAPI.h" - - -#ifdef ZTS -int basic_globals_id; -#else -php_basic_globals basic_globals; -#endif - -static unsigned char second_and_third_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; -static unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; -static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; -; - -typedef struct _php_shutdown_function_entry { - zval **arguments; - int arg_count; -} php_shutdown_function_entry; - -/* some prototypes for local functions */ -static void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry); -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); - -function_entry basic_functions[] = { - PHP_FE(intval, NULL) - PHP_FE(doubleval, NULL) - PHP_FE(strval, 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) -#else - PHP_FALIAS(strftime , warn_not_available, NULL) - PHP_FALIAS(gmstrftime, warn_not_available, NULL) -#endif - PHP_FE(strtotime, NULL) - PHP_FE(date, NULL) - PHP_FE(gmdate, NULL) - PHP_FE(getdate, NULL) - PHP_FE(localtime, NULL) - PHP_FE(checkdate, NULL) - - PHP_FE(flush, NULL) - - PHP_FE(gettype, NULL) - PHP_FE(settype, first_arg_force_ref) - - PHP_FE(getimagesize, NULL) - - PHP_FE(htmlspecialchars, NULL) - PHP_FE(htmlentities, NULL) - PHP_FE(get_html_translation_table, NULL) - - PHP_NAMED_FE(md5, php_if_md5, NULL) - - PHP_FE(iptcparse, NULL) - PHP_FE(iptcembed, 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(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(strrpos, 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(stripslashes, NULL) - PHP_FE(stripcslashes, NULL) - PHP_FE(strstr, NULL) - PHP_FE(stristr, NULL) - PHP_FE(strrchr, NULL) - 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(chop, NULL) - PHP_FE(str_replace, 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_argument_force_ref) - PHP_FE(explode, NULL) - PHP_FE(implode, NULL) - PHP_FE(setlocale, NULL) - PHP_FE(soundex, NULL) - PHP_FE(levenshtein, NULL) - PHP_FE(chr, NULL) - PHP_FE(ord, NULL) - PHP_FE(parse_str, NULL) - PHP_FE(str_pad, NULL) - PHP_FALIAS(rtrim, chop, 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(sscanf, NULL) - PHP_FE(fscanf, NULL) - - PHP_FE(parse_url, NULL) - PHP_FE(urlencode, NULL) - PHP_FE(urldecode, NULL) - PHP_FE(rawurlencode, NULL) - PHP_FE(rawurldecode, NULL) - - PHP_FE(readlink, NULL) - PHP_FE(linkinfo, NULL) - PHP_FE(symlink, NULL) - PHP_FE(link, NULL) - 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(passthru, second_arg_force_ref) - PHP_FE(shell_exec, NULL) - - 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) - PHP_FE(getservbyname, NULL) - PHP_FE(getservbyport, NULL) - PHP_FE(getprotobyname, NULL) - PHP_FE(getprotobynumber, NULL) - PHP_FE(gethostbyaddr, NULL) - PHP_FE(gethostbyname, NULL) - PHP_FE(gethostbynamel, NULL) -#if !defined(PHP_WIN32)||HAVE_BINDLIB - PHP_FE(checkdnsrr, NULL) - PHP_FE(getmxrr, second_and_third_args_force_ref) -#else - PHP_FALIAS(checkdnsrr, warn_not_available, NULL) - PHP_FALIAS(getmxrr, warn_not_available, NULL) -#endif - - PHP_FE(getmyuid, 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(pi, NULL) - PHP_FE(pow, NULL) - PHP_FE(exp, NULL) - PHP_FE(log, NULL) - PHP_FE(log10, NULL) - PHP_FE(sqrt, 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(ip2long, NULL) - PHP_FE(long2ip, NULL) - - PHP_FE(getenv, NULL) -#ifdef HAVE_PUTENV - PHP_FE(putenv, NULL) -#else - PHP_FALIAS(putenv , warn_not_available, NULL) -#endif - - PHP_FE(microtime, NULL) - PHP_FE(gettimeofday, NULL) -#ifdef HAVE_GETRUSAGE - PHP_FE(getrusage, NULL) -#else - PHP_FALIAS(getrusage , warn_not_available, NULL) -#endif - - PHP_FE(uniqid, NULL) - - 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(is_resource, first_arg_allow_ref) - PHP_FE(is_bool, first_arg_allow_ref) - PHP_FE(is_long, first_arg_allow_ref) - PHP_FALIAS(is_int, is_long, first_arg_allow_ref) - PHP_FALIAS(is_integer, is_long, first_arg_allow_ref) - PHP_FALIAS(is_float, is_double, first_arg_allow_ref) - PHP_FE(is_double, first_arg_allow_ref) - PHP_FALIAS(is_real, is_double, first_arg_allow_ref) - PHP_FE(is_numeric, NULL) - PHP_FE(is_string, first_arg_allow_ref) - PHP_FE(is_array, first_arg_allow_ref) - PHP_FE(is_object, first_arg_allow_ref) - - PHP_FE(error_log, NULL) - PHP_FE(call_user_func, NULL) - PHP_FE(call_user_method, NULL) - - PHP_FE(var_dump, NULL) - PHP_FE(serialize, first_arg_allow_ref) - PHP_FE(unserialize, first_arg_allow_ref) - - PHP_FE(register_shutdown_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_set, NULL) - PHP_FALIAS(ini_alter, ini_set, NULL) - PHP_FE(ini_restore, NULL) - - PHP_FE(print_r, NULL) - - PHP_FE(setcookie, NULL) - PHP_NAMED_FE(header, PHP_FN(Header), NULL) - PHP_FE(headers_sent, NULL) - - PHP_FE(connection_aborted, NULL) - PHP_FE(connection_timeout, NULL) - PHP_FE(connection_status, NULL) - PHP_FE(ignore_user_abort, NULL) - - PHP_FE(get_loaded_extensions, NULL) - PHP_FE(extension_loaded, NULL) - PHP_FE(get_extension_funcs, NULL) - - PHP_FE(parse_ini_file, NULL) - - /* functions from reg.c */ - PHP_FE(ereg, third_argument_force_ref) - PHP_FE(ereg_replace, NULL) - PHP_FE(eregi, third_argument_force_ref) - PHP_FE(eregi_replace, NULL) - PHP_FE(split, 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_FE(fopen, NULL) - PHP_FE(fpassthru, NULL) - PHP_FE(ftruncate, NULL) - PHP_FE(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_FE(tmpfile, NULL) - PHP_FE(file, NULL) - PHP_FE(fgetcsv, NULL) - PHP_FE(flock, NULL) - PHP_FE(get_meta_tags, NULL) - /* set_socket_blocking() is deprecated, - use socket_set_blocking() instead */ - PHP_FE(set_socket_blocking, NULL) - PHP_FE(socket_set_blocking, NULL) -#if HAVE_SYS_TIME_H - PHP_FE(socket_set_timeout, NULL) -#else - PHP_FALIAS(socket_set_timeout , warn_not_available, NULL) -#endif - PHP_FE(socket_get_status, NULL) - PHP_FE(realpath, NULL) - - /* 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) -#else - PHP_FALIAS(crypt , warn_not_available, NULL) -#endif - - /* functions from dir.c */ - PHP_FE(opendir, NULL) - PHP_FE(closedir, NULL) - PHP_FE(chdir, NULL) - PHP_FE(getcwd, NULL) - PHP_FE(rewinddir, NULL) - PHP_FE(readdir, NULL) - PHP_FALIAS(dir, getdir, NULL) - - /* 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_FE(stat, NULL) - PHP_FE(lstat, NULL) - PHP_FE(chown, NULL) - PHP_FE(chgrp, NULL) - PHP_FE(chmod, NULL) - PHP_FE(touch, NULL) - PHP_FE(clearstatcache, NULL) - PHP_FE(diskfreespace, NULL) - - /* functions from mail.c */ - PHP_FE(mail, NULL) - - /* functions from syslog.c */ - PHP_FE(openlog, NULL) - PHP_FE(syslog, NULL) - PHP_FE(closelog, NULL) - PHP_FE(define_syslog_variables, NULL) - - /* 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_end_flush, NULL) - PHP_FE(ob_end_clean, NULL) - PHP_FE(ob_get_contents, NULL) - PHP_FE(ob_implicit_flush, 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(count, first_arg_allow_ref) - 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(extract, NULL) - PHP_FE(compact, 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_pad, NULL) - PHP_FE(array_flip, NULL) - PHP_FE(array_rand, NULL) - /* aliases from array.c */ - PHP_FALIAS(pos, current, first_arg_force_ref) - PHP_FALIAS(sizeof, count, first_arg_allow_ref) - - /* functions from assert.c */ - PHP_FE(assert, NULL) - PHP_FE(assert_options, NULL) - - {NULL, NULL, NULL} -}; - - -static PHP_INI_MH(OnUpdateSafeModeProtectedEnvVars) -{ - char *protected_vars, *protected_var; - int dummy=1; - BLS_FETCH(); - - protected_vars = estrndup(new_value, new_value_length); - zend_hash_clean(&BG(sm_protected_env_vars)); - - protected_var=strtok(protected_vars, ", "); - while (protected_var) { - zend_hash_update(&BG(sm_protected_env_vars), protected_var, strlen(protected_var), &dummy, sizeof(int), NULL); - protected_var=strtok(NULL, ", "); - } - efree(protected_vars); - return SUCCESS; -} - - -static PHP_INI_MH(OnUpdateSafeModeAllowedEnvVars) -{ - BLS_FETCH(); - - 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_END() - - -zend_module_entry basic_functions_module = { - "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_GINIT(basic), /* global startup function */ - NULL, /* global shutdown function */ - STANDARD_MODULE_PROPERTIES_EX -}; - -#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 - - -void test_class_startup(void); - -static void basic_globals_ctor(BLS_D) -{ - BG(next) = NULL; - BG(left) = -1; - zend_hash_init(&BG(sm_protected_env_vars), 5, NULL, NULL, 1); - BG(sm_allowed_env_vars) = NULL; -} - -static void basic_globals_dtor(BLS_D) -{ - 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 - basic_globals_id = ts_allocate_id(sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor); -#else - basic_globals_ctor(BLS_C); -#endif - -#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); - - - test_class_startup(); - REGISTER_INI_ENTRIES(); - - register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU); - register_html_constants(INIT_FUNC_ARGS_PASSTHRU); - - PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(fsock)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU); - -#if HAVE_CRYPT - PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU); -#endif - - PHP_MINIT(dir)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} - - -PHP_MSHUTDOWN_FUNCTION(basic) -{ - BLS_FETCH(); - - basic_globals_dtor(BLS_C); - -#ifdef ZTS - ts_free_id(basic_globals_id); -#endif - - UNREGISTER_INI_ENTRIES(); - - PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_MSHUTDOWN(fsock)(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); - - return SUCCESS; -} - - -PHP_RINIT_FUNCTION(basic) -{ - BLS_FETCH(); - - BG(strtok_string) = NULL; - BG(locale_string) = NULL; - BG(user_compare_func_name) = NULL; - BG(array_walk_func_name) = NULL; - BG(page_uid) = -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; - - PHP_RINIT(head)(INIT_FUNC_ARGS_PASSTHRU); - PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU); - PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU); - PHP_RINIT(assert)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(basic) -{ - BLS_FETCH(); - - STR_FREE(BG(strtok_string)); -#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(fsock)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} - - -PHP_GINIT_FUNCTION(basic) -{ - PHP_GINIT(output)(GINIT_FUNC_ARGS_PASSTHRU); - - 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_MINFO(assert)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU); - php_info_print_table_end(); -} - -/* {{{ 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(inet_addr((*str)->value.str.val)); -} -/* }}} */ - -/* {{{ 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; - struct in_addr myaddr; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(num); - myaddr.s_addr = (unsigned long)(*num)->value.lval; - - RETURN_STRING (inet_ntoa(myaddr), 1); -} -/* }}} */ - - -/******************** - * System Functions * - ********************/ - -/* {{{ proto string getenv(string varname) - Get the value of an environment variable */ -PHP_FUNCTION(getenv) -{ - pval **str; - char *ptr; - - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if ((*str)->type != IS_STRING) { - RETURN_FALSE; - } - - - ptr = sapi_getenv((*str)->value.str.val, (*str)->value.str.len); - if (!ptr) { - ptr = getenv((*str)->value.str.val); - } - if (ptr) { - RETURN_STRING(ptr, 1); - } - RETURN_FALSE; -} -/* }}} */ - -#ifdef HAVE_PUTENV - -/* {{{ proto void putenv(string setting) - Set the value of an environment variable */ -PHP_FUNCTION(putenv) -{ - pval **str; - BLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if ((*str)->value.str.val && *((*str)->value.str.val)) { - int ret; - char *p,**env; - putenv_entry pe; - PLS_FETCH(); - - pe.putenv_string = estrndup((*str)->value.str.val,(*str)->value.str.len); - pe.key = estrndup((*str)->value.str.val, (*str)->value.str.len); - 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(E_WARNING, "Safe Mode: 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(E_WARNING, "Safe Mode: 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 ((ret=putenv(pe.putenv_string))==0) { /* success */ - zend_hash_add(&BG(putenv_ht),pe.key,pe.key_len+1,(void **) &pe,sizeof(putenv_entry),NULL); - RETURN_TRUE; - } else { - efree(pe.putenv_string); - efree(pe.key); - RETURN_FALSE; - } - } -} -/* }}} */ -#endif - - -/******************* - * Basic Functions * - *******************/ -/* {{{ 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 = (*arg_base)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - *return_value=**num; - zval_copy_ctor(return_value); - convert_to_long_base(return_value,base); -} -/* }}} */ - -/* {{{ proto double doubleval(mixed var) - Get the double-precision value of a variable */ -PHP_FUNCTION(doubleval) -{ - 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); -} -/* }}} */ - -/* {{{ proto void flush(void) - Flush the output buffer */ -PHP_FUNCTION(flush) -{ - sapi_flush(); -} -/* }}} */ - -/* {{{ 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((*num)->value.lval); -} -/* }}} */ - -/* {{{ 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((*num)->value.lval); -#endif -} -/* }}} */ - -/* {{{ 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 ((*arg)->type) { - 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); - break; - /* - { - char *result; - int res_len; - - res_len = sizeof("object of type ")-1 + arg->value.obj.ce->name_length; - result = (char *) emalloc(res_len+1); - sprintf(result, "object of type %s", arg->value.obj.ce->name); - RETVAL_STRINGL(result, res_len, 0); - } - */ - break; - default: - RETVAL_STRING("unknown type",1); - } -} -/* }}} */ - -/* {{{ proto int settype(string 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 = (*type)->value.str.val; - - if (!strcasecmp(new_type, "integer")) { - convert_to_long(*var); - } else if (!strcasecmp(new_type, "double")) { - 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, "boolean")) { - convert_to_boolean(*var); - } else if (!strcasecmp(new_type, "resource")) { - php_error(E_WARNING, "settype: cannot convert to resource type"); - RETURN_FALSE; - } else { - php_error(E_WARNING, "settype: invalid type"); - RETURN_FALSE; - } - RETVAL_TRUE; -} -/* }}} */ - -/* {{{ proto string get_current_user(void) - Get the name of the owner of the current PHP script */ -PHP_FUNCTION(get_current_user) -{ - 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((*varname)->value.str.val,&value)==FAILURE) { - RETURN_FALSE; - } - RETURN_STRING(value,1); -} -/* }}} */ - - -/* {{{ proto int 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; - PLS_FETCH(); - - 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) (*new_setting)->value.lval; - 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) -{ - PLS_FETCH(); - - 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) -{ - PLS_FETCH(); - - RETURN_LONG(PG(magic_quotes_gpc)); -} -/* }}} */ - - -void php_is_type(INTERNAL_FUNCTION_PARAMETERS,int type) -{ - pval **arg; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) { - RETURN_FALSE; - } - if ((*arg)->type == type) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} - -/* {{{ 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_double(mixed var) - Returns true if variable is a double */ -PHP_FUNCTION(is_double) -{ - 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 ((*arg)->type) { - case IS_LONG: - case IS_DOUBLE: - RETURN_TRUE; - break; - - case IS_STRING: - result = is_numeric_string((*arg)->value.str.val, (*arg)->value.str.len, NULL, NULL); - if (result == IS_LONG || result == IS_DOUBLE) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } - break; - - default: - RETURN_FALSE; - break; - } -} -/* }}} */ - -/* - 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 int 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(E_WARNING,"Invalid argument 1 in error_log"); - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2,&string,&erropt) == FAILURE) { - php_error(E_WARNING,"Invalid arguments in error_log"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err=(*erropt)->value.lval; - break; - case 3: - if (zend_get_parameters_ex(3,&string,&erropt,&option) == FAILURE){ - php_error(E_WARNING,"Invalid arguments in error_log"); - RETURN_FALSE; - } - convert_to_long_ex(erropt); - opt_err=(*erropt)->value.lval; - convert_to_string_ex(option); - opt=(*option)->value.str.val; - break; - case 4: - if (zend_get_parameters_ex(4,&string,&erropt,&option,&emailhead) == FAILURE){ - php_error(E_WARNING,"Invalid arguments in error_log"); - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(string); - message=(*string)->value.str.val; - if (erropt != NULL) { - convert_to_long_ex(erropt); - opt_err=(*erropt)->value.lval; - } - if (option != NULL) { - convert_to_string_ex(option); - opt=(*option)->value.str.val; - } - if (emailhead != NULL) { - convert_to_string_ex(emailhead); - headers=(*emailhead)->value.str.val; - } - - if (_php_error_log(opt_err,message,opt,headers)==FAILURE) { - RETURN_FALSE; - } - - RETURN_TRUE; -} -/* }}} */ - -PHPAPI int _php_error_log(int opt_err,char *message,char *opt,char *headers){ - FILE *logfile; - int issock=0, socketd=0;; - - switch(opt_err){ - case 1: /*send an email*/ - { -#if HAVE_SENDMAIL - if (!php_mail(opt,"PHP error_log message",message,headers)){ - return FAILURE; - } -#else - php_error(E_WARNING,"Mail option not available!"); - return FAILURE; -#endif - } - break; - case 2: /*send to an address */ - php_error(E_WARNING,"TCP/IP option not available!"); - return FAILURE; - break; - case 3: /*save to a file*/ - logfile=php_fopen_wrapper(opt,"a", (IGNORE_URL|ENFORCE_SAFE_MODE), &issock, &socketd, NULL); - if(!logfile) { - php_error(E_WARNING,"error_log: Unable to write to %s",opt); - return FAILURE; - } - fwrite(message,strlen(message),1,logfile); - fclose(logfile); - break; - default: - php_log_err(message); - break; - } - return SUCCESS; -} - -/* {{{ proto mixed call_user_func(mixed params) - Call user function which is the first parameter */ -PHP_FUNCTION(call_user_func) -{ - pval ***params; - pval *retval_ptr; - int arg_count=ZEND_NUM_ARGS(); - CLS_FETCH(); - - if (arg_count<1) { - WRONG_PARAM_COUNT; - } - params = (pval ***) emalloc(sizeof(pval **)*arg_count); - - if (zend_get_parameters_array_ex(arg_count, params)==FAILURE) { - efree(params); - RETURN_FALSE; - } - SEPARATE_ZVAL(params[0]); - if (call_user_function_ex(CG(function_table), NULL, *params[0], &retval_ptr, arg_count-1, params+1, 1)==SUCCESS - && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - php_error(E_WARNING,"Unable to call %s() - function does not exist", (*params[0])->value.str.val); - } - efree(params); -} -/* }}} */ - -/* {{{ proto mixed call_user_method(mixed params) - Call a user method, on a specific object where the first argument is the method name, the second argument is the object and the subsequent arguments are the parameters */ -PHP_FUNCTION(call_user_method) -{ - pval ***params; - pval *retval_ptr; - int arg_count=ZEND_NUM_ARGS(); - CLS_FETCH(); - - if (arg_count<2) { - WRONG_PARAM_COUNT; - } - params = (pval ***) emalloc(sizeof(pval **)*arg_count); - - if (zend_get_parameters_array_ex(arg_count, params)==FAILURE) { - efree(params); - RETURN_FALSE; - } - if ((*params[1])->type != IS_OBJECT) { - php_error(E_WARNING,"2nd argument is not an object\n"); - efree(params); - RETURN_FALSE; - } - SEPARATE_ZVAL(params[0]); - SEPARATE_ZVAL(params[1]); - convert_to_string(*params[0]); - if (call_user_function_ex(CG(function_table), *params[1], *params[0], &retval_ptr, arg_count-2, params+2, 1)==SUCCESS - && retval_ptr) { - COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); - } else { - php_error(E_WARNING,"Unable to call %s() - function does not exist", (*params[0])->value.str.val); - } - efree(params); -} -/* }}} */ - -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); -} - - -static int user_shutdown_function_call(php_shutdown_function_entry *shutdown_function_entry) -{ - zval retval; - CLS_FETCH(); - - if (call_user_function(CG(function_table), NULL, shutdown_function_entry->arguments[0], &retval, shutdown_function_entry->arg_count-1, shutdown_function_entry->arguments+1)==SUCCESS) { - zval_dtor(&retval); - } else { - php_error(E_WARNING,"Unable to call %s() - function does not exist", - shutdown_function_entry->arguments[0]->value.str.val); - } - return 0; -} - - -void php_call_shutdown_functions(void) -{ - BLS_FETCH(); - ELS_FETCH(); - - if (BG(user_shutdown_function_names)) { - jmp_buf orig_bailout; - - memcpy(&orig_bailout, &EG(bailout), sizeof(jmp_buf)); - if (setjmp(EG(bailout))!=0) { - /* one of the shutdown functions bailed out */ - memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); - return; - } - zend_hash_apply(BG(user_shutdown_function_names), - (apply_func_t)user_shutdown_function_call); - memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf)); - zend_hash_destroy(BG(user_shutdown_function_names)); - efree(BG(user_shutdown_function_names)); - } -} - -/* {{{ 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; - BLS_FETCH(); - - 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)) { - BG(user_shutdown_function_names) = (HashTable *) emalloc(sizeof(HashTable)); - 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 void highlight_file(string file_name) - Syntax highlight a source file */ -PHP_FUNCTION(highlight_file) -{ - pval **filename; - zend_syntax_highlighter_ini syntax_highlighter_ini; - - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - php_get_highlight_struct(&syntax_highlighter_ini); - - if (highlight_file((*filename)->value.str.val, &syntax_highlighter_ini)==FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto void highlight_string(string string) - Syntax highlight a string */ -PHP_FUNCTION(highlight_string) -{ - pval **expr; - zend_syntax_highlighter_ini syntax_highlighter_ini; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &expr)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(expr); - - php_get_highlight_struct(&syntax_highlighter_ini); - - if (highlight_string(*expr, &syntax_highlighter_ini)==FAILURE) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - - -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 (overloaded_property->type) { - case OE_IS_ARRAY: - printf("Array offset: "); - break; - case OE_IS_OBJECT: - printf("Object property: "); - break; - } - switch (overloaded_property->element.type) { - case IS_LONG: - printf("%ld (numeric)\n", overloaded_property->element.value.lval); - break; - case IS_STRING: - printf("'%s'\n", overloaded_property->element.value.str.val); - break; - } - pval_destructor(&overloaded_property->element); - } - - result.value.str.val = estrndup("testing", 7); - result.value.str.len = 7; - result.type = 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 (overloaded_property->type) { - case OE_IS_ARRAY: - printf("Array offset: "); - break; - case OE_IS_OBJECT: - printf("Object property: "); - break; - } - switch (overloaded_property->element.type) { - case IS_LONG: - printf("%ld (numeric)\n", overloaded_property->element.value.lval); - break; - case IS_STRING: - printf("'%s'\n", overloaded_property->element.value.str.val); - 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 (overloaded_property->type) { - case OE_IS_ARRAY: - printf("Array offset: "); - break; - case OE_IS_OBJECT: - printf("Object property: "); - break; - case OE_IS_METHOD: - printf("Overloaded method: "); - } - switch (overloaded_property->element.type) { - case IS_LONG: - printf("%ld (numeric)\n", overloaded_property->element.value.lval); - break; - case IS_STRING: - printf("'%s'\n", overloaded_property->element.value.str.val); - break; - } - pval_destructor(&overloaded_property->element); - } - - printf("%d arguments\n", ZEND_NUM_ARGS()); - return_value->value.str.val = estrndup("testing", 7); - return_value->value.str.len = 7; - return_value->type = IS_STRING; -} - - -void test_class_startup() -{ - zend_class_entry test_class_entry; - - 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); -} - -/* {{{ proto string ini_get(string varname) - Get a configuration option */ -PHP_FUNCTION(ini_get) -{ - pval **varname; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &varname)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - - return_value->value.str.val = php_ini_string((*varname)->value.str.val, (*varname)->value.str.len+1, 0); - - if (!return_value->value.str.val) { - RETURN_FALSE; - } - - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = IS_STRING; - pval_copy_constructor(return_value); -} -/* }}} */ - -/* {{{ 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 failure */ -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 = php_ini_string((*varname)->value.str.val, (*varname)->value.str.len+1, 0); - - if (php_alter_ini_entry((*varname)->value.str.val, (*varname)->value.str.len+1, (*new_value)->value.str.val, (*new_value)->value.str.len, PHP_INI_USER, PHP_INI_STAGE_RUNTIME)==FAILURE) { - RETURN_FALSE; - } - if (old_value) { - RETURN_STRING(old_value, 1); - } else { - 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); - - php_restore_ini_entry((*varname)->value.str.val, (*varname)->value.str.len, PHP_INI_STAGE_RUNTIME); -} -/* }}} */ - -/* {{{ proto string print_r(mixed var) - Prints out information about the specified variable */ -PHP_FUNCTION(print_r) -{ - pval **expr; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &expr)==FAILURE) { - WRONG_PARAM_COUNT; - } - - zend_print_pval_r(*expr, 0); - - RETURN_TRUE; -} -/* }}} */ - - -/* This should go back to PHP */ - -/* {{{ proto int connection_aborted(void) - Returns true if client disconnected */ -PHP_FUNCTION(connection_aborted) -{ - PLS_FETCH(); - - RETURN_LONG(PG(connection_status)&PHP_CONNECTION_ABORTED); -} -/* }}} */ - -/* {{{ proto int connection_timeout(void) - Returns true if script timed out */ -PHP_FUNCTION(connection_timeout) -{ - PLS_FETCH(); - - RETURN_LONG(PG(connection_status)&PHP_CONNECTION_TIMEOUT); -} -/* }}} */ - -/* {{{ proto int connection_status(void) - Returns the connection status bitfield */ -PHP_FUNCTION(connection_status) -{ - PLS_FETCH(); - - RETURN_LONG(PG(connection_status)); -} -/* }}} */ - -/* {{{ proto int ignore_user_abort(boolean value) - Set whether we want to ignore a user abort event or not */ -PHP_FUNCTION(ignore_user_abort) -{ - pval **arg; - int old_setting; - PLS_FETCH(); - - 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_boolean_ex(arg); - PG(ignore_user_abort) = (zend_bool) (*arg)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - RETURN_LONG(old_setting); -} -/* }}} */ - -/* {{{ 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((*name)->value.str.val,(*proto)->value.str.val); - - if(serv == NULL) - RETURN_FALSE; - - RETURN_LONG(ntohs(serv->s_port)); -} -/* }}} */ - - -/* {{{ 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) (*port)->value.lval),(*proto)->value.str.val); - - if(serv == NULL) - RETURN_FALSE; - - RETURN_STRING(serv->s_name,1); -} -/* }}} */ - - -/* {{{ 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((*name)->value.str.val); - - if(ent == NULL) { - return_value->value.lval = -1; - return_value->type = IS_LONG; - return; - } - - RETURN_LONG(ent->p_proto); -} -/* }}} */ - - -/* {{{ 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((*proto)->value.lval); - - if(ent == NULL) - RETURN_FALSE; - - RETURN_STRING(ent->p_name,1); -} -/* }}} */ - - -static int php_add_extension_info(zend_module_entry *module, void *arg) -{ - zval *name_array = (zval *)arg; - add_next_index_string(name_array, module->name, 1); - return 0; -} - -/* {{{ proto array get_loaded_extensions(void) - Return an array containing names of loaded extensions */ -PHP_FUNCTION(get_loaded_extensions) -{ - if (ZEND_NUM_ARGS() != 0) { - WRONG_PARAM_COUNT; - } - - array_init(return_value); - zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void*)) php_add_extension_info, return_value); -} -/* }}} */ - - -/* {{{ proto bool extension_loaded(string extension_name) - Returns true if the named extension is loaded */ -PHP_FUNCTION(extension_loaded) -{ - zval **extension_name; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &extension_name)) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(extension_name); - if (zend_hash_exists(&module_registry, (*extension_name)->value.str.val, (*extension_name)->value.str.len+1)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto array get_extension_funcs(string extension_name) - Returns an array with the names of functions belonging to the named extension */ -PHP_FUNCTION(get_extension_funcs) -{ - zval **extension_name; - zend_module_entry *module; - zend_function_entry *func; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &extension_name)) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(extension_name); - if (zend_hash_find(&module_registry, (*extension_name)->value.str.val, - (*extension_name)->value.str.len+1, (void**)&module) == FAILURE) { - return; - } - - array_init(return_value); - func = module->functions; - while(func->fname) { - add_next_index_string(return_value, func->fname, 1); - func++; - } -} -/* }}} */ - - - -/* This function is not directly accessible to end users */ -PHP_FUNCTION(warn_not_available) -{ - php_error(E_WARNING, "%s() is not supported in this PHP build", get_active_function_name()); - RETURN_FALSE; -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h deleted file mode 100644 index c76bb54575..0000000000 --- a/ext/standard/basic_functions.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | 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" - -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_GINIT_FUNCTION(basic); - -PHP_FUNCTION(intval); -PHP_FUNCTION(doubleval); -PHP_FUNCTION(strval); -PHP_FUNCTION(toggle_short_open_tag); -PHP_FUNCTION(sleep); -PHP_FUNCTION(usleep); -PHP_FUNCTION(flush); -PHP_FUNCTION(gettype); -PHP_FUNCTION(settype); -PHP_FUNCTION(ip2long); -PHP_FUNCTION(long2ip); - -/* system functions */ -PHP_FUNCTION(getenv); -PHP_FUNCTION(putenv); - -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); - -void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type); -PHP_FUNCTION(is_resource); -PHP_FUNCTION(is_bool); -PHP_FUNCTION(is_long); -PHP_FUNCTION(is_double); -PHP_FUNCTION(is_numeric); -PHP_FUNCTION(is_string); -PHP_FUNCTION(is_array); -PHP_FUNCTION(is_object); - -PHP_FUNCTION(error_log); - -PHP_FUNCTION(call_user_func); -PHP_FUNCTION(call_user_method); - -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_set); -PHP_FUNCTION(ini_restore); - -PHP_FUNCTION(print_r); - -PHP_FUNCTION(connection_aborted); -PHP_FUNCTION(connection_timeout); -PHP_FUNCTION(connection_status); -PHP_FUNCTION(ignore_user_abort); - -PHP_FUNCTION(getservbyname); -PHP_FUNCTION(getservbyport); -PHP_FUNCTION(getprotobyname); -PHP_FUNCTION(getprotobynumber); - -PHP_FUNCTION(get_loaded_extensions); -PHP_FUNCTION(extension_loaded); -PHP_FUNCTION(get_extension_funcs); - -PHP_FUNCTION(warn_not_available); - -/* From the INI parser */ -PHP_FUNCTION(parse_ini_file); - -#ifdef PHP_WIN32 -typedef unsigned int php_stat_len; -#else -typedef int php_stat_len; -#endif - -#if SIZEOF_INT == 4 -/* Most 32-bit and 64-bit systems have 32-bit ints */ -typedef unsigned int php_uint32; -#elif SIZEOF_LONG == 4 -/* 16-bit systems? */ -typedef unsigned long php_uint32; -#else -#error Need type which holds 32 bits -#endif - -#define MT_N (624) - -typedef struct { - HashTable *user_shutdown_function_names; - HashTable putenv_ht; - char *strtok_string; - char *locale_string; - char *strtok_pos1; - char *strtok_pos2; - char str_ebuf[40]; - zval **array_walk_func_name; - zval **user_compare_func_name; - - HashTable sm_protected_env_vars; - char *sm_allowed_env_vars; - - /* pageinfo.c */ - long page_uid; - 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 */ - - /* syslog.c */ - int syslog_started; - char *syslog_device; -} php_basic_globals; - -#ifdef ZTS -#define BLS_D php_basic_globals *basic_globals -#define BLS_DC , BLS_D -#define BLS_C basic_globals -#define BLS_CC , BLS_C -#define BG(v) (basic_globals->v) -#define BLS_FETCH() php_basic_globals *basic_globals = ts_resource(basic_globals_id) -extern int basic_globals_id; -#else -#define BLS_D -#define BLS_DC -#define BLS_C -#define BLS_CC -#define BG(v) (basic_globals.v) -#define BLS_FETCH() -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 8dc50a5f31..0000000000 --- a/ext/standard/browscap.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_regex.h" -#include "php_browscap.h" -#include "php_ini.h" - -#include "zend_globals.h" - -#ifndef THREAD_SAFE -HashTable browser_hash; -static char *lookup_browser_name; -static pval *found_browser_entry; -#endif - -static int browser_reg_compare(zval **browser) -{ - pval *browser_name; - regex_t r; - - if (found_browser_entry) { /* already found */ - return 0; - } - zend_hash_find((*browser)->value.obj.properties, "browser_name_pattern",sizeof("browser_name_pattern"),(void **) &browser_name); - if (!strchr(browser_name->value.str.val,'*')) { - return 0; - } - if (regcomp(&r,browser_name->value.str.val,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 agent_name) - ??? */ -PHP_FUNCTION(get_browser) -{ - pval **agent_name,**agent, tmp; - - if (!INI_STR("browscap")) { - RETURN_FALSE; - } - - switch(ZEND_NUM_ARGS()) { - case 0: - if (zend_hash_find(&EG(symbol_table), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &agent_name)==FAILURE) { - *agent_name = &tmp; - var_reset(*agent_name); - } - 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, (*agent_name)->value.str.val,(*agent_name)->value.str.len+1, (void **) &agent)==FAILURE) { - lookup_browser_name = (*agent_name)->value.str.val; - found_browser_entry = NULL; - zend_hash_apply(&browser_hash,(int (*)(void *)) browser_reg_compare); - - if (found_browser_entry) { - *agent = found_browser_entry; - } else if (zend_hash_find(&browser_hash, "Default Browser", sizeof("Default Browser"), (void **) &agent)==FAILURE) { - RETURN_FALSE; - } - } - - *return_value = **agent; - return_value->type = IS_OBJECT; - pval_copy_constructor(return_value); - return_value->value.obj.properties->pDestructor = ZVAL_DESTRUCTOR; - - while (zend_hash_find((*agent)->value.obj.properties, "parent",sizeof("parent"), (void **) &agent_name)==SUCCESS) { - zval *tmp_copy; - - if (zend_hash_find(&browser_hash,(*agent_name)->value.str.val, (*agent_name)->value.str.len+1, (void **)&agent)==FAILURE) { - break; - } - zend_hash_merge(return_value->value.obj.properties,(*agent)->value.obj.properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(pval *), 0); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 deleted file mode 100644 index 7bc4b47d9a..0000000000 --- a/ext/standard/config.m4 +++ /dev/null @@ -1,150 +0,0 @@ -dnl $Id$ -*- sh -*- - -divert(3)dnl - -dnl -dnl Check for crypt() capabilities -dnl -AC_DEFUN(AC_CRYPT_CAP,[ - - AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[ - AC_TRY_RUN([ -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([ -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([ -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([ -main() { -#if HAVE_CRYPT - char salt[25], 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[16],"O............gl95GkTKn53Of.H4YchXl5PwvvW.5ri"); - 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_FUNC(dlopen, [AC_DEFINE(HAVE_LIBDL,1,[ ])]) - -AC_CHECK_LIB(pam, pam_start, [ - EXTRA_LIBS="$EXTRA_LIBS -lpam" - AC_DEFINE(HAVE_LIBPAM,1,[ ]) ], []) - -AC_CHECK_FUNCS(getcwd getwd) - -AC_CRYPT_CAP - -divert(5)dnl - -AC_ARG_WITH(regex, -[ --with-regex=TYPE regex library type: system, apache, php],[ - REGEX_TYPE=$withval -],[ - REGEX_TYPE=php -]) - -AC_ARG_WITH(system-regex, -[ --with-system-regex (deprecated) Use system regex library],[ - if test "$withval" = "yes"; then - REGEX_TYPE=system - else - REGEX_TYPE=php - fi -]) - -PHP_EXTENSION(standard) - diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c deleted file mode 100644 index c422e42efd..0000000000 --- a/ext/standard/crypt.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -/* $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_crypt.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 17 -#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 - -#if HAVE_LRAND48 -#define PHP_CRYPT_RAND lrand48() -#else -#if HAVE_RANDOM -#define PHP_CRYPT_RAND random() -#else -#define PHP_CRYPT_RAND rand() -#endif -#endif - -PHP_MINIT_FUNCTION(crypt) -{ -#if PHP_STD_DES_CRYPT - REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", 2, CONST_CS | CONST_PERSISTENT); -#else -#if PHP_MD5_CRYPT - REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", 12, CONST_CS | CONST_PERSISTENT); -#endif -#endif - 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; -} - -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]; - pval **arg1, **arg2; - - 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); - - switch (ZEND_NUM_ARGS()) { - case 1: - if (zend_get_parameters_ex(1, &arg1)==FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - memcpy(salt, (*arg2)->value.str.val, MIN(PHP_MAX_SALT_LEN,(*arg2)->value.str.len)); - break; - default: - WRONG_PARAM_COUNT; - break; - } - convert_to_string_ex(arg1); - - /* The automatic salt generation only covers standard DES and md5-crypt */ - if(!*salt) { -#if HAVE_SRAND48 - srand48((unsigned int) time(0) * getpid()); -#else -#if HAVE_SRANDOM - srandom((unsigned int) time(0) * getpid()); -#else - srand((unsigned int) time(0) * getpid()); -#endif -#endif - -#if PHP_STD_DES_CRYPT - php_to64(&salt[0], PHP_CRYPT_RAND, 2); - salt[2] = '\0'; -#else -#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], "$"); -#endif -#endif - } - - return_value->value.str.val = (char *) crypt((*arg1)->value.str.val, salt); - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = IS_STRING; - pval_copy_constructor(return_value); -} -/* }}} */ -#endif - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/cyr_convert.c b/ext/standard/cyr_convert.c deleted file mode 100644 index c5919b58c0..0000000000 --- a/ext/standard/cyr_convert.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: 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 = { -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, -46,46,46,46,46,46,46,46,179,46,32,46,46,46,46,32, -46,46,46,46,46,46,46,46,163,46,32,46,46,46,46,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, -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,32,32,32,32,32,32,32,32,32,32,32,32, -32,32,32,168,32,32,32,32,32,32,32,32,32,32,32,32, -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,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,240,32,32,32,32,32,32,32,32,32,32,32,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, -}; - - -/***************************************************************************** -* 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, char from, char to) -{ - 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(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(E_WARNING, "Unknown destination charset: %c", to); - break; - } - - - if (!str) - return (char *)str; - - for( i = 0; str[i]; 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*) (*str_arg)->value.str.val; - - php_convert_cyr_string(str, (*fr_cs)->value.str.val[0],(*to_cs)->value.str.val[0]); - RETVAL_STRING((char *)str, 1) -} -/* }}} */ diff --git a/ext/standard/cyr_convert.h b/ext/standard/cyr_convert.h deleted file mode 100644 index 91eb2346ec..0000000000 --- a/ext/standard/cyr_convert.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: 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 7aaedd6972..0000000000 --- a/ext/standard/datetime.c +++ /dev/null @@ -1,730 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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> - -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) -extern time_t timezone; -#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) - -extern PHPAPI time_t parsedate(char *p, struct timeval *now); - -/* {{{ proto int time(void) - Return current UNIX timestamp */ -PHP_FUNCTION(time) -{ - RETURN_LONG((long)time(NULL)); -} -/* }}} */ - -void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) -{ - pval **arguments[7]; - struct tm *ta, tmbuf; - time_t t; - int i, gmadjust, seconds, arg_count = ZEND_NUM_ARGS(); - - 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: - ta->tm_isdst = (*arguments[6])->value.lval; - /* fall-through */ - case 6: - /* - ** 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 ((*arguments[5])->value.lval < 70) - ta->tm_year = (*arguments[5])->value.lval + 100; - else - ta->tm_year = (*arguments[5])->value.lval - - (((*arguments[5])->value.lval > 1000) ? 1900 : 0); - /* fall-through */ - case 5: - ta->tm_mday = (*arguments[4])->value.lval; - /* fall-through */ - case 4: - ta->tm_mon = (*arguments[3])->value.lval - 1; - /* fall-through */ - case 3: - ta->tm_sec = (*arguments[2])->value.lval; - /* fall-through */ - case 2: - ta->tm_min = (*arguments[1])->value.lval; - /* fall-through */ - case 1: - ta->tm_hour = (*arguments[0])->value.lval; - /* fall-through */ - case 0: - break; - } - - seconds = mktime(ta); - - 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 - /* - ** Without tm_gmtoff, the non-ANSI C run-time global 'timezone' - ** variable simply returns the current Winter GMT offset - ** in the current locale (defined in DOS/Windows compilers). - */ - gmadjust = timezone; -#endif - seconds += gmadjust; - } - - RETURN_LONG(seconds); -} - -/* {{{ proto int mktime(int hour, int min, int sec, int mon, int mday, 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 mday, int year) - Get UNIX timestamp for a GMT date */ -PHP_FUNCTION(gmmktime) -{ - php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -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; - char tmp_buff[16]; - - 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 = (*timestamp)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(format); - - if (gm) { - ta = php_gmtime_r(&the_time, &tmbuf); - } else { - ta = php_localtime_r(&the_time, &tmbuf); - } - - if (!ta) { /* that really shouldn't happen... */ - php_error(E_WARNING, "unexpected error in date()"); - RETURN_FALSE; - } - for (i = 0; i < (*format)->value.str.len; i++) { - switch ((*format)->value.str.val[i]) { - case 'U': /* seconds since the epoch */ - size += 10; - break; - case 'F': /* month, textual, full */ - case 'l': /* day (of the week), textual */ - case 'T': /* timezone name */ - size += 9; - break; - case 'Z': /* timezone offset in seconds */ - size += 6; - 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 */ - 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 */ - size += 2; - break; - case '\\': - if(i < (*format)->value.str.len-1) { - i++; - } - case 'L': /* boolean for leap year */ - case 'B': /* Swatch Beat, 3 digits */ - size += 3; - break; - case 'w': /* day of the week, numeric */ - case 'I': /* DST? */ - default: - size++; - break; - } - } - - return_value->value.str.val = (char *) emalloc(size + 1); - return_value->value.str.val[0] = '\0'; - - for (i = 0; i < (*format)->value.str.len; i++) { - switch ((*format)->value.str.val[i]) { - case '\\': - if(i < (*format)->value.str.len-1) { - char ch[2]; - ch[0]=(*format)->value.str.val[i+1]; - ch[1]='\0'; - strcat(return_value->value.str.val, ch); - i++; - } - break; - case 'U': /* seconds since the epoch */ - sprintf(tmp_buff, "%ld", (long)the_time); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'F': /* month, textual, full */ - strcat(return_value->value.str.val, mon_full_names[ta->tm_mon]); - break; - case 'l': /* day (of the week), textual, full */ - strcat(return_value->value.str.val, day_full_names[ta->tm_wday]); - break; - case 'Y': /* year, numeric, 4 digits */ - sprintf(tmp_buff, "%d", ta->tm_year + 1900); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'M': /* month, textual, 3 letters */ - strcat(return_value->value.str.val, mon_short_names[ta->tm_mon]); - break; - case 'D': /* day (of the week), textual, 3 letters */ - strcat(return_value->value.str.val, day_short_names[ta->tm_wday]); - break; - case 'z': /* day (of the year) */ - sprintf(tmp_buff, "%d", ta->tm_yday); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'y': /* year, numeric, 2 digits */ - sprintf(tmp_buff, "%02d", ((ta->tm_year)%100)); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'm': /* month, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'n': /* month, numeric, no leading zeros */ - sprintf(tmp_buff, "%d", ta->tm_mon + 1); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'd': /* day of the month, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_mday); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'j': - sprintf(tmp_buff, "%d", ta->tm_mday); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'H': /* hour, numeric, 24 hour format */ - sprintf(tmp_buff, "%02d", ta->tm_hour); /* SAFE */ - strcat(return_value->value.str.val, 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(return_value->value.str.val, tmp_buff); - break; - case 'G': /* hour, numeric, 24 hour format, no leading zeros */ - sprintf(tmp_buff, "%d", ta->tm_hour); /* SAFE */ - strcat(return_value->value.str.val, 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(return_value->value.str.val, tmp_buff); - break; - case 'i': /* minutes, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_min); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 's': /* seconds, numeric */ - sprintf(tmp_buff, "%02d", ta->tm_sec); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'A': /* AM/PM */ - strcat(return_value->value.str.val, (ta->tm_hour >= 12 ? "PM" : "AM")); - break; - case 'a': /* am/pm */ - strcat(return_value->value.str.val, (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(return_value->value.str.val, "th"); - } else { - switch (ta->tm_mday % 10) { - case 1: - strcat(return_value->value.str.val, "st"); - break; - case 2: - strcat(return_value->value.str.val, "nd"); - break; - case 3: - strcat(return_value->value.str.val, "rd"); - break; - default: - strcat(return_value->value.str.val, "th"); - break; - } - } - break; - case 't': /* days in current month */ - sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+1900))][ta->tm_mon] ); - strcat(return_value->value.str.val, tmp_buff); - break; - case 'w': /* day of the week, numeric EXTENSION */ - sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */ - strcat(return_value->value.str.val, 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", timezone); -#endif - strcat(return_value->value.str.val, tmp_buff); - break; - case 'L': /* boolean for leapyear */ - sprintf(tmp_buff, "%d", (isleap((ta->tm_year+1900)) ? 1 : 0 ) ); - strcat(return_value->value.str.val, tmp_buff); - break; - case 'T': /* timezone name */ -#if HAVE_TM_ZONE - strcat(return_value->value.str.val, ta->tm_zone); -#else - strcat(return_value->value.str.val, tzname[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); - if (beat > 999) beat = 0; - sprintf(tmp_buff, "%03d", beat); /* SAFE */ - strcat(return_value->value.str.val, tmp_buff); - break; - case 'I': - sprintf(tmp_buff, "%d", ta->tm_isdst); - strcat(return_value->value.str.val, tmp_buff); - break; - default: - length = strlen(return_value->value.str.val); - return_value->value.str.val[length] = (*format)->value.str.val[i]; - return_value->value.str.val[length + 1] = '\0'; - break; - } - } - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = 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/CUT date/time */ -PHP_FUNCTION(gmdate) -{ - php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* {{{ 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 = (*timestamp_arg)->value.lval; - break; - case 2: - convert_to_long_ex(timestamp_arg); - convert_to_long_ex(assoc_array_arg); - timestamp = (*timestamp_arg)->value.lval; - assoc_array = (*assoc_array_arg)->value.lval; - break; - } - ta = php_localtime_r(×tamp, &tmbuf); - if (array_init(return_value) == FAILURE) { - php_error(E_ERROR, "Cannot prepare return array from localtime"); - RETURN_FALSE; - } - - 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 = (*timestamp_arg)->value.lval; - } - - ta = php_localtime_r(×tamp, &tmbuf); - if (!ta) { - php_error(E_WARNING, "Cannot perform date calculation"); - return; - } - if (array_init(return_value) == FAILURE) { - php_error(E_ERROR, "Unable to initialize array"); - return; - } - 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); -} -/* }}} */ - -/* Return date string in standard format for http headers */ -char *php_std_date(time_t t) -{ - struct tm *tm1, tmbuf; - char *str; - PLS_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_full_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 */ -PHP_FUNCTION(checkdate) -{ - pval **month, **day, **year; - int m, d, y; - - if (ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &month, &day, &year) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(day); - convert_to_long_ex(month); - convert_to_long_ex(year); - y = (*year)->value.lval; - m = (*month)->value.lval; - d = (*day)->value.lval; - - if (y < 100) - y += 1900; - - if (y < 0 || 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 -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 = (*timestamp_arg)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string_ex(format_arg); - if ((*format_arg)->value.str.len==0) { - RETURN_FALSE; - } - format = (*format_arg)->value.str.val; - 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/CUT 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) -{ - pval **timep, **nowp; - int ac; - struct timeval tv; - - ac = ZEND_NUM_ARGS(); - - if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &timep,&nowp)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(timep); - if (ac == 2) { - convert_to_long_ex(nowp); - tv.tv_sec = (*nowp)->value.lval; - tv.tv_usec = 0; - RETURN_LONG(parsedate((*timep)->value.str.val, &tv)); - } else { - RETURN_LONG(parsedate((*timep)->value.str.val, NULL)); - } -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h deleted file mode 100644 index 6171197c61..0000000000 --- a/ext/standard/datetime.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | 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(gmdate); -PHP_FUNCTION(localtime); -PHP_FUNCTION(getdate); -PHP_FUNCTION(checkdate); -#if HAVE_STRFTIME -PHP_FUNCTION(strftime); -PHP_FUNCTION(gmstrftime); -#endif -PHP_FUNCTION(strtotime); - -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 73f9cb8f9a..0000000000 --- a/ext/standard/dir.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes/startup/misc */ - -#include "php.h" -#include "fopen-wrappers.h" - -#include "php_dir.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 - -typedef struct { - int default_dir; -} php_dir_globals; - -#ifdef ZTS -#define DIR(v) (dir_globals->v) -#define DIRLS_FETCH() php_dir_globals *dir_globals = ts_resource(dir_globals_id) -int dir_globals_id; -#else -#define DIR(v) (dir_globals.v) -#define DIRLS_FETCH() -php_dir_globals dir_globals; -#endif - -typedef struct { - int id; - DIR *dir; -} php_dir; - -static int le_dirp; - -static zend_class_entry *dir_class_entry_ptr; - -#define FETCH_DIRP() \ - if (ZEND_NUM_ARGS() == 0) { \ - myself = getThis(); \ - if (myself) { \ - if (zend_hash_find(myself->value.obj.properties, "handle", sizeof("handle"), (void **)&tmp) == FAILURE) { \ - php_error(E_WARNING, "unable to find my handle property"); \ - RETURN_FALSE; \ - } \ - ZEND_FETCH_RESOURCE(dirp,php_dir *,tmp,-1, "Directory", le_dirp); \ - } else { \ - ZEND_FETCH_RESOURCE(dirp,php_dir *,0,DIR(default_dir), "Directory", le_dirp); \ - } \ - } else if ((ZEND_NUM_ARGS() != 1) || zend_get_parameters_ex(1, &id) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } else { \ - ZEND_FETCH_RESOURCE(dirp,php_dir *,id,-1, "Directory", le_dirp); \ - } - -static zend_function_entry php_dir_class_functions[] = { - PHP_FALIAS(close, closedir, NULL) - PHP_FALIAS(rewind, rewinddir, NULL) - PHP_FALIAS(read, readdir, NULL) - {NULL, NULL, NULL} -}; - - -static void _dir_dtor(php_dir *dirp) -{ - closedir(dirp->dir); - efree(dirp); -} - -#ifdef ZTS -static void php_dir_init_globals(php_dir_globals *dir_globals) -{ - DIR(default_dir) = 0; -} -#endif - -PHP_MINIT_FUNCTION(dir) -{ - zend_class_entry dir_class_entry; - - le_dirp = register_list_destructors(_dir_dtor,NULL); - - INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions); - dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry); - -#ifdef ZTS - dir_globals_id = ts_allocate_id(sizeof(php_dir_globals), (ts_allocate_ctor) php_dir_init_globals, NULL); -#else - DIR(default_dir) = 0; -#endif - - return SUCCESS; -} - -/* }}} */ -/* {{{ internal functions */ - -static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject) -{ - pval **arg; - php_dir *dirp; - DIRLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (php_check_open_basedir((*arg)->value.str.val)) { - RETURN_FALSE; - } - - dirp = emalloc(sizeof(php_dir)); - - dirp->dir = V_OPENDIR((*arg)->value.str.val); - - if (! dirp->dir) { - efree(dirp); - php_error(E_WARNING, "OpenDir: %s (errno %d)", strerror(errno), errno); - RETURN_FALSE; - } - - dirp->id = zend_list_insert(dirp,le_dirp); - - DIR(default_dir) = dirp->id; - - if (createobject) { - object_init_ex(return_value, dir_class_entry_ptr); - add_property_stringl(return_value, "path", (*arg)->value.str.val, (*arg)->value.str.len, 1); - add_property_resource(return_value, "handle", dirp->id); - zend_list_addref(dirp->id); - } else { - RETURN_RESOURCE(dirp->id); - } -} - -/* }}} */ -/* {{{ proto int opendir(string path) - Open a directory and return a dir_handle */ - -PHP_FUNCTION(opendir) -{ - _php_do_opendir(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); -} - -/* }}} */ -/* {{{ proto class 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([int dir_handle]) - Close directory connection identified by the dir_handle */ - -PHP_FUNCTION(closedir) -{ - pval **id, **tmp, *myself; - php_dir *dirp; - DIRLS_FETCH(); - - FETCH_DIRP(); - - zend_list_delete(dirp->id); -} - -/* }}} */ -/* {{{ proto int chdir(string directory) - Change the current directory */ - -PHP_FUNCTION(chdir) -{ - pval **arg; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - ret = V_CHDIR((*arg)->value.str.val); - - if (ret != 0) { - php_error(E_WARNING, "ChDir: %s (errno %d)", strerror(errno), errno); - RETURN_FALSE; - } - - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto string 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 = V_GETCWD(path,MAXPATHLEN-1); -#elif HAVE_GETWD - ret = V_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([int dir_handle]) - Rewind dir_handle back to the start */ - -PHP_FUNCTION(rewinddir) -{ - pval **id, **tmp, *myself; - php_dir *dirp; - DIRLS_FETCH(); - - FETCH_DIRP(); - - rewinddir(dirp->dir); -} -/* }}} */ -/* {{{ proto string readdir([int dir_handle]) - Read directory entry from dir_handle */ - -PHP_FUNCTION(readdir) -{ - pval **id, **tmp, *myself; - php_dir *dirp; - struct dirent entry; - struct dirent *result; - DIRLS_FETCH(); - - FETCH_DIRP(); - - if (php_readdir_r(dirp->dir, &entry, &result) == 0 && result) { - RETURN_STRINGL(result->d_name, strlen(result->d_name), 1); - } - RETURN_FALSE; -} - -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/dl.c b/ext/standard/dl.c deleted file mode 100644 index 978ae54e90..0000000000 --- a/ext/standard/dl.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "dl.h" -#include "php_globals.h" -#include "ext/standard/info.h" - -#ifdef HAVE_LIBDL -#include <stdlib.h> -#include <stdio.h> - -#if HAVE_STRING_H -#include <string.h> -#else -#include <strings.h> -#endif -#ifdef PHP_WIN32 -#include "win32/param.h" -#include "win32/winutil.h" -#else -#include <sys/param.h> -#endif - -#endif - -/* {{{ proto int dl(string extension_filename) - Load a PHP extension at runtime */ -PHP_FUNCTION(dl) -{ - pval **file; - PLS_FETCH(); - - /* 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(E_ERROR, "Dynamically loaded extentions aren't enabled."); - } else if (PG(safe_mode)) { - php_error(E_ERROR, "Dynamically loaded extensions aren't allowed when running in SAFE MODE."); - } else { - php_dl(*file,MODULE_TEMPORARY,return_value); - } -} - -/* }}} */ - - -#ifdef HAVE_LIBDL - -#ifdef ZTS -#define USING_ZTS 1 -#else -#define USING_ZTS 0 -#endif - -#define IS_SLASH(c) \ - (((c)=='/') || ((c)=='\\')) - -void php_dl(pval *file,int type,pval *return_value) -{ - void *handle; - char *libpath; - zend_module_entry *module_entry,*tmp; - zend_module_entry *(*get_module)(void); - PLS_FETCH(); - ELS_FETCH(); - - if (PG(extension_dir) && PG(extension_dir)[0]){ - int extension_dir_len = strlen(PG(extension_dir)); - - libpath = emalloc(extension_dir_len+file->value.str.len+2); - - if (IS_SLASH(PG(extension_dir)[extension_dir_len-1])) { - sprintf(libpath,"%s%s", PG(extension_dir), file->value.str.val); /* SAFE */ - } else { - sprintf(libpath,"%s/%s", PG(extension_dir), file->value.str.val); /* SAFE */ - } - } else { - libpath = estrndup(file->value.str.val, file->value.str.len); - } - - /* load dynamic symbol */ - handle = DL_LOAD(libpath); - if (!handle) { - int error_type; - - if (type==MODULE_TEMPORARY) { - error_type = E_ERROR; - } else { - error_type = E_CORE_ERROR; - } -#ifdef PHP_WIN32 - php_error(error_type,"Unable to load dynamic library '%s'<br>\n%s",libpath,php_win_err()); -#else - php_error(error_type,"Unable to load dynamic library '%s' - %s",libpath,dlerror()); -#endif - - efree(libpath); - - RETURN_FALSE; - } - - efree(libpath); - - - 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"); - - if (!get_module) { - DL_UNLOAD(handle); - php_error(E_CORE_WARNING,"Invalid library (maybe not a PHP library) '%s' ",file->value.str.val); - 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)) { - php_error(E_CORE_WARNING, - "%s: Unable to initialize module\n" - "Module compiled with debug=%d, thread-safety=%d module API=%d\n" - "PHP compiled with debug=%d, thread-safety=%d module API=%d\n" - "These options need to match\n", - module_entry->name, module_entry->zend_debug, module_entry->zts, module_entry->zend_api, - ZEND_DEBUG, USING_ZTS, ZEND_MODULE_API_NO); - DL_UNLOAD(handle); - RETURN_FALSE; - } - module_entry->type = 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 ELS_CC)==FAILURE) { - php_error(E_CORE_WARNING,"%s: Unable to initialize module",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 ELS_CC)) { - php_error(E_CORE_WARNING,"%s: Unable to initialize module",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(E_ERROR,"%s: Loaded module 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) -{ - php_error(E_WARNING,"Cannot dynamically load %s - dynamic modules are not supported",file->value.str.val); - 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: - */ diff --git a/ext/standard/dl.h b/ext/standard/dl.h deleted file mode 100644 index f816b72c12..0000000000 --- a/ext/standard/dl.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | 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); - - -/* 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 ac366126ba..0000000000 --- a/ext/standard/dns.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef PHP_WIN32 -#if HAVE_BINDLIB -#ifndef WINNT -#define WINNT 1 -#endif -/* located in www.php.net/extra/bindlib.zip */ -#include "arpa/inet.h" -#include "netdb.h" -#include "arpa/nameser.h" -#include "resolv.h" -#endif -#include <winsock.h> -#else -#include <netinet/in.h> -#include <arpa/inet.h> -#include <netdb.h> -#ifdef _OSD_POSIX -#undef STATUS -#undef T_UNSPEC -#endif -#include <arpa/nameser.h> -#include <resolv.h> -#endif - -#include "dns.h" - -char *php_gethostbyaddr(char *ip); -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) -{ - pval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - return_value->value.str.val = php_gethostbyaddr((*arg)->value.str.val); - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = IS_STRING; -} -/* }}} */ - - -char *php_gethostbyaddr(char *ip) -{ - struct in_addr addr; - struct hostent *hp; - - addr.s_addr = inet_addr(ip); - if (addr.s_addr == -1) { -#if PHP_DEBUG - php_error(E_WARNING, "address not in a.b.c.d form"); -#endif - return estrdup(ip); - } - hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET); - if (!hp) { -#if PHP_DEBUG - php_error(E_WARNING, "Unable to resolve %s\n", ip); -#endif - 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) -{ - pval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - return_value->value.str.val = php_gethostbyname((*arg)->value.str.val); - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = IS_STRING; -} -/* }}} */ - -/* {{{ proto array gethostbynamel(string hostname) - Return a list of IP addresses that a given hostname resolves to. */ -PHP_FUNCTION(gethostbynamel) -{ - pval **arg; - struct hostent *hp; - struct in_addr in; - int i; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - hp = gethostbyname((*arg)->value.str.val); - if (hp == NULL || hp->h_addr_list == NULL) { -#if PHP_DEBUG - php_error(E_WARNING, "Unable to resolve %s\n", (*arg)->value.str.val); -#endif - return; - } - - 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); - } - - return; -} -/* }}} */ - -char *php_gethostbyname(char *name) -{ - struct hostent *hp; - struct in_addr in; - - hp = gethostbyname(name); - if (!hp || !hp->h_addr_list) { -#if PHP_DEBUG - php_error(E_WARNING, "Unable to resolve %s\n", name); -#endif - return estrdup(name); - } - memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr)); - return estrdup(inet_ntoa(in)); -} - -#if !defined(PHP_WIN32)||HAVE_BINDLIB - -/* {{{ proto int checkdnsrr(string host [, string type]) - Check DNS records corresponding to a given Internet host name or IP address */ -PHP_FUNCTION(checkdnsrr) -{ - pval **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",(*arg2)->value.str.val) ) type = T_A; - else if ( !strcasecmp("NS",(*arg2)->value.str.val) ) type = T_NS; - else if ( !strcasecmp("MX",(*arg2)->value.str.val) ) type = T_MX; - else if ( !strcasecmp("PTR",(*arg2)->value.str.val) ) type = T_PTR; - else if ( !strcasecmp("ANY",(*arg2)->value.str.val) ) type = T_ANY; - else if ( !strcasecmp("SOA",(*arg2)->value.str.val) ) type = T_SOA; - else if ( !strcasecmp("CNAME",(*arg2)->value.str.val) ) type = T_CNAME; - else { - php_error(E_WARNING,"Type '%s' not supported",(*arg2)->value.str.val); - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - } - i = res_search((*arg1)->value.str.val,C_IN,type,ans,sizeof(ans)); - if ( i < 0 ) { - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - -#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 */ - -/* {{{ proto int getmxrr(string hostname, array mxhosts [, array weight]) - Get MX records corresponding to a given Internet host name */ -PHP_FUNCTION(getmxrr) -{ - 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; - } - if (!ParameterPassedByReference(ht, 2)) { - php_error(E_WARNING, "Array to be filled with values must be passed by reference."); - RETURN_FALSE; - } - break; - case 3: - if (zend_get_parameters(ht, 3, &host, &mx_list, &weight_list) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (!ParameterPassedByReference(ht, 2) || !ParameterPassedByReference(ht, 3)) { - php_error(E_WARNING, "Array to be filled with values must be passed by reference."); - RETURN_FALSE; - } - need_weight = 1; - pval_destructor(weight_list); /* start with clean array */ - if ( array_init(weight_list) == FAILURE ) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string( host ); - pval_destructor(mx_list); /* start with clean array */ - if ( array_init(mx_list) == FAILURE ) { - RETURN_FALSE; - } - - /* Go! */ - i = res_search(host->value.str.val,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 -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/dns.h b/ext/standard/dns.h deleted file mode 100644 index 1e5b755bd8..0000000000 --- a/ext/standard/dns.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: | - | | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _DNS_H -#define _DNS_H - -PHP_FUNCTION(gethostbyaddr); -PHP_FUNCTION(gethostbyname); -PHP_FUNCTION(gethostbynamel); -#if !defined(PHP_WIN32)||(HAVE_BINDLIB) -PHP_FUNCTION(checkdnsrr); -PHP_FUNCTION(getmxrr); -#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 ad57cfd266..0000000000 --- a/ext/standard/exec.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include <ctype.h> -#include "php_string.h" -#include "safe_mode.h" -#include "ext/standard/head.h" -#include "exec.h" -#include "php_globals.h" -#include "SAPI.h" - -#if HAVE_SYS_WAIT_H -#include <sys/wait.h> -#endif - -/* - * 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) - * - */ -static int _Exec(int type, char *cmd, pval *array, pval *return_value) -{ - FILE *fp; - char *buf, *tmp=NULL; - int buflen = 0; - int t, l, ret, output=1; - int overflow_limit, lcmd, ldir; - char *b, *c, *d=NULL; - PLS_FETCH(); - - buf = (char*) emalloc(EXEC_INPUT_BUF); - if (!buf) { - php_error(E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF); - return -1; - } - buflen = EXEC_INPUT_BUF; - - if (PG(safe_mode)) { - lcmd = strlen(cmd); - ldir = strlen(PG(safe_mode_exec_dir)); - l = lcmd + ldir + 2; - overflow_limit = l; - c = strchr(cmd, ' '); - if (c) *c = '\0'; - if (strstr(cmd, "..")) { - php_error(E_WARNING, "No '..' components allowed in path"); - efree(buf); - return -1; - } - d = emalloc(l); - strcpy(d, PG(safe_mode_exec_dir)); - overflow_limit -= ldir; - b = strrchr(cmd, '/'); - if (b) { - strcat(d, b); - overflow_limit -= strlen(b); - } else { - strcat(d, "/"); - strcat(d, cmd); - overflow_limit-=(strlen(cmd)+1); - } - if (c) { - *c = ' '; - strncat(d, c, overflow_limit); - } - tmp = php_escape_shell_cmd(d); - efree(d); - d = tmp; -#ifdef PHP_WIN32 - fp = popen(d, "rb"); -#else - fp = popen(d, "r"); -#endif - if (!fp) { - php_error(E_WARNING, "Unable to fork [%s]", d); - efree(d); - efree(buf); - return -1; - } - } else { /* not safe_mode */ -#ifdef PHP_WIN32 - fp = popen(cmd, "rb"); -#else - fp = popen(cmd, "r"); -#endif - if (!fp) { - php_error(E_WARNING, "Unable to fork [%s]", cmd); - efree(buf); - return -1; - } - } - buf[0] = '\0'; - if (type==2) { - if (array->type != IS_ARRAY) { - pval_destructor(array); - array_init(array); - } - } - if (type != 3) { - l=0; - while ( !feof(fp) || l != 0 ) { - l = 0; - /* Read a line or fill the buffer, whichever comes first */ - do { - if ( buflen <= (l+1) ) { - buf = erealloc(buf, buflen + EXEC_INPUT_BUF); - if ( buf == NULL ) { - php_error(E_WARNING, "Unable to erealloc %d bytes for exec buffer", - buflen + EXEC_INPUT_BUF); - return -1; - } - buflen += EXEC_INPUT_BUF; - } - - if ( fgets(&(buf[l]), buflen - l, fp) == NULL ) { - /* eof */ - break; - } - l += strlen(&(buf[l])); - } while ( (l > 0) && (buf[l-1] != '\n') ); - - if ( feof(fp) && (l == 0) ) { - break; - } - - - if (type == 1) { - if (output) PUTS(buf); - sapi_flush(); - } - else if (type == 2) { - /* strip trailing whitespaces */ - l = strlen(buf); - t = l; - while (l-- && isspace((int)buf[l])); - if (l < t) { - buf[l + 1] = '\0'; - } - add_next_index_string(array, buf, 1); - } - } - - /* strip trailing spaces */ - l = strlen(buf); - t = l; - while (l && isspace((int)buf[--l])); - if (l < t) buf[l + 1] = '\0'; - - /* Return last line from the shell command */ - if (PG(magic_quotes_runtime)) { - int len; - - tmp = php_addslashes(buf, 0, &len, 0); - RETVAL_STRINGL(tmp,len,0); - } else - RETVAL_STRINGL(buf,l+1,1); - } else { - int b, i; - - while ((b = fread(buf, 1, buflen, fp)) > 0) { - for (i = 0; i < b; i++) - if (output) (void)PUTC(buf[i]); - } - } - - ret = pclose(fp); -#if HAVE_SYS_WAIT_H - if (WIFEXITED(ret)) { - ret = WEXITSTATUS(ret); - } -#endif - - if (d) efree(d); - efree(buf); - return ret; -} - -/* {{{ proto int exec(string command [, array output [, int return_value]]) - Execute an external program */ -PHP_FUNCTION(exec) -{ - pval **arg1, **arg2, **arg3; - int arg_count = ZEND_NUM_ARGS(); - int ret; - - if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1,&arg2, &arg3) == FAILURE) { - WRONG_PARAM_COUNT; - } - switch (arg_count) { - case 1: - ret = _Exec(0, (*arg1)->value.str.val, NULL,return_value); - break; - case 2: - if (!ParameterPassedByReference(ht,2)) { - php_error(E_WARNING,"Array argument to exec() not passed by reference"); - } - ret = _Exec(2, (*arg1)->value.str.val,*arg2,return_value); - break; - case 3: - if (!ParameterPassedByReference(ht,2)) { - php_error(E_WARNING,"Array argument to exec() not passed by reference"); - } - if (!ParameterPassedByReference(ht,3)) { - php_error(E_WARNING,"return_status argument to exec() not passed by reference"); - } - ret = _Exec(2,(*arg1)->value.str.val,*arg2,return_value); - (*arg3)->type = IS_LONG; - (*arg3)->value.lval=ret; - break; - } -} - -/* }}} */ - -/* {{{ proto int system(string command [, int return_value]) - Execute an external program and display output */ -PHP_FUNCTION(system) -{ - pval **arg1, **arg2; - int arg_count = ZEND_NUM_ARGS(); - int ret; - - if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - switch (arg_count) { - case 1: - ret = _Exec(1, (*arg1)->value.str.val, NULL,return_value); - break; - case 2: - if (!ParameterPassedByReference(ht,2)) { - php_error(E_WARNING,"return_status argument to system() not passed by reference"); - } - ret = _Exec(1, (*arg1)->value.str.val, NULL,return_value); - (*arg2)->type = IS_LONG; - (*arg2)->value.lval=ret; - break; - } -} -/* }}} */ - -/* {{{ proto void passthru(string command [, int return_value]) - Execute an external program and display raw output */ -PHP_FUNCTION(passthru) -{ - pval **arg1, **arg2; - int arg_count = ZEND_NUM_ARGS(); - int ret; - - if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - switch (arg_count) { - case 1: - ret = _Exec(3, (*arg1)->value.str.val, NULL,return_value); - break; - case 2: - if (!ParameterPassedByReference(ht,2)) { - php_error(E_WARNING,"return_status argument to system() not passed by reference"); - } - ret = _Exec(3, (*arg1)->value.str.val, NULL,return_value); - (*arg2)->type = IS_LONG; - (*arg2)->value.lval=ret; - break; - } -} -/* }}} */ - -static int php_get_index(char *s, char c) -{ - register int x; - - for (x = 0; s[x]; x++) - if (s[x] == c) - return x; - - return -1; -} - -/* 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); - strcpy(cmd, str); - for (x = 0; cmd[x]; x++) { - if (php_get_index("&;`'\"|*?~<>^()[]{}$\\\x0A\xFF", cmd[x]) != -1) { - for (y = l + 1; y > x; y--) - cmd[y] = cmd[y - 1]; - l++; /* length has been increased */ - cmd[x] = '\\'; - x++; /* skip the character */ - } - } - 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 ((*arg1)->value.str.len) { - cmd = php_escape_shell_cmd((*arg1)->value.str.val); - RETVAL_STRING(cmd, 1); - efree(cmd); - } -} -/* }}} */ - -/* {{{ proto string shell_exec(strng cmd) - What excatly is this variant for ??? */ -PHP_FUNCTION(shell_exec) -{ - FILE *in; - int readbytes,total_readbytes=0,allocated_space; - pval **cmd; - PLS_FETCH(); - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1,&cmd)==FAILURE) { - WRONG_PARAM_COUNT; - } - - if (PG(safe_mode)) { - php_error(E_WARNING,"Cannot execute using backquotes in safe mode"); - RETURN_FALSE; - } - - convert_to_string_ex(cmd); -#ifdef PHP_WIN32 - if ((in=popen((*cmd)->value.str.val,"rt"))==NULL) { -#else - if ((in=popen((*cmd)->value.str.val,"r"))==NULL) { -#endif - php_error(E_WARNING,"Unable to execute '%s'",(*cmd)->value.str.val); - } - allocated_space = EXEC_INPUT_BUF; - return_value->value.str.val = (char *) emalloc(allocated_space); - while (1) { - readbytes = fread(return_value->value.str.val+total_readbytes,1,EXEC_INPUT_BUF,in); - if (readbytes<=0) { - break; - } - total_readbytes += readbytes; - allocated_space = total_readbytes+EXEC_INPUT_BUF; - return_value->value.str.val = (char *) erealloc(return_value->value.str.val,allocated_space); - } - pclose(in); - - return_value->value.str.val = erealloc(return_value->value.str.val,total_readbytes+1); - return_value->value.str.val[total_readbytes]=0; - return_value->value.str.len = total_readbytes; - return_value->type = IS_STRING; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/exec.h b/ext/standard/exec.h deleted file mode 100644 index 361554b33b..0000000000 --- a/ext/standard/exec.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _EXEC_H -#define _EXEC_H - -PHP_FUNCTION(system); -PHP_FUNCTION(exec); -PHP_FUNCTION(escapeshellcmd); -PHP_FUNCTION(passthru); -PHP_FUNCTION(shell_exec); - -char *php_escape_shell_cmd(char *); -#endif /* _EXEC_H */ diff --git a/ext/standard/file.c b/ext/standard/file.c deleted file mode 100644 index bd7b7f90cb..0000000000 --- a/ext/standard/file.c +++ /dev/null @@ -1,2039 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $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 <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#ifdef PHP_WIN32 -#include <windows.h> -#include <winsock.h> -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#include "win32/winutil.h" -#else -#include <sys/param.h> -#include <sys/socket.h> -#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" -#else -#include <pwd.h> -#endif -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#ifdef PHP_WIN32 -#include <winsock.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#endif -#include "fsock.h" -#include "fopen-wrappers.h" -#include "php_globals.h" - -#ifdef HAVE_SYS_FILE_H -#include <sys/file.h> -#endif - -#if MISSING_FCLOSE_DECL -extern int fclose(); -#endif - -#ifdef HAVE_SYS_MMAN_H -#include <sys/mman.h> -#endif - -#ifndef MAP_FAILED -#define MAP_FAILED ((void *) -1) -#endif - -#include "php_realpath.h" -#include "scanf.h" -#include "zend_API.h" - - -/* }}} */ -/* {{{ ZTS-stuff / Globals / Prototypes */ - -typedef struct { - int fgetss_state; - int pclose_ret; -} php_file_globals; - -#ifdef ZTS -#define FIL(v) (file_globals->v) -#define FIL_FETCH() php_file_globals *file_globals = ts_resource(file_globals_id) -int file_globals_id; -#else -#define FIL(v) (file_globals.v) -#define FIL_FETCH() -php_file_globals file_globals; -#endif - -static void _file_fopen_dtor(FILE *pipe); -static void _file_popen_dtor(FILE *pipe); -static void _file_socket_dtor(int *sock); -static void _file_upload_dtor(char *file); - -/* sharing globals is *evil* */ -static int le_fopen,le_popen, le_socket, le_uploads; - - -/* }}} */ -/* {{{ tempnam */ - -#ifndef HAVE_TEMPNAM -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif - -#ifndef MAXPATHLEN -# ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX -# else -# define MAXPATHLEN 255 -# endif -#endif - -char *tempnam(const char *dir, const char *pfx) -{ - int save_errno; - char *f, *name; - static char path_tmp[] = "/tmp"; - - if (!(name = emalloc(MAXPATHLEN))) { - return(NULL); - } - - if (!pfx) { - pfx = "tmp."; - } - - if (f = getenv("TMPDIR")) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if (f = mktemp(name)) - return(f); - } - - if (f = (char *)dir) { - (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f, - *(f + strlen(f) - 1) == '/'? "": "/", pfx); - if (f = mktemp(name)) - return(f); - } - - f = P_tmpdir; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if (f = mktemp(name)) - return(f); - - f = path_tmp; - (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx); - if (f = mktemp(name)) - return(f); - - save_errno = errno; - efree(name); - errno = save_errno; - return(NULL); -} - -#endif - -/* }}} */ -/* {{{ Module-Stuff */ - -static void _file_popen_dtor(FILE *pipe) -{ - FIL_FETCH(); - FIL(pclose_ret) = pclose(pipe); -} - - -static void _file_socket_dtor(int *sock) -{ - SOCK_FCLOSE(*sock); -#if HAVE_SHUTDOWN - shutdown(*sock, 0); -#endif - efree(sock); -} - - -static void _file_upload_dtor(char *file) -{ - V_UNLINK(file); -} - - -static void _file_fopen_dtor(FILE *fp) -{ - fclose(fp); -} - - -PHPAPI int php_file_le_fopen(void) /* XXX doe we really want this???? */ -{ - return le_fopen; -} - -PHPAPI int php_file_le_popen(void) /* XXX you may not like this, but I need it. -- KK */ -{ - return le_popen; -} - - -PHPAPI int php_file_le_socket(void) /* XXX doe we really want this???? */ -{ - return le_socket; -} - - -PHPAPI int php_file_le_uploads(void) /* XXX doe we really want this???? */ -{ - return le_uploads; -} - - -#ifdef ZTS -static void php_file_init_globals(php_file_globals *file_globals) -{ - FIL(fgetss_state) = 0; - FIL(pclose_ret) = 0; -} -#endif - -PHP_MINIT_FUNCTION(file) -{ - le_fopen = register_list_destructors(_file_fopen_dtor, NULL); - le_popen = register_list_destructors(_file_popen_dtor, NULL); - le_socket = register_list_destructors(_file_socket_dtor, NULL); - le_uploads = register_list_destructors(_file_upload_dtor, NULL); - -#ifdef ZTS - file_globals_id = ts_allocate_id(sizeof(php_file_globals), (ts_allocate_ctor) php_file_init_globals, NULL); -#else - FIL(fgetss_state) = 0; - FIL(pclose_ret) = 0; -#endif - - 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); - - return SUCCESS; -} - -/* }}} */ -/* {{{ proto bool flock(int fp, int operation [, int wouldblock]) - Portable file locking */ - -static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; - -PHP_FUNCTION(flock) -{ - pval **arg1, **arg2, **arg3; - int type, fd, act, ret, arg_count = ARG_COUNT(ht); - void *what; - - if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, &arg2, &arg3) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - fd = *(int *) what; - } else { - fd = fileno((FILE*) what); - } - - convert_to_long_ex(arg2); - - act = (*arg2)->value.lval & 3; - if (act < 1 || act > 3) { - php_error(E_WARNING, "Illegal operation argument"); - RETURN_FALSE; - } - - /* flock_values contains all possible actions - if (arg2 & 4) we won't block on the lock */ - act = flock_values[act - 1] | ((*arg2)->value.lval & 4 ? LOCK_NB : 0); - if ((ret=flock(fd, act)) == -1) { - RETURN_FALSE; - } - if(ret==-1 && errno==EWOULDBLOCK && arg_count==3) { - (*arg3)->type = IS_LONG; - (*arg3)->value.lval=1; - } - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto array get_meta_tags(string filename [, int use_include_path]) - Extracts all meta tag content attributes from a file and returns an array */ - -PHP_FUNCTION(get_meta_tags) -{ - pval **filename, **arg2; - FILE *fp; - char buf[8192]; - char buf_lcase[8192]; - int use_include_path = 0; - int issock=0, socketd=0; - int len, var_namelen; - char var_name[50],*val=NULL,*tmp,*end,*slashed; - PLS_FETCH(); - - /* check args */ - switch (ARG_COUNT(ht)) { - case 1: - if (zend_get_parameters_ex(1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (zend_get_parameters_ex(2,&filename,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - use_include_path = (*arg2)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - fp = php_fopen_wrapper((*filename)->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL); - if (!fp && !socketd) { - if (issock != BAD_URL) { - char *tmp = estrdup((*filename)->value.str.val); - php_strip_url_passwd(tmp); - php_error(E_WARNING,"get_meta_tags(\"%s\") - %s", tmp, strerror(errno)); - efree(tmp); - } - RETURN_FALSE; - } - - if (array_init(return_value)==FAILURE) { - if (issock) { - SOCK_FCLOSE(socketd); - } else { - fclose(fp); - } - RETURN_FALSE; - } - /* Now loop through the file and do the magic quotes thing if needed */ - memset(buf, 0, 8191); - while((FP_FGETS(buf,8191,socketd,fp,issock) != NULL)) { - memcpy(buf_lcase, buf, 8191); - php_strtolower(buf_lcase, 8191); - if (php_memnstr(buf_lcase, "</head>", sizeof("</head>")-1, buf_lcase + 8191)) - break; - - if(php_memnstr(buf_lcase, "<meta", sizeof("<meta")-1, buf_lcase + 8191)) { - - memset(var_name,0,50); - /* get the variable name from the name attribute of the meta tag */ - tmp = php_memnstr(buf_lcase, "name=\"", sizeof("name=\"")-1, buf_lcase + 8191); - if(tmp) { - tmp = &buf[tmp - buf_lcase]; - tmp+=6; - end=strstr(tmp,"\""); - if(end) { - unsigned char *c; - *end='\0'; - snprintf(var_name,50,"%s",tmp); - *end='"'; - - c = (unsigned char*)var_name; - while (*c) { - switch(*c) { - case '.': - case '\\': - case '+': - case '*': - case '?': - case '[': - case '^': - case ']': - case '$': - case '(': - case ')': - case ' ': - *c++ ='_'; - break; - default: - *c++ = tolower((unsigned char)*c); - } - } - var_namelen=strlen(var_name); - } - - /* get the variable value from the content attribute of the meta tag */ - tmp = php_memnstr(buf_lcase, "content=\"", sizeof("content=\"")-1, buf_lcase + 8191); - if(tmp) { - tmp = &buf[tmp - buf_lcase]; - tmp+=9; - end=strstr(tmp,"\""); - if(end) { - *end='\0'; - val=estrdup(tmp); - *end='"'; - } - } - } - if(*var_name && val) { - if (PG(magic_quotes_runtime)) { - slashed = php_addslashes(val,0,&len,0); - } else { - slashed = estrndup(val,strlen(val)); - } - add_assoc_string(return_value, var_name, slashed, 0); - efree(val); - } - } - } - if (issock) { - SOCK_FCLOSE(socketd); - } else { - fclose(fp); - } -} - -/* }}} */ -/* {{{ proto array file(string filename) - Read entire file into an array */ - -PHP_FUNCTION(file) -{ - pval **filename, **arg2; - FILE *fp; - char *slashed, buf[8192]; - register int i=0; - int use_include_path = 0; - int issock=0, socketd=0; - PLS_FETCH(); - - /* check args */ - switch (ARG_COUNT(ht)) { - case 1: - if (zend_get_parameters_ex(1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (zend_get_parameters_ex(2,&filename,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - use_include_path = (*arg2)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - fp = php_fopen_wrapper((*filename)->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL); - if (!fp && !socketd) { - if (issock != BAD_URL) { - char *tmp = estrdup((*filename)->value.str.val); - php_strip_url_passwd(tmp); - php_error(E_WARNING,"file(\"%s\") - %s", tmp, strerror(errno)); - efree(tmp); - } - RETURN_FALSE; - } - - /* Initialize return array */ - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - /* Now loop through the file and do the magic quotes thing if needed */ - memset(buf,0,8191); - while (FP_FGETS(buf,8191,socketd,fp,issock) != NULL) { - if (PG(magic_quotes_runtime)) { - int len; - - slashed = php_addslashes(buf,0,&len,0); /* 0 = don't free source string */ - add_index_stringl(return_value, i++, slashed, len, 0); - } else { - add_index_string(return_value, i++, buf, 1); - } - } - if (issock) { - SOCK_FCLOSE(socketd); - } else { - fclose(fp); - } -} - - -/* }}} */ -/* {{{ proto string tempnam(string dir, string prefix) - Create a unique filename in a directory */ - -PHP_FUNCTION(tempnam) -{ - pval **arg1, **arg2; - char *d; - char *t; - char p[64]; - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - d = estrndup((*arg1)->value.str.val,(*arg1)->value.str.len); - strlcpy(p,(*arg2)->value.str.val,sizeof(p)); - - t = tempnam(d,p); - efree(d); - if(!t) { - RETURN_FALSE; - } - RETURN_STRING(t,1); -} - -/* }}} */ -/* {{{ proto int tmpfile(void) - Create a temporary file that will be deleted automatically after use */ -PHP_FUNCTION(tmpfile) -{ - FILE *fp; - if (ARG_COUNT(ht) != 0) { - WRONG_PARAM_COUNT; - } - fp = tmpfile(); - if (fp == NULL) { - php_error(E_WARNING, "tmpfile: %s", strerror(errno)); - RETURN_FALSE; - } - ZEND_REGISTER_RESOURCE(return_value, fp, le_fopen); -} -/* }}} */ - -/* {{{ proto int fopen(string filename, string mode [, int use_include_path]) - Open a file or a URL and return a file pointer */ - -PHP_FUNCTION(fopen) -{ - pval **arg1, **arg2, **arg3; - FILE *fp; - char *p; - int *sock; - int use_include_path = 0; - int issock=0, socketd=0; - FIL_FETCH(); - - switch(ARG_COUNT(ht)) { - case 2: - if (zend_get_parameters_ex(2,&arg1,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (zend_get_parameters_ex(3,&arg1,&arg2,&arg3) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg3); - use_include_path = (*arg3)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - p = estrndup((*arg2)->value.str.val,(*arg2)->value.str.len); - - /* - * We need a better way of returning error messages from - * php_fopen_wrapper(). - */ - fp = php_fopen_wrapper((*arg1)->value.str.val, p, use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL); - if (!fp && !socketd) { - if (issock != BAD_URL) { - char *tmp = estrdup((*arg1)->value.str.val); - php_strip_url_passwd(tmp); - php_error(E_WARNING,"fopen(\"%s\",\"%s\") - %s", tmp, p, strerror(errno)); - efree(tmp); - } - efree(p); - RETURN_FALSE; - } - - efree(p); - FIL(fgetss_state)=0; - - if (issock) { - sock=emalloc(sizeof(int)); - *sock=socketd; - ZEND_REGISTER_RESOURCE(return_value,sock,le_socket); - } else { - ZEND_REGISTER_RESOURCE(return_value,fp,le_fopen); - } -} - -/* }}} */ -/* {{{ proto int fclose(int fp) - Close an open file pointer */ - -PHP_FUNCTION(fclose) -{ - pval **arg1; - int type; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,2,le_fopen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - zend_list_delete((*arg1)->value.lval); - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto int popen(string command, string mode) - Execute a command and open either a read or a write pipe to it */ - -PHP_FUNCTION(popen) -{ - pval **arg1, **arg2; - FILE *fp; - char *p,*tmp = NULL; - char *b, buf[1024]; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_string_ex(arg2); - p = estrndup((*arg2)->value.str.val,(*arg2)->value.str.len); - if (PG(safe_mode)){ - b = strchr((*arg1)->value.str.val,' '); - if (!b) { - b = strrchr((*arg1)->value.str.val,'/'); - } else { - char *c; - c = (*arg1)->value.str.val; - 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),(*arg1)->value.str.val); - } - - tmp = php_escape_shell_cmd(buf); - fp = popen(tmp,p); - efree(tmp); - - if (!fp) { - php_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",buf,p,strerror(errno)); - RETURN_FALSE; - } - } else { - fp = popen((*arg1)->value.str.val,p); - if (!fp) { - php_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",(*arg1)->value.str.val,p,strerror(errno)); - efree(p); - RETURN_FALSE; - } - } - efree(p); - - ZEND_REGISTER_RESOURCE(return_value,fp,le_popen); -} - -/* }}} */ -/* {{{ proto int pclose(int fp) - Close a file pointer opened by popen() */ - -PHP_FUNCTION(pclose) -{ - pval **arg1; - void *what; - FIL_FETCH(); - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,1,le_popen); - ZEND_VERIFY_RESOURCE(what); - - zend_list_delete((*arg1)->value.lval); - RETURN_LONG(FIL(pclose_ret)); -} - -/* }}} */ -/* {{{ proto int feof(int fp) - Test for end-of-file on a file pointer */ - -PHP_FUNCTION(feof) -{ - pval **arg1; - int type; - int issock=0; - int socketd=0; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int *) what; - } - - if (FP_FEOF(socketd, (FILE*)what, issock)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto int set_socket_blocking(int socket descriptor, int mode) - Set blocking/non-blocking mode on a socket */ -PHPAPI int php_set_sock_blocking(int socketd, int block) -{ - int ret = SUCCESS; - int flags; - int myflag = 0; - -#ifdef PHP_WIN32 - /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */ - flags = block; - if (ioctlsocket(socketd,FIONBIO,&flags)==SOCKET_ERROR){ - php_error(E_WARNING,"%s",WSAGetLastError()); - ret = FALSE; - } -#else - flags = fcntl(socketd, F_GETFL); -#ifdef O_NONBLOCK - myflag = O_NONBLOCK; /* POSIX version */ -#elif defined(O_NDELAY) - myflag = O_NDELAY; /* old non-POSIX version */ -#endif - if (!block) { - flags |= myflag; - } else { - flags &= ~myflag; - } - fcntl(socketd, F_SETFL, flags); -#endif - return ret; -} - -PHP_FUNCTION(socket_set_blocking) -{ - pval **arg1, **arg2; - int block; - int socketd = 0; - void *what; - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,1,le_socket); - ZEND_VERIFY_RESOURCE(what); - - convert_to_long_ex(arg2); - block = (*arg2)->value.lval; - - socketd = *(int*)what; - - if (php_set_sock_blocking(socketd, block) == FAILURE) - RETURN_FALSE; - - php_sockset_blocking(socketd, block == 0 ? 0 : 1); - - RETURN_TRUE; -} - -/* }}} */ - -PHP_FUNCTION(set_socket_blocking) -{ - php_error(E_NOTICE, "set_socket_blocking() is deprecated, use socket_set_blocking() instead"); - PHP_FN(socket_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} - -/* {{{ proto bool socket_set_timeout(int socket descriptor, int seconds, int microseconds) - Set timeout on socket read to seconds + microseonds */ -PHP_FUNCTION(socket_set_timeout) -{ -#if HAVE_SYS_TIME_H - zval **socket, **seconds, **microseconds; - int type; - void *what; - int socketd = 0; - struct timeval t; - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, µseconds)==FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(socket, -1, "File-Handle", &type, 1, le_socket); - ZEND_VERIFY_RESOURCE(what); - socketd = *(int *)what; - - convert_to_long_ex(seconds); - t.tv_sec = (*seconds)->value.lval; - - if (ZEND_NUM_ARGS() == 3) { - convert_to_long_ex(microseconds); - t.tv_usec = (*microseconds)->value.lval % 1000000; - t.tv_sec += (*microseconds)->value.lval / 1000000; - } - else - t.tv_usec = 0; - - php_sockset_timeout(socketd, &t); - RETURN_TRUE; -#endif /* HAVE_SYS_TIME_H */ -} - -/* }}} */ - - -/* {{{ proto array socket_get_status(resource socket_descriptor) - Return an array describing socket status */ -PHP_FUNCTION(socket_get_status) -{ - zval **socket; - int type; - void *what; - int socketd = 0; - struct php_sockbuf *sock; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(socket, -1, "File-Handle", &type, 1, le_socket); - ZEND_VERIFY_RESOURCE(what); - socketd = *(int *)what; - sock = php_get_socket(socketd); - - array_init(return_value); - - 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", sock->eof); - add_assoc_long(return_value, "unread_bytes", sock->writepos - sock->readpos); -} -/* }}} */ - - -/* {{{ proto string fgets(int fp, int length) - Get a line from file pointer */ - -PHP_FUNCTION(fgets) -{ - pval **arg1, **arg2; - int len, type; - char *buf; - int issock=0; - int socketd=0; - void *what; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - convert_to_long_ex(arg2); - len = (*arg2)->value.lval; - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - buf = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - memset(buf,0,len+1); - if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) { - efree(buf); - RETVAL_FALSE; - } else { - if (PG(magic_quotes_runtime)) { - return_value->value.str.val = php_addslashes(buf,0,&return_value->value.str.len,1); - } else { - return_value->value.str.val = buf; - return_value->value.str.len = strlen(return_value->value.str.val); - } - return_value->type = IS_STRING; - } -} - -/* }}} */ -/* {{{ proto string fgetc(int fp) - Get a character from file pointer */ - -PHP_FUNCTION(fgetc) { - pval **arg1; - int type; - char *buf; - int issock=0; - int socketd=0; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - buf = emalloc(sizeof(char) * 2); - if (!(*buf = FP_FGETC(socketd, (FILE*)what, issock))) { - efree(buf); - RETVAL_FALSE; - } else { - buf[1]='\0'; - return_value->value.str.val = buf; - return_value->value.str.len = 1; - return_value->type = IS_STRING; - } -} - -/* }}} */ - -/* {{{ proto string fgetss(int fp, int length [, string allowable_tags]) - Get a line from file pointer and strip HTML tags */ - -PHP_FUNCTION(fgetss) -{ - pval **fd, **bytes, **allow=NULL; - int len, type; - char *buf; - int issock=0; - int socketd=0; - void *what; - char *allowed_tags=NULL; - int allowed_tags_len=0; - FIL_FETCH(); - - switch(ARG_COUNT(ht)) { - 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 = (*allow)->value.str.val; - allowed_tags_len = (*allow)->value.str.len; - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - what = zend_fetch_resource(fd,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - convert_to_long_ex(bytes); - len = (*bytes)->value.lval; - - buf = emalloc(sizeof(char) * (len + 1)); - /*needed because recv doesnt set null char at end*/ - memset(buf, 0, len + 1); - if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) { - efree(buf); - RETURN_FALSE; - } - - /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), FIL(fgetss_state), allowed_tags, allowed_tags_len); - - RETURN_STRING(buf, 0); -} - -/* }}} */ -/* {{{ proto mixed fscanf(string str,string format, ...) - implements a mostly ANSI compatible fscanf() . */ -PHP_FUNCTION(fscanf) -{ - int result; - pval **file_handle, **format_string; - int len, type; - char *buf; - int issock=0; - int socketd=0; - void *what; - - zval ***args; - int argCount; - PLS_FETCH(); - - argCount = ZEND_NUM_ARGS(); - if (argCount < 2) { - WRONG_PARAM_COUNT; - } - args = (zval ***)emalloc(argCount * sizeof(zval **)); - if (!args || (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,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - - /* - * 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; - } - - len = SCAN_MAX_FSCANF_BUFSIZE; - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - buf = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - memset(buf,0,len+1); - if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) { - efree(buf); - RETVAL_FALSE; - } else { - convert_to_string_ex( format_string ); - result = php_sscanf_internal( buf,(*format_string)->value.str.val, - argCount,args, 2,&return_value); - efree(args); - efree(buf); - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { - WRONG_PARAM_COUNT - } - } - - -} -/* }}} */ - -/* {{{ proto int fwrite(int fp, string str [, int length]) - Binary-safe file write */ - -PHP_FUNCTION(fwrite) -{ - pval **arg1, **arg2, **arg3=NULL; - int ret,type; - int num_bytes; - int issock=0; - int socketd=0; - void *what; - PLS_FETCH(); - - switch (ARG_COUNT(ht)) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - num_bytes = (*arg2)->value.str.len; - 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((*arg3)->value.lval, (*arg2)->value.str.len); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - if (!arg3 && PG(magic_quotes_runtime)) { - zval_copy_ctor(*arg2); - php_stripslashes((*arg2)->value.str.val,&num_bytes); - } - - if (issock){ - ret = SOCK_WRITEL((*arg2)->value.str.val,num_bytes,socketd); - } else { - ret = fwrite((*arg2)->value.str.val,1,num_bytes,(FILE*)what); - } - RETURN_LONG(ret); -} - -/* }}} */ -/* {{{ proto int fflush(int fp) - flushes output */ - -PHP_FUNCTION(fflush) -{ - pval **arg1; - int ret,type; - int issock=0; - int socketd=0; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - if (issock){ - ret = fsync(socketd); - } else { - ret = fflush((FILE*)what); - } - - if (ret) { - RETURN_FALSE; - } else { - RETURN_TRUE; - } -} - -/* }}} */ -/* {{{ proto int set_file_buffer(int fp, int buffer) - Set file write buffer */ - -PHP_FUNCTION(set_file_buffer) -{ - pval **arg1, **arg2; - int ret,type,buff; - void *what; - - switch (ARG_COUNT(ht)) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,2,le_fopen,le_popen); - ZEND_VERIFY_RESOURCE(what); - - convert_to_long_ex(arg2); - buff = (*arg2)->value.lval; - - /* if buff is 0 then set to non-buffered */ - if (buff == 0){ - ret = setvbuf((FILE*)what, NULL, _IONBF, 0); - } else { - ret = setvbuf((FILE*)what, NULL, _IOFBF, buff); - } - - RETURN_LONG(ret); -} - -/* }}} */ -/* {{{ proto int rewind(int fp) - Rewind the position of a file pointer */ - -PHP_FUNCTION(rewind) -{ - pval **arg1; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen); - ZEND_VERIFY_RESOURCE(what); - - rewind((FILE*) what); - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto int ftell(int fp) - Get file pointer's read/write position */ - -PHP_FUNCTION(ftell) -{ - pval **arg1; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen); - ZEND_VERIFY_RESOURCE(what); - - RETURN_LONG(ftell((FILE*) what)); -} - -/* }}} */ -/* {{{ proto int fseek(int fp, int offset [, int whence]) - Seek on a file pointer */ - -PHP_FUNCTION(fseek) -{ - zval **arg1, **arg2, **arg3; - int argcount = ARG_COUNT(ht), whence = SEEK_SET; - void *what; - - if (argcount < 2 || argcount > 3 || - zend_get_parameters_ex(argcount, &arg1, &arg2, &arg3) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen); - ZEND_VERIFY_RESOURCE(what); - - convert_to_long_ex(arg2); - if (argcount > 2) { - convert_to_long_ex(arg3); - whence = (*arg3)->value.lval; - } - - RETURN_LONG(fseek((FILE*)what, (*arg2)->value.lval, whence)); -} - -/* }}} */ -/* {{{ proto int mkdir(string pathname, int mode) - Create a directory */ - -PHP_FUNCTION(mkdir) -{ - pval **arg1, **arg2; - int ret,mode; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - convert_to_long_ex(arg2); - mode = (*arg2)->value.lval; - if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val,3))) { - RETURN_FALSE; - } - ret = V_MKDIR((*arg1)->value.str.val,mode); - if (ret < 0) { - php_error(E_WARNING,"MkDir failed (%s)", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto int rmdir(string dirname) - Remove a directory */ - -PHP_FUNCTION(rmdir) -{ - pval **arg1; - int ret; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val,1))) { - RETURN_FALSE; - } - ret = rmdir((*arg1)->value.str.val); - if (ret < 0) { - php_error(E_WARNING,"RmDir failed (%s)", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} - -/* }}} */ -/* {{{ php_passthru_fd */ - -static size_t php_passthru_fd(int socketd, FILE *fp, int issock) -{ - size_t bcount = 0; - int ready = 0; - char buf[8192]; - -#ifdef HAVE_MMAP - if(!issock) { - int fd; - struct stat sbuf; - off_t off; - void *p; - size_t len; - - fd = fileno(fp); - fstat(fd, &sbuf); - - if(sbuf.st_size > sizeof(buf)) { - off = ftell(fp); - len = sbuf.st_size - off; - p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off); - if(p!=MAP_FAILED) { - PHPWRITE(p, len); - munmap(p, len); - bcount += len; - ready = 1; - } - } - } -#endif - - if(!ready) { - int b; - - while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) { - PHPWRITE(buf, b); - bcount += b; - } - } - - return bcount; -} - -/* }}} */ -/* {{{ proto int readfile(string filename [, int use_include_path]) - Output a file or a URL */ - -PHP_FUNCTION(readfile) -{ - pval **arg1, **arg2; - FILE *fp; - int size=0; - int use_include_path=0; - int issock=0, socketd=0; - - /* check args */ - switch (ARG_COUNT(ht)) { - 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 = (*arg2)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - - /* - * We need a better way of returning error messages from - * php_fopen_wrapper(). - */ - fp = php_fopen_wrapper((*arg1)->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL); - if (!fp && !socketd){ - if (issock != BAD_URL) { - char *tmp = estrdup((*arg1)->value.str.val); - php_strip_url_passwd(tmp); - php_error(E_WARNING,"readfile(\"%s\") - %s", tmp, strerror(errno)); - efree(tmp); - } - RETURN_FALSE; - } - if (php_header()) { - size = php_passthru_fd(socketd, fp, issock); - } - if (issock) { - SOCK_FCLOSE(socketd); - } else { - fclose(fp); - } - RETURN_LONG(size); -} - -/* }}} */ -/* {{{ proto int umask([int mask]) - Return or change the umask */ - -PHP_FUNCTION(umask) -{ - pval **arg1; - int oldumask; - int arg_count = ARG_COUNT(ht); - - 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((*arg1)->value.lval); - } - - /* XXX we should maybe reset the umask after each request! */ - - RETURN_LONG(oldumask); -} - -/* }}} */ -/* {{{ proto int fpassthru(int fp) - Output all remaining data from a file pointer */ - -PHP_FUNCTION(fpassthru) -{ - pval **arg1; - int size, type; - int issock=0; - int socketd=0; - void *what; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - size = 0; - if (php_header()) { /* force headers if not already sent */ - size = php_passthru_fd(socketd, (FILE*) what, issock); - } - - zend_list_delete((*arg1)->value.lval); - RETURN_LONG(size); -} - -/* }}} */ -/* {{{ proto int rename(string old_name, string new_name) - Rename a file */ - -PHP_FUNCTION(rename) -{ - pval **old_arg, **new_arg; - char *old_name, *new_name; - int ret; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 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 = (*old_arg)->value.str.val; - new_name = (*new_arg)->value.str.val; - - if (PG(safe_mode) &&(!php_checkuid(old_name, 2))) { - RETURN_FALSE; - } - ret = rename(old_name, new_name); - - if (ret == -1) { - php_error(E_WARNING,"Rename failed (%s)", strerror(errno)); - RETURN_FALSE; - } - - RETVAL_TRUE; -} - -/* }}} */ -/* {{{ proto int ftruncate (int fp, int size) - Truncate file to 'size' length */ -PHP_FUNCTION(ftruncate) -{ - zval **fp , **size; - short int ret; - int type; - void *what; - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) - { - php_error(E_WARNING, "can't truncate sockets!"); - RETURN_FALSE; - } - - convert_to_long_ex(size); - - ret = ftruncate(fileno((FILE *)what), (*size)->value.lval); - RETURN_LONG(ret + 1); -} -/* }}} */ - -/* {{{ proto int fstat (int fp) - Stat() on a filehandle */ -PHP_FUNCTION(fstat) -{ - zval **fp; - int type; - void *what; - struct stat stat_sb; - - if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (fstat(fileno((FILE *) what ), &stat_sb)) { - RETURN_FALSE; - } - - array_init(return_value); - - add_assoc_long ( return_value , "dev" , stat_sb.st_dev ); - add_assoc_long ( return_value , "ino" , stat_sb.st_ino ); - add_assoc_long ( return_value , "mode" , stat_sb.st_mode ); - add_assoc_long ( return_value , "nlink" , stat_sb.st_nlink ); - add_assoc_long ( return_value , "uid" , stat_sb.st_uid ); - add_assoc_long ( return_value , "gid" , stat_sb.st_gid ); - -#ifdef HAVE_ST_BLKSIZE - add_assoc_long ( return_value, "rdev" , stat_sb.st_rdev ); - add_assoc_long ( return_value , "blksize" , stat_sb.st_blksize ); -#endif - - add_assoc_long ( return_value , "size" , stat_sb.st_size ); - add_assoc_long ( return_value , "atime" , stat_sb.st_atime ); - add_assoc_long ( return_value , "mtime" , stat_sb.st_mtime ); - add_assoc_long ( return_value , "ctime" , stat_sb.st_ctime ); - -#ifdef HAVE_ST_BLOCKS - add_assoc_long ( return_value , "blocks" , stat_sb.st_blocks ); -#endif -} -/* }}} */ - - -/* {{{ proto int copy(string source_file, string destination_file) - Copy a file */ - -PHP_FUNCTION(copy) -{ - pval **source, **target; - char buffer[8192]; - int fd_s,fd_t,read_bytes; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 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((*source)->value.str.val,2))) { - RETURN_FALSE; - } - -#ifdef PHP_WIN32 - if ((fd_s=V_OPEN((Z_STRVAL_PP(source),O_RDONLY|_O_BINARY)))==-1) { -#else - if ((fd_s=V_OPEN((Z_STRVAL_PP(source),O_RDONLY)))==-1) { -#endif - php_error(E_WARNING,"Unable to open '%s' for reading: %s", Z_STRVAL_PP(source), strerror(errno)); - RETURN_FALSE; - } -#ifdef PHP_WIN32 - if ((fd_t=V_OPEN((Z_STRVAL_PP(target),_O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY,_S_IREAD|_S_IWRITE)))==-1){ -#else - if ((fd_t=V_CREAT(Z_STRVAL_PP(target),0700))==-1) { -#endif - php_error(E_WARNING,"Unable to create '%s': %s", Z_STRVAL_PP(target), strerror(errno)); - close(fd_s); - RETURN_FALSE; - } - - while ((read_bytes=read(fd_s,buffer,8192))!=-1 && read_bytes!=0) { - if (write(fd_t,buffer,read_bytes)==-1) { - php_error(E_WARNING,"Unable to write to '%s': %s", Z_STRVAL_PP(target), strerror(errno)); - close(fd_s); - close(fd_t); - RETURN_FALSE; - } - } - - close(fd_s); - close(fd_t); - - RETVAL_TRUE; -} - -/* }}} */ -/* {{{ proto int fread(int fp, int length) - Binary-safe file read */ - -PHP_FUNCTION(fread) -{ - pval **arg1, **arg2; - int len, type; - int issock=0; - int socketd=0; - void *what; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - convert_to_long_ex(arg2); - len = (*arg2)->value.lval; - - return_value->value.str.val = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - - if (!issock) { - return_value->value.str.len = fread(return_value->value.str.val, 1, len, (FILE*)what); - return_value->value.str.val[return_value->value.str.len] = 0; - } else { - return_value->value.str.len = SOCK_FREAD(return_value->value.str.val, len, socketd); - } - if (PG(magic_quotes_runtime)) { - return_value->value.str.val = php_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1); - } - return_value->type = IS_STRING; -} - -/* }}} */ -/* {{{ proto array fgetcsv(int fp, int length) - 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 */ - - /* first section exactly as php_fgetss */ - - pval **fd, **bytes, **p_delim; - int len, type; - char *buf; - int issock=0; - int socketd=0; - void *what; - - switch(ARG_COUNT(ht)) { - 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 ((*p_delim)->value.str.len < 1) { - WRONG_PARAM_COUNT; - } - /* use first character from string */ - delimiter = (*p_delim)->value.str.val[0]; - break; - - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - what = zend_fetch_resource(fd,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - if (type == le_socket) { - issock=1; - socketd=*(int*)what; - } - - convert_to_long_ex(bytes); - len = (*bytes)->value.lval; - - buf = emalloc(sizeof(char) * (len + 1)); - /*needed because recv doesnt set null char at end*/ - memset(buf, 0, len + 1); - if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) { - efree(buf); - RETURN_FALSE; - } - - /* Now into new section that parses buf for comma/quote delimited fields */ - - /* Strip trailing space from buf, saving end of line in case required for quoted field */ - - lineEnd = emalloc(sizeof(char) * (len + 1)); - bptr = buf; - tptr = buf + strlen(buf) -1; - while ( isspace((int)*tptr) && (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 = emalloc(sizeof(char) * len); /* unlikely but possible! */ - tptr = temp; - - /* Initialize return array */ - if (array_init(return_value) == FAILURE) { - efree(lineEnd); - efree(temp); - efree(buf); - RETURN_FALSE; - } - - /* 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)*bptr)) bptr++; - /* 2. Read field, leaving bptr pointing at start of next field */ - if (*bptr == '"') { - /* 2A. handle quote delimited field */ - bptr++; /* move on to first character in field */ - while (*bptr) { - if (*bptr == '"') { - /* handle the double-quote */ - if ( *(bptr+1) == '"') { - /* embedded double quotes */ - *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 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 (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) { - efree(lineEnd); efree(temp); efree(buf); - RETURN_FALSE; - } - bptr = buf; - tptr = buf + strlen(buf) -1; - while ( isspace((int)*tptr) && (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-quoted field */ - while ( (*bptr != delimiter) && *bptr ) *tptr++ = *bptr++; - *tptr=0; /* terminate temporary string */ - if (strlen(temp)) { - tptr--; - while (isspace((int)*tptr)) *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); -} - -/* }}} */ - -/* {{{ proto string realpath(string path) - Return the resolved path */ -PHP_FUNCTION(realpath) -{ - zval **path; - char resolved_path[MAXPATHLEN]; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(path); - if (php_realpath((*path)->value.str.val, resolved_path)) { - RETURN_STRING(resolved_path, 1); - } else { - RETURN_FALSE; - } -} -/* }}} */ - - - -#if 0 - -static fd_set readfd; -static int max_fd; - -PHP_FUNCTION(fd_set) -{ - pval **arg; - void *what; - int type, fd; - - if(ARG_COUNT(ht) <= 0) { - php_error(E_WARNING, "fd_set: Must be passed at least one value" ); - var_uninit(return_value); - return; - } - else if(ARG_COUNT(ht) == 1) { - if(zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - what = zend_fetch_resource(arg,-1,"select",&type,3,le_fopen,le_socket,le_popen); - ZEND_VERIFY_RESOURCE(what); - if(type == le_socket) { - fd = *(int *)what; - } else { - fd = fileno((FILE *)what); - } - max_fd = fd; - FD_ZERO(&readfd); - FD_SET(max_fd, &readfd); - } - else { - pval ***args = (pval ***) emalloc(sizeof(pval **) * ARG_COUNT(ht)); - int i; - if(zend_get_parameters_array_ex(ARG_COUNT(ht), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - FD_ZERO(&readfd); - for(i = 0; i < ARG_COUNT(ht); i++) { - what = zend_fetch_resource(*args,-1,"select",&type,3,le_fopen,le_socket,le_popen); - ZEND_VERIFY_RESOURCE(what); - if(type == le_socket) { - fd = *(int *)what; - } else { - fd = fileno((FILE *)what); - } - FD_SET(fd, &readfd); - if(fd > max_fd) max_fd = fd; - } - efree(args); - } - RETURN_LONG(1); -} - -PHP_FUNCTION(select) -{ - pval **timeout; - struct timeval tv; - - if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &timeout) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_long_ex(timeout); - - tv.tv_sec = (*timeout)->value.lval / 1000000; - tv.tv_usec = (*timeout)->value.lval % 1000000; - - RETURN_LONG(select(max_fd + 1,&readfd,NULL,NULL,((*timeout)->value.lval <= 0) ? NULL : &tv)); -} - -PHP_FUNCTION(fd_isset) -{ - pval **fdarg; - void *what; - int type, fd; - - if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fdarg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(fdarg,-1,"select",&type,3,le_fopen,le_socket,le_popen); - ZEND_VERIFY_RESOURCE(what); - - if(type == le_socket) { - fd = *(int *)what; - } else { - fd = fileno((FILE *)what); - } - - if(FD_ISSET(fd,&readfd)) { - RETURN_TRUE; - } - RETURN_FALSE; -} - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/file.h b/ext/standard/file.h deleted file mode 100644 index adf9d9b028..0000000000 --- a/ext/standard/file.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: 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 - -extern PHP_MINIT_FUNCTION(file); - -PHP_FUNCTION(tempnam); -PHP_FUNCTION(tmpfile); -PHP_FUNCTION(fopen); -PHP_FUNCTION(fclose); -PHP_FUNCTION(popen); -PHP_FUNCTION(pclose); -PHP_FUNCTION(feof); -PHP_FUNCTION(fread); -PHP_FUNCTION(fgetc); -PHP_FUNCTION(fgets); -PHP_FUNCTION(fscanf); -PHP_FUNCTION(fgetss); -PHP_FUNCTION(fgetcsv); -PHP_FUNCTION(fwrite); -PHP_FUNCTION(fflush); -PHP_FUNCTION(rewind); -PHP_FUNCTION(ftell); -PHP_FUNCTION(fseek); -PHP_FUNCTION(mkdir); -PHP_FUNCTION(rmdir); -PHP_FUNCTION(fpassthru); -PHP_FUNCTION(readfile); -PHP_FUNCTION(umask); -PHP_FUNCTION(rename); -PHP_FUNCTION(copy); -PHP_FUNCTION(file); -PHP_FUNCTION(set_socket_blocking); /* deprecated */ -PHP_FUNCTION(socket_set_blocking); -PHP_FUNCTION(socket_set_timeout); -PHP_FUNCTION(socket_get_status); -PHP_FUNCTION(set_file_buffer); -PHP_FUNCTION(get_meta_tags); -PHP_FUNCTION(flock); -PHP_FUNCTION(fd_set); -PHP_FUNCTION(fd_isset); -PHP_FUNCTION(select); -PHP_FUNCTION(realpath); -PHP_FUNCTION(ftruncate); -PHP_FUNCTION(fstat); - -PHPAPI int php_set_sock_blocking(int socketd, int block); -PHPAPI int php_file_le_fopen(void); -PHPAPI int php_file_le_popen(void); -PHPAPI int php_file_le_socket(void); -PHPAPI int php_file_le_uploads(void); - -#endif /* _FILE_H */ diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c deleted file mode 100644 index 7b95a36cde..0000000000 --- a/ext/standard/filestat.c +++ /dev/null @@ -1,722 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 - -#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> -#endif - -#if HAVE_PWD_H -# ifdef PHP_WIN32 -# include "win32/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 - -#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 - -#define S_IXROOT ( S_IXUSR | S_IXGRP | S_IXOTH ) - -PHP_RINIT_FUNCTION(filestat) -{ - BLS_FETCH(); - - BG(CurrentStatFile)=NULL; - BG(CurrentStatLength)=0; - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(filestat) -{ - BLS_FETCH(); - - if (BG(CurrentStatFile)) { - efree (BG(CurrentStatFile)); - } - return SUCCESS; -} - -/* {{{ proto double diskfreespace(string path) - Get free diskspace for filesystem that path is on */ -PHP_FUNCTION(diskfreespace) -{ - 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_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((*path)->value.str.val)) 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((*path)->value.str.val, - &FreeBytesAvailableToCaller, - &TotalNumberOfBytes, - &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; - - /* i know - this is ugly, but i works (thies@digicol.de) */ - bytesfree = FreeBytesAvailableToCaller.HighPart * - (double) (((unsigned long)1) << 31) * 2.0 + - FreeBytesAvailableToCaller.LowPart; - } - /* If it's not available, we just use GetDiskFreeSpace */ - else { - if (GetDiskFreeSpace((*path)->value.str.val, - &SectorsPerCluster, &BytesPerSector, - &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; - bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector; - } - } - else { - php_error(E_WARNING, "Unable to load kernel32.dll"); - RETURN_FALSE; - } - -#elif defined(OS2) - { - FSALLOCATE fsinfo; - char drive = (*path)->value.str.val[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((*path)->value.str.val,&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_STATFS) - if (statfs((*path)->value.str.val,&buf)) RETURN_FALSE; - bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail)); -#endif -#endif /* WINDOWS */ - - RETURN_DOUBLE(bytesfree); -} -/* }}} */ - -/* {{{ proto bool chown(string filename, mixed user) - Change file owner */ -PHP_FUNCTION(chgrp) -{ -#ifndef WINDOWS - pval **filename, **group; - gid_t gid; - struct group *gr=NULL; - int ret; - PLS_FETCH(); - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2,&filename,&group)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - if ((*group)->type == IS_STRING) { - gr = getgrnam((*group)->value.str.val); - if (!gr) { - php_error(E_WARNING, "unable to find gid for %s", - (*group)->value.str.val); - RETURN_FALSE; - } - gid = gr->gr_gid; - } else { - convert_to_long_ex(group); - gid = (*group)->value.lval; - } - - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val,1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val)) - RETURN_FALSE; - - ret = chown((*filename)->value.str.val, -1, gid); - if (ret == -1) { - php_error(E_WARNING, "chgrp failed: %s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -#else - RETURN_FALSE; -#endif -} -/* }}} */ - -/* {{{ proto bool chgrp(string filename, mixed group) - Change file group */ -PHP_FUNCTION(chown) -{ -#ifndef WINDOWS - pval **filename, **user; - int ret; - uid_t uid; - struct passwd *pw = NULL; - PLS_FETCH(); - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2,&filename,&user)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - if ((*user)->type == IS_STRING) { - pw = getpwnam((*user)->value.str.val); - if (!pw) { - php_error(E_WARNING, "unable to find uid for %s", - (*user)->value.str.val); - RETURN_FALSE; - } - uid = pw->pw_uid; - } else { - convert_to_long_ex(user); - uid = (*user)->value.lval; - } - - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val,1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val)) - RETURN_FALSE; - - ret = chown((*filename)->value.str.val, uid, -1); - if (ret == -1) { - php_error(E_WARNING, "chown failed: %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,imode; - PLS_FETCH(); - - 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((*filename)->value.str.val,1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val)) - RETURN_FALSE; - - imode = (*mode)->value.lval; - /* 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 = chmod((*filename)->value.str.val, imode); - if (ret == -1) { - php_error(E_WARNING, "chmod failed: %s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} -/* }}} */ - - -/* {{{ proto bool touch(string filename[, int time]) - Set modification time of file */ -PHP_FUNCTION(touch) -{ -#if HAVE_UTIME - pval **filename, **filetime; - int ret; - struct stat sb; - FILE *file; - struct utimbuf *newtime = NULL; - int ac = ZEND_NUM_ARGS(); - PLS_FETCH(); - - if (ac == 1 && zend_get_parameters_ex(1,&filename) != FAILURE) { -#ifndef HAVE_UTIME_NULL - newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf)); - if (!newtime) { - php_error(E_WARNING, "unable to emalloc memory for changing time"); - return; - } - newtime->actime = time(NULL); - newtime->modtime = newtime->actime; -#endif - } else if (ac == 2 && zend_get_parameters_ex(2,&filename,&filetime) != FAILURE) { - newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf)); - if (!newtime) { - php_error(E_WARNING, "unable to emalloc memory for changing time"); - return; - } - convert_to_long_ex(filetime); - newtime->actime = (*filetime)->value.lval; - newtime->modtime = (*filetime)->value.lval; - } else { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val,1))) { - if (newtime) efree(newtime); - RETURN_FALSE; - } - - /* Check the basedir */ - if (php_check_open_basedir((*filename)->value.str.val)) - RETURN_FALSE; - - /* create the file if it doesn't exist already */ - ret = V_STAT((*filename)->value.str.val, &sb); - if (ret == -1) { - file = V_FOPEN((*filename)->value.str.val, "w"); - if (file == NULL) { - php_error(E_WARNING, "unable to create file %s because %s", (*filename)->value.str.val, strerror(errno)); - if (newtime) efree(newtime); - RETURN_FALSE; - } - fclose(file); - } - - ret = utime((*filename)->value.str.val, newtime); - if (newtime) efree(newtime); - if (ret == -1) { - php_error(E_WARNING, "utime failed: %s", strerror(errno)); - RETURN_FALSE; - } else { - RETURN_TRUE; - } -#endif -} -/* }}} */ - - -/* {{{ proto void clearstatcache(void) - Clear file stat cache */ -PHP_FUNCTION(clearstatcache) -{ - BLS_FETCH(); - - if (BG(CurrentStatFile)) { - efree(BG(CurrentStatFile)); - BG(CurrentStatFile) = NULL; - } -} -/* }}} */ - - -static void php_stat(const char *filename, int type, pval *return_value) -{ - struct stat *stat_sb; - int rmask=S_IROTH,wmask=S_IWOTH,xmask=S_IXOTH; /* access rights defaults to other */ - BLS_FETCH(); - - stat_sb = &BG(sb); - - if (!BG(CurrentStatFile) || strcmp(filename,BG(CurrentStatFile))) { - if (!BG(CurrentStatFile) - || strlen(filename) > BG(CurrentStatLength)) { - if (BG(CurrentStatFile)) efree(BG(CurrentStatFile)); - BG(CurrentStatLength) = strlen(filename); - BG(CurrentStatFile) = estrndup(filename,BG(CurrentStatLength)); - } else { - strcpy(BG(CurrentStatFile),filename); - } -#if HAVE_SYMLINK - BG(lsb).st_mode = 0; /* mark lstat buf invalid */ -#endif - if (V_STAT(BG(CurrentStatFile),&BG(sb))==-1) { - if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */ - php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno)); - } - efree(BG(CurrentStatFile)); - BG(CurrentStatFile)=NULL; - RETURN_FALSE; - } - } - -#if HAVE_SYMLINK - if (8 == type /* filetype */ - || 14 == type /* is link */ - || 16 == type) { /* lstat */ - - /* do lstat if the buffer is empty */ - - if (!BG(lsb).st_mode) { - if (V_LSTAT(BG(CurrentStatFile),&BG(lsb)) == -1) { - php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno)); - RETURN_FALSE; - } - } - } -#endif - - - 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); - } - } - - switch(type) { - case 0: /* fileperms */ - RETURN_LONG((long)BG(sb).st_mode); - case 1: /* fileinode */ - RETURN_LONG((long)BG(sb).st_ino); - case 2: /* filesize */ - RETURN_LONG((long)BG(sb).st_size); - case 3: /* fileowner */ - RETURN_LONG((long)BG(sb).st_uid); - case 4: /* filegroup */ - RETURN_LONG((long)BG(sb).st_gid); - case 5: /* fileatime */ - RETURN_LONG((long)BG(sb).st_atime); - case 6: /* filemtime */ - RETURN_LONG((long)BG(sb).st_mtime); - case 7: /* filectime */ - RETURN_LONG((long)BG(sb).st_ctime); - case 8: /* filetype */ -#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); - } - php_error(E_WARNING,"Unknown file type (%d)",BG(sb).st_mode&S_IFMT); - RETURN_STRING("unknown",1); - case 9: /*is writable*/ - if(getuid()==0) RETURN_LONG(1); /* root */ - RETURN_LONG((BG(sb).st_mode&wmask)!=0); - case 10: /*is readable*/ - if(getuid()==0) RETURN_LONG(1); /* root */ - RETURN_LONG((BG(sb).st_mode&rmask)!=0); - case 11: /*is executable*/ - if(getuid()==0) xmask = S_IXROOT; /* root */ - RETURN_LONG((BG(sb).st_mode&xmask)!=0 && !S_ISDIR(BG(sb).st_mode)); - case 12: /*is file*/ - RETURN_LONG(S_ISREG(BG(sb).st_mode)); - case 13: /*is dir*/ - RETURN_LONG(S_ISDIR(BG(sb).st_mode)); - case 14: /*is link*/ -#if HAVE_SYMLINK - RETURN_LONG(S_ISLNK(BG(lsb).st_mode)); -#else - RETURN_FALSE; -#endif - case 15: /*file exists*/ - RETURN_TRUE; /* the false case was done earlier */ - case 16: /* lstat */ -#if HAVE_SYMLINK - stat_sb = &BG(lsb); -#endif - /* FALLTHROUGH */ - case 17: /* stat */ - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - add_next_index_long(return_value, stat_sb->st_dev); - add_next_index_long(return_value, stat_sb->st_ino); - add_next_index_long(return_value, stat_sb->st_mode); - add_next_index_long(return_value, stat_sb->st_nlink); - add_next_index_long(return_value, stat_sb->st_uid); - add_next_index_long(return_value, stat_sb->st_gid); -#ifdef HAVE_ST_BLKSIZE - add_next_index_long(return_value, stat_sb->st_rdev); -#else - add_next_index_long(return_value, -1); -#endif - add_next_index_long(return_value, stat_sb->st_size); - add_next_index_long(return_value, stat_sb->st_atime); - add_next_index_long(return_value, stat_sb->st_mtime); - add_next_index_long(return_value, stat_sb->st_ctime); -#ifdef HAVE_ST_BLKSIZE - add_next_index_long(return_value, stat_sb->st_blksize); -#else - add_next_index_long(return_value, -1); -#endif -#ifdef HAVE_ST_BLOCKS - add_next_index_long(return_value, stat_sb->st_blocks); -#else - add_next_index_long(return_value, -1); -#endif - return; - } - php_error(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); \ - if ((*filename)->value.str.len) \ - php_stat((*filename)->value.str.val, funcnum, return_value); \ -} - -/* {{{ proto int fileperms(string filename) - Get file permissions */ -FileFunction(PHP_FN(fileperms),0) -/* }}} */ - -/* {{{ proto int fileinode(string filename) - Get file inode */ -FileFunction(PHP_FN(fileinode),1) -/* }}} */ - -/* {{{ proto int filesize(string filename) - Get file size */ -FileFunction(PHP_FN(filesize), 2) -/* }}} */ - -/* {{{ proto int fileowner(string filename) - Get file owner */ -FileFunction(PHP_FN(fileowner),3) -/* }}} */ - -/* {{{ proto nt filegroup(string filename) - Get file group */ -FileFunction(PHP_FN(filegroup),4) -/* }}} */ - -/* {{{ proto int fileatime(string filename) - Get last access time of file */ -FileFunction(PHP_FN(fileatime),5) -/* }}} */ - -/* {{{ proto int filemtime(string filename) - Get last modification time of file */ -FileFunction(PHP_FN(filemtime),6) -/* }}} */ - -/* {{{ proto int filectime(string filename) - Get inode modification time of file */ -FileFunction(PHP_FN(filectime),7) -/* }}} */ - -/* {{{ proto string filetype(string filename) - Get file type */ -FileFunction(PHP_FN(filetype), 8) -/* }}} */ - -/* {{{ proto int is_writable(string filename) - Returns true if file can be written */ -FileFunction(PHP_FN(is_writable), 9) -/* }}} */ - -/* {{{ proto int is_readable(string filename) - Returns true if file can be read */ -FileFunction(PHP_FN(is_readable),10) -/* }}} */ - -/* {{{ proto int is_executable(string filename) - Returns true if file is executable */ -FileFunction(PHP_FN(is_executable),11) -/* }}} */ - -/* {{{ proto int is_file(string filename) - Returns true if file is a regular file */ -FileFunction(PHP_FN(is_file),12) -/* }}} */ - -/* {{{ proto int is_dir(string filename) - Returns true if file is directory */ -FileFunction(PHP_FN(is_dir),13) -/* }}} */ - -/* {{{ proto int is_link(string filename) - Returns true if file is symbolic link */ -FileFunction(PHP_FN(is_link),14) -/* }}} */ - -/* {{{ proto bool file_exists(string filename) - Returns true if filename exists */ -FileFunction(PHP_FN(file_exists),15) -/* }}} */ - -/* {{{ proto array lstat(string filename) - Give information about a file or symbolic link */ -FileFunction(PHP_FN(lstat),16) -/* }}} */ - -/* {{{ proto array stat(string filename) - Give information about a file */ -FileFunction(PHP_FN(stat),17) -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c deleted file mode 100644 index 8447b07fb0..0000000000 --- a/ext/standard/flock_compat.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Sascha Schumann <sas@schell.de> | - +----------------------------------------------------------------------+ - - $Id$ - */ - - -#include <php.h> -#include <errno.h> -#include "ext/standard/flock_compat.h" - -#if HAVE_STRUCT_FLOCK -#include <unistd.h> -#include <fcntl.h> -#endif - -#ifdef PHP_WIN32 -#include <windows.h> -#include <io.h> -#endif - -#ifndef HAVE_FLOCK -int 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 -#endif /* !defined(HAVE_FLOCK) */ - -#if !(HAVE_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 */ diff --git a/ext/standard/flock_compat.h b/ext/standard/flock_compat.h deleted file mode 100644 index a94be11091..0000000000 --- a/ext/standard/flock_compat.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _FLOCK_COMPAT_H -#define _FLOCK_COMPAT_H - -#ifndef HAVE_FLOCK -# define LOCK_SH 1 -# define LOCK_EX 2 -# define LOCK_NB 4 -# define LOCK_UN 8 -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 3b38248889..0000000000 --- a/ext/standard/formatted_print.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 Sæther Bakken <ssb@guardian.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> - -#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) < 1) { - 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) -{ - if ((*pos + 1) >= *size) { - *size <<= 1; - PRINTF_DEBUG(("%s: ereallocing buffer to %d bytes\n", get_active_function_name(), *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) -{ - register int npad = min_width - MIN(len,(max_width?max_width: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)); - if (max_width == 0) { - max_width = MAX(min_width,len); - } - if ((*pos + max_width) >= *size) { - while ((*pos + max_width) >= *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)); - strncpy(&(*buffer)[*pos], add, max_width); - *pos += MIN(max_width,len); - if (alignment == ALIGN_LEFT) { - while (npad--) { - (*buffer)[(*pos)++] = padding; - } - } -} - - -inline static void -php_sprintf_appendint(char **buffer, int *pos, int *size, int number, - int width, char padding, int alignment) -{ - char numbuf[NUM_BUF_SIZE]; - register unsigned int magn, nmagn, 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 int) -(number + 1)) + 1; - } else { - 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] = (magn - (nmagn * 10)) + '0'; - magn = nmagn; - } - while (magn > 0 && i > 0); - if (neg) { - 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); -} - - -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) -{ - char numbuf[NUM_BUF_SIZE]; - char *cvt; - register int i = 0, j = 0; - int sign, decpt; - - 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; - } - cvt = php_convert_to_decimal(number, precision, &decpt, &sign, (fmt == 'e')); - - if (sign) { - numbuf[i++] = '-'; - } - - if (fmt == 'f') { - if (decpt <= 0) { - numbuf[i++] = '0'; - if (precision > 0) { - int k = precision; - numbuf[i++] = '.'; - while ((decpt++ < 0) && k--) { - numbuf[i++] = '0'; - } - } - } else { - while (decpt-- > 0) - numbuf[i++] = cvt[j++]; - if (precision > 0) - numbuf[i++] = '.'; - } - } else { - numbuf[i++] = cvt[j++]; - if (precision > 0) - numbuf[i++] = '.'; - } - - 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); -} - - -inline static void -php_sprintf_append2n(char **buffer, int *pos, int *size, int number, - int width, char padding, int alignment, int n, - char *chartable) -{ - char numbuf[NUM_BUF_SIZE]; - register unsigned int num, i = NUM_BUF_SIZE - 1, neg = 0; - 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)); - - if (number < 0) { - neg = 1; - num = ((unsigned int) -(number + 1)) + 1; - } else { - num = (unsigned int) number; - } - - numbuf[i] = '\0'; - - do { - numbuf[--i] = chartable[(num & andbits)]; - num >>= n; - } - while (num > 0); - - if (neg) { - numbuf[--i] = '-'; - } - php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0, - padding, alignment, (NUM_BUF_SIZE - 1) - i, neg); -} - - -inline static int -php_sprintf_getnumber(char *buffer, int *pos) -{ - char *endptr; - register int 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; -} - - -/* - * New sprintf implementation for PHP. - * - * Modifiers: - * - * " " pad integers with spaces - * "-" left adjusted field - * n field size - * "."n precision (floats only) - * - * 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) -{ - pval ***args; - int argc, size = 240, inpos = 0, outpos = 0; - int alignment, width, precision, currarg, adjusting; - char *format, *result, padding; - - argc = ZEND_NUM_ARGS(); - - if (argc < 1) { - WRONG_PARAM_COUNT_WITH_RETVAL(NULL); - } - args = (pval ***)emalloc(argc * sizeof(pval *)); - - if (zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT_WITH_RETVAL(NULL); - } - convert_to_string_ex(args[0]); - format = (*args[0])->value.str.val; - result = emalloc(size); - - currarg = 1; - - while (format[inpos]) { - 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++]); - } else if (format[inpos + 1] == '%') { - php_sprintf_appendchar(&result, &outpos, &size, '%'); - inpos += 2; - } else { - if (currarg >= argc && format[inpos + 1] != '%') { - efree(result); - efree(args); - php_error(E_WARNING, "%s(): too few arguments",get_active_function_name()); - return NULL; - } - /* starting a new format specifier, reset variables */ - alignment = ALIGN_RIGHT; - adjusting = 0; - padding = ' '; - 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 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] == '\'') { - 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 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; - } else { - precision = 0; - } - } else { - precision = 0; - } - PRINTF_DEBUG(("sprintf: precision=%d\n", precision)); - } else { - width = precision = 0; - } - - 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[currarg]); - php_sprintf_appendstring(&result, &outpos, &size, - (*args[currarg])->value.str.val, - width, precision, padding, - alignment, - (*args[currarg])->value.str.len,0); - break; - - case 'd': - convert_to_long_ex(args[currarg]); - php_sprintf_appendint(&result, &outpos, &size, - (*args[currarg])->value.lval, - width, padding, alignment); - break; - - case 'e': - case 'f': - /* XXX not done */ - convert_to_double_ex(args[currarg]); - php_sprintf_appenddouble(&result, &outpos, &size, - (*args[currarg])->value.dval, - width, padding, alignment, - precision, adjusting, - format[inpos]); - break; - - case 'c': - convert_to_long_ex(args[currarg]); - php_sprintf_appendchar(&result, &outpos, &size, - (char) (*args[currarg])->value.lval); - break; - - case 'o': - convert_to_long_ex(args[currarg]); - php_sprintf_append2n(&result, &outpos, &size, - (*args[currarg])->value.lval, - width, padding, alignment, 3, - hexchars); - break; - - case 'x': - convert_to_long_ex(args[currarg]); - php_sprintf_append2n(&result, &outpos, &size, - (*args[currarg])->value.lval, - width, padding, alignment, 4, - hexchars); - break; - - case 'X': - convert_to_long_ex(args[currarg]); - php_sprintf_append2n(&result, &outpos, &size, - (*args[currarg])->value.lval, - width, padding, alignment, 4, - HEXCHARS); - break; - - case 'b': - convert_to_long_ex(args[currarg]); - php_sprintf_append2n(&result, &outpos, &size, - (*args[currarg])->value.lval, - width, padding, alignment, 1, - hexchars); - break; - - case '%': - php_sprintf_appendchar(&result, &outpos, &size, '%'); - - break; - default: - break; - } - currarg++; - 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 [, ...]]) - Return a formatted string */ -PHP_FUNCTION(user_sprintf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht,&len))==NULL) { - RETURN_FALSE; - } - RETVAL_STRINGL(result,len,1); - efree(result); -} -/* }}} */ - -/* {{{ proto int printf(string format [, mixed arg1 [, ...]]) - Output a formatted string */ -PHP_FUNCTION(user_printf) -{ - char *result; - int len; - - if ((result=php_formatted_print(ht,&len))==NULL) { - RETURN_FALSE; - } - PHPWRITE(result,len); - efree(result); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c deleted file mode 100644 index 49da899934..0000000000 --- a/ext/standard/fsock.c +++ /dev/null @@ -1,774 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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$ */ - -/* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */ -/* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */ - -#include "php.h" -#include "php_globals.h" -#include <stdlib.h> -#include <stddef.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif - -#ifdef HAVE_FCNTL_H -# include <fcntl.h> -#endif - -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif - -#include <sys/types.h> -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#ifdef PHP_WIN32 -#include <winsock.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#endif -#ifdef PHP_WIN32 -#undef AF_UNIX -#endif -#if defined(AF_UNIX) -#include <sys/un.h> -#endif -#ifdef HAVE_SYS_SELECT_H -#include <sys/select.h> -#endif - -#include <string.h> -#include <errno.h> - -#include "base64.h" -#include "file.h" -#include "url.h" -#include "fsock.h" - -#ifdef ZTS -static int fsock_globals_id; -#else -static php_fsock_globals fsock_globals; -extern int le_fp; -#endif - -#define CLOSE_SOCK(free_sock) \ - if(socketd >= 0) { \ - close(socketd); \ - } \ - if (free_sock) { \ - efree(sock); \ - } \ - if (key) { \ - efree(key); \ - } - -#define SEARCHCR() \ - p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen)); - -#ifdef PHP_WIN32 -#define EWOULDBLOCK WSAEWOULDBLOCK -#else -#include "build-defs.h" -#endif - -/* {{{ lookup_hostname */ - -/* - * Converts a host name to an IP address. - */ -int lookup_hostname(const char *addr, struct in_addr *in) -{ - struct hostent *host_info; - - if (!inet_aton(addr, in)) { - /* XXX NOT THREAD SAFE */ - host_info = gethostbyname(addr); - if (host_info == 0) { - /* Error: unknown host */ - return -1; - } - *in = *((struct in_addr *) host_info->h_addr); - } - return 0; -} -/* }}} */ -/* {{{ php_is_persistent_sock */ - -int php_is_persistent_sock(int sock) -{ - char *key; - FLS_FETCH(); - - if (zend_hash_find(&FG(ht_fsock_socks), (char *) &sock, sizeof(sock), - (void **) &key) == SUCCESS) { - return 1; - } - return 0; -} -/* }}} */ -/* {{{ connect_nonb */ -PHPAPI int connect_nonb(int sockfd, - struct sockaddr *addr, - socklen_t addrlen, - struct timeval *timeout) -{ -/* probably won't work on Win32, someone else might try it (read: fix it ;) */ -#if !defined(PHP_WIN32) && (defined(O_NONBLOCK) || defined(O_NDELAY)) - -#ifndef O_NONBLOCK -#define O_NONBLOCK O_NDELAY -#endif - - int flags; - int n; - int error = 0; - socklen_t len; - int ret = 0; - fd_set rset; - fd_set wset; - - flags = fcntl(sockfd, F_GETFL, 0); - fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); - - if ((n = connect(sockfd, addr, addrlen)) < 0) { - if (errno != EINPROGRESS) { - return -1; - } - } - - if (n == 0) { - goto ok; - } - - FD_ZERO(&rset); - FD_SET(sockfd, &rset); - - wset = rset; - - if ((n = select(sockfd + 1, &rset, &wset, NULL, timeout)) == 0) { - error = ETIMEDOUT; - } - - if(FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) { - len = sizeof(error); - /* - BSD-derived systems set errno correctly - Solaris returns -1 from getsockopt in case of error - */ - if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { - ret = -1; - } - } else { - /* whoops: sockfd has disappeared */ - ret = -1; - } - - ok: - fcntl(sockfd, F_SETFL, flags); - - if(error) { - errno = error; - ret = -1; - } - return ret; -#else /* !defined(PHP_WIN32) && ... */ - return connect(sockfd, addr, addrlen); -#endif -} -/* }}} */ -/* {{{ php_fsockopen() */ - -/* - This function takes an optional third argument which should be - passed by reference. The error code from the connect call is written - to this variable. -*/ -static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - pval **args[5]; - int *sock=emalloc(sizeof(int)); - int *sockp; - int arg_count=ZEND_NUM_ARGS(); - int socketd = -1; - unsigned char udp = 0; - struct timeval timeout = { 60, 0 }; - unsigned short portno; - unsigned long conv; - char *key = NULL; - FLS_FETCH(); - - if (arg_count > 5 || arg_count < 2 || zend_get_parameters_array_ex(arg_count,args)==FAILURE) { - CLOSE_SOCK(1); - WRONG_PARAM_COUNT; - } - switch(arg_count) { - case 5: - convert_to_double_ex(args[4]); - conv = (unsigned long) ((*args[4])->value.dval * 1000000.0); - timeout.tv_sec = conv / 1000000; - timeout.tv_usec = conv % 1000000; - /* fall-through */ - case 4: - if(!ParameterPassedByReference(ht,4)) { - php_error(E_WARNING,"error string argument to fsockopen not passed by reference"); - } - pval_copy_constructor(*args[3]); - (*args[3])->value.str.val = empty_string; - (*args[3])->value.str.len = 0; - (*args[3])->type = IS_STRING; - /* fall-through */ - case 3: - if(!ParameterPassedByReference(ht,3)) { - php_error(E_WARNING,"error argument to fsockopen not passed by reference"); - } - (*args[2])->type = IS_LONG; - (*args[2])->value.lval = 0; - break; - } - convert_to_string_ex(args[0]); - convert_to_long_ex(args[1]); - portno = (unsigned short) (*args[1])->value.lval; - - key = emalloc((*args[0])->value.str.len + 10); - sprintf(key, "%s:%d", (*args[0])->value.str.val, portno); - - if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1, - (void *) &sockp) == SUCCESS) { - CLOSE_SOCK(0); - *sock = *sockp; - ZEND_REGISTER_RESOURCE(return_value,sock,php_file_le_socket()); - return; - } - - if (portno) { - struct sockaddr_in server; - - memset(&server, 0, sizeof(server)); - if((*args[0])->value.str.val[0] == 'u' && - (*args[0])->value.str.val[1] == 'd' && - (*args[0])->value.str.val[2] == 'p' && - (*args[0])->value.str.val[3] == ':' && - (*args[0])->value.str.val[4] == '/' && - (*args[0])->value.str.val[5] == '/') { - udp = 1; - } - - socketd = socket(AF_INET,udp ? SOCK_DGRAM : SOCK_STREAM,0); - - if (socketd == SOCK_ERR) { - CLOSE_SOCK(1); - RETURN_FALSE; - } - - server.sin_family = AF_INET; - - if(lookup_hostname(udp ? &(*args[0])->value.str.val[6] : (*args[0])->value.str.val,&server.sin_addr)) { - CLOSE_SOCK(1); - RETURN_FALSE; - } - - server.sin_port = htons(portno); - - if (connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) { - CLOSE_SOCK(1); - if(arg_count>2) (*args[2])->value.lval = errno; - if(arg_count>3) { - (*args[3])->value.str.val = estrdup(strerror(errno)); - (*args[3])->value.str.len = strlen((*args[3])->value.str.val); - } - RETURN_FALSE; - } -#if defined(AF_UNIX) - } else { - /* Unix domain socket. s->strval is socket name. */ - struct sockaddr_un unix_addr; - socketd = socket(AF_UNIX,SOCK_STREAM,0); - if (socketd == SOCK_ERR) { - CLOSE_SOCK(1); - RETURN_FALSE; - } - - memset(&unix_addr,(char)0,sizeof(unix_addr)); - unix_addr.sun_family = AF_UNIX; - strcpy(unix_addr.sun_path, (*args[0])->value.str.val); - - if (connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) { - CLOSE_SOCK(1); - if(arg_count>2) (*args[2])->value.lval = errno; - if(arg_count>3) { - (*args[3])->value.str.val = estrdup(strerror(errno)); - (*args[3])->value.str.len = strlen((*args[3])->value.str.val); - } - RETURN_FALSE; - } -#endif /* AF_UNIX */ - } - -#if 0 - if ((fp = fdopen (socketd, "r+")) == NULL){ - RETURN_LONG(-6); /* FIXME */ - } - -#ifdef HAVE_SETVBUF - if ((setvbuf(fp, NULL, _IONBF, 0)) != 0){ - RETURN_LONG(-7); /* FIXME */ - } -#endif -#endif - - *sock=socketd; - if (persistent) { - zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1, - sock, sizeof(*sock), NULL); - zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock), - key, strlen(key) + 1, NULL); - } - if(key) efree(key); - - ZEND_REGISTER_RESOURCE(return_value,sock,php_file_le_socket()); -} -/* }}} */ - -/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]]) - Open Internet or Unix domain socket connection */ -PHP_FUNCTION(fsockopen) -{ - php_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ -/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]]) - Open persistent Internet or Unix domain socket connection */ -PHP_FUNCTION(pfsockopen) -{ - php_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -#define CHUNK_SIZE 8192 -#define SOCK_DESTROY(sock) \ - if(sock->readbuf) pefree(sock->readbuf, sock->persistent); \ - if(sock->prev) sock->prev->next = sock->next; \ - if(sock->next) sock->next->prev = sock->prev; \ - if(sock == FG(phpsockbuf)) \ - FG(phpsockbuf) = sock->next; \ - pefree(sock, sock->persistent) - -static void php_cleanup_sockbuf(int persistent FLS_DC) -{ - php_sockbuf *now, *next; - - for(now = FG(phpsockbuf); now; now = next) { - next = now->next; - if(now->persistent == persistent) { - SOCK_DESTROY(now); - } - } -} - -#define TOREAD(sock) ((sock)->writepos - (sock)->readpos) -#define READPTR(sock) ((sock)->readbuf + (sock)->readpos) -#define WRITEPTR(sock) ((sock)->readbuf + (sock)->writepos) -#define SOCK_FIND(sock,socket) \ - php_sockbuf *sock; \ - FLS_FETCH(); \ - sock = php_sockfind(socket FLS_CC); \ - if(!sock) sock = php_sockcreate(socket FLS_CC) - -static php_sockbuf *php_sockfind(int socket FLS_DC) -{ - php_sockbuf *buf = NULL, *tmp; - - for(tmp = FG(phpsockbuf); tmp; tmp = tmp->next) - if(tmp->socket == socket) { - buf = tmp; - break; - } - - return buf; -} - -static php_sockbuf *php_sockcreate(int socket FLS_DC) -{ - php_sockbuf *sock; - int persistent = php_is_persistent_sock(socket); - - sock = pecalloc(sizeof(*sock), 1, persistent); - sock->socket = socket; - if((sock->next = FG(phpsockbuf))) - FG(phpsockbuf)->prev = sock; - sock->persistent = persistent; - sock->is_blocked = 1; - sock->chunk_size = FG(def_chunk_size); - sock->timeout.tv_sec = -1; - FG(phpsockbuf) = sock; - - return sock; -} - -PHPAPI php_sockbuf *php_get_socket(int socket) -{ - SOCK_FIND(sock, socket); - return sock; -} - -size_t php_sock_set_def_chunk_size(size_t size) -{ - size_t old; - FLS_FETCH(); - - old = FG(def_chunk_size); - - if(size <= CHUNK_SIZE || size > 0) - FG(def_chunk_size) = size; - - return old; -} - -int php_sockdestroy(int socket) -{ - int ret = 0; - php_sockbuf *sock; - FLS_FETCH(); - - sock = php_sockfind(socket FLS_CC); - if(sock) { - ret = 1; - SOCK_DESTROY(sock); - } - - return ret; -} - -#if !defined(PHP_WIN32) -#undef closesocket -#define closesocket close -#endif - -#ifndef HAVE_SHUTDOWN -#undef shutdown -#define shutdown -#endif - -#define SOCK_CLOSE(s) shutdown(s, 0); closesocket(s) - -int php_sock_close(int socket) -{ - int ret = 0; - php_sockbuf *sock; - FLS_FETCH(); - - sock = php_sockfind(socket FLS_CC); - if(sock) { - if(!sock->persistent) { - SOCK_CLOSE(sock->socket); - SOCK_DESTROY(sock); - } - } else { - SOCK_CLOSE(socket); - } - - return ret; -} - -#define MAX_CHUNKS_PER_READ 10 - -static void php_sockwait_for_data(php_sockbuf *sock) -{ - fd_set fdr, tfdr; - int retval; - struct timeval timeout, *ptimeout; - - FD_ZERO(&fdr); - FD_SET(sock->socket, &fdr); - sock->timeout_event = 0; - - if (sock->timeout.tv_sec == -1) - ptimeout = NULL; - else - ptimeout = &timeout; - - while(1) { - tfdr = fdr; - timeout = sock->timeout; - - retval = select(sock->socket + 1, &tfdr, NULL, NULL, ptimeout); - - if (retval == 0) - sock->timeout_event = 1; - - if (retval >= 0) - break; - } -} - -static size_t php_sockread_internal(php_sockbuf *sock) -{ - char buf[CHUNK_SIZE]; - int nr_bytes; - size_t nr_read = 0; - - /* For blocking sockets, we wait until there is some - data to read (real data or EOF) - - Otherwise, recv() may time out and return 0 and - therefore sock->eof would be set errornously. - */ - - - if(sock->is_blocked) { - php_sockwait_for_data(sock); - if (sock->timeout_event) - return 0; - } - - /* read at a maximum sock->chunk_size */ - nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0); - if(nr_bytes > 0) { - if(sock->writepos + nr_bytes > sock->readbuflen) { - sock->readbuflen += sock->chunk_size; - sock->readbuf = perealloc(sock->readbuf, sock->readbuflen, - sock->persistent); - } - memcpy(WRITEPTR(sock), buf, nr_bytes); - sock->writepos += nr_bytes; - nr_read = nr_bytes; - } else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) { - sock->eof = 1; - } - - return nr_read; -} - -static void php_sockread_total(php_sockbuf *sock, size_t maxread) -{ - while(!sock->eof && TOREAD(sock) < maxread && !sock->timeout_event) { - php_sockread_internal(sock); - } -} - -static size_t php_sockread(php_sockbuf *sock) -{ - size_t nr_bytes; - size_t nr_read = 0; - int i; - - for(i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) { - nr_bytes = php_sockread_internal(sock); - if(nr_bytes == 0) break; - nr_read += nr_bytes; - } - - return nr_read; -} - -int php_sockset_blocking(int socket, int mode) -{ - int old; - SOCK_FIND(sock, socket); - - old = sock->is_blocked; - - sock->is_blocked = mode; - - return old; -} - -void php_sockset_timeout(int socket, struct timeval *timeout) -{ - SOCK_FIND(sock, socket); - - sock->timeout = *timeout; -} - -#define SOCK_FIND_AND_READ_MAX(max) \ - SOCK_FIND(sock, socket); \ - if(sock->is_blocked) php_sockread_total(sock, max); else php_sockread(sock) - -/* {{{ php_sock_fgets() */ -/* - * FIXME: fgets depends on '\n' as line delimiter - */ -char *php_sock_fgets(char *buf, size_t maxlen, int socket) -{ - char *p = NULL; - char *ret = NULL; - size_t amount = 0; - SOCK_FIND(sock, socket); - - if (maxlen==0) { - buf[0] = 0; - return buf; - } - - SEARCHCR(); - - if(!p) { - if(sock->is_blocked) { - while(!p && !sock->eof && !sock->timeout_event && TOREAD(sock) < maxlen) { - php_sockread_internal(sock); - SEARCHCR(); - } - } else { - php_sockread(sock); - SEARCHCR(); - } - } - - - if(p) { - amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1; - } else { - amount = TOREAD(sock); - } - - amount = MIN(amount, maxlen); - - if(amount > 0) { - memcpy(buf, READPTR(sock), amount); - sock->readpos += amount; - } - buf[amount] = '\0'; - - /* signal error only, if we don't return data from this call and - if there is no data to read and if the eof flag is set */ - if(amount || TOREAD(sock) || !sock->eof) - ret = buf; - - return ret; -} - -/* }}} */ - -/* - * FIXME: fgetc returns EOF, if no data is available on a nonblocking socket. - * I don't have any documentation on the semantics of fgetc in this case. - * - * ss@2ns.de 19990528 - */ - -int php_sock_fgetc(int socket) -{ - int ret = EOF; - SOCK_FIND_AND_READ_MAX(1); - - if(TOREAD(sock) > 0) { - ret = *READPTR(sock); - sock->readpos++; - } - - return ret; -} - -int php_sock_feof(int socket) -{ - int ret = 0; - SOCK_FIND(sock, socket); - - if(!sock->is_blocked) - php_sockread(sock); - - if(!TOREAD(sock) && sock->eof) - ret = 1; - - return ret; -} - -/* {{{ php_sock_fread() */ - -size_t php_sock_fread(char *ptr, size_t size, int socket) -{ - size_t ret = 0; - SOCK_FIND_AND_READ_MAX(size); - - if(size < 0) - return ret; - - ret = MIN(TOREAD(sock), size); - if(ret) { - memcpy(ptr, READPTR(sock), ret); - sock->readpos += ret; - } - - return ret; -} - -/* }}} */ -/* {{{ module start/shutdown functions */ - - /* {{{ php_msock_destroy */ -void php_msock_destroy(int *data) -{ - close(*data); -} -/* }}} */ - -static void fsock_globals_ctor(FLS_D) -{ - zend_hash_init(&FG(ht_fsock_keys), 0, NULL, NULL, 1); - zend_hash_init(&FG(ht_fsock_socks), 0, NULL, (void (*)(void *))php_msock_destroy, 1); - FG(def_chunk_size) = CHUNK_SIZE; - FG(phpsockbuf) = NULL; -} - -static void fsock_globals_dtor(FLS_D) -{ - zend_hash_destroy(&FG(ht_fsock_socks)); - zend_hash_destroy(&FG(ht_fsock_keys)); - php_cleanup_sockbuf(1 FLS_CC); -} - -PHP_MINIT_FUNCTION(fsock) -{ -#ifdef ZTS - fsock_globals_id = ts_allocate_id(sizeof(php_fsock_globals), (ts_allocate_ctor) fsock_globals_ctor, (ts_allocate_dtor) fsock_globals_dtor); -#else - fsock_globals_ctor(FLS_C); -#endif - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(fsock) -{ -#ifndef ZTS - fsock_globals_dtor(FLS_C); -#endif - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(fsock) -{ - FLS_FETCH(); - - php_cleanup_sockbuf(0 FLS_CC); - return SUCCESS; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h deleted file mode 100644 index 0be635232a..0000000000 --- a/ext/standard/fsock.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - | Jim Winstead (jimw@php.net) | - +----------------------------------------------------------------------+ -*/ -/* $Id$ */ - -/* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */ - -#ifndef _FSOCK_H -#define _FSOCK_H - -#ifdef PHP_WIN32 -# ifndef WINNT -# define WINNT 1 -# endif -# undef FD_SETSIZE -# include "arpa/inet.h" -# define socklen_t unsigned int -#endif - -#ifdef HAVE_NETINET_IN_H -# include <netinet/in.h> -#endif - -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif - -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif - -struct php_sockbuf { - int socket; - unsigned char *readbuf; - size_t readbuflen; - size_t readpos; - size_t writepos; - struct php_sockbuf *next; - struct php_sockbuf *prev; - char eof; - char persistent; - char is_blocked; - size_t chunk_size; - struct timeval timeout; - char timeout_event; -}; - -typedef struct php_sockbuf php_sockbuf; - -PHP_FUNCTION(fsockopen); -PHP_FUNCTION(pfsockopen); - -int lookup_hostname(const char *addr, struct in_addr *in); -char *php_sock_fgets(char *buf, size_t maxlen, int socket); -size_t php_sock_fread(char *buf, size_t maxlen, int socket); -int php_sock_feof(int socket); -int php_sock_fgetc(int socket); -int php_is_persistent_sock(int); -int php_sockset_blocking(int socket, int mode); -void php_sockset_timeout(int socket, struct timeval *timeout); -int php_sockdestroy(int socket); -int php_sock_close(int socket); -size_t php_sock_set_def_chunk_size(size_t size); -void php_msock_destroy(int *data); - -PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout); -PHPAPI struct php_sockbuf *php_get_socket(int socket); - -PHP_MINIT_FUNCTION(fsock); -PHP_MSHUTDOWN_FUNCTION(fsock); -PHP_RSHUTDOWN_FUNCTION(fsock); - -typedef struct { - HashTable ht_fsock_keys; - HashTable ht_fsock_socks; - struct php_sockbuf *phpsockbuf; - size_t def_chunk_size; -} php_fsock_globals; - -#ifdef ZTS -#define FLS_D php_fsock_globals *fsock_globals -#define FLS_DC , FLS_D -#define FLS_C fsock_globals -#define FLS_CC , FLS_C -#define FG(v) (fsock_globals->v) -#define FLS_FETCH() php_fsock_globals *fsock_globals = ts_resource(fsock_globals_id) -#else -#define FLS_D void -#define FLS_DC -#define FLS_C -#define FLS_CC -#define FG(v) (fsock_globals.v) -#define FLS_FETCH() -#endif - -#endif /* _FSOCK_H */ diff --git a/ext/standard/head.c b/ext/standard/head.c deleted file mode 100644 index 72c457a219..0000000000 --- a/ext/standard/head.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#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" - - -/* need to figure out some nice way to get rid of these */ -#ifndef THREAD_SAFE -static int php_header_printed = 0; -static int php_print_header = 1; -static CookieList *top = NULL; -static char *cont_type = NULL; -static int header_called = 0; -#endif - -void php_push_cookie_list(char *, char *, time_t, char *, char *, int); -CookieList *php_pop_cookie_list(void); - -PHP_RINIT_FUNCTION(head) -{ - php_header_printed = 0; - if (header_called == 0) - php_print_header = 1; - top = NULL; - cont_type = NULL; - - return SUCCESS; -} - - -/* Implementation of the language Header() function */ -/* {{{ proto void header(string header) - Send a raw HTTP header */ -PHP_FUNCTION(Header) -{ - pval **arg1; - - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - sapi_add_header(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1), 1); -} -/* }}} */ - -PHPAPI int php_header() -{ - SLS_FETCH(); - - if (sapi_send_headers()==FAILURE || SG(request_info).headers_only) { - return 0; /* don't allow output */ - } else { - return 1; /* allow output */ - } -} - - -void php_push_cookie_list(char *name, char *value, time_t expires, char *path, char *domain, int secure) -{ - CookieList *new; - - new = emalloc(sizeof(CookieList)); - new->next = top; - new->name = name; - new->value = value; - new->expires = expires; - new->path = path; - new->domain = domain; - new->secure = secure; - top = new; -} - -CookieList *php_pop_cookie_list(void) -{ - CookieList *ret; - - ret = top; - if (top) - top = top->next; - return (ret); -} - -/* php_set_cookie(name,value,expires,path,domain,secure) */ -/* {{{ proto void setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]]) - Send a cookie */ -PHP_FUNCTION(setcookie) -{ - char *cookie, *encoded_value = NULL; - int len=sizeof("Set-Cookie: "); - time_t t; - char *dt; - char *name = NULL, *value = NULL, *path = NULL, *domain = NULL; - time_t expires = 0; - int secure = 0; - pval **arg[6]; - int arg_count; - - arg_count = ZEND_NUM_ARGS(); - if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (php_header_printed == 1) { - php_error(E_WARNING, "Oops, php_set_cookie called after header has been sent\n"); - return; - } - switch (arg_count) { - case 6: - convert_to_boolean_ex(arg[5]); - secure = (*arg[5])->value.lval; - /* break missing intentionally */ - case 5: - convert_to_string_ex(arg[4]); - domain = estrndup((*arg[4])->value.str.val,(*arg[4])->value.str.len); - /* break missing intentionally */ - case 4: - convert_to_string_ex(arg[3]); - path = estrndup((*arg[3])->value.str.val,(*arg[3])->value.str.len); - /* break missing intentionally */ - case 3: - convert_to_long_ex(arg[2]); - expires = (*arg[2])->value.lval; - /* break missing intentionally */ - case 2: - convert_to_string_ex(arg[1]); - value = estrndup((*arg[1])->value.str.val,(*arg[1])->value.str.len); - /* break missing intentionally */ - case 1: - convert_to_string_ex(arg[0]); - name = estrndup((*arg[0])->value.str.val,(*arg[0])->value.str.len); - break; - } -#if 0 - php_push_cookie_list(name, value, expires, path, domain, secure); -#else - if (name) { - len += strlen(name); - } - if (value) { - encoded_value = php_url_encode(value, strlen (value)); - len += strlen(encoded_value); - } - if (path) { - len += strlen(path); - } - if (domain) { - len += strlen(domain); - } - cookie = emalloc(len + 100); - if (!value || (value && !*value)) { - /* - * 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 - */ - sprintf(cookie, "Set-Cookie: %s=deleted", name); - strcat(cookie, "; expires="); - t = time(NULL) - 31536001; - dt = php_std_date(t); - strcat(cookie, dt); - efree(dt); - } else { - /* FIXME: XXX: this is not binary data safe */ - sprintf(cookie, "Set-Cookie: %s=%s", name, value ? encoded_value : ""); - if (value) efree(value); - value=NULL; - if (name) efree(name); - name=NULL; - if (expires > 0) { - strcat(cookie, "; expires="); - dt = php_std_date(expires); - strcat(cookie, dt); - efree(dt); - } - } - - if (encoded_value) efree(encoded_value); - - if (path && strlen(path)) { - strcat(cookie, "; path="); - strcat(cookie, path); - efree(path); - path=NULL; - } - if (domain && strlen(domain)) { - strcat(cookie, "; domain="); - strcat(cookie, domain); - efree(domain); - domain=NULL; - } - if (secure) { - strcat(cookie, "; secure"); - } - - if (sapi_add_header(cookie, strlen(cookie), 0)==SUCCESS) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } - - if (domain) { - efree(domain); - } - if (path) { - efree(path); - } - if (name) { - efree(name); - } - if (value) { - efree(value); - } -#endif -} -/* }}} */ - -int php_headers_unsent(void) -{ - if (php_header_printed!=1 || !php_print_header) { - return 1; - } else { - return 0; - } -} - -/* {{{ proto int headers_sent(void) - Return true if headers have already been sent, false otherwise */ -PHP_FUNCTION(headers_sent) -{ - SLS_FETCH(); - - if (SG(headers_sent)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/head.h b/ext/standard/head.h deleted file mode 100644 index 6207daa6fe..0000000000 --- a/ext/standard/head.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -#ifndef _HEAD_H -#define _HEAD_H - - -/* - We are still using a PHP2-style Push/Pop list here as opposed - to the PHP built-in list functionality because of the nature - of this particular list. It is just used as a structured - buffer. Doing this with the built-in list code would require - some changes to allow a search for the first item with a - certain type. This type of search would not be optimal. - Private list management makes more sense here -*/ -typedef struct CookieList { - char *name; - char *value; - time_t expires; - char *path; - char *domain; - int secure; - struct CookieList *next; -} CookieList; - -extern PHP_RINIT_FUNCTION(head); -PHP_FUNCTION(Header); -PHP_FUNCTION(setcookie); -PHP_FUNCTION(headers_sent); - -PHPAPI int php_header(void); -int php_headers_unsent(void); - -#endif diff --git a/ext/standard/html.c b/ext/standard/html.c deleted file mode 100644 index 570ba81975..0000000000 --- a/ext/standard/html.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | Jaakko Hyvätti <jaakko.hyvatti@iki.fi> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "reg.h" -#include "html.h" - -/* This must be fixed to handle the input string according to LC_CTYPE. - Defaults to ISO-8859-1 for now. */ - -static char EntTable[][7] = -{ - "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" -}; - -PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all) -{ - int i, maxlen, len; - char *new; - - maxlen = 2 * oldlen; - if (maxlen < 128) - maxlen = 128; - new = emalloc (maxlen); - len = 0; - - i = oldlen; - while (i--) { - if (len + 9 > maxlen) - new = erealloc (new, maxlen += 128); - if (38 == *old) { - memcpy (new + len, "&", 5); - len += 5; - } else if (34 == *old) { - memcpy (new + len, """, 6); - len += 6; - } else if (60 == *old) { - memcpy (new + len, "<", 4); - len += 4; - } else if (62 == *old) { - memcpy (new + len, ">", 4); - len += 4; - } else if (all && 160 <= *old) { - new [len++] = '&'; - strcpy (new + len, EntTable [*old - 160]); - len += strlen (EntTable [*old - 160]); - new [len++] = ';'; - } else { - new [len++] = *old; - } - old++; - } - new [len] = '\0'; - *newlen = len; - - return new; -} - -static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all) -{ - zval **arg; - int len; - char *new; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - new = php_escape_html_entities((*arg)->value.str.val, (*arg)->value.str.len, &len, all); - RETVAL_STRINGL(new,len,0); -} - -#define HTML_SPECIALCHARS 0 -#define HTML_ENTITIES 1 - -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); -} - -/* {{{ proto string htmlspecialchars(string string) - Convert special characters to HTML entities */ -PHP_FUNCTION(htmlspecialchars) -{ - php_html_entities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); -} -/* }}} */ - -/* {{{ proto string htmlentities(string string) - 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 whichone]) - Returns the internal translation table used by htmlspecialchars and htmlentities */ -PHP_FUNCTION(get_html_translation_table) -{ - zval **whichone; - int which = 0; - int ac = ZEND_NUM_ARGS(); - int inx; - char ind[ 2 ]; - - if (ac < 0 || ac > 1 || zend_get_parameters_ex(ac, &whichone) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if (ac == 1) { - convert_to_long_ex(whichone); - which = (*whichone)->value.lval; - } - - array_init(return_value); - - ind[1] = 0; - - switch (which) { - case HTML_ENTITIES: - for (inx = 160; inx <= 255; inx++) { - char buffer[16]; - ind[0] = inx; - sprintf(buffer,"&%s;",EntTable[inx-160]); - add_assoc_string(return_value,ind,buffer,1); - } - /* break thru */ - - case HTML_SPECIALCHARS: - ind[0]=38; add_assoc_string(return_value,ind,"&",1); - ind[0]=34; add_assoc_string(return_value,ind,""",1); - ind[0]=60; add_assoc_string(return_value,ind,"<",1); - ind[0]=62; add_assoc_string(return_value,ind,">",1); - break; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/html.h b/ext/standard/html.h deleted file mode 100644 index 082a0e9f08..0000000000 --- a/ext/standard/html.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _HTML_H -#define _HTML_H - -void register_html_constants(INIT_FUNC_ARGS); - -PHP_FUNCTION(htmlspecialchars); -PHP_FUNCTION(htmlentities); -PHP_FUNCTION(get_html_translation_table); - -PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all); - -#endif /* _HTML_H */ diff --git a/ext/standard/image.c b/ext/standard/image.c deleted file mode 100644 index ea11afebc3..0000000000 --- a/ext/standard/image.c +++ /dev/null @@ -1,427 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ -/* - * Based on Daniel Schmitt's imageinfo.c which carried the following - * Copyright notice. - */ - -/* - * imageinfo.c - * - * Simple routines to extract image width/height data from GIF/JPEG files. - * - * Copyright (c) 1997 Daniel Schmitt, opal online publishing, Bonn, Germany. - * - * Includes code snippets from rdjpgcom.c, - * Copyright (c) 1994-1995 Thomas G. Lane - * from release 6a of the Independent JPEG Group's software. - * - * Legal status: see GNU General Public License version 2 or later. - * - */ - -#include "php.h" -#include <stdio.h> -#if HAVE_FCNTL_H -#include <fcntl.h> -#endif -#include "fopen-wrappers.h" -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include "php_image.h" - -/* file type markers */ -const char php_sig_gif[3] = -{'G', 'I', 'F'}; -const char php_sig_jpg[3] = -{(char) 0xff, (char) 0xd8, (char) 0xff}; -const char php_sig_png[8] = -{(char) 0x89, (char) 0x50, (char) 0x4e, - (char) 0x47, (char) 0x0d, (char) 0x0a, - (char) 0x1a, (char) 0x0a}; -const char php_sig_swf[3] = -{'F', 'W', 'S'}; - -/* return info as a struct, to make expansion easier */ - -struct gfxinfo { - unsigned int width; - unsigned int height; - unsigned int bits; - unsigned int channels; -}; - -/* routine to handle GIF files. If only everything were that easy... ;} */ -static struct gfxinfo *php_handle_gif (FILE *fp) -{ - struct gfxinfo *result = NULL; - unsigned char a[2]; - - result = (struct gfxinfo *) ecalloc(1,sizeof(struct gfxinfo)); - fseek(fp, 6L, SEEK_SET); - fread(a,sizeof(a),1,fp); - result->width = (unsigned short)a[0] | (((unsigned short)a[1])<<8); - fread(a,sizeof(a),1,fp); - result->height = (unsigned short)a[0] | (((unsigned short)a[1])<<8); - return result; -} - -static unsigned long php_read4(FILE *fp) -{ - unsigned char a[ 4 ]; - - /* just return 0 if we hit the end-of-file */ - if (fread(a,sizeof(a),1,fp) != 1) return 0; - - return (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]); - -} - -static unsigned long int php_swf_get_bits (unsigned char* buffer, int pos, 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; -} - -static struct gfxinfo *php_handle_swf (FILE* fp) -{ - struct gfxinfo *result = NULL; - unsigned char bits; - unsigned char a[32]; - - result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo)); - fseek(fp, 8, SEEK_SET); - fread(a,sizeof(a),1,fp); - 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; - return result; -} - -/* routine to handle PNG files. - even easier */ -static struct gfxinfo *php_handle_png(FILE *fp) -{ - struct gfxinfo *result = NULL; - unsigned long in_width, in_height; - - result = (struct gfxinfo *) ecalloc(1,sizeof(struct gfxinfo)); - fseek(fp, 16L, SEEK_SET); - in_width = php_read4(fp); - in_height = php_read4(fp); - result->width = (unsigned int) in_width; - result->height = (unsigned int) in_height; - 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 - -static unsigned short php_read2(FILE *fp) -{ - unsigned char a[ 2 ]; - - /* just return 0 if we hit the end-of-file */ - if (fread(a,sizeof(a),1,fp) != 1) return 0; - - return (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]); -} - -static unsigned int php_next_marker(FILE *fp) - /* get next marker byte from file */ -{ - int c; - - /* skip unimportant stuff */ - - c = getc(fp); - - while (c != 0xff) { - if ((c = getc(fp)) == EOF) - return M_EOI; /* we hit EOF */ - } - - /* get marker byte, swallowing possible padding */ - do { - if ((c = getc(fp)) == EOF) - return M_EOI; /* we hit EOF */ - } while (c == 0xff); - - return (unsigned int) c; -} - -static void php_skip_variable(FILE *fp) - /* skip over a variable-length block; assumes proper length marker */ -{ - unsigned short length; - - length = php_read2(fp); - length -= 2; /* length includes itself */ - fseek(fp, (long) length, SEEK_CUR); /* skip the header */ -} - -static void php_read_APP(FILE *fp,unsigned int marker,pval *info) -{ - unsigned short length; - unsigned char *buffer; - unsigned char markername[ 16 ]; - - length = php_read2(fp); - length -= 2; /* length includes itself */ - - buffer = emalloc(length); - - if (fread(buffer,length,1,fp) != 1) { - return; - } - - sprintf(markername,"APP%d",marker - M_APP0); - - add_assoc_stringl(info,markername,buffer,length,1); - - efree(buffer); -} - -static struct gfxinfo *php_handle_jpeg(FILE *fp,pval *info) - /* main loop to parse JPEG structure */ -{ - struct gfxinfo *result = NULL; - unsigned int marker; - - fseek(fp, 0L, SEEK_SET); /* position file pointer on SOF */ - - if (getc(fp) != 0xFF) /* JPEG header... */ - return NULL; - - if (getc(fp) != M_SOI) /* JPEG header... */ - return NULL; - - for (;;) { - marker = php_next_marker(fp); - 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)); - - fseek(fp, 2, SEEK_CUR); - - result->bits = fgetc(fp); - result->height = php_read2(fp); - result->width = php_read2(fp); - result->channels = fgetc(fp); - - if (! info) /* if we don't want an extanded info -> return */ - return result; - } else { - php_skip_variable(fp); - } - 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(fp,marker,info); /* read all the app markes... */ - } else { - php_skip_variable(fp); - } - break; - - case M_SOS: - case M_EOI: - return result; /* we're about to hit image data, or are at EOF. stop processing. */ - break; - - default: - php_skip_variable(fp); /* anything else isn't interesting */ - break; - } - } - - return NULL; -} - -/* main function */ - -/* {{{ proto array getimagesize(string imagefile [, array info]) - Get the size of an image as 4-element array */ -PHP_FUNCTION(getimagesize) -{ - pval **arg1,**info = 0; - FILE *fp; - int itype = 0; - char filetype[3]; - char pngtype[8]; - char temp[64]; - struct gfxinfo *result = NULL; - - switch(ZEND_NUM_ARGS()){ - case 1: - if (zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - break; - - case 2: - if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (!ParameterPassedByReference(ht, 2)) { - php_error(E_WARNING, "Array to be filled with values must be passed by reference."); - RETURN_FALSE; - } - - zval_dtor(*info); - - if (array_init(*info) == FAILURE) { - return; - } - - convert_to_string_ex(arg1); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - /* Check open_basedir */ - if (php_check_open_basedir((*arg1)->value.str.val)) return; - - if ((fp = V_FOPEN((*arg1)->value.str.val,"rb")) == 0) { - php_error(E_WARNING, "Unable to open %s", (*arg1)->value.str.val); - return; - } - fread(filetype,sizeof(filetype),1,fp); - if (!memcmp(filetype, php_sig_gif, 3)) { - result = php_handle_gif (fp); - itype = 1; - } else if (!memcmp(filetype, php_sig_jpg, 3)) { - if (info) { - result = php_handle_jpeg(fp,*info); - } else { - result = php_handle_jpeg(fp,NULL); - } - itype = 2; - } else if (!memcmp(filetype, php_sig_png, 3)) { - fseek(fp, 0L, SEEK_SET); - fread(pngtype, sizeof(pngtype), 1, fp); - if (!memcmp(pngtype, php_sig_png, 8)) { - result = php_handle_png(fp); - itype = 3; - } else { - php_error(E_WARNING, "PNG file corrupted by ASCII conversion"); - } - } else if (!memcmp(filetype, php_sig_swf, 3)) { - result = php_handle_swf(fp); - itype = 4; - } - fclose(fp); - if (result) { - if (array_init(return_value) == FAILURE) { - php_error(E_ERROR, "Unable to initialize array"); - if (result) efree(result); - return; - } - add_index_long(return_value, 0, result->width); - add_index_long(return_value, 1, result->height); - add_index_long(return_value, 2, itype); - sprintf(temp, "width=\"%d\" height=\"%d\"", result->width, result->height); /* safe */ - add_index_string(return_value, 3, temp, 1); - - if (result->bits != 0) { - add_assoc_long(return_value,"bits",result->bits); - } - if (result->channels != 0) { - add_assoc_long(return_value,"channels",result->channels); - } - - efree(result); - } -} -/* }}} */ diff --git a/ext/standard/info.c b/ext/standard/info.c deleted file mode 100644 index c1567e8016..0000000000 --- a/ext/standard/info.c +++ /dev/null @@ -1,646 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_ini.h" -#include "php_globals.h" -#include "ext/standard/head.h" -#include "info.h" -#include "SAPI.h" -#include <time.h> -#if !defined(PHP_WIN32) -#include "build-defs.h" -#endif -#include "zend_globals.h" /* needs ELS */ -#include "zend_highlight.h" - - -#define PHP_CONF_LONG(directive,value1,value2) \ - php_printf("<TR VALIGN=\"baseline\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\"><TD BGCOLOR=\"" PHP_ENTRY_NAME_COLOR "\">%s<BR></TD><TD>%ld<BR></TD><TD>%ld<BR></TD></TR>\n",directive,value1,value2); - -#define SECTION(name) PUTS("<H2>" name "</H2>\n") - -#define CREDIT_LINE(module, authors) php_info_print_table_row(2, module, authors) - - -static int _display_module_info(zend_module_entry *module, void *arg) -{ - int show_info_func = *((int *) arg); - - if (show_info_func && module->info_func) { - php_printf("<A NAME=\"module_%s\"><H2>%s</H2>\n", module->name, module->name); - module->info_func(module); - } else if (!show_info_func && !module->info_func) { - php_printf("<TR VALIGN=\"baseline\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\">"); - php_printf("<TD>"); - php_printf(module->name); - php_printf("</TD></TR>\n"); - } - return 0; -} - - -static void php_print_gpcse_array(char *name, uint name_length ELS_DC) -{ - zval **data, **tmp; - char *string_key; - ulong num_key; - - if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE - && ((*data)->type==IS_ARRAY)) { - zend_hash_internal_pointer_reset((*data)->value.ht); - while (zend_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) { - zval tmp2, *value_ptr; - - if ((*tmp)->type != IS_STRING) { - tmp2 = **tmp; - zval_copy_ctor(&tmp2); - convert_to_string(&tmp2); - value_ptr = &tmp2; - } else { - value_ptr = *tmp; - } - PUTS("<TR VALIGN=\"baseline\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\">"); - PUTS("<TD BGCOLOR=\"" PHP_ENTRY_NAME_COLOR "\"><B>"); - PUTS(name); - PUTS("[\""); - switch (zend_hash_get_current_key((*data)->value.ht, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - PUTS(string_key); - efree(string_key); - break; - case HASH_KEY_IS_LONG: - php_printf("%ld",num_key); - break; - } - PUTS("\"]</B></TD><TD>"); - if ((*tmp)->type == IS_ARRAY) { - PUTS("<PRE>"); - zend_print_zval_r(*tmp, 0); - PUTS("</PRE>"); - } else { - PUTS(value_ptr->value.str.val); - } - PUTS("</TD></TR>\n"); - zend_hash_move_forward((*data)->value.ht); - if (value_ptr==&tmp2) { - zval_dtor(value_ptr); - } - } - } -} - -void php_info_print_style() -{ - php_printf("<STYLE TYPE=\"text/css\"><!--\n"); - php_printf("A { text-decoration: none; }\n"); - php_printf("A:hover { text-decoration: underline; }\n"); - php_printf("H1 { font-family: arial,helvetica,sans-serif; font-size: 18pt; font-weight: bold;}\n"); - php_printf("H2 { font-family: arial,helvetica,sans-serif; font-size: 14pt; font-weight: bold;}\n"); - php_printf("BODY,TD { font-family: arial,helvetica,sans-serif; font-size: 10pt; }\n"); - php_printf("TH { font-family: arial,helvetica,sans-serif; font-size: 11pt; font-weight: bold; }\n"); - php_printf("//--></STYLE>\n"); -} - - -PHPAPI void php_print_info(int flag) -{ - char **env,*tmp1,*tmp2; - char *php_uname; - int expose_php = INI_INT("expose_php"); - time_t the_time; - struct tm *ta, tmbuf; -#ifdef PHP_WIN32 - char php_windows_uname[256]; - DWORD dwBuild=0; - DWORD dwVersion = GetVersion(); - DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); - DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); -#endif - ELS_FETCH(); - SLS_FETCH(); - - the_time = time(NULL); - ta = php_localtime_r(&the_time, &tmbuf); - - PUTS("<CENTER>"); - - if (flag & PHP_INFO_GENERAL) { - char *zend_version = get_zend_version(); - -#ifdef PHP_WIN32 - // Get build numbers for Windows NT or Win95 - if (dwVersion < 0x80000000){ - dwBuild = (DWORD)(HIWORD(dwVersion)); - snprintf(php_windows_uname,255,"%s %d.%d build %d","Windows NT",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild); - } else { - snprintf(php_windows_uname,255,"%s %d.%d","Windows 95/98",dwWindowsMajorVersion,dwWindowsMinorVersion); - } - php_uname = php_windows_uname; -#else - php_uname=PHP_UNAME; -#endif - - php_info_print_style(); - - php_info_print_box_start(1); - if (expose_php) { - PUTS("<a href=\"http://www.php.net/\"><img src=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - if ((ta->tm_mon==3) && (ta->tm_mday==1)) { - PUTS("?=PHPE9568F36-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\"></a>"); - } else { - PUTS("?=PHPE9568F34-D428-11d2-A769-00AA001ACF42\" border=0 align=\"right\"></a>"); - } - } - php_printf("<H1>PHP Version %s</H1>\n", 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__ ); -#ifdef CONFIGURE_COMMAND - php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND ); -#endif - if (sapi_module.name) { - php_info_print_table_row(2, "Server API", sapi_module.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", CONFIGURATION_FILE_PATH ); - -#if ZEND_DEBUG - php_info_print_table_row(2, "ZEND_DEBUG", "enabled" ); -#else - php_info_print_table_row(2, "ZEND_DEBUG", "disabled" ); -#endif - -#ifdef ZTS - php_info_print_table_row(2, "Thread Safety", "enabled" ); -#else - php_info_print_table_row(2, "Thread Safety", "disabled" ); -#endif - php_info_print_table_end(); - - /* Zend Engine */ - php_info_print_box_start(0); - if (expose_php) { - PUTS("<a href=\"http://www.zend.com/\"><img src=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - PUTS("?=PHPE9568F35-D428-11d2-A769-00AA001ACF42\" border=\"0\" align=\"right\"></a>\n"); - } - php_printf("This program makes use of the Zend scripting language engine:<BR>"); - zend_html_puts(zend_version, strlen(zend_version)); - php_printf("</BR>\n"); - php_info_print_box_end(); - } - - if ((flag & PHP_INFO_CREDITS) && expose_php) { - php_info_print_hr(); - PUTS("<a href=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">"); - PUTS("<h1>PHP 4.0 Credits</h1>"); - PUTS("</a>\n"); - } - - php_ini_sort_entries(); - - if (flag & PHP_INFO_CONFIGURATION) { - php_info_print_hr(); - PUTS("<h1>Configuration</h1>\n"); - SECTION("PHP Core\n"); - display_ini_entries(NULL); - } - - if (flag & PHP_INFO_MODULES) { - int show_info_func; - - show_info_func = 1; - zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); - - SECTION("Additional Modules"); - php_info_print_table_start(); - show_info_func = 0; - zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); - php_info_print_table_end(); - } - - 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", (*data)->value.str.val); - } - 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", (*data)->value.str.val); - } - 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", (*data)->value.str.val); - } - 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", (*data)->value.str.val); - } - php_print_gpcse_array("HTTP_GET_VARS", sizeof("HTTP_GET_VARS")-1 ELS_CC); - php_print_gpcse_array("HTTP_POST_VARS", sizeof("HTTP_POST_VARS")-1 ELS_CC); - php_print_gpcse_array("HTTP_POST_FILES", sizeof("HTTP_POST_FILES")-1 ELS_CC); - php_print_gpcse_array("HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS")-1 ELS_CC); - php_print_gpcse_array("HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS")-1 ELS_CC); - php_print_gpcse_array("HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS")-1 ELS_CC); - php_info_print_table_end(); - } - - if (flag & PHP_INFO_LICENSE) { - 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(); - } - - PUTS("</center>"); -} - - -void php_print_credits(int flag) -{ - if (flag & PHP_CREDITS_FULLPAGE) { - PUTS("<html><head><title>PHP Credits</title></head><body>\n"); - } - - php_info_print_style(); - - PUTS("<center>"); - PUTS("<h1>PHP 4.0 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, 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.0 Language */ - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "PHP 4.0 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"); - 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"); - php_info_print_table_end(); - } - - if (flag & PHP_CREDITS_GENERAL) { - /* SAPI Modules */ - - php_info_print_table_start(); - php_info_print_table_colspan_header(2, "SAPI Module"); - php_info_print_table_header(2, "Contribution", "Authors"); - CREDIT_LINE("Apache", "Rasmus Lerdorf, Zeev Suraski"); - CREDIT_LINE("ISAPI", "Andi Gutmans, Zeev Suraski"); - CREDIT_LINE("CGI", "Rasmus Lerdorf, Stig Bakken"); - CREDIT_LINE("AOLserver", "Sascha Schumann"); - CREDIT_LINE("Java Servlet", "Sam Ruby"); - CREDIT_LINE("Roxen", "David Hedbor"); - CREDIT_LINE("thttpd", "Sascha Schumann"); - 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"); - CREDIT_LINE("Apache", "Rasmus Lerdorf, Stig Bakken, David Sklar"); - CREDIT_LINE("Assert", "Thies C. Arntzen"); - CREDIT_LINE("BC Math", "Andi Gutmans"); - CREDIT_LINE("CyberCash", "Evan Klinger"); - CREDIT_LINE("Win32 COM", "Zeev Suraski"); - CREDIT_LINE("DAV", "Stig Bakken"); - CREDIT_LINE("DBA", "Sascha Schumann"); - CREDIT_LINE("DBM", "Rasmus Lerdorf, Jim Winstead"); - CREDIT_LINE("dBase", "Jim Winstead"); - CREDIT_LINE("FDF", "Uwe Steinmann"); - CREDIT_LINE("FilePro", "Chad Robinson"); - CREDIT_LINE("FTP", "Andrew Skalski"); - CREDIT_LINE("GD imaging", "Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto"); - CREDIT_LINE("GetText", "Alex Plotnick"); - 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"); - CREDIT_LINE("Informix", "Danny Heijl, Christian Cartus"); - CREDIT_LINE("Java", "Sam Ruby"); - CREDIT_LINE("InterBase", "Jouni Ahto, Andrew Avdeev"); - CREDIT_LINE("LDAP", "Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson"); - CREDIT_LINE("MCAL", "Mark Musone, Chuck Hagenbuch"); - CREDIT_LINE("mcrypt", "Sascha Schumann"); - CREDIT_LINE("mhash", "Sascha Schumann"); - CREDIT_LINE("MS SQL", "Frank M. Kromann"); - CREDIT_LINE("mSQL", "Zeev Suraski"); - CREDIT_LINE("MySQL", "Zeev Suraski"); - CREDIT_LINE("OCI8", "Stig Bakken, Thies C. Arntzen"); - CREDIT_LINE("ODBC", "Stig Bakken, Andreas Karajannis, Frank M. Kromann"); - CREDIT_LINE("Oracle", "Stig Bakken, Mitch Golden, Rasmus Lerdorf, Andreas Karajannis, Thies C. Arntzen"); - CREDIT_LINE("Perl Compatible Regexps", "Andrei Zmievski"); - CREDIT_LINE("PDF", "Uwe Steinmann"); - CREDIT_LINE("Posix", "Kristian Köhntopp"); - CREDIT_LINE("PostgreSQL", "Jouni Ahto, Zeev Suraski"); - CREDIT_LINE("Readline", "Thies C. Arntzen"); - CREDIT_LINE("Recode", "Kristian Köhntopp"); - CREDIT_LINE("Sessions", "Sascha Schumann, Andrei Zmievski"); - CREDIT_LINE("SNMP", "Rasmus Lerdorf"); - CREDIT_LINE("SWF", "Sterling Hughes"); - CREDIT_LINE("Sybase", "Zeev Suraski"); - CREDIT_LINE("System V Shared Memory", "Christian Cartus"); - CREDIT_LINE("System V Semaphores", "Tom May"); - CREDIT_LINE("WDDX", "Andrei Zmievski"); - CREDIT_LINE("XML", "Stig Bakken, Thies C. Arntzen"); - CREDIT_LINE("Yellow Pages", "Stephanie Wehner"); - CREDIT_LINE("Zlib", "Rasmus Lerdorf, Stefan Roehrich"); - 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, "Alexander Aulbach, Stig Bakken, Rasmus Lerdorf, Egon Schmid, Zeev Suraski, Lars Torben Wilson, Jim Winstead"); - php_info_print_table_row(1, "Edited by: Stig Bakken and Egon Schmid"); - php_info_print_table_end(); - } - - PUTS("</center>"); - - if (flag & PHP_CREDITS_FULLPAGE) { - PUTS("</body></html>\n"); - } -} - -PHPAPI void php_info_print_table_start() -{ - php_printf("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=600 BGCOLOR=\"#000000\">\n"); -} - -PHPAPI void php_info_print_table_end() -{ - php_printf("</TABLE><BR>\n"); - -} - -PHPAPI void php_info_print_box_start(int flag) -{ - php_info_print_table_start(); - if (flag) { - php_printf("<TR VALIGN=\"middle\" BGCOLOR=\"" PHP_HEADER_COLOR "\"><TD ALIGN=\"left\">\n"); - } else { - php_printf("<TR VALIGN=\"top\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\"><TD ALIGN=\"left\">\n"); - } -} - -PHPAPI void php_info_print_box_end() -{ - php_printf("</TD></TR>\n"); - php_info_print_table_end(); -} - -PHPAPI void php_info_print_hr() -{ - php_printf("<HR NOSHADE SIZE=1 WIDTH=600>\n"); -} - -PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) -{ - php_printf("<TR BGCOLOR=\"" PHP_HEADER_COLOR "\"><TH COLSPAN=%d>%s</TH></TR>\n", num_cols, header ); -} - - -PHPAPI void php_info_print_table_header(int num_cols, ...) -{ - int i; - va_list row_elements; - char *row_element; - - va_start(row_elements, num_cols); - - php_printf("<TR VALIGN=\"bottom\" bgcolor=\"" PHP_HEADER_COLOR "\">"); - for (i=0; i<num_cols; i++) { - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - row_element = " "; - } - php_printf("<TH>%s</TH>", row_element); - } - php_printf("</TR>\n"); - - va_end(row_elements); -} - - -PHPAPI void php_info_print_table_row(int num_cols, ...) -{ - int i; - va_list row_elements; - char *row_element; - - va_start(row_elements, num_cols); - - php_printf("<TR VALIGN=\"baseline\" BGCOLOR=\"" PHP_CONTENTS_COLOR "\">"); - for (i=0; i<num_cols; i++) { - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - row_element = " "; - } - php_printf("<TD %s>%s%s%s</td>", - (i==0?"BGCOLOR=\"" PHP_ENTRY_NAME_COLOR "\" ":"ALIGN=\"center\""), - (i==0?"<B>":""), - row_element, - (i==0?"</B>":"")); - } - php_printf("</TR>\n"); - - va_end(row_elements); -} - - - -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_ALL", PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS); -} - - -/* {{{ proto void phpinfo(void) - Output a page of useful information about PHP and the current request */ -PHP_FUNCTION(phpinfo) -{ - int flag; - zval **flag_arg; - - - switch (ZEND_NUM_ARGS()) { - case 0: - flag = 0xFFFFFFFF; - break; - case 1: - if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(flag_arg); - flag = (*flag_arg)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - php_print_info(flag); - RETURN_TRUE; -} - -/* }}} */ - -/* {{{ proto string phpversion(void) - Return the current PHP version */ -PHP_FUNCTION(phpversion) -{ - RETURN_STRING(PHP_VERSION,1); -} -/* }}} */ - - -/* {{{ proto void phpcredits(int) - Prints the list of people who've contributed to the PHP project */ -PHP_FUNCTION(phpcredits) -{ - int flag; - zval **flag_arg; - - - switch (ZEND_NUM_ARGS()) { - case 0: - flag = 0xFFFFFFFF; - break; - case 1: - if (zend_get_parameters_ex(1, &flag_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(flag_arg); - flag = (*flag_arg)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - php_print_credits(flag); - RETURN_TRUE; -} - -/* }}} */ - - -PHP_FUNCTION(php_logo_guid) -{ - RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1); -} - -PHP_FUNCTION(php_egg_logo_guid) -{ - RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1); -} - - -PHP_FUNCTION(zend_logo_guid) -{ - RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/info.h b/ext/standard/info.h deleted file mode 100644 index 66c3c007d8..0000000000 --- a/ext/standard/info.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | 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 - - -#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_ALL 0xFFFFFFFF - -#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" - -PHP_FUNCTION(phpversion); -PHP_FUNCTION(phpinfo); -PHP_FUNCTION(phpcredits); -PHP_FUNCTION(php_logo_guid); -PHP_FUNCTION(zend_logo_guid); -PHPAPI void php_print_info(int flag); -PHPAPI void php_print_credits(int flag); -PHPAPI void php_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 248eafd619..0000000000 --- a/ext/standard/iptc.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $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 - -static int php_iptc_put1(FILE *fp,int spool,unsigned char c,unsigned char **spoolbuf) -{ - if (spool > 0) - PUTC(c); - - if (spoolbuf) *(*spoolbuf)++ = c; - - return c; -} - -static int php_iptc_get1(FILE *fp,int spool,unsigned char **spoolbuf) -{ - 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; -} - -static int php_iptc_read_remaining(FILE *fp,int spool,unsigned char **spoolbuf) -{ - int c; - - while ((c = php_iptc_get1(fp,spool,spoolbuf)) != EOF) continue; - - return M_EOI; -} - -static int php_iptc_skip_variable(FILE *fp,int spool,unsigned char **spoolbuf) -{ - unsigned int length; - int c1,c2; - - if ((c1 = php_iptc_get1(fp,spool,spoolbuf)) == EOF) return M_EOI; - - if ((c2 = php_iptc_get1(fp,spool,spoolbuf)) == EOF) return M_EOI; - - length = (((unsigned char) c1) << 8) + ((unsigned char) c2); - - length -= 2; - - while (length--) - if (php_iptc_get1(fp,spool,spoolbuf) == EOF) return M_EOI; - - return 0; -} - -static int php_iptc_next_marker(FILE *fp,int spool,unsigned char **spoolbuf) -{ - int c; - - /* skip unimportant stuff */ - - c = php_iptc_get1(fp,spool,spoolbuf); - - if (c == EOF) return M_EOI; - - while (c != 0xff) { - if ((c = php_iptc_get1(fp,spool,spoolbuf)) == EOF) - return M_EOI; /* we hit EOF */ - } - - /* get marker byte, swallowing possible padding */ - do { - c = php_iptc_get1(fp,0,0); - if (c == EOF) - return M_EOI; /* we hit EOF */ - else - if (c == 0xff) - php_iptc_put1(fp,spool,(unsigned char)c,spoolbuf); - } 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 = (*spool_flag)->value.lval; - 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((*jpeg_file)->value.str.val)) - RETURN_FALSE; - - if ((fp = V_FOPEN((*jpeg_file)->value.str.val,"rb")) == 0) { - php_error(E_WARNING, "Unable to open %s", (*jpeg_file)->value.str.val); - RETURN_FALSE; - } - - if (spool > 0) - if (!php_header()){ /* we got a HEAD request. */ - if (spool == 2){ - RETURN_TRUE; /* we only wanted to spool - report success. */ - } else - if (spool == 1) { - spool = 0; /* we wanted the file to be spooled/returned, just return it */ - } - } - - len = (*iptcdata)->value.str.len; - - 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) != 0xFF) { - fclose(fp); - RETURN_FALSE; - } - - if (php_iptc_get1(fp,spool,poi?&poi:0) != 0xD8) { - fclose(fp); - RETURN_FALSE; - } - - while (!done) { - marker = php_iptc_next_marker(fp,spool,poi?&poi:0); - - if (marker == M_EOI) { /* EOF */ - break; - } else if (marker != M_APP13) { - php_iptc_put1(fp,spool,(unsigned char)marker,poi?&poi:0); - } - - 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); - php_iptc_read_remaining(fp,spool,poi?&poi:0); - 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); - - 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); - - php_iptc_put1(fp,spool,(unsigned char)(len>>8),poi?&poi:0); - php_iptc_put1(fp,spool,(unsigned char)(len&0xff),poi?&poi:0); - - for (inx = 0; inx < len; inx++) - php_iptc_put1(fp,spool,(*iptcdata)->value.str.val[inx],poi?&poi:0); - break; - - case M_SOS: - /* we hit data, no more marker-inserting can be done! */ - php_iptc_read_remaining(fp,spool,poi?&poi:0); - done = 1; - break; - - default: - php_iptc_skip_variable(fp,spool,poi?&poi:0); - 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, inheader, 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 = (*str)->value.str.len; - buffer = (*str)->value.str.val; - - inheader = 0; /* have we already found the IPTC-Header??? */ - 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 ((inx + len) > length) - break; - - if (tagsfound == 0) { /* found the 1st tag - initialize the return array */ - if (array_init(return_value) == FAILURE) { - php_error(E_ERROR, "Unable to initialize array"); - RETURN_FALSE; - } - } - - if (zend_hash_find(return_value->value.ht,key,strlen(key) + 1,(void **) &element) == FAILURE) { - ALLOC_ZVAL(values); - INIT_PZVAL(values); - if (array_init(values) == FAILURE) { - php_error(E_ERROR, "Unable to initialize array"); - RETURN_FALSE; - } - - zend_hash_update(return_value->value.ht, 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: - */ diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c deleted file mode 100644 index 43148517f5..0000000000 --- a/ext/standard/lcg.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Sascha Schumann <ss@2ns.de> | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_lcg.h" - -#if HAVE_UNISTD_H -#include <unistd.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 - -double php_combined_lcg(void) -{ - long q; - long z; - LCGLS_FETCH(); - - 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_init_globals(LCGLS_D) -{ - LCG(s1) = 1; -#ifdef ZTS - LCG(s2) = (long) tsrm_thread_id(); -#else - LCG(s2) = (long) getpid(); -#endif -} - -PHP_MINIT_FUNCTION(lcg) -{ -#ifdef ZTS - lcg_globals_id = ts_allocate_id(sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL); -#else - lcg_init_globals(); -#endif - return SUCCESS; -} - -/* {{{ proto double lcg_value() - Returns a value from the combined linear congruential generator */ -PHP_FUNCTION(lcg_value) -{ - RETURN_DOUBLE(php_combined_lcg()); -} -/* }}} */ diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c deleted file mode 100644 index ccb767b6d8..0000000000 --- a/ext/standard/levenshtein.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 <hartmut@six.de> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include "php.h" -#include <stdlib.h> -#include <errno.h> -#include <ctype.h> -#include "php_string.h" - -static int calc_levdist(const char *s1, const char *s2) /* faster, but obfuscated */ -{ - register char *p1,*p2; - register int i,j,n; - int l1=0,l2=0; - char r[512]; - const char *tmp; - - /* skip equal start sequence, if any */ - while(*s1==*s2) { - if(!*s1) break; - s1++; s2++; - } - - /* if we already used up one string, then - the result is the length of the other */ - if(*s1=='\0') return strlen(s2); - if(*s2=='\0') return strlen(s1); - - /* length count */ - while(*s1++) l1++; - while(*s2++) l2++; - - /* cut of equal tail sequence, if any */ - while(*--s1 == *--s2) { - l1--; l2--; - } - - - /* reset pointers, adjust length */ - s1-=l1++; - s2-=l2++; - - - /* possible dist to great? */ - if(abs(l1-l2)>=255) return -1; - - /* swap if l2 longer than l1 */ - if(l1<l2) { - tmp=s1; s1=s2; s2=tmp; - l1 ^= l2; l2 ^= l1; l1 ^= l2; - } - - - /* fill initial row */ - n=(*s1!=*s2); - for(i=0,p1=r;i<l1;i++,*p1++=n++,p1++) {/*empty*/} - - /* calc. rowwise */ - for(j=1;j<l2;j++) { - /* init pointers and col#0 */ - p1 = r + !(j&1); - p2 = r + (j&1); - n=*p1+1; - *p2++=n;p2++; - s2++; - - /* foreach column */ - for(i=1;i<l1;i++) { - if(*p1<n) n=*p1+(*(s1+i)!=*(s2)); /* replace cheaper than delete? */ - p1++; - if(*++p1<n) n=*p1+1; /* insert cheaper then insert ? */ - *p2++=n++; /* update field and cost for next col's delete */ - p2++; - } - } - - /* return result */ - return n-1; -} - - -/* {{{ proto int levenshtein(string str1, string str2) - Calculate Levenshtein distance between two strings */ -PHP_FUNCTION(levenshtein) -{ - zval **str1, **str2; - int l; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &str1, &str2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str1); - convert_to_string_ex(str2); - - l = calc_levdist((*str1)->value.str.val, (*str2)->value.str.val); - - if(l<0) { - php_error(E_WARNING,"levenshtein(): argument string(s) too long"); - } - - RETURN_LONG(l); -} -/* }}} */ - diff --git a/ext/standard/link.c b/ext/standard/link.c deleted file mode 100644 index 7cb9102b94..0000000000 --- a/ext/standard/link.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_filestat.h" -#include "php_globals.h" - -#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" -#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) -{ -#if HAVE_SYMLINK - pval **filename; - char buff[256]; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - ret = readlink((*filename)->value.str.val, buff, 255); - if (ret == -1) { - php_error(E_WARNING, "readlink failed (%s)", strerror(errno)); - RETURN_FALSE; - } - /* Append NULL to the end of the string */ - buff[ret] = '\0'; - RETURN_STRING(buff,1); -#endif -} -/* }}} */ - -/* {{{ proto int linkinfo(string filename) - Returns the st_dev field of the UNIX C stat structure describing the link */ -PHP_FUNCTION(linkinfo) -{ -#if HAVE_SYMLINK - pval **filename; - struct stat sb; - int ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - ret = V_LSTAT((*filename)->value.str.val, &sb); - if (ret == -1) { - php_error(E_WARNING, "LinkInfo failed (%s)", strerror(errno)); - RETURN_LONG(-1L); - } - RETURN_LONG((long) sb.st_dev); -#endif -} -/* }}} */ - -/* {{{ proto int symlink(string target, string link) - Create a symbolic link */ -PHP_FUNCTION(symlink) -{ -#if HAVE_SYMLINK - pval **topath, **frompath; - int ret; - PLS_FETCH(); - - 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); - - if (PG(safe_mode) && !php_checkuid((*topath)->value.str.val, 2)) { - RETURN_FALSE; - } - if (!strncasecmp((*topath)->value.str.val,"http://",7) || !strncasecmp((*topath)->value.str.val,"ftp://",6)) { - php_error(E_WARNING, "Unable to symlink to a URL"); - RETURN_FALSE; - } - - ret = symlink((*topath)->value.str.val, (*frompath)->value.str.val); - if (ret == -1) { - php_error(E_WARNING, "SymLink failed (%s)", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -#endif -} -/* }}} */ - -/* {{{ proto int link(string target, string link) - Create a hard link */ -PHP_FUNCTION(link) -{ -#if HAVE_LINK - pval **topath, **frompath; - int ret; - PLS_FETCH(); - - 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); - - if (PG(safe_mode) && !php_checkuid((*topath)->value.str.val, 2)) { - RETURN_FALSE; - } - if (!strncasecmp((*topath)->value.str.val,"http://",7) || !strncasecmp((*topath)->value.str.val,"ftp://",6)) { - php_error(E_WARNING, "Unable to link to a URL"); - RETURN_FALSE; - } - - ret = link((*topath)->value.str.val, (*frompath)->value.str.val); - if (ret == -1) { - php_error(E_WARNING, "Link failed (%s)", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -#endif -} -/* }}} */ - -/* {{{ proto int unlink(string filename) - Delete a file */ -PHP_FUNCTION(unlink) -{ - pval **filename; - int ret; - PLS_FETCH(); - - 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((*filename)->value.str.val, 2)) { - RETURN_FALSE; - } - - ret = V_UNLINK((*filename)->value.str.val); - if (ret == -1) { - php_error(E_WARNING, "Unlink failed (%s)", strerror(errno)); - RETURN_FALSE; - } - /* Clear stat cache */ - PHP_FN(clearstatcache)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - RETURN_TRUE; -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/mail.c b/ext/standard/mail.c deleted file mode 100644 index 4e71e33320..0000000000 --- a/ext/standard/mail.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include "php.h" -#include "ext/standard/info.h" -#if !defined(PHP_WIN32) -#include "build-defs.h" -#endif -#include "php_mail.h" -#include "php_ini.h" - -#if HAVE_SENDMAIL -#ifdef PHP_WIN32 -#include "win32/sendmail.h" -#endif - -#ifdef COMPILE_DL_STANDARD -ZEND_GET_MODULE(odbc) -#endif - -/* {{{ proto int mail(string to, string subject, string message [, string additional_headers]) - Send an email message */ -PHP_FUNCTION(mail) -{ - pval **argv[4]; - char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL; - int argc; - - argc = ZEND_NUM_ARGS(); - if (argc < 3 || argc > 4 || zend_get_parameters_array_ex(argc, argv) == FAILURE) { - WRONG_PARAM_COUNT; - } - /* To: */ - convert_to_string_ex(argv[0]); - if ((*argv[0])->value.str.val) { - to = (*argv[0])->value.str.val; - } else { - php_error(E_WARNING, "No to field in mail command"); - RETURN_FALSE; - } - - /* Subject: */ - convert_to_string_ex(argv[1]); - if ((*argv[1])->value.str.val) { - subject = (*argv[1])->value.str.val; - } else { - php_error(E_WARNING, "No subject field in mail command"); - RETURN_FALSE; - } - - /* message body */ - convert_to_string_ex(argv[2]); - if ((*argv[2])->value.str.val) { - message = (*argv[2])->value.str.val; - } else { - /* this is not really an error, so it is allowed. */ - php_error(E_WARNING, "No message string in mail command"); - message = NULL; - } - - if (argc == 4) { /* other headers */ - convert_to_string_ex(argv[3]); - headers = (*argv[3])->value.str.val; - } - - if (php_mail(to, subject, message, headers)){ - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -int php_mail(char *to, char *subject, char *message, char *headers) -{ -#ifdef PHP_WIN32 - int tsm_err; -#else - FILE *sendmail; - int ret; - char *sendmail_path = INI_STR("sendmail_path"); -#endif - -#ifdef PHP_WIN32 - if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){ - php_error(E_WARNING, GetSMErrorText(tsm_err)); - return 0; - } -#else - if (!sendmail_path) { - return 0; - } - sendmail = popen(sendmail_path, "w"); - - if (sendmail) { - 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); - if (ret == -1) { - return 0; - } else { - return 1; - } - } else { - php_error(E_WARNING, "Could not execute mail delivery program"); - return 0; - } -#endif - return 1; -} - -PHP_MINFO_FUNCTION(mail) -{ -#ifdef PHP_WIN32 - php_info_print_table_row(2, "Internal Sendmail Support for Windows 4", "enabled"); -#else - php_info_print_table_row(2, "Path to sendmail", INI_STR("sendmail_path") ); -#endif -} - -#else - -PHP_FUNCTION(mail) {} -PHP_MINFO_FUNCTION(mail) {} - -#endif - - -/* - * Local variables: - * tab-width: 4 - * End: - */ diff --git a/ext/standard/math.c b/ext/standard/math.c deleted file mode 100644 index dfda040458..0000000000 --- a/ext/standard/math.c +++ /dev/null @@ -1,734 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@guardian.no> | - | Zeev Suraski <zeev@zend.com> | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ -*/ - -/* $Id: */ - -#include "php.h" -#include "phpmath.h" - -#include <math.h> -#include <float.h> - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - - -char *_php_math_number_format(double, int, char ,char); - -/* {{{ 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 ((*value)->type == IS_DOUBLE) { - RETURN_DOUBLE(fabs((*value)->value.dval)); - } else if ((*value)->type == IS_LONG) { - RETURN_LONG((*value)->value.lval < 0 ? -(*value)->value.lval : (*value)->value.lval); - } - - RETURN_FALSE; -} - -/* }}} */ -/* {{{ proto int ceil(double 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 ((*value)->type == IS_DOUBLE) { - RETURN_LONG((long)ceil((*value)->value.dval)); - } else if ((*value)->type == IS_LONG) { - RETURN_LONG((*value)->value.lval); - } - - RETURN_FALSE; -} - -/* }}} */ -/* {{{ proto int floor(double 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 ((*value)->type == IS_DOUBLE) { - RETURN_LONG((long)floor((*value)->value.dval)); - } else if ((*value)->type == IS_LONG) { - RETURN_LONG((*value)->value.lval); - } - - RETURN_FALSE; -} - -/* }}} */ - - -/* {{{ proto double round(double 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, 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 double sin(double 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); - return_value->value.dval = sin((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double cos(double 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); - return_value->value.dval = cos((*num)->value.dval); - return_value->type = IS_DOUBLE; -} -/* }}} */ -/* {{{ proto double tan(double 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); - return_value->value.dval = tan((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double asin(double 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); - return_value->value.dval = asin((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double acos(double 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); - return_value->value.dval = acos((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double atan(double 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); - return_value->value.dval = atan((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double atan2(double y, double 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); - return_value->value.dval = atan2((*num1)->value.dval,(*num2)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double pi(void) - Returns an approximation of pi */ - -PHP_FUNCTION(pi) -{ - return_value->value.dval = M_PI; - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double pow(double base, double exponent) - Returns base raised to the power of exponent */ - -PHP_FUNCTION(pow) -{ - 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); - RETURN_DOUBLE(pow((*num1)->value.dval, (*num2)->value.dval)); -} - -/* }}} */ -/* {{{ proto double exp(double 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); - return_value->value.dval = exp((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double log(double number) - Returns the natural logarithm of the number */ - -PHP_FUNCTION(log) -{ - zval **num; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_double_ex(num); - return_value->value.dval = log((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double log10(double 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); - return_value->value.dval = log10((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double sqrt(double 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); - return_value->value.dval = sqrt((*num)->value.dval); - return_value->type = IS_DOUBLE; -} - -/* }}} */ -/* {{{ proto double deg2rad(double 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(((*deg)->value.dval / 180.0) * M_PI); -} - -/* }}} */ -/* {{{ proto double rad2deg(double 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(((*rad)->value.dval / M_PI) * 180); -} - -/* }}} */ -/* {{{ _php_math_basetolong */ - -/* - * Convert a string representation of a base(2-36) number to a long. - */ -static long -_php_math_basetolong(zval *arg, int base) { - long mult = 1, num = 0, digit; - int i; - char c, *s; - - if (arg->type != IS_STRING || base < 2 || base > 36) { - return 0; - } - - s = arg->value.str.val; - - for (i = arg->value.str.len - 1; i >= 0; i--, mult *= base) { - c = toupper(s[i]); - if (c >= '0' && c <= '9') { - digit = (c - '0'); - } else if (c >= 'A' && c <= 'Z') { - digit = (c - 'A' + 10); - } else { - continue; - } - if (digit >= base) { - continue; - } - num += mult * digit; - } - - return num; -} - -/* }}} */ -/* {{{ _php_math_longtobase */ - -/* - * Convert a long to a string containing a base(2-36) representation of - * the number. - */ -static char * -_php_math_longtobase(zval *arg, int base) -{ - static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - char *result, *ptr, *ret; - int len, digit; - long value; - - if (arg->type != IS_LONG || base < 2 || base > 36) { - return empty_string; - } - - value = arg->value.lval; - - /* allocates space for the longest possible result with the lowest base */ - len = (sizeof(arg->value.lval) * 8) + 1; - result = emalloc((sizeof(arg->value.lval) * 8) + 1); - - ptr = result + len - 1; - *ptr-- = '\0'; - - do { - digit = value % base; - *ptr = digits[digit]; - value /= base; - } - while (ptr-- > result && value); - ptr++; - ret = estrdup(ptr); - efree(result); - - return ret; -} - -/* }}} */ -/* {{{ proto int bindec(string binary_number) - Returns the decimal equivalent of the binary number */ - -PHP_FUNCTION(bindec) -{ - zval **arg; - long ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - ret = _php_math_basetolong(*arg, 2); - - RETVAL_LONG(ret); -} - -/* }}} */ -/* {{{ proto int hexdec(string hexadimal_number) - Returns the decimal equivalent of the hexadecimal number */ - -PHP_FUNCTION(hexdec) -{ - zval **arg; - long ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - ret = _php_math_basetolong(*arg, 16); - RETVAL_LONG(ret); -} - -/* }}} */ -/* {{{ proto int octdec(string octal_number) - Returns the decimal equivalent of an octal string */ - -PHP_FUNCTION(octdec) -{ - zval **arg; - long ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - ret = _php_math_basetolong(*arg, 8); - RETVAL_LONG(ret); -} - -/* }}} */ -/* {{{ 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); - return_value->type = IS_STRING; - return_value->value.str.len = strlen(result); - return_value->value.str.val = 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); - return_value->type = IS_STRING; - return_value->value.str.len = strlen(result); - return_value->value.str.val = 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); - return_value->type = IS_STRING; - return_value->value.str.len = strlen(result); - return_value->value.str.val = 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 ((*frombase)->value.lval < 2 || (*frombase)->value.lval > 36) { - php_error(E_WARNING, "base_convert: invalid `from base' (%d)",(*frombase)->value.lval); - RETURN_FALSE; - } - if ((*tobase)->value.lval < 2 || (*tobase)->value.lval > 36) { - php_error(E_WARNING, "base_convert: invalid `to base' (%d)",(*tobase)->value.lval); - RETURN_FALSE; - } - temp.type = IS_LONG; - temp.value.lval = _php_math_basetolong(*number, (*frombase)->value.lval); - result = _php_math_longtobase(&temp, (*tobase)->value.lval); - RETVAL_STRING(result, 0); -} - -/* }}} */ -/* {{{ _php_math_number_format */ - -char *_php_math_number_format(double d,int dec,char dec_point,char thousand_sep) -{ - char *tmpbuf,*resbuf; - char *s,*t; /* source, target */ - int tmplen,reslen=0; - int count=0; - int is_negative=0; - - if (d<0) { - is_negative=1; - d = -d; - } - dec = MAX(0,dec); - tmpbuf = (char *) emalloc(1+DBL_MAX_10_EXP+1+dec+1); - - tmplen=sprintf(tmpbuf,"%.*f",dec,d); - - if (!isdigit((int)tmpbuf[0])) { - return tmpbuf; - } - - if (dec_point!='.') { - for (t=tmpbuf; *t; t++) { - if (*t=='.') { - *t = dec_point; - break; - } - } - } - if (dec) { - reslen = dec+1 + (tmplen-dec-1) + (tmplen-1-dec-1)/3; - } else { - reslen = tmplen+(tmplen-1)/3; - } - if (is_negative) { - reslen++; - } - resbuf = (char *) emalloc(reslen+1); - - s = tmpbuf+tmplen-1; - t = resbuf+reslen; - *t-- = 0; - - if (dec) { - while (*s!=dec_point) { - *t-- = *s--; - } - *t-- = *s--; /* copy that dot */ - } - - while(s>=tmpbuf) { - *t-- = *s--; - if ((++count%3)==0 && s>=tmpbuf) { - *t-- = thousand_sep; - } - } - if (is_negative) { - *t-- = '-'; - } - efree(tmpbuf); - return resbuf; -} - -/* }}} */ -/* {{{ proto string number_format(double 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((*num)->value.dval,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((*num)->value.dval,(*dec)->value.lval,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 ((*d_p)->value.str.len==1) { - dec_point=(*d_p)->value.str.val[0]; - } - if ((*t_s)->value.str.len==1) { - thousand_sep=(*t_s)->value.str.val[0]; - } - RETURN_STRING(_php_math_number_format((*num)->value.dval,(*dec)->value.lval,dec_point,thousand_sep),0); - break; - default: - WRONG_PARAM_COUNT; - break; - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/md5.c b/ext/standard/md5.c deleted file mode 100644 index f86dfa9927..0000000000 --- a/ext/standard/md5.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Lachlan Roche | - +----------------------------------------------------------------------+ - */ - -/* - * md5.c - Copyright 1997 Lachlan Roche - */ - -#include <stdio.h> -#include "php.h" - -#include "md5.h" - -/* {{{ proto string md5(string str) - Calculate the md5 hash of a string */ -PHP_NAMED_FUNCTION(php_if_md5) -{ - pval **arg; - char md5str[33]; - PHP_MD5_CTX context; - unsigned char digest[16]; - int i; - char *r; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - md5str[0] = '\0'; - PHP_MD5Init(&context); - PHP_MD5Update(&context, (*arg)->value.str.val, (*arg)->value.str.len); - PHP_MD5Final(digest, &context); - for (i = 0, r = md5str; i < 16; i++, r += 2) { - sprintf(r, "%02x", digest[i]); - } - *r = '\0'; - 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 PROTO_LIST((UINT4[4], const unsigned char[64])); -static void Encode PROTO_LIST - ((unsigned char *, UINT4 *, unsigned int)); -static void Decode PROTO_LIST - ((UINT4 *, const unsigned char *, unsigned int)); -static void MD5_memcpy PROTO_LIST((_POINTER, _POINTER, unsigned int)); -static void MD5_memset PROTO_LIST((_POINTER, int, 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) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define GG(a, b, c, d, x, s, ac) { \ - (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define HH(a, b, c, d, x, s, ac) { \ - (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } -#define II(a, b, c, d, x, s, ac) { \ - (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \ - (a) = ROTATE_LEFT ((a), (s)); \ - (a) += (b); \ - } - -/* MD5 initialization. Begins an MD5 operation, writing a new context. - */ -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; -} - -/* MD5 block update operation. Continues an MD5 message-digest - operation, processing another message block, and updating the - context. - */ -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] += ((UINT4) inputLen << 3)) - < ((UINT4) inputLen << 3)) - context->count[1]++; - context->count[1] += ((UINT4) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - MD5_memcpy - ((_POINTER) & context->buffer[index], (_POINTER) 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 */ - MD5_memcpy - ((_POINTER) & context->buffer[index], (_POINTER) & input[i], - inputLen - i); -} - -/* MD5 finalization. Ends an MD5 message-digest operation, writing the - the message digest and zeroizing the context. - */ -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. - */ - MD5_memset((_POINTER) context, 0, sizeof(*context)); -} - -/* MD5 basic transformation. Transforms state based on block. - */ -static void MD5Transform(state, block) -UINT4 state[4]; -const unsigned char block[64]; -{ - UINT4 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. */ - MD5_memset((_POINTER) x, 0, sizeof(x)); -} - -/* Encodes input (UINT4) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void Encode(output, input, len) -unsigned char *output; -UINT4 *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); - } -} - -/* Decodes input (unsigned char) into output (UINT4). Assumes len is - a multiple of 4. - */ -static void Decode(output, input, len) -UINT4 *output; -const unsigned char *input; -unsigned int len; -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) | - (((UINT4) input[j + 2]) << 16) | (((UINT4) input[j + 3]) << 24); -} - -/* Note: Replace "for loop" with standard memcpy if possible. - */ - -static void MD5_memcpy(output, input, len) -_POINTER output; -_POINTER input; -unsigned int len; -{ - unsigned int i; - - for (i = 0; i < len; i++) - output[i] = input[i]; -} - -/* Note: Replace "for loop" with standard memset if possible. - */ -static void MD5_memset(output, value, len) -_POINTER output; -int value; -unsigned int len; -{ - unsigned int i; - - for (i = 0; i < len; i++) - ((char *) output)[i] = (char) value; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/md5.h b/ext/standard/md5.h deleted file mode 100644 index 86bb4f7ada..0000000000 --- a/ext/standard/md5.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -#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 "php_global.h" - -/* MD5 context. */ -typedef struct { - UINT4 state[4]; /* state (ABCD) */ - UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ - unsigned char buffer[64]; /* input buffer */ -} PHP_MD5_CTX; - -void PHP_MD5Init PROTO_LIST((PHP_MD5_CTX *)); -void PHP_MD5Update PROTO_LIST((PHP_MD5_CTX *, const unsigned char *, unsigned int)); -void PHP_MD5Final PROTO_LIST((unsigned char[16], PHP_MD5_CTX *)); - -PHP_NAMED_FUNCTION(php_if_md5); - -#endif diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c deleted file mode 100644 index fe9eae97fc..0000000000 --- a/ext/standard/metaphone.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Thies C. Arntzen <thies@digicol.de> | - +----------------------------------------------------------------------+ -*/ -/* - 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 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) -{ - pval **pstr, **pphones; - char *result = 0; - int phones = 0; - - if (zend_get_parameters_ex(2, &pstr, &pphones) == SUCCESS) { - convert_to_long_ex(pphones); - phones = (*pphones)->value.lval; - } else if (zend_get_parameters_ex(1, &pstr) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(pstr); - - if (metaphone((*pstr)->value.str.val, 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 */ -#define Phonize(c) {(*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)) - - -static int metaphone(char *word, 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 */ - -/*-- 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 */ - *phoned_word = emalloc(sizeof(char) * strlen(word) + 1); - if (!*phoned_word) - return -1; - } else { - *phoned_word = emalloc(sizeof(char) * max_phonemes + 1); - if (!*phoned_word) - return -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: - */ diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c deleted file mode 100644 index 2fb8a30ec5..0000000000 --- a/ext/standard/microtime.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#endif -#ifdef PHP_WIN32 -#include "win32/time.h" -#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 - -/* {{{ proto string microtime(void) - Returns a string containing the current time in seconds and microseconds */ -PHP_FUNCTION(microtime) -{ -#ifdef HAVE_GETTIMEOFDAY - 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); -#endif -} -/* }}} */ - - -/* {{{ proto array gettimeofday(void) - Returns the current time as array */ -PHP_FUNCTION(gettimeofday) -{ -#ifdef HAVE_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); - add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest); - add_assoc_long(return_value, "dsttime", tz.tz_dsttime); - return; - } else -#endif - RETURN_FALSE; -} -/* }}} */ - -#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((*pwho)->value.lval == 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) -#ifndef _OSD_POSIX /* 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: - */ diff --git a/ext/standard/microtime.h b/ext/standard/microtime.h deleted file mode 100644 index c815bfca82..0000000000 --- a/ext/standard/microtime.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _MICROTIME_H -#define _MICROTIME_H - -PHP_FUNCTION(microtime); -PHP_FUNCTION(gettimeofday); -PHP_FUNCTION(getrusage); - -#endif /* _MICROTIME_H */ diff --git a/ext/standard/output.c b/ext/standard/output.c deleted file mode 100644 index 03d81165ff..0000000000 --- a/ext/standard/output.c +++ /dev/null @@ -1,430 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Zeev Suraski <zeev@zend.com> | - | Thies C. Arntzen <thies@digicol.de> | - +----------------------------------------------------------------------+ -*/ - - -#include "php.h" -#include "ext/standard/head.h" -#include "ext/session/php_session.h" -#include "SAPI.h" - -/* output functions */ -static int php_ub_body_write(const char *str, uint str_length); -static int php_ub_body_write_no_header(const char *str, uint str_length); -static int php_b_body_write(const char *str, uint str_length); - -static void php_ob_init(uint initial_size, uint block_size); -static void php_ob_destroy(void); -static void php_ob_append(const char *text, uint text_length); -#if 0 -static void php_ob_prepend(const char *text, uint text_length); -#endif -static inline void php_ob_send(void); - - -typedef struct { - int (*php_body_write)(const char *str, uint str_length); /* string output */ - int (*php_header_write)(const char *str, uint str_length); /* unbuffer string output */ - char *ob_buffer; - uint ob_size; - uint ob_block_size; - uint ob_text_length; - unsigned char implicit_flush; - char *output_start_filename; - int output_start_lineno; -} php_output_globals; - -#ifdef ZTS -#define OLS_D php_output_globals *output_globals -#define OLS_C output_globals -#define OG(v) (output_globals->v) -#define OLS_FETCH() php_output_globals *output_globals = ts_resource(output_globals_id) -int output_globals_id; -#else -#define OLS_D void -#define OLS_C -#define OG(v) (output_globals.v) -#define OLS_FETCH() -php_output_globals output_globals; -#endif - -static void php_output_init_globals(OLS_D) -{ - OG(php_body_write) = NULL; - OG(php_header_write) = NULL; - OG(ob_buffer) = NULL; - OG(ob_size) = 0; - OG(ob_block_size) = 0; - OG(ob_text_length) = 0; - OG(implicit_flush) = 0; - OG(output_start_filename) = NULL; - OG(output_start_lineno) = 0; -} - - -PHP_GINIT_FUNCTION(output) -{ -#ifdef ZTS - output_globals_id = ts_allocate_id(sizeof(php_output_globals), (ts_allocate_ctor) php_output_init_globals, NULL); -#else - php_output_init_globals(OLS_C); -#endif - - return SUCCESS; -} - -/* Start output layer */ -PHPAPI void php_output_startup() -{ - OLS_FETCH(); - - OG(ob_buffer) = NULL; - OG(php_body_write) = php_ub_body_write; - OG(php_header_write) = sapi_module.ub_write; -} - -PHPAPI int php_body_write(const char *str, uint str_length) -{ - OLS_FETCH(); - return OG(php_body_write)(str, str_length); -} - -PHPAPI int php_header_write(const char *str, uint str_length) -{ - OLS_FETCH(); - return OG(php_header_write)(str, str_length); -} - -/* Start output buffering */ -PHPAPI void php_start_ob_buffering() -{ - OLS_FETCH(); - - php_ob_init(4096, 1024); - OG(php_body_write) = php_b_body_write; -} - - -/* End output buffering */ -PHPAPI void php_end_ob_buffering(int send_buffer) -{ - SLS_FETCH(); - OLS_FETCH(); - - if (!OG(ob_buffer)) { - return; - } - if (SG(headers_sent) && !SG(request_info).headers_only) { - OG(php_body_write) = php_ub_body_write_no_header; - } else { - OG(php_body_write) = php_ub_body_write; - } - if (send_buffer) { - php_ob_send(); - } - php_ob_destroy(); -} - - -PHPAPI void php_start_implicit_flush() -{ - OLS_FETCH(); - - php_end_ob_buffering(1); /* Switch out of output buffering if we're in it */ - OG(implicit_flush)=1; -} - - -PHPAPI void php_end_implicit_flush() -{ - OLS_FETCH(); - - OG(implicit_flush)=0; -} - - -/* - * Output buffering - implementation - */ - -static inline void php_ob_allocate(void) -{ - OLS_FETCH(); - - if (OG(ob_size)<OG(ob_text_length)) { - while (OG(ob_size) <= OG(ob_text_length)) - OG(ob_size)+=OG(ob_block_size); - - OG(ob_buffer) = (char *) erealloc(OG(ob_buffer), OG(ob_size)+1); - } -} - - -static void php_ob_init(uint initial_size, uint block_size) -{ - OLS_FETCH(); - - if (OG(ob_buffer)) { - return; - } - OG(ob_block_size) = block_size; - OG(ob_size) = initial_size; - OG(ob_buffer) = (char *) emalloc(initial_size+1); - OG(ob_text_length) = 0; -} - - -static void php_ob_destroy() -{ - OLS_FETCH(); - - if (OG(ob_buffer)) { - efree(OG(ob_buffer)); - OG(ob_buffer) = NULL; - } -} - - -static void php_ob_append(const char *text, uint text_length) -{ - char *target; - int original_ob_text_length; - OLS_FETCH(); - - original_ob_text_length=OG(ob_text_length); - - OG(ob_text_length) += text_length; - php_ob_allocate(); - target = OG(ob_buffer)+original_ob_text_length; - memcpy(target, text, text_length); - target[text_length]=0; -} - -#if 0 -static void php_ob_prepend(const char *text, uint text_length) -{ - char *p, *start; - OLS_FETCH(); - - OG(ob_text_length) += text_length; - php_ob_allocate(); - - /* php_ob_allocate() may change OG(ob_buffer), so we can't initialize p&start earlier */ - p = OG(ob_buffer)+OG(ob_text_length); - start = OG(ob_buffer); - - while (--p>=start) { - p[text_length] = *p; - } - memcpy(OG(ob_buffer), text, text_length); - OG(ob_buffer)[OG(ob_text_length)]=0; -} -#endif - -static inline void php_ob_send() -{ - OLS_FETCH(); - - /* header_write is a simple, unbuffered output function */ - OG(php_body_write)(OG(ob_buffer), OG(ob_text_length)); -} - - -/* Return the current output buffer */ -int php_ob_get_buffer(pval *p) -{ - OLS_FETCH(); - - if (!OG(ob_buffer)) { - return FAILURE; - } - p->type = IS_STRING; - p->value.str.val = estrndup(OG(ob_buffer), OG(ob_text_length)); - p->value.str.len = OG(ob_text_length); - return SUCCESS; -} - - -/* - * Wrapper functions - implementation - */ - - -/* buffered output function */ -static int php_b_body_write(const char *str, uint str_length) -{ - php_ob_append(str, str_length); - return str_length; -} - - -static int php_ub_body_write_no_header(const char *str, uint str_length) -{ - char *newstr = NULL; - uint new_length=0; - int result; - OLS_FETCH(); - - session_adapt_uris(str, str_length, &newstr, &new_length); - - if (newstr) { - str = newstr; - str_length = new_length; - } - - result = OG(php_header_write)(str, str_length); - - if (newstr) { - free(newstr); - } - - if (OG(implicit_flush)) { - sapi_flush(); - } - - return result; -} - - -static int php_ub_body_write(const char *str, uint str_length) -{ - int result = 0; - SLS_FETCH(); - OLS_FETCH(); - - if (SG(request_info).headers_only) { - zend_bailout(); - } - if (php_header()) { - if (zend_is_compiling()) { - CLS_FETCH(); - - OG(output_start_filename) = zend_get_compiled_filename(CLS_C); - OG(output_start_lineno) = zend_get_compiled_lineno(CLS_C); - } else if (zend_is_executing()) { - ELS_FETCH(); - - OG(output_start_filename) = zend_get_executed_filename(ELS_C); - OG(output_start_lineno) = zend_get_executed_lineno(ELS_C); - } - - OG(php_body_write) = php_ub_body_write_no_header; - result = php_ub_body_write_no_header(str, str_length); - } - - return result; -} - - -/* - * HEAD support - */ - - -/* {{{ proto void ob_start(void) - Turn on Output Buffering */ -PHP_FUNCTION(ob_start) -{ - php_start_ob_buffering(); -} -/* }}} */ - - -/* {{{ proto void ob_end_flush(void) - Flush (send) the output buffer, and turn off output buffering */ -PHP_FUNCTION(ob_end_flush) -{ - php_end_ob_buffering(1); -} -/* }}} */ - - -/* {{{ proto void ob_end_clean(void) - Clean (erase) the output buffer, and turn off output buffering */ -PHP_FUNCTION(ob_end_clean) -{ - php_end_ob_buffering(0); -} -/* }}} */ - - -/* {{{ proto string ob_get_contents(void) - Return the contents of the output buffer */ -PHP_FUNCTION(ob_get_contents) -{ - if (php_ob_get_buffer(return_value)==FAILURE) { - RETURN_FALSE; - } -} -/* }}} */ - - -/* {{{ proto void ob_implicit_flush([int flag]) - Turn implicit flush on/off and is equivalent to calling flush() after every output call */ -PHP_FUNCTION(ob_implicit_flush) -{ - zval **zv_flag; - int flag; - - switch(ZEND_NUM_ARGS()) { - case 0: - flag = 1; - break; - case 1: - if (zend_get_parameters_ex(1, &zv_flag)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(zv_flag); - flag = (*zv_flag)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - if (flag) { - php_start_implicit_flush(); - } else { - php_end_implicit_flush(); - } -} -/* }}} */ - - -PHPAPI char *php_get_output_start_filename() -{ - OLS_FETCH(); - - return OG(output_start_filename); -} - - -PHPAPI int php_get_output_start_lineno() -{ - OLS_FETCH(); - - return OG(output_start_lineno); -} - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/pack.c b/ext/standard/pack.c deleted file mode 100644 index ef3e139d11..0000000000 --- a/ext/standard/pack.c +++ /dev/null @@ -1,863 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: 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 -#include <windows.h> -#include <winsock.h> -#define O_RDONLY _O_RDONLY -#include "win32/param.h" -#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" -#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]; - - -static void php_pack(pval **val, int size, int *map, char *output) -{ - int i; - char *v; - - convert_to_long_ex(val); - v = (char *)&(*val)->value.lval; - - 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 [, ...]]) - Takes 1 or more arguments and packs them into a binary string according to the format argument */ -PHP_FUNCTION(pack) -{ - pval ***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(pval **)); - - if (zend_get_parameters_array_ex(argc, argv) == FAILURE) { - efree(argv); - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(argv[0]); - format = (*argv[0])->value.str.val; - formatlen = (*argv[0])->value.str.len; - - /* 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(E_WARNING, "pack 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(E_ERROR, "pack type %c: not enough arguments", code); - RETURN_FALSE; - } - - if (arg < 0) { - arg = (*argv[currentarg])->value.str.len; - } - - 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(E_ERROR, "pack type %c: too few arguments", code); - RETURN_FALSE; - } - break; - } - - default: { - php_error(E_ERROR, "pack type %c: unknown format code", code); - RETURN_FALSE; - } - } - - formatcodes[formatcount] = code; - formatargs[formatcount] = arg; - } - - if (currentarg < argc) { - php_error(E_WARNING, "pack %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(E_WARNING, "pack 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]; - pval **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],(*val)->value.str.val, - ((*val)->value.str.len < arg) ? (*val)->value.str.len : 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 = (*val)->value.str.val; - outputpos--; - - 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(E_WARNING, "pack 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)(*val)->value.dval; - 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)(*val)->value.dval; - 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); -} -/* }}} */ - - -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()), "[repeatt]" 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) -{ - pval **formatarg; - pval **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 = (*formatarg)->value.str.val; - formatlen = (*formatarg)->value.str.len; - input = (*inputarg)->value.str.val; - inputlen = (*inputarg)->value.str.len; - inputpos = 0; - - if (array_init(return_value) == FAILURE) - return; - - 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': case 'h': case 'H': { - size = 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)) { - len = size; - } - - size = (len + 1) / 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(float)); - 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(E_WARNING, "pack type %c: outside of string", type); - } - } - break; - } - - case '@': { - if (arg <= inputlen) { - inputpos = arg; - } else { - php_error(E_WARNING, "pack 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(E_ERROR, "pack type %c: not enough input, need %d, have %d", type, size, inputlen - inputpos); - RETURN_FALSE; - } - } - - formatlen--; /* Skip '/' separator, does no harm if inputlen == 0 */ - format++; - } -} -/* }}} */ - - -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 { - pval val; - int size = sizeof(val.value.lval); - val.value.lval=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 - * End: - */ diff --git a/ext/standard/pack.h b/ext/standard/pack.h deleted file mode 100644 index 3550c0270b..0000000000 --- a/ext/standard/pack.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _PACK_H -#define _PACK_H - -extern 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 00550645f0..0000000000 --- a/ext/standard/pageinfo.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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> | - +----------------------------------------------------------------------+ - */ -/* $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" -#else -#include <pwd.h> -#endif -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> -#ifdef PHP_WIN32 -#include <process.h> -#endif - -#include "ext/standard/basic_functions.h" - -static void php_statpage(BLS_D) -{ - struct stat *pstat; - - pstat = sapi_get_stat(); - - if (BG(page_uid)==-1) { - BG(page_uid) = pstat->st_uid; - BG(page_inode) = pstat->st_ino; - BG(page_mtime) = pstat->st_mtime; - } -} - -long php_getuid(void) -{ - BLS_FETCH(); - - php_statpage(BLS_C); - return (BG(page_uid)); -} - -/* {{{ 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 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) -{ - BLS_FETCH(); - - php_statpage(BLS_C); - if (BG(page_inode) < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(BG(page_inode)); - } -} -/* }}} */ - -/* {{{ proto int getlastmod(void) - Get time of last page modification */ -PHP_FUNCTION(getlastmod) -{ - BLS_FETCH(); - - php_statpage(BLS_C); - if (BG(page_mtime) < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(BG(page_mtime)); - } -} -/* }}} */ diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h deleted file mode 100644 index 5f230fec05..0000000000 --- a/ext/standard/pageinfo.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _PROCESS_H -#define _PROCESS_H - -PHP_FUNCTION(getmyuid); -PHP_FUNCTION(getmypid); -PHP_FUNCTION(getmyinode); -PHP_FUNCTION(getlastmod); - -extern long php_getuid(void); - -#endif diff --git a/ext/standard/parsedate.y b/ext/standard/parsedate.y deleted file mode 100644 index f0a5e80f8a..0000000000 --- a/ext/standard/parsedate.y +++ /dev/null @@ -1,907 +0,0 @@ -%{ -/* $Revision$ -** -** 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@osf.org> and Jim Berets <jberets@bbn.com> in August, 1990. -** Further revised (removed obsolete constructs and cleaned up timezone -** names) in August, 1991, by Rich. Paul Eggert <eggert@twinsun.com> -** helped in September, 1992. -** -** This grammar has six shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -*/ -/* SUPPRESS 530 *//* Empty body for statement */ -/* SUPPRESS 593 on yyerrlab *//* Label was not used */ -/* SUPPRESS 593 on yynewstate *//* Label was not used */ -/* SUPPRESS 595 on yypvt *//* Automatic variable may be used before set */ - - -#include "php.h" - -#ifdef PHP_WIN32 -#include <malloc.h> -#endif - -#ifdef HAVE_STDLIB_H -# include <stdlib.h> -#endif - -#include <stdio.h> -#include <sys/types.h> -#include <time.h> - -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif -#ifdef PHP_WIN32 -# include "win32/time.h" -#endif - -#include <ctype.h> - -#if defined(_HPUX_SOURCE) -#include <alloca.h> -#endif - -#if !defined(HAVE_TM_ZONE) && !defined(_TIMEZONE) && !defined(HAVE_DECLARED_TIMEZONE) -extern time_t timezone; -#endif - -#define yylhs date_yylhs -#define yylen date_yylen -#define yydefred date_yydefred -#define yydgoto date_yydgoto -#define yysindex date_yysindex -#define yyrindex date_yyrindex -#define yygindex date_yygindex -#define yytable date_yytable -#define yycheck date_yycheck -#define yyparse date_parse -#define yyparse date_parse -#define yylex date_lex -#define yyerror date_error - - - /* See the LeapYears table in Convert. */ -#define EPOCH 1970 -#define END_OF_TIME 2038 - /* Constants for general time calculations. */ -#define DST_OFFSET 1 -#define SECSPERDAY (24L * 60L * 60L) - /* Readability for TABLE stuff. */ -#define HOUR(x) (x * 60) - -#define LPAREN '(' -#define RPAREN ')' -#define IS7BIT(x) ((unsigned int)(x) < 0200) - -/* -** Get the number of elements in a fixed-size array, or a pointer just -** past the end of it. -*/ -#define SIZEOF(array) ((int)(sizeof array / sizeof array[0])) -#define ENDOF(array) (&array[SIZEOF(array)]) -#define CTYPE(isXXXXX, c) ((isascii((c)) && isXXXXX((c)))) - -typedef struct _TIMEINFO { - time_t time; - long usec; - long tzone; -} TIMEINFO; - -int GetTimeInfo(TIMEINFO *Now); - -typedef char const *STRING; -typedef char * const CSTRING; - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - STRING name; - int type; - time_t value; -} TABLE; - -/* -** Daylight-savings mode: on, off, or not yet known. -*/ -typedef enum _DSTMODE { - DSTon, DSToff, DSTmaybe -} DSTMODE; - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of them by using a yacc -** union, but this is more efficient. (This routine predates the -** yacc %union construct.) -*/ -static char *yyInput; -static DSTMODE yyDSTmode; -static int yyHaveDate; -static int yyHaveRel; -static int yyHaveTime; -static time_t yyTimezone; -static time_t yyDay; -static time_t yyHour; -static time_t yyMinutes; -static time_t yyMonth; -static time_t yySeconds; -static time_t yyYear; -static MERIDIAN yyMeridian; -static time_t yyRelMonth; -static time_t yyRelSeconds; - - - -static void date_error(char *s); - -%} - -%pure_parser -%expect 6 - -%union { - time_t Number; - enum _MERIDIAN Meridian; -} - -%{ -static int date_lex(YYSTYPE *yylval); -%} - -%token tDAY tDAYZONE tMERIDIAN tMONTH tMONTH_UNIT tSEC_UNIT tSNUMBER -%token tUNUMBER tZONE - -%type <Number> tDAYZONE tMONTH tMONTH_UNIT tSEC_UNIT -%type <Number> tSNUMBER tUNUMBER tZONE numzone zone -%type <Meridian> tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; -#if defined(lint) - /* I am compulsive about lint natterings... */ - if (yyHaveTime == -1) { - YYERROR; - } -#endif /* defined(lint) */ - } - | time zone { - yyHaveTime++; - yyTimezone = $2; - } - | date { - yyHaveDate++; - } - | rel { - yyHaveRel = 1; - } - ; - -time : tUNUMBER o_merid { - if ($1 < 100) { - yyHour = $1; - yyMinutes = 0; - } - else { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER numzone { - yyHour = $1; - yyMinutes = $3; - yyTimezone = $4; - yyMeridian = MER24; - yyDSTmode = DSToff; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER numzone { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyTimezone = $6; - yyMeridian = MER24; - yyDSTmode = DSToff; - } - ; - -zone : tZONE { - $$ = $1; - yyDSTmode = DSToff; - } - | tDAYZONE { - $$ = $1; - yyDSTmode = DSTon; - } - | tZONE numzone { - /* Only allow "GMT+300" and "GMT-0800" */ - if ($1 != 0) { - YYABORT; - } - $$ = $2; - yyDSTmode = DSToff; - } - | numzone { - $$ = $1; - yyDSTmode = DSToff; - } - ; - -numzone : tSNUMBER { - int i; - - /* Unix and GMT and numeric timezones -- a little confusing. */ - if ($1 < 0) { - /* Don't work with negative modulus. */ - $1 = -$1; - if ($1 > 9999 || (i = $1 % 100) >= 60) { - YYABORT; - } - $$ = ($1 / 100) * 60 + i; - } - else { - if ($1 > 9999 || (i = $1 % 100) >= 60) { - YYABORT; - } - $$ = -(($1 / 100) * 60 + i); - } - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - if ($1 > 100) { - /* assume YYYY/MM/DD format, so need not to add 1900 */ - yyYear = $1; - yyMonth = $3; - yyDay = $5; - } - else { - /* assume MM/DD/YY* format */ - yyMonth = $1; - yyDay = $3; - if ($5 > 100) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $5; - } else { - /* assume year is YY format, so need to add 1900 */ - yyYear = $5 + 1900; - } - } - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - if ($4 > 100) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $4; - } else { - /* assume year is YY format, so need to add 1900 */ - yyYear = $4 + 1900; - } - } - | tUNUMBER tMONTH { - yyDay = $1; - yyMonth = $2; - } - | tUNUMBER tMONTH tUNUMBER { - yyDay = $1; - yyMonth = $2; - if ($3 > 100) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $3; - } else { - /* assume year is YY format, so need to add 1900 */ - yyYear = $3 + 1900; - } - } - | tDAY ',' tUNUMBER tMONTH tUNUMBER { - yyDay = $3; - yyMonth = $4; - if ($5 > 100) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $5; - } else { - /* assume year is YY format, so need to add 1900 */ - yyYear = $5 + 1900; - } - } - ; - -rel : tSNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - ; - -o_merid : /* NULL */ { - $$ = MER24; - } - | tMERIDIAN { - $$ = $1; - } - ; - -%% - -/* Month and day table. */ -static TABLE 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 }, - { "october", tMONTH, 10 }, - { "november", tMONTH, 11 }, - { "december", tMONTH, 12 }, - /* The value of the day isn't used... */ - { "sunday", tDAY, 0 }, - { "monday", tDAY, 0 }, - { "tuesday", tDAY, 0 }, - { "wednesday", tDAY, 0 }, - { "thursday", tDAY, 0 }, - { "friday", tDAY, 0 }, - { "saturday", tDAY, 0 }, -}; - -/* Time units table. */ -static TABLE UnitsTable[] = { - { "year", tMONTH_UNIT, 12 }, - { "month", tMONTH_UNIT, 1 }, - { "week", tSEC_UNIT, 7 * 24 * 60 * 60 }, - { "day", tSEC_UNIT, 1 * 24 * 60 * 60 }, - { "hour", tSEC_UNIT, 60 * 60 }, - { "minute", tSEC_UNIT, 60 }, - { "min", tSEC_UNIT, 60 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, -}; - -/* Timezone table. */ -static TABLE TimezoneTable[] = { - { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR( 0) }, /* Universal */ - { "utc", tZONE, HOUR( 0) }, /* Universal Coordinated */ - { "cut", tZONE, HOUR( 0) }, /* Coordinated Universal */ - { "z", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "wet", tZONE, HOUR( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ - { "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */ - { "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 */ - { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */ - { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */ - { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ - { "hast", tZONE, HOUR(10) }, /* Hawaii-Aleutian Standard */ - { "hadt", tDAYZONE, HOUR(10) }, /* Hawaii-Aleutian Daylight */ - { "ces", tDAYZONE, -HOUR(1) }, /* Central European Summer */ - { "cest", tDAYZONE, -HOUR(1) }, /* Central European Summer */ - { "mez", tZONE, -HOUR(1) }, /* Middle European */ - { "mezt", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "cet", tZONE, -HOUR(1) }, /* Central European */ - { "met", tZONE, -HOUR(1) }, /* Middle European */ - { "eet", tZONE, -HOUR(2) }, /* Eastern Europe */ - { "msk", tZONE, -HOUR(3) }, /* Moscow Winter */ - { "msd", tDAYZONE, -HOUR(3) }, /* Moscow Summer */ - { "wast", tZONE, -HOUR(8) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR(8) }, /* West Australian Daylight */ - { "hkt", tZONE, -HOUR(8) }, /* Hong Kong */ - { "cct", tZONE, -HOUR(8) }, /* China Coast */ - { "jst", tZONE, -HOUR(9) }, /* Japan Standard */ - { "kst", tZONE, -HOUR(9) }, /* Korean Standard */ - { "kdt", tZONE, -HOUR(9) }, /* Korean Daylight */ - { "cast", tZONE, -(HOUR(9)+30) }, /* Central Australian Standard */ - { "cadt", tDAYZONE, -(HOUR(9)+30) }, /* Central Australian Daylight */ - { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ - { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ - - /* For completeness we include the following entries. */ -#if 0 - - /* Duplicate names. Either they conflict with a zone listed above - * (which is either more likely to be seen or just been in circulation - * longer), or they conflict with another zone in this section and - * we could not reasonably choose one over the other. */ - { "fst", tZONE, HOUR( 2) }, /* Fernando De Noronha Standard */ - { "fdt", tDAYZONE, HOUR( 2) }, /* Fernando De Noronha Daylight */ - { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ - { "est", tZONE, HOUR( 3) }, /* Eastern Standard (Brazil) */ - { "edt", tDAYZONE, HOUR( 3) }, /* Eastern Daylight (Brazil) */ - { "wst", tZONE, HOUR( 4) }, /* Western Standard (Brazil) */ - { "wdt", tDAYZONE, HOUR( 4) }, /* Western Daylight (Brazil) */ - { "cst", tZONE, HOUR( 5) }, /* Chile Standard */ - { "cdt", tDAYZONE, HOUR( 5) }, /* Chile Daylight */ - { "ast", tZONE, HOUR( 5) }, /* Acre Standard */ - { "adt", tDAYZONE, HOUR( 5) }, /* Acre Daylight */ - { "cst", tZONE, HOUR( 5) }, /* Cuba Standard */ - { "cdt", tDAYZONE, HOUR( 5) }, /* Cuba Daylight */ - { "est", tZONE, HOUR( 6) }, /* Easter Island Standard */ - { "edt", tDAYZONE, HOUR( 6) }, /* Easter Island Daylight */ - { "sst", tZONE, HOUR(11) }, /* Samoa Standard */ - { "ist", tZONE, -HOUR(2) }, /* Israel Standard */ - { "idt", tDAYZONE, -HOUR(2) }, /* Israel Daylight */ - { "idt", tDAYZONE, -(HOUR(3)+30) }, /* Iran Daylight */ - { "ist", tZONE, -(HOUR(3)+30) }, /* Iran Standard */ - { "cst", tZONE, -HOUR(8) }, /* China Standard */ - { "cdt", tDAYZONE, -HOUR(8) }, /* China Daylight */ - { "sst", tZONE, -HOUR(8) }, /* Singapore Standard */ - - /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */ - { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ - { "wat", tZONE, -HOUR(1) }, /* West Africa */ - { "at", tZONE, HOUR( 2) }, /* Azores */ - { "gst", tZONE, -HOUR(10) }, /* Guam Standard */ - { "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */ - { "idlw", tZONE, HOUR(12) }, /* International Date Line West */ - { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */ - { "mest", 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 */ - { "bt", tZONE, -HOUR(3) }, /* Baghdad */ - { "it", tZONE, -(HOUR(3)+30) }, /* Iran */ - { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */ - { "ist", tZONE, -(HOUR(5)+30) }, /* Indian Standard */ - { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */ - { "nst", tZONE, -HOUR(7) }, /* North Sumatra */ - { "sst", tZONE, -HOUR(7) }, /* South Sumatra */ - { "jt", tZONE, -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */ - { "nzt", tZONE, -HOUR(12) }, /* New Zealand */ - { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { "cat", tZONE, HOUR(10) }, /* -- expired 1967 */ - { "nt", tZONE, HOUR(11) }, /* -- expired 1967 */ - { "ahst", tZONE, HOUR(10) }, /* -- expired 1983 */ - { "hdt", tDAYZONE, HOUR(10) }, /* -- expired 1986 */ -#endif /* 0 */ -}; - - - -/* ARGSUSED */ -static void -date_error(char *s) -{ - /* NOTREACHED */ -} - -int GetTimeInfo(TIMEINFO *Now) -{ - static time_t NextHour; - static long LastTzone; - struct tm *tm, tmbuf; - int secondsUntilNextHour; -#if defined(HAVE_GETTIMEOFDAY) - struct timeval tv; -#endif /* defined(HAVE_GETTIMEOFDAY) */ -#if !defined(HAVE_TM_GMTOFF) - struct tm local; - struct tm gmt; -#endif /* !defined(HAVE_TM_GMTOFF) */ - - /* Get the basic time. */ -#if defined(HAVE_GETTIMEOFDAY) - if (gettimeofday(&tv, (struct timezone *)NULL) == -1) - return -1; - Now->time = tv.tv_sec; - Now->usec = tv.tv_usec; -#else - /* Can't check for -1 since that might be a time, I guess. */ - (void)time(&Now->time); - Now->usec = 0; -#endif /* defined(HAVE_GETTIMEOFDAY) */ - - /* Now get the timezone if the last time < HH:00:00 <= now for some HH. */ - if (NextHour <= Now->time) { - if ((tm = php_localtime_r(&Now->time, &tmbuf)) == NULL) - return -1; - secondsUntilNextHour = 60 * (60 - tm->tm_min) - tm->tm_sec; -#if !defined(HAVE_TM_GMTOFF) - /* To get the timezone, compare localtime with GMT. */ - local = *tm; - if ((tm = php_gmtime_r(&Now->time, &tmbuf)) == NULL) - return -1; - gmt = *tm; - - /* Assume we are never more than 24 hours away. */ - LastTzone = gmt.tm_yday - local.tm_yday; - if (LastTzone > 1) - LastTzone = -24; - else if (LastTzone < -1) - LastTzone = 24; - else - LastTzone *= 24; - - /* Scale in the hours and minutes; ignore seconds. */ - LastTzone += gmt.tm_hour - local.tm_hour; - LastTzone *= 60; - LastTzone += gmt.tm_min - local.tm_min; -#else - LastTzone = (0 - tm->tm_gmtoff) / 60; -#endif /* defined(HAVE_TM_GMTOFF) */ - NextHour = Now->time + secondsUntilNextHour; - } - Now->tzone = LastTzone; - return 0; -} - - -static time_t -ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) -{ - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61) - return -1; - if (Meridian == MER24) { - if (Hours < 0 || Hours > 23) - return -1; - } - else { - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - if (Meridian == MERpm) - Hours += 12; - } - return (Hours * 60L + Minutes) * 60L + Seconds; -} - - -static time_t -Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian, DSTMODE dst) -{ - static int DaysNormal[13] = { - 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - static int DaysLeap[13] = { - 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - static int LeapYears[] = { - 1972, 1976, 1980, 1984, 1988, 1992, 1996, - 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 - }; - int *yp; - int *mp; - time_t Julian; - int i; - time_t tod; - struct tm tmbuf; - - /* Year should not be passed as a relative value, but absolute one. - so this should not happen, but just ensure it */ - if (Year < 0) - Year = -Year; - if (Year < 100) - Year += 1900; - if (Year < EPOCH) - Year += 100; - for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++) - if (Year == *yp) { - mp = DaysLeap; - break; - } - if (Year < EPOCH || Year > END_OF_TIME - || Month < 1 || Month > 12 - /* NOSTRICT *//* conversion from long may lose accuracy */ - || Day < 1 || Day > mp[(int)Month]) - return -1; - - Julian = Day - 1 + (Year - EPOCH) * 365; - for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++) - if (Year <= *yp) - break; - for (i = 1; i < Month; i++) - Julian += *++mp; - Julian *= SECSPERDAY; - Julian += yyTimezone * 60L; - if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) - return -1; - Julian += tod; - tod = Julian; - if (dst == DSTon || (dst == DSTmaybe && php_localtime_r(&tod,&tmbuf)->tm_isdst)) - Julian -= DST_OFFSET * 60 * 60; - return Julian; -} - - -static time_t -DSTcorrect(time_t Start, time_t Future) -{ - time_t StartDay; - time_t FutureDay; - struct tm tmbuf; - - StartDay = (php_localtime_r(&Start,&tmbuf)->tm_hour + 1) % 24; - FutureDay = (php_localtime_r(&Future,&tmbuf)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60 * 60; -} - - -static time_t -RelativeMonth(time_t Start, time_t RelMonth) -{ - struct tm *tm, tmbuf; - time_t Month; - time_t Year; - - tm = php_localtime_r(&Start, &tmbuf); - Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; - Year = Month / 12; - Year += 1900; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - MER24, DSTmaybe)); -} - - -static int LookupWord(char *buff, int length, YYSTYPE *yylval) -{ - char *p; - STRING q; - TABLE *tp; - int c; - - p = buff; - c = p[0]; - - /* See if we have an abbreviation for a month. */ - if (length == 3 || (length == 4 && p[3] == '.')) - for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) { - q = tp->name; - if (c == q[0] && p[1] == q[1] && p[2] == q[2]) { - yylval->Number = tp->value; - return tp->type; - } - } - else - for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - yylval->Number = tp->value; - return tp->type; - } - - /* Try for a timezone. */ - for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++) - if (c == tp->name[0] && p[1] == tp->name[1] - && strcmp(p, tp->name) == 0) { - yylval->Number = tp->value; - return tp->type; - } - - /* Try the units table. */ - for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - yylval->Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - if (--length > 0 && p[length] == 's') { - p[length] = '\0'; - for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - p[length] = 's'; - yylval->Number = tp->value; - return tp->type; - } - p[length] = 's'; - } - length++; - - /* Drop out any periods. */ - for (p = buff, q = (STRING)buff; *q; q++) - if (*q != '.') - *p++ = *q; - *p = '\0'; - - /* Try the meridians. */ - if (buff[1] == 'm' && buff[2] == '\0') { - if (buff[0] == 'a') { - yylval->Meridian = MERam; - return tMERIDIAN; - } - if (buff[0] == 'p') { - yylval->Meridian = MERpm; - return tMERIDIAN; - } - } - - /* If we saw any periods, try the timezones again. */ - if (p - buff != length) { - c = buff[0]; - for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++) - if (c == tp->name[0] && p[1] == tp->name[1] - && strcmp(p, tp->name) == 0) { - yylval->Number = tp->value; - return tp->type; - } - } - - /* Unknown word -- assume GMT timezone. */ - yylval->Number = 0; - return tZONE; -} - - -static int date_lex(YYSTYPE *yylval) -{ - char c; - char *p; - char buff[20]; - int sign; - int i; - int nesting; - - for ( ; ; ) { - /* Get first character after the whitespace. */ - for ( ; ; ) { - while (CTYPE(isspace, (int)*yyInput)) - yyInput++; - c = *yyInput; - - /* Ignore RFC 822 comments, typically time zone names. */ - if (c != LPAREN) - break; - for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; ) - if (c == LPAREN) - nesting++; - else if (!IS7BIT(c) || c == '\0' || c == '\r' - || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c)))) - /* Lexical error: bad comment. */ - return '?'; - yyInput++; - } - - /* A number? */ - if (CTYPE(isdigit, (int)c) || c == '-' || c == '+') { - if (c == '-' || c == '+') { - sign = c == '-' ? -1 : 1; - yyInput++; - if (!CTYPE(isdigit, (int)*yyInput)) - /* Skip the plus or minus sign. */ - continue; - } - else - sign = 0; - for (i = 0; (c = *yyInput++) != '\0' && CTYPE(isdigit, (int)c); ) - i = 10 * i + c - '0'; - yyInput--; - yylval->Number = sign < 0 ? -i : i; - return sign ? tSNUMBER : tUNUMBER; - } - - /* A word? */ - if (CTYPE(isalpha, (int)c)) { - for (p = buff; (c = *yyInput++) == '.' || CTYPE(isalpha, (int)c); ) - if (p < &buff[sizeof buff - 1]) - *p++ = CTYPE(isupper, (int)c) ? tolower(c) : c; - *p = '\0'; - yyInput--; - return LookupWord(buff, p - buff, yylval); - } - - return *yyInput++; - } -} - - -time_t parsedate(char *p, TIMEINFO *now) -{ - struct tm *tm, tmbuf; - TIMEINFO ti; - time_t Start; - - yyInput = p; - if (now == NULL) { - now = &ti; - (void)GetTimeInfo(&ti); - } - - tm = php_localtime_r(&now->time, &tmbuf); - yyYear = tm->tm_year + 1900; - yyMonth = tm->tm_mon + 1; - yyDay = tm->tm_mday; -#ifdef HAVE_TM_GMTOFF - yyTimezone = tm->tm_gmtoff/60; -#else - yyTimezone = timezone/60; -#endif - yyDSTmode = DSTmaybe; - yyHour = 0; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMonth = 0; - yyHaveDate = 0; - yyHaveRel = 0; - yyHaveTime = 0; - - if (date_parse(YYPARSE_PARAM_ARG) || yyHaveTime > 1 || yyHaveDate > 1) - return -1; - - if (yyHaveDate || yyHaveTime) { - Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, - yyMeridian, yyDSTmode); - if (Start < 0) - return -1; - } - else { - Start = now->time; - if (!yyHaveRel) - Start -= (tm->tm_hour * 60L + tm->tm_min) * 60L + tm->tm_sec; - } - - Start += yyRelSeconds; - if (yyRelMonth) - Start += RelativeMonth(Start, yyRelMonth); - - /* Have to do *something* with a legitimate -1 so it's distinguishable - * from the error return value. (Alternately could set errno on error.) */ - return Start == -1 ? 0 : Start; -} diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h deleted file mode 100644 index 38b3174c24..0000000000 --- a/ext/standard/php_array.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@ispi.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(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(extract); -PHP_FUNCTION(compact); -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_pad); -PHP_FUNCTION(array_flip); -PHP_FUNCTION(array_rand); - -HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **); -int multisort_compare(const void *a, const void *b); - -typedef struct { - int *multisort_flags; - int (*compare_func)(zval *result, zval *op1, zval *op2); -} php_array_globals; - -#ifdef ZTS -#define ARRAYLS_D php_array_globals *array_globals -#define ARRAYLS_DC , ARRAYLS_D -#define ARRAYLS_C array_globals -#define ARRAYLS_CC , ARRAYLS_C -#define ARRAYG(v) (array_globals->v) -#define ARRAYLS_FETCH() php_array_globals *array_globals = ts_resource(array_globals_id) -extern int array_globals_id; -#else -#define ARRAYLS_D -#define ARRAYLS_DC -#define ARRAYLS_C -#define ARRAYLS_CC -#define ARRAYG(v) (array_globals.v) -#define ARRAYLS_FETCH() -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 7d0c8ddf67..0000000000 --- a/ext/standard/php_assert.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $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 04eb072582..0000000000 --- a/ext/standard/php_browscap.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - - -#ifndef _PHP_BROWSCAP_H -#define _PHP_BROWSCAP_H - -extern PHP_MINIT_FUNCTION(browscap); -extern 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 036ade2abe..0000000000 --- a/ext/standard/php_crypt.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_CRYPT_H -#define PHP_CRYPT_H - -PHP_FUNCTION(crypt); -#if HAVE_CRYPT -extern PHP_MINIT_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 5d636edc1e..0000000000 --- a/ext/standard/php_dir.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _PHP_DIR_H -#define _PHP_DIR_H - -/* directory functions */ -extern PHP_MINIT_FUNCTION(dir); -PHP_FUNCTION(opendir); -PHP_FUNCTION(closedir); -PHP_FUNCTION(chdir); -PHP_FUNCTION(getcwd); -PHP_FUNCTION(rewinddir); -PHP_FUNCTION(readdir); -PHP_FUNCTION(getdir); - -#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 bf905fb5fc..0000000000 --- a/ext/standard/php_ext_syslog.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Stig Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -#ifndef _PHP_EXT_SYSLOG_H -#define _PHP_EXT_SYSLOG_H - -#ifdef HAVE_SYSLOG_H - -#include "php_syslog.h" - -extern PHP_MINIT_FUNCTION(syslog); -extern PHP_RINIT_FUNCTION(syslog); -extern 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 580351f0b1..0000000000 --- a/ext/standard/php_filestat.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Author: Jim Winstead <jimw@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _FILESTAT_H -#define _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_FUNCTION(stat); -PHP_FUNCTION(lstat); -PHP_FUNCTION(diskfreespace); -PHP_FUNCTION(chown); -PHP_FUNCTION(chgrp); -PHP_FUNCTION(chmod); -PHP_FUNCTION(touch); -PHP_FUNCTION(clearstatcache); - -#endif /* _FILESTAT_H */ diff --git a/ext/standard/php_global.h b/ext/standard/php_global.h deleted file mode 100644 index 9b03e21b82..0000000000 --- a/ext/standard/php_global.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -/* GLOBAL.H - RSAREF types and constants - */ - -/* PROTOTYPES should be set to one if and only if the compiler supports - function argument prototyping. - The following makes PROTOTYPES default to 0 if it has not already - been defined with C compiler flags. - */ -#ifndef PROTOTYPES -#define PROTOTYPES 1 /* PHP has prototypes everywhere */ -#endif - -/* _POINTER defines a generic pointer type */ -typedef unsigned char *_POINTER; - -/* UINT2 defines a two byte word */ -typedef unsigned short int UINT2; - -/* UINT4 defines a four byte word */ -#if SIZEOF_INT == 4 -typedef unsigned int UINT4; -#elif SIZEOF_LONG == 4 -typedef unsigned long UINT4; -#endif - -/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. - If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it - returns an empty list. - */ -#if PROTOTYPES -#define PROTO_LIST(list) list -#else -#define PROTO_LIST(list) () -#endif diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h deleted file mode 100644 index d2fb431c0e..0000000000 --- a/ext/standard/php_image.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -#ifndef _IMAGE_H -#define _IMAGE_H - -PHP_FUNCTION(getimagesize); - -#endif /* _IMAGE_H */ diff --git a/ext/standard/php_iptc.h b/ext/standard/php_iptc.h deleted file mode 100644 index 2abc43dae1..0000000000 --- a/ext/standard/php_iptc.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Thies C. Arntzen <thies@digicol.de> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _PHPIPTC_H -#define _PHPIPTC_H - -PHP_FUNCTION(iptcparse); -PHP_FUNCTION(iptcembed); - -#endif /* _PHPIPTC_H */ diff --git a/ext/standard/php_lcg.h b/ext/standard/php_lcg.h deleted file mode 100644 index 99c8e33f6f..0000000000 --- a/ext/standard/php_lcg.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Sascha Schumann <ss@2ns.de> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_LCG_H -#define PHP_LCG_H - -typedef struct { - long s1; - long s2; -} php_lcg_globals; - -double php_combined_lcg(void); -PHP_FUNCTION(lcg_value); -PHP_MINIT_FUNCTION(lcg); - -#ifdef ZTS -#define LCGLS_D php_lcg_globals *lcg_globals -#define LCG(v) (lcg_globals->v) -#define LCGLS_FETCH() php_lcg_globals *lcg_globals = ts_resource(lcg_globals_id) -#else -#define LCGLS_D void -#define LCG(v) (lcg_globals.v) -#define LCGLS_FETCH() -#endif - -#endif diff --git a/ext/standard/php_link.h b/ext/standard/php_link.h deleted file mode 100644 index e3c1116f25..0000000000 --- a/ext/standard/php_link.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: | - | | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ -#ifndef _PHP_LINK_H -#define _PHP_LINK_H - -PHP_FUNCTION(link); -PHP_FUNCTION(unlink); -PHP_FUNCTION(readlink); -PHP_FUNCTION(linkinfo); -PHP_FUNCTION(symlink); - -#endif /* _PHP_LINK_H */ diff --git a/ext/standard/php_mail.h b/ext/standard/php_mail.h deleted file mode 100644 index e897c6c83e..0000000000 --- a/ext/standard/php_mail.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _MAIL_H -#define _MAIL_H - -#if HAVE_SENDMAIL - -PHP_FUNCTION(mail); -PHP_MINFO_FUNCTION(mail); -extern int php_mail(char *to, char *subject, char *message, char *headers); - -#endif - -#endif /* _MAIL_H */ diff --git a/ext/standard/php_metaphone.h b/ext/standard/php_metaphone.h deleted file mode 100644 index a8ccf98ba4..0000000000 --- a/ext/standard/php_metaphone.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Thies C. Arntzen <thies@digicol.de> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _php_metaphone_h -#define _php_metaphone_h - -PHP_FUNCTION(metaphone); - -#endif diff --git a/ext/standard/php_output.h b/ext/standard/php_output.h deleted file mode 100644 index 957116ca41..0000000000 --- a/ext/standard/php_output.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _OUTPUT_BUFFER -#define _OUTPUT_BUFFER - -#include "php.h" - -PHPAPI void php_output_startup(void); -PHPAPI int php_body_write(const char *str, uint str_length); -PHPAPI int php_header_write(const char *str, uint str_length); -PHPAPI void php_start_ob_buffering(void); -PHPAPI void php_end_ob_buffering(int send_buffer); -PHPAPI int php_ob_get_buffer(pval *p); -PHPAPI void php_start_implicit_flush(void); -PHPAPI void php_end_implicit_flush(void); -PHPAPI char *php_get_output_start_filename(void); -PHPAPI int php_get_output_start_lineno(void); - -PHP_FUNCTION(ob_start); -PHP_FUNCTION(ob_end_flush); -PHP_FUNCTION(ob_end_clean); -PHP_FUNCTION(ob_get_contents); -PHP_FUNCTION(ob_implicit_flush); - -PHP_GINIT_FUNCTION(output); - -#endif /* _OUTPUT_BUFFER */ diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h deleted file mode 100644 index e6c50f1745..0000000000 --- a/ext/standard/php_rand.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - | Pedro Melo <melo@ip.pt> | - | | - | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef _PHP_RAND_H -#define _PHP_RAND_H - -#include <stdlib.h> - -#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 - -#endif /* _PHP_RAND_H */ diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h deleted file mode 100644 index f87cccf9d5..0000000000 --- a/ext/standard/php_standard.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: | - | | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "basic_functions.h" -#include "phpmath.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 "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 "type.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" - -#define phpext_standard_ptr basic_functions_module_ptr - -/* - * 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 983d098ca3..0000000000 --- a/ext/standard/php_string.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-1999 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Sæther Bakken <ssb@guardian.no> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ - -#ifndef _PHPSTRING_H -#define _PHPSTRING_H - -PHP_FUNCTION(strspn); -PHP_FUNCTION(strcspn); -PHP_FUNCTION(str_replace); -PHP_FUNCTION(chop); -PHP_FUNCTION(trim); -PHP_FUNCTION(ltrim); -PHP_FUNCTION(soundex); -PHP_FUNCTION(levenshtein); - -PHP_FUNCTION(count_chars); -PHP_FUNCTION(explode); -PHP_FUNCTION(implode); -PHP_FUNCTION(strtok); -PHP_FUNCTION(strtoupper); -PHP_FUNCTION(strtolower); -PHP_FUNCTION(basename); -PHP_FUNCTION(dirname); -PHP_FUNCTION(strstr); -PHP_FUNCTION(strpos); -PHP_FUNCTION(strrpos); -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(addcslashes); -PHP_FUNCTION(addslashes); -PHP_FUNCTION(stripcslashes); -PHP_FUNCTION(stripslashes); -PHP_FUNCTION(chr); -PHP_FUNCTION(ord); -PHP_FUNCTION(nl2br); -PHP_FUNCTION(setlocale); -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); - -#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); - -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); -PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int freeit, char *what, int wlength); -PHPAPI void php_stripslashes(char *str, int *len); -PHPAPI void php_stripcslashes(char *str, int *len); -PHPAPI char *php_basename(char *str, size_t len); -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(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len, int *_new_length); -PHPAPI void php_trim(pval *str, pval *return_value, int mode); -PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len); - -PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result); - -PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value); -PHPAPI void php_explode(pval *delim, pval *str, pval *return_value, int limit); -PHPAPI inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end); -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 - -#endif /* _PHPSTRING_H */ diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h deleted file mode 100644 index 850baac254..0000000000 --- a/ext/standard/php_var.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Jani Lehtimäki <jkl@njet.net> | - +----------------------------------------------------------------------+ - */ - - -#ifndef _PHPVAR_H -#define _PHPVAR_H - -PHP_FUNCTION(var_dump); -PHP_FUNCTION(serialize); -PHP_FUNCTION(unserialize); - -void php_var_dump(pval **struc, int level); -void php_var_serialize(pval *buf, pval **struc); -int php_var_unserialize(pval **rval, const char **p, const char *max); - -#endif /* _PHPVAR_H */ diff --git a/ext/standard/phpdir.h b/ext/standard/phpdir.h deleted file mode 100644 index 7d7bc985cb..0000000000 --- a/ext/standard/phpdir.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _PHPDIR_H -#define _PHPDIR_H - -/* directory functions */ -PHP_FUNCTION(opendir); -PHP_FUNCTION(closedir); -PHP_FUNCTION(chdir); -PHP_FUNCTION(rewinddir); -PHP_FUNCTION(readdir); -PHP_FUNCTION(getdir); - -#endif /* _PHPDIR_H */ diff --git a/ext/standard/phpmath.h b/ext/standard/phpmath.h deleted file mode 100644 index 77ee5363df..0000000000 --- a/ext/standard/phpmath.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Jim Winstead (jimw@php.net) | - | Stig Sæther Bakken <ssb@guardian.no> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _PHPMATH_H -#define _PHPMATH_H -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(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(deg2rad); -PHP_FUNCTION(rad2deg); - - -#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_2_SQRTPI -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#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 - -#endif /* _PHPMATH_H */ diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c deleted file mode 100644 index 9b916edcca..0000000000 --- a/ext/standard/quot_print.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: 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 "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 - { - return -1; - } -} - -/* -* -* 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; - int i = 0, j = 0; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1,&arg1)==FAILURE) - { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - - str = (*arg1)->value.str.val; - while ( str[i] ) - { - if ( (str[i] == '=') && str[i+1] && str[i+2] && - ( isdigit((int)str[i+1]) || (str[i+1]<='F' && str[i+1]>='A')) - && - ( isdigit((int)str[i+2]) || (str[i+2]<='F' && str[i+2]>='A')) - ) - { - str[j++] = (php_hex2int((int)str[i+1]) << 4 ) - + php_hex2int((int)str[i+2]); - i += 3; - } - else if ( str[i] == 13 ) - { - i++; - } - else - { - str[j++] = str[i++]; - } - } - str[j] = '\0'; - - RETVAL_STRINGL(str, j, 1) -} -/* }}} */ diff --git a/ext/standard/quot_print.h b/ext/standard/quot_print.h deleted file mode 100644 index c8a826a6f5..0000000000 --- a/ext/standard/quot_print.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Kirill Maximov (kir@rus.net) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _QUOT_PRINT_H -#define _QUOT_PRINT_H - -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 a1b490f3af..0000000000 --- a/ext/standard/rand.c +++ /dev/null @@ -1,368 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - | Pedro Melo <melo@ip.pt> | - | | - | Based on code from: Shawn Cokus <Cokus@math.washington.edu> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdlib.h> - -#include "php.h" -#include "phpmath.h" -#include "php_rand.h" - -#include "basic_functions.h" - -/* - 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 */ - -#define MT_RAND_MAX ((long)(0x7FFFFFFF)) /* (1<<31) - 1 */ - -static void seedMT(php_uint32 seed BLS_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); -} - - -static php_uint32 reloadMT(BLS_D) -{ - register php_uint32 *p0=BG(state), *p2=BG(state)+2, *pM=BG(state)+M, s0, s1; - register int j; - - if(BG(left) < -1) - seedMT(4357U BLS_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)); -} - - -static inline php_uint32 randomMT(void) -{ - php_uint32 y; - BLS_FETCH(); - - if(--BG(left) < 0) - return(reloadMT(BLS_C)); - - y = *BG(next)++; - y ^= (y >> 11); - y ^= (y << 7) & 0x9D2C5680U; - y ^= (y << 15) & 0xEFC60000U; - return(y ^ (y >> 18)); -} - -/* {{{ proto void srand(int seed) - Seeds random number generator */ -PHP_FUNCTION(srand) -{ - pval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg); -#ifdef HAVE_SRAND48 - srand48((unsigned int) (*arg)->value.lval); -#else -#ifdef HAVE_SRANDOM - srandom((unsigned int) (*arg)->value.lval); -#else - srand((unsigned int) (*arg)->value.lval); -#endif -#endif -} -/* }}} */ - -/* {{{ proto void mt_srand(int seed) - Seeds Mersenne Twister random number generator */ -PHP_FUNCTION(mt_srand) -{ - pval **arg; - BLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg); - seedMT((*arg)->value.lval BLS_CC); -} -/* }}} */ - -/* {{{ proto int rand([int min, int max]) - Returns a random number */ -PHP_FUNCTION(rand) -{ - pval **p_min=NULL, **p_max=NULL; - - switch (ZEND_NUM_ARGS()) { - case 0: - break; - case 2: - if (zend_get_parameters_ex(2, &p_min, &p_max)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(p_min); - convert_to_long_ex(p_max); - if ((*p_max)->value.lval-(*p_min)->value.lval <= 0) { - php_error(E_WARNING,"rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval); - }else if ((*p_max)->value.lval-(*p_min)->value.lval > RAND_MAX){ - php3_error(E_WARNING,"rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - - return_value->type = IS_LONG; -#ifdef HAVE_LRAND48 - return_value->value.lval = lrand48(); -#else -#ifdef HAVE_RANDOM - return_value->value.lval = random(); -#else - return_value->value.lval = rand(); -#endif -#endif - /* - * 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 - */ - if (p_min && p_max) { /* implement range */ - return_value->value.lval = (*p_min)->value.lval + - (int)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1.0) * return_value->value.lval/(PHP_RAND_MAX+1.0)); - } -} -/* }}} */ - -/* {{{ proto int mt_rand([int min, int max]) - Returns a random number from Mersenne Twister */ -PHP_FUNCTION(mt_rand) -{ - pval **p_min=NULL, **p_max=NULL; - - switch (ZEND_NUM_ARGS()) { - case 0: - break; - case 2: - if (zend_get_parameters_ex(2, &p_min, &p_max)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(p_min); - convert_to_long_ex(p_max); - if ((*p_max)->value.lval-(*p_min)->value.lval <= 0) { - php_error(E_WARNING,"mt_rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval); - }else if ((*p_max)->value.lval-(*p_min)->value.lval > MT_RAND_MAX){ - php3_error(E_WARNING,"mt_rand(): Invalid range: %ld..%ld",(*p_min)->value.lval, (*p_max)->value.lval); - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - - return_value->type = IS_LONG; - /* - * 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 - */ - return_value->value.lval = (long)(randomMT() >> 1); - - if (p_min && p_max) { /* implement range */ - return_value->value.lval = (*p_min)->value.lval + - (long)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1.0) * return_value->value.lval/(MT_RAND_MAX+1.0)); - } -} -/* }}} */ - -/* {{{ proto int getrandmax(void) - Returns the maximum value a random number can have */ -PHP_FUNCTION(getrandmax) -{ - return_value->type = IS_LONG; - return_value->value.lval = PHP_RAND_MAX; -} -/* }}} */ - - -/* {{{ proto int mt_getrandmax(void) - Returns the maximum value a random number from Mersenne Twister can have */ -PHP_FUNCTION(mt_getrandmax) -{ - return_value->type = IS_LONG; - /* - * Melo: it could be 2^^32 but we only use 2^^31 to maintain - * compatibility with the previous php_rand - */ - return_value->value.lval = MT_RAND_MAX; /* 2^^31 */ -} -/* }}} */ -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/reg.c b/ext/standard/reg.c deleted file mode 100644 index 3f8f28be04..0000000000 --- a/ext/standard/reg.c +++ /dev/null @@ -1,637 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@lerdorf.on.ca> | - | Jim Winstead <jimw@php.net> | - | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include "php_string.h" -#include "reg.h" -#include "ext/standard/info.h" - -#if 0 -zend_module_entry regexp_module_entry = { - "Regular Expressions", - reg_functions, - PHP_MINIT(regex), PHP_MSHUTDOWN(regex), - NULL, NULL, PHP_MINFO(regex), - STANDARD_MODULE_PROPERTIES -}; -#endif - -#ifdef ZTS -int reg_globals_id; -#else -static php_reg_globals reg_globals; -#endif - -typedef struct { - regex_t preg; - int cflags; -} reg_cache; - -static int _php_regcomp(regex_t *preg, const char *pattern, int cflags) -{ - int r = 0; - int patlen = strlen(pattern); - reg_cache *rc = NULL; - REGLS_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(php_reg_globals *reg_globals) -{ - zend_hash_init(®_globals->ht_rc, 0, NULL, (void (*)(void *)) _free_reg_cache, 1); -} - -PHP_MINIT_FUNCTION(regex) -{ -#ifdef ZTS - reg_globals_id = ts_allocate_id(sizeof(php_reg_globals), (ts_allocate_ctor) php_reg_init_globals, NULL); -#else - php_reg_init_globals(®_globals); -#endif - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(regex) -{ - REGLS_FETCH(); - - zend_hash_destroy(®(ht_rc)); - 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 -} - - -/* This is the maximum number of (..) constructs we'll generate from a - call to ereg() or eregi() with the optional third argument. */ -#define NS 10 - -/* - * 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) { - 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(E_WARNING, "%s", message); - } - - STR_FREE(buf); - STR_FREE(message); -} - -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[NS]; - int err, i, match_len, string_len; - int copts = 0; - off_t start, end; - char *buf = NULL; - char *string = NULL; - - if (icase) - copts |= REG_ICASE; - - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, ®ex, &findin) == FAILURE) { - WRONG_PARAM_COUNT; - } - /* don't bother doing substring matching if we're not going - to make use of the information */ - copts |= REG_NOSUB; - break; - case 3: - if (zend_get_parameters_ex(3, ®ex, &findin, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (!ParameterPassedByReference(ht, 3)) { - php_error(E_WARNING, "Array to be filled with values must be passed by reference."); - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - } - - - /* compile the regular expression from the supplied regex */ - if ((*regex)->type == IS_STRING) { - err = regcomp(&re, (*regex)->value.str.val, REG_EXTENDED | copts); - } else { - /* we convert numbers to integers and treat them as a string */ - if ((*regex)->type == 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, (*regex)->value.str.val, 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((*findin)->value.str.val, (*findin)->value.str.len); - - /* actually execute the regular expression */ - err = regexec(&re, string, (size_t) NS, subs, 0); - if (err && err != REG_NOMATCH) { - php_reg_eprint(err, &re); - regfree(&re); - RETURN_FALSE; - } - match_len = 1; - - if (array && err != REG_NOMATCH) { - match_len = (int) (subs[0].rm_eo - subs[0].rm_so); - string_len = strlen(string) + 1; - - buf = emalloc(string_len); - if (!buf) { - php_error(E_WARNING, "Unable to allocate memory in php_ereg"); - RETURN_FALSE; - } - - pval_destructor(*array); /* start with clean array */ - array_init(*array); - - for (i = 0; i < NS; 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(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); -} -/* }}} */ - -/* this is the meat and potatoes of regex replacement! */ -char *php_reg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended) -{ - regex_t re; - regmatch_t subs[NS]; - - 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); - } - - /* 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)); - if (!buf) { - php_error(E_WARNING, "Unable to allocate memory in php_reg_replace"); - regfree(&re); - return ((char *) -1); - } - - err = pos = 0; - buf[0] = '\0'; - - while (!err) { - err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0)); - - if (err && err != REG_NOMATCH) { - php_reg_eprint(err, &re); - 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 - && '0' <= walk[1] && '9' >= walk[1] - && 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 - && '0' <= walk[1] && '9' >= walk[1] - && subs[walk[1] - '0'].rm_so > -1 - && subs[walk[1] - '0'].rm_eo > -1) { - 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 .. */ - regfree(&re); - - /* whew. */ - return (buf); -} - -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 ((*arg_pattern)->type == IS_STRING) { - if ((*arg_pattern)->value.str.val && (*arg_pattern)->value.str.len) - pattern = estrndup((*arg_pattern)->value.str.val,(*arg_pattern)->value.str.len); - else - pattern = empty_string; - } else { - convert_to_long_ex(arg_pattern); - pattern = emalloc(2); - pattern[0] = (char) (*arg_pattern)->value.lval; - pattern[1] = '\0'; - } - - if ((*arg_replace)->type == IS_STRING) { - if ((*arg_replace)->value.str.val && (*arg_replace)->value.str.len) - replace = estrndup((*arg_replace)->value.str.val, (*arg_replace)->value.str.len); - else - replace = empty_string; - } else { - convert_to_long_ex(arg_replace); - replace = emalloc(2); - replace[0] = (char) (*arg_replace)->value.lval; - replace[1] = '\0'; - } - - convert_to_string_ex(arg_string); - if ((*arg_string)->value.str.val && (*arg_string)->value.str.len) - string = estrndup((*arg_string)->value.str.val, (*arg_string)->value.str.len); - 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 string [, array registers]) - Replace regular expression */ -PHP_FUNCTION(ereg_replace) -{ - php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string eregi_replace(string pattern, string string [, array registers]) - Case insensitive replace regular expression */ -PHP_FUNCTION(eregi_replace) -{ - php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh") - = split(":", $passwd_file, 5); */ -/* {{{ proto array split(string pattern, string string [, int limit]) - Split string into array by regular expression */ -PHP_FUNCTION(split) -{ - pval **spliton, **str, **arg_count = NULL; - regex_t re; - regmatch_t subs[1]; - char *strp, *endp; - int err, size, count; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &spliton, &str) == FAILURE) - WRONG_PARAM_COUNT; - count = -1; - break; - case 3: - if (zend_get_parameters_ex(3, &spliton, &str, &arg_count) == FAILURE) - WRONG_PARAM_COUNT; - convert_to_long_ex(arg_count); - count = (*arg_count)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(spliton); - convert_to_string_ex(str); - - strp = (*str)->value.str.val; - endp = (*str)->value.str.val + strlen((*str)->value.str.val); - - err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED); - if (err) { - php_error(E_WARNING, "unexpected regex error (%d)", err); - RETURN_FALSE; - } - - if (array_init(return_value) == FAILURE) { - regfree(&re); - RETURN_FALSE; - } - - /* 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(E_WARNING, "bad regular expression for split()"); - zend_hash_destroy(return_value->value.ht); - efree(return_value->value.ht); - 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_error(E_WARNING, "unexpected regex error (%d)", err); - regfree(&re); - zend_hash_destroy(return_value->value.ht); - efree(return_value->value.ht); - 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); - - return; -} -/* }}} */ - -/* {{{ proto string sql_regcase(string string) - Make regular expression for case insensitive match */ -PHPAPI PHP_FUNCTION(sql_regcase) -{ - pval **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 = (char *) emalloc((*string)->value.str.len*4+1); - - for (i=j=0; i<(*string)->value.str.len; i++) { - c = (unsigned char) (*string)->value.str.val[i]; - if(isalpha(c)) { - tmp[j++] = '['; - tmp[j++] = toupper(c); - tmp[j++] = tolower(c); - tmp[j++] = ']'; - } else { - tmp[j++] = c; - } - } - tmp[j]=0; - - tmp = erealloc(tmp, j + 1); - - RETVAL_STRINGL(tmp, j, 0); -} -/* }}} */ - - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/reg.h b/ext/standard/reg.h deleted file mode 100644 index 0ffa7438bd..0000000000 --- a/ext/standard/reg.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _REG_H -#define _REG_H - -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); -PHPAPI PHP_FUNCTION(sql_regcase); - -typedef struct { - HashTable ht_rc; -} php_reg_globals; - -PHP_MINIT_FUNCTION(regex); -PHP_MSHUTDOWN_FUNCTION(regex); -PHP_MINFO_FUNCTION(regex); - - -#ifdef ZTS -#define REGLS_D php_reg_globals *reg_globals -#define REGLS_DC , REGLS_D -#define REGLS_C reg_globals -#define REGLS_CC , REGLS_C -#define REG(v) (reg_globals->v) -#define REGLS_FETCH() php_reg_globals *reg_globals = ts_resource(reg_globals_id) -#else -#define REGLS_D -#define REGLS_DC -#define REGLS_C -#define REGLS_CC -#define REG(v) (reg_globals.v) -#define REGLS_FETCH() -#endif - -#endif /* _REG_H */ diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c deleted file mode 100644 index 50561239a2..0000000000 --- a/ext/standard/scanf.c +++ /dev/null @@ -1,1241 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: clayton collie <clcollie@mindspring.com> | - +----------------------------------------------------------------------+ - */ - -/* - 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); - - -/* - *---------------------------------------------------------------------- - * - * 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 -- - * - * 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 -- - * - * 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 -- - * - * 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; - - /* - * 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(E_WARNING, - "cannot mix \"%\" and \"%n$\" conversion specifiers in %s", get_active_function_name() ); - 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(E_WARNING, "field width may not be specified in %c conversion"); - goto error; - } - */ - break; - case '[': - if (*format == '\0') { - goto badSet; - } - (char *)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(E_WARNING, "unmatched [ in format string"); - goto error; - default: - { - php_error(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(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(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(E_WARNING, "\"%n$\" argument index out of range"); - } else { - php_error(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 -} - - - -/* 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) -{ - 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(E_WARNING,"Parameter %d to %s() must be passed by reference", - i, get_active_function_name()); - 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 */ - if (array_init(*return_value) == FAILURE) { - scan_set_error_return(0, return_value); - return FAILURE; - } - for (i = 0; i < totalVars; i++) { - if (add_next_index_unset(*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) { - current = args[objIndex++]; - convert_to_long( *current ); - ZVAL_STRINGL( *current, string, end-string, 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) { - 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 '[': { - 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 ); - (*return_value)->value.lval = 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 */ -inline void scan_set_error_return(int numVars,pval **return_value) { - if (numVars) { - (*return_value)->type = IS_LONG; - (*return_value)->value.lval = SCAN_ERROR_EOF; /* EOF marker */ - } else { - pval_destructor( *return_value ); - convert_to_null( *return_value ); - } -} - - diff --git a/ext/standard/scanf.h b/ext/standard/scanf.h deleted file mode 100644 index d95545d8c8..0000000000 --- a/ext/standard/scanf.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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: clayton collie <clcollie@mindspring.com> | - +----------------------------------------------------------------------+ - */ -#ifndef _SCAN_H_ -#define _SCAN_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_MAX_FSCANF_BUFSIZE 512 /* Max input buffer allocated for fscanf */ -#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); -inline void scan_set_error_return(int numVars,pval **return_value); - - -#endif /* ifndef _SCAN_PHP_ */ diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c deleted file mode 100644 index c6d733c75c..0000000000 --- a/ext/standard/soundex.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 *somestring; - int i, _small, len, code, last; - pval *arg, **parg; - 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_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &parg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(parg); - arg = *parg; - if (arg->value.str.len==0) { - RETURN_FALSE; - } - somestring = arg->value.str.val; - len = arg->value.str.len; - - /* build soundex string */ - last = -1; - for (i = 0, _small = 0; i < 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(somestring[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_value->value.str.val = estrndup(soundex, _small); - return_value->value.str.len = _small; - return_value->type = IS_STRING; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/string.c b/ext/standard/string.c deleted file mode 100644 index 03bbc2900f..0000000000 --- a/ext/standard/string.c +++ /dev/null @@ -1,2683 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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_string.h" -#include "php_variables.h" -#ifdef HAVE_LOCALE_H -# include <locale.h> -#endif -#include "scanf.h" -#include "zend_API.h" -#include "zend_execute.h" -#include "php_globals.h" -#include "basic_functions.h" - -int php_tag_find(char *tag, int len, char *set); - -/* this is read-only, so it's ok */ -static char hexconvtab[] = "0123456789abcdef"; - -static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *newlen) -{ - unsigned char *result = NULL; - size_t i, j; - - result = (char *) emalloc(oldlen * 2 * sizeof(char)); - if(!result) { - return result; - } - - for(i = j = 0; i < oldlen; i++) { - result[j++] = hexconvtab[old[i] >> 4]; - result[j++] = hexconvtab[old[i] & 15]; - } - - if(newlen) *newlen = oldlen * 2 * sizeof(char); - - return result; -} - -/* {{{ 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((*data)->value.str.val, (*data)->value.str.len, &newlen); - - if(!result) { - RETURN_FALSE; - } - - RETURN_STRINGL(result, newlen, 0); -} -/* }}} */ - -/* {{{ proto int strspn(string str, string mask) - Find length of initial segment consisting entirely of characters found in mask */ -PHP_FUNCTION(strspn) -{ - 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(php_strspn((*s1)->value.str.val, (*s2)->value.str.val, - (*s1)->value.str.val + (*s1)->value.str.len, - (*s2)->value.str.val + (*s2)->value.str.len)); -} -/* }}} */ - -/* {{{ proto int strcspn(string str, string mask) - Find length of initial segment consisting entirely of characters not found in mask */ -PHP_FUNCTION(strcspn) -{ - 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(php_strcspn((*s1)->value.str.val, (*s2)->value.str.val, - (*s1)->value.str.val + (*s1)->value.str.len, - (*s2)->value.str.val + (*s2)->value.str.len)); -} -/* }}} */ - -PHPAPI void php_trim(zval *str, zval * return_value, int mode) -/* mode 1 : trim left - mode 2 : trim right - mode 3 : trim left and right -*/ -{ - register int i; - int len = str->value.str.len; - int trimmed = 0; - char *c = str->value.str.val; - - if (mode & 1) { - for (i = 0; i < len; i++) { - if (c[i] == ' ' || c[i] == '\n' || c[i] == '\r' || - c[i] == '\t' || c[i] == '\v' || c[i] == '\0') { - trimmed++; - } else { - break; - } - } - len -= trimmed; - c += trimmed; - } - if (mode & 2) { - for (i = len - 1; i >= 0; i--) { - if (c[i] == ' ' || c[i] == '\n' || c[i] == '\r' || - c[i] == '\t' || c[i] == '\v' || c[i] == '\0') { - len--; - } else { - break; - } - } - } - RETVAL_STRINGL(c, len, 1); -} - -/* {{{ proto string rtrim(string str) - An alias for chop */ -/* }}} */ - -/* {{{ proto string chop(string str) - Remove trailing whitespace */ -PHP_FUNCTION(chop) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if ((*str)->type == IS_STRING) { - php_trim(*str, return_value, 2); - return; - } - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string trim(string str) - Strip whitespace from the beginning and end of a string */ -PHP_FUNCTION(trim) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if ((*str)->type == IS_STRING) { - php_trim(*str, return_value, 3); - return; - } - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto string ltrim(string str) - Strip whitespace from the beginning of a string */ -PHP_FUNCTION(ltrim) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - if ((*str)->type == IS_STRING) { - php_trim(*str, return_value, 1); - return; - } - RETURN_FALSE; -} -/* }}} */ - -PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit) -{ - char *p1, *p2, *endp; - - endp = str->value.str.val + str->value.str.len; - - p1 = str->value.str.val; - p2 = php_memnstr(str->value.str.val, delim->value.str.val, delim->value.str.len, endp); - - if (p2 == NULL) { - add_next_index_stringl(return_value, p1, str->value.str.len, 1); - } else { - do { - add_next_index_stringl(return_value, p1, p2-p1, 1); - p1 = p2 + delim->value.str.len; - } while ((p2 = php_memnstr(p1, delim->value.str.val, delim->value.str.len, 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]) - Split a string on string separator and return array of components */ -PHP_FUNCTION(explode) -{ - zval **str, **delim, **zlimit = NULL; - int limit; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &delim, &str) == FAILURE) - WRONG_PARAM_COUNT; - limit=-1; - break; - case 3: - if (zend_get_parameters_ex(3, &delim, &str, &zlimit) == FAILURE) - WRONG_PARAM_COUNT; - convert_to_long_ex(zlimit); - limit = (*zlimit)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - convert_to_string_ex(delim); - - if (! (*delim)->value.str.len) { - php_error(E_WARNING,"Empty delimiter"); - RETURN_FALSE; - } - - if (array_init(return_value) == FAILURE) { - RETURN_FALSE; - } - - if(limit==0 || limit==1) { - add_index_stringl(return_value, 0, (*str)->value.str.val, (*str)->value.str.len, 1); - } else { - php_explode(*delim, *str, return_value, limit); - } -} -/* }}} */ - - -/* {{{ proto string join(array src, string glue) - An alias for implode */ -/* }}} */ -PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value) -{ - zval **tmp; - int len = 0, count = 0, target = 0; - - /* convert everything to strings, and calculate length */ - zend_hash_internal_pointer_reset(arr->value.ht); - while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) { - convert_to_string_ex(tmp); - len += (*tmp)->value.str.len; - if (count>0) { - len += delim->value.str.len; - } - count++; - zend_hash_move_forward(arr->value.ht); - } - - /* do it */ - return_value->value.str.val = (char *) emalloc(len + 1); - return_value->value.str.val[0] = '\0'; - return_value->value.str.val[len] = '\0'; - zend_hash_internal_pointer_reset(arr->value.ht); - while (zend_hash_get_current_data(arr->value.ht, (void **) &tmp) == SUCCESS) { - count--; - memcpy(return_value->value.str.val + target, (*tmp)->value.str.val, - (*tmp)->value.str.len); - target += (*tmp)->value.str.len; - if (count > 0) { - memcpy(return_value->value.str.val + target, delim->value.str.val, - delim->value.str.len); - target += delim->value.str.len; - } - zend_hash_move_forward(arr->value.ht); - } - return_value->type = IS_STRING; - return_value->value.str.len = len; -} - - -/* {{{ proto string implode(array src, string glue) - Join array elements placing glue string between items and return one string */ -PHP_FUNCTION(implode) -{ - zval **arg1, **arg2, *delim, *arr; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*arg1)->type == IS_ARRAY && (*arg2)->type == IS_STRING) { - SEPARATE_ZVAL(arg1); - arr = *arg1; - delim = *arg2; - } else if ((*arg2)->type == IS_ARRAY) { - SEPARATE_ZVAL(arg2) - arr = *arg2; - convert_to_string_ex(arg1); - delim = *arg1; - } else { - php_error(E_WARNING, "Bad arguments to %s()", - get_active_function_name()); - return; - } - php_implode(delim, arr, return_value); -} -/* }}} */ - - -/* {{{ proto string strtok([string str,] string token) - Tokenize a string */ -PHP_FUNCTION(strtok) -{ - zval **str, **tok; - char *token = NULL, *tokp=NULL; - char *first = NULL; - int argc; - BLS_FETCH(); - - argc = ZEND_NUM_ARGS(); - - if ((argc == 1 && zend_get_parameters_ex(1, &tok) == FAILURE) || - (argc == 2 && zend_get_parameters_ex(2, &str, &tok) == FAILURE) || - argc < 1 || argc > 2) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(tok); - tokp = token = (*tok)->value.str.val; - - if (argc == 2) { - convert_to_string_ex(str); - - STR_FREE(BG(strtok_string)); - BG(strtok_string) = estrndup((*str)->value.str.val,(*str)->value.str.len); - BG(strtok_pos1) = BG(strtok_string); - BG(strtok_pos2) = NULL; - } - if (BG(strtok_pos1) && *BG(strtok_pos1)) { - for ( /* NOP */ ; token && *token; token++) { - BG(strtok_pos2) = strchr(BG(strtok_pos1), (int) *token); - if (!first || (BG(strtok_pos2) && BG(strtok_pos2) < first)) { - first = BG(strtok_pos2); - } - } /* NB: token is unusable now */ - - BG(strtok_pos2) = first; - if (BG(strtok_pos2)) { - *BG(strtok_pos2) = '\0'; - } - RETVAL_STRING(BG(strtok_pos1),1); -#if 0 - /* skip 'token' white space for next call to strtok */ - while (BG(strtok_pos2) && - strchr(tokp, *(BG(strtok_pos2)+1))) { - BG(strtok_pos2)++; - } -#endif - if (BG(strtok_pos2)) - BG(strtok_pos1) = BG(strtok_pos2) + 1; - else - BG(strtok_pos1) = NULL; - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -PHPAPI char *php_strtoupper(char *s, size_t len) -{ - char *c; - int ch; - size_t i; - - c = s; - for (i=0; i<len; i++) { - ch = toupper((unsigned char)*c); - *c++ = ch; - } - return (s); -} - -/* {{{ proto string strtoupper(string str) - Make 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(return_value->value.str.val, return_value->value.str.len); -} -/* }}} */ - - -PHPAPI char *php_strtolower(char *s, size_t len) -{ - register int ch; - char *c; - size_t i; - - c = s; - for (i=0; i<len; i++) { - ch = tolower((unsigned char)*c); - *c++ = ch; - } - return (s); -} - -/* {{{ proto string strtolower(string str) - Make 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(return_value->value.str.val, return_value->value.str.len); -} -/* }}} */ - -PHPAPI char *php_basename(char *s, size_t len) -{ - char *ret=NULL, *c, *p=NULL, buf='\0'; - c = s + len - 1; - - /* strip trailing slashes */ - while (*c == '/' -#ifdef PHP_WIN32 - || *c == '\\' -#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, '\\')) -#endif - ) { - ret = estrdup(c + 1); - } else { - ret = estrdup(s); - } - if(buf) *p = buf; - return (ret); -} - -/* {{{ proto string basename(string path) - Return the filename component of the path */ -PHP_FUNCTION(basename) -{ - zval **str; - char *ret; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - ret = php_basename((*str)->value.str.val,(*str)->value.str.len); - RETVAL_STRING(ret,1) - efree(ret); -} -/* }}} */ - -PHPAPI void php_dirname(char *str, int len) { - register char *c; - - c = str + len - 1; - while (*c == '/' -#ifdef PHP_WIN32 - || *c == '\\' -#endif - ) - c--; /* strip trailing slashes */ - *(c + 1) = '\0'; - if ((c = strrchr(str, '/')) -#ifdef PHP_WIN32 - || (c = strrchr(str, '\\')) -#endif - ) - *c='\0'; -} - -/* {{{ proto string dirname(string path) - Return 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)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - ret = estrdup((*str)->value.str.val); - php_dirname(ret,(*str)->value.str.len); - RETVAL_STRING(ret,1); - efree(ret); -} -/* }}} */ - - -/* 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); -} - -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); -} - -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) - Find 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((*haystack)->value.str.val, - (*haystack)->value.str.len); - - if ((*needle)->type == IS_STRING) { - if ((*needle)->value.str.len==0) { - php_error(E_WARNING,"Empty delimiter"); - efree(haystack_orig); - RETURN_FALSE; - } - - found = php_stristr((*haystack)->value.str.val, (*needle)->value.str.val, - (*haystack)->value.str.len, (*needle)->value.str.len); - } else { - convert_to_long_ex(needle); - needle_char[0] = tolower((char) (*needle)->value.lval); - needle_char[1] = '\0'; - - found = php_stristr((*haystack)->value.str.val, needle_char, - (*haystack)->value.str.len, 1); - } - - if (found) { - found_offset = found - (*haystack)->value.str.val; - RETVAL_STRINGL(haystack_orig + found_offset, - (*haystack)->value.str.len - found_offset, 1); - } else { - RETVAL_FALSE; - } - efree(haystack_orig); -} -/* }}} */ - -/* {{{ proto string strstr(string haystack, string needle) - Find first occurrence of a string within another */ -PHP_FUNCTION(strstr) -{ - zval **haystack, **needle; - char *haystack_end; - char *found = NULL; - char needle_char[2]; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - haystack_end = (*haystack)->value.str.val + (*haystack)->value.str.len; - - if ((*needle)->type == IS_STRING) { - if ((*needle)->value.str.len==0) { - php_error(E_WARNING,"Empty delimiter"); - RETURN_FALSE; - } - found = php_memnstr((*haystack)->value.str.val, (*needle)->value.str.val, - (*needle)->value.str.len, haystack_end); - } else { - convert_to_long_ex(needle); - needle_char[0] = (char) (*needle)->value.lval; - needle_char[1] = '\0'; - found = php_memnstr((*haystack)->value.str.val, needle_char, 1, haystack_end); - } - - - if (found) { - RETVAL_STRING(found, 1); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto string strchr(string haystack, string needle) - An alias for strstr */ -/* }}} */ - -/* {{{ proto int strpos(string haystack, string needle [, int offset]) - Find position of first occurrence of a string within another */ -PHP_FUNCTION(strpos) -{ - zval **haystack, **needle, **OFFSET; - int offset = 0; - char *found = NULL; - char *endp; - char *startp; - - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (zend_get_parameters_ex(3, &haystack, &needle, &OFFSET) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(OFFSET); - offset = (*OFFSET)->value.lval; - if (offset < 0) { - php_error(E_WARNING,"offset not contained in string"); - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(haystack); - - if (offset > (*haystack)->value.str.len) { - php_error(E_WARNING,"offset not contained in string"); - RETURN_FALSE; - } - - startp = (*haystack)->value.str.val; - startp+= offset; - - endp = (*haystack)->value.str.val; - endp+= (*haystack)->value.str.len; - - if ((*needle)->type == IS_STRING) { - if ((*needle)->value.str.len==0) { - php_error(E_WARNING,"Empty delimiter"); - RETURN_FALSE; - } - found = php_memnstr(startp, (*needle)->value.str.val, (*needle)->value.str.len, endp); - } else { - char buf; - - convert_to_long_ex(needle); - buf = (char) (*needle)->value.lval; - - found = php_memnstr(startp, &buf, 1, endp); - } - - if (found) { - RETVAL_LONG(found - (*haystack)->value.str.val); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto int strrpos(string haystack, string needle) - Find the last occurrence of a character in a string within another */ -PHP_FUNCTION(strrpos) -{ - zval **haystack, **needle; - char *found = NULL; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if ((*needle)->type == IS_STRING) { - found = strrchr((*haystack)->value.str.val, *(*needle)->value.str.val); - } else { - convert_to_long_ex(needle); - found = strrchr((*haystack)->value.str.val, (char) (*needle)->value.lval); - } - - if (found) { - RETVAL_LONG((*haystack)->value.str.len - strlen(found)); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ proto string strrchr(string haystack, string needle) - Find the last occurrence of a character in a string within another */ -PHP_FUNCTION(strrchr) -{ - zval **haystack, **needle; - char *found = NULL; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if ((*needle)->type == IS_STRING) { - found = strrchr((*haystack)->value.str.val, *(*needle)->value.str.val); - } else { - - convert_to_long_ex(needle); - found = strrchr((*haystack)->value.str.val, (*needle)->value.lval); - } - - - if (found) { - RETVAL_STRING(found,1); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -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]]) - Return split line */ -PHP_FUNCTION(chunk_split) -{ - zval **p_str, **p_chunklen, **p_ending; - int argc; - char *result; - char *end = "\r\n"; - int endlen = 2; - int chunklen = 76; - int result_len; - - argc = ZEND_NUM_ARGS(); - - if (argc < 1 || argc > 3 || - zend_get_parameters_ex(argc, &p_str, &p_chunklen, &p_ending) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch(argc) { - case 3: - convert_to_string_ex(p_ending); - end = (*p_ending)->value.str.val; - endlen = (*p_ending)->value.str.len; - case 2: - convert_to_long_ex(p_chunklen); - chunklen = (*p_chunklen)->value.lval; - case 1: - convert_to_string_ex(p_str); - } - - if(chunklen == 0) { - php_error(E_WARNING, "chunk length is 0"); - RETURN_FALSE; - } - - result = php_chunk_split((*p_str)->value.str.val, (*p_str)->value.str.len, - end, endlen, chunklen, &result_len); - - if(result) { - RETVAL_STRINGL(result, result_len, 0); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto string substr(string str, int start [, int length]) - Return part of a string */ -PHP_FUNCTION(substr) -{ - zval **str, **from, **len; - int argc, l; - int f; - - argc = ZEND_NUM_ARGS(); - - if ((argc == 2 && zend_get_parameters_ex(2, &str, &from) == FAILURE) || - (argc == 3 && zend_get_parameters_ex(3, &str, &from, &len) == FAILURE) || - argc < 2 || argc > 3) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - convert_to_long_ex(from); - f = (*from)->value.lval; - - if (argc == 2) { - l = (*str)->value.str.len; - } else { - convert_to_long_ex(len); - l = (*len)->value.lval; - } - - /* if "from" position is negative, count start position from the end - * of the string - */ - if (f < 0) { - f = (*str)->value.str.len + 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 = ((*str)->value.str.len - f) + l; - if (l < 0) { - l = 0; - } - } - - if (f >= (int)(*str)->value.str.len) { - RETURN_FALSE; - } - - if((f+l) > (int)(*str)->value.str.len) { - l = (int)(*str)->value.str.len - f; - } - - RETVAL_STRINGL((*str)->value.str.val + f, l, 1); -} -/* }}} */ - - -/* {{{ proto string substr_replace(string str, string repl, int start [, int length]) - Replace 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 argc; - int l; - int f; - - argc = ZEND_NUM_ARGS(); - - if ((argc == 3 && zend_get_parameters_ex(3, &str, &repl, &from) == FAILURE) || - (argc == 4 && zend_get_parameters_ex(4, &str, &repl, &from, &len) == FAILURE) || - argc < 3 || argc > 4) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - convert_to_string_ex(repl); - convert_to_long_ex(from); - f = (*from)->value.lval; - - if (argc == 3) { - l = (*str)->value.str.len; - } else { - convert_to_long_ex(len); - l = (*len)->value.lval; - } - - /* if "from" position is negative, count start position from the end - * of the string - */ - if (f < 0) { - f = (*str)->value.str.len + 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 = ((*str)->value.str.len - f) + l; - if (l < 0) { - l = 0; - } - } - - if (f >= (int)(*str)->value.str.len) { - RETURN_STRINGL((*str)->value.str.val, (*str)->value.str.len, 1); - } - - if((f+l) > (int)(*str)->value.str.len) { - l = (int)(*str)->value.str.len - f; - } - - result_len = (*str)->value.str.len - l + (*repl)->value.str.len; - result = (char *)ecalloc(result_len + 1, sizeof(char *)); - - memcpy(result, (*str)->value.str.val, f); - memcpy(&result[f], (*repl)->value.str.val, (*repl)->value.str.len); - memcpy(&result[f + (*repl)->value.str.len], (*str)->value.str.val + f + l, - (*str)->value.str.len - f - l); - - RETVAL_STRINGL(result, result_len, 0); -} -/* }}} */ - - -/* {{{ proto string quotemeta(string str) - Quote 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 = (*arg)->value.str.val; - old_end = (*arg)->value.str.val + (*arg)->value.str.len; - - if (old == old_end) { - RETURN_FALSE; - } - - str = emalloc(2 * (*arg)->value.str.len + 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; - RETVAL_STRINGL(erealloc(str, q - str + 1), q - str, 0); -} -/* }}} */ - -/* {{{ proto int ord(string character) - Return 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); - RETVAL_LONG((unsigned char)(*str)->value.str.val[0]); -} -/* }}} */ - -/* {{{ proto string chr(int ascii) - Convert 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) (*num)->value.lval; - temp[1] = '\0'; - RETVAL_STRINGL(temp, 1,1); -} -/* }}} */ - -/* {{{ proto string ucfirst(string str) - Make a string's first character uppercase */ -PHP_FUNCTION(ucfirst) -{ - zval **arg; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!*(*arg)->value.str.val) { - RETURN_FALSE; - } - - *return_value=**arg; - zval_copy_ctor(return_value); - *return_value->value.str.val = toupper((unsigned char)*return_value->value.str.val); -} -/* }}} */ - -/* {{{ 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_FALSE; - } - *return_value=**str; - zval_copy_ctor(return_value); - - r=return_value->value.str.val; - *r=toupper((unsigned char)*r); - for(r_end = r + return_value->value.str.len - 1 ; r < r_end ; ) { - if(isspace((int)*r++)) { - *r=toupper((unsigned char)*r); - } - } -} -/* }}} */ - -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; -} - -static void php_strtr_array(zval *return_value,char *str,int slen,HashTable *hash) -{ - zval *entry; - char *string_key; - zval **trans; - zval ctmp; - ulong num_key; - int minlen = 128*1024; - int maxlen = 0, pos, len, newpos, newlen, found; - char *newstr, *key; - - zend_hash_internal_pointer_reset(hash); - while (zend_hash_get_current_data(hash, (void **)&entry) == SUCCESS) { - switch (zend_hash_get_current_key(hash, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - len = strlen(string_key); - if (len > maxlen) maxlen = len; - if (len < minlen) minlen = len; - efree(string_key); - break; - - case HASH_KEY_IS_LONG: - ctmp.type = IS_LONG; - ctmp.value.lval = num_key; - - convert_to_string(&ctmp); - len = ctmp.value.str.len; - zval_dtor(&ctmp); - - if (len > maxlen) maxlen = len; - if (len < minlen) minlen = len; - break; - } - zend_hash_move_forward(hash); - } - - key = emalloc(maxlen+1); - newstr = emalloc(8192); - newlen = 8192; - newpos = 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 ((*trans)->type != IS_STRING) { - tmp = **trans; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - tval = tmp.value.str.val; - tlen = tmp.value.str.len; - } else { - tval = (*trans)->value.str.val; - tlen = (*trans)->value.str.len; - } - - if ((newpos + tlen + 1) > newlen) { - newlen = newpos + tlen + 1 + 8192; - newstr = erealloc(newstr,newlen); - } - - memcpy(newstr+newpos,tval,tlen); - newpos += tlen; - pos += len; - found = 1; - - if ((*trans)->type != IS_STRING) { - zval_dtor(&tmp); - } - break; - } - } - - if (! found) { - if ((newpos + 1) > newlen) { - newlen = newpos + 1 + 8192; - newstr = erealloc(newstr,newlen); - } - - newstr[ newpos++ ] = str[ pos++ ]; - } - } - - efree(key); - newstr[ newpos ] = 0; - RETURN_STRINGL(newstr,newpos,0); -} - -/* {{{ proto string strtr(string str, string from, string to) - Translate characters in str using given translation tables */ -PHP_FUNCTION(strtr) -{ /* strtr(STRING,FROM,TO) */ - 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 && (*from)->type != IS_ARRAY) { - php_error(E_WARNING,"arg2 must be passed an array"); - RETURN_FALSE; - } - - convert_to_string_ex(str); - - if (ac == 2) { - php_strtr_array(return_value,(*str)->value.str.val,(*str)->value.str.len,HASH_OF(*from)); - } else { - convert_to_string_ex(from); - convert_to_string_ex(to); - - *return_value=**str; - zval_copy_ctor(return_value); - - php_strtr(return_value->value.str.val, - return_value->value.str.len, - (*from)->value.str.val, - (*to)->value.str.val, - MIN((*from)->value.str.len,(*to)->value.str.len)); - } -} -/* }}} */ - - -/* {{{ proto string strrev(string str) - Reverse a string */ -PHP_FUNCTION(strrev) -{ - zval **str; - int i,len; - char c; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - - *return_value = **str; - zval_copy_ctor(return_value); - - len = return_value->value.str.len; - - for (i=0; i<len-1-i; i++) { - c=return_value->value.str.val[i]; - return_value->value.str.val[i] = return_value->value.str.val[len-1-i]; - return_value->value.str.val[len-1-i]=c; - } -} -/* }}} */ - -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; - } - } - } -} - -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 [, double 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 (((*t1)->value.str.len + (*t2)->value.str.len) == 0) { - if(ac > 2) { - (*percent)->value.dval = 0; - } - RETURN_LONG(0); - } - - sim = php_similar_char((*t1)->value.str.val, (*t1)->value.str.len, - (*t2)->value.str.val, (*t2)->value.str.len); - - if (ac > 2) { - (*percent)->value.dval = sim * 200.0 / ((*t1)->value.str.len + (*t2)->value.str.len); - } - - RETURN_LONG(sim); -} -/* }}} */ - - -/* be careful, this edits the string in-place */ -PHPAPI void php_stripslashes(char *str, int *len) -{ - char *s, *t; - int l; - char escape_char='\\'; - PLS_FETCH(); - - if (PG(magic_quotes_sybase)) { - escape_char='\''; - } - - if (len != NULL) { - l = *len; - } else { - l = strlen(str); - } - s = str; - t = str; - while (l > 0) { - if (*t == escape_char) { - 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) - Escape 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); - return_value->value.str.val = php_addcslashes((*str)->value.str.val,(*str)->value.str.len,&return_value->value.str.len,0,(*what)->value.str.val,(*what)->value.str.len); - return_value->type = IS_STRING; -} -/* }}} */ - -/* {{{ proto string addslashes(string str) - Escape 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); - return_value->value.str.val = php_addslashes((*str)->value.str.val,(*str)->value.str.len,&return_value->value.str.len,0); - return_value->type = IS_STRING; -} -/* }}} */ - -/* {{{ proto string stripcslashes(string str) - Strip 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); - - *return_value = **str; - zval_copy_ctor(return_value); - php_stripcslashes(return_value->value.str.val,&return_value->value.str.len); -} -/* }}} */ - -/* {{{ proto string stripslashes(string str) - Strip 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); - - *return_value = **str; - zval_copy_ctor(return_value); - php_stripslashes(return_value->value.str.val,&return_value->value.str.len); -} -/* }}} */ - -#ifndef HAVE_STRERROR -char *php_strerror(int errnum) -{ - extern int sys_nerr; - extern char *sys_errlist[]; - BLS_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 - -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; - } - } - *target='\0'; - - *len = nlen; -} - - -PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_free, char *what, int wlength) -{ - 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); - } - - memset(flags, '\0', sizeof(flags)); - for (source=what,end=source+wlength; (c=*source) || source<end; source++) { - if (source+3<end && *(source+1) == '.' && *(source+2) == '.' && (unsigned char)*(source+3)>=(unsigned char)c) { - memset(flags+c, 1, (unsigned char)*(source+3)-(unsigned char)c+1); - source+=3; - } else - flags[(unsigned char)c]=1; - } - - 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; -} - -PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free) -{ - /* maximum string length, worst case situation */ - char *new_str; - char *source,*target; - char *end; - char c; - PLS_FETCH(); - - if (!str) { - *new_length = 0; - return str; - } - new_str = (char *) emalloc((length?length:(length=strlen(str)))*2+1); - for (source=str,end=source+length,target=new_str; (c = *source) || source<end; source++) { - switch(c) { - case '\0': - *target++ = '\\'; - *target++ = '0'; - break; - case '\'': - if (PG(magic_quotes_sybase)) { - *target++ = '\''; - *target++ = '\''; - break; - } - /* break is missing *intentionally* */ - case '\"': - case '\\': - if (!PG(magic_quotes_sybase)) { - *target++ = '\\'; - } - /* break is missing *intentionally* */ - default: - *target++ = c; - break; - } - } - *target = 0; - if (new_length) { - *new_length = target - new_str; - } - if (should_free) { - STR_FREE(str); - } - 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) - -PHPAPI void php_char_to_str(char *str,uint len,char from,char *to,int to_len,zval *result) -{ - int char_count=0; - char *source,*target,*tmp,*source_end=str+len, *tmp_end=NULL; - - for (source=str; source<source_end; source++) { - if (*source==from) { - char_count++; - } - } - - result->type = IS_STRING; - - if (char_count==0) { - result->value.str.val = estrndup(str,len); - result->value.str.len = len; - return; - } - - result->value.str.len = len+char_count*(to_len-1); - result->value.str.val = target = (char *) emalloc(result->value.str.len+1); - - for (source=str; source<source_end; source++) { - if (*source==from) { - for (tmp=to,tmp_end=tmp+to_len; tmp<tmp_end; tmp++) { - *target = *tmp; - target++; - } - } else { - *target = *source; - target++; - } - } - *target = 0; -} - - -PHPAPI inline char * -php_memnstr(char *haystack, char *needle, int needle_len, char *end) -{ - char *p = haystack; - char *s = NULL; - - for(; p <= end - needle_len && - (s = memchr(p, *needle, end - p - needle_len + 1)); p = s + 1) { - if(memcmp(s, needle, needle_len) == 0) - return s; - } - return NULL; -} - -PHPAPI char *php_str_to_str(char *haystack, int length, - char *needle, int needle_len, char *str, int str_len, int *_new_length) -{ - char *p, *q; - char *r, *s; - char *end = haystack + length; - char *result; - char *off; - - result = emalloc(length); - /* we jump through haystack searching for the needle. hurray! */ - for(p = haystack, q = result; - (r = php_memnstr(p, needle, needle_len, end));) { - /* this ain't optimal. you could call it `efficient memory usage' */ - off = erealloc(result, (q - result) + (r - p) + (str_len) + 1); - if(off != result) { - if(!off) { - goto finish; - } - q += off - result; - result = off; - } - memcpy(q, p, r - p); - q += r - p; - memcpy(q, str, str_len); - q += str_len; - p = r + needle_len; - } - - /* if there is a rest, copy it */ - if((end - p) > 0) { - s = (q) + (end - p); - off = erealloc(result, s - result + 1); - if(off != result) { - if(!off) { - goto finish; - } - q += off - result; - result = off; - s = q + (end - p); - } - memcpy(q, p, end - p); - q = s; - } -finish: - *q = '\0'; - if(_new_length) *_new_length = q - result; - return result; -} - - -/* {{{ proto string str_replace(string needle, string str, string haystack) - Replace all occurrences of needle in haystack with str */ -PHP_FUNCTION(str_replace) -{ - zval **haystack, **needle, **str; - char *result; - int len = 0; - - if(ZEND_NUM_ARGS() != 3 || - zend_get_parameters_ex(3, &needle, &str, &haystack) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(haystack); - convert_to_string_ex(needle); - convert_to_string_ex(str); - - if((*haystack)->value.str.len == 0) { - RETURN_STRING(empty_string,1); - } - - if((*needle)->value.str.len == 1) { - php_char_to_str((*haystack)->value.str.val, - (*haystack)->value.str.len, - (*needle)->value.str.val[0], - (*str)->value.str.val, - (*str)->value.str.len, - return_value); - return; - } - - if((*needle)->value.str.len == 0) { - php_error(E_WARNING, "The length of the needle must not be 0"); - RETURN_FALSE; - } - - result = php_str_to_str((*haystack)->value.str.val, (*haystack)->value.str.len, - (*needle)->value.str.val, (*needle)->value.str.len, - (*str)->value.str.val, (*str)->value.str.len, &len); - RETURN_STRINGL(result, len, 0); -} -/* }}} */ - -/* 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,*opposite_target,*broken_str; - int block_start, block_end, block_type, block_length, i; - int block_ended; - 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 = (*max_chars_per_line)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string_ex(str); - - if ((*str)->value.str.len==0) { - RETURN_FALSE; - } - - tmp = (*str)->value.str.val; - block_start=block_end=0; - block_ended=0; - - heb_str = (char *) emalloc((*str)->value.str.len+1); - target = heb_str+(*str)->value.str.len; - opposite_target = heb_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<(*str)->value.str.len-1) { - tmp++; - block_end++; - block_length++; - } - for (i=block_start; i<=block_end; i++) { - *target = (*str)->value.str.val[i]; - switch (*target) { - 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<(*str)->value.str.len-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 = (*str)->value.str.val[i]; - target--; - } - block_type = _HEB_BLOCK_TYPE_HEB; - } - block_start=block_end+1; - } while(block_end<(*str)->value.str.len-1); - - - broken_str = (char *) emalloc((*str)->value.str.len+1); - begin=end=(*str)->value.str.len-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,(*str)->value.str.len,'\n',"<br>\n",5,return_value); - efree(broken_str); - } else { - return_value->value.str.val = broken_str; - return_value->value.str.len = (*str)->value.str.len; - return_value->type = IS_STRING; - } -} - - -/* {{{ proto string hebrev(string str [, int max_chars_per_line]) - Convert 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]) - Convert 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) -{ - zval **str; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - - php_char_to_str((*str)->value.str.val,(*str)->value.str.len,'\n',"<br>\n",5,return_value); -} -/* }}} */ - -/* {{{ 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; - - 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 = (*allow)->value.str.val; - allowed_tags_len = (*allow)->value.str.len; - break; - default: - WRONG_PARAM_COUNT; - break; - } - convert_to_string_ex(str); - buf = estrndup((*str)->value.str.val,(*str)->value.str.len); - php_strip_tags(buf, (*str)->value.str.len, 0, allowed_tags, allowed_tags_len); - RETURN_STRING(buf, 0); -} -/* }}} */ - -/* {{{ proto string setlocale(string category, string locale) - Set locale information */ -PHP_FUNCTION(setlocale) -{ - zval **pcategory, **plocale; - zval *category, *locale; - int cat; - char *loc, *retval; - BLS_FETCH(); - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &pcategory, &plocale)==FAILURE) - WRONG_PARAM_COUNT; -#ifdef HAVE_SETLOCALE - convert_to_string_ex(pcategory); - convert_to_string_ex(plocale); - category = *pcategory; - locale = *plocale; - if (!strcasecmp ("LC_ALL", category->value.str.val)) - cat = LC_ALL; - else if (!strcasecmp ("LC_COLLATE", category->value.str.val)) - cat = LC_COLLATE; - else if (!strcasecmp ("LC_CTYPE", category->value.str.val)) - cat = LC_CTYPE; - else if (!strcasecmp ("LC_MONETARY", category->value.str.val)) - cat = LC_MONETARY; - else if (!strcasecmp ("LC_NUMERIC", category->value.str.val)) - cat = LC_NUMERIC; - else if (!strcasecmp ("LC_TIME", category->value.str.val)) - cat = LC_TIME; - else { - php_error(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->value.str.val); - RETURN_FALSE; - } - if (!strcmp ("0", locale->value.str.val)) - loc = NULL; - else - loc = locale->value.str.val; - retval = setlocale (cat, loc); - if (retval) { - /* Remember if locale was changed */ - if (loc) { - STR_FREE(BG(locale_string)); - BG(locale_string) = estrdup(retval); - } - - RETVAL_STRING(retval,1); - return; - } -#endif - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto void parse_str(string encoded_string) - Parses GET/POST/COOKIE data and sets global variables. */ -PHP_FUNCTION(parse_str) -{ - zval **arg; - char *res = NULL; - PLS_FETCH(); - SLS_FETCH(); - - if (zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - if ((*arg)->value.str.val && *(*arg)->value.str.val) { - res = estrndup((*arg)->value.str.val,(*arg)->value.str.len); - } - php_treat_data(PARSE_STRING, res ELS_CC PLS_CC SLS_CC); -} -/* }}} */ - -#define PHP_TAG_BUF_SIZE 1023 - -/* 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; -} - -/* 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. -*/ -PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len) -{ - char *tbuf, *buf, *p, *tp, *rp, c, lc; - int br, i=0; - - 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 (state == 0) { - lc = '<'; - state = 1; - if(allow) { - *(tp++) = '<'; - } - } - break; - - case '(': - if (state == 2) { - if (lc != '\"') { - lc = '('; - br++; - } - } else if (state == 0) { - *(rp++) = c; - } - break; - - case ')': - if (state == 2) { - if (lc != '\"') { - lc = ')'; - br--; - } - } else if (state == 0) { - *(rp++) = c; - } - break; - - case '>': - if (state == 1) { - 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; - } - } else if (state == 2) { - if (!br && lc != '\"' && *(p-1)=='?') { - state = 0; - } - } - break; - - case '\"': - if (state == 2) { - if (lc == '\"') { - lc = '\0'; - } else if (lc != '\\') { - lc = '\"'; - } - } else if (state == 0) { - *(rp++) = c; - } else if (allow && state == 1) { - *(tp++) = c; - } - break; - - case '?': - if (state==1 && *(p-1)=='<') { - br=0; - state=2; - break; - } - /* fall-through */ - - default: - 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++; - } - *rp = '\0'; - efree(buf); - if(allow) efree(tbuf); -} - -/* {{{ 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 */ - int i; - - 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 ((*mult)->value.lval < 1) { - php_error(E_WARNING, "Second argument to %s() has to be greater than 0", - get_active_function_name()); - return; - } - - /* Don't waste our time if it's empty */ - if ((*input_str)->value.str.len == 0) - RETURN_STRINGL(empty_string, 0, 1); - - /* Initialize the result string */ - result_len = (*input_str)->value.str.len * (*mult)->value.lval; - result = (char *)emalloc(result_len + 1); - - /* Copy the input string into the result as many times as necessary */ - for (i=0; i<(*mult)->value.lval; i++) { - memcpy(result + (*input_str)->value.str.len * i, - (*input_str)->value.str.val, - (*input_str)->value.str.len); - } - 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 = (*mode)->value.lval; - - if (mymode < 0 || mymode > 4) { - php_error(E_WARNING, "unknown mode"); - RETURN_FALSE; - } - } - - len = (*input)->value.str.len; - buf = (unsigned char *) (*input)->value.str.val; - memset((void*) chars,0,sizeof(chars)); - - while (len > 0) { - chars[*buf]++; - buf++; - len--; - } - - if (mymode < 3) { - array_init(return_value); - } - - for (inx=0; inx < 255; 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); - } -} -/* }}} */ - -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((*s1)->value.str.val, (*s1)->value.str.len, - (*s2)->value.str.val, (*s2)->value.str.len, - 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 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 i, length, 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 ((*needle)->value.str.len == 0) { - php_error(E_WARNING, "Empty substring"); - RETURN_FALSE; - } else if ((*needle)->value.str.len == 1) { - /* Special optimized case to avoid calls to php_memnstr(). */ - for (i = 0, p = (*haystack)->value.str.val, - length = (*haystack)->value.str.len, cmp = (*needle)->value.str.val[0]; - i < length; i++) { - if (p[i] == cmp) { - count++; - } - } - } else { - p = (*haystack)->value.str.val; - endp = p + (*haystack)->value.str.len; - while (p <= endp) { - if( (p = php_memnstr(p, (*needle)->value.str.val, (*needle)->value.str.len, endp)) != NULL ) { - p += (*needle)->value.str.len; - count++; - } else { - break; - } - } - } - - RETURN_LONG(count); -} -/* }}} */ - - -/* {{{ proto string str_pad(string input, int pad_length [, string pad_string]) - Returns input string padded on the left or right to specified length with pad_string */ -PHP_FUNCTION(str_pad) -{ - zval **input, /* Input string */ - **pad_length, /* Length to pad to (positive/negative) */ - **pad_string; /* Padding string */ - int pad_length_abs; /* Absolute padding length */ - 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 i; - - if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 || - zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &pad_length, &pad_string) == FAILURE) { - WRONG_PARAM_COUNT; - } - - /* Perform initial conversion to expected data types. */ - convert_to_string_ex(input); - convert_to_long_ex(pad_length); - - pad_length_abs = abs(Z_LVAL_PP(pad_length)); - - /* If resulting string turns out to be shorter than input string, - we simply copy the input and return. */ - if (pad_length_abs <= Z_STRLEN_PP(input)) { - *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(E_WARNING, "Padding string cannot be empty in %s()", - get_active_function_name()); - return; - } - pad_str_val = Z_STRVAL_PP(pad_string); - pad_str_len = Z_STRLEN_PP(pad_string); - } - - result = (char *)emalloc(pad_length_abs); - - /* If positive, we pad on the right and copy the input now. */ - if (Z_LVAL_PP(pad_length) > 0) { - memcpy(result, Z_STRVAL_PP(input), Z_STRLEN_PP(input)); - result_len = Z_STRLEN_PP(input); - } - - /* Loop through pad string, copying it into result. */ - for (i = 0; i < pad_length_abs - Z_STRLEN_PP(input); i++) { - result[result_len++] = pad_str_val[i % pad_str_len]; - } - - /* If negative, we've padded on the left, and copy the input now. */ - if (Z_LVAL_PP(pad_length) < 0) { - memcpy(result + result_len, Z_STRVAL_PP(input), Z_STRLEN_PP(input)); - result_len += Z_STRLEN_PP(input); - } - - RETURN_STRINGL(result, result_len, 0); -} -/* }}} */ - - -/* {{{ proto mixed sscanf(string str,string format, ...) - implements an ANSI compatible sscanf. */ -PHP_FUNCTION(sscanf) -{ - zval **format; - zval **literal; - int result; - zval ***args; - int argCount; - - - argCount = ZEND_NUM_ARGS(); - if (argCount < 2) { - WRONG_PARAM_COUNT; - } - args = (zval ***)emalloc(argCount * sizeof(zval **)); - if (!args || (zend_get_parameters_array_ex(argCount,args) == FAILURE)) { - efree( args ); - WRONG_PARAM_COUNT; - } - - literal = args[0]; - format = args[1]; - - convert_to_string_ex( format ); - convert_to_string_ex( literal ); - - result = php_sscanf_internal( (*literal)->value.str.val, - (*format)->value.str.val, - argCount,args, - 2,&return_value); - efree(args); - - if (SCAN_ERROR_WRONG_PARAM_COUNT == result) { - WRONG_PARAM_COUNT - } - -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c deleted file mode 100644 index 42c26ce1cd..0000000000 --- a/ext/standard/strnatcmp.c +++ /dev/null @@ -1,158 +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 - -static char const *version UNUSED = - "$Id$"; - -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; -} - - -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; -} - - -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; - } -} diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c deleted file mode 100644 index 882c4e1259..0000000000 --- a/ext/standard/syslog.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 Sæther Bakken <ssb@fast.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.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(BLS_D); - -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) - 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); - REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT); -#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) -{ - BLS_FETCH(); - - if (INI_INT("define_syslog_variables")) { - start_syslog(BLS_C); - } else { - BG(syslog_started)=0; - } - BG(syslog_device)=NULL; - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(syslog) -{ - BLS_FETCH(); - - if (BG(syslog_device)) { - efree(BG(syslog_device)); - } - return SUCCESS; -} - - -static void start_syslog(BLS_D) -{ - ELS_FETCH(); - - /* 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) - 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); - SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT); -#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) -{ - BLS_FETCH(); - - if (!BG(syslog_started)) { - start_syslog(BLS_C); - } -} - -/* {{{ proto int 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) -{ - pval **ident, **option, **facility; - BLS_FETCH(); - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &ident, &option, &facility) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(ident); - convert_to_long_ex(option); - convert_to_long_ex(facility); - if (BG(syslog_device)) { - efree(BG(syslog_device)); - } - BG(syslog_device) = estrndup((*ident)->value.str.val,(*ident)->value.str.len); - openlog(BG(syslog_device), (*option)->value.lval, (*facility)->value.lval); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int closelog(void) - Close connection to system logger */ -PHP_FUNCTION(closelog) -{ - BLS_FETCH(); - - closelog(); - if (BG(syslog_device)) { - efree(BG(syslog_device)); - BG(syslog_device)=NULL; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int syslog(int priority, string message) - Generate a system log message */ -PHP_FUNCTION(syslog) -{ - pval **priority, **message; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &priority, &message) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(priority); - convert_to_string_ex(message); - - /* - * CAVEAT: if the message contains patterns such as "%s", - * this will cause problems. - */ - - php_syslog((*priority)->value.lval, (*message)->value.str.val); - RETURN_TRUE; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/type.c b/ext/standard/type.c deleted file mode 100644 index c1f2fb9a47..0000000000 --- a/ext/standard/type.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ -#include "php.h" -#include "type.h" - -/* - * Determines if 'str' is an integer (long), real number or a string - * - * Note that leading zeroes automatically force a STRING type - */ -int php_check_type(char *str) -{ - char *s; - int type = IS_LONG; - - s = str; - if (*s == '0' && *(s + 1) && *(s + 1) != '.') - return (IS_STRING); - if (*s == '+' || *s == '-' || (*s >= '0' && *s <= '9') || *s == '.') { - if (*s == '.') - type = IS_DOUBLE; - s++; - while (*s) { - if (*s >= '0' && *s <= '9') { - s++; - continue; - } else if (*s == '.' && type == IS_LONG) { - type = IS_DOUBLE; - s++; - continue; - } else - return (IS_STRING); - } - } else - return (IS_STRING); - - return (type); -} /* php_check_type */ - -/* - * 0 - simple variable - * 1 - non-index array - * 2 - index array - */ -int php_check_ident_type(char *str) -{ - char *s; - - if (!(s = (char *) strchr(str, '['))) - return (GPC_REGULAR); - s++; - while (*s == ' ' || *s == '\t' || *s == '\n') { - s++; - } - if (*s == ']') { - return (GPC_NON_INDEXED_ARRAY); - } - return (GPC_INDEXED_ARRAY); -} - -char *php_get_ident_index(char *str) -{ - char *temp; - char *s, *t; - char o; - - temp = emalloc(strlen(str)); - temp[0] = '\0'; - s = (char *) strchr(str, '['); - if (s) { - t = (char *) strrchr(str, ']'); - if (t) { - o = *t; - *t = '\0'; - strcpy(temp, s + 1); - *t = o; - } - } - return (temp); -} diff --git a/ext/standard/type.h b/ext/standard/type.h deleted file mode 100644 index c5c4ae6b36..0000000000 --- a/ext/standard/type.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -#ifndef _TYPE_H -#define _TYPE_H - -extern int php_check_type(char *str); -extern int php_check_ident_type(char *str); -extern char *php_get_ident_index(char *str); - -#define GPC_REGULAR 0x1 -#define GPC_INDEXED_ARRAY 0x2 -#define GPC_NON_INDEXED_ARRAY 0x4 -#define GPC_ARRAY (GPC_INDEXED_ARRAY | GPC_NON_INDEXED_ARRAY) - -#endif diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c deleted file mode 100644 index 0280599a31..0000000000 --- a/ext/standard/uniqid.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@guardian.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" - -#define MORE_ENTROPY (argc == 2 && (*flags)->value.lval) - -/* {{{ proto string uniqid(string prefix, [bool more_entropy]) - Generate a unique id */ -PHP_FUNCTION(uniqid) -{ -#ifdef HAVE_GETTIMEOFDAY - pval **prefix, **flags; - char uniqid[138]; - int sec, usec, argc; - struct timeval tv; - - argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &prefix, &flags)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(prefix); - if (argc == 2) { - convert_to_boolean_ex(flags); - } - - /* Do some bounds checking since we are using a char array. */ - if ((*prefix)->value.str.len > 114) { - php_error(E_WARNING, "The prefix to uniqid should not be more than 114 characters."); - return; - } -#if HAVE_USLEEP && !defined(PHP_WIN32) - if (!MORE_ENTROPY) { - usleep(1); - } -#endif - gettimeofday((struct timeval *) &tv, (struct timezone *) NULL); - sec = (int) tv.tv_sec; - usec = (int) (tv.tv_usec % 1000000); - - /* The max value usec can have is 0xF423F, so we use only five hex - * digits for usecs. - */ - if (MORE_ENTROPY) { - sprintf(uniqid, "%s%08x%05x%.8f", (*prefix)->value.str.val, sec, usec, php_combined_lcg() * 10); - } else { - sprintf(uniqid, "%s%08x%05x", (*prefix)->value.str.val, sec, usec); - } - - RETURN_STRING(uniqid,1); -#endif -} -/* }}} */ - -function_entry uniqid_functions[] = { - PHP_FE(uniqid, NULL) - {NULL, NULL, NULL} -}; - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/uniqid.h b/ext/standard/uniqid.h deleted file mode 100644 index 3666e0a8c2..0000000000 --- a/ext/standard/uniqid.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Author: Stig Sæther Bakken <ssb@guardian.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _UNIQID_H -#define _UNIQID_H - -PHP_FUNCTION(uniqid); - -#endif /* _UNIQID_H */ diff --git a/ext/standard/url.c b/ext/standard/url.c deleted file mode 100644 index 9b159d8887..0000000000 --- a/ext/standard/url.c +++ /dev/null @@ -1,439 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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*/ - - -void free_url(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); -} - -url *url_parse(char *str) -{ - regex_t re; - regmatch_t subs[10]; - int err; - int length = strlen(str); - char *result; - - url *ret = (url *) emalloc(sizeof(url)); - if (!ret) { - /*php_error(E_WARNING,"Unable to allocate memory\n");*/ - return NULL; - } - memset(ret, 0, sizeof(url)); - - /* from Appendix B of draft-fielding-url-syntax-09, - http://www.ics.uci.edu/~fielding/url/url.txt */ - err = regcomp(&re, "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?", REG_EXTENDED); - if (err) { - /*php_error(E_WARNING,"Unable to compile regex: %d\n", err);*/ - efree(ret); - return NULL; - } - err = regexec(&re, str, 10, subs, 0); - if (err) { - /*php_error(E_WARNING,"Error with regex\n");*/ - efree(ret); - regfree(&re); - return NULL; - } - /* no processing necessary on the scheme */ - if (subs[2].rm_so != -1 && subs[2].rm_so < length) { - ret->scheme = estrndup(str + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so); - } - - /* the path to the resource */ - if (subs[5].rm_so != -1 && subs[5].rm_so < length) { - ret->path = estrndup(str + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so); - } - - /* the query part */ - if (subs[7].rm_so != -1 && subs[7].rm_so < length) { - ret->query = estrndup(str + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so); - } - - /* the fragment */ - if (subs[9].rm_so != -1 && subs[9].rm_so < length) { - ret->fragment = estrndup(str + subs[9].rm_so, subs[9].rm_eo - subs[9].rm_so); - } - - /* extract the username, pass, and port from the hostname */ - if (subs[4].rm_so != -1 && subs[4].rm_so < length) { - - int cerr; - /* extract username:pass@host:port from regex results */ - result = estrndup(str + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so); - length = strlen(result); - - regfree(&re); /* free the old regex */ - - if ((cerr=regcomp(&re, "^(([^@:]+)(:([^@:]+))?@)?([^:@]+)(:([^:@]+))?", REG_EXTENDED)) - || (err=regexec(&re, result, 10, subs, 0))) { - STR_FREE(ret->scheme); - STR_FREE(ret->path); - STR_FREE(ret->query); - STR_FREE(ret->fragment); - efree(ret); - efree(result); - /*php_error(E_WARNING,"Unable to compile regex: %d\n", err);*/ - if (!cerr) regfree(&re); - return NULL; - } - /* now deal with all of the results */ - if (subs[2].rm_so != -1 && subs[2].rm_so < length) { - ret->user = estrndup(result + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so); - } - if (subs[4].rm_so != -1 && subs[4].rm_so < length) { - ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so); - } - if (subs[5].rm_so != -1 && subs[5].rm_so < length) { - ret->host = estrndup(result + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so); - } - if (subs[7].rm_so != -1 && subs[7].rm_so < length) { - ret->port = (unsigned short) strtol(result + subs[7].rm_so, NULL, 10); - } - efree(result); - } - else if (ret->scheme && !strcmp(ret->scheme, "http")) { - STR_FREE(ret->scheme); - STR_FREE(ret->path); - STR_FREE(ret->query); - STR_FREE(ret->fragment); - efree(ret); - regfree(&re); - return NULL; - } - regfree(&re); - return ret; -} - -/* {{{ proto array parse_url(string url) - Parse a URL and return its components */ -PHP_FUNCTION(parse_url) -{ - pval **str; - url *resource; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - resource = url_parse((*str)->value.str.val); - - if (resource == NULL) { - php_error(E_WARNING, "unable to parse url (%s)", (*str)->value.str.val); - RETURN_FALSE; - } - /* allocate an array for return */ - if (array_init(return_value) == FAILURE) { - free_url(resource); - RETURN_FALSE; - } - /* 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); - free_url(resource); -} -/* }}} */ - -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"; - -char *php_url_encode(char *s, int len) -{ - register int x, y; - unsigned char *str; - - str = (unsigned char *) emalloc(3 * strlen(s) + 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) { - 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'; - return ((char *) str); -} - -/* {{{ proto string urlencode(string str) - URL-encodes string */ -PHP_FUNCTION(urlencode) -{ - pval **arg; - char *str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - var_reset(return_value); - return; - } - str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len); - RETVAL_STRING(str, 1); - efree(str); -} -/* }}} */ - -/* {{{ proto string urldecode(string str) - Decodes URL-encoded string */ -PHP_FUNCTION(urldecode) -{ - pval **arg; - int len; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - var_reset(return_value); - return; - } - - *return_value = **arg; - zval_copy_ctor(return_value); - - len = php_url_decode(return_value->value.str.val, return_value->value.str.len); - return_value->value.str.len = len; -} -/* }}} */ - -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; -} - -char *php_raw_url_encode(char *s, int len) -{ - 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'; - return ((char *) str); -} - -/* {{{ proto string rawurlencode(string str) - URL-encodes string */ -PHP_FUNCTION(rawurlencode) -{ - pval **arg; - char *str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } - str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len); - RETVAL_STRING(str, 1); - efree(str); -} -/* }}} */ - -/* {{{ proto string rawurldecode(string str) - Decodes URL-encodes string */ -PHP_FUNCTION(rawurldecode) -{ - pval **arg; - int len; - char *str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } - str = estrndup(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)); - len = php_raw_url_decode(str, Z_STRLEN_PP(arg)); - - RETVAL_STRINGL(str, len, 0); -} -/* }}} */ - -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; -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/url.h b/ext/standard/url.h deleted file mode 100644 index 6b49640dd8..0000000000 --- a/ext/standard/url.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP HTML Embedded Scripting Language Version 3.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | - +----------------------------------------------------------------------+ - | This program is free software; you can redistribute it and/or modify | - | it under the terms of one of the following licenses: | - | | - | A) the GNU General Public License as published by the Free Software | - | Foundation; either version 2 of the License, or (at your option) | - | any later version. | - | | - | B) the PHP License as published by the PHP Development Team and | - | included in the distribution in the file: LICENSE | - | | - | This program 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 General Public License for more details. | - | | - | You should have received a copy of both licenses referred to here. | - | If you did not, or have any questions about PHP licensing, please | - | contact core@php.net. | - +----------------------------------------------------------------------+ - | Authors: Jim Winstead (jimw@php.net) | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#ifndef _URL_H -#define _URL_H - -typedef struct url { - char *scheme; - char *user; - char *pass; - char *host; - unsigned short port; - char *path; - char *query; - char *fragment; -} url; - -void free_url(url *); -extern url *url_parse(char *); -extern int php_url_decode(char *, int); /* return value: length of decoded string */ -extern char *php_url_encode(char *, int); -extern int php_raw_url_decode(char *, int); /* return value: length of decoded string */ -extern char *php_raw_url_encode(char *, int); - -PHP_FUNCTION(parse_url); -PHP_FUNCTION(urlencode); -PHP_FUNCTION(urldecode); -PHP_FUNCTION(rawurlencode); -PHP_FUNCTION(rawurldecode); - -#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 c5285bb996..0000000000 --- a/ext/standard/url_scanner.c +++ /dev/null @@ -1,535 +0,0 @@ -/* Generated by re2c 0.5 on Sat Nov 27 16:22:34 1999 */ -#line 1 "../../../php4/ext/standard/url_scanner.re" -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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" - -#ifdef TRANS_SID - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#undef MIN -#define MIN(a,b) (a)<(b)?(a):(b) - -#define YYCTYPE char -#define YYCURSOR state->crs -#define YYLIMIT state->end -#define YYMARKER state->ptr -#define YYFILL(n) - -typedef enum { - INITIAL, - REF -} state; - -typedef struct { - state state; - const char *crs; - const char *end; - const char *ptr; - const char *start; - char *target; - size_t targetsize; - const char *data; -} lexdata; - -#define FINISH { catchup(state); goto finish; } - -#define BEGIN(x) \ - switch(state->state) { \ - case INITIAL: \ - catchup(state); \ - break; \ - case REF: \ - screw_url(state); \ - break; \ - } \ - state->state = x; \ - state->start = state->crs; \ - goto nextiter - -#define ATTACH(s, n) \ -{ \ - size_t _newlen = state->targetsize + n; \ - state->target = realloc(state->target, _newlen + 1); \ - memcpy(state->target + state->targetsize, s, n); \ - state->targetsize = _newlen; \ - state->target[_newlen] = '\0'; \ -} - -#define URLLEN 512 - -static void screw_url(lexdata *state) -{ - int len; - char buf[URLLEN]; - char url[URLLEN]; - const char *p, *q; - char c; - - /* search outer limits for URI */ - for(p = state->start; p < state->crs && (c = *p); p++) - if(c != '"' && c != ' ') break; - - /* - * we look at q-1, because q points to the character behind the last - * character we are going to copy and the decision is based on that last - * character - */ - - for(q = state->crs; q > state->start && (c = *(q-1)); q--) - if(c != '"' && c != ' ') break; - - /* attach beginning */ - - ATTACH(state->start, p-state->start); - - /* copy old URI */ - len = MIN(q - p, sizeof(buf) - 1); - memcpy(url, p, len); - url[len] = '\0'; - - /* construct new URI */ - len = snprintf(buf, sizeof(buf), "%s%c%s", url, - memchr(state->start, '?', len) ? '&' : '?', - state->data); - - /* attach new URI */ - ATTACH(buf, len); - - /* attach rest */ - ATTACH(q, state->crs - q); -} - -static void catchup(lexdata *state) -{ - ATTACH(state->start, (state->crs - state->start)); -} - -#line 144 - - -static void url_scanner(lexdata *state) -{ - while(state->crs < state->end) { - - switch(state->state) { - case INITIAL: -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy0; -yy1: ++YYCURSOR; -yy0: - if((YYLIMIT - YYCURSOR) < 7) YYFILL(7); - yych = *YYCURSOR; - switch(yych){ - case '\000': goto yy7; - case '<': goto yy2; - default: goto yy4; - } -yy2: yych = *++YYCURSOR; - switch(yych){ - case 'A': case 'a': goto yy9; - case 'F': case 'f': goto yy10; - default: goto yy3; - } -yy3:yy4: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy5: switch(yych){ - case '\000': case '<': goto yy6; - default: goto yy4; - } -yy6: -#line 157 - { BEGIN(INITIAL); } -yy7: yych = *++YYCURSOR; -yy8: -#line 158 - { FINISH; } -yy9: yych = *++YYCURSOR; - switch(yych){ - case 'H': case 'h': goto yy3; - case 'R': case 'r': goto yy41; - default: goto yy40; - } -yy10: yych = *++YYCURSOR; - switch(yych){ - case 'O': case 'o': goto yy12; - case 'R': case 'r': goto yy11; - default: goto yy3; - } -yy11: yych = *++YYCURSOR; - switch(yych){ - case 'A': case 'a': goto yy27; - default: goto yy3; - } -yy12: yych = *++YYCURSOR; - switch(yych){ - case 'R': case 'r': goto yy13; - default: goto yy3; - } -yy13: yych = *++YYCURSOR; - switch(yych){ - case 'M': case 'm': goto yy14; - default: goto yy3; - } -yy14: yych = *++YYCURSOR; - switch(yych){ - case 'A': case 'a': goto yy3; - default: goto yy16; - } -yy15: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy16: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy15; - case 'A': case 'a': goto yy17; - default: goto yy3; - } -yy17: yych = *++YYCURSOR; - switch(yych){ - case 'C': case 'c': goto yy18; - default: goto yy3; - } -yy18: yych = *++YYCURSOR; - switch(yych){ - case 'T': case 't': goto yy19; - default: goto yy3; - } -yy19: yych = *++YYCURSOR; - switch(yych){ - case 'I': case 'i': goto yy20; - default: goto yy3; - } -yy20: yych = *++YYCURSOR; - switch(yych){ - case 'O': case 'o': goto yy21; - default: goto yy3; - } -yy21: yych = *++YYCURSOR; - switch(yych){ - case 'N': case 'n': goto yy22; - default: goto yy3; - } -yy22: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy23: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy22; - case '=': goto yy24; - default: goto yy3; - } -yy24: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy25: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy24; - default: goto yy26; - } -yy26: -#line 155 - { BEGIN(REF); } -yy27: yych = *++YYCURSOR; - switch(yych){ - case 'M': case 'm': goto yy28; - default: goto yy3; - } -yy28: yych = *++YYCURSOR; - switch(yych){ - case 'E': case 'e': goto yy29; - default: goto yy3; - } -yy29: yych = *++YYCURSOR; - switch(yych){ - case 'S': case 's': goto yy3; - default: goto yy31; - } -yy30: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy31: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy30; - case 'S': case 's': goto yy32; - default: goto yy3; - } -yy32: yych = *++YYCURSOR; - switch(yych){ - case 'R': case 'r': goto yy33; - default: goto yy3; - } -yy33: yych = *++YYCURSOR; - switch(yych){ - case 'C': case 'c': goto yy34; - default: goto yy3; - } -yy34: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy35: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy34; - case '=': goto yy36; - default: goto yy3; - } -yy36: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy37: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy36; - default: goto yy38; - } -yy38: -#line 153 - { BEGIN(REF); } -yy39: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy40: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy39; - case 'H': case 'h': goto yy54; - default: goto yy3; - } -yy41: yych = *++YYCURSOR; - switch(yych){ - case 'E': case 'e': goto yy42; - default: goto yy3; - } -yy42: yych = *++YYCURSOR; - switch(yych){ - case 'A': case 'a': goto yy43; - default: goto yy3; - } -yy43: yych = *++YYCURSOR; - switch(yych){ - case 'H': case 'h': goto yy3; - default: goto yy45; - } -yy44: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy45: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy44; - case 'H': case 'h': goto yy46; - default: goto yy3; - } -yy46: yych = *++YYCURSOR; - switch(yych){ - case 'R': case 'r': goto yy47; - default: goto yy3; - } -yy47: yych = *++YYCURSOR; - switch(yych){ - case 'E': case 'e': goto yy48; - default: goto yy3; - } -yy48: yych = *++YYCURSOR; - switch(yych){ - case 'F': case 'f': goto yy49; - default: goto yy3; - } -yy49: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy50: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy49; - case '=': goto yy51; - default: goto yy3; - } -yy51: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy52: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy51; - default: goto yy53; - } -yy53: -#line 156 - { BEGIN(REF); } -yy54: yych = *++YYCURSOR; - switch(yych){ - case 'R': case 'r': goto yy55; - default: goto yy3; - } -yy55: yych = *++YYCURSOR; - switch(yych){ - case 'E': case 'e': goto yy56; - default: goto yy3; - } -yy56: yych = *++YYCURSOR; - switch(yych){ - case 'F': case 'f': goto yy57; - default: goto yy3; - } -yy57: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy58: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy57; - case '=': goto yy59; - default: goto yy3; - } -yy59: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy60: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy59; - default: goto yy61; - } -yy61: -#line 154 - { BEGIN(REF); } -} -#line 159 - - break; - case REF: -{ - YYCTYPE yych; - unsigned int yyaccept; - goto yy62; -yy63: ++YYCURSOR; -yy62: - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - switch(yych){ - case '\000': case '>': goto yy64; - case '\t': case '\v': - case '\f': case ' ': case '"': goto yy65; - case '#': goto yy69; - case ':': goto yy71; - default: goto yy67; - } -yy64: -#line 163 - { BEGIN(INITIAL); } -yy65: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy66: switch(yych){ - case '\000': case '>': goto yy64; - case '\t': case '\v': - case '\f': case ' ': goto yy65; - case '"': goto yy79; - case '#': goto yy69; - case ':': goto yy71; - default: goto yy67; - } -yy67: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy68: switch(yych){ - case '\000': case '>': goto yy64; - case '\t': case '\v': - case '\f': case ' ': goto yy77; - case '"': goto yy79; - case '#': goto yy69; - case ':': goto yy71; - default: goto yy67; - } -yy69: yych = *++YYCURSOR; -yy70: YYCURSOR -= 1; -#line 164 - { BEGIN(INITIAL); } -yy71: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy72: switch(yych){ - case '\000': case '#': case '>': goto yy73; - case '\t': case '\v': - case '\f': case ' ': goto yy74; - case '"': goto yy76; - default: goto yy71; - } -yy73: -#line 165 - { - /* don't modify absolute links */ - state->state = INITIAL; BEGIN(INITIAL); - } -yy74: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy75: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy74; - case '"': goto yy76; - default: goto yy73; - } -yy76: yych = *++YYCURSOR; - goto yy73; -yy77: ++YYCURSOR; - if(YYLIMIT == YYCURSOR) YYFILL(1); - yych = *YYCURSOR; -yy78: switch(yych){ - case '\t': case '\v': - case '\f': case ' ': goto yy77; - case '"': goto yy79; - default: goto yy64; - } -yy79: yych = *++YYCURSOR; - goto yy64; -} -#line 169 - - break; - } -nextiter: - ; - } -finish: - ; -} - -char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen) -{ - lexdata state; - - state.state = INITIAL; - state.start = state.crs = src; - state.end = src + srclen; - state.ptr = NULL; - state.target = NULL; - state.targetsize = 0; - state.data = data; - - url_scanner(&state); - - if(newlen) *newlen = state.targetsize; - - return state.target; -} - -#endif diff --git a/ext/standard/url_scanner.h b/ext/standard/url_scanner.h deleted file mode 100644 index 3c0e7b29a5..0000000000 --- a/ext/standard/url_scanner.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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 - -char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen); - -#endif diff --git a/ext/standard/url_scanner.re b/ext/standard/url_scanner.re deleted file mode 100644 index dd40b9172c..0000000000 --- a/ext/standard/url_scanner.re +++ /dev/null @@ -1,198 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.0 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_0.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 "snprintf.h" - -#ifdef TRANS_SID - -#include <sys/types.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#undef MIN -#define MIN(a,b) (a)<(b)?(a):(b) - -#define YYCTYPE char -#define YYCURSOR state->crs -#define YYLIMIT state->end -#define YYMARKER state->ptr -#define YYFILL(n) - -typedef enum { - INITIAL, - REF -} state; - -typedef struct { - state state; - const char *crs; - const char *end; - const char *ptr; - const char *start; - char *target; - size_t targetsize; - const char *data; -} lexdata; - -#define FINISH { catchup(state); goto finish; } - -#define BEGIN(x) \ - switch(state->state) { \ - case INITIAL: \ - catchup(state); \ - break; \ - case REF: \ - screw_url(state); \ - break; \ - } \ - state->state = x; \ - state->start = state->crs; \ - goto nextiter - -#define ATTACH(s, n) \ -{ \ - size_t _newlen = state->targetsize + n; \ - state->target = realloc(state->target, _newlen + 1); \ - memcpy(state->target + state->targetsize, s, n); \ - state->targetsize = _newlen; \ - state->target[_newlen] = '\0'; \ -} - -#define URLLEN 512 - -static void screw_url(lexdata *state) -{ - int len; - char buf[URLLEN]; - char url[URLLEN]; - const char *p, *q; - char c; - - /* search outer limits for URI */ - for(p = state->start; p < state->crs && (c = *p); p++) - if(c != '"' && c != ' ') break; - - /* - * we look at q-1, because q points to the character behind the last - * character we are going to copy and the decision is based on that last - * character - */ - - for(q = state->crs; q > state->start && (c = *(q-1)); q--) - if(c != '"' && c != ' ') break; - - /* attach beginning */ - - ATTACH(state->start, p-state->start); - - /* copy old URI */ - len = MIN(q - p, sizeof(buf) - 1); - memcpy(url, p, len); - url[len] = '\0'; - - /* construct new URI */ - len = snprintf(buf, sizeof(buf), "%s%c%s", url, - memchr(state->start, '?', len) ? '&' : '?', - state->data); - - /* attach new URI */ - ATTACH(buf, len); - - /* attach rest */ - ATTACH(q, state->crs - q); -} - -static void catchup(lexdata *state) -{ - ATTACH(state->start, (state->crs - state->start)); -} - -/*!re2c -all = [\001-\377]; -eof = [\000]; -ws = [ \t\v\f]; -A = [aA]; -C = [cC]; -E = [eE]; -F = [fF]; -H = [hH]; -I = [iI]; -M = [mM]; -N = [nN]; -O = [oO]; -R = [rR]; -S = [sS]; -T = [tT]; -*/ - -static void url_scanner(lexdata *state) -{ - while(state->crs < state->end) { - - switch(state->state) { - case INITIAL: -/*!re2c - "<" F R A M E ws+ S R C ws* "=" ws* { BEGIN(REF); } - "<" A ws+ H R E F ws* "=" ws* { BEGIN(REF); } - "<" F O R M ws+ A C T I O N ws* "=" ws* { BEGIN(REF); } - "<" A R E A ws+ H R E F ws* "=" ws* { BEGIN(REF); } - (all\[<])+ { BEGIN(INITIAL); } - eof { FINISH; } -*/ - break; - case REF: -/*!re2c - ["]? ws* (all\[> \t\v\f":#])* ws* ["]? { BEGIN(INITIAL); } - ["]? ws* (all\[> \t\v\f":#])* /[#] { BEGIN(INITIAL); } - ["]? ws* (all\[> \t\v\f"#])* ws* ["]? { - /* don't modify absolute links */ - state->state = INITIAL; BEGIN(INITIAL); - } -*/ - break; - } -nextiter: - ; - } -finish: - ; -} - -char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen) -{ - lexdata state; - - state.state = INITIAL; - state.start = state.crs = src; - state.end = src + srclen; - state.ptr = NULL; - state.target = NULL; - state.targetsize = 0; - state.data = data; - - url_scanner(&state); - - if(newlen) *newlen = state.targetsize; - - return state.target; -} - -#endif diff --git a/ext/standard/var.c b/ext/standard/var.c deleted file mode 100644 index 5b342471a6..0000000000 --- a/ext/standard/var.c +++ /dev/null @@ -1,586 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999, 2000 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@digicol.de> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -/* {{{ includes -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "php.h" -#include "php_string.h" -#include "php_var.h" - -#define COMMON ((*struc)->is_ref?"&":"") - -/* }}} */ -/* {{{ php_var_dump */ - -static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key) -{ - int level; - - 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); - return 0; -} - - -void php_var_dump(pval **struc, int level) -{ - HashTable *myht; - - if (level>1) { - php_printf("%*c", level-1, ' '); - } - - switch ((*struc)->type) { - case IS_BOOL: - php_printf("%sbool(%s)\n", COMMON, ((*struc)->value.lval?"true":"false")); - break; - case IS_NULL: - php_printf("%sNULL\n", COMMON); - break; - case IS_LONG: - php_printf("%sint(%ld)\n", COMMON, (*struc)->value.lval); - break; - case IS_DOUBLE: { - ELS_FETCH(); - - php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), (*struc)->value.dval); - } - break; - case IS_STRING: - php_printf("%sstring(%d) \"", COMMON, (*struc)->value.str.len); - PHPWRITE((*struc)->value.str.val, (*struc)->value.str.len); - PUTS("\"\n"); - break; - case IS_ARRAY: - myht = HASH_OF(*struc); - php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht)); - goto head_done; - case IS_OBJECT: - myht = HASH_OF(*struc); - php_printf("%sobject(%s)(%d) {\n", COMMON, (*struc)->value.obj.ce->name, zend_hash_num_elements(myht)); -head_done: - zend_hash_apply_with_arguments(myht, php_array_element_dump, 1, level); - if (level>1) { - php_printf("%*c\n", level-1, ' '); - } - PUTS("}\n"); - break; - case IS_RESOURCE: { - int type; - zend_list_find((*struc)->value.lval, &type); - php_printf("%sresource(%ld) of type %d\n", COMMON, (*struc)->value.lval, type); - 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); - - efree(args); -} -/* }}} */ - - -/* {{{ php_var_dump */ - - -#define STR_CAT(P,S,I) {\ - pval *__p = (P);\ - ulong __i = __p->value.str.len;\ - __p->value.str.len += (I);\ - if (__p->value.str.val) {\ - __p->value.str.val = (char *)erealloc(__p->value.str.val, __p->value.str.len + 1);\ - } else {\ - __p->value.str.val = emalloc(__p->value.str.len + 1);\ - *__p->value.str.val = 0;\ - }\ - strcat(__p->value.str.val + __i, (S));\ -} - -/* }}} */ -/* {{{ php_var_serialize */ - -void php_var_serialize(pval *buf, pval **struc) -{ - char s[256]; - ulong slen; - int i; - HashTable *myht; - - switch ((*struc)->type) { - case IS_BOOL: - slen = sprintf(s, "b:%ld;", (*struc)->value.lval); - STR_CAT(buf, s, slen); - return; - - case IS_NULL: - STR_CAT(buf, "N;", 2); - return; - - case IS_LONG: - slen = sprintf(s, "i:%ld;", (*struc)->value.lval); - STR_CAT(buf, s, slen); - return; - - case IS_DOUBLE: { - ELS_FETCH(); - slen = sprintf(s, "d:%.*G;",(int) EG(precision), (*struc)->value.dval); - STR_CAT(buf, s, slen); - } - return; - - case IS_STRING:{ - char *p; - - i = buf->value.str.len; - slen = sprintf(s, "s:%d:\"", (*struc)->value.str.len); - STR_CAT(buf, s, slen + (*struc)->value.str.len + 2); - p = buf->value.str.val + i + slen; - if ((*struc)->value.str.len > 0) { - memcpy(p, (*struc)->value.str.val, (*struc)->value.str.len); - p += (*struc)->value.str.len; - } - *p++ = '\"'; - *p++ = ';'; - *p = 0; - } - return; - - case IS_OBJECT: { - zval *retval_ptr; - zval *fname; - int res; - CLS_FETCH(); - - MAKE_STD_ZVAL(fname); - ZVAL_STRING(fname,"__sleep",1); - - res = call_user_function_ex(CG(function_table), *struc, fname, &retval_ptr, 0, 0, 1); - - if ((res == SUCCESS)) { - if (retval_ptr && HASH_OF(retval_ptr)) { - int count = zend_hash_num_elements(HASH_OF(retval_ptr)); - slen = sprintf(s, "O:%d:\"%s\":%d:{",(*struc)->value.obj.ce->name_length,(*struc)->value.obj.ce->name, count); - STR_CAT(buf, s, slen); - if (count > 0) { - char *key; - zval **d,**name; - ulong index; - - zend_hash_internal_pointer_reset(HASH_OF(retval_ptr)); - for (;; zend_hash_move_forward(HASH_OF(retval_ptr))) { - if ((i = zend_hash_get_current_key(HASH_OF(retval_ptr), &key, &index)) == HASH_KEY_NON_EXISTANT) { - break; - } - - zend_hash_get_current_data(HASH_OF(retval_ptr), (void **) (&name)); - - if ((*name)->type != IS_STRING) { - php_error(E_NOTICE, "_sleep_ should return an array only containing the names of instance-variables to serialize."); - continue; - } - - php_var_serialize(buf, name); - - if (zend_hash_find((*struc)->value.obj.properties,(*name)->value.str.val,(*name)->value.str.len+1,(void*)&d) == SUCCESS) { - php_var_serialize(buf,d); - } - } - } - STR_CAT(buf, "}", 1); - } - } else { - zval_dtor(fname); - FREE_ZVAL(fname); - - if (retval_ptr) { - zval_dtor(retval_ptr); - FREE_ZVAL(retval_ptr); - } - goto std_array; - } - - zval_dtor(fname); - FREE_ZVAL(fname); - - if (retval_ptr) { - zval_dtor(retval_ptr); - FREE_ZVAL(retval_ptr); - } - return; - } - - case IS_ARRAY: - std_array: - myht = HASH_OF(*struc); - i = zend_hash_num_elements(myht); - if ((*struc)->type == IS_ARRAY) { - slen = sprintf(s, "a:%d:{", i); - } else { - slen = sprintf(s, "O:%d:\"%s\":%d:{",(*struc)->value.obj.ce->name_length,(*struc)->value.obj.ce->name, i); - } - STR_CAT(buf, s, slen); - if (i > 0) { - char *key; - pval **data,*d; - ulong index; - - zend_hash_internal_pointer_reset(myht); - for (;; zend_hash_move_forward(myht)) { - if ((i = zend_hash_get_current_key(myht, &key, &index)) == HASH_KEY_NON_EXISTANT) { - break; - } - if (zend_hash_get_current_data(myht, (void **) (&data)) != SUCCESS || !data || ((*data) == (*struc))) { - if (i == HASH_KEY_IS_STRING) - efree(key); - continue; - } - - switch (i) { - case HASH_KEY_IS_LONG: - MAKE_STD_ZVAL(d); - d->type = IS_LONG; - d->value.lval = index; - php_var_serialize(buf, &d); - FREE_ZVAL(d); - break; - case HASH_KEY_IS_STRING: - MAKE_STD_ZVAL(d); - d->type = IS_STRING; - d->value.str.val = key; - d->value.str.len = strlen(key); - php_var_serialize(buf, &d); - efree(key); - FREE_ZVAL(d); - break; - } - php_var_serialize(buf, data); - } - } - STR_CAT(buf, "}", 1); - return; - - default: - STR_CAT(buf, "i:0;", 4); - return; - } -} - -/* }}} */ -/* {{{ php_var_dump */ - -int php_var_unserialize(pval **rval, const char **p, const char *max) -{ - const char *q; - char *str; - int i; - char cur; - HashTable *myht; - ELS_FETCH(); - - switch (cur = **p) { - case 'N': - if (*((*p) + 1) != ';') { - return 0; - } - (*p)++; - INIT_PZVAL(*rval); - (*rval)->type = IS_NULL; - (*p)++; - return 1; - - case 'b': /* bool */ - case 'i': - if (*((*p) + 1) != ':') { - return 0; - } - q = *p; - while (**p && **p != ';') { - (*p)++; - } - if (**p != ';') { - return 0; - } - (*p)++; - if (cur == 'b') { - (*rval)->type = IS_BOOL; - } else { - (*rval)->type = IS_LONG; - } - INIT_PZVAL(*rval); - (*rval)->value.lval = atol(q + 2); - return 1; - - case 'd': - if (*((*p) + 1) != ':') { - return 0; - } - q = *p; - while (**p && **p != ';') { - (*p)++; - } - if (**p != ';') { - return 0; - } - (*p)++; - (*rval)->type = IS_DOUBLE; - INIT_PZVAL(*rval); - (*rval)->value.dval = atof(q + 2); - return 1; - - case 's': - if (*((*p) + 1) != ':') { - return 0; - } - (*p) += 2; - q = *p; - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':') { - return 0; - } - i = atoi(q); - if (i < 0 || (*p + 3 + i) > max || *((*p) + 1) != '\"' || - *((*p) + 2 + i) != '\"' || *((*p) + 3 + i) != ';') { - return 0; - } - (*p) += 2; - - if (i == 0) { - str = empty_string; - } else { - str = estrndup(*p,i); - } - (*p) += i + 2; - (*rval)->type = IS_STRING; - (*rval)->value.str.val = str; - (*rval)->value.str.len = i; - INIT_PZVAL(*rval); - return 1; - - case 'a': - case 'o': - case 'O': - INIT_PZVAL(*rval); - - if (cur == 'a') { - (*rval)->type = IS_ARRAY; - ALLOC_HASHTABLE((*rval)->value.ht); - myht = (*rval)->value.ht; - } else { - zend_class_entry *ce; - - if (cur == 'O') { /* php4 serialized - we get the class-name */ - char *class_name; - - if (*((*p) + 1) != ':') { - return 0; - } - (*p) += 2; - q = *p; - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':') { - return 0; - } - i = atoi(q); - if (i < 0 || (*p + 3 + i) > max || *((*p) + 1) != '\"' || - *((*p) + 2 + i) != '\"' || *((*p) + 3 + i) != ':') { - return 0; - } - (*p) += 2; - class_name = emalloc(i + 1); - if (i > 0) { - memcpy(class_name, *p, i); - } - class_name[i] = 0; - (*p) += i; - - if (zend_hash_find(EG(class_table), class_name, i+1, (void **) &ce)==FAILURE) { - php_error(E_NOTICE, "Unserializing non-existant class: %s! No methods will be available!", class_name); - ce = &zend_standard_class_def; - } - - efree(class_name); - } else { /* old php 3.0 data 'o' */ - ce = &zend_standard_class_def; - } - - object_init_ex(*rval,ce); - myht = (*rval)->value.obj.properties; - } - - (*p) += 2; - i = atoi(*p); - - if (cur == 'a') { /* object_init_ex will init the HashTable for objects! */ - zend_hash_init(myht, i + 1, NULL, ZVAL_PTR_DTOR, 0); - } - - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':' || *((*p) + 1) != '{') { - return 0; - } - for ((*p) += 2; **p && **p != '}' && i > 0; i--) { - pval *key; - pval *data; - - ALLOC_INIT_ZVAL(key); - ALLOC_INIT_ZVAL(data); - - if (!php_var_unserialize(&key, p, max)) { - zval_dtor(key); - FREE_ZVAL(key); - FREE_ZVAL(data); - return 0; - } - if (!php_var_unserialize(&data, p, max)) { - zval_dtor(key); - FREE_ZVAL(key); - zval_dtor(data); - FREE_ZVAL(data); - return 0; - } - switch (key->type) { - case IS_LONG: - zend_hash_index_update(myht, key->value.lval, &data, sizeof(data), NULL); - break; - case IS_STRING: - zend_hash_update(myht, key->value.str.val, key->value.str.len + 1, &data, sizeof(data), NULL); - break; - } - zval_dtor(key); - FREE_ZVAL(key); - } - - if ((*rval)->type == IS_OBJECT) { - zval *retval_ptr; - zval *fname; - CLS_FETCH(); - - MAKE_STD_ZVAL(fname); - ZVAL_STRING(fname,"__wakeup",1); - - call_user_function_ex(CG(function_table), *rval, fname, &retval_ptr, 0, 0, 1); - - zval_dtor(fname); - FREE_ZVAL(fname); - } - - return *((*p)++) == '}'; - } - - return 0; -} - -/* }}} */ -/* {{{ proto string serialize(mixed variable) - Returns a string representation of variable (which can later be unserialized) */ -PHP_FUNCTION(serialize) -{ - pval **struc; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &struc) == FAILURE) { - WRONG_PARAM_COUNT; - } - return_value->type = IS_STRING; - return_value->value.str.val = NULL; - return_value->value.str.len = 0; - php_var_serialize(return_value, struc); -} - -/* }}} */ -/* {{{ proto mixed unserialize(string variable_representation) - Takes a string representation of variable and recreates it */ - - -PHP_FUNCTION(unserialize) -{ - pval **buf; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buf) == FAILURE) { - WRONG_PARAM_COUNT; - } - - if ((*buf)->type == IS_STRING) { - const char *p = (*buf)->value.str.val; - - if ((*buf)->value.str.len == 0) { - RETURN_FALSE; - } - - if (!php_var_unserialize(&return_value, &p, p + (*buf)->value.str.len)) { - zval_dtor(return_value); - php_error(E_NOTICE, "unserialize() failed at offset %d of %d bytes",p-(*buf)->value.str.val,(*buf)->value.str.len); - RETURN_FALSE; - } - } else { - php_error(E_NOTICE, "argument passed to unserialize() is not an string"); - RETURN_FALSE; - } -} - -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ |