diff options
Diffstat (limited to 'ext/standard')
94 files changed, 0 insertions, 25800 deletions
diff --git a/ext/standard/Makefile.am b/ext/standard/Makefile.am deleted file mode 100644 index 6191a23f2a..0000000000 --- a/ext/standard/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -## Process this file with automake to produce Makefile.in -noinst_LTLIBRARIES=libphpext_standard.la -libphpext_standard_la_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.y post.c quot_print.c rand.c reg.c soundex.c string.c \ - syslog.c type.c uniqid.c url.c url_scanner.c var.c output.c assert.c - -$(srcdir)/url_scanner.c: $(srcdir)/url_scanner.re - -re2c $< > $@.new && mv $@.new $@ - -#number.o: number.c -# $(CC) $(CFLAGS) -w@WARNING_LEVEL@ -c $< -o $@ diff --git a/ext/standard/array.c b/ext/standard/array.c deleted file mode 100644 index cec2d13a68..0000000000 --- a/ext/standard/array.c +++ /dev/null @@ -1,2068 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -#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 -#if WIN32|WINNT -#include "win32/unistd.h" -#endif -#include "zend_globals.h" -#include "php_globals.h" -#include "php_array.h" -#include "basic_functions.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 - -static unsigned char all_args_force_ref[] = { 1, BYREF_FORCE_REST }; - -function_entry array_functions[] = { - PHP_FE(ksort, first_arg_force_ref) - PHP_FE(krsort, 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(multisort, all_args_force_ref) - 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_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) - - /* Aliases */ - PHP_FALIAS(pos, current, first_arg_force_ref) - PHP_FALIAS(sizeof, count, first_arg_allow_ref) - - {NULL, NULL, NULL} -}; - -zend_module_entry array_module_entry = { - "Array Functions", /* extension name */ - array_functions, /* function list */ - PHP_MINIT(array), /* process startup */ - PHP_MSHUTDOWN(array), /* process shutdown */ - NULL, /* request startup */ - NULL, /* request shutdown */ - NULL, /* extension info */ - STANDARD_MODULE_PROPERTIES -}; - -PHP_MINIT_FUNCTION(array) -{ - ELS_FETCH(); - -#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); - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(array) -{ -#ifdef ZTS - ts_free_id(array_globals_id); -#endif - - return SUCCESS; -} - -static int array_key_compare(const void *a, const void *b) -{ - Bucket *f; - Bucket *s; - pval result; - pval first; - pval second; - - 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 (compare_function(&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; -} - -PHP_FUNCTION(krsort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in krsort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_reverse_key_compare, 0) == FAILURE) { - return; - } - RETURN_TRUE; -} - -PHP_FUNCTION(ksort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in ksort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_key_compare,0) == FAILURE) { - return; - } - RETURN_TRUE; -} - - -PHP_FUNCTION(count) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - if ((*array)->type == IS_STRING && (*array)->value.str.val==undefined_variable_string) { - 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; - - f = *((Bucket **) a); - s = *((Bucket **) b); - - first = *((pval **) f->pData); - second = *((pval **) s->pData); - - if (compare_function(&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; -} - -PHP_FUNCTION(asort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in asort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_data_compare,0) == FAILURE) { - return; - } - RETURN_TRUE; -} - -PHP_FUNCTION(arsort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in arsort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare,0) == FAILURE) { - return; - } - RETURN_TRUE; -} - -PHP_FUNCTION(sort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in sort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_data_compare,1) == FAILURE) { - return; - } - RETURN_TRUE; -} - -PHP_FUNCTION(rsort) -{ - pval **array; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - php_error(E_WARNING, "Wrong datatype in rsort() call"); - return; - } - if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare,1) == FAILURE) { - return; - } - RETURN_TRUE; -} - - -static int array_user_compare(const void *a, const void *b) -{ - Bucket *f; - Bucket *s; - pval **args[2]; - pval retval; - 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, 2, args, 0)==SUCCESS) { - convert_to_long(&retval); - return retval.value.lval; - } else { - return 0; - } -} - - -PHP_FUNCTION(usort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - old_compare_func = BG(user_compare_func_name); - if (ARG_COUNT(ht) != 2 || getParametersEx(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; - } - convert_to_string_ex(BG(user_compare_func_name)); - if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - return; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} - -PHP_FUNCTION(uasort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - old_compare_func = BG(user_compare_func_name); - if (ARG_COUNT(ht) != 2 || getParametersEx(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; - } - convert_to_string_ex(BG(user_compare_func_name)); - if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - return; - } - 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; - 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; - 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; - } -} - - -PHP_FUNCTION(uksort) -{ - pval **array; - pval **old_compare_func; - HashTable *target_hash; - BLS_FETCH(); - - old_compare_func = BG(user_compare_func_name); - if (ARG_COUNT(ht) != 2 || getParametersEx(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; - } - convert_to_string_ex(BG(user_compare_func_name)); - if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == FAILURE) { - BG(user_compare_func_name) = old_compare_func; - return; - } - BG(user_compare_func_name) = old_compare_func; - RETURN_TRUE; -} - -PHP_FUNCTION(end) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - } - 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); - } -} - - -PHP_FUNCTION(prev) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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); - } -} - - -PHP_FUNCTION(next) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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); - } -} - - -PHP_FUNCTION(reset) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - } - 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); - } -} - -PHP_FUNCTION(current) -{ - pval **array, **entry; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - } - if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) { - return; - } - *return_value = **entry; - zval_copy_ctor(return_value); -} - - -PHP_FUNCTION(key) -{ - pval **array; - char *string_key; - ulong num_key; - HashTable *target_hash; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - } - 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; - } -} - - -PHP_FUNCTION(min) -{ - int argc=ARG_COUNT(ht); - pval **result; - - if (argc<=0) { - php_error(E_WARNING, "min: must be passed at least 1 value"); - var_uninit(return_value); - return; - } - if (argc == 1) { - pval **arr; - - if (getParametersEx(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 **)*ARG_COUNT(ht)); - pval **min, result; - int i; - - if (getParametersArrayEx(ARG_COUNT(ht), args)==FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - min = args[0]; - - for (i=1; i<ARG_COUNT(ht); 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); - } -} - - -PHP_FUNCTION(max) -{ - int argc=ARG_COUNT(ht); - pval **result; - - if (argc<=0) { - php_error(E_WARNING, "max: must be passed at least 1 value"); - var_uninit(return_value); - return; - } - if (argc == 1) { - pval **arr; - - if (getParametersEx(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 **)*ARG_COUNT(ht)); - pval **max, result; - int i; - - if (getParametersArrayEx(ARG_COUNT(ht), args)==FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - max = args[0]; - - for (i=1; i<ARG_COUNT(ht); 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, /* 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; - - /* 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 */ - call_user_function_ex(CG(function_table), NULL, *BG(array_walk_func_name), - &retval, userdata ? 3 : 2, args, 0); - - /* 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 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 = ARG_COUNT(ht); - old_walk_func_name = BG(array_walk_func_name); - if (argc < 2 || argc > 3 || - getParametersEx(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; - } - 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) - Checks if the given value exists in the array */ -PHP_FUNCTION(in_array) -{ - zval **value, /* value to check for */ - **array, /* array to check in */ - **entry_ptr, /* pointer to array entry */ - *entry, /* actual array entry */ - res; /* comparison result */ - HashTable *target_hash; /* array hashtable */ - - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &value, &array) == 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; - } - - if ((*array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype for second argument in call to in_array()"); - return; - } - - target_hash = HASH_OF(*array); - zend_hash_internal_pointer_reset(target_hash); - while(zend_hash_get_current_data(target_hash, (void **)&entry_ptr) == SUCCESS) { - entry = *entry_ptr; - is_equal_function(&res, *value, entry); - if (zval_is_true(&res)) { - 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, *exist, *data; - char *varname, *finalname; - ulong lkey; - int res, extype; - ELS_FETCH(); - - switch(ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1, &var_array) == FAILURE) { - WRONG_PARAM_COUNT; - } - extype = EXTR_OVERWRITE; - break; - - case 2: - if (getParametersEx(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 (getParametersEx(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; - } - - if ((*var_array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype in call to extract()"); - return; - } - - 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_find(EG(active_symbol_table), - varname, strlen(varname)+1, (void**)&exist); - switch (extype) { - case EXTR_OVERWRITE: - finalname = estrdup(varname); - break; - - case EXTR_PREFIX_SAME: - if (res != SUCCESS) - 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 != SUCCESS) - 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; - data = (zval *)emalloc(sizeof(zval)); - *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(string var_name | array var_names [, ... ]) - Creates a hash containing variables and their values */ -PHP_FUNCTION(compact) -{ - zval ***args; /* function arguments array */ - int i; - ELS_FETCH(); - - args = (zval ***)emalloc(ARG_COUNT(ht) * sizeof(zval **)); - - if (getParametersArrayEx(ARG_COUNT(ht), args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - array_init(return_value); - - for (i=0; i<ARG_COUNT(ht); 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 (ARG_COUNT(ht) != 2 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if ((*array)->type != IS_ARRAY) { - php_error(E_WARNING, "Wrong datatype in shuffle() call"); - return; - } - if (zend_hash_sort((*array)->value.ht, (sort_func_t)mergesort, array_data_shuffle, 1) == FAILURE) { - return; - } - RETURN_TRUE; -} -/* }}} */ - - -/* HashTable* _phpi_splice(HashTable *in_hash, int offset, int length, - zval ***list, int list_count, HashTable **removed) */ -HashTable* _phpi_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, PVAL_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 = ARG_COUNT(ht); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (getParametersArrayEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 = _phpi_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 = ARG_COUNT(ht); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (getParametersArrayEx(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 = _phpi_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 = ARG_COUNT(ht); - 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 (getParametersArrayEx(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 = _phpi_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 = ARG_COUNT(ht); - if (argc < 2 || argc > 3 || getParametersEx(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); - } -} -/* }}} */ - - -/* {{{ proto array array_merge(array arr1, array arr2 [, ...]) - Merges elements from passed arrays into one array */ -PHP_FUNCTION(array_merge) -{ - zval ***args = NULL, - **entry; - HashTable *hash; - int argc, - i; - char *string_key; - ulong num_key; - - /* Get the argument count and check it */ - argc = ARG_COUNT(ht); - if (argc < 2) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (getParametersArrayEx(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - array_init(return_value); - - for (i=0; i<argc; i++) { - if ((*args[i])->type != IS_ARRAY) { - php_error(E_WARNING, "Skipping argument #%d to array_merge(), since it's not an array", i+1); - continue; - } - hash = (*args[i])->value.ht; - - zend_hash_internal_pointer_reset(hash); - while(zend_hash_get_current_data(hash, (void **)&entry) == SUCCESS) { - (*entry)->refcount++; - - switch (zend_hash_get_current_key(hash, &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_forward(hash); - } - } - - efree(args); -} -/* }}} */ - - -/* {{{ 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 (ARG_COUNT(ht) < 1 || ARG_COUNT(ht) > 2 || - getParametersEx(ARG_COUNT(ht), &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 (ARG_COUNT(ht) != 1 || getParametersEx(ARG_COUNT(ht), &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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 3 || getParametersEx(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 = _phpi_splice(return_value->value.ht, input_size, 0, pads, num_pads, NULL); - else - new_hash = _phpi_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 (ARG_COUNT(ht) != 1 || getParametersEx(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; - - r = 0; - do { - compare_function(&temp, *((zval **)ab[r]->pData), *((zval **)bb[r]->pData)); - result = temp.value.lval; - if (result != 0) - return result; - r++; - } while (ab[r] != NULL); - return result; -} - -PHP_FUNCTION(multisort) -{ - zval*** args; - Bucket*** indirect; - Bucket* p; - HashTable* hash; - int argc; - int array_size; - int i, k; - - /* Get the argument count and check it */ - argc = ARG_COUNT(ht); - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - /* Allocate arguments array and get the arguments, checking for errors. */ - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (getParametersArrayEx(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - for (i = 0; i < argc; i++) { - if ((*args[i])->type != IS_ARRAY) { - php_error(E_WARNING, "Argument %i to %s() is not an array", i+1, - get_active_function_name()); - efree(args); - return; - } - } - - /* Make sure the arrays are of the same size */ - array_size = zend_hash_num_elements((*args[0])->value.ht); - for (i = 0; i < argc; i++) { - if (zend_hash_num_elements((*args[i])->value.ht) != array_size) { - php_error(E_WARNING, "Array sizes are inconsistent"); - efree(args); - return; - } - } - - /* Create the indirection array */ - indirect = (Bucket ***)emalloc(array_size * sizeof(Bucket **)); - for (i = 0; i < array_size; i++) - indirect[i] = (Bucket **)emalloc((argc+1) * sizeof(Bucket *)); - - for (i = 0; i < argc; i++) { - k = 0; - for (p = (*args[i])->value.ht->pListHead; p; p = p->pListNext, k++) { - indirect[k][i] = p; - } - } - for (k = 0; k < array_size; k++) - indirect[k][argc] = NULL; - - /* Do the actual sort */ - qsort(indirect, array_size, sizeof(Bucket **), multisort_compare); - - /* Restructure the arrays based on sorted indirect */ - HANDLE_BLOCK_INTERRUPTIONS(); - for (i = 0; i < argc; i++) { - hash = (*args[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(args); -} diff --git a/ext/standard/assert.c b/ext/standard/assert.c deleted file mode 100644 index 87d5222679..0000000000 --- a/ext/standard/assert.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* {{{ includes/startup/misc */ - -#include "php.h" -#include "php_assert.h" -#include "php_ini.h" - -typedef struct { - int active; - int bail; - int warning; - int 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):"") - -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); - -static zend_function_entry php_assert_functions[] = { - PHP_FE(assert, NULL) - PHP_FE(assert_options, NULL) - {NULL, NULL, NULL} -}; - - -zend_module_entry assert_module_entry = { - "Assertion", - php_assert_functions, - PHP_MINIT(assert), - PHP_MSHUTDOWN(assert), - PHP_RINIT(assert), - PHP_RSHUTDOWN(assert), - PHP_MINFO(assert), - STANDARD_MODULE_PROPERTIES -}; - -#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", "0", 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 - ELS_FETCH(); - 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(); - ELS_FETCH(); - ASSERTLS_FETCH(); - - if (! ASSERT(active)) { - RETURN_TRUE; - } - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - } - - zend_eval_string(myeval, &retval CLS_CC ELS_CC); - - 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 = ARG_COUNT(ht); - ASSERTLS_FETCH(); - - if (ac < 1 || ac > 2 || getParametersEx(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 fcec86bbba..0000000000 --- a/ext/standard/base64.c +++ /dev/null @@ -1,193 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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 *_php3_base64_encode(const unsigned char *string, int length, int *ret_length) { - const unsigned char *current = string; - 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 *_php3_base64_decode(const unsigned char *string, int length, int *ret_length) { - const unsigned char *current = string; - 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 / 4 * 3 + 1) * sizeof(char)); - if (result == NULL) { - return NULL; - } - - /* run through the whole string, converting as we go */ - while ((ch = *current++) != '\0') { - if (ch == base64_pad) break; - 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 **string; - unsigned char *result; - int ret_length; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1,&string) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(string); - result = _php3_base64_encode((*string)->value.str.val, (*string)->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 **string; - unsigned char *result; - int ret_length; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1,&string) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(string); - result = _php3_base64_decode((*string)->value.str.val, (*string)->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 b71898dac3..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 *_php3_base64_encode(const unsigned char *, int, int *); -extern unsigned char *_php3_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 360784df4a..0000000000 --- a/ext/standard/basic_functions.c +++ /dev/null @@ -1,1527 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - - -#include "php.h" -#include "main.h" -#include "php_ini.h" -#include "internal_functions_registry.h" -#include "php_standard.h" -#include "zend_operators.h" -#include <stdarg.h> -#include <stdlib.h> -#include <math.h> -#include <time.h> -#include <stdio.h> -#include <netdb.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" -#if WIN32|WINNT -#include "win32/unistd.h" -#endif -#include "zend_globals.h" - -#include "php_globals.h" -#include "SAPI.h" - -#if APACHE -/* - ap_compat.h does a - #define md5 ap_md5 - which "kills" out md5 function. -*/ -#undef md5 -#endif - -#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 }; -/* uncomment this if/when we actually need it - tired of seeing the warning -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 int 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(toggle_short_open_tag, 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) -#endif - PHP_FE(strtotime, NULL) - PHP_FE(date, NULL) - PHP_FE(gmdate, NULL) - PHP_FE(getdate, 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_FE(md5, NULL) - - PHP_FE(iptcparse, NULL) - PHP_FE(iptcembed, NULL) - - PHP_FE(phpinfo, NULL) - PHP_FE(phpversion, NULL) - PHP_FE(phpcredits, 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(chunk_split, NULL) - PHP_FE(trim, NULL) - PHP_FE(ltrim, NULL) - PHP_FE(strip_tags, NULL) - PHP_FE(similar_text, NULL) - PHP_FE(explode, NULL) - PHP_FE(implode, NULL) - PHP_FE(setlocale, NULL) - PHP_FE(soundex, NULL) - PHP_FE(chr, NULL) - PHP_FE(ord, NULL) - PHP_FE(parse_str, NULL) - PHP_FALIAS(rtrim, chop, NULL) - PHP_FALIAS(strchr, strstr, NULL) - PHP_NAMED_FE(sprintf, php3_user_sprintf, NULL) - PHP_NAMED_FE(printf, php3_user_printf, 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 !(WIN32|WINNT)||HAVE_BINDLIB - PHP_FE(checkdnsrr, NULL) - PHP_FE(getmxrr, second_and_third_args_force_ref) -#endif - - PHP_FE(getmyuid, NULL) - PHP_FE(getmypid, NULL) - PHP_FE(getmyinode, NULL) - PHP_FE(getlastmod, NULL) - /*getmyiid is here for forward compatibility with 3.1 - See pageinfo.c in 3.1 for more information*/ - /* {"getmyiid", php3_getmypid, 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(getenv, NULL) -#ifdef HAVE_PUTENV - PHP_FE(putenv, NULL) -#endif - - PHP_FE(microtime, NULL) - PHP_FE(gettimeofday, NULL) - PHP_FE(getrusage, NULL) - - 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_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_NAMED_FE(show_source, php3_highlight_file, NULL) - PHP_FE(highlight_string, NULL) - - PHP_FE(ini_get, NULL) - PHP_FE(ini_alter, 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(function_exists, NULL) - - PHP_FE(connection_aborted, NULL) - PHP_FE(connection_timeout, NULL) - PHP_FE(connection_status, NULL) - PHP_FE(ignore_user_abort, NULL) - - {NULL, NULL, NULL} -}; - - -PHP_INI_BEGIN() - PHP_INI_ENTRY1("highlight.string", "#foobar", PHP_INI_ALL, NULL, NULL) - PHP_INI_ENTRY1("test2", "testing", PHP_INI_SYSTEM, NULL, NULL) -PHP_INI_END() - - -php3_module_entry basic_functions_module = { - "Basic Functions", /* 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 */ - NULL, /* extension info */ - STANDARD_MODULE_PROPERTIES -}; - -#if defined(HAVE_PUTENV) - -static int _php3_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); - return 1; -} -#endif - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -void test_class_startup(void); - -PHP_MINIT_FUNCTION(basic) -{ - ELS_FETCH(); -#ifdef ZTS - basic_globals_id = ts_allocate_id(sizeof(php_basic_globals), NULL, NULL); -#endif - - REGISTER_DOUBLE_CONSTANT("M_PI", M_PI, CONST_CS | CONST_PERSISTENT); - - test_class_startup(); - REGISTER_INI_ENTRIES(); - - register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU); - register_html_constants(INIT_FUNC_ARGS_PASSTHRU); - return SUCCESS; -} - - -PHP_MSHUTDOWN_FUNCTION(basic) -{ -#ifdef ZTS - ts_free_id(basic_globals_id); -#endif - - UNREGISTER_INI_ENTRIES(); - 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; -#ifdef HAVE_PUTENV - if (zend_hash_init(&BG(putenv_ht), 1, NULL, (int (*)(void *)) _php3_putenv_destructor, 0) == FAILURE) { - return FAILURE; - } -#endif - BG(user_shutdown_function_names)=NULL; - 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, ""); - } - STR_FREE(BG(locale_string)); - - return SUCCESS; -} - -/******************** - * System Functions * - ********************/ - -PHP_FUNCTION(getenv) -{ -#if FHTTPD - int i; -#endif - pval **str; - char *ptr; -#if APACHE - SLS_FETCH(); -#endif - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - -#if FHTTPD - ptr=NULL; - if ((*str)->type == IS_STRING && req){ - for(i=0;i<req->nlines;i++){ - if (req->lines[i].paramc>1){ - if (req->lines[i].params[0]){ - if (!strcmp(req->lines[i].params[0], - (*str)->value.str.val)){ - ptr=req->lines[i].params[1]; - i=req->nlines; - } - } - } - } - } - if (!ptr) ptr = getenv((*str)->value.str.val); - if (ptr -#else - - if ((*str)->type == IS_STRING && -#if APACHE - ((ptr = (char *)table_get(((request_rec *) SG(server_context))->subprocess_env, (*str)->value.str.val)) || (ptr = getenv((*str)->value.str.val))) -#endif -#if CGI_BINARY - (ptr = getenv((*str)->value.str.val)) -#endif - -#if USE_SAPI - (ptr = sapi_rqst->getenv(sapi_rqst->scid,(*str)->value.str.val)) -#endif -#endif - ) { - RETURN_STRING(ptr,1); - } - RETURN_FALSE; -} - - -#ifdef HAVE_PUTENV -PHP_FUNCTION(putenv) -{ - pval **str; - BLS_FETCH(); - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - - pe.putenv_string = estrndup((*str)->value.str.val,(*str)->value.str.len); - pe.key = (*str)->value.str.val; - if ((p=strchr(pe.key,'='))) { /* nullify the '=' if there is one */ - *p='\0'; - } - pe.key_len = strlen(pe.key); - pe.key = estrndup(pe.key,pe.key_len); - - 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 - - - -PHP_FUNCTION(toggle_short_open_tag) -{ - /* has to be implemented within Zend */ -#if 0 - pval **value; - int ret; - - ret = php3_ini.short_open_tag; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1,&value) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(value); - php3_ini.short_open_tag = (*value)->value.lval; - RETURN_LONG(ret); -#endif -} - -/******************* - * Basic Functions * - *******************/ - -PHP_FUNCTION(intval) -{ - pval **num, **arg_base; - int base; - - switch(ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - base = 10; - break; - case 2: - if (getParametersEx(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); -} - - -PHP_FUNCTION(doubleval) -{ - pval **num; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - *return_value=**num; - zval_copy_ctor(return_value); - convert_to_double(return_value); -} - - -PHP_FUNCTION(strval) -{ - pval **num; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - *return_value=**num; - zval_copy_ctor(return_value); - convert_to_string(return_value); -} - -#ifdef __cplusplus -void php3_flush(HashTable *) -#else -PHP_FUNCTION(flush) -#endif -{ -#if APACHE - SLS_FETCH(); -#endif - -#if APACHE -# if MODULE_MAGIC_NUMBER > 19970110 - rflush(((request_rec *) SG(server_context))); -# else - bflush(((request_rec *) SG(server_context))->connection->client); -# endif -#endif -#if FHTTPD - /*FIXME -- what does it flush really? the whole response?*/ -#endif -#if CGI_BINARY - fflush(stdout); -#endif -#if USE_SAPI - sapi_rqst->flush(sapi_rqst->scid); -#endif -} - - -PHP_FUNCTION(sleep) -{ - pval **num; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(num); - sleep((*num)->value.lval); -} - -PHP_FUNCTION(usleep) -{ -#if HAVE_USLEEP - pval **num; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &num) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(num); - usleep((*num)->value.lval); -#endif -} - -PHP_FUNCTION(gettype) -{ - pval **arg; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - switch ((*arg)->type) { - 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); - } -} - - -PHP_FUNCTION(settype) -{ - pval **var, **type; - char *new_type; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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; -} - - -PHP_FUNCTION(get_current_user) -{ - RETURN_STRING(_php3_get_current_user(),1); -} - - -PHP_FUNCTION(get_cfg_var) -{ - pval **varname; - char *value; - - if (ARG_COUNT(ht)!=1 || getParametersEx(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); -} - -PHP_FUNCTION(set_magic_quotes_runtime) -{ - pval **new_setting; - PLS_FETCH(); - - if (ARG_COUNT(ht)!=1 || getParametersEx(1, &new_setting)==FAILURE) { - RETURN_FALSE; - } - convert_to_boolean_ex(new_setting); - - PG(magic_quotes_runtime) = (zend_bool) (*new_setting)->value.lval; - RETURN_TRUE; -} - -PHP_FUNCTION(get_magic_quotes_runtime) -{ - PLS_FETCH(); - - RETURN_LONG(PG(magic_quotes_runtime)); -} - -PHP_FUNCTION(get_magic_quotes_gpc) -{ - PLS_FETCH(); - - RETURN_LONG(PG(magic_quotes_gpc)); -} - - -void php3_is_type(INTERNAL_FUNCTION_PARAMETERS,int type) -{ - pval **arg; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1, &arg)==FAILURE) { - RETURN_FALSE; - } - if ((*arg)->type == type) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} - - -PHP_FUNCTION(is_resource) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE); -} - -PHP_FUNCTION(is_bool) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_BOOL); -} - -PHP_FUNCTION(is_long) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG); -} - -PHP_FUNCTION(is_double) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE); -} - -PHP_FUNCTION(is_string) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING); -} - -PHP_FUNCTION(is_array) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY); -} - -PHP_FUNCTION(is_object) -{ - php3_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT); -} - - -/* - 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 -*/ - -PHP_FUNCTION(error_log) -{ - pval **string, **erropt = NULL, **option = NULL, **emailhead = NULL; - int opt_err = 0; - char *message, *opt=NULL, *headers=NULL; - - switch(ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1,&string) == FAILURE) { - php_error(E_WARNING,"Invalid argument 1 in error_log"); - RETURN_FALSE; - } - break; - case 2: - if (getParametersEx(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 (getParametersEx(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 (getParametersEx(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 (!_php3_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=php3_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: - php3_log_err(message); - break; - } - return SUCCESS; -} - - -PHP_FUNCTION(call_user_func) -{ - pval ***params; - pval retval; - int arg_count=ARG_COUNT(ht); - CLS_FETCH(); - - if (arg_count<1) { - WRONG_PARAM_COUNT; - } - params = (pval ***) emalloc(sizeof(pval **)*arg_count); - - if (getParametersArrayEx(arg_count, params)==FAILURE) { - efree(params); - RETURN_FALSE; - } - SEPARATE_ZVAL(params[0]); - convert_to_string(*params[0]); - if (call_user_function_ex(CG(function_table), NULL, *params[0], &retval, arg_count-1, params+1, 1)==SUCCESS) { - *return_value = retval; - } else { - php_error(E_WARNING,"Unable to call %s() - function does not exist", (*params[0])->value.str.val); - } - efree(params); -} - - -PHP_FUNCTION(call_user_method) -{ - pval ***params; - pval retval; - int arg_count=ARG_COUNT(ht); - CLS_FETCH(); - - if (arg_count<2) { - WRONG_PARAM_COUNT; - } - params = (pval ***) emalloc(sizeof(pval **)*arg_count); - - if (getParametersArrayEx(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, arg_count-2, params+2, 1)==SUCCESS) { - *return_value = retval; - } else { - php_error(E_WARNING,"Unable to call %s() - function does not exist", (*params[0])->value.str.val); - } - efree(params); -} - - -int user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry) -{ - pval retval; - int i; - 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) { - pval_destructor(&retval); - } - for (i=0; i<shutdown_function_entry->arg_count; i++) { - zval_ptr_dtor(&shutdown_function_entry->arguments[i]); - } - efree(shutdown_function_entry->arguments); - return 1; -} - - -void php_call_shutdown_functions(void) -{ - BLS_FETCH(); - - if (BG(user_shutdown_function_names)) { - 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 = ARG_COUNT(ht); - - if (shutdown_function_entry.arg_count<1) { - WRONG_PARAM_COUNT; - } - shutdown_function_entry.arguments = (pval **) emalloc(sizeof(pval *)*shutdown_function_entry.arg_count); - - if (getParametersArray(ht, shutdown_function_entry.arg_count, shutdown_function_entry.arguments)==FAILURE) { - RETURN_FALSE; - } - convert_to_string(shutdown_function_entry.arguments[0]); - 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, (int (*)(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 (ARG_COUNT(ht)!=1 || getParametersEx(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 (ARG_COUNT(ht)!=1 || getParametersEx(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 IS_ARRAY: - printf("Array offset: "); - break; - case 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 IS_ARRAY: - printf("Array offset: "); - break; - case 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 IS_ARRAY: - printf("Array offset: "); - break; - case IS_OBJECT: - printf("Object property: "); - break; - case 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", ARG_COUNT(ht)); - 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); - - register_internal_class(&test_class_entry); -} - - -PHP_FUNCTION(ini_get) -{ - pval **varname; - - if (ARG_COUNT(ht)!=1 || getParametersEx(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); -} - - -PHP_FUNCTION(ini_alter) -{ - pval **varname, **new_value; - char *old_value; - - if (ARG_COUNT(ht)!=2 || getParametersEx(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)==FAILURE) { - RETURN_FALSE; - } - if (old_value) { - RETURN_STRING(old_value, 1); - } else { - RETURN_FALSE; - } -} - - - -PHP_FUNCTION(ini_restore) -{ - pval **varname; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1, &varname)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(varname); - - php_restore_ini_entry((*varname)->value.str.val, (*varname)->value.str.len); -} - - -PHP_FUNCTION(print_r) -{ - pval **expr; - - if (ARG_COUNT(ht)!=1 || getParametersEx(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 (ARG_COUNT(ht)) { - case 0: - break; - case 1: - if (getParametersEx(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 bool function_exists(string function_name) - Checks if a given function has been defined */ -PHP_FUNCTION(function_exists) -{ - pval **fname; - pval *tmp; - char *lcname; - CLS_FETCH(); - - if (ARG_COUNT(ht)!=1 || getParametersEx(1, &fname)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(fname); - - lcname = estrdup((*fname)->value.str.val); - zend_str_tolower(lcname, (*fname)->value.str.len); - if (zend_hash_find(CG(function_table), lcname, - (*fname)->value.str.len+1, (void**)&tmp) == FAILURE) { - efree(lcname); - RETURN_FALSE; - } else { - efree(lcname); - RETURN_TRUE; - } -} - -/* }}} */ - - -/* {{{ 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(ARG_COUNT(ht) != 2 || getParametersEx(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(ARG_COUNT(ht) != 2 || getParametersEx(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(ARG_COUNT(ht) != 1 || getParametersEx(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(ARG_COUNT(ht) != 1 || getParametersEx(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); -} -/* }}} */ - - -/* - * 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 e0dce06e1f..0000000000 --- a/ext/standard/basic_functions.h +++ /dev/null @@ -1,145 +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 "zend_highlight.h" - -extern php3_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_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); - -/* 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 php3_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_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_alter); -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(function_exists); - -PHP_FUNCTION(getservbyname); -PHP_FUNCTION(getservbyport); -PHP_FUNCTION(getprotobyname); -PHP_FUNCTION(getprotobynumber); - -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; -} 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 - -#endif /* _BASIC_FUNCTIONS_H */ diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c deleted file mode 100644 index 55dc0f049e..0000000000 --- a/ext/standard/browscap.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -#include "php.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 - -function_entry browscap_functions[] = { - PHP_FE(get_browser, NULL) - {NULL, NULL, NULL} -}; - -php3_module_entry browscap_module_entry = { - "browscap", browscap_functions, PHP_MINIT(browscap), PHP_MSHUTDOWN(browscap), - NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES -}; - - -static int browser_reg_compare(pval *browser) -{ - pval *browser_name; - regex_t r; - - if (found_browser_entry) { /* already found */ - return 0; - } - zend_hash_find(browser->value.ht,"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; -} - -PHP_FUNCTION(get_browser) -{ - pval *agent_name,*agent,tmp; - ELS_FETCH(); - - if (!INI_STR("browscap")) { - RETURN_FALSE; - } - - switch(ARG_COUNT(ht)) { - 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 (getParameters(ht, 1, &agent_name)==FAILURE) { - RETURN_FALSE; - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string(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.ht->pDestructor = PVAL_DESTRUCTOR; - - while (zend_hash_find(agent->value.ht, "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) { - 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.ht, agent->value.ht, PVAL_COPY_CTOR, (void *) &tmp, sizeof(pval), 0); - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/config.h.stub b/ext/standard/config.h.stub deleted file mode 100644 index 6021062968..0000000000 --- a/ext/standard/config.h.stub +++ /dev/null @@ -1,17 +0,0 @@ -/* Define if you have the crypt() function */ -#define HAVE_CRYPT 1 - -/* Define if you have and want to use libcrypt */ -#define HAVE_LIBCRYPT 0 - -/* crypt capability checks */ -#undef PHP3_STD_DES_CRYPT -#undef PHP3_EXT_DES_CRYPT -#undef PHP3_MD5_CRYPT -#undef PHP3_BLOWFISH_CRYPT - -/* Define if you have libdl (used for dynamic linking) */ -#undef HAVE_LIBDL - -#undef HAVE_GETWD -#undef HAVE_GETCWD diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 deleted file mode 100644 index 33852add19..0000000000 --- a/ext/standard/config.m4 +++ /dev/null @@ -1,143 +0,0 @@ -dnl $Id$ -*- sh -*- - -divert(1) - -dnl -dnl Check for crypt() capabilities -dnl -AC_DEFUN(AC_CRYPT_CAP,[ - - AC_MSG_CHECKING([for standard DES crypt]) - AC_TRY_RUN([ -main() { -#if HAVE_CRYPT - exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M")); -#else - exit(0); -#endif -}],[ - AC_DEFINE(PHP3_STD_DES_CRYPT,1) - AC_MSG_RESULT(yes) - ],[ - AC_DEFINE(PHP3_STD_DES_CRYPT,0) - AC_MSG_RESULT(no) - ],[ - AC_DEFINE(PHP3_STD_DES_CRYPT,1) - AC_MSG_RESULT(cannot check, guessing yes) - ]) - - AC_MSG_CHECKING([for extended DES crypt]) - AC_TRY_RUN([ -main() { -#if HAVE_CRYPT - exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc")); -#else - exit(0); -#endif -}],[ - AC_DEFINE(PHP3_EXT_DES_CRYPT,1) - AC_MSG_RESULT(yes) - ],[ - AC_DEFINE(PHP3_EXT_DES_CRYPT,0) - AC_MSG_RESULT(no) - ],[ - AC_DEFINE(PHP3_EXT_DES_CRYPT,0) - AC_MSG_RESULT(cannot check, guessing no) - ]) - - AC_MSG_CHECKING([for MD5 crypt]) - 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_DEFINE(PHP3_MD5_CRYPT,1) - AC_MSG_RESULT(yes) - ],[ - AC_DEFINE(PHP3_MD5_CRYPT,0) - AC_MSG_RESULT(no) - ],[ - AC_DEFINE(PHP3_MD5_CRYPT,0) - AC_MSG_RESULT(cannot check, guessing no) - ]) - - AC_MSG_CHECKING([for Blowfish crypt]) - 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_DEFINE(PHP3_BLOWFISH_CRYPT,1) - AC_MSG_RESULT(yes) - ],[ - AC_DEFINE(PHP3_BLOWFISH_CRYPT,0) - AC_MSG_RESULT(no) - ],[ - AC_DEFINE(PHP3_BLOWFISH_CRYPT,0) - AC_MSG_RESULT(cannot check, guessing no) - ]) -]) - -AC_CHECK_LIB(c, dlopen, [ - # fake it - AC_DEFINE(HAVE_LIBDL) ], [ - AC_CHECK_LIB(dl, dlopen, [ - LIBS="-ldl $LIBS" - AC_DEFINE(HAVE_LIBDL) ], []) ]) - -AC_CHECK_LIB(pam, pam_start, [ - EXTRA_LIBS="$EXTRA_LIBS -lpam" - AC_DEFINE(HAVE_LIBPAM) ], []) - -AC_CHECK_LIB(crypt, crypt, [ - AC_ADD_LIBRARY(crypt) - AC_DEFINE(HAVE_LIBCRYPT) ], []) - -AC_CHECK_FUNCS(getcwd) -AC_CHECK_FUNCS(getwd) - -divert(3) - -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 -]) - -AC_CRYPT_CAP - -PHP_EXTENSION(standard) - diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c deleted file mode 100644 index 48619c5a67..0000000000 --- a/ext/standard/crypt.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 - -#if MSVC5 -#include <process.h> -extern char *crypt(char *__key,char *__salt); -#endif - -#include "php_crypt.h" - -function_entry crypt_functions[] = { - PHP_FE(crypt, NULL) - {NULL, NULL, NULL} -}; - -php3_module_entry crypt_module_entry = { - "Crypt", crypt_functions, PHP_MINIT(crypt), NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES -}; - - -/* - The capabilities of the crypt() function is determined by the test programs - run by configure from aclocal.m4. They will set PHP3_STD_DES_CRYPT, - PHP3_EXT_DES_CRYPT, PHP3_MD5_CRYPT and PHP3_BLOWFISH_CRYPT as appropriate - for the target platform -*/ -#if PHP3_STD_DES_CRYPT -#define PHP3_MAX_SALT_LEN 2 -#endif -#if PHP3_EXT_DES_CRYPT -#undef PHP3_MAX_SALT_LEN -#define PHP3_MAX_SALT_LEN 9 -#endif -#if PHP3_MD5_CRYPT -#undef PHP3_MAX_SALT_LEN -#define PHP3_MAX_SALT_LEN 12 -#endif -#if PHP3_BLOWFISH_CRYPT -#undef PHP3_MAX_SALT_LEN -#define PHP3_MAX_SALT_LEN 17 -#endif - -#if HAVE_LRAND48 -#define PHP3_CRYPT_RAND lrand48() -#else -#if HAVE_RANDOM -#define PHP3_CRYPT_RAND random() -#else -#define PHP3_CRYPT_RAND rand() -#endif -#endif - -PHP_MINIT_FUNCTION(crypt) -{ - ELS_FETCH(); - -#if PHP3_STD_DES_CRYPT - REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", 2, CONST_CS | CONST_PERSISTENT); -#else -#if PHP3_MD5_CRYPT - REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", 12, CONST_CS | CONST_PERSISTENT); -#endif -#endif - REGISTER_LONG_CONSTANT("CRYPT_STD_DES", PHP3_STD_DES_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_EXT_DES", PHP3_EXT_DES_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_MD5", PHP3_MD5_CRYPT, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CRYPT_BLOWFISH", PHP3_BLOWFISH_CRYPT, CONST_CS | CONST_PERSISTENT); - return SUCCESS; -} - -static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - -static void php3i_to64(char *s, long v, int n) { - while (--n >= 0) { - *s++ = itoa64[v&0x3f]; - v >>= 6; - } -} - -PHP_FUNCTION(crypt) -{ - char salt[PHP3_MAX_SALT_LEN+1]; - pval **arg1, **arg2; - - salt[0]=salt[PHP3_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], '$', PHP3_MAX_SALT_LEN-1); - - switch (ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1, &arg1)==FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (getParametersEx(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - memcpy(salt, (*arg2)->value.str.val, MIN(PHP3_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 PHP3_STD_DES_CRYPT - php3i_to64(&salt[0], PHP3_CRYPT_RAND, 2); - salt[2] = '\0'; -#else -#if PHP3_MD5_CRYPT - strcpy(salt, "$1$"); - php3i_to64(&salt[3], PHP3_CRYPT_RAND, 4); - php3i_to64(&salt[7], PHP3_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 f99ec4a254..0000000000 --- a/ext/standard/cyr_convert.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 * _php3_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 (ARG_COUNT(ht) != 3 || getParameters(ht,3,&str_arg, &fr_cs, &to_cs)==FAILURE) - { - WRONG_PARAM_COUNT; - } - convert_to_string(str_arg); - convert_to_string(fr_cs); - convert_to_string(to_cs); - - str = (unsigned char*) str_arg->value.str.val; - - _php3_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 872428c757..0000000000 --- a/ext/standard/datetime.c +++ /dev/null @@ -1,630 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 "snprintf.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) && !(WIN32||WINNT) -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); - - -PHP_FUNCTION(time) -{ - return_value->value.lval = (long) time(NULL); - return_value->type = IS_LONG; -} - -void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) -{ - pval *arguments[7]; - struct tm *ta, tmbuf; - time_t t; - int i, gmadjust, seconds, arg_count = ARG_COUNT(ht); - - if (arg_count > 7 || getParametersArray(ht, arg_count, arguments) == FAILURE) { - WRONG_PARAM_COUNT; - } - /* convert supplied arguments to longs */ - for (i = 0; i < arg_count; i++) { - convert_to_long(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 = 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. - */ - 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); -} - -PHP_FUNCTION(mktime) -{ - _php3_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} - -PHP_FUNCTION(gmmktime) -{ - _php3_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -static void -_php3_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(ARG_COUNT(ht)) { - case 1: - if (getParameters(ht, 1, &format) == FAILURE) { - WRONG_PARAM_COUNT; - } - the_time = time(NULL); - break; - case 2: - if (getParameters(ht, 2, &format, ×tamp) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long(timestamp); - the_time = timestamp->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - convert_to_string(format); - - if (gm) { - ta = gmtime_r(&the_time, &tmbuf); - } else { - ta = 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 */ - 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; - 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; -} - -PHP_FUNCTION(date) -{ - _php3_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} - -PHP_FUNCTION(gmdate) -{ - _php3_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} - -PHP_FUNCTION(getdate) -{ - pval *timestamp_arg; - struct tm *ta, tmbuf; - time_t timestamp; - - if (ARG_COUNT(ht) == 0) { - timestamp = time(NULL); - } else if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, ×tamp_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } else { - convert_to_long(timestamp_arg); - timestamp = timestamp_arg->value.lval; - } - - ta = 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 *php3_std_date(time_t t) -{ - struct tm *tm1, tmbuf; - char *str; - PLS_FETCH(); - - tm1 = gmtime_r(&t, &tmbuf); - str = emalloc(81); - if (PG(y2k_compliance)) { - snprintf(str, 80, "%s, %02d-%s-%04d %02d:%02d:%02d GMT", - day_full_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); -} - -/* - * CheckDate(month, day, year); - * returns True(1) if it is valid date - * - */ -#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0) -PHP_FUNCTION(checkdate) -{ - pval *month, *day, *year; - int m, d, y; - - if (ARG_COUNT(ht) != 3 || - getParameters(ht, 3, &month, &day, &year) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long(day); - convert_to_long(month); - convert_to_long(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 - -PHP_FUNCTION(strftime) -{ - 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 (ARG_COUNT(ht)) { - case 1: - if (getParameters(ht, 1, &format_arg)==FAILURE) { - RETURN_FALSE; - } - time(×tamp); - break; - case 2: - if (getParameters(ht, 2, &format_arg, ×tamp_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long(timestamp_arg); - timestamp = timestamp_arg->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - convert_to_string(format_arg); - if (format_arg->value.str.len==0) { - RETURN_FALSE; - } - format = format_arg->value.str.val; - ta = 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; -} -#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 = ARG_COUNT(ht); - - if (ac < 1 || ac > 2 || getParameters(ht, ac, &timep, &nowp)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(timep); - if (ac == 2) { - convert_to_long(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 bf518fcd7f..0000000000 --- a/ext/standard/datetime.h +++ /dev/null @@ -1,52 +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(getdate); -PHP_FUNCTION(checkdate); -#if HAVE_STRFTIME -PHP_FUNCTION(strftime); -#endif -PHP_FUNCTION(strtotime); - -extern char *php3_std_date(time_t t); -void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm); - -#endif /* _DATETIME_H */ diff --git a/ext/standard/dir.c b/ext/standard/dir.c deleted file mode 100644 index 4f40dd2d98..0000000000 --- a/ext/standard/dir.c +++ /dev/null @@ -1,312 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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> - -#if WIN32||WINNT -#define NEEDRDH 1 -#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 (ARG_COUNT(ht) == 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 ((ARG_COUNT(ht) != 1) || getParametersEx(1, &id) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } else { \ - ZEND_FETCH_RESOURCE(dirp,php_dir *,id,-1, "Directory", le_dirp); \ - } - -static zend_function_entry php_dir_functions[] = { - 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) - {NULL, NULL, NULL} -}; - - -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} -}; - - -php3_module_entry php3_dir_module_entry = { - "PHP_dir", php_dir_functions, PHP_MINIT(dir), NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES -}; - -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 = 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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (_php3_check_open_basedir((*arg)->value.str.val)) { - RETURN_FALSE; - } - - dirp = emalloc(sizeof(php_dir)); - - dirp->dir = 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(); - - php3_list_delete(dirp->id); -} - -/* }}} */ -/* {{{ proto int chdir(string directory) - Change the current directory */ - -PHP_FUNCTION(chdir) -{ - pval **arg; - int ret; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - ret = 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() - Gets the current directory */ - -PHP_FUNCTION(getcwd) -{ - char path[MAXPATHLEN]; - char *ret=NULL; - - if (ARG_COUNT(ht) != 0) { - WRONG_PARAM_COUNT; - } - -#if HAVE_GETCWD - ret = getcwd(path,MAXPATHLEN-1); -#elif HAVE_GETWD - ret = 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 *direntp; - DIRLS_FETCH(); - - FETCH_DIRP(); - - direntp = readdir(dirp->dir); - if (direntp) { - RETURN_STRINGL(direntp->d_name, strlen(direntp->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 e113249fd1..0000000000 --- a/ext/standard/dl.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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" - -#ifdef HAVE_LIBDL -#include <stdlib.h> -#include <stdio.h> -#ifndef RTLD_LAZY -# define RTLD_LAZY 1 /* Solaris 1, FreeBSD's (2.1.7.1 and older) */ -#endif -#if HAVE_STRING_H -#include <string.h> -#else -#include <strings.h> -#endif -#if MSVC5 -#include "win32/param.h" -#include "win32/winutil.h" -#else -#include <sys/param.h> -#endif - -function_entry dl_functions[] = { - {"dl", dl, NULL}, - {NULL, NULL, NULL} -}; - - -php3_module_entry dl_module_entry = { - "PHP_DL", dl_functions, NULL, NULL, NULL, NULL, PHP_MINFO(dl), STANDARD_MODULE_PROPERTIES -}; - -#endif - -/* {{{ proto int dl(string extension_filename) - Load a PHP extension at runtime */ -void dl(INTERNAL_FUNCTION_PARAMETERS) -{ - pval **file; - PLS_FETCH(); - - /* obtain arguments */ - if (ARG_COUNT(ht) != 1 || getParametersEx(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 - -void php_dl(pval *file,int type,pval *return_value) -{ - void *handle; - char libpath[MAXPATHLEN + 1]; - php3_module_entry *module_entry,*tmp; - php3_module_entry *(*get_module)(void); - PLS_FETCH(); - - if (cfg_get_string("extension_dir",&PG(extension_dir))==SUCCESS - && PG(extension_dir) - && PG(extension_dir)[0]){ - int extension_dir_len = strlen(PG(extension_dir)); - - if (PG(extension_dir)[extension_dir_len-1]=='/' || 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 { - sprintf(libpath,"%s",file->value.str.val); /* SAFE */ - } - - /* load dynamic symbol */ - handle = dlopen(libpath, RTLD_LAZY); - if (!handle) { - int error_type; - - if (type==MODULE_TEMPORARY) { - error_type = E_ERROR; - } else { - error_type = E_CORE_ERROR; - } -#if MSVC5 - php_error(error_type,"Unable to load dynamic library '%s'<br>\n%s",libpath,php3_win_err()); -#else - php_error(error_type,"Unable to load dynamic library '%s' - %s",libpath,dlerror()); -#endif - RETURN_FALSE; - } - get_module = (php3_module_entry *(*)(void)) dlsym(handle, "get_module"); - - if (!get_module) { - dlclose(handle); - php_error(E_CORE_WARNING,"Invalid library (maybe not a PHP library) '%s' ",file->value.str.val); - RETURN_FALSE; - } - module_entry = get_module(); - 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)==FAILURE) { - php_error(E_CORE_WARNING,"%s: Unable to initialize module",module_entry->name); - dlclose(handle); - RETURN_FALSE; - } - } - zend_register_module(module_entry); - - - if (module_entry->request_startup_func) { - if (module_entry->request_startup_func(type, module_entry->module_number)) { - php_error(E_CORE_WARNING,"%s: Unable to initialize module",module_entry->name); - dlclose(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) -{ - PUTS("Dynamic Library support enabled.\n"); -} - -#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; -} - -#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 6bf453d23e..0000000000 --- a/ext/standard/dl.h +++ /dev/null @@ -1,61 +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); - - -#ifdef HAVE_LIBDL - -extern php3_module_entry dl_module_entry; -#define dl_module_ptr &dl_module_entry - -/* dynamic loading functions */ -void dl(INTERNAL_FUNCTION_PARAMETERS); -extern PHP_MINIT_FUNCTION(dl); -extern PHP_MSHUTDOWN_FUNCTION(dl); -extern PHP_RSHUTDOWN_FUNCTION(dl); -PHP_MINFO_FUNCTION(dl); - -#else - -#define dl_module_ptr NULL - -#endif - -#define phpext_dl_ptr dl_module_ptr - -#endif /* _DL_H */ diff --git a/ext/standard/dns.c b/ext/standard/dns.c deleted file mode 100644 index d5fc032ac0..0000000000 --- a/ext/standard/dns.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#if HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif -#if WIN32|WINNT -#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 *_php3_gethostbyaddr(char *ip); -char *_php3_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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - return_value->value.str.val = _php3_gethostbyaddr((*arg)->value.str.val); - return_value->value.str.len = strlen(return_value->value.str.val); - return_value->type = IS_STRING; -} -/* }}} */ - - -char *_php3_gethostbyaddr(char *ip) -{ - unsigned long addr; - struct hostent *hp; - - if ((int) (addr = inet_addr(ip)) == -1) { -#if 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 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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - return_value->value.str.val = _php3_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 (ARG_COUNT(ht) != 1 || getParametersEx(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 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 *_php3_gethostbyname(char *name) -{ - struct hostent *hp; - struct in_addr in; - - hp = gethostbyname(name); - if (!hp || !hp->h_addr_list) { -#if 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 !(WIN32|WINNT)||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 (ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - type = T_MX; - convert_to_string_ex(arg1); - break; - case 2: - if (getParametersEx(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(ARG_COUNT(ht)) { - case 2: - if (getParameters(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 (getParameters(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 9d2c6cec0b..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 !(WIN32|WINNT)||(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 b190ea8b98..0000000000 --- a/ext/standard/exec.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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 = _php3_escapeshellcmd(d); - efree(d); - d = tmp; -#if WIN32|WINNT - 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 */ -#if WIN32|WINNT - 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 APACHE - SLS_FETCH(); -#endif - - if (output) PUTS(buf); -#if APACHE -# if MODULE_MAGIC_NUMBER > 19970110 - if (output) rflush(((request_rec *) SG(server_context))); -# else - if (output) bflush(((request_rec *) SG(server_context))->connection->client); -# endif -#endif -#if CGI_BINARY - fflush(stdout); -#endif -#if FHTTPD - /* fhttpd doesn't flush */ -#endif -#if USE_SAPI - sapi_rqst->flush(sapi_rqst->scid); -#endif - } - 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'; - - } else { - int b, i; - - while ((b = fread(buf, 1, sizeof(buf), fp)) > 0) { - for (i = 0; i < b; i++) - if (output) (void)PUTC(buf[i]); - } - } - - /* Return last line from the shell command */ - if (PG(magic_quotes_runtime) && type!=3) { - int len; - - tmp = php_addslashes(buf, 0, &len, 0); - RETVAL_STRINGL(tmp,len,0); - } else { - RETVAL_STRING(buf,1); - } - - 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 = ARG_COUNT(ht); - int ret; - - if (arg_count > 3 || getParameters(ht, 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 = ARG_COUNT(ht); - int ret; - - if (arg_count > 2 || getParameters(ht, 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 int passthru(string command [, int return_value]) - Execute an external program and display raw output */ -PHP_FUNCTION(passthru) -{ - pval *arg1, *arg2; - int arg_count = ARG_COUNT(ht); - int ret; - - if (arg_count > 2 || getParameters(ht, 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 php3_ind(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 * _php3_escapeshellcmd(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 (php3_ind("&;`'\"|*?~<>^()[]{}$\\\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 escapeshellcmd(string command) - escape shell metacharacters */ -PHP_FUNCTION(escapeshellcmd) -{ - pval *arg1; - char *cmd = NULL; - - if (getParameters(ht, 1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(arg1); - if (arg1->value.str.len) { - cmd = _php3_escapeshellcmd(arg1->value.str.val); - RETVAL_STRING(cmd, 1); - efree(cmd); - } -} -/* }}} */ - - -PHP_FUNCTION(shell_exec) -{ - FILE *in; - int readbytes,total_readbytes=0,allocated_space; - pval *cmd; - PLS_FETCH(); - - if (ARG_COUNT(ht)!=1 || getParameters(ht, 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(cmd); -#if WIN32|WINNT - 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 a9e6a1e32d..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 *_php3_escapeshellcmd(char *); -#endif /* _EXEC_H */ diff --git a/ext/standard/file.c b/ext/standard/file.c deleted file mode 100644 index 60e0b30d9a..0000000000 --- a/ext/standard/file.c +++ /dev/null @@ -1,1767 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Synced with php3 revision 1.218 1999-06-16 [ssb] */ - -/* {{{ includes */ - -#include "php.h" -#include "php_globals.h" -#include "ext/standard/flock_compat.h" - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#if MSVC5 -#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 -#if MSVC5 -#include "win32/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif -#if WIN32|WINNT -#include <winsock.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#endif -#include "snprintf.h" -#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 - -/* }}} */ -/* {{{ 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; - -static fd_set readfd; -static int max_fd; - -/* }}} */ -/* {{{ 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 */ - -function_entry file_functions[] = { - 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(fseek, NULL) - PHP_FE(ftell, 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) - PHP_FE(set_socket_blocking, NULL) -#if (0 && defined(HAVE_SYS_TIME_H) && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)) - PHP_FE(set_socket_timeout, NULL) -#endif - PHP_FE(fd_set, NULL) - PHP_FE(fd_isset, NULL) - PHP_FE(select, NULL) - {NULL, NULL, NULL} -}; - -zend_module_entry file_module_entry = { - "File functions", - file_functions, - PHP_MINIT(file), - NULL, - NULL, - NULL, - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -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) -{ - 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_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 - - return SUCCESS; -} - -/* }}} */ -/* {{{ proto bool flock(int fp, int operation) - portable file locking */ - -static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN }; - -PHP_FUNCTION(flock) -{ - pval **arg1, **arg2; - int type, fd, act; - void *what; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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) { - 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 value for second 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 (flock(fd, act) == -1) { - RETURN_FALSE; - } - - 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 (getParametersEx(1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (getParametersEx(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 = php3_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); - php3_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 (getParametersEx(1,&filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (getParametersEx(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 = php3_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); - php3_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 || getParametersEx(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() - 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 (getParametersEx(2,&arg1,&arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (getParametersEx(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 - * php3_fopen__wrapper(). - */ - fp = php3_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); - php3_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 || getParametersEx(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",&type,2,le_fopen,le_socket); - ZEND_VERIFY_RESOURCE(what); - - php3_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; - char *b, buf[1024]; - PLS_FETCH(); - - if (ARG_COUNT(ht) != 2 || getParametersEx(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); - } - fp = popen(buf,p); - 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 || getParametersEx(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,1,le_popen); - ZEND_VERIFY_RESOURCE(what); - - php3_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 || getParametersEx(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 _php3_set_sock_blocking(int socketd, int block) -{ - int ret = SUCCESS; - int flags; - int myflag = 0; - -#if WIN32|WINNT - /* 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(set_socket_blocking) -{ - pval **arg1, **arg2; - int block; - int socketd = 0; - void *what; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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 (_php3_set_sock_blocking(socketd, block) == FAILURE) - RETURN_FALSE; - - _php3_sock_set_blocking(socketd, block == 0 ? 0 : 1); - - RETURN_TRUE; -} - -/* }}} */ -/* {{{ proto int set_socket_timeout(int socket descriptor, int timeout ) - NYI */ - -#if (0 && defined(HAVE_SYS_TIME_H) && HAVE_SETSOCKOPT && defined(SO_SNDTIMEO) && defined(SO_RCVTIMEO)) -/* this doesn't work, as it appears those properties are read-only :( */ -PHP_FUNCTION(set_socket_timeout) -{ - pval *socket,*timeout; - int type, *sock; - struct timeval t; - - if (ARG_COUNT(ht)!=2 || getParameters(ht, 2, &socket, &timeout)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long(socket); - convert_to_long(timeout); - - sock = php3_list_find(socket->value.lval, &type); - if (type!=le_socket) { - php_error(E_WARNING,"%d is not a socket id",socket->value.lval); - RETURN_FALSE; - } - t.tv_sec = timeout->value.lval; - t.tv_usec = 0; - setsockopt(*sock,SOL_SOCKET,SO_SNDTIMEO,(void *) &t,sizeof(struct timeval)); - setsockopt(*sock,SOL_SOCKET,SO_RCVTIMEO,(void *) &t,sizeof(struct timeval)); - RETURN_TRUE; -} -#endif - -/* }}} */ -/* {{{ 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 || getParametersEx(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 || getParametersEx(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; - FIL_FETCH(); - - switch(ARG_COUNT(ht)) { - case 2: - if (getParametersEx(2, &fd, &bytes) == FAILURE) { - RETURN_FALSE; - } - break; - case 3: - if (getParametersEx(3, &fd, &bytes, &allow) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - 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), allow?(*allow)->value.str.val:NULL); - - RETURN_STRING(buf, 0); -} - -/* }}} */ -/* {{{ 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 (getParametersEx(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - num_bytes = (*arg2)->value.str.len; - break; - case 3: - if (getParametersEx(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 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 (getParametersEx(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 || getParametersEx(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 || getParametersEx(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) - Seek on a file pointer */ - -PHP_FUNCTION(fseek) -{ - pval **arg1, **arg2; - void *what; - - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &arg1, &arg2) == 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); - - RETURN_LONG(fseek((FILE*)what,(*arg2)->value.lval,SEEK_SET)); -} - -/* }}} */ -/* {{{ 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 || getParametersEx(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) &&(!_php3_checkuid((*arg1)->value.str.val,3))) { - RETURN_FALSE; - } - ret = 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 || getParametersEx(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg1); - if (PG(safe_mode) &&(!_php3_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 (getParametersEx(1,&arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 2: - if (getParametersEx(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 - * php3_fopen_wrapper(). - */ - fp = php3_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); - php3_strip_url_passwd(tmp); - php_error(E_WARNING,"readfile(\"%s\") - %s", tmp, strerror(errno)); - efree(tmp); - } - RETURN_FALSE; - } - if (php3_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 || getParametersEx(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 || getParametersEx(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 (php3_header()) { /* force headers if not already sent */ - size = php_passthru_fd(socketd, (FILE*) what, issock); - } - - php3_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 || getParametersEx(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) &&(!_php3_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 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 || getParametersEx(2, &source, &target) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(source); - convert_to_string_ex(target); - - if (PG(safe_mode) &&(!_php3_checkuid((*source)->value.str.val,2))) { - RETURN_FALSE; - } - -#if WIN32|WINNT - if ((fd_s=open((*source)->value.str.val,O_RDONLY|_O_BINARY))==-1) { -#else - if ((fd_s=open((*source)->value.str.val,O_RDONLY))==-1) { -#endif - php_error(E_WARNING,"Unable to open '%s' for reading: %s",(*source)->value.str.val,strerror(errno)); - RETURN_FALSE; - } -#if WIN32|WINNT - if ((fd_t=open((*target)->value.str.val,_O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY,_S_IREAD|_S_IWRITE))==-1){ -#else - if ((fd_t=creat((*target)->value.str.val,0777))==-1) { -#endif - php_error(E_WARNING,"Unable to create '%s': %s", (*target)->value.str.val,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",(*target)->value.str.val,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 || getParametersEx(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; - char delimiter = ','; /* allow this to be set as parameter */ - - /* first section exactly as php3_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 (getParametersEx(2, &fd, &bytes) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - - case 3: - if (getParametersEx(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 */ - - bptr = buf; - tptr = buf + strlen(buf) -1; - while ( isspace((int)*tptr) && (tptr > bptr) ) *tptr--=0; - - /* 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(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++; - } - } - } 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(temp); - efree(buf); -} - -/* }}} */ - -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(getParametersEx(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(getParametersArrayEx(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 || getParametersEx(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 || getParametersEx(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; -} diff --git a/ext/standard/file.h b/ext/standard/file.h deleted file mode 100644 index 30e48a4467..0000000000 --- a/ext/standard/file.h +++ /dev/null @@ -1,81 +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 php3 revision 1.30 1999-06-16 [ssb] */ - -#ifndef _FILE_H -#define _FILE_H - -extern zend_module_entry file_module_entry; -#define file_module_ptr &file_module_entry - -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(fgetss); -PHP_FUNCTION(fgetcsv); -PHP_FUNCTION(fwrite); -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); -PHP_FUNCTION(set_socket_timeout); -PHP_FUNCTION(set_file_buffer); -PHP_FUNCTION(get_meta_tags); -PHP_FUNCTION(flock); -PHP_FUNCTION(fd_set); -PHP_FUNCTION(fd_isset); -PHP_FUNCTION(select); - -PHPAPI int _php3_set_sock_blocking(int socketd, int block); -PHPAPI int php_file_le_fopen(void); -PHPAPI int php_file_le_socket(void); -PHPAPI int php_file_le_uploads(void); - -#define phpext_file_ptr file_module_ptr -#endif /* _FILE_H */ diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c deleted file mode 100644 index 8a40fed719..0000000000 --- a/ext/standard/filestat.c +++ /dev/null @@ -1,606 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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 -# if MSVC5 -# include "win32/pwd.h" -# else -# include <pwd.h> -# endif -#endif - -#if HAVE_GRP_H -# if MSVC5 -# include "win32/grp.h" -# else -# include <grp.h> -# endif -#endif - -#if HAVE_UTIME -# if MSVC5 -# include <sys/utime.h> -# else -# include <utime.h> -# endif -#endif - -#include "php_filestat.h" - -#ifndef THREAD_SAFE -static char *CurrentStatFile=NULL; -# if MSVC5 -static unsigned int CurrentStatLength=0; -# else -static int CurrentStatLength=0; -# endif -static struct stat sb; -#if HAVE_SYMLINK -static struct stat lsb; -#endif -#endif - -#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 - - -PHP_RINIT_FUNCTION(filestat) -{ - CurrentStatFile=NULL; - CurrentStatLength=0; - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(filestat) -{ - if (CurrentStatFile) { - efree (CurrentStatFile); - } - return SUCCESS; -} - -PHP_FUNCTION(diskfreespace) -{ -#ifdef WINDOWS - pval *path; - 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 */ - pval *path; -#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 (ARG_COUNT(ht)!=1 || getParameters(ht,1,&path)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(path); - - if (_php3_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 { - php3_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); -} - -PHP_FUNCTION(chgrp) -{ -#ifndef WINDOWS - pval *filename, *group; - gid_t gid; - struct group *gr=NULL; - int ret; - PLS_FETCH(); - - if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&group)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(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(group); - gid = group->value.lval; - } - - if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (_php3_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 -} - - -PHP_FUNCTION(chown) -{ -#ifndef WINDOWS - pval *filename, *user; - int ret; - uid_t uid; - struct passwd *pw = NULL; - PLS_FETCH(); - - if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&user)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(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(user); - uid = user->value.lval; - } - - if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (_php3_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; -} - - -PHP_FUNCTION(chmod) -{ - pval *filename, *mode; - int ret; - PLS_FETCH(); - - if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&mode)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(filename); - convert_to_long(mode); - - if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) { - RETURN_FALSE; - } - - /* Check the basedir */ - if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE; - - ret = chmod(filename->value.str.val, mode->value.lval); - if (ret == -1) { - php_error(E_WARNING, "chmod failed: %s", strerror(errno)); - RETURN_FALSE; - } - RETURN_TRUE; -} - - -PHP_FUNCTION(touch) -{ -#if HAVE_UTIME - pval *filename, *filetime; - int ret; - struct stat sb; - FILE *file; - struct utimbuf *newtime = NULL; - int ac = ARG_COUNT(ht); - PLS_FETCH(); - - if (ac == 1 && getParameters(ht,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 && getParameters(ht,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(filetime); - newtime->actime = filetime->value.lval; - newtime->modtime = filetime->value.lval; - } else { - WRONG_PARAM_COUNT; - } - convert_to_string(filename); - - if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) { - if (newtime) efree(newtime); - RETURN_FALSE; - } - - /* Check the basedir */ - if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE; - - /* create the file if it doesn't exist already */ - ret = stat(filename->value.str.val, &sb); - if (ret == -1) { - file = 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 -} - - -PHP_FUNCTION(clearstatcache) -{ - if (CurrentStatFile) { - efree(CurrentStatFile); - CurrentStatFile = NULL; - } -} - - -static void _php3_stat(const char *filename, int type, pval *return_value) -{ - struct stat *stat_sb = &sb; - - if (!CurrentStatFile || strcmp(filename,CurrentStatFile)) { - if (!CurrentStatFile - || strlen(filename) > CurrentStatLength) { - if (CurrentStatFile) efree(CurrentStatFile); - CurrentStatLength = strlen(filename); - CurrentStatFile = estrndup(filename,CurrentStatLength); - } else { - strcpy(CurrentStatFile,filename); - } -#if HAVE_SYMLINK - lsb.st_mode = 0; /* mark lstat buf invalid */ -#endif - if (stat(CurrentStatFile,&sb)==-1) { - if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */ - php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",CurrentStatFile,errno,strerror(errno)); - } - efree(CurrentStatFile); - 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 (!lsb.st_mode) { - if (lstat(CurrentStatFile,&lsb) == -1) { - php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",CurrentStatFile,errno,strerror(errno)); - RETURN_FALSE; - } - } - } -#endif - - switch(type) { - case 0: /* fileperms */ - RETURN_LONG((long)sb.st_mode); - case 1: /* fileinode */ - RETURN_LONG((long)sb.st_ino); - case 2: /* filesize */ - RETURN_LONG((long)sb.st_size); - case 3: /* fileowner */ - RETURN_LONG((long)sb.st_uid); - case 4: /* filegroup */ - RETURN_LONG((long)sb.st_gid); - case 5: /* fileatime */ - RETURN_LONG((long)sb.st_atime); - case 6: /* filemtime */ - RETURN_LONG((long)sb.st_mtime); - case 7: /* filectime */ - RETURN_LONG((long)sb.st_ctime); - case 8: /* filetype */ -#if HAVE_SYMLINK - if (S_ISLNK(lsb.st_mode)) { - RETURN_STRING("link",1); - } -#endif - switch(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)",sb.st_mode&S_IFMT); - RETURN_STRING("unknown",1); - case 9: /*is writable*/ - RETURN_LONG((sb.st_mode&S_IWRITE)!=0); - case 10: /*is readable*/ - RETURN_LONG((sb.st_mode&S_IREAD)!=0); - case 11: /*is executable*/ - RETURN_LONG((sb.st_mode&S_IEXEC)!=0 && !S_ISDIR(sb.st_mode)); - case 12: /*is file*/ - RETURN_LONG(S_ISREG(sb.st_mode)); - case 13: /*is dir*/ - RETURN_LONG(S_ISDIR(sb.st_mode)); - case 14: /*is link*/ -#if HAVE_SYMLINK - RETURN_LONG(S_ISLNK(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 = &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 (ARG_COUNT(ht)!=1 || getParameters(ht,1,&filename) == FAILURE) { \ - WRONG_PARAM_COUNT; \ - } \ - convert_to_string(filename); \ - _php3_stat(filename->value.str.val, funcnum, return_value); \ -} - -FileFunction(PHP_FN(fileperms),0) -FileFunction(PHP_FN(fileinode),1) -FileFunction(PHP_FN(filesize), 2) -FileFunction(PHP_FN(fileowner),3) -FileFunction(PHP_FN(filegroup),4) -FileFunction(PHP_FN(fileatime),5) -FileFunction(PHP_FN(filemtime),6) -FileFunction(PHP_FN(filectime),7) -FileFunction(PHP_FN(filetype), 8) -FileFunction(PHP_FN(is_writable), 9) -FileFunction(PHP_FN(is_readable),10) -FileFunction(PHP_FN(is_executable),11) -FileFunction(PHP_FN(is_file),12) -FileFunction(PHP_FN(is_dir),13) -FileFunction(PHP_FN(is_link),14) -FileFunction(PHP_FN(file_exists),15) -FileFunction(PHP_FN(lstat),16) -FileFunction(PHP_FN(stat),17) - -function_entry php3_filestat_functions[] = { - 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) - {NULL, NULL, NULL} -}; - - -php3_module_entry php3_filestat_module_entry = { - "PHP_filestat", php3_filestat_functions, NULL, NULL, PHP_RINIT(filestat), - PHP_RSHUTDOWN(filestat), NULL, STANDARD_MODULE_PROPERTIES -}; - -/* - * 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 de6571cd48..0000000000 --- a/ext/standard/flock_compat.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 - -#if WIN32|WINNT -#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 WIN32|WINNT -/* - * 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 !(WIN32|WINNT) - 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 59c8e3bea4..0000000000 --- a/ext/standard/flock_compat.h +++ /dev/null @@ -1,28 +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 - -#if WIN32|WINNT -# define fsync _commit -# define ftruncate chsize -#endif /* WIN32|WINNT */ - -#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 ffd53e3aca..0000000000 --- a/ext/standard/formatted_print.c +++ /dev/null @@ -1,592 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 - */ - -/* - * _php3_cvt 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 * -_php3_cvt(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++; } - 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 = _php3_cvt(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 * -php3_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 = ARG_COUNT(ht); - - if (argc < 1) { - WRONG_PARAM_COUNT_WITH_RETVAL(NULL); - } - args = (pval ***)emalloc(argc * sizeof(pval *)); - - if (getParametersArrayEx(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=php3_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=php3_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 7366859f39..0000000000 --- a/ext/standard/fsock.c +++ /dev/null @@ -1,770 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - | Jim Winstead (jimw@php.net) | - | Sascha Schumann <sascha@schumann.cx> | - +----------------------------------------------------------------------+ -*/ - -/* $Id$ */ - -/* Synced with php3 revision 1.121 1999-06-18 [ssb] */ -/* Synced with php3 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 WIN32 -#include <winsock.h> -#else -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> -#endif -#ifdef 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 "post.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 FREE_SOCK if(socketd >= 0) close(socketd); efree(sock); if (key) efree(key) - -#define SEARCHCR() \ - p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen)); - -#if WIN32|WINNT -#define EWOULDBLOCK WSAEWOULDBLOCK -#else -#include "build-defs.h" -#endif - -static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE }; - -function_entry fsock_functions[] = { - PHP_FE(fsockopen, third_and_fourth_args_force_ref) - PHP_FE(pfsockopen, third_and_fourth_args_force_ref) - {NULL, NULL, NULL} -}; - -struct php3i_sockbuf { - int socket; - unsigned char *readbuf; - size_t readbuflen; - size_t readpos; - size_t writepos; - struct php3i_sockbuf *next; - struct php3i_sockbuf *prev; - char eof; - char persistent; - char is_blocked; - size_t chunk_size; -}; - -typedef struct php3i_sockbuf php3i_sockbuf; - -php3_module_entry fsock_module_entry = { - "Socket functions", - fsock_functions, - PHP_MINIT(fsock), - PHP_MSHUTDOWN(fsock), - NULL, - PHP_RSHUTDOWN(fsock), - NULL, - STANDARD_MODULE_PROPERTIES -}; - - -/* {{{ 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; -} -/* }}} */ -/* {{{ _php3_is_persistent_sock */ - -int _php3_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(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(WIN32) && ... */ - return connect(sockfd, addr, addrlen); -#endif -} -/* }}} */ -/* {{{ _php3_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 _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) { - pval *args[5]; - int *sock=emalloc(sizeof(int)); - int *sockp; - int arg_count=ARG_COUNT(ht); - int socketd = -1; - struct timeval timeout = { 60, 0 }; - unsigned short portno; - unsigned long conv; - char *key = NULL; - FLS_FETCH(); - - if (arg_count > 5 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) { - FREE_SOCK; - WRONG_PARAM_COUNT; - } - switch(arg_count) { - case 5: - convert_to_double(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(args[0]); - convert_to_long(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) { - FREE_SOCK; - *sock = *sockp; - ZEND_REGISTER_RESOURCE(return_value,sock,php_file_le_socket()); - return; - } - - if (portno) { - struct sockaddr_in server; - - memset(&server, 0, sizeof(server)); - socketd = socket(AF_INET, SOCK_STREAM, 0); - if (socketd == SOCK_ERR) { - FREE_SOCK; - RETURN_FALSE; - } - - server.sin_family = AF_INET; - - if (lookup_hostname(args[0]->value.str.val, &server.sin_addr)) { - FREE_SOCK; - RETURN_FALSE; - } - - server.sin_port = htons(portno); - - if (connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) { - FREE_SOCK; - 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) { - FREE_SOCK; - 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) { - FREE_SOCK; - 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) -{ - _php3_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) -{ - _php3_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) -{ - php3i_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) \ - php3i_sockbuf *sock; \ - FLS_FETCH(); \ - sock = _php3_sock_find(socket FLS_CC); \ - if(!sock) sock = _php3_sock_create(socket FLS_CC) - -static php3i_sockbuf *_php3_sock_find(int socket FLS_DC) -{ - php3i_sockbuf *buf = NULL, *tmp; - - for(tmp = FG(phpsockbuf); tmp; tmp = tmp->next) - if(tmp->socket == socket) { - buf = tmp; - break; - } - - return buf; -} - -static php3i_sockbuf *_php3_sock_create(int socket FLS_DC) -{ - php3i_sockbuf *sock; - int persistent = _php3_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); - FG(phpsockbuf) = sock; - - return sock; -} - -size_t _php3_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 _php3_sock_destroy(int socket) -{ - int ret = 0; - php3i_sockbuf *sock; - FLS_FETCH(); - - sock = _php3_sock_find(socket FLS_CC); - if(sock) { - ret = 1; - SOCK_DESTROY(sock); - } - - return ret; -} - -#if !defined(WIN32) && !defined(WINNT) -#undef closesocket -#define closesocket close -#endif - -#ifndef HAVE_SHUTDOWN -#undef shutdown -#define shutdown -#endif - -#define SOCK_CLOSE(s) shutdown(s, 0); closesocket(s) - -int _php3_sock_close(int socket) -{ - int ret = 0; - php3i_sockbuf *sock; - FLS_FETCH(); - - sock = _php3_sock_find(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 _php3_sock_wait_for_data(php3i_sockbuf *sock) -{ - fd_set fdr, tfdr; - - FD_ZERO(&fdr); - FD_SET(sock->socket, &fdr); - - while(1) { - tfdr = fdr; - if(select(sock->socket + 1, &tfdr, NULL, NULL, NULL) == 1) - break; - } -} - -static size_t _php3_sock_read_internal(php3i_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) { - _php3_sock_wait_for_data(sock); - } - - /* 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 _php3_sock_read_total(php3i_sockbuf *sock, size_t maxread) -{ - while(!sock->eof && TOREAD(sock) < maxread) { - _php3_sock_read_internal(sock); - } -} - -static size_t _php3_sock_read(php3i_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 = _php3_sock_read_internal(sock); - if(nr_bytes == 0) break; - nr_read += nr_bytes; - } - - return nr_read; -} - -int _php3_sock_set_blocking(int socket, int mode) -{ - int old; - SOCK_FIND(sock, socket); - - old = sock->is_blocked; - - sock->is_blocked = mode; - - return old; -} - -#define SOCK_FIND_AND_READ_MAX(max) \ - SOCK_FIND(sock, socket); \ - if(sock->is_blocked) _php3_sock_read_total(sock, max); else _php3_sock_read(sock) - -/* {{{ _php3_sock_fgets() */ -/* - * FIXME: fgets depends on '\n' as line delimiter - */ -char *_php3_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 && TOREAD(sock) < maxlen) { - _php3_sock_read_internal(sock); - SEARCHCR(); - } - } else { - _php3_sock_read(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 _php3_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 _php3_sock_feof(int socket) -{ - int ret = 0; - SOCK_FIND(sock, socket); - - if(!sock->is_blocked) - _php3_sock_read(sock); - - if(!TOREAD(sock) && sock->eof) - ret = 1; - - return ret; -} - -/* {{{ _php3_sock_fread() */ - -size_t _php3_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 */ -int php_msock_destroy(int *data) -{ - close(*data); - return 1; -} -/* }}} */ - /* {{{ php3_minit_fsock */ - -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, (int (*)(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; -} -/* }}} */ - /* {{{ php3_mshutdown_fsock */ - -PHP_MSHUTDOWN_FUNCTION(fsock) -{ -#ifndef ZTS - fsock_globals_dtor(FLS_C); -#endif - return SUCCESS; -} -/* }}} */ - /* {{{ php3_rshutdown_fsock() */ - -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 cc0a360e25..0000000000 --- a/ext/standard/fsock.h +++ /dev/null @@ -1,104 +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 php3 revision 1.24 1999-06-18 [ssb] */ - -#ifndef _FSOCK_H -#define _FSOCK_H - -#if WIN32|WINNT -# 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 - -extern php3_module_entry fsock_module_entry; -#define phpext_fsock_ptr &fsock_module_entry - -PHP_FUNCTION(fsockopen); -PHP_FUNCTION(pfsockopen); -int lookup_hostname(const char *addr, struct in_addr *in); -char *_php3_sock_fgets(char *buf, size_t maxlen, int socket); -size_t _php3_sock_fread(char *buf, size_t maxlen, int socket); -int _php3_sock_feof(int socket); -int _php3_sock_fgetc(int socket); -int _php3_is_persistent_sock(int); -int _php3_sock_set_blocking(int socket, int mode); -int _php3_sock_destroy(int socket); -int _php3_sock_close(int socket); -size_t _php3_sock_set_def_chunk_size(size_t size); -int php_msock_destroy(int *data); - -PHPAPI int connect_nonb(int sockfd, struct sockaddr *addr, socklen_t addrlen, struct timeval *timeout); - -PHP_MINIT_FUNCTION(fsock); -PHP_MSHUTDOWN_FUNCTION(fsock); -PHP_RSHUTDOWN_FUNCTION(fsock); - -typedef struct { - HashTable ht_fsock_keys; - HashTable ht_fsock_socks; - struct php3i_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/global.h b/ext/standard/global.h deleted file mode 100644 index 3b52173897..0000000000 --- a/ext/standard/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 /* php3 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/head.c b/ext/standard/head.c deleted file mode 100644 index 523e3ff9ac..0000000000 --- a/ext/standard/head.c +++ /dev/null @@ -1,585 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -#include <stdio.h> -#include "php.h" -#include "ext/standard/php_standard.h" -#include "SAPI.h" -#include "main.h" -#include "head.h" -#include "post.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 php3_HeaderPrinted = 0; -static int php3_PrintHeader = 1; -static CookieList *top = NULL; -static char *cont_type = NULL; -static int header_called = 0; -#endif - -void php3_PushCookieList(char *, char *, time_t, char *, char *, int); -CookieList *php3_PopCookieList(void); - -PHP_RINIT_FUNCTION(head) -{ - php3_HeaderPrinted = 0; - if (header_called == 0) - php3_PrintHeader = 1; - top = NULL; - cont_type = NULL; - - return SUCCESS; -} - - -#if 0 -/* Adds header information */ -void php4i_add_header_information(char *header_information, uint header_length) -{ - char *r; -#if APACHE - char *rr = NULL; - char *temp = NULL; - long myuid = 0L; - char temp2[32]; - request_rec *req; - SLS_FETCH(); - - req = ((request_rec *) SG(server_context)); -#endif - - if (php3_HeaderPrinted == 1) { -#if DEBUG - php_error(E_WARNING, "Cannot add more header information - the header was already sent " - "(header information may be added only before any output is generated from the script - " - "check for text or whitespace outside PHP tags, or calls to functions that output text)"); -#endif - return; /* too late, already sent */ - } -#if APACHE - /* - * Not entirely sure this is the right way to support the header - * command in the Apache module. Comments? - */ - r = strchr(header_information, ':'); - if (r) { - *r = '\0'; - if (!strcasecmp(header_information, "Content-type")) { - if (*(r + 1) == ' ') - req->content_type = pstrdup(req->pool,r + 2); - else - req->content_type = pstrdup(req->pool,r + 1); - cont_type = (char *) req->content_type; - } else { - if (*(r + 1) == ' ') { - rr = r + 2; - } else { - rr = r + 1; - } - if (PG(safe_mode) && (!strcasecmp(header_information, "WWW-authenticate"))) { - myuid = _php3_getuid(); - sprintf(temp2, "realm=\"%ld ", myuid); /* SAFE */ - temp = _php3_regreplace("realm=\"", temp2, rr, 1, 0); - if (!strcmp(temp, rr)) { - sprintf(temp2, "realm=%ld", myuid); /* SAFE */ - temp = _php3_regreplace("realm=", temp2, rr, 1, 0); - if (!strcmp(temp, rr)) { - sprintf(temp2, " realm=%ld", myuid); /* SAFE */ - temp = _php3_regreplace("$", temp2, rr, 0, 0); - } - } - table_set(req->headers_out, header_information, temp); - } else - table_set(req->headers_out, header_information, rr); - } - if (!strcasecmp(header_information, "location")) { - req->status = REDIRECT; - } - *r = ':'; - php3_HeaderPrinted = 2; - } - if (!strncasecmp(header_information, "http/", 5)) { - if (strlen(header_information) > 9) { - req->status = atoi(&((header_information)[9])); - } - /* Use a pstrdup here to get the memory straight from Apache's per-request pool to - * avoid having our own memory manager complain about this memory not being freed - * because it really shouldn't be freed until the end of the request and it isn't - * easy for us to figure out when we allocated it vs. when something else might have. - */ - req->status_line = pstrdup(req->pool,&((header_information)[9])); - } -#else - r = strchr(header_information, ':'); - if (r) { - *r = '\0'; - if (!strcasecmp(header_information, "Content-type")) { - if (cont_type) efree(cont_type); - cont_type = estrdup(r + 1); -#if 0 /*WIN32|WINNT / *M$ does us again*/ - if (!strcmp(cont_type," text/html")){ - *r=':'; - PUTS_H(header_information); - PUTS_H("\015\012"); - } -#endif - } else { - *r = ':'; -#if USE_SAPI - { - char *tempstr=emalloc(strlen(header_information)+2); - - sprintf(tempstr,"%s\015\012",tempstr); - sapi_rqst->header(sapi_rqst->scid,tempstr); - efree(tempstr); - } -#elif FHTTPD - php3_fhttpd_puts_header(header_information); - php3_fhttpd_puts_header("\r\n"); -#else - PUTS_H(header_information); - PUTS_H("\015\012"); -#endif - } - } else { -#if USE_SAPI - { - char *tempstr=emalloc(strlen(header_information)+2); - sprintf(tempstr,"%s\015\012",tempstr); - sapi_rqst->header(sapi_rqst->scid,tempstr); - efree(tempstr); - } -#elif FHTTPD - php3_fhttpd_puts_header(header_information); - php3_fhttpd_puts_header("\r\n"); -#else - PUTS_H(header_information); - PUTS_H("\015\012"); -#endif - } -#endif -} -#else -void php4i_add_header_information(char *header_information, uint header_length) -{ - sapi_add_header(header_information, header_length); -} -#endif - - -/* Implementation of the language Header() function */ -PHP_FUNCTION(Header) -{ - pval *arg1; - - if (getParameters(ht, 1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(arg1); - php4i_add_header_information(arg1->value.str.val, arg1->value.str.len); - arg1->type = IS_LONG; /* change arg1's type so that it doesn't get freed */ - arg1->value.lval = 0; -} - - - - - -#if 0 -/* - * php3_header() flushes the header info built up using calls to - * the Header() function. If type is 1, a redirect to str is done. - * Otherwise type should be 0 and str NULL. - * - * The function returns non-zero if output is allowed after the - * call, and zero otherwise. Any call to php3_header() must check - * the return status and if false, no output must be sent. This - * is in order to correctly handle HEAD requests. - */ -PHPAPI int php3_header(void) -{ -#if APACHE - CookieList *cookie; - int len = 0; - time_t t; - char *dt, *cookievalue = NULL; -#endif -#if APACHE || defined(USE_SAPI) || FHTTPD - char *tempstr; -#endif - PLS_FETCH(); - SLS_FETCH(); - - if (PG(header_is_being_sent)) { - return 0; - } else { - PG(header_is_being_sent) = 1; - } - -#if APACHE - if (!((request_rec *) SG(server_context))) { /* we're not in a request, allow output */ - PG(header_is_being_sent) = 0; - return 1; - } - if ((php3_PrintHeader && !php3_HeaderPrinted) || (php3_PrintHeader && php3_HeaderPrinted == 2)) { - cookie = php3_PopCookieList(); - while (cookie) { - if (cookie->name) - len += strlen(cookie->name); - if (cookie->value) { - cookievalue = _php3_urlencode(cookie->value, strlen (cookie->value)); - len += strlen(cookievalue); - } - if (cookie->path) - len += strlen(cookie->path); - if (cookie->domain) - len += strlen(cookie->domain); - tempstr = emalloc(len + 100); - if (!cookie->value || (cookie->value && !*cookie->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(tempstr, "%s=deleted", cookie->name); - t = time(NULL) - 31536001; - strcat(tempstr, "; expires="); - dt = php3_std_date(t); - strcat(tempstr, dt); - efree(dt); - } else { - /* FIXME: XXX: this is not binary data safe */ - sprintf(tempstr, "%s=%s", cookie->name, cookie->value ? cookievalue : ""); - if (cookie->name) efree(cookie->name); - if (cookie->value) efree(cookie->value); - if (cookievalue) efree(cookievalue); - cookie->name=NULL; - cookie->value=NULL; - cookievalue=NULL; - if (cookie->expires > 0) { - strcat(tempstr, "; expires="); - dt = php3_std_date(cookie->expires); - strcat(tempstr, dt); - efree(dt); - } - } - if (cookie->path && strlen(cookie->path)) { - strcat(tempstr, "; path="); - strcat(tempstr, cookie->path); - efree(cookie->path); - cookie->path=NULL; - } - if (cookie->domain && strlen(cookie->domain)) { - strcat(tempstr, "; domain="); - strcat(tempstr, cookie->domain); - efree(cookie->domain); - cookie->domain=NULL; - } - if (cookie->secure) { - strcat(tempstr, "; secure"); - } - table_add(((request_rec *) SG(server_context))->headers_out, "Set-Cookie", tempstr); - if (cookie->domain) efree(cookie->domain); - if (cookie->path) efree(cookie->path); - if (cookie->name) efree(cookie->name); - if (cookie->value) efree(cookie->value); - if (cookievalue) efree(cookievalue); - efree(cookie); - cookie = php3_PopCookieList(); - efree(tempstr); - } - php3_HeaderPrinted = 1; - header_called = 1; - send_http_header(((request_rec *) SG(server_context))); - if (((request_rec *) SG(server_context))->header_only) { - set_header_request(1); - PG(header_is_being_sent) = 0; - return(0); - } - } -#else - if (php3_PrintHeader && !php3_HeaderPrinted) { - if (!cont_type) { -#if USE_SAPI - sapi_rqst->header(sapi_rqst->scid,"Content-type: text/html\015\012\015\012"); -#elif FHTTPD - php3_fhttpd_puts_header("Content-type: text/html\r\n"); -#else - PUTS_H("Content-type: text/html\015\012\015\012"); -#endif - } else { -#if 0 /*WIN32|WINNT / *M$ does us again*/ - if (!strcmp(cont_type,"text/html")){ -#endif -#if USE_SAPI - tempstr=emalloc(strlen(cont_type)+18); - sprintf(tempstr,"Content-type: %s\015\012\015\012",cont_type); - sapi_rqst->header(sapi_rqst->scid,tempstr); - efree(tempstr); -#elif FHTTPD - tempstr = emalloc(strlen(cont_type) - + sizeof("Content-type:") + 2); - if(tempstr) { - strcpy(tempstr, "Content-type:"); - strcpy(tempstr + sizeof("Content-type:") - 1, - cont_type); - strcat(tempstr, "\r\n"); - php3_fhttpd_puts_header(tempstr); - efree(tempstr); - } -#else - PUTS_H("Content-type:"); - PUTS_H(cont_type); - PUTS_H("\015\012\015\012"); -#endif - efree(cont_type); -#if 0 /*WIN32|WINNT / *M$ does us again*/ - } else { - PUTS_H("\015\012"); - }/*end excluding output of text/html*/ -#endif - } -#if USE_SAPI - sapi_rqst->flush(sapi_rqst->scid); -#else - fflush(stdout); -#endif - php3_HeaderPrinted = 1; - header_called = 1; - } -#endif - PG(header_is_being_sent) = 0; - return(1); -} -#else -PHPAPI int php3_header() -{ - SLS_FETCH(); - - if (sapi_send_headers()==FAILURE || SG(request_info).headers_only) { - return 0; /* don't allow output */ - } else { - return 1; /* allow output */ - } -} -#endif - - - -void php3_PushCookieList(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 *php3_PopCookieList(void) -{ - CookieList *ret; - - ret = top; - if (top) - top = top->next; - return (ret); -} - -/* php3_setcookie(name,value,expires,path,domain,secure) */ -PHP_FUNCTION(setcookie) -{ - char *cookie; - int len=sizeof("Set-Cookie: "); - time_t t; - char *r, *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 = ARG_COUNT(ht); - if (arg_count < 1 || arg_count > 6 || getParametersArray(ht, arg_count, arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (php3_HeaderPrinted == 1) { - php_error(E_WARNING, "Oops, php3_SetCookie called after header has been sent\n"); - return; - } - switch (arg_count) { - case 6: - convert_to_boolean(arg[5]); - secure = arg[5]->value.lval; - /* break missing intentionally */ - case 5: - convert_to_string(arg[4]); - domain = estrndup(arg[4]->value.str.val,arg[4]->value.str.len); - /* break missing intentionally */ - case 4: - convert_to_string(arg[3]); - path = estrndup(arg[3]->value.str.val,arg[3]->value.str.len); - /* break missing intentionally */ - case 3: - convert_to_long(arg[2]); - expires = arg[2]->value.lval; - /* break missing intentionally */ - case 2: - convert_to_string(arg[1]); - value = estrndup(arg[1]->value.str.val,arg[1]->value.str.len); - /* break missing intentionally */ - case 1: - convert_to_string(arg[0]); - name = estrndup(arg[0]->value.str.val,arg[0]->value.str.len); - break; - } -#if 0 - php3_PushCookieList(name, value, expires, path, domain, secure); -#else - if (name) { - len += strlen(name); - } - if (value) { - len += strlen(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 = php3_std_date(t); - strcat(cookie, dt); - efree(dt); - } else { - /* FIXME: XXX: this is not binary data safe */ - r = _php3_urlencode(value, strlen (value)); - sprintf(cookie, "Set-Cookie: %s=%s", name, value ? r : ""); - if (r) efree(r); - if (value) efree(value); - value=NULL; - if (name) efree(name); - name=NULL; - if (expires > 0) { - strcat(cookie, "; expires="); - dt = php3_std_date(expires); - strcat(cookie, dt); - efree(dt); - } - } - 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))==SUCCESS) { - RETVAL_TRUE; - } else { - RETVAL_FALSE; - } - - if (domain) { - efree(domain); - } - if (path) { - efree(path); - } - if (name) { - efree(name); - } - if (value) { - efree(value); - } -#endif -} - - -int php3_headers_unsent(void) -{ - if (php3_HeaderPrinted!=1 || !php3_PrintHeader) { - return 1; - } else { - return 0; - } -} - -PHP_FUNCTION(headers_sent) -{ - SLS_FETCH(); - - if (SG(headers_sent)) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} - -function_entry php3_header_functions[] = { - {NULL, NULL, NULL} -}; - - -php3_module_entry php3_header_module_entry = { - "PHP_head", php3_header_functions, NULL, NULL, PHP_RINIT(head), NULL, NULL, STANDARD_MODULE_PROPERTIES -}; - -/* - * 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 51208a606e..0000000000 --- a/ext/standard/head.h +++ /dev/null @@ -1,67 +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 PHP3 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 php3_module_entry php3_header_module_entry; -#define php3_header_module_ptr &php3_header_module_entry - -extern PHP_RINIT_FUNCTION(head); -PHP_FUNCTION(Header); -PHP_FUNCTION(setcookie); -PHP_FUNCTION(headers_sent); - -void php4i_add_header_information(char *header_information, uint header_length); - -PHPAPI int php3_header(void); -int php3_headers_unsent(void); - -#define phpext_head_ptr php3_header_module_ptr - -#endif diff --git a/ext/standard/html.c b/ext/standard/html.c deleted file mode 100644 index 93b01b2f53..0000000000 --- a/ext/standard/html.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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" -}; - -static void _php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS, int all) -{ - pval **arg; - int i, len, maxlen; - unsigned char *old; - char *new; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(arg); - - maxlen = 2 * (*arg)->value.str.len; - if (maxlen < 128) - maxlen = 128; - new = emalloc (maxlen); - len = 0; - - old = (unsigned char *)(*arg)->value.str.val; - i = (*arg)->value.str.len; - 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'; - - RETVAL_STRINGL(new,len,1); - efree(new); -} - -#define HTML_SPECIALCHARS 0 -#define HTML_ENTITIES 1 - -void register_html_constants(INIT_FUNC_ARGS) -{ - ELS_FETCH(); - 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) -{ - _php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0); -} -/* }}} */ - -/* {{{ proto string htmlentities(string string) - Convert all applicable characters to HTML entities */ -PHP_FUNCTION(htmlentities) -{ - _php3_htmlentities(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 = ARG_COUNT(ht); - int inx; - char ind[ 2 ]; - - if (ac < 0 || ac > 1 || getParametersEx(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 265f0656b7..0000000000 --- a/ext/standard/html.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> | - +----------------------------------------------------------------------+ - */ - -/* $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); - -#endif /* _HTML_H */ diff --git a/ext/standard/image.c b/ext/standard/image.c deleted file mode 100644 index cdcdf84ada..0000000000 --- a/ext/standard/image.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 php3_sig_gif[3] = -{'G', 'I', 'F'}; -const char php3_sig_jpg[3] = -{(char) 0xff, (char) 0xd8, (char) 0xff}; -const char php3_sig_png[8] = -{(char) 0x89, (char) 0x50, (char) 0x4e, - (char) 0x47, (char) 0x0d, (char) 0x0a, - (char) 0x1a, (char) 0x0a}; - -/* 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 *php3_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 php3_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 ]); - -} - -/* routine to handle PNG files. - even easier */ -static struct gfxinfo *php3_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 = php3_read4(fp); - in_height = php3_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 php3_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 php3_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 php3_skip_variable(FILE *fp) - /* skip over a variable-length block; assumes proper length marker */ -{ - unsigned short length; - - length = php3_read2(fp); - length -= 2; /* length includes itself */ - fseek(fp, (long) length, SEEK_CUR); /* skip the header */ -} - -static void php3_read_APP(FILE *fp,unsigned int marker,pval *info) -{ - unsigned short length; - unsigned char *buffer; - unsigned char markername[ 16 ]; - - length = php3_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 *php3_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 = php3_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 = php3_read2(fp); - result->width = php3_read2(fp); - result->channels = fgetc(fp); - - if (! info) /* if we don't want an extanded info -> return */ - return result; - } else { - php3_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) { - php3_read_APP(fp,marker,info); /* read all the app markes... */ - } else { - php3_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: - php3_skip_variable(fp); /* anything else isn't interesting */ - break; - } - } - - return NULL; -} - -/* main function */ -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(ARG_COUNT(ht)){ - case 1: - if (getParameters(ht, 1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(arg1); - break; - - case 2: - if (getParameters(ht, 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; - } - - pval_destructor(info); - - if (array_init(info) == FAILURE) { - return; - } - - convert_to_string(arg1); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - /* Check open_basedir */ - if (_php3_check_open_basedir(arg1->value.str.val)) return; - - if ((fp = 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, php3_sig_gif, 3)) { - result = php3_handle_gif (fp); - itype = 1; - } else if (!memcmp(filetype, php3_sig_jpg, 3)) { - result = php3_handle_jpeg(fp,info); - itype = 2; - } else if (!memcmp(filetype, php3_sig_png, 3)) { - fseek(fp, 0L, SEEK_SET); - fread(pngtype, sizeof(pngtype), 1, fp); - if (!memcmp(pngtype, php3_sig_png, 8)) { - result = php3_handle_png(fp); - itype = 3; - } else { - php_error(E_WARNING, "PNG file corrupted by ASCII conversion"); - } - } - 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 141de2f865..0000000000 --- a/ext/standard/info.c +++ /dev/null @@ -1,511 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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" -#ifndef MSVC5 -#include "build-defs.h" -#endif -#include "zend_globals.h" /* needs ELS */ - - -#define PHP3_CONF_LONG(directive,value1,value2) \ - php_printf("<tr><td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\">%s</td><td bgcolor=\"" PHP_CONTENTS_COLOR "\">%ld</td><td bgcolor=\"" PHP_CONTENTS_COLOR "\">%ld</td></tr>\n",directive,value1,value2); - -#define SECTION(name) PUTS("<hr><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("<hr><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><td bgcolor=\"" PHP_CONTENTS_COLOR "\">"); - php_printf(module->name); - php_printf("</td><tr>\n"); - } - return 0; -} - - -PHPAPI void php_print_info(int flag) -{ - char **env,*tmp1,*tmp2; - char *php3_uname; - int expose_php = INI_INT("expose_php"); -#if WIN32|WINNT - char php3_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(); - - - if (flag & PHP_INFO_GENERAL) { -#if WIN32|WINNT - // Get build numbers for Windows NT or Win95 - if (dwVersion < 0x80000000){ - dwBuild = (DWORD)(HIWORD(dwVersion)); - snprintf(php3_windows_uname,255,"%s %d.%d build %d","Windows NT",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild); - } else { - snprintf(php3_windows_uname,255,"%s %d.%d","Windows 95/98",dwWindowsMajorVersion,dwWindowsMinorVersion); - } - php3_uname = php3_windows_uname; -#else - php3_uname=PHP_UNAME; -#endif - - - php_printf("<center><h1>PHP Version %s</h1></center>\n", PHP_VERSION); - - PUTS("<hr>"); - if (expose_php) { - PUTS("<a href=\"http://www.php.net/\"><img src=\""); - if (SG(request_info).request_uri) { - PUTS(SG(request_info).request_uri); - } - PUTS("?=PHPE9568F34-D428-11d2-A769-00AA001ACF42\" border=\"0\" align=\"right\"></a>\n"); - } - php_printf("System: %s<br>Build Date: %s\n<br>", php3_uname, __DATE__); -#ifdef CONFIGURE_COMMAND - php_printf("Configure command: %s<br>\n", CONFIGURE_COMMAND); -#endif - php_printf("php.ini path: %s<br>\n", CONFIGURATION_FILE_PATH); - php_printf("ZEND_DEBUG=%d<br>\n", ZEND_DEBUG); -#ifdef ZTS - php_printf("ZTS is defined"); -#else - php_printf("ZTS is undefined"); -#endif - /* Zend Engine */ - PUTS("<hr>"); - 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><pre>%s</pre>", get_zend_version()); - } - - PUTS("<center>"); - - if ((flag & PHP_INFO_CREDITS) && expose_php) { - PUTS("<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>\n"); - PUTS("</a>\n"); - } - - - if (flag & PHP_INFO_CONFIGURATION) { - PUTS("<hr><h1>Configuration</h1>\n"); - PUTS("<h2>PHP Core</h2>\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"); - PUTS("<table border=5 width=\"600\">\n"); - show_info_func = 0; - zend_hash_apply_with_argument(&module_registry, (int (*)(void *, void *)) _display_module_info, &show_info_func); - PUTS("</table>\n"); - } - - if (flag & PHP_INFO_ENVIRONMENT) { - SECTION("Environment"); - PUTS("<table border=5 width=\"600\">\n"); - 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); - } - PUTS("</table>\n"); - } - - if (flag & PHP_INFO_VARIABLES) { - pval **data, **tmp; - char *string_key; - ulong num_key; - - SECTION("PHP Variables"); - - PUTS("<table border=5 width=\"600\">\n"); - 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); - } - if (zend_hash_find(&EG(symbol_table), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), (void **) &data) != FAILURE) { - 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><td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>HTTP_GET_VARS[\""); - 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 bgcolor=\"" PHP_CONTENTS_COLOR "\">"); - 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); - } - } - } - if (zend_hash_find(&EG(symbol_table), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), (void **) &data) != FAILURE) { - zend_hash_internal_pointer_reset((*data)->value.ht); - while (zend_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) { - convert_to_string(*tmp); - PUTS("<tr><td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>HTTP_POST_VARS[\""); - 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 bgcolor=\"" PHP_CONTENTS_COLOR "\">"); - PUTS((*tmp)->value.str.val); - PUTS("</td></tr>\n"); - zend_hash_move_forward((*data)->value.ht); - } - } - if (zend_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), (void **) &data) != FAILURE) { - zend_hash_internal_pointer_reset((*data)->value.ht); - while (zend_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) { - convert_to_string(*tmp); - PUTS("<tr><td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>HTTP_COOKIE_VARS[\""); - 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 bgcolor=\"" PHP_CONTENTS_COLOR "\">"); - PUTS((*tmp)->value.str.val); - PUTS("</td></tr>\n"); - zend_hash_move_forward((*data)->value.ht); - } - } - PUTS("</table>\n"); - } - - PUTS("</center>"); - - - if (flag & PHP_INFO_LICENSE) { - SECTION("PHP License"); - PUTS("<PRE>This program is free software; you can redistribute it and/or modify\n"); - PUTS("it under the terms of the PHP License as published by the PHP Group\n"); - PUTS("and included in the distribution in the file: LICENSE\n"); - PUTS("\n"); - PUTS("This program is distributed in the hope that it will be useful,\n"); - PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); - PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); - PUTS("\n"); - PUTS("If you did not receive a copy of the PHP license, or have any questions about\n"); - PUTS("PHP licensing, please contact license@php.net.</PRE>\n"); - } -} - - -void php_print_credits(int flag) -{ - if (flag & PHP_CREDITS_FULLPAGE) { - PUTS("<html><head><title>PHP Credits</title></head><body><center>\n"); - } - - PUTS("<h1>PHP 4.0 Credits</h1>\n"); - - if (flag & PHP_CREDITS_GENERAL) { - /* Language */ - PUTS("<table border=5 width=\"600\">\n"); - PUTS("<tr><th colspan=\"2\" bgcolor=\"" PHP_HEADER_COLOR "\">PHP 4.0 Authors</th></tr>\n"); - 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"); - CREDIT_LINE("Apache SAPI Module", "Rasmus Lerdorf, Zeev Suraski"); - CREDIT_LINE("ISAPI SAPI Module", "Andi Gutmans, Zeev Suraski"); - CREDIT_LINE("CGI SAPI Module", "Rasmus Lerdorf, Stig Bakken"); - CREDIT_LINE("AOLserver SAPI Module", "Sascha Schumann"); - CREDIT_LINE("Servlet SAPI Module", "Sam Ruby"); - CREDIT_LINE("Roxen SAPI Module", "David Hedbor"); - CREDIT_LINE("Overall Work", "Thies C. Arntzen, Stig Bakken, Shane Caraveo, \ - Rasmus Lerdorf, Sascha Schumann, Zeev Suraski, Andrei Zmievski, \ - and others"); - PUTS("</table>\n"); - } - - if (flag & PHP_CREDITS_MODULES) { - /* Modules */ - PUTS("<table border=5 width=\"600\">\n"); - PUTS("<tr><th colspan=\"2\" bgcolor=\"" PHP_HEADER_COLOR "\">Module Authors</th></tr>\n"); - php_info_print_table_header(2, "Module", "Authors"); - CREDIT_LINE("Apache", "Rasmus Lerdorf, Stig Bakken, David Sklar"); - 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("GD imaging", "Rasmus Lerdorf, Stig Bakken, Jim Winstead"); - 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"); - CREDIT_LINE("Informix", "Danny Heijl, Christian Cartus, Jouni Ahto"); - CREDIT_LINE("Java", "Sam Ruby"); - CREDIT_LINE("Interbase", "Jouni Ahto"); - CREDIT_LINE("LDAP", "Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson"); - 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("PostgreSQL", "Jouni Ahto, Zeev Suraski"); - CREDIT_LINE("Sessions", "Sascha Schumann, Andrei Zmievski"); - CREDIT_LINE("SNMP", "Rasmus Lerdorf"); - 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"); - PUTS("</table>\n"); - } - - if (flag & PHP_CREDITS_DOCS) { - /* Documentation */ - } - - if (flag & PHP_CREDITS_FULLPAGE) { - PUTS("</center></body></html>\n"); - } -} - - -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>"); - for (i=0; i<num_cols; i++) { - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - row_element = " "; - } - php_printf("<th bgcolor=\"" PHP_HEADER_COLOR "\" valign=\"top\">%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 *color = PHP_ENTRY_NAME_COLOR; - char *row_element; - - va_start(row_elements, num_cols); - - php_printf("<tr>"); - for (i=0; i<num_cols; i++) { - row_element = va_arg(row_elements, char *); - if (!row_element || !*row_element) { - row_element = " "; - } - php_printf("<td bgcolor=\"%s\" valign=\"top\">%s%s%s</td>", - color, (i==0?"<b>":""), row_element, (i==0?"</b>":"")); - color = PHP_CONTENTS_COLOR; - } - php_printf("</tr>\n"); - - va_end(row_elements); -} - - - -void register_phpinfo_constants(INIT_FUNC_ARGS) -{ - ELS_FETCH(); - - 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); -} - - -/* {{{ 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 (ARG_COUNT(ht)) { - case 0: - flag = 0xFFFFFFFF; - break; - case 1: - if (getParameters(ht, 1, &flag_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long(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 (ARG_COUNT(ht)) { - case 0: - flag = 0xFFFFFFFF; - break; - case 1: - if (getParameters(ht, 1, &flag_arg)==FAILURE) { - RETURN_FALSE; - } - convert_to_long(flag_arg); - flag = flag_arg->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - php_print_credits(flag); - RETURN_TRUE; -} -/* }}} */ - -/* - * 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 627accf213..0000000000 --- a/ext/standard/info.h +++ /dev/null @@ -1,67 +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 "#FFFFFF" -#define PHP_CONTENTS_COLOR "#DDDDDD" -#define PHP_HEADER_COLOR "#FFFF99" - -#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_GENERAL (1<<0) -#define PHP_CREDITS_MODULES (1<<1) -#define PHP_CREDITS_DOCS (1<<2) -#define PHP_CREDITS_FULLPAGE (1<<3) -#define PHP_CREDITS_ALL 0xFFFFFFFF - -PHP_FUNCTION(phpversion); -PHP_FUNCTION(phpinfo); -PHP_FUNCTION(phpcredits); -PHPAPI void php_print_info(int flag); -PHPAPI void php_print_credits(int flag); - - -PHPAPI void php_info_print_table_header(int num_cols, ...); -PHPAPI void php_info_print_table_row(int num_cols, ...); - -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 a15ac04020..0000000000 --- a/ext/standard/iptc.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 php3_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 php3_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 php3_iptc_read_remaining(FILE *fp,int spool,unsigned char **spoolbuf) -{ - int c; - - while ((c = php3_iptc_get1(fp,spool,spoolbuf)) != EOF) continue; - - return M_EOI; -} - -static int php3_iptc_skip_variable(FILE *fp,int spool,unsigned char **spoolbuf) -{ - unsigned int length; - int c1,c2; - - if ((c1 = php3_iptc_get1(fp,spool,spoolbuf)) == EOF) return M_EOI; - - if ((c2 = php3_iptc_get1(fp,spool,spoolbuf)) == EOF) return M_EOI; - - length = (((unsigned char) c1) << 8) + ((unsigned char) c2); - - length -= 2; - - while (length--) - if (php3_iptc_get1(fp,spool,spoolbuf) == EOF) return M_EOI; - - return 0; -} - -static int php3_iptc_nextmarker(FILE *fp,int spool,unsigned char **spoolbuf) -{ - int c; - - /* skip unimportant stuff */ - - c = php3_iptc_get1(fp,spool,spoolbuf); - - if (c == EOF) return M_EOI; - - while (c != 0xff) { - if ((c = php3_iptc_get1(fp,spool,spoolbuf)) == EOF) - return M_EOI; /* we hit EOF */ - } - - /* get marker byte, swallowing possible padding */ - do { - c = php3_iptc_get1(fp,0,0); - if (c == EOF) - return M_EOI; /* we hit EOF */ - else - if (c == 0xff) - php3_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) -{ - pval *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(ARG_COUNT(ht)){ - case 3: - if (getParameters(ht, 3, &iptcdata, &jpeg_file, &spool_flag) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(iptcdata); - convert_to_string(jpeg_file); - convert_to_long(spool_flag); - spool = spool_flag->value.lval; - break; - - case 2: - if (getParameters(ht, 2, &iptcdata, &jpeg_file) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(iptcdata); - convert_to_string(jpeg_file); - break; - - default: - WRONG_PARAM_COUNT; - break; - } - - if (_php3_check_open_basedir(jpeg_file->value.str.val)) - RETURN_FALSE; - - if ((fp = 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 (!php3_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 + 30 + sb.st_size); - - if (! spoolbuf) { - fclose(fp); - RETURN_FALSE; - } - } - - if (php3_iptc_get1(fp,spool,poi?&poi:0) != 0xFF) { - fclose(fp); - RETURN_FALSE; - } - - if (php3_iptc_get1(fp,spool,poi?&poi:0) != 0xD8) { - fclose(fp); - RETURN_FALSE; - } - - while (!done) { - marker = php3_iptc_nextmarker(fp,spool,poi?&poi:0); - - if (marker == M_EOI) { /* EOF */ - break; - } else if (marker != M_APP13) { - php3_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 */ - php3_iptc_skip_variable(fp,0,0); - php3_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! */ - php3_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++) - php3_iptc_put1(fp,spool,psheader[inx],poi?&poi:0); - - php3_iptc_put1(fp,spool,(unsigned char)(len>>8),poi?&poi:0); - php3_iptc_put1(fp,spool,(unsigned char)(len&0xff),poi?&poi:0); - - for (inx = 0; inx < len; inx++) - php3_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! */ - php3_iptc_read_remaining(fp,spool,poi?&poi:0); - done = 1; - break; - - default: - php3_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 ]; - pval *values, *str, **element; - - if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string(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) { - values = emalloc(sizeof(pval)); - 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 4e0d1b4ccc..0000000000 --- a/ext/standard/lcg.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 - -#if WIN32||WINNT -#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 -} - -static int php_minit_lcg(INIT_FUNC_ARGS) -{ -#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()); -} -/* }}} */ - -static function_entry lcg_functions[] = { - PHP_FE(lcg_value, NULL) - {0} -}; - -zend_module_entry lcg_module_entry = { - "LCG", - lcg_functions, - php_minit_lcg, NULL, - NULL, NULL, - NULL, - STANDARD_MODULE_PROPERTIES -}; diff --git a/ext/standard/link.c b/ext/standard/link.c deleted file mode 100644 index f296a2dbcb..0000000000 --- a/ext/standard/link.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 -#if MSVC5 -#include "win32/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#if HAVE_GRP_H -#if MSVC5 -#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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - ret = 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 (ARG_COUNT(ht) != 2 || getParametersEx(2, &topath, &frompath) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(topath); - convert_to_string_ex(frompath); - - if (PG(safe_mode) && !_php3_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 (ARG_COUNT(ht) != 2 || getParametersEx(2, &topath, &frompath) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(topath); - convert_to_string_ex(frompath); - - if (PG(safe_mode) && !_php3_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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &filename) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(filename); - - if (PG(safe_mode) && !_php3_checkuid((*filename)->value.str.val, 2)) { - RETURN_FALSE; - } - - ret = unlink((*filename)->value.str.val); - if (ret == -1) { - php_error(E_WARNING, "Unlink failed (%s)", strerror(errno)); - RETURN_FALSE; - } - /* Clear stat cache */ - php3_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 db4988a659..0000000000 --- a/ext/standard/mail.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> -#include <ctype.h> -#include <stdio.h> -#include "php.h" -#ifndef MSVC5 -#include "build-defs.h" -#endif -#include "php_mail.h" -#include "php_ini.h" - -#if APACHE -# ifndef DEBUG -# undef palloc -# endif -#endif - -#if HAVE_SENDMAIL -#if MSVC5 -#include "win32/sendmail.h" -#endif - -function_entry mail_functions[] = { - PHP_FE(mail, NULL) - {NULL, NULL, NULL} -}; - -php3_module_entry mail_module_entry = { - "Sendmail", mail_functions, NULL, NULL, NULL, NULL, PHP_MINFO(mail), STANDARD_MODULE_PROPERTIES -}; - - -#if COMPILE_DL -DLEXPORT php3_module_entry *get_module(void) { return &odbc_module_entry; } -#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 = ARG_COUNT(ht); - if (argc < 3 || argc > 4 || getParametersArrayEx(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 (_php3_mail(to, subject, message, headers)){ - RETURN_TRUE; - } else { - RETURN_FALSE; - } -} -/* }}} */ - -int _php3_mail(char *to, char *subject, char *message, char *headers) -{ -#if MSVC5 - int tsm_err; -#else - FILE *sendmail; - int ret; - char *sendmail_path = INI_STR("sendmail_path"); -#endif - -#if MSVC5 - 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) -{ -#if MSVC5 - PUTS("Internal Sendmail support for Windows 4"); -#else - php_printf("Path to sendmail: <tt>%s</tt>", 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 0ab4fbc16c..0000000000 --- a/ext/standard/math.c +++ /dev/null @@ -1,712 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 "snprintf.h" - -#include <math.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 (ARG_COUNT(ht)!=1||getParametersEx(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 (ARG_COUNT(ht)!=1||getParametersEx(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 (ARG_COUNT(ht)!=1||getParametersEx(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 int round(double number) - Returns the rounded value of the number */ - -#ifndef HAVE_RINT -/* emulate rint */ -inline double rint(double n) -{ - double i, f; - f = modf(n, &i); - if (f > .5) - i++; - else if (f < -.5) - i--; - return i; -} -#endif - -PHP_FUNCTION(round) -{ - zval **value; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &value) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_scalar_to_number_ex(value); - - if ((*value)->type == IS_DOUBLE) { - RETURN_DOUBLE(rint((*value)->value.dval)); - } else if ((*value)->type == IS_LONG) { - RETURN_DOUBLE((double)(*value)->value.lval); - } - RETURN_FALSE; -} - -/* }}} */ -/* {{{ proto double sin(double number) - Returns the sine of the number in radians */ - -PHP_FUNCTION(sin) -{ - zval **num; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 2 || getParametersEx(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 (ARG_COUNT(ht) != 2 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 3 || getParametersEx(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(32+dec); - - tmplen=php_sprintf(tmpbuf,"%.*f",dec,d); - - if (!isdigit((int)tmpbuf[0])) { - return tmpbuf; - } - - for (t=tmpbuf; *t; t++) { - if (*t=='.') { - *t = dec_point; - } - } - 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(ARG_COUNT(ht)) { - case 1: - if (getParametersEx(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 (getParametersEx(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 (getParametersEx(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 3396e261af..0000000000 --- a/ext/standard/md5.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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_FUNCTION(md5) -{ - pval **arg; - char md5str[33]; - PHP3_MD5_CTX context; - unsigned char digest[16]; - int i; - char *r; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - md5str[0] = '\0'; - PHP3_MD5Init(&context); - PHP3_MD5Update(&context, (*arg)->value.str.val, (*arg)->value.str.len); - PHP3_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 PHP3_MD5Init(PHP3_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 PHP3_MD5Update(PHP3_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 PHP3_MD5Final(unsigned char digest[16], PHP3_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); - PHP3_MD5Update(context, PADDING, padLen); - - /* Append length (before padding) */ - PHP3_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 47ce03682e..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 "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 */ -} PHP3_MD5_CTX; - -void PHP3_MD5Init PROTO_LIST((PHP3_MD5_CTX *)); -void PHP3_MD5Update PROTO_LIST((PHP3_MD5_CTX *, const unsigned char *, unsigned int)); -void PHP3_MD5Final PROTO_LIST((unsigned char[16], PHP3_MD5_CTX *)); - -PHP_FUNCTION(md5); - -#endif diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c deleted file mode 100644 index 7c6832ef5d..0000000000 --- a/ext/standard/metaphone.c +++ /dev/null @@ -1,475 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 2.01 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. | - +----------------------------------------------------------------------+ - | 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); - -function_entry metaphone_functions[] = -{ - PHP_FE(metaphone, NULL) - {0}, -}; - -zend_module_entry metaphone_module_entry = -{ - "Metaphone", - metaphone_functions, - NULL, - NULL, - NULL, - NULL, - NULL, - STANDARD_MODULE_PROPERTIES, -}; - -/* metaphone -- Breaks english phrases down into their phonemes. */ -PHP_FUNCTION(metaphone) -{ - pval *pstr, *pphones; - char *result = 0; - int phones = 0; - - if (getParameters(ht, 2, &pstr, &pphones) == SUCCESS) { - convert_to_long(pphones); - phones = pphones->value.lval; - } else if (getParameters(ht, 1, &pstr) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(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... */ -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 */ diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c deleted file mode 100644 index 1eec292e18..0000000000 --- a/ext/standard/microtime.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Paul Panotzki - Bunyip Information Systems | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdlib.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <string.h> -#include <errno.h> - -#include "php.h" -#include "microtime.h" -#include "snprintf.h" - -#include <stdio.h> -#ifdef HAVE_GETTIMEOFDAY -#if MSVC5 -#include "win32/time.h" -#else -#include <sys/time.h> -#endif -#endif - -#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; -} -/* }}} */ - -/* {{{ proto array getrusage([ int who ]) - returns an array of usage statistics */ -PHP_FUNCTION(getrusage) -{ -#if HAVE_GETRUSAGE - struct rusage usg; - int ac = ARG_COUNT(ht); - pval **pwho; - int who = RUSAGE_SELF; - - if(ac == 1 && - getParametersEx(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 PHP3_RUSAGE_PARA(a) \ - add_assoc_long(return_value, #a, usg.a) -#ifndef _OSD_POSIX /* BS2000 has only a few fields in the rusage struct */ - PHP3_RUSAGE_PARA(ru_oublock); - PHP3_RUSAGE_PARA(ru_inblock); - PHP3_RUSAGE_PARA(ru_msgsnd); - PHP3_RUSAGE_PARA(ru_msgrcv); - PHP3_RUSAGE_PARA(ru_maxrss); - PHP3_RUSAGE_PARA(ru_ixrss); - PHP3_RUSAGE_PARA(ru_idrss); - PHP3_RUSAGE_PARA(ru_minflt); - PHP3_RUSAGE_PARA(ru_majflt); - PHP3_RUSAGE_PARA(ru_nsignals); - PHP3_RUSAGE_PARA(ru_nvcsw); - PHP3_RUSAGE_PARA(ru_nivcsw); -#endif /*_OSD_POSIX*/ - PHP3_RUSAGE_PARA(ru_utime.tv_usec); - PHP3_RUSAGE_PARA(ru_utime.tv_sec); - PHP3_RUSAGE_PARA(ru_stime.tv_usec); - PHP3_RUSAGE_PARA(ru_stime.tv_sec); -#undef PHP3_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 a4b022313c..0000000000 --- a/ext/standard/output.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans <andi@zend.com> | - | 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); - -void php_start_ob_buffering(void); -void php_end_ob_buffering(int send_buffer); -int php_ob_get_buffer(pval *p); - -/* HEAD support */ -void set_header_request(int value); - -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; -} 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 - - -PHP_FUNCTION(ob_start); -PHP_FUNCTION(ob_end_flush); -PHP_FUNCTION(ob_end_clean); -PHP_FUNCTION(ob_get_contents); - - -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; -} - - -PHP_GINIT_FUNCTION(output) -{ -#ifdef ZTS - output_globals_id = ts_allocate_id(sizeof(php_output_globals), NULL, NULL); -#else - php_output_init_globals(OLS_C); -#endif - - return SUCCESS; -} - -static zend_function_entry php_output_functions[] = { - PHP_FE(ob_start, NULL) - PHP_FE(ob_end_flush, NULL) - PHP_FE(ob_end_clean, NULL) - PHP_FE(ob_get_contents, NULL) - {NULL, NULL, NULL} -}; - -PHP_RINIT_FUNCTION(output); -PHP_RSHUTDOWN_FUNCTION(output); - -php3_module_entry output_module_entry = { - "PHP_output", - php_output_functions, - NULL, /* extension-wide startup function */ - NULL, /* extension-wide shutdown function */ - PHP_RINIT(output), /* per-request startup function */ - PHP_RSHUTDOWN(output), /* per-request shutdown function */ - NULL, /* information function */ - PHP_GINIT(output), /* global startup function */ - NULL, /* global shutdown function */ - STANDARD_MODULE_PROPERTIES_EX -}; - -PHP_RINIT_FUNCTION(output) -{ - php_output_startup(); - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(output) -{ - /* XXX needs filling in */ - 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(); -} - - -/* - * 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); - } - - 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 (php3_header()) { - OG(php_body_write) = php_ub_body_write_no_header; - result = php_ub_body_write_no_header(str, str_length); - } - - return result; -} - - -/* - * HEAD support - */ - -void set_header_request(int value) -{ - /* deprecated */ -} - -PHP_FUNCTION(ob_start) -{ - php_start_ob_buffering(); -} - - -PHP_FUNCTION(ob_end_flush) -{ - php_end_ob_buffering(1); -} - - -PHP_FUNCTION(ob_end_clean) -{ - php_end_ob_buffering(0); -} - - -PHP_FUNCTION(ob_get_contents) -{ - if (php_ob_get_buffer(return_value)==FAILURE) { - RETURN_FALSE; - } -} - - -/* - * 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 af6ad58f5d..0000000000 --- a/ext/standard/pack.c +++ /dev/null @@ -1,874 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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> -#if MSVC5 -#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 -#if MSVC5 -#include "win32/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#include "snprintf.h" -#include "fsock.h" -#if HAVE_NETINET_IN_H -#include <netinet/in.h> -#endif - -function_entry pack_functions[] = { - PHP_FE(pack, NULL) - PHP_FE(unpack, NULL) - {NULL, NULL, NULL} -}; - -php3_module_entry pack_module_entry = { - "PHP_pack", pack_functions, PHP_MINIT(pack), NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES -}; - -/* 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 _php3_pack(pval *val, int size, int *map, char *output) -{ - int i; - char *v; - - convert_to_long(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 = ARG_COUNT(ht); - - if (argc < 1) { - WRONG_PARAM_COUNT; - } - - argv = emalloc(argc * sizeof(pval *)); - - if (getParametersArray(ht, argc, argv) == FAILURE) { - efree(argv); - WRONG_PARAM_COUNT; - } - - convert_to_string(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(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(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) { - _php3_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) { - _php3_pack(argv[currentarg++], 2, map, &output[outputpos]); - outputpos += 2; - } - break; - } - - case 'i': case 'I': { - while (arg-- > 0) { - _php3_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) { - _php3_pack(argv[currentarg++], 4, map, &output[outputpos]); - outputpos += 4; - } - break; - } - - case 'f': { - float v; - - while (arg-- > 0) { - val = argv[currentarg++]; - convert_to_double(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(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 _php3_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 ((ARG_COUNT(ht) != 2) || getParameters(ht, 2, &formatarg, &inputarg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(formatarg); - convert_to_string(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 = _php3_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 = _php3_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 = _php3_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 = _php3_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 bad1af9cfe..0000000000 --- a/ext/standard/pack.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 _PACK_H -#define _PACK_H - -extern php3_module_entry pack_module_entry; -#define pack_module_ptr &pack_module_entry - -extern PHP_MINIT_FUNCTION(pack); -PHP_FUNCTION(pack); -PHP_FUNCTION(unpack); - -#define phpext_pack_ptr pack_module_ptr - -#endif /* _PACK_H */ diff --git a/ext/standard/pageinfo.c b/ext/standard/pageinfo.c deleted file mode 100644 index 464d2a0bed..0000000000 --- a/ext/standard/pageinfo.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 -#if MSVC5 -#include "win32/pwd.h" -#else -#include <pwd.h> -#endif -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#include <sys/stat.h> -#if MSVC5 -#include <process.h> -#endif - -#ifndef THREAD_SAFE -static long page_uid = -1; -static long page_inode = -1; -static long page_mtime = -1; -#endif - -static void _php3_statpage(void) -{ -#if !APACHE - char *path; - struct stat sb; -#else - request_rec *r; - SLS_FETCH(); - - r = ((request_rec *) SG(server_context)); -#endif - -#if APACHE - /* Apache has already gone through the trouble of doing - the stat(), so the only real overhead is copying three - values. We can afford it, and it means we don't have to - worry about resetting the static variables after every - hit. */ - page_uid = r ->finfo.st_uid; - page_inode = r->finfo.st_ino; - page_mtime = r->finfo.st_mtime; -#else - if (page_uid == -1) { - SLS_FETCH(); - - path = SG(request_info).path_translated; - if (path != NULL) { - if (stat(path, &sb) == -1) { - php_error(E_WARNING, "Unable to find file: '%s'", path); - return; - } - page_uid = sb.st_uid; - page_inode = sb.st_ino; - page_mtime = sb.st_mtime; - } - } -#endif -} - -long _php3_getuid(void) -{ - _php3_statpage(); - return (page_uid); -} - -/* {{{ proto int getmyuid(void) - Get PHP script owner's UID */ -PHP_FUNCTION(getmyuid) -{ - long uid; - - uid = _php3_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) -{ - _php3_statpage(); - if (page_inode < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(page_inode); - } -} -/* }}} */ - -/* {{{ proto int getlastmod(void) - Get time of last page modification */ -PHP_FUNCTION(getlastmod) -{ - _php3_statpage(); - if (page_mtime < 0) { - RETURN_FALSE; - } else { - RETURN_LONG(page_mtime); - } -} -/* }}} */ diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h deleted file mode 100644 index d593ade004..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 _php3_getuid(void); - -#endif diff --git a/ext/standard/parsedate.y b/ext/standard/parsedate.y deleted file mode 100644 index 60245f6c69..0000000000 --- a/ext/standard/parsedate.y +++ /dev/null @@ -1,917 +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 */ - - -#ifdef WIN32 -# include "config.w32.h" -#else -# include "php_config.h" -#endif - -#if WIN32||WINNT -#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 WIN32 -# include "win32/time.h" -#endif - -#include <ctype.h> - -#if defined(_HPUX_SOURCE) -#include <alloca.h> -#endif - -#if WIN32||WINNT -# include <time.h> -# include "php_reentrancy.h" -#else -# if !defined(HAVE_TM_ZONE) && !defined(_TIMEZONE) -extern time_t timezone; -# endif -#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 = 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 = 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 && 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 = (localtime_r(&Start,&tmbuf)->tm_hour + 1) % 24; - FutureDay = (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 = 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 = 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 2fee1a3589..0000000000 --- a/ext/standard/php_array.h +++ /dev/null @@ -1,106 +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$ */ - -#ifndef _PHP_ARRAY_H -#define _PHP_ARRAY_H - -extern zend_module_entry array_module_entry; -#define array_module_ptr &array_module_entry - -PHP_MINIT_FUNCTION(array); -PHP_MSHUTDOWN_FUNCTION(array); - -PHP_FUNCTION(ksort); -PHP_FUNCTION(krsort); -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(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_keys); -PHP_FUNCTION(array_values); -PHP_FUNCTION(array_count_values); -PHP_FUNCTION(array_reverse); -PHP_FUNCTION(array_pad); -PHP_FUNCTION(array_flip); - -HashTable* _phpi_splice(HashTable *, int, int, zval ***, int, HashTable **); -int multisort_compare(const void *a, const void *b); - -typedef struct { - int *multisort_flags; -} 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 - -#define phpext_array_ptr array_module_ptr -#endif /* _PHP_ARRAY_H */ diff --git a/ext/standard/php_assert.h b/ext/standard/php_assert.h deleted file mode 100644 index 597eb6af4c..0000000000 --- a/ext/standard/php_assert.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _PHP_ASSERT_H -#define _PHP_ASSERT_H - -extern zend_module_entry assert_module_entry; -#define phpext_assert_ptr &assert_module_entry - - -#endif /* _PHP_ASSERT_H */ diff --git a/ext/standard/php_browscap.h b/ext/standard/php_browscap.h deleted file mode 100644 index 338272692e..0000000000 --- a/ext/standard/php_browscap.h +++ /dev/null @@ -1,45 +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 php3_module_entry browscap_module_entry; -#define browscap_module_ptr &browscap_module_entry - -extern PHP_MINIT_FUNCTION(browscap); -extern PHP_MSHUTDOWN_FUNCTION(browscap); - -PHP_FUNCTION(get_browser); - - -#define phpext_browscap_ptr browscap_module_ptr - -#endif /* _PHP_BROWSCAP_H */ diff --git a/ext/standard/php_crypt.h b/ext/standard/php_crypt.h deleted file mode 100644 index 1b93431cb5..0000000000 --- a/ext/standard/php_crypt.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef PHP_CRYPT_H -#define PHP_CRYPT_H - -#if HAVE_CRYPT -extern php3_module_entry crypt_module_entry; -#define crypt_module_ptr &crypt_module_entry -PHP_FUNCTION(crypt); -extern PHP_MINIT_FUNCTION(crypt); -#else -#define crypt_module_ptr NULL -#endif - -#define phpext_crypt_ptr crypt_module_ptr - -#endif diff --git a/ext/standard/php_dir.h b/ext/standard/php_dir.h deleted file mode 100644 index bb09e2fbdd..0000000000 --- a/ext/standard/php_dir.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: | - | PHP 4.0 patches by Thies C. Arntzen (thies@digicol.de) | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _PHP_DIR_H -#define _PHP_DIR_H -extern php3_module_entry php3_dir_module_entry; -#define php3_dir_module_ptr &php3_dir_module_entry - -/* 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); - -#define phpext_dir_ptr php3_dir_module_ptr - -#endif /* _PHP_DIR_H */ diff --git a/ext/standard/php_filestat.h b/ext/standard/php_filestat.h deleted file mode 100644 index 05003fa807..0000000000 --- a/ext/standard/php_filestat.h +++ /dev/null @@ -1,69 +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); - -extern php3_module_entry php3_filestat_module_entry; -#define php3_filestat_module_ptr &php3_filestat_module_entry - -#define phpext_filestat_ptr php3_filestat_module_ptr - -#endif /* _FILESTAT_H */ diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h deleted file mode 100644 index 39dd9fa2fd..0000000000 --- a/ext/standard/php_image.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 cf397f7771..0000000000 --- a/ext/standard/php_lcg.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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); - -#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 - -extern zend_module_entry lcg_module_entry; -#define phpext_lcg_ptr &lcg_module_entry - -#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 918bcbdf1c..0000000000 --- a/ext/standard/php_mail.h +++ /dev/null @@ -1,49 +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 -extern php3_module_entry mail_module_entry; -#define mail_module_ptr &mail_module_entry - -PHP_FUNCTION(mail); -PHP_MINFO_FUNCTION(mail); -extern int _php3_mail(char *to, char *subject, char *message, char *headers); - -#else -#define mail_module_ptr NULL -#endif - -#define phpext_mail_ptr mail_module_ptr - -#endif /* _MAIL_H */ diff --git a/ext/standard/php_metaphone.h b/ext/standard/php_metaphone.h deleted file mode 100644 index 14991b4fe9..0000000000 --- a/ext/standard/php_metaphone.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Thies C. Arntzen <thies@digicol.de> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef _php_metaphone_h -#define _php_metaphone_h - -char Lookahead(char *word, int how_far); -extern zend_module_entry metaphone_module_entry; -#define phpext_metaphone_ptr &metaphone_module_entry - -#endif diff --git a/ext/standard/php_output.h b/ext/standard/php_output.h deleted file mode 100644 index 9eeb17c80b..0000000000 --- a/ext/standard/php_output.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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); - -extern zend_module_entry output_module_entry; -#define phpext_output_ptr &output_module_entry - -#endif /* _OUTPUT_BUFFER */ diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h deleted file mode 100644 index 5751e2c8a8..0000000000 --- a/ext/standard/php_rand.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 - -#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 8e48c18503..0000000000 --- a/ext/standard/php_standard.h +++ /dev/null @@ -1,75 +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_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 "post.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 d7078f0201..0000000000 --- a/ext/standard/php_string.h +++ /dev/null @@ -1,107 +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 php3 revision 1.43 1999-06-16 [ssb] */ - -#ifndef _PHPSTRING_H -#define _PHPSTRING_H - -#include "basic_functions.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(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); - -extern PHPAPI char *php_strtoupper(char *s, size_t len); -extern PHPAPI char *php_strtolower(char *s, size_t len); -extern PHPAPI char *php_strtr(char *string, int len, char *str_from, char *str_to, int trlen); -extern PHPAPI char *php_addslashes(char *string, int length, int *new_length, int freeit); -extern PHPAPI char *php_addcslashes(char *string, int length, int *new_length, int freeit, char *what, int wlength); -extern PHPAPI void php_stripslashes(char *string, int *len); -extern PHPAPI void php_stripcslashes(char *string, int *len); -extern PHPAPI void php_dirname(char *str, int len); -extern PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t t_len); -extern PHPAPI char *php_str_to_str(char *haystack, int length, char *needle, - int needle_len, char *str, int str_len, int *_new_length); -extern PHPAPI void php_trim(pval *str, pval *return_value, int mode); -extern PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow); - -extern PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result); - -extern PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value); -extern PHPAPI void php_explode(pval *delim, pval *str, pval *return_value); -PHPAPI inline char *php_memnstr(char *haystack, char *needle, int needle_len, char *end); - -#endif /* _PHPSTRING_H */ diff --git a/ext/standard/php_syslog.h b/ext/standard/php_syslog.h deleted file mode 100644 index 69dd4abb80..0000000000 --- a/ext/standard/php_syslog.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: | - | | - +----------------------------------------------------------------------+ - */ - -#ifndef _PHP_SYSLOG_H -#define _PHP_SYSLOG_H - -#if HAVE_SYSLOG_H -extern php3_module_entry syslog_module_entry; -#define syslog_module_ptr &syslog_module_entry - -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); - -#else -#define syslog_module_ptr NULL -#endif - -#define phpext_syslog_ptr syslog_module_ptr - -#endif /* _PHP_SYSLOG_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 f9d56abd5b..0000000000 --- a/ext/standard/phpmath.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: 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); - -#endif /* _PHPMATH_H */ diff --git a/ext/standard/post.c b/ext/standard/post.c deleted file mode 100644 index c6b1c5297a..0000000000 --- a/ext/standard/post.c +++ /dev/null @@ -1,420 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ -/* $Id: */ - -#include <stdio.h> -#include "php.h" -#include "php_standard.h" -#include "php_globals.h" -#include "SAPI.h" - -#include "zend_globals.h" - - -/* - * parse Get/Post/Cookie string and create appropriate variable - * - * This is a tad ugly because it was yanked out of the middle of - * the old TreatData function. This is a temporary measure filling - * the gap until a more flexible parser can be built to do this. - */ -void php_parse_gpc_data(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC) -{ - int var_type; - char *ind, *tmp = NULL, *array_index = NULL; - int var_len, val_len; - pval *gpc_element; - zend_bool do_insert; - - if (!PG(gpc_globals) && !track_vars_array) { - /* we don't need track_vars, and we're not setting GPC globals either. */ - return; - } - - var_type = php3_check_ident_type(var); - if (var_type == GPC_INDEXED_ARRAY) { - ind = php3_get_ident_index(var); - if (PG(magic_quotes_gpc)) { - array_index = php_addslashes(ind, 0, NULL, 1); - } else { - array_index = ind; - } - } - if (var_type & GPC_ARRAY) { /* array (indexed or not) */ - tmp = strchr(var, '['); - if (tmp) { - *tmp = '\0'; - } - } - /* ignore leading spaces in the variable name */ - while (*var && *var==' ') { - var++; - } - var_len = strlen(var); - if (var_len==0) { /* empty variable name, or variable name with a space in it */ - return; - } - - /* ensure that we don't have spaces or dots in the variable name (not binary safe) */ - for (tmp=var; *tmp; tmp++) { - switch(*tmp) { - case ' ': - case '.': - *tmp='_'; - break; - } - } - - val_len = strlen(val); - if (PG(magic_quotes_gpc)) { - val = php_addslashes(val, val_len, &val_len, 0); - } else { - val = estrndup(val, val_len); - } - - if (var_type & GPC_ARRAY) { - pval *gpc_element; - pval **arr_ptr_ptr; - pval *array_element; - - if (zend_hash_find(EG(active_symbol_table), var, var_len+1, (void **) &arr_ptr_ptr) == FAILURE) { - /* If the array doesn't exist, create it */ - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - do_insert=1; - } else { - if ((*arr_ptr_ptr)->type!=IS_ARRAY) { - if (--(*arr_ptr_ptr)->refcount > 0) { - MAKE_STD_ZVAL(*arr_ptr_ptr); - } else { - zval_dtor(*arr_ptr_ptr); - } - array_init(*arr_ptr_ptr); - } - gpc_element = *arr_ptr_ptr; - do_insert=0; - } - - /* Create the element */ - array_element = (pval *) emalloc(sizeof(pval)); - INIT_PZVAL(array_element); - array_element->value.str.val = val; - array_element->value.str.len = val_len; - array_element->type = IS_STRING; - - /* Insert it */ - if (array_index) { - /* indexed array */ - if (php3_check_type(array_index) == IS_LONG) { - /* numeric index */ - zend_hash_index_update(gpc_element->value.ht, atol(array_index), &array_element, sizeof(pval *), NULL); /* s[array_index]=tmp */ - } else { - /* associative index */ - zend_hash_update(gpc_element->value.ht, array_index, strlen(array_index)+1, &array_element, sizeof(pval *), NULL); /* s["ret"]=tmp */ - } - efree(array_index); - } else { - /* non-indexed array */ - zend_hash_next_index_insert(gpc_element->value.ht, &array_element, sizeof(pval *), NULL); - } - } else { /* we have a normal variable */ - MAKE_STD_ZVAL(gpc_element); - gpc_element->type = IS_STRING; - gpc_element->refcount = 0; - gpc_element->value.str.val = val; - gpc_element->value.str.len = val_len; - do_insert=1; - } - - if (do_insert) { - gpc_element->refcount = 0; - if (PG(gpc_globals)) { - zend_hash_update(EG(active_symbol_table), var, var_len+1, &gpc_element, sizeof(pval *), NULL); - gpc_element->refcount++; - } - if (track_vars_array) { - zend_hash_update(track_vars_array->value.ht, var, var_len+1, &gpc_element, sizeof(pval *), NULL); - gpc_element->refcount++; - } - } -} - - -void php_parse_gpc_data2(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC) -{ - char *p = NULL; - char *ip; /* index pointer */ - char *index; - int var_len, val_len, index_len; - zval *gpc_element, **gpc_element_p, **top_gpc_p=NULL; - zend_bool is_array; - zend_bool free_index; - HashTable *symtable1=NULL; - HashTable *symtable2=NULL; - - if (PG(gpc_globals)) { - symtable1 = EG(active_symbol_table); - } - if (track_vars_array) { - if (symtable1) { - symtable2 = track_vars_array->value.ht; - } else { - symtable1 = track_vars_array->value.ht; - } - } - if (!symtable1) { - /* we don't need track_vars, and we're not setting GPC globals either. */ - return; - } - - /* - * Prepare variable name - */ - ip = strchr(var, '['); - if (ip) { - is_array = 1; - *ip = 0; - } else { - is_array = 0; - } - /* ignore leading spaces in the variable name */ - while (*var && *var==' ') { - var++; - } - var_len = strlen(var); - if (var_len==0) { /* empty variable name, or variable name with a space in it */ - return; - } - /* ensure that we don't have spaces or dots in the variable name (not binary safe) */ - for (p=var; *p; p++) { - switch(*p) { - case ' ': - case '.': - *p='_'; - break; - } - } - - /* Prepare value */ - val_len = strlen(val); - if (PG(magic_quotes_gpc)) { - val = php_addslashes(val, val_len, &val_len, 0); - } else { - val = estrndup(val, val_len); - } - - index = var; - index_len = var_len; - free_index = 0; - - while (1) { - if (is_array) { - char *escaped_index; - - if (!index) { - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } else { - if (PG(magic_quotes_gpc) && (index!=var)) { - /* no need to addslashes() the index if it's the main variable name */ - escaped_index = php_addslashes(index, index_len, &index_len, 0); - } else { - escaped_index = index; - } - if (zend_hash_find(symtable1, escaped_index, index_len+1, (void **) &gpc_element_p)==FAILURE - || (*gpc_element_p)->type != IS_ARRAY) { - MAKE_STD_ZVAL(gpc_element); - array_init(gpc_element); - zend_hash_update(symtable1, escaped_index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } - if (index!=escaped_index) { - efree(escaped_index); - } - } - if (!top_gpc_p) { - top_gpc_p = gpc_element_p; - } - symtable1 = (*gpc_element_p)->value.ht; - /* ip pointed to the '[' character, now obtain the key */ - index = ++ip; - index_len = 0; - if (*ip=='\n' || *ip=='\r' || *ip=='\t' || *ip==' ') { - ip++; - } - if (*ip==']') { - index = NULL; - } else { - ip = strchr(ip, ']'); - if (!ip) { - php_error(E_WARNING, "Missing ] in %s variable", var); - return; - } - *ip = 0; - index_len = strlen(index); - } - ip++; - if (*ip=='[') { - is_array = 1; - *ip = 0; - } else { - is_array = 0; - } - } else { - MAKE_STD_ZVAL(gpc_element); - gpc_element->value.str.val = val; - gpc_element->value.str.len = val_len; - gpc_element->type = IS_STRING; - if (!index) { - zend_hash_next_index_insert(symtable1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } else { - zend_hash_update(symtable1, index, index_len+1, &gpc_element, sizeof(zval *), (void **) &gpc_element_p); - } - if (!top_gpc_p) { - top_gpc_p = gpc_element_p; - } - break; - } - } - - if (top_gpc_p) { - (*top_gpc_p)->is_ref = 1; - if (symtable2) { - zend_hash_update(symtable2, var, var_len+1, top_gpc_p, sizeof(zval *), NULL); - (*top_gpc_p)->refcount++; - } - } -} - - -void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC) -{ - char *res = NULL, *var, *val; - pval *array_ptr; - int free_buffer=0; - char *strtok_buf = NULL; - - switch (arg) { - case PARSE_POST: - case PARSE_GET: - case PARSE_COOKIE: - if (PG(track_vars)) { - array_ptr = (pval *) emalloc(sizeof(pval)); - array_init(array_ptr); - INIT_PZVAL(array_ptr); - switch (arg) { - case PARSE_POST: - zend_hash_add(&EG(symbol_table), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), &array_ptr, sizeof(pval *),NULL); - break; - case PARSE_GET: - zend_hash_add(&EG(symbol_table), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), &array_ptr, sizeof(pval *),NULL); - break; - case PARSE_COOKIE: - zend_hash_add(&EG(symbol_table), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), &array_ptr, sizeof(pval *),NULL); - break; - } - } else { - array_ptr=NULL; - } - break; - default: - array_ptr=NULL; - break; - } - - if (arg == PARSE_POST) { /* POST data */ - res = SG(request_info).post_data; - free_buffer = 0; - } else if (arg == PARSE_GET) { /* GET data */ - var = SG(request_info).query_string; - if (var && *var) { - res = (char *) estrdup(var); - free_buffer = 1; - } else { - free_buffer = 0; - } - } else if (arg == PARSE_COOKIE) { /* Cookie data */ - var = SG(request_info).cookie_data; - if (var && *var) { - res = (char *) estrdup(var); - free_buffer = 1; - } else { - free_buffer = 0; - } - } else if (arg == PARSE_STRING) { /* String data */ - res = str; - free_buffer = 1; - } - if (!res) { - return; - } - -#if HAVE_FDFLIB - if((NULL != SG(request_info).content_type) && (0 == strcmp(SG(request_info).content_type, "application/vnd.fdf"))) { - pval *tmp; - - tmp = (pval *) emalloc(sizeof(pval)); - tmp->value.str.len = SG(request_info).post_data_length; - tmp->value.str.val = estrndup(SG(request_info).post_data, SG(request_info).post_data_length); - tmp->type = IS_STRING; - INIT_PZVAL(tmp); - zend_hash_add(&EG(symbol_table), "HTTP_FDF_DATA", sizeof("HTTP_FDF_DATA"), &tmp, sizeof(pval *),NULL); - - } else { -#endif - if (arg == PARSE_COOKIE) { - var = strtok_r(res, ";", &strtok_buf); - } else if (arg == PARSE_POST) { - var = strtok_r(res, "&", &strtok_buf); - } else { - var = strtok_r(res, PG(arg_separator), &strtok_buf); - } - - while (var) { - val = strchr(var, '='); - if (val) { /* have a value */ - *val++ = '\0'; - /* FIXME: XXX: not binary safe, discards returned length */ - _php3_urldecode(var, strlen(var)); - _php3_urldecode(val, strlen(val)); - php_parse_gpc_data2(val,var,array_ptr ELS_CC PLS_CC); - } - if (arg == PARSE_COOKIE) { - var = strtok_r(NULL, ";", &strtok_buf); - } else if (arg == PARSE_POST) { - var = strtok_r(NULL, "&", &strtok_buf); - } else { - var = strtok_r(NULL, PG(arg_separator), &strtok_buf); - } - } -#if HAVE_FDFLIB - } -#endif - if (free_buffer) { - efree(res); - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/post.h b/ext/standard/post.h deleted file mode 100644 index 243bac6fc2..0000000000 --- a/ext/standard/post.h +++ /dev/null @@ -1,45 +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 _POST_H -#define _POST_H - -#include "SAPI.h" - -#define PARSE_POST 0 -#define PARSE_GET 1 -#define PARSE_COOKIE 2 -#define PARSE_STRING 3 - -void php_treat_data(int arg, char *str ELS_DC PLS_DC SLS_DC); -void php_parse_gpc_data(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC); -void php_parse_gpc_data2(char *val, char *var, pval *track_vars_array ELS_DC PLS_DC); - -#endif diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c deleted file mode 100644 index 9f8e46b969..0000000000 --- a/ext/standard/quot_print.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 _php3_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 (ARG_COUNT(ht) != 1 || getParameters(ht,1,&arg1)==FAILURE) - { - WRONG_PARAM_COUNT; - } - convert_to_string(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++] = (_php3_hex2int((int)str[i+1]) << 4 ) - + _php3_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 e7ea2ac493..0000000000 --- a/ext/standard/rand.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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" - -/* - 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. - - - - 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... -*/ - -typedef unsigned int uint32; - -#define N (624) /* 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 */ - -static uint32 state[N+1]; /* state vector + 1 extra to not violate ANSI C */ -static uint32 *next; /* next random value is computed from here */ -static int left = -1; /* can *next++ this many times before reloading */ - - -static void seedMT(uint32 seed) -{ - /* - 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 uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = state; - register int j; - - for(left=0, *s++=x, j=N; --j; - *s++ = (x*=69069U) & 0xFFFFFFFFU); -} - - -static uint32 reloadMT(void) -{ - register uint32 *p0=state, *p2=state+2, *pM=state+M, s0, s1; - register int j; - - if(left < -1) - seedMT(4357U); - - left=N-1, next=state+1; - - for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++) - *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); - - for(pM=state, j=M; --j; s0=s1, s1=*p2++) - *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U); - - s1=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 uint32 randomMT(void) -{ - uint32 y; - - if(--left < 0) - return(reloadMT()); - - y = *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 (ARG_COUNT(ht) != 1 || getParametersEx(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; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg); - seedMT((*arg)->value.lval); -} -/* }}} */ - -/* {{{ proto int rand([int min, int max]) - Returns a random number */ -PHP_FUNCTION(rand) -{ - pval **p_min=NULL, **p_max=NULL; - - switch (ARG_COUNT(ht)) { - case 0: - break; - case 2: - if (getParametersEx(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); - } - 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) * 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 (ARG_COUNT(ht)) { - case 0: - break; - case 2: - if (getParametersEx(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,"mtrand(): 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 php3_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 + - (int)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1) * return_value->value.lval/(PHP_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 php3_rand - */ - return_value->value.lval = 2147483647; /* 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 58c8fc82f2..0000000000 --- a/ext/standard/reg.c +++ /dev/null @@ -1,653 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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" - -unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; - -function_entry reg_functions[] = { - 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) - {NULL, NULL, NULL} -}; - - -static PHP_MINIT_FUNCTION(regex); -static PHP_MSHUTDOWN_FUNCTION(regex); -static PHP_MINFO_FUNCTION(regex); - -zend_module_entry regexp_module_entry = { - "Regular Expressions", - reg_functions, - PHP_MINIT(regex), PHP_MSHUTDOWN(regex), - NULL, NULL, PHP_MINFO(regex), - STANDARD_MODULE_PROPERTIES -}; - -#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 int _free_reg_cache(reg_cache *rc) -{ - regfree(&rc->preg); - return 1; -} - -#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, (int (*)(void *)) _free_reg_cache, 1); -} - -static 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; -} - -static PHP_MSHUTDOWN_FUNCTION(regex) -{ - REGLS_FETCH(); - - zend_hash_destroy(®(ht_rc)); - return SUCCESS; -} - -static PHP_MINFO_FUNCTION(regex) -{ -#if HSREGEX - PUTS("Bundled regex library enabled\n"); -#else - PUTS("System regex library enabled\n"); -#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 - -/* - * _php3_reg_eprint - convert error number to name - */ -static void _php3_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 _php3_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(ARG_COUNT(ht)) { - case 2: - if (getParameters(ht, 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 (getParameters(ht, 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(regex); /* get rid of decimal places */ - convert_to_string(regex); - /* don't bother doing an extended regex with just a number */ - err = regcomp(&re, regex->value.str.val, copts); - } - - if (err) { - _php3_reg_eprint(err, &re); - RETURN_FALSE; - } - - /* make a copy of the string we're looking in */ - convert_to_string(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) { - _php3_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 _php3_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) -{ - _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto int eregi(string pattern, string string [, array registers]) - Case-insensitive regular expression match */ -PHP_FUNCTION(eregi) -{ - _php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); -} -/* }}} */ - -/* this is the meat and potatoes of regex replacement! */ -char *_php3_regreplace(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) { - _php3_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 _php3_regreplace"); - 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) { - _php3_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 _php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS, int icase) -{ - pval *arg_pattern, - *arg_replace, - *arg_string; - char *pattern; - char *string; - char *replace; - char *ret; - - if (ARG_COUNT(ht) != 3 || getParameters(ht, 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(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(arg_replace); - replace = emalloc(2); - replace[0] = (char) arg_replace->value.lval; - replace[1] = '\0'; - } - - convert_to_string(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 = _php3_regreplace(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) -{ - _php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); -} -/* }}} */ - -/* {{{ proto string eregi_replace(string pattern, string string [, array registers]) - Case insensitive replace regular expression */ -PHP_FUNCTION(eregi_replace) -{ - _php3_eregreplace(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 (ARG_COUNT(ht)) { - case 2: - if (getParameters(ht, 2, &spliton, &str) == FAILURE) - WRONG_PARAM_COUNT; - count = -1; - break; - case 3: - if (getParameters(ht, 3, &spliton, &str, &arg_count) == FAILURE) - WRONG_PARAM_COUNT; - convert_to_long(arg_count); - count = arg_count->value.lval; - break; - default: - WRONG_PARAM_COUNT; - } - - convert_to_string(spliton); - convert_to_string(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 (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string(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 c261abf4d2..0000000000 --- a/ext/standard/reg.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> | - +----------------------------------------------------------------------+ - */ - - -/* $Id$ */ - -#ifndef _REG_H -#define _REG_H - -extern php3_module_entry regexp_module_entry; -#define regexp_module_ptr ®exp_module_entry - -char *_php3_regreplace(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; - - -#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 - -#define phpext_regex_ptr regexp_module_ptr - -#endif /* _REG_H */ diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c deleted file mode 100644 index 25946e4854..0000000000 --- a/ext/standard/soundex.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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 (ARG_COUNT(ht) != 1 || getParametersEx(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 47896b913a..0000000000 --- a/ext/standard/string.c +++ /dev/null @@ -1,2326 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | - | Stig Sæther Bakken <ssb@fast.no> | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -/* Synced with php3 revision 1.193 1999-06-16 [ssb] */ - -#include <stdio.h> -#include "php.h" -#include "reg.h" -#include "post.h" -#include "php_string.h" -#ifdef HAVE_LOCALE_H -# include <locale.h> -#endif -#include "zend_execute.h" -#include "php_globals.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 *new = NULL; - size_t i, j; - - new = (char *) emalloc(oldlen * 2 * sizeof(char)); - if(!new) { - return new; - } - - for(i = j = 0; i < oldlen; i++) { - new[j++] = hexconvtab[old[i] >> 4]; - new[j++] = hexconvtab[old[i] & 15]; - } - - if(newlen) *newlen = oldlen * 2 * sizeof(char); - - return new; -} - -/* proto bin2hex(string data) - converts the binary representation of data to hex */ -PHP_FUNCTION(bin2hex) -{ - pval **data; - char *new; - size_t newlen; - - if(ARG_COUNT(ht) != 1 || getParametersEx(1, &data) == FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(data); - - new = php_bin2hex((*data)->value.str.val, (*data)->value.str.len, &newlen); - - if(!new) { - RETURN_FALSE; - } - - RETURN_STRINGL(new, newlen, 0); -} - - -/* {{{ proto int strspn(string str, string mask) - Find length of initial segment consisting entirely of characters found in mask */ -PHP_FUNCTION(strspn) -{ - pval **s1,**s2; - - if (ARG_COUNT(ht)!=2 || getParametersEx(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - RETURN_LONG(strspn((*s1)->value.str.val,(*s2)->value.str.val)); -} -/* }}} */ - -/* {{{ proto int strcspn(string str, string mask) - Find length of initial segment consisting entirely of characters not found in mask */ -PHP_FUNCTION(strcspn) -{ - pval **s1,**s2; - - if (ARG_COUNT(ht)!=2 || getParametersEx(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - RETURN_LONG(strcspn((*s1)->value.str.val,(*s2)->value.str.val)); -} -/* }}} */ - -PHPAPI void php_trim(pval *str, pval * 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') { - 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') { - 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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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(pval *delim, pval *str, pval *return_value) -{ - char *p1, *p2, *endp; - int i = 0; - - 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_index_stringl(return_value, i++, p1, str->value.str.len, 1); - } else { - do { - add_index_stringl(return_value, i++, 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); - - if (p1 <= endp) { - add_index_stringl(return_value, i++, p1, endp-p1, 1); - } - } -} - -/* {{{ proto array explode(string separator, string str) - Split a string on string separator and return array of components */ -PHP_FUNCTION(explode) -{ - pval **str, **delim; - - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &delim, &str) == FAILURE) { - 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; - } - - php_explode(*delim, *str, return_value); -} -/* }}} */ - - -/* {{{ proto string join(array src, string glue) - An alias for implode */ -/* }}} */ -PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value) -{ - pval **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) -{ - pval **arg1, **arg2, *delim, *arr; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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) -{ - pval **str, **tok; - char *token = NULL, *tokp=NULL; - char *first = NULL; - int argc; - BLS_FETCH(); - - argc = ARG_COUNT(ht); - - if ((argc == 1 && getParametersEx(1, &tok) == FAILURE) || - (argc == 2 && getParametersEx(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; - int 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) -{ - pval **arg; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - int 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) -{ - pval **str; - char *ret; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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); -} -/* }}} */ - -/* {{{ proto string basename(string path) - Return the filename component of the path */ -PHP_FUNCTION(basename) -{ - pval **str; - char *ret, *c; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str)) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - ret = estrdup((*str)->value.str.val); - c = ret + (*str)->value.str.len -1; - while (*c == '/' -#ifdef MSVC5 - || *c == '\\' -#endif - ) - c--; - *(c + 1) = '\0'; - if ((c = strrchr(ret, '/')) -#ifdef MSVC5 - || (c = strrchr(ret, '\\')) -#endif - ) { - RETVAL_STRING(c + 1,1); - } else { - RETVAL_STRING((*str)->value.str.val,1); - } - efree(ret); -} -/* }}} */ - -PHPAPI void php_dirname(char *str, int len) { - register char *c; - - c = str + len - 1; - while (*c == '/' -#ifdef MSVC5 - || *c == '\\' -#endif - ) - c--; /* strip trailing slashes */ - *(c + 1) = '\0'; - if ((c = strrchr(str, '/')) -#ifdef MSVC5 - || (c = strrchr(str, '\\')) -#endif - ) - *c='\0'; -} - -/* {{{ proto string dirname(string path) - Return the directory name component of the path */ -PHP_FUNCTION(dirname) -{ - pval **str; - char *ret; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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); -} - -/* {{{ 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; - char needle_char[2]; - - if (ARG_COUNT(ht) != 2 || getParametersEx(2, &haystack, &needle) == - FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(haystack); - - if ((*needle)->type == IS_STRING) { - if ((*needle)->value.str.len==0) { - php_error(E_WARNING,"Empty delimiter"); - 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) { - RETVAL_STRING(found, 1); - } else { - RETVAL_FALSE; - } -} -/* }}} */ - -/* {{{ 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 (ARG_COUNT(ht) != 2 || getParametersEx(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) -{ - pval **haystack, **needle, **OFFSET; - int offset = 0; - char *found = NULL; - char *endp; - char *startp; - - switch(ARG_COUNT(ht)) { - case 2: - if (getParametersEx(2, &haystack, &needle) == FAILURE) { - WRONG_PARAM_COUNT; - } - break; - case 3: - if (getParametersEx(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) -{ - pval **haystack, **needle; - char *found = NULL; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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) -{ - pval **haystack, **needle; - char *found = NULL; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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) -{ - pval **p_str, **p_chunklen, **p_ending; - int argc; - char *result; - char *end = "\r\n"; - int endlen = 2; - int chunklen = 76; - int result_len; - - argc = ARG_COUNT(ht); - - if (argc < 1 || argc > 3 || - getParametersEx(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) -{ - pval **string, **from, **len; - int argc, l; - int f; - - argc = ARG_COUNT(ht); - - if ((argc == 2 && getParametersEx(2, &string, &from) == FAILURE) || - (argc == 3 && getParametersEx(3, &string, &from, &len) == FAILURE) || - argc < 2 || argc > 3) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(string); - convert_to_long_ex(from); - f = (*from)->value.lval; - - if (argc == 2) { - l = (*string)->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 = (*string)->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 = ((*string)->value.str.len - f) + l; - if (l < 0) { - l = 0; - } - } - - if (f >= (int)(*string)->value.str.len) { - RETURN_FALSE; - } - - if((f+l) > (int)(*string)->value.str.len) { - l = (int)(*string)->value.str.len - f; - } - - RETVAL_STRINGL((*string)->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** string; - zval** from; - zval** len; - zval** repl; - char* result; - int result_len; - int argc; - int l; - int f; - - argc = ARG_COUNT(ht); - - if ((argc == 3 && getParametersEx(3, &string, &repl, &from) == FAILURE) || - (argc == 4 && getParametersEx(4, &string, &repl, &from, &len) == FAILURE) || - argc < 3 || argc > 4) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(string); - convert_to_string_ex(repl); - convert_to_long_ex(from); - f = (*from)->value.lval; - - if (argc == 3) { - l = (*string)->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 = (*string)->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 = ((*string)->value.str.len - f) + l; - if (l < 0) { - l = 0; - } - } - - if (f >= (int)(*string)->value.str.len) { - RETURN_STRINGL((*string)->value.str.val, (*string)->value.str.len, 1); - } - - if((f+l) > (int)(*string)->value.str.len) { - l = (int)(*string)->value.str.len - f; - } - - result_len = (*string)->value.str.len - l + (*repl)->value.str.len; - result = (char *)ecalloc(result_len + 1, sizeof(char *)); - - memcpy(result, (*string)->value.str.val, f); - memcpy(&result[f], (*repl)->value.str.val, (*repl)->value.str.len); - memcpy(&result[f + (*repl)->value.str.len], (*string)->value.str.val + f + l, - (*string)->value.str.len - f - l); - - RETVAL_STRINGL(result, result_len, 0); -} -/* }}} */ - - -/* {{{ proto string quotemeta(string str) - Quote meta characters */ -PHP_FUNCTION(quotemeta) -{ - pval **arg; - char *str, *old; - char *p, *q; - char c; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - old = (*arg)->value.str.val; - - if (!*old) { - RETURN_FALSE; - } - - str = emalloc(2 * (*arg)->value.str.len + 1); - - for(p = old, q = str; (c = *p); 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_STRING(erealloc(str, q - str + 1), 0); -} -/* }}} */ - -/* {{{ proto int ord(string character) - Return ASCII value of character */ -PHP_FUNCTION(ord) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **num; - char temp[2]; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **arg; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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; - char *r; - char *r_end; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - - if (!(*str)->value.str.len) { - RETURN_FALSE; - } - *return_value=**str; - zval_copy_ctor(return_value); - *return_value->value.str.val = toupper((unsigned char)*return_value->value.str.val); - - r=return_value->value.str.val; - r_end = r + (*str)->value.str.len; - while((r=php_memnstr(r, " ", 1, r_end)) != NULL){ - if(r < r_end){ - r++; - *r=toupper((unsigned char)*r); - } else { - break; - } - } -} -/* }}} */ - -PHPAPI char *php_strtr(char *string, int len, char *str_from, - char *str_to, int trlen) -{ - int i; - unsigned char xlat[256]; - - if ((trlen < 1) || (len < 1)) { - return string; - } - - 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++) { - string[i] = xlat[(unsigned char) string[i]]; - } - - return string; -} - -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 = realloc(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 = realloc(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) */ - pval **str, **from, **to; - int ac = ARG_COUNT(ht); - - if (ac < 2 || ac > 3 || getParametersEx(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) -{ - pval **str; - int i,len; - char c; - - if (ARG_COUNT(ht)!=1 || getParametersEx(1, &str)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(str); - - len = (*str)->value.str.len; - - for (i=0; i<len-1-i; i++) { - c=(*str)->value.str.val[i]; - (*str)->value.str.val[i] = (*str)->value.str.val[len-1-i]; - (*str)->value.str.val[len-1-i]=c; - } - - *return_value = **str; - pval_copy_constructor(return_value); -} -/* }}} */ - -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) -{ - pval **t1, **t2, **percent; - int ac = ARG_COUNT(ht); - int sim; - - if (ac < 2 || ac > 3 || - getParametersEx(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 *string, 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(string); - } - s = string; - t = string; - 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) -{ - pval **str, **what; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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 -#if !APACHE -char *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 -#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++='\\'; - *target++=*source; - } - } - } 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 *) emalloc((length?length:(length=strlen(str)))*2+1); - char *source,*target; - char *end; - char c; - PLS_FETCH(); - - 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,pval *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 *new; - char *off; - - new = emalloc(length); - /* we jump through haystack searching for the needle. hurray! */ - for(p = haystack, q = new; - (r = php_memnstr(p, needle, needle_len, end));) { - /* this ain't optimal. you could call it `efficient memory usage' */ - off = erealloc(new, (q - new) + (r - p) + (str_len) + 1); - if(off != new) { - if(!off) { - goto finish; - } - q += off - new; - new = 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(new, s - new + 1); - if(off != new) { - if(!off) { - goto finish; - } - q += off - new; - new = off; - s = q + (end - p); - } - memcpy(q, p, end - p); - q = s; - } -finish: - *q = '\0'; - if(_new_length) *_new_length = q - new; - return new; -} - - -/* {{{ proto string str_replace(string needle, string str, string haystack) - Replace all occurrences of needle in haystack with str */ -PHP_FUNCTION(str_replace) -{ - pval **haystack, **needle, **str; - char *new; - int len = 0; - - if(ARG_COUNT(ht) != 3 || - getParametersEx(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; - } - - new = 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(new, 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) -{ - pval **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(ARG_COUNT(ht)) { - case 1: - if (getParametersEx(1, &str)==FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if (getParametersEx(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) -{ - pval **str; - - if (ARG_COUNT(ht)!=1 || getParametersEx(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; - pval **str, **allow=NULL; - - switch(ARG_COUNT(ht)) { - case 1: - if(getParametersEx(1, &str)==FAILURE) { - RETURN_FALSE; - } - break; - case 2: - if(getParametersEx(2, &str, &allow)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - break; - default: - WRONG_PARAM_COUNT; - break; - } - convert_to_string_ex(str); - buf = estrdup((*str)->value.str.val); - php_strip_tags(buf, (*str)->value.str.len, 0, allow?(*allow)->value.str.val:NULL); - RETURN_STRING(buf, 0); -} -/* }}} */ - -/* {{{ proto string setlocale(string category, string locale) - Set locale information */ -PHP_FUNCTION(setlocale) -{ - pval **pcategory, **plocale; - pval *category, *locale; - int cat; - char *loc, *retval; - BLS_FETCH(); - - if (ARG_COUNT(ht)!=2 || getParametersEx(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(strtok_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) -{ - pval **arg; - char *res = NULL; - ELS_FETCH(); - PLS_FETCH(); - SLS_FETCH(); - - if (getParametersEx(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 i=0, state=0, done=0; - char *norm = emalloc(len); - - 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> - */ - while(i<len && !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) { - char *tbuf, *buf, *p, *tp, *rp, c, lc; - int br, i=0; - - buf = estrdup(rbuf); - c = *buf; - lc = '\0'; - p = buf; - rp = rbuf; - br = 0; - if(allow) { - php_strtolower(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 (ARG_COUNT(ht) != 2 || getParametersEx(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 + 1, 0); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c deleted file mode 100644 index 2154212ce7..0000000000 --- a/ext/standard/syslog.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Stig Sæther Bakken <ssb@guardian.no> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include "php.h" -#include "php_ini.h" -#include "zend_globals.h" - -#include <stdlib.h> -#if HAVE_UNISTD_H -#include <unistd.h> -#endif -#if MSVC5 -#include "win32/syslog.h" -#else -#include <syslog.h> -#endif - -#include <string.h> -#include <errno.h> - -#include <stdio.h> -#include "php_syslog.h" - -static int syslog_started; -static char *syslog_device; -static void start_syslog(void); - -PHP_MINIT_FUNCTION(syslog) -{ - ELS_FETCH(); - - /* 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 -#ifndef MSVC5 - 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) -{ - if (INI_INT("define_syslog_variables")) { - start_syslog(); - } else { - syslog_started=0; - } - syslog_device=NULL; - return SUCCESS; -} - - -PHP_RSHUTDOWN_FUNCTION(syslog) -{ - if (syslog_device) { - efree(syslog_device); - } - return SUCCESS; -} - - -static void start_syslog(void) -{ - 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 -#ifndef MSVC5 - 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 - - syslog_started=1; -} - -/* {{{ proto void define_syslog_variables(void) - Initializes all syslog-related variables */ -PHP_FUNCTION(define_syslog_variables) -{ - if (!syslog_started) { - start_syslog(); - } -} - -/* {{{ 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; - if (ARG_COUNT(ht) != 3 || getParametersEx(3, &ident, &option, &facility) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(ident); - convert_to_long_ex(option); - convert_to_long_ex(facility); - if (syslog_device) { - efree(syslog_device); - } - syslog_device = estrndup((*ident)->value.str.val,(*ident)->value.str.len); - openlog(syslog_device, (*option)->value.lval, (*facility)->value.lval); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int closelog(void) - Close connection to system logger */ -PHP_FUNCTION(closelog) -{ - closelog(); - if (syslog_device) { - efree(syslog_device); - syslog_device=NULL; - } - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int syslog(int priority, string message) - Generate a system log message */ -PHP_FUNCTION(syslog) -{ - pval **priority, **message; - - if (ARG_COUNT(ht) != 2 || getParametersEx(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. - */ - - syslog((*priority)->value.lval, (*message)->value.str.val); - RETURN_TRUE; -} -/* }}} */ - - -function_entry syslog_functions[] = { - PHP_FE(openlog, NULL) - PHP_FE(syslog, NULL) - PHP_FE(closelog, NULL) - PHP_FE(define_syslog_variables, NULL) - {NULL, NULL, NULL} -}; - - -php3_module_entry syslog_module_entry = { - "Syslog", syslog_functions, PHP_MINIT(syslog), NULL, PHP_RINIT(syslog), PHP_RSHUTDOWN(syslog), NULL, STANDARD_MODULE_PROPERTIES -}; - - -#if COMPILE_DL -DLEXPORT php3_module_entry *get_module(void) { return &syslog_module_entry; } -#endif - - -/* - * 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 ee6ab91049..0000000000 --- a/ext/standard/type.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | 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 php3_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); -} /* php3_check_type */ - -/* - * 0 - simple variable - * 1 - non-index array - * 2 - index array - */ -int php3_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 *php3_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 62f98bea7a..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 php3_check_type(char *str); -extern int php3_check_ident_type(char *str); -extern char *php3_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 ced8f5c2a1..0000000000 --- a/ext/standard/uniqid.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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> -#if MSVC5 -#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 = ARG_COUNT(ht); - if (argc < 1 || argc > 2 || getParametersEx(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 && !(WIN32|WINNT) - 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 23eb24bc38..0000000000 --- a/ext/standard/url.c +++ /dev/null @@ -1,432 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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: 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, PHP3 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 *string) -{ - regex_t re; - regmatch_t subs[10]; - int err; - int length = strlen(string); - 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, string, 10, subs, 0); - if (err) { - /*php_error(E_WARNING,"Error with regex\n");*/ - efree(ret); - return NULL; - } - /* no processing necessary on the scheme */ - if (subs[2].rm_so != -1 && subs[2].rm_so < length) { - ret->scheme = estrndup(string + 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(string + 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(string + 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(string + 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) { - /* extract username:pass@host:port from regex results */ - result = estrndup(string + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so); - length = strlen(result); - - regfree(&re); /* free the old regex */ - - if ((err=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);*/ - 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); - return NULL; - } - regfree(&re); - return ret; -} - -/* {{{ proto array parse_url(string url) - Parse a URL and return its components */ -PHP_FUNCTION(parse_url) -{ - pval **string; - url *resource; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &string) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(string); - - resource = url_parse((*string)->value.str.val); - - if (resource == NULL) { - php_error(E_WARNING, "unable to parse url (%s)", (*string)->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 php3_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 *_php3_urlencode(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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - var_reset(return_value); - return; - } - str = _php3_urlencode((*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 (ARG_COUNT(ht) != 1 || getParametersEx(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 = _php3_urldecode(return_value->value.str.val, return_value->value.str.len); - return_value->value.str.len = len; -} -/* }}} */ - -int _php3_urldecode(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) php3_htoi(data + 1); -#else - *dest = os_toebcdic[(char) php3_htoi(data + 1)]; -#endif - data += 2; - len -= 2; - } else - *dest = *data; - data++; - dest++; - } - *dest = '\0'; - return dest - str; -} - -char *_php3_rawurlencode(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 (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } - str = _php3_rawurlencode((*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; - - if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(arg); - - if (!(*arg)->value.str.len) { - RETURN_FALSE; - } - len = _php3_rawurldecode((*arg)->value.str.val, (*arg)->value.str.len); - - RETVAL_STRINGL((*arg)->value.str.val, len, 1); -} -/* }}} */ - -int _php3_rawurldecode(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) php3_htoi(data + 1); -#else - *dest = os_toebcdic[(char) php3_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 eaf5c32f77..0000000000 --- a/ext/standard/url.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: Jim Winstead (jimw@php.net) | - +----------------------------------------------------------------------+ - */ -/* $Id$ */ - -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 _php3_urldecode(char *, int); /* return value: length of decoded string */ -extern char *_php3_urlencode(char *, int); -extern int _php3_rawurldecode(char *, int); /* return value: length of decoded string */ -extern char *_php3_rawurlencode(char *, int); - -PHP_FUNCTION(parse_url); -PHP_FUNCTION(urlencode); -PHP_FUNCTION(urldecode); -PHP_FUNCTION(rawurlencode); -PHP_FUNCTION(rawurldecode); - -/* - * 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 c6c14d31af..0000000000 --- a/ext/standard/url_scanner.c +++ /dev/null @@ -1,536 +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 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)); -} - -#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 7651f77d8e..0000000000 --- a/ext/standard/url_scanner.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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$ */ - -#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 2939582b68..0000000000 --- a/ext/standard/url_scanner.re +++ /dev/null @@ -1,198 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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 4aeccd88e1..0000000000 --- a/ext/standard/var.c +++ /dev/null @@ -1,522 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP version 4.0 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997, 1998, 1999 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. | - +----------------------------------------------------------------------+ - | Authors: Jani Lehtimäki <jkl@njet.net> | - | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - - -/* {{{ includes -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> -#include "php.h" -#include "php_string.h" -#include "php_var.h" - -/* }}} */ -/* {{{ php_var_dump */ - -void php_var_dump(pval **struc, int level) -{ - ulong index; - char *key; - int i, c = 0; - pval **data; - char buf[512]; - HashTable *myht; - - switch ((*struc)->type) { - case IS_BOOL: - i = sprintf(buf, "%*cbool(%s)\n", level, ' ', ((*struc)->value.lval?"true":"false")); - PHPWRITE(&buf[1], i - 1); - break; - - case IS_LONG: - i = sprintf(buf, "%*cint(%ld)\n", level, ' ', (*struc)->value.lval); - PHPWRITE(&buf[1], i - 1); - break; - - case IS_DOUBLE: { - ELS_FETCH(); - i = sprintf(buf, "%*cfloat(%.*G)\n", level, ' ', (int) EG(precision), (*struc)->value.dval); - PHPWRITE(&buf[1], i - 1); - } - break; - - case IS_STRING: - i = sprintf(buf, "%*cstring(%d) \"", level, ' ', (*struc)->value.str.len); - PHPWRITE(&buf[1], i - 1); - PHPWRITE((*struc)->value.str.val, (*struc)->value.str.len); - strcpy(buf, "\"\n"); - PHPWRITE(buf, strlen(buf)); - break; - - case IS_ARRAY: - myht = HASH_OF(*struc); - i = sprintf(buf, "%*carray(%d) {\n", level, ' ', zend_hash_num_elements(myht)); - PHPWRITE(&buf[1], i - 1); - goto head_done; - - case IS_OBJECT: - myht = HASH_OF(*struc); - i = sprintf(buf, "%*cobject of %s (%d) {\n", level, ' ', (*struc)->value.obj.ce->name, zend_hash_num_elements(myht)); - PHPWRITE(&buf[1], i - 1); - head_done: - - 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 (c > 0) { - strcpy(buf, "\n"); - PHPWRITE(buf, strlen(buf)); - } - c++; - 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:{ - pval *d = emalloc(sizeof(pval)); - - d->type = IS_LONG; - d->value.lval = index; - php_var_dump(&d, level + 2); - efree(d); - } - break; - - case HASH_KEY_IS_STRING:{ - pval *d = emalloc(sizeof(pval)); - - d->type = IS_STRING; - d->value.str.val = key; - d->value.str.len = strlen(key); - php_var_dump(&d, level + 2); - efree(key); - efree(d); - } - break; - } - php_var_dump(data, level + 2); - } - i = sprintf(buf, "%*c}\n", level, ' '); - PHPWRITE(&buf[1], i - 1); - break; - - case IS_RESOURCE: { - int type; - zend_list_find((*struc)->value.lval, &type); - i = sprintf(buf, "%*cresource(%ld) of type %d\n", level, ' ', - (*struc)->value.lval, type); - PHPWRITE(&buf[1], i - 1); - break; - } - - default: - i = sprintf(buf, "%*ci:0\n", level, ' '); - PHPWRITE(&buf[1], i - 1); - } -} - -/* }}} */ - - -/* {{{ php_var_dump */ -PHP_FUNCTION(var_dump) -{ - zval ***args; - int argc; - int i; - - argc = ARG_COUNT(ht); - - args = (zval ***)emalloc(argc * sizeof(zval **)); - if (ARG_COUNT(ht) == 0 || getParametersArrayEx(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_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_ARRAY: - case IS_OBJECT: - 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: - d = emalloc(sizeof(pval)); - d->type = IS_LONG; - d->value.lval = index; - php_var_serialize(buf, &d); - efree(d); - break; - case HASH_KEY_IS_STRING: - d = emalloc(sizeof(pval)); - d->type = IS_STRING; - d->value.str.val = key; - d->value.str.len = strlen(key); - php_var_serialize(buf, &d); - efree(key); - efree(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 '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; - (*rval)->value.ht = (HashTable *) emalloc(sizeof(HashTable)); - 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 php3 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, PVAL_PTR_DTOR, 0); - } - - while (**p && **p != ':') { - (*p)++; - } - if (**p != ':' || *((*p) + 1) != '{') { - return 0; - } - for ((*p) += 2; **p && **p != '}' && i > 0; i--) { - pval *key = emalloc(sizeof(pval)); - pval *data = emalloc(sizeof(pval)); - - if (!php_var_unserialize(&key, p, max)) { - zval_dtor(key); - efree(key); - efree(data); - return 0; - } - if (!php_var_unserialize(&data, p, max)) { - zval_dtor(key); - efree(key); - zval_dtor(data); - efree(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; - } - pval_destructor(key); - efree(key); - } - return *((*p)++) == '}'; - - default: - return 0; - } -} - -/* }}} */ -/* {{{ proto string serialize(mixed variable) - Returns a string representation of variable (which can later be unserialized) */ -PHP_FUNCTION(serialize) -{ - pval **struc; - - if (ARG_COUNT(ht) != 1 || getParametersEx(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 (ARG_COUNT(ht) != 1 || getParametersEx(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: - */ |