summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorSVN Migration <svn@php.net>2001-08-13 16:13:26 +0000
committerSVN Migration <svn@php.net>2001-08-13 16:13:26 +0000
commite9e6c46b503cb7335e517d422a6d34f825db2a9d (patch)
tree4e7367e55215f4f8241cf587723d0c139e6ecc4b /ext/standard
parent9a3d4e736c974213e2c0862d420907604e22e5d5 (diff)
downloadphp-git-e9e6c46b503cb7335e517d422a6d34f825db2a9d.tar.gz
This commit was manufactured by cvs2svn to create branch 'unlabeled-1.67.2'.
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/CREDITS3
-rw-r--r--ext/standard/Makefile.in18
-rw-r--r--ext/standard/array.c3152
-rw-r--r--ext/standard/assert.c301
-rw-r--r--ext/standard/base64.c203
-rw-r--r--ext/standard/base64.h37
-rw-r--r--ext/standard/basic_functions.c2710
-rw-r--r--ext/standard/basic_functions.h221
-rw-r--r--ext/standard/browscap.c269
-rw-r--r--ext/standard/config.m4232
-rw-r--r--ext/standard/crc32.c136
-rw-r--r--ext/standard/credits.c125
-rw-r--r--ext/standard/credits.h42
-rw-r--r--ext/standard/credits_ext.h89
-rw-r--r--ext/standard/credits_sapi.h24
-rw-r--r--ext/standard/crypt.c181
-rw-r--r--ext/standard/cyr_convert.c299
-rw-r--r--ext/standard/cyr_convert.h29
-rw-r--r--ext/standard/datetime.c832
-rw-r--r--ext/standard/datetime.h45
-rw-r--r--ext/standard/dir.c357
-rw-r--r--ext/standard/dl.c230
-rw-r--r--ext/standard/dl.h34
-rw-r--r--ext/standard/dns.c332
-rw-r--r--ext/standard/dns.h42
-rw-r--r--ext/standard/exec.c487
-rw-r--r--ext/standard/exec.h35
-rw-r--r--ext/standard/file.c2492
-rw-r--r--ext/standard/file.h127
-rw-r--r--ext/standard/filestat.c875
-rw-r--r--ext/standard/flock_compat.c225
-rw-r--r--ext/standard/flock_compat.h49
-rw-r--r--ext/standard/formatted_print.c712
-rw-r--r--ext/standard/fsock.c774
-rw-r--r--ext/standard/fsock.h88
-rw-r--r--ext/standard/ftp_fopen_wrapper.c324
-rw-r--r--ext/standard/head.c201
-rw-r--r--ext/standard/head.h31
-rw-r--r--ext/standard/html.c502
-rw-r--r--ext/standard/html.h36
-rw-r--r--ext/standard/http_fopen_wrapper.c314
-rw-r--r--ext/standard/image.c525
-rw-r--r--ext/standard/incomplete_class.c151
-rw-r--r--ext/standard/info.c579
-rw-r--r--ext/standard/info.h80
-rw-r--r--ext/standard/iptc.c396
-rw-r--r--ext/standard/lcg.c107
-rw-r--r--ext/standard/levenshtein.c162
-rw-r--r--ext/standard/link.c168
-rw-r--r--ext/standard/mail.c239
-rw-r--r--ext/standard/math.c1067
-rw-r--r--ext/standard/md5.c377
-rw-r--r--ext/standard/md5.h63
-rw-r--r--ext/standard/metaphone.c473
-rw-r--r--ext/standard/microtime.c149
-rw-r--r--ext/standard/microtime.h28
-rw-r--r--ext/standard/pack.c877
-rw-r--r--ext/standard/pack.h28
-rw-r--r--ext/standard/pageinfo.c160
-rw-r--r--ext/standard/pageinfo.h33
-rw-r--r--ext/standard/parsedate.y1028
-rw-r--r--ext/standard/php_array.h99
-rw-r--r--ext/standard/php_assert.h32
-rw-r--r--ext/standard/php_browscap.h29
-rw-r--r--ext/standard/php_crypt.h39
-rw-r--r--ext/standard/php_dir.h39
-rw-r--r--ext/standard/php_ext_syslog.h39
-rw-r--r--ext/standard/php_filestat.h76
-rw-r--r--ext/standard/php_fopen_wrapper.c61
-rw-r--r--ext/standard/php_fopen_wrappers.h30
-rw-r--r--ext/standard/php_image.h26
-rw-r--r--ext/standard/php_incomplete_class.h62
-rw-r--r--ext/standard/php_iptc.h27
-rw-r--r--ext/standard/php_lcg.h42
-rw-r--r--ext/standard/php_link.h33
-rw-r--r--ext/standard/php_mail.h33
-rw-r--r--ext/standard/php_math.h142
-rw-r--r--ext/standard/php_metaphone.h26
-rw-r--r--ext/standard/php_parsedate.h26
-rw-r--r--ext/standard/php_rand.h61
-rw-r--r--ext/standard/php_smart_str.h128
-rw-r--r--ext/standard/php_smart_str_public.h30
-rw-r--r--ext/standard/php_standard.h67
-rw-r--r--ext/standard/php_string.h156
-rw-r--r--ext/standard/php_var.h69
-rw-r--r--ext/standard/quot_print.c138
-rw-r--r--ext/standard/quot_print.h26
-rw-r--r--ext/standard/rand.c365
-rw-r--r--ext/standard/reg.c664
-rw-r--r--ext/standard/reg.h50
-rw-r--r--ext/standard/scanf.c1253
-rw-r--r--ext/standard/scanf.h50
-rw-r--r--ext/standard/soundex.c122
-rw-r--r--ext/standard/string.c3753
-rw-r--r--ext/standard/strnatcmp.c173
-rw-r--r--ext/standard/syslog.c270
-rw-r--r--ext/standard/tests/assert/assert.phpt39
-rw-r--r--ext/standard/tests/file/001.phpt149
-rw-r--r--ext/standard/tests/general_functions/001.phpt55
-rw-r--r--ext/standard/tests/general_functions/002.phpt13
-rw-r--r--ext/standard/tests/general_functions/003.phpt54
-rw-r--r--ext/standard/tests/general_functions/004.data4
-rw-r--r--ext/standard/tests/general_functions/004.phpt17
-rw-r--r--ext/standard/tests/general_functions/005.phpt26
-rw-r--r--ext/standard/tests/math/001.phpt45
-rw-r--r--ext/standard/tests/math/pow.phpt144
-rw-r--r--ext/standard/tests/reg/001.phpt9
-rw-r--r--ext/standard/tests/reg/002.phpt9
-rw-r--r--ext/standard/tests/reg/003.phpt10
-rw-r--r--ext/standard/tests/reg/004.phpt16
-rw-r--r--ext/standard/tests/reg/005.phpt20
-rw-r--r--ext/standard/tests/reg/006.phpt10
-rw-r--r--ext/standard/tests/reg/007.phpt12
-rw-r--r--ext/standard/tests/reg/008.phpt10
-rw-r--r--ext/standard/tests/reg/009.phpt19
-rw-r--r--ext/standard/tests/reg/010.phpt9
-rw-r--r--ext/standard/tests/reg/011.phpt9
-rw-r--r--ext/standard/tests/reg/012.phpt9
-rw-r--r--ext/standard/tests/reg/013.phpt9
-rw-r--r--ext/standard/tests/reg/014.phpt9
-rw-r--r--ext/standard/tests/reg/015.phpt8
-rw-r--r--ext/standard/tests/reg/016.phpt8
-rw-r--r--ext/standard/tests/serialize/001.phpt111
-rw-r--r--ext/standard/tests/strings/trim.phpt29
-rw-r--r--ext/standard/tests/time/001.phpt19
-rw-r--r--ext/standard/tests/time/002.phpt40
-rw-r--r--ext/standard/type.c112
-rw-r--r--ext/standard/type.h33
-rw-r--r--ext/standard/uniqid.c103
-rw-r--r--ext/standard/uniqid.h26
-rw-r--r--ext/standard/url.c470
-rw-r--r--ext/standard/url.h54
-rw-r--r--ext/standard/url_scanner.c385
-rw-r--r--ext/standard/url_scanner.h54
-rw-r--r--ext/standard/url_scanner_ex.c903
-rw-r--r--ext/standard/url_scanner_ex.h56
-rw-r--r--ext/standard/url_scanner_ex.re419
-rw-r--r--ext/standard/var.c677
138 files changed, 0 insertions, 36354 deletions
diff --git a/ext/standard/CREDITS b/ext/standard/CREDITS
deleted file mode 100644
index 4021b08860..0000000000
--- a/ext/standard/CREDITS
+++ /dev/null
@@ -1,3 +0,0 @@
-Assert
-Thies C. Arntzen
-
diff --git a/ext/standard/Makefile.in b/ext/standard/Makefile.in
deleted file mode 100644
index 123e4cb110..0000000000
--- a/ext/standard/Makefile.in
+++ /dev/null
@@ -1,18 +0,0 @@
-
-LTLIBRARY_NAME = libstandard.la
-LTLIBRARY_SOURCES=\
- array.c base64.c basic_functions.c browscap.c crc32.c crypt.c cyr_convert.c datetime.c \
- dir.c dl.c dns.c exec.c file.c filestat.c flock_compat.c \
- formatted_print.c fsock.c head.c html.c image.c info.c iptc.c lcg.c \
- link.c mail.c math.c md5.c metaphone.c microtime.c pack.c pageinfo.c \
- parsedate.c quot_print.c rand.c reg.c soundex.c string.c scanf.c \
- syslog.c type.c uniqid.c url.c url_scanner.c var.c assert.c \
- strnatcmp.c levenshtein.c incomplete_class.c url_scanner_ex.c \
- ftp_fopen_wrapper.c http_fopen_wrapper.c php_fopen_wrapper.c credits.c
-
-include $(top_srcdir)/build/dynlib.mk
-
-parsedate.c: $(srcdir)/parsedate.y
-
-$(srcdir)/url_scanner_ex.c: $(srcdir)/url_scanner_ex.re
- re2c -b $(srcdir)/url_scanner_ex.re > $@
diff --git a/ext/standard/array.c b/ext/standard/array.c
deleted file mode 100644
index 312dfb35af..0000000000
--- a/ext/standard/array.c
+++ /dev/null
@@ -1,3152 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- | Rasmus Lerdorf <rasmus@php.net> |
- | Andrei Zmievski <andrei@ispi.net> |
- | Stig Venaas <venaas@php.net> |
- | Jason Greene <jason@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_ini.h"
-#include "zend_operators.h"
-#include <stdarg.h>
-#include <stdlib.h>
-#include <math.h>
-#include <time.h>
-#include <stdio.h>
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#ifdef PHP_WIN32
-#include "win32/unistd.h"
-#endif
-#include "zend_globals.h"
-#include "php_globals.h"
-#include "php_array.h"
-#include "basic_functions.h"
-#include "php_string.h"
-#include "php_rand.h"
-
-#ifdef ZTS
-int array_globals_id;
-#else
-php_array_globals array_globals;
-#endif
-
-#define EXTR_OVERWRITE 0
-#define EXTR_SKIP 1
-#define EXTR_PREFIX_SAME 2
-#define EXTR_PREFIX_ALL 3
-#define EXTR_PREFIX_INVALID 4
-
-#define SORT_REGULAR 0
-#define SORT_NUMERIC 1
-#define SORT_STRING 2
-
-#define SORT_DESC 3
-#define SORT_ASC 4
-
-PHP_MINIT_FUNCTION(array)
-{
-#ifdef ZTS
- ts_allocate_id(&array_globals_id, sizeof(php_array_globals), NULL, NULL);
-#endif
-
- REGISTER_LONG_CONSTANT("EXTR_OVERWRITE", EXTR_OVERWRITE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("EXTR_SKIP", EXTR_SKIP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("EXTR_PREFIX_SAME", EXTR_PREFIX_SAME, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("EXTR_PREFIX_ALL", EXTR_PREFIX_ALL, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("EXTR_PREFIX_INVALID", EXTR_PREFIX_INVALID, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("SORT_ASC", SORT_ASC, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SORT_DESC", SORT_DESC, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("SORT_REGULAR", SORT_REGULAR, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SORT_NUMERIC", SORT_NUMERIC, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SORT_STRING", SORT_STRING, CONST_CS | CONST_PERSISTENT);
-
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(array)
-{
-#ifdef ZTS
- ts_free_id(array_globals_id);
-#endif
-
- return SUCCESS;
-}
-
-static void set_compare_func(int sort_type TSRMLS_DC)
-{
- switch (sort_type) {
- case SORT_NUMERIC:
- ARRAYG(compare_func) = numeric_compare_function;
- break;
-
- case SORT_STRING:
- ARRAYG(compare_func) = string_compare_function;
- break;
-
- case SORT_REGULAR:
- default:
- ARRAYG(compare_func) = compare_function;
- break;
- }
-}
-
-static int array_key_compare(const void *a, const void *b)
-{
- Bucket *f;
- Bucket *s;
- pval result;
- pval first;
- pval second;
- TSRMLS_FETCH();
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- if (f->nKeyLength == 0) {
- Z_TYPE(first) = IS_LONG;
- Z_LVAL(first) = f->h;
- } else {
- Z_TYPE(first) = IS_STRING;
- Z_STRVAL(first) = f->arKey;
- Z_STRLEN(first) = f->nKeyLength;
- }
-
- if (s->nKeyLength == 0) {
- Z_TYPE(second) = IS_LONG;
- Z_LVAL(second) = s->h;
- } else {
- Z_TYPE(second) = IS_STRING;
- Z_STRVAL(second) = s->arKey;
- Z_STRLEN(second) = s->nKeyLength;
- }
-
- if (ARRAYG(compare_func)(&result, &first, &second TSRMLS_CC) == FAILURE) {
- return 0;
- }
-
- if (Z_TYPE(result) == IS_DOUBLE) {
- if (Z_DVAL(result) < 0) {
- return -1;
- } else if (Z_DVAL(result) > 0) {
- return 1;
- } else {
- return 0;
- }
- }
-
- convert_to_long(&result);
-
- if (Z_LVAL(result) < 0) {
- return -1;
- } else if (Z_LVAL(result) > 0) {
- return 1;
- }
-
- return 0;
-}
-
-static int array_reverse_key_compare(const void *a, const void *b)
-{
- return array_key_compare(a, b)*-1;
-}
-
-/* {{{ proto int krsort(array array_arg [, int sort_flags])
- Sort an array reverse by key */
-PHP_FUNCTION(krsort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in krsort() call");
- return;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_reverse_key_compare, 0) == FAILURE) {
- return;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ksort(array array_arg [, int sort_flags])
- Sort an array by key */
-PHP_FUNCTION(ksort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in ksort() call");
- return;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_key_compare, 0) == FAILURE) {
- return;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int count(mixed var)
- Count the number of elements in a variable (usually an array) */
-PHP_FUNCTION(count)
-{
- pval **array;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- if (Z_TYPE_PP(array) == IS_NULL) {
- RETURN_LONG(0);
- } else {
- RETURN_LONG(1);
- }
- }
-
- RETURN_LONG(zend_hash_num_elements(target_hash));
-}
-/* }}} */
-
-/* Numbers are always smaller than strings int this function as it
- * anyway doesn't make much sense to compare two different data types.
- * This keeps it consistant and simple.
- *
- * This is not correct any more, depends on what compare_func is set to.
- */
-static int array_data_compare(const void *a, const void *b)
-{
- Bucket *f;
- Bucket *s;
- pval result;
- pval *first;
- pval *second;
- TSRMLS_FETCH();
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- first = *((pval **) f->pData);
- second = *((pval **) s->pData);
-
- if (ARRAYG(compare_func)(&result, first, second TSRMLS_CC) == FAILURE) {
- return 0;
- }
-
- if (Z_TYPE(result) == IS_DOUBLE) {
- if (Z_DVAL(result) < 0) {
- return -1;
- } else if (Z_DVAL(result) > 0) {
- return 1;
- } else {
- return 0;
- }
- }
-
- convert_to_long(&result);
-
- if (Z_LVAL(result) < 0) {
- return -1;
- } else if (Z_LVAL(result) > 0) {
- return 1;
- }
-
- return 0;
-}
-
-static int array_reverse_data_compare(const void *a, const void *b)
-{
- return array_data_compare(a, b)*-1;
-}
-
-static int array_natural_general_compare(const void *a, const void *b, int fold_case)
-{
- Bucket *f, *s;
- zval *fval, *sval;
- zval first, second;
- int result;
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- fval = *((pval **) f->pData);
- sval = *((pval **) s->pData);
- first = *fval;
- second = *sval;
- if (Z_TYPE_P(fval) != IS_STRING) {
- zval_copy_ctor(&first);
- convert_to_string(&first);
- }
- if (Z_TYPE_P(sval) != IS_STRING) {
- zval_copy_ctor(&first);
- convert_to_string(&second);
- }
-
- result = strnatcmp_ex(Z_STRVAL(first), Z_STRLEN(first),
- Z_STRVAL(second), Z_STRLEN(second), fold_case);
-
- if (Z_TYPE_P(fval) != IS_STRING)
- zval_dtor(&first);
- if (Z_TYPE_P(sval) != IS_STRING)
- zval_dtor(&second);
-
- return result;
-}
-
-static int array_natural_compare(const void *a, const void *b)
-{
- return array_natural_general_compare(a, b, 0);
-}
-
-static int array_natural_case_compare(const void *a, const void *b)
-{
- return array_natural_general_compare(a, b, 1);
-}
-
-static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
-{
- zval **array;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in %s() call",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- if (fold_case) {
- if (zend_hash_sort(target_hash, qsort, array_natural_case_compare, 0) == FAILURE) {
- return;
- }
- } else {
- if (zend_hash_sort(target_hash, qsort, array_natural_compare, 0) == FAILURE) {
- return;
- }
- }
-
- RETURN_TRUE;
-}
-
-
-/* {{{ proto void natsort(array array_arg)
- Sort an array using natural sort */
-PHP_FUNCTION(natsort)
-{
- php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-
-/* {{{ proto void natcasesort(array array_arg)
- Sort an array using case-insensitive natural sort */
-PHP_FUNCTION(natcasesort)
-{
- php_natsort(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-
-/* {{{ proto void asort(array array_arg [, int sort_flags])
- Sort an array and maintain index association */
-PHP_FUNCTION(asort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in asort() call");
- return;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_data_compare, 0) == FAILURE) {
- return;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto void arsort(array array_arg [, int sort_flags])
- Sort an array in reverse order and maintain index association */
-PHP_FUNCTION(arsort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in arsort() call");
- RETURN_FALSE;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 0) == FAILURE) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto void sort(array array_arg [, int sort_flags])
- Sort an array */
-PHP_FUNCTION(sort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in sort() call");
- RETURN_FALSE;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_data_compare, 1) == FAILURE) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto void rsort(array array_arg [, int sort_flags])
- Sort an array in reverse order */
-PHP_FUNCTION(rsort)
-{
- zval **array, **sort_type;
- int sort_type_val = SORT_REGULAR;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &array, &sort_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in rsort() call");
- RETURN_FALSE;
- }
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(sort_type);
- sort_type_val = Z_LVAL_PP(sort_type);
- }
- set_compare_func(sort_type_val TSRMLS_CC);
- if (zend_hash_sort(target_hash, qsort, array_reverse_data_compare, 1) == FAILURE) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-
-
-static int array_user_compare(const void *a, const void *b)
-{
- Bucket *f;
- Bucket *s;
- pval **args[2];
- pval *retval_ptr;
- TSRMLS_FETCH();
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- args[0] = (pval **) f->pData;
- args[1] = (pval **) s->pData;
-
- if (call_user_function_ex(EG(function_table), NULL, *BG(user_compare_func_name), &retval_ptr, 2, args, 0, NULL TSRMLS_CC)==SUCCESS
- && retval_ptr) {
- long retval;
-
- convert_to_long_ex(&retval_ptr);
- retval = Z_LVAL_P(retval_ptr);
- zval_ptr_dtor(&retval_ptr);
- return retval;
- } else {
- return 0;
- }
-}
-
-/* {{{ proto void usort(array array_arg, string cmp_function)
- Sort an array by values using a user-defined comparison function */
-PHP_FUNCTION(usort)
-{
- pval **array;
- pval **old_compare_func;
- HashTable *target_hash;
-
- old_compare_func = BG(user_compare_func_name);
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in usort() call");
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- if (zend_hash_sort(target_hash, qsort, array_user_compare, 1) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- BG(user_compare_func_name) = old_compare_func;
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto void uasort(array array_arg, string cmp_function)
- Sort an array with a user-defined comparison function and maintain index association */
-PHP_FUNCTION(uasort)
-{
- pval **array;
- pval **old_compare_func;
- HashTable *target_hash;
-
- old_compare_func = BG(user_compare_func_name);
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in uasort() call");
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- if (zend_hash_sort(target_hash, qsort, array_user_compare, 0) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- BG(user_compare_func_name) = old_compare_func;
- RETURN_TRUE;
-}
-/* }}} */
-
-static int array_user_key_compare(const void *a, const void *b)
-{
- Bucket *f;
- Bucket *s;
- pval key1, key2;
- pval *args[2];
- pval retval;
- int status;
- TSRMLS_FETCH();
-
- args[0] = &key1;
- args[1] = &key2;
- INIT_PZVAL(&key1);
- INIT_PZVAL(&key2);
-
- f = *((Bucket **) a);
- s = *((Bucket **) b);
-
- if (f->nKeyLength) {
- Z_STRVAL(key1) = estrndup(f->arKey, f->nKeyLength);
- Z_STRLEN(key1) = f->nKeyLength-1;
- Z_TYPE(key1) = IS_STRING;
- } else {
- Z_LVAL(key1) = f->h;
- Z_TYPE(key1) = IS_LONG;
- }
- if (s->nKeyLength) {
- Z_STRVAL(key2) = estrndup(s->arKey, s->nKeyLength);
- Z_STRLEN(key2) = s->nKeyLength-1;
- Z_TYPE(key2) = IS_STRING;
- } else {
- Z_LVAL(key2) = s->h;
- Z_TYPE(key2) = IS_LONG;
- }
-
- status = call_user_function(EG(function_table), NULL, *BG(user_compare_func_name), &retval, 2, args TSRMLS_CC);
-
- zval_dtor(&key1);
- zval_dtor(&key2);
-
- if (status==SUCCESS) {
- convert_to_long(&retval);
- return Z_LVAL(retval);
- } else {
- return 0;
- }
-}
-
-/* {{{ proto void uksort(array array_arg, string cmp_function)
- Sort an array by keys using a user-defined comparison function */
-PHP_FUNCTION(uksort)
-{
- pval **array;
- pval **old_compare_func;
- HashTable *target_hash;
-
- old_compare_func = BG(user_compare_func_name);
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &array, &BG(user_compare_func_name)) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in uksort() call");
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- if (zend_hash_sort(target_hash, qsort, array_user_key_compare, 0) == FAILURE) {
- BG(user_compare_func_name) = old_compare_func;
- RETURN_FALSE;
- }
- BG(user_compare_func_name) = old_compare_func;
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto mixed end(array array_arg)
- Advances array argument's internal pointer to the last element and return it */
-PHP_FUNCTION(end)
-{
- pval **array, **entry;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to end() is not an array or object");
- RETURN_FALSE;
- }
- zend_hash_internal_pointer_end(target_hash);
-
- if (return_value_used) {
- if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) {
- RETURN_FALSE;
- }
-
- *return_value = **entry;
- zval_copy_ctor(return_value);
- }
-}
-/* }}} */
-
-/* {{{ proto mixed prev(array array_arg)
- Move array argument's internal pointer to the previous element and return it */
-PHP_FUNCTION(prev)
-{
- pval **array, **entry;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to prev() is not an array or object");
- RETURN_FALSE;
- }
- zend_hash_move_backwards(target_hash);
-
- if (return_value_used) {
- if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) {
- RETURN_FALSE;
- }
-
- *return_value = **entry;
- zval_copy_ctor(return_value);
- }
-}
-/* }}} */
-
-/* {{{ proto mixed next(array array_arg)
- Move array argument's internal pointer to the next element and return it */
-PHP_FUNCTION(next)
-{
- pval **array, **entry;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to next() is not an array or object");
- RETURN_FALSE;
- }
- zend_hash_move_forward(target_hash);
-
- if (return_value_used) {
- if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) {
- RETURN_FALSE;
- }
-
- *return_value = **entry;
- zval_copy_ctor(return_value);
- }
-}
-/* }}} */
-
-/* {{{ proto mixed reset(array array_arg)
- Set array argument's internal pointer to the first element and return it */
-PHP_FUNCTION(reset)
-{
- pval **array, **entry;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to reset() is not an array or object");
- RETURN_FALSE;
- }
- zend_hash_internal_pointer_reset(target_hash);
-
- if (return_value_used) {
- if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) {
- RETURN_FALSE;
- }
-
- *return_value = **entry;
- zval_copy_ctor(return_value);
- }
-}
-/* }}} */
-
-/* {{{ proto mixed current(array array_arg)
- Return the element currently pointed to by the internal array pointer */
-PHP_FUNCTION(current)
-{
- pval **array, **entry;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to current() is not an array or object");
- RETURN_FALSE;
- }
- if (zend_hash_get_current_data(target_hash, (void **) &entry) == FAILURE) {
- RETURN_FALSE;
- }
- *return_value = **entry;
- zval_copy_ctor(return_value);
-}
-/* }}} */
-
-/* {{{ proto mixed key(array array_arg)
- Return the key of the element currently pointed to by the internal array pointer */
-PHP_FUNCTION(key)
-{
- pval **array;
- char *string_key;
- ulong num_key;
- HashTable *target_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Variable passed to key() is not an array or object");
- RETURN_FALSE;
- }
- switch (zend_hash_get_current_key(target_hash, &string_key, &num_key, 1)) {
- case HASH_KEY_IS_STRING:
- RETVAL_STRING(string_key, 0);
- break;
- case HASH_KEY_IS_LONG:
- RETVAL_LONG(num_key);
- break;
- case HASH_KEY_NON_EXISTANT:
- return;
- }
-}
-/* }}} */
-
-/* {{{ proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]])
- Return the lowest value in an array or a series of arguments */
-PHP_FUNCTION(min)
-{
- int argc=ZEND_NUM_ARGS();
- pval **result;
-
- if (argc<=0) {
- php_error(E_WARNING, "min: must be passed at least 1 value");
- RETURN_NULL();
- }
- set_compare_func(SORT_REGULAR TSRMLS_CC);
- if (argc == 1) {
- pval **arr;
-
- if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) {
- WRONG_PARAM_COUNT;
- }
- if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 0, (void **) &result)==SUCCESS) {
- *return_value = **result;
- zval_copy_ctor(return_value);
- } else {
- php_error(E_WARNING, "min: array must contain at least 1 element");
- RETURN_FALSE;
- }
- } else {
- pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS());
- pval **min, result;
- int i;
-
- if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args)==FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- min = args[0];
-
- for (i=1; i<ZEND_NUM_ARGS(); i++) {
- is_smaller_function(&result, *args[i], *min TSRMLS_CC);
- if (Z_LVAL(result) == 1) {
- min = args[i];
- }
- }
-
- *return_value = **min;
- zval_copy_ctor(return_value);
-
- efree(args);
- }
-}
-/* }}} */
-
-/* {{{ proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]])
- Return the highest value in an array or a series of arguments */
-PHP_FUNCTION(max)
-{
- int argc=ZEND_NUM_ARGS();
- pval **result;
-
- if (argc<=0) {
- php_error(E_WARNING, "max: must be passed at least 1 value");
- RETURN_NULL();
- }
- set_compare_func(SORT_REGULAR TSRMLS_CC);
- if (argc == 1) {
- pval **arr;
-
- if (zend_get_parameters_ex(1, &arr) == FAILURE || Z_TYPE_PP(arr) != IS_ARRAY) {
- WRONG_PARAM_COUNT;
- }
- if (zend_hash_minmax(Z_ARRVAL_PP(arr), array_data_compare, 1, (void **) &result)==SUCCESS) {
- *return_value = **result;
- zval_copy_ctor(return_value);
- } else {
- php_error(E_WARNING, "max: array must contain at least 1 element");
- RETURN_FALSE;
- }
- } else {
- pval ***args = (pval ***) emalloc(sizeof(pval **)*ZEND_NUM_ARGS());
- pval **max, result;
- int i;
-
- if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args)==FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- max = args[0];
-
- for (i=1; i<ZEND_NUM_ARGS(); i++) {
- is_smaller_or_equal_function(&result, *args[i], *max TSRMLS_CC);
- if (Z_LVAL(result) == 0) {
- max = args[i];
- }
- }
-
- *return_value = **max;
- zval_copy_ctor(return_value);
-
- efree(args);
- }
-}
-/* }}} */
-
-static int php_array_walk(HashTable *target_hash, zval **userdata TSRMLS_DC)
-{
- zval **args[3], /* Arguments to userland function */
- *retval_ptr, /* Return value - unused */
- *key; /* Entry key */
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- HashPosition pos;
-
- /* Allocate space for key */
- MAKE_STD_ZVAL(key);
-
- /* Set up known arguments */
- args[1] = &key;
- args[2] = userdata;
-
- zend_hash_internal_pointer_reset_ex(target_hash, &pos);
-
- /* Iterate through hash */
- while(zend_hash_get_current_data_ex(target_hash, (void **)&args[0], &pos) == SUCCESS) {
- /* Set up the key */
- if (zend_hash_get_current_key_ex(target_hash, &string_key, &string_key_len, &num_key, 0, &pos) == HASH_KEY_IS_LONG) {
- Z_TYPE_P(key) = IS_LONG;
- Z_LVAL_P(key) = num_key;
- } else {
- Z_TYPE_P(key) = IS_STRING;
- Z_STRVAL_P(key) = string_key;
- Z_STRLEN_P(key) = string_key_len-1;
- }
-
- /* Call the userland function */
- if (call_user_function_ex(EG(function_table), NULL, *BG(array_walk_func_name),
- &retval_ptr, userdata ? 3 : 2, args, 0, NULL TSRMLS_CC) == SUCCESS) {
-
- zval_ptr_dtor(&retval_ptr);
- } else
- php_error(E_WARNING, "Unable to call %s() - function does not exist",
- (*BG(array_walk_func_name))->value.str.val);
-
- zend_hash_move_forward_ex(target_hash, &pos);
- }
- efree(key);
-
- return 0;
-}
-
-/* {{{ proto int array_walk(array input, string funcname [, mixed userdata])
- Apply a user function to every member of an array */
-PHP_FUNCTION(array_walk)
-{
- int argc;
- zval **array,
- **userdata = NULL,
- **old_walk_func_name;
- HashTable *target_hash;
-
- argc = ZEND_NUM_ARGS();
- old_walk_func_name = BG(array_walk_func_name);
- if (argc < 2 || argc > 3 ||
- zend_get_parameters_ex(argc, &array, &BG(array_walk_func_name), &userdata) == FAILURE) {
- BG(array_walk_func_name) = old_walk_func_name;
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in %s() call",
- get_active_function_name(TSRMLS_C));
- BG(array_walk_func_name) = old_walk_func_name;
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(BG(array_walk_func_name)) != IS_ARRAY &&
- Z_TYPE_PP(BG(array_walk_func_name)) != IS_STRING) {
- php_error(E_WARNING, "Wrong syntax for function name in %s() call",
- get_active_function_name(TSRMLS_C));
- BG(array_walk_func_name) = old_walk_func_name;
- RETURN_FALSE;
- }
- php_array_walk(target_hash, userdata TSRMLS_CC);
- BG(array_walk_func_name) = old_walk_func_name;
- RETURN_TRUE;
-}
-/* }}} */
-
-/* void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior)
- * 0 = return boolean
- * 1 = return key
- */
-static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior)
-{
- zval **value, /* value to check for */
- **array, /* array to check in */
- **strict, /* strict comparison or not */
- **entry, /* pointer to array entry */
- res; /* comparison result */
- HashTable *target_hash; /* array hashtable */
- HashPosition pos; /* hash iterator */
- ulong num_key;
- char *string_key;
- int (*compare_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
-
- if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &value, &array, &strict) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(value) == IS_ARRAY || Z_TYPE_PP(value) == IS_OBJECT) {
- php_error(E_WARNING, "Wrong datatype for first argument in call to %s", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
-
- if (Z_TYPE_PP(array) != IS_ARRAY) {
- php_error(E_WARNING, "Wrong datatype for second argument in call to %s", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
-
- if (ZEND_NUM_ARGS() == 3) {
- convert_to_boolean_ex(strict);
- if (Z_LVAL_PP(strict)) {
- compare_func = is_identical_function;
- }
- }
-
- target_hash = HASH_OF(*array);
- zend_hash_internal_pointer_reset_ex(target_hash, &pos);
- while(zend_hash_get_current_data_ex(target_hash, (void **)&entry, &pos) == SUCCESS) {
- compare_func(&res, *value, *entry TSRMLS_CC);
- if (Z_LVAL(res) == 1) {
- if (behavior==0) {
- RETURN_TRUE;
- } else {
- /* Return current key */
- switch (zend_hash_get_current_key_ex(target_hash, &string_key, NULL, &num_key, 1, &pos)) {
- case HASH_KEY_IS_STRING:
- RETVAL_STRING(string_key, 0);
- break;
- case HASH_KEY_IS_LONG:
- RETVAL_LONG(num_key);
- break;
- }
- }
- }
-
- zend_hash_move_forward_ex(target_hash, &pos);
- }
-
- if (behavior == 0) {
- RETURN_FALSE;
- } else {
- return;
- }
-}
-
-
-/* {{{ proto bool in_array(mixed needle, array haystack [, bool strict])
- Checks if the given value exists in the array */
-PHP_FUNCTION(in_array)
-{
- php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto mixed array_search(mixed needle, array haystack [, bool strict])
- Searches the array for a given value and returns the corresponding key if successful */
-PHP_FUNCTION(array_search)
-{
- php_search_array(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-
-static int php_valid_var_name(char *var_name)
-{
- int len, i;
-
- if (!var_name)
- return 0;
-
- len = strlen(var_name);
-
- if (!isalpha((int)var_name[0]) && var_name[0] != '_')
- return 0;
-
- if (len > 1) {
- for(i=1; i<len; i++) {
- if (!isalnum((int)var_name[i]) && var_name[i] != '_') {
- return 0;
- }
- }
- }
-
- return 1;
-}
-
-
-/* {{{ proto int extract(array var_array [, int extract_type [, string prefix]])
- Imports variables into symbol table from an array */
-PHP_FUNCTION(extract)
-{
- zval **var_array, **z_extract_type, **prefix;
- zval **entry, *data;
- char *var_name, *final_name;
- ulong num_key, var_name_len;
- int var_exists, extract_type, key_type, count = 0;
- HashPosition pos;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &var_array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- extract_type = EXTR_OVERWRITE;
- break;
-
- case 2:
- if (zend_get_parameters_ex(2, &var_array, &z_extract_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(z_extract_type);
- extract_type = Z_LVAL_PP(z_extract_type);
- if (extract_type > EXTR_SKIP && extract_type <= EXTR_PREFIX_INVALID) {
- php_error(E_WARNING, "%s() expects a prefix to be specified",
- get_active_function_name(TSRMLS_C));
- return;
- }
- break;
-
- case 3:
- if (zend_get_parameters_ex(3, &var_array, &z_extract_type, &prefix) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(z_extract_type);
- extract_type = Z_LVAL_PP(z_extract_type);
- convert_to_string_ex(prefix);
- break;
-
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- if (extract_type < EXTR_OVERWRITE || extract_type > EXTR_PREFIX_INVALID) {
- php_error(E_WARNING, "Unknown extract type in call to %s()",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- if (Z_TYPE_PP(var_array) != IS_ARRAY) {
- php_error(E_WARNING, "%s() expects first argument to be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(var_array), &pos);
- while(zend_hash_get_current_data_ex(Z_ARRVAL_PP(var_array), (void **)&entry, &pos) == SUCCESS) {
- key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(var_array), &var_name, &var_name_len, &num_key, 0, &pos);
- final_name = NULL;
- var_exists = 0;
-
- if (key_type == HASH_KEY_IS_STRING) {
- var_name_len--;
- var_exists = zend_hash_exists(EG(active_symbol_table), var_name, var_name_len + 1);
- } else if (extract_type == EXTR_PREFIX_ALL || extract_type == EXTR_PREFIX_INVALID) {
- final_name = emalloc(MAX_LENGTH_OF_LONG + Z_STRLEN_PP(prefix) + 2);
- zend_sprintf(final_name, "%s_%ld", Z_STRVAL_PP(prefix), num_key);
- } else {
- zend_hash_move_forward_ex(Z_ARRVAL_PP(var_array), &pos);
- continue;
- }
-
- switch (extract_type) {
- case EXTR_OVERWRITE:
- final_name = estrndup(var_name, var_name_len);
- break;
-
- case EXTR_PREFIX_SAME:
- if (!var_exists)
- final_name = estrndup(var_name, var_name_len);
- /* break omitted intentionally */
-
- case EXTR_PREFIX_ALL:
- if (!final_name) {
- final_name = emalloc(var_name_len + Z_STRLEN_PP(prefix) + 2);
- strcpy(final_name, Z_STRVAL_PP(prefix));
- strcat(final_name, "_");
- strcat(final_name, var_name);
- }
- break;
-
- case EXTR_PREFIX_INVALID:
- if (!final_name) {
- if (!php_valid_var_name(var_name)) {
- final_name = emalloc(var_name_len + Z_STRLEN_PP(prefix) + 2);
- strcpy(final_name, Z_STRVAL_PP(prefix));
- strcat(final_name, "_");
- strcat(final_name, var_name);
- } else
- final_name = estrndup(var_name, var_name_len);
- }
- break;
-
- default:
- if (!var_exists)
- final_name = estrndup(var_name, var_name_len);
- break;
- }
-
- if (final_name) {
- if (php_valid_var_name(final_name)) {
- MAKE_STD_ZVAL(data);
- *data = **entry;
- zval_copy_ctor(data);
-
- ZEND_SET_SYMBOL(EG(active_symbol_table), final_name, data);
-
- count++;
- }
- efree(final_name);
- }
-
- zend_hash_move_forward_ex(Z_ARRVAL_PP(var_array), &pos);
- }
-
- RETURN_LONG(count);
-}
-/* }}} */
-
-
-static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_value, zval *entry)
-{
- zval **value_ptr, *value, *data;
-
- if (Z_TYPE_P(entry) == IS_STRING) {
- if (zend_hash_find(eg_active_symbol_table, Z_STRVAL_P(entry),
- Z_STRLEN_P(entry)+1, (void **)&value_ptr) != FAILURE) {
- value = *value_ptr;
- ALLOC_ZVAL(data);
- *data = *value;
- zval_copy_ctor(data);
- INIT_PZVAL(data);
-
- zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_P(entry),
- Z_STRLEN_P(entry)+1, &data, sizeof(zval *), NULL);
- }
- }
- else if (Z_TYPE_P(entry) == IS_ARRAY) {
- HashPosition pos;
-
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(entry), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_P(entry), (void**)&value_ptr, &pos) == SUCCESS) {
- value = *value_ptr;
-
- php_compact_var(eg_active_symbol_table, return_value, value);
- zend_hash_move_forward_ex(Z_ARRVAL_P(entry), &pos);
- }
- }
-}
-
-
-/* {{{ proto array compact(mixed var_names [, mixed ...])
- Creates a hash containing variables and their values */
-PHP_FUNCTION(compact)
-{
- zval ***args; /* function arguments array */
- int i;
-
- args = (zval ***)emalloc(ZEND_NUM_ARGS() * sizeof(zval **));
-
- if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- array_init(return_value);
-
- for (i=0; i<ZEND_NUM_ARGS(); i++) {
- php_compact_var(EG(active_symbol_table), return_value, *args[i]);
- }
-
- efree(args);
-}
-/* }}} */
-
-/* {{{ proto array range(mixed low, mixed high)
- Create an array containing the range of integers or characters from low to high (inclusive) */
-PHP_FUNCTION(range)
-{
- zval **zlow, **zhigh;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &zlow, &zhigh) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- /* allocate an array for return */
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- if(Z_TYPE_PP(zlow)==IS_STRING && Z_TYPE_PP(zhigh)==IS_STRING) {
- char *low, *high;
- convert_to_string_ex(zlow);
- convert_to_string_ex(zhigh);
- low = Z_STRVAL_PP(zlow);
- high = Z_STRVAL_PP(zhigh);
- if(*low>*high) {
- for (; *low >= *high; (*low)--) {
- add_next_index_stringl(return_value, low, 1, 1);
- }
- } else {
- for (; *low <= *high; (*low)++) {
- add_next_index_stringl(return_value, low, 1, 1);
- }
- }
- } else {
- int low, high;
- convert_to_long_ex(zlow);
- convert_to_long_ex(zhigh);
- low = Z_LVAL_PP(zlow);
- high = Z_LVAL_PP(zhigh);
- if(low>high) {
- for (; low >= high; low--) {
- add_next_index_long(return_value, low);
- }
- } else {
- for (; low <= high; low++) {
- add_next_index_long(return_value, low);
- }
- }
- }
-}
-/* }}} */
-
-
-static int array_data_shuffle(const void *a, const void*b) {
- return (php_rand() % 2) ? 1 : -1;
-}
-
-
-/* {{{ proto int shuffle(array array_arg)
- Randomly shuffle the contents of an array */
-PHP_FUNCTION(shuffle)
-{
- zval **array;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- if (Z_TYPE_PP(array) != IS_ARRAY) {
- php_error(E_WARNING, "Wrong datatype in shuffle() call");
- RETURN_FALSE;
- }
- if (zend_hash_sort(Z_ARRVAL_PP(array), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-
-/* HashTable* php_splice(HashTable *in_hash, int offset, int length,
- zval ***list, int list_count, HashTable **removed) */
-HashTable* php_splice(HashTable *in_hash, int offset, int length,
- zval ***list, int list_count, HashTable **removed)
-{
- HashTable *out_hash = NULL; /* Output hashtable */
- int num_in, /* Number of entries in the input hashtable */
- pos, /* Current position in the hashtable */
- i; /* Loop counter */
- Bucket *p; /* Pointer to hash bucket */
- zval *entry; /* Hash entry */
-
- /* If input hash doesn't exist, we have nothing to do */
- if (!in_hash)
- return NULL;
-
- /* Get number of entries in the input hash */
- num_in = zend_hash_num_elements(in_hash);
-
- /* Clamp the offset.. */
- if (offset > num_in)
- offset = num_in;
- else if (offset < 0 && (offset=num_in+offset) < 0)
- offset = 0;
-
- /* ..and the length */
- if (length < 0)
- length = num_in-offset+length;
- else if(offset+length > num_in)
- length = num_in-offset;
-
- /* Create and initialize output hash */
- ALLOC_HASHTABLE(out_hash);
- zend_hash_init(out_hash, 0, NULL, ZVAL_PTR_DTOR, 0);
-
- /* Start at the beginning of the input hash and copy
- entries to output hash until offset is reached */
- for (pos=0, p=in_hash->pListHead; pos<offset && p ; pos++, p=p->pListNext) {
- /* Get entry and increase reference count */
- entry = *((zval **)p->pData);
- entry->refcount++;
-
- /* Update output hash depending on key type */
- if (p->nKeyLength)
- zend_hash_update(out_hash, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL);
- else
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
- }
-
- /* If hash for removed entries exists, go until offset+length
- and copy the entries to it */
- if (removed != NULL) {
- for( ; pos<offset+length && p; pos++, p=p->pListNext) {
- entry = *((zval **)p->pData);
- entry->refcount++;
- if (p->nKeyLength)
- zend_hash_update(*removed, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL);
- else
- zend_hash_next_index_insert(*removed, &entry, sizeof(zval *), NULL);
- }
- } else /* otherwise just skip those entries */
- for( ; pos<offset+length && p; pos++, p=p->pListNext);
-
- /* If there are entries to insert.. */
- if (list != NULL) {
- /* ..for each one, create a new zval, copy entry into it
- and copy it into the output hash */
- for (i=0; i<list_count; i++) {
- entry = *list[i];
- entry->refcount++;
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
- }
- }
-
- /* Copy the remaining input hash entries to the output hash */
- for ( ; p ; p=p->pListNext) {
- entry = *((zval **)p->pData);
- entry->refcount++;
- if (p->nKeyLength)
- zend_hash_update(out_hash, p->arKey, p->nKeyLength, &entry, sizeof(zval *), NULL);
- else
- zend_hash_next_index_insert(out_hash, &entry, sizeof(zval *), NULL);
- }
-
- zend_hash_internal_pointer_reset(out_hash);
- return out_hash;
-}
-/* }}} */
-
-
-/* {{{ proto int array_push(array stack, mixed var [, mixed ...])
- Pushes elements onto the end of the array */
-PHP_FUNCTION(array_push)
-{
- zval ***args, /* Function arguments array */
- *stack, /* Input array */
- *new_var; /* Variable to be pushed */
- int i, /* Loop counter */
- argc; /* Number of function arguments */
-
- /* Get the argument count and check it */
- argc = ZEND_NUM_ARGS();
- if (argc < 2) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- /* Get first argument and check that it's an array */
- stack = *args[0];
- if (Z_TYPE_P(stack) != IS_ARRAY) {
- php_error(E_WARNING, "First argument to array_push() needs to be an array");
- efree(args);
- RETURN_FALSE;
- }
-
- /* For each subsequent argument, make it a reference, increase refcount,
- and add it to the end of the array */
- for (i=1; i<argc; i++) {
- new_var = *args[i];
- new_var->refcount++;
-
- zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var, sizeof(zval *), NULL);
- }
-
- /* Clean up and return the number of values in the stack */
- efree(args);
- RETVAL_LONG(zend_hash_num_elements(Z_ARRVAL_P(stack)));
-}
-/* }}} */
-
-
-/* {{{ void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int which_end) */
-static void _phpi_pop(INTERNAL_FUNCTION_PARAMETERS, int off_the_end)
-{
- zval **stack, /* Input stack */
- **val; /* Value to be popped */
- HashTable *new_hash; /* New stack */
-
- /* Get the arguments and do error-checking */
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &stack) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(stack) != IS_ARRAY) {
- php_error(E_WARNING, "The argument needs to be an array");
- return;
- }
-
- if (zend_hash_num_elements(Z_ARRVAL_PP(stack)) == 0) {
- return;
- }
-
- /* Get the first or last value and copy it into the return value */
- if (off_the_end)
- zend_hash_internal_pointer_end(Z_ARRVAL_PP(stack));
- else
- zend_hash_internal_pointer_reset(Z_ARRVAL_PP(stack));
- zend_hash_get_current_data(Z_ARRVAL_PP(stack), (void **)&val);
- *return_value = **val;
- zval_copy_ctor(return_value);
- INIT_PZVAL(return_value);
-
- /* Delete the first or last value */
- new_hash = php_splice(Z_ARRVAL_PP(stack), (off_the_end) ? -1 : 0, 1, NULL, 0, NULL);
- zend_hash_destroy(Z_ARRVAL_PP(stack));
- efree(Z_ARRVAL_PP(stack));
- Z_ARRVAL_PP(stack) = 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 [, mixed ...])
- Pushes elements onto the beginning of the array */
-PHP_FUNCTION(array_unshift)
-{
- zval ***args, /* Function arguments array */
- *stack; /* Input stack */
- HashTable *new_hash; /* New hashtable for the stack */
- int argc; /* Number of function arguments */
-
-
- /* Get the argument count and check it */
- argc = ZEND_NUM_ARGS();
- if (argc < 2) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- /* Get first argument and check that it's an array */
- stack = *args[0];
- if (Z_TYPE_P(stack) != IS_ARRAY) {
- php_error(E_WARNING, "First argument to array_unshift() needs to be an array");
- efree(args);
- RETURN_FALSE;
- }
-
- /* Use splice to insert the elements at the beginning. Destroy old
- hashtable and replace it with new one */
- new_hash = php_splice(Z_ARRVAL_P(stack), 0, 0, &args[1], argc-1, NULL);
- zend_hash_destroy(Z_ARRVAL_P(stack));
- efree(Z_ARRVAL_P(stack));
- Z_ARRVAL_P(stack) = new_hash;
-
- /* Clean up and return the number of elements in the stack */
- efree(args);
- RETVAL_LONG(zend_hash_num_elements(Z_ARRVAL_P(stack)));
-}
-/* }}} */
-
-
-/* {{{ proto array array_splice(array input, int offset [, int length [, array replacement]])
- Removes the elements designated by offset and length and replace them with supplied array */
-PHP_FUNCTION(array_splice)
-{
- zval ***args, /* Function arguments array */
- *array, /* Input array */
- ***repl = NULL; /* Replacement elements */
- HashTable *new_hash = NULL; /* Output array's hash */
- Bucket *p; /* Bucket used for traversing hash */
- int argc, /* Number of function arguments */
- i,
- offset,
- length,
- repl_num = 0; /* Number of replacement elements */
-
- /* Get the argument count and check it */
- argc = ZEND_NUM_ARGS();
- if (argc < 2 || argc > 4) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- /* Get first argument and check that it's an array */
- array = *args[0];
- if (Z_TYPE_P(array) != IS_ARRAY) {
- php_error(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 = Z_LVAL_PP(args[1]);
- if (argc > 2) {
- convert_to_long_ex(args[2]);
- length = Z_LVAL_PP(args[2]);
- } else
- length = zend_hash_num_elements(Z_ARRVAL_P(array));
-
- if (argc == 4) {
- /* Make sure the last argument, if passed, is an array */
- convert_to_array_ex(args[3]);
-
- /* Create the array of replacement elements */
- repl_num = zend_hash_num_elements(Z_ARRVAL_PP(args[3]));
- repl = (zval ***)emalloc(repl_num * sizeof(zval **));
- for (p=Z_ARRVAL_PP(args[3])->pListHead, i=0; p; p=p->pListNext, i++) {
- repl[i] = ((zval **)p->pData);
- }
- }
-
- /* Initialize return value */
- array_init(return_value);
-
- /* Perform splice */
- new_hash = php_splice(Z_ARRVAL_P(array), offset, length,
- repl, repl_num,
- &Z_ARRVAL_P(return_value));
-
- /* Replace input array's hashtable with the new one */
- zend_hash_destroy(Z_ARRVAL_P(array));
- efree(Z_ARRVAL_P(array));
- Z_ARRVAL_P(array) = new_hash;
-
- /* Clean up */
- if (argc == 4)
- efree(repl);
- efree(args);
-}
-/* }}} */
-
-
-/* {{{ proto array array_slice(array input, int offset [, int length])
- Returns elements specified by offset and length */
-PHP_FUNCTION(array_slice)
-{
- zval **input, /* Input array */
- **offset, /* Offset to get elements from */
- **length, /* How many elements to get */
- **entry; /* An array entry */
- int offset_val, /* Value of the offset argument */
- length_val, /* Value of the length argument */
- num_in, /* Number of elements in the input array */
- pos, /* Current position in the array */
- argc; /* Number of function arguments */
-
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- HashPosition hpos;
-
-
- /* Get the arguments and do error-checking */
- argc = ZEND_NUM_ARGS();
- if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &input, &offset, &length)) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(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 = Z_LVAL_PP(offset);
- if (argc == 3) {
- convert_to_long_ex(length);
- length_val = Z_LVAL_PP(length);
- } else
- length_val = zend_hash_num_elements(Z_ARRVAL_PP(input));
-
- /* Initialize returned array */
- array_init(return_value);
-
- /* Get number of entries in the input hash */
- num_in = zend_hash_num_elements(Z_ARRVAL_PP(input));
-
- /* Clamp the offset.. */
- if (offset_val > num_in)
- return;
- else if (offset_val < 0 && (offset_val=num_in+offset_val) < 0)
- offset_val = 0;
-
- /* ..and the length */
- if (length_val < 0)
- length_val = num_in-offset_val+length_val;
- else if(offset_val+length_val > num_in)
- length_val = num_in-offset_val;
-
- if (length_val == 0)
- return;
-
- /* Start at the beginning and go until we hit offset */
- pos = 0;
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &hpos);
- while(pos < offset_val &&
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) {
- pos++;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos);
- }
-
- /* Copy elements from input array to the one that's returned */
- while(pos < offset_val+length_val &&
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &hpos) == SUCCESS) {
-
- (*entry)->refcount++;
-
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &hpos)) {
- case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len,
- entry, sizeof(zval *), NULL);
- break;
-
- case HASH_KEY_IS_LONG:
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value),
- entry, sizeof(zval *), NULL);
- break;
- }
- pos++;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &hpos);
- }
-}
-/* }}} */
-
-
-PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive)
-{
- zval **src_entry,
- **dest_entry;
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- HashPosition pos;
-
- zend_hash_internal_pointer_reset_ex(src, &pos);
- while(zend_hash_get_current_data_ex(src, (void **)&src_entry, &pos) == SUCCESS) {
- switch (zend_hash_get_current_key_ex(src, &string_key, &string_key_len, &num_key, 0, &pos)) {
- case HASH_KEY_IS_STRING:
- if (recursive &&
- zend_hash_find(dest, string_key, string_key_len,
- (void **)&dest_entry) == SUCCESS) {
- convert_to_array_ex(dest_entry);
- convert_to_array_ex(src_entry);
- php_array_merge(Z_ARRVAL_PP(dest_entry),
- Z_ARRVAL_PP(src_entry), recursive);
- } else {
- (*src_entry)->refcount++;
-
- zend_hash_update(dest, string_key, strlen(string_key)+1,
- src_entry, sizeof(zval *), NULL);
- }
- break;
-
- case HASH_KEY_IS_LONG:
- (*src_entry)->refcount++;
- zend_hash_next_index_insert(dest, src_entry, sizeof(zval *), NULL);
- break;
- }
-
- zend_hash_move_forward_ex(src, &pos);
- }
-}
-
-static void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMETERS, int recursive)
-{
- zval ***args = NULL;
- int argc,
- i;
-
- /* Get the argument count and check it */
- argc = ZEND_NUM_ARGS();
- if (argc < 2) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- array_init(return_value);
-
- for (i=0; i<argc; i++) {
- convert_to_array_ex(args[i]);
- php_array_merge(Z_ARRVAL_P(return_value), Z_ARRVAL_PP(args[i]), recursive);
- }
-
- efree(args);
-}
-
-
-/* {{{ proto array array_merge(array arr1, array arr2 [, array ...])
- Merges elements from passed arrays into one array */
-PHP_FUNCTION(array_merge)
-{
- php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-
-/* {{{ proto array array_merge_recursive(array arr1, array arr2 [, array ...])
- Recursively merges elements from passed arrays into one array */
-PHP_FUNCTION(array_merge_recursive)
-{
- php_array_merge_wrapper(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-
-/* {{{ proto array array_keys(array input [, mixed search_value])
- Return just the keys from the input array, optionally only for the specified search_value */
-PHP_FUNCTION(array_keys)
-{
- zval **input, /* Input array */
- **search_value, /* Value to search for */
- **entry, /* An entry in the input array */
- res, /* Result of comparison */
- *new_val; /* New value */
- int add_key; /* Flag to indicate whether a key should be added */
- char *string_key; /* String key */
- ulong string_key_len;
- ulong num_key; /* Numeric key */
- HashPosition pos;
-
- search_value = NULL;
-
- /* Get arguments and do error-checking */
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &search_value) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(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_ex(Z_ARRVAL_PP(input), &pos);
- while(zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) {
- if (search_value != NULL) {
- is_equal_function(&res, *search_value, *entry TSRMLS_CC);
- add_key = zval_is_true(&res);
- }
-
- if (add_key) {
- MAKE_STD_ZVAL(new_val);
-
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 1, &pos)) {
- case HASH_KEY_IS_STRING:
- Z_TYPE_P(new_val) = IS_STRING;
- Z_STRVAL_P(new_val) = string_key;
- Z_STRLEN_P(new_val) = string_key_len-1;
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val,
- sizeof(zval *), NULL);
- break;
-
- case HASH_KEY_IS_LONG:
- Z_TYPE_P(new_val) = IS_LONG;
- Z_LVAL_P(new_val) = num_key;
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &new_val,
- sizeof(zval *), NULL);
- break;
- }
- }
-
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos);
- }
-}
-/* }}} */
-
-
-/* {{{ proto array array_values(array input)
- Return just the values from the input array */
-PHP_FUNCTION(array_values)
-{
- zval **input, /* Input array */
- **entry; /* An entry in the input array */
- HashPosition pos;
-
- /* Get arguments and do error-checking */
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &input) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(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_ex(Z_ARRVAL_PP(input), &pos);
- while(zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) {
-
- (*entry)->refcount++;
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value), entry,
- sizeof(zval *), NULL);
-
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos);
- }
-}
-/* }}} */
-
-
-/* {{{ proto array array_count_values(array input)
- Return the value as key and the frequency of that value in input as value */
-PHP_FUNCTION(array_count_values)
-{
- zval **input, /* Input array */
- **entry; /* An entry in the input array */
- zval **tmp;
- HashTable *myht;
- HashPosition pos;
-
- /* Get arguments and do error-checking */
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &input) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(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 = Z_ARRVAL_PP(input);
- zend_hash_internal_pointer_reset_ex(myht, &pos);
- while (zend_hash_get_current_data_ex(myht, (void **)&entry, &pos) == SUCCESS) {
- if (Z_TYPE_PP(entry) == IS_LONG) {
- if (zend_hash_index_find(Z_ARRVAL_P(return_value),
- Z_LVAL_PP(entry),
- (void**)&tmp) == FAILURE) {
- zval *data;
- MAKE_STD_ZVAL(data);
- Z_TYPE_P(data) = IS_LONG;
- Z_LVAL_P(data) = 1;
- zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
- } else {
- Z_LVAL_PP(tmp)++;
- }
- } else if (Z_TYPE_PP(entry) == IS_STRING) {
- if (zend_hash_find(Z_ARRVAL_P(return_value),
- Z_STRVAL_PP(entry),
- Z_STRLEN_PP(entry)+1,
- (void**)&tmp) == FAILURE) {
- zval *data;
- MAKE_STD_ZVAL(data);
- Z_TYPE_P(data) = IS_LONG;
- Z_LVAL_P(data) = 1;
- zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
- } else {
- Z_LVAL_PP(tmp)++;
- }
- } else {
- php_error(E_WARNING, "Can only count STRING and INTEGER values!");
- }
-
- zend_hash_move_forward_ex(myht, &pos);
- }
-}
-/* }}} */
-
-
-/* {{{ proto array array_reverse(array input [, bool preserve keys])
- Return input as a new array with the order of the entries reversed */
-PHP_FUNCTION(array_reverse)
-{
- zval **input, /* Input array */
- **z_preserve_keys, /* Flag: whether to preserve keys */
- **entry; /* An entry in the input array */
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- zend_bool preserve_keys = 0;
- HashPosition pos;
-
- /* Get arguments and do error-checking */
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &z_preserve_keys) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(E_WARNING, "Argument to array_reverse() should be an array");
- return;
- }
-
- if (ZEND_NUM_ARGS() > 1) {
- convert_to_boolean_ex(z_preserve_keys);
- preserve_keys = Z_BVAL_PP(z_preserve_keys);
- }
-
- /* Initialize return array */
- array_init(return_value);
-
- zend_hash_internal_pointer_end_ex(Z_ARRVAL_PP(input), &pos);
- while(zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS) {
- (*entry)->refcount++;
-
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) {
- case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key, string_key_len,
- entry, sizeof(zval *), NULL);
- break;
-
- case HASH_KEY_IS_LONG:
- if (preserve_keys)
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key,
- entry, sizeof(zval *), NULL);
- else
- zend_hash_next_index_insert(Z_ARRVAL_P(return_value),
- entry, sizeof(zval *), NULL);
- break;
- }
-
- zend_hash_move_backwards_ex(Z_ARRVAL_PP(input), &pos);
- }
-}
-/* }}} */
-
-
-/* {{{ proto array array_pad(array input, int pad_size, mixed pad_value)
- Returns a copy of input array padded with pad_value to size pad_size */
-PHP_FUNCTION(array_pad)
-{
- zval **input; /* Input array */
- zval **pad_size; /* Size to pad to */
- zval **pad_value; /* Padding value obviously */
- zval ***pads; /* Array to pass to splice */
- HashTable *new_hash; /* Return value from splice */
- int input_size; /* Size of the input array */
- int pad_size_abs; /* Absolute value of pad_size */
- int num_pads; /* How many pads do we need */
- int do_pad; /* Whether we should do padding at all */
- int i;
-
- /* Get arguments and do error-checking */
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &input, &pad_size, &pad_value) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- /* Make sure arguments are of the proper type */
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(E_WARNING, "Argument to %s() should be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
- convert_to_long_ex(pad_size);
-
- /* Do some initial calculations */
- input_size = zend_hash_num_elements(Z_ARRVAL_PP(input));
- pad_size_abs = abs(Z_LVAL_PP(pad_size));
- do_pad = (input_size >= pad_size_abs) ? 0 : 1;
-
- /* Copy the original array */
- *return_value = **input;
- zval_copy_ctor(return_value);
-
- /* If no need to pad, no need to continue */
- if (!do_pad)
- return;
-
- /* Populate the pads array */
- num_pads = pad_size_abs - input_size;
- pads = (zval ***)emalloc(num_pads * sizeof(zval **));
- for (i = 0; i < num_pads; i++)
- pads[i] = pad_value;
-
- /* Pad on the right or on the left */
- if (Z_LVAL_PP(pad_size) > 0)
- new_hash = php_splice(Z_ARRVAL_P(return_value), input_size, 0, pads, num_pads, NULL);
- else
- new_hash = php_splice(Z_ARRVAL_P(return_value), 0, 0, pads, num_pads, NULL);
-
-
- /* Copy the result hash into return value */
- zend_hash_destroy(Z_ARRVAL_P(return_value));
- efree(Z_ARRVAL_P(return_value));
- Z_ARRVAL_P(return_value) = new_hash;
-
- /* Clean up */
- efree(pads);
-}
-/* }}} */
-
-/* {{{ proto array array_flip(array input)
- Return array with key <-> value flipped */
-PHP_FUNCTION(array_flip)
-{
- zval **array, **entry, *data;
- HashTable *target_hash;
- char *string_key;
- ulong str_key_len;
- ulong num_key;
- HashPosition pos;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in array_flip() call");
- RETURN_FALSE;
- }
-
- array_init(return_value);
-
- zend_hash_internal_pointer_reset_ex(target_hash, &pos);
- while (zend_hash_get_current_data_ex(target_hash, (void **)&entry, &pos) == SUCCESS) {
- MAKE_STD_ZVAL(data);
- switch (zend_hash_get_current_key_ex(target_hash, &string_key, &str_key_len, &num_key, 1, &pos)) {
- case HASH_KEY_IS_STRING:
- Z_STRVAL_P(data) = string_key;
- Z_STRLEN_P(data) = str_key_len-1;
- Z_TYPE_P(data) = IS_STRING;
- break;
- case HASH_KEY_IS_LONG:
- Z_TYPE_P(data) = IS_LONG;
- Z_LVAL_P(data) = num_key;
- break;
- }
-
- if (Z_TYPE_PP(entry) == IS_LONG) {
- zend_hash_index_update(Z_ARRVAL_P(return_value), Z_LVAL_PP(entry), &data, sizeof(data), NULL);
- } else if (Z_TYPE_PP(entry) == IS_STRING) {
- zend_hash_update(Z_ARRVAL_P(return_value), Z_STRVAL_PP(entry), Z_STRLEN_PP(entry) + 1, &data, sizeof(data), NULL);
- } else {
- zval_ptr_dtor(&data); /* will free also zval structure */
- php_error(E_WARNING, "Can only flip STRING and INTEGER values!");
- }
-
- zend_hash_move_forward_ex(target_hash, &pos);
- }
-}
-/* }}} */
-
-/* {{{ proto array array_unique(array input)
- Removes duplicate values from array */
-PHP_FUNCTION(array_unique)
-{
- zval **array;
- HashTable *target_hash;
- Bucket **arTmp, **cmpdata, **lastkept;
- Bucket *p;
- int i;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- target_hash = HASH_OF(*array);
- if (!target_hash) {
- php_error(E_WARNING, "Wrong datatype in array_unique() call");
- RETURN_FALSE;
- }
-
- /* copy the argument array */
- *return_value = **array;
- zval_copy_ctor(return_value);
-
- if (target_hash->nNumOfElements <= 1) /* nothing to do */
- return;
-
- /* create and sort array with pointers to the target_hash buckets */
- arTmp = (Bucket **) pemalloc((target_hash->nNumOfElements + 1) * sizeof(Bucket *), target_hash->persistent);
- if (!arTmp)
- RETURN_FALSE;
- for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext)
- arTmp[i] = p;
- arTmp[i] = NULL;
- set_compare_func(SORT_STRING TSRMLS_CC);
- qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare);
-
- /* go through the sorted array and delete duplicates from the copy */
- lastkept = arTmp;
- for (cmpdata = arTmp + 1; *cmpdata; cmpdata++) {
- if (array_data_compare(lastkept, cmpdata)) {
- lastkept = cmpdata;
- } else {
- p = *cmpdata;
- if (p->nKeyLength)
- zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength);
- else
- zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
- }
- }
- pefree(arTmp, target_hash->persistent);
-}
-/* }}} */
-
-/* {{{ proto array array_intersect(array arr1, array arr2 [, array ...])
- Returns the entries of arr1 that have values which are present in all the other arguments */
-PHP_FUNCTION(array_intersect)
-{
- zval ***args = NULL;
- HashTable *hash;
- int argc, i, c = 0;
- Bucket ***lists, **list, ***ptrs, *p;
-
- /* 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 (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
- /* for each argument, create and sort list with pointers to the hash buckets */
- lists = (Bucket ***)emalloc(argc * sizeof(Bucket **));
- ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **));
- set_compare_func(SORT_STRING TSRMLS_CC);
- for (i=0; i<argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
- php_error(E_WARNING, "Argument #%d to array_intersect() is not an array", i+1);
- argc = i; /* only free up to i-1 */
- goto out;
- }
- hash = HASH_OF(*args[i]);
- list = (Bucket **) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket *), hash->persistent);
- if (!list)
- RETURN_FALSE;
- lists[i] = list;
- ptrs[i] = list;
- for (p = hash->pListHead; p; p = p->pListNext)
- *list++ = p;
- *list = NULL;
- qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare);
- }
-
- /* copy the argument array */
- *return_value = **args[0];
- zval_copy_ctor(return_value);
-
- /* go through the lists and look for common values */
- while (*ptrs[0]) {
- for (i=1; i<argc; i++) {
- while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i]))))
- ptrs[i]++;
- if (!*ptrs[i]) {
- /* delete any values corresponding to remains of ptrs[0] */
- /* and exit */
- for (;;) {
- p = *ptrs[0]++;
- if (!p)
- goto out;
- if (p->nKeyLength)
- zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength);
- else
- zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
- }
- }
- if (c)
- break;
- ptrs[i]++;
- }
- if (c) {
- /* Value of ptrs[0] not in all arguments, delete all entries */
- /* with value < value of ptrs[i] */
- for (;;) {
- p = *ptrs[0];
- if (p->nKeyLength)
- zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength);
- else
- zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
- if (!*++ptrs[0])
- goto out;
- if (0 <= array_data_compare(ptrs[0], ptrs[i]))
- break;
- }
- } else {
- /* ptrs[0] is present in all the arguments */
- /* Skip all entries with same value as ptrs[0] */
- for (;;) {
- if (!*++ptrs[0])
- goto out;
- if (array_data_compare(ptrs[0]-1, ptrs[0]))
- break;
- }
- }
- }
-
-out:
- for (i=0; i<argc; i++) {
- hash = HASH_OF(*args[i]);
- pefree(lists[i], hash->persistent);
- }
- efree(ptrs);
- efree(lists);
- efree(args);
-}
-/* }}} */
-
-/* {{{ proto array array_diff(array arr1, array arr2 [, array ...])
- Returns the entries of arr1 that have values which are not present in any of the others arguments */
-PHP_FUNCTION(array_diff)
-{
- zval ***args = NULL;
- HashTable *hash;
- int argc, i, c;
- Bucket ***lists, **list, ***ptrs, *p;
-
- /* 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 (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
- /* for each argument, create and sort list with pointers to the hash buckets */
- lists = (Bucket ***)emalloc(argc * sizeof(Bucket **));
- ptrs = (Bucket ***)emalloc(argc * sizeof(Bucket **));
- set_compare_func(SORT_STRING TSRMLS_CC);
- for (i=0; i<argc; i++) {
- if (Z_TYPE_PP(args[i]) != IS_ARRAY) {
- php_error(E_WARNING, "Argument #%d to array_diff() is not an array", i+1);
- argc = i; /* only free up to i-1 */
- goto out;
- }
- hash = HASH_OF(*args[i]);
- list = (Bucket **) pemalloc((hash->nNumOfElements + 1) * sizeof(Bucket *), hash->persistent);
- if (!list)
- RETURN_FALSE;
- lists[i] = list;
- ptrs[i] = list;
- for (p = hash->pListHead; p; p = p->pListNext)
- *list++ = p;
- *list = NULL;
- qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare);
- }
-
- /* copy the argument array */
- *return_value = **args[0];
- zval_copy_ctor(return_value);
-
- /* go through the lists and look for values of ptr[0]
- that are not in the others */
- while (*ptrs[0]) {
- c = 1;
- for (i=1; i<argc; i++) {
- while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i]))))
- ptrs[i]++;
- if (!c) {
- if (*ptrs[i])
- ptrs[i]++;
- break;
- }
- }
- if (!c) {
- /* ptrs[0] in one of the other arguments */
- /* delete all entries with value as ptrs[0] */
- for (;;) {
- p = *ptrs[0];
- if (p->nKeyLength)
- zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength);
- else
- zend_hash_index_del(Z_ARRVAL_P(return_value), p->h);
- if (!*++ptrs[0])
- goto out;
- if (array_data_compare(ptrs[0]-1, ptrs[0]))
- break;
- }
- } else {
- /* ptrs[0] in none of the other arguments */
- /* skip all entries with value as ptrs[0] */
- for (;;) {
- if (!*++ptrs[0])
- goto out;
- if (array_data_compare(ptrs[0]-1, ptrs[0]))
- break;
- }
- }
- }
-out:
- for (i=0; i<argc; i++) {
- hash = HASH_OF(*args[i]);
- pefree(lists[i], hash->persistent);
- }
- efree(ptrs);
- efree(lists);
- efree(args);
-}
-/* }}} */
-
-#define MULTISORT_ORDER 0
-#define MULTISORT_TYPE 1
-#define MULTISORT_LAST 2
-
-int multisort_compare(const void *a, const void *b)
-{
- Bucket** ab = *(Bucket ***)a;
- Bucket** bb = *(Bucket ***)b;
- int r;
- int result = 0;
- zval temp;
- TSRMLS_FETCH();
-
- r = 0;
- do {
- set_compare_func(ARRAYG(multisort_flags)[MULTISORT_TYPE][r] TSRMLS_CC);
-
- ARRAYG(compare_func)(&temp, *((zval **)ab[r]->pData), *((zval **)bb[r]->pData) TSRMLS_CC);
- result = ARRAYG(multisort_flags)[MULTISORT_ORDER][r] * Z_LVAL(temp);
- if (result != 0)
- return result;
- r++;
- } while (ab[r] != NULL);
- return result;
-}
-
-#define MULTISORT_ABORT \
- for (k = 0; k < MULTISORT_LAST; k++) \
- efree(ARRAYG(multisort_flags)[k]); \
- efree(arrays); \
- efree(args); \
- RETURN_FALSE;
-
-/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING]], ...])
- Sort multiple arrays at once similar to how ORDER BY clause works in SQL */
-PHP_FUNCTION(array_multisort)
-{
- zval*** args;
- zval*** arrays;
- Bucket*** indirect;
- Bucket* p;
- HashTable* hash;
- int argc;
- int array_size;
- int num_arrays = 0;
- int parse_state[MULTISORT_LAST]; /* 0 - flag not allowed
- 1 - flag allowed */
- int sort_order = SORT_ASC;
- int sort_type = SORT_REGULAR;
- int i, k;
-
- /* Get the argument count and check it */
- argc = ZEND_NUM_ARGS();
- if (argc < 1) {
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate arguments array and get the arguments, checking for errors. */
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- /* Allocate space for storing pointers to input arrays and sort flags. */
- arrays = (zval ***)ecalloc(argc, sizeof(zval **));
- for (i = 0; i < MULTISORT_LAST; i++) {
- parse_state[i] = 0;
- ARRAYG(multisort_flags)[i] = (int *)ecalloc(argc, sizeof(int));
- }
-
- /* Here we go through the input arguments and parse them. Each one can
- be either an array or a sort flag which follows an array. If not
- specified, the sort flags defaults to SORT_ASC and SORT_REGULAR
- accordingly. There can't be two sort flags of the same type after an
- array, and the very first argument has to be an array.
- */
- for (i = 0; i < argc; i++) {
- if (Z_TYPE_PP(args[i]) == IS_ARRAY) {
- /* We see the next array, so we update the sort flags of
- the previous array and reset the sort flags. */
- if (i > 0) {
- ARRAYG(multisort_flags)[MULTISORT_ORDER][num_arrays-1] = sort_order;
- ARRAYG(multisort_flags)[MULTISORT_TYPE][num_arrays-1] = sort_type;
- sort_order = SORT_ASC;
- sort_type = SORT_REGULAR;
- }
- arrays[num_arrays++] = args[i];
-
- /* Next one may be an array or a list of sort flags. */
- for (k = 0; k < MULTISORT_LAST; k++)
- parse_state[k] = 1;
- } else if (Z_TYPE_PP(args[i]) == IS_LONG) {
- switch (Z_LVAL_PP(args[i])) {
- case SORT_ASC:
- case SORT_DESC:
- /* flag allowed here */
- if (parse_state[MULTISORT_ORDER] == 1) {
- /* Save the flag and make sure then next arg is not the current flag. */
- sort_order = Z_LVAL_PP(args[i]) == SORT_DESC ? -1 : 1;
- parse_state[MULTISORT_ORDER] = 0;
- } else {
- php_error(E_WARNING, "Argument %i to %s() is expected to be an array or sorting flag that has not already been specified", i+1, get_active_function_name(TSRMLS_C));
- MULTISORT_ABORT;
- }
- break;
-
- case SORT_REGULAR:
- case SORT_NUMERIC:
- case SORT_STRING:
- /* flag allowed here */
- if (parse_state[MULTISORT_TYPE] == 1) {
- /* Save the flag and make sure then next arg is not the current flag. */
- sort_type = Z_LVAL_PP(args[i]);
- parse_state[MULTISORT_TYPE] = 0;
- } else {
- php_error(E_WARNING, "Argument %i to %s() is expected to be an array or sorting flag that has not already been specified", i+1, get_active_function_name(TSRMLS_C));
- MULTISORT_ABORT;
- }
- break;
-
- default:
- php_error(E_WARNING, "Argument %i to %s() is an unknown sort flag", i+1,
- get_active_function_name(TSRMLS_C));
- MULTISORT_ABORT;
- break;
-
- }
- } else {
- php_error(E_WARNING, "Argument %i to %s() is expected to be an array or a sort flag", i+1, get_active_function_name(TSRMLS_C));
- MULTISORT_ABORT;
- }
- }
- /* Take care of the last array sort flags. */
- ARRAYG(multisort_flags)[MULTISORT_ORDER][num_arrays-1] = sort_order;
- ARRAYG(multisort_flags)[MULTISORT_TYPE][num_arrays-1] = sort_type;
-
- /* Make sure the arrays are of the same size. */
- array_size = zend_hash_num_elements(Z_ARRVAL_PP(arrays[0]));
- for (i = 0; i < num_arrays; i++) {
- if (zend_hash_num_elements(Z_ARRVAL_PP(arrays[i])) != array_size) {
- php_error(E_WARNING, "Array sizes are inconsistent");
- MULTISORT_ABORT;
- }
- }
-
- /* If all arrays are empty or have only one entry,
- we don't need to do anything. */
- if (array_size <= 1) {
- for (k = 0; k < MULTISORT_LAST; k++)
- efree(ARRAYG(multisort_flags)[k]);
- efree(arrays);
- efree(args);
- RETURN_TRUE;
- }
-
- /* Create the indirection array. This array is of size MxN, where
- M is the number of entries in each input array and N is the number
- of the input arrays + 1. The last column is NULL to indicate the end
- of the row.
- */
- indirect = (Bucket ***)emalloc(array_size * sizeof(Bucket **));
- for (i = 0; i < array_size; i++)
- indirect[i] = (Bucket **)emalloc((num_arrays+1) * sizeof(Bucket *));
-
- for (i = 0; i < num_arrays; i++) {
- k = 0;
- for (p = Z_ARRVAL_PP(arrays[i])->pListHead; p; p = p->pListNext, k++) {
- indirect[k][i] = p;
- }
- }
- for (k = 0; k < array_size; k++)
- indirect[k][num_arrays] = NULL;
-
- /* Do the actual sort magic - bada-bim, bada-boom. */
- qsort(indirect, array_size, sizeof(Bucket **), multisort_compare);
-
- /* Restructure the arrays based on sorted indirect - this is mostly
- taken from zend_hash_sort() function. */
- HANDLE_BLOCK_INTERRUPTIONS();
- for (i = 0; i < num_arrays; i++) {
- hash = Z_ARRVAL_PP(arrays[i]);
- hash->pListHead = indirect[0][i];;
- hash->pListTail = NULL;
- hash->pInternalPointer = hash->pListHead;
-
- for (k = 0; k < array_size; k++) {
- if (hash->pListTail) {
- hash->pListTail->pListNext = indirect[k][i];
- }
- indirect[k][i]->pListLast = hash->pListTail;
- indirect[k][i]->pListNext = NULL;
- hash->pListTail = indirect[k][i];
- }
-
- p = hash->pListHead;
- k = 0;
- while (p != NULL) {
- if (p->nKeyLength == 0)
- p->h = k++;
- p = p->pListNext;
- }
- hash->nNextFreeElement = array_size;
- zend_hash_rehash(hash);
- }
- HANDLE_UNBLOCK_INTERRUPTIONS();
-
- /* Clean up. */
- for (i = 0; i < array_size; i++)
- efree(indirect[i]);
- efree(indirect);
- for (k = 0; k < MULTISORT_LAST; k++)
- efree(ARRAYG(multisort_flags)[k]);
- efree(arrays);
- efree(args);
- RETURN_TRUE;
-}
-/* }}} */
-
-
-/* {{{ proto mixed array_rand(array input [, int num_req])
- Return key/keys for random entry/entries in the array */
-PHP_FUNCTION(array_rand)
-{
- zval **input, **num_req;
- long randval;
- int num_req_val, num_avail, key_type;
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- HashPosition pos;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &num_req) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- zend_error(E_WARNING, "Argument to %s() has to be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- num_avail = zend_hash_num_elements(Z_ARRVAL_PP(input));
-
- if (ZEND_NUM_ARGS() > 1) {
- convert_to_long_ex(num_req);
- num_req_val = Z_LVAL_PP(num_req);
- if (num_req_val <= 0 || num_req_val > num_avail) {
- zend_error(E_WARNING, "Second argument to %s() has to be between 1 and the number of elements in the array", get_active_function_name(TSRMLS_C));
- return;
- }
- } else
- num_req_val = 1;
-
- /* Make the return value an array only if we need to pass back more than one
- result. */
- if (num_req_val > 1)
- array_init(return_value);
-
- /* We can't use zend_hash_index_find() because the array may have string keys or gaps. */
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
- while (num_req_val && (key_type = zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTANT) {
-
-#ifdef HAVE_RANDOM
- randval = random();
-#else
-#ifdef HAVE_LRAND48
- randval = lrand48();
-#else
- randval = rand();
-#endif
-#endif
-
- if ((double)(randval/(PHP_RAND_MAX+1.0)) < (double)num_req_val/(double)num_avail) {
- /* If we are returning a single result, just do it. */
- if (Z_TYPE_P(return_value) != IS_ARRAY) {
- if (key_type == HASH_KEY_IS_STRING) {
- RETURN_STRINGL(string_key, string_key_len-1, 1);
- } else {
- RETURN_LONG(num_key);
- }
- } else {
- /* Append the result to the return value. */
- if (key_type == HASH_KEY_IS_STRING)
- add_next_index_stringl(return_value, string_key, string_key_len-1, 1);
- else
- add_next_index_long(return_value, num_key);
- }
- num_req_val--;
- }
- num_avail--;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos);
- }
-
- if (num_req_val == num_avail) {
- if (zend_hash_sort(Z_ARRVAL_P(return_value), (sort_func_t)php_mergesort, array_data_shuffle, 1) == FAILURE) {
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-
-/* {{{ proto mixed array_sum(array input)
- Returns the sum of the array entries */
-
-PHP_FUNCTION(array_sum)
-{
- zval **input,
- **entry;
- int argc = ZEND_NUM_ARGS();
- HashPosition pos;
- double dval;
-
- if (argc != 1 || zend_get_parameters_ex(argc, &input) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(E_WARNING, "The argument to %s() should be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- ZVAL_LONG(return_value, 0);
-
- for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&entry, &pos) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) {
-
- if (Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT)
- continue;
-
- SEPARATE_ZVAL(entry);
- convert_scalar_to_number(*entry TSRMLS_CC);
-
- if (Z_TYPE_PP(entry) == IS_LONG && Z_TYPE_P(return_value) == IS_LONG) {
- dval = (double)Z_LVAL_P(return_value) + (double)Z_LVAL_PP(entry);
- if ( (double)LONG_MIN <= dval && dval <= (double)LONG_MAX ) {
- Z_LVAL_P(return_value) += Z_LVAL_PP(entry);
- continue;
- }
- }
- convert_to_double(return_value);
- convert_to_double_ex(entry);
- Z_DVAL_P(return_value) += Z_DVAL_PP(entry);
- }
-}
-
-/* }}} */
-
-/* {{{ proto mixed array_reduce(array input, mixed callback [, int initial])
- Iteratively reduce the array to a single value via the callback. */
-PHP_FUNCTION(array_reduce)
-{
- zval **input, **callback, **initial;
- zval **args[2];
- zval **operand;
- zval *result = NULL;
- zval *retval;
- char *callback_name;
- HashPosition pos;
-
- if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &callback, &initial) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(E_WARNING, "%s() expects argument 1 to be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- if (!zend_is_callable(*callback, 0, &callback_name)) {
- php_error(E_WARNING, "%s() expects argument 2, '%s', to be a valid callback",
- get_active_function_name(TSRMLS_C), callback_name);
- efree(callback_name);
- return;
- }
- efree(callback_name);
-
- if (ZEND_NUM_ARGS() > 2) {
- result = *initial;
- zval_add_ref(&result);
- }
-
- if (zend_hash_num_elements(Z_ARRVAL_PP(input)) == 0) {
- if (result) {
- *return_value = *result;
- zval_copy_ctor(return_value);
- }
- return;
- }
-
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&operand, &pos) == SUCCESS) {
- if (result) {
- args[0] = &result;
- args[1] = operand;
- if (call_user_function_ex(EG(function_table), NULL, *callback, &retval, 2, args, 0, NULL TSRMLS_CC) == SUCCESS && retval) {
- zval_ptr_dtor(&result);
- result = retval;
- } else {
- php_error(E_WARNING, "%s() had an error invoking the reduction callback", get_active_function_name(TSRMLS_C));
- return;
- }
- } else {
- result = *operand;
- zval_add_ref(&result);
- }
-
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos);
- }
-
- *return_value = *result;
- zval_copy_ctor(return_value);
- zval_ptr_dtor(&result);
-}
-/* }}} */
-
-
-/* {{{ proto array array_filter(array input [, mixed callback])
- Filters elements from the array via the callback. */
-PHP_FUNCTION(array_filter)
-{
- zval **input, **callback = NULL;
- zval **operand;
- zval **args[1];
- zval *retval = NULL;
- char *callback_name;
- char *string_key;
- ulong string_key_len;
- ulong num_key;
- HashPosition pos;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &callback) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(input) != IS_ARRAY) {
- php_error(E_WARNING, "%s() expects argument 1 to be an array",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- if (ZEND_NUM_ARGS() > 1) {
- if (!zend_is_callable(*callback, 0, &callback_name)) {
- php_error(E_WARNING, "%s() expects argument 2, '%s', to be a valid callback",
- get_active_function_name(TSRMLS_C), callback_name);
- efree(callback_name);
- return;
- }
- efree(callback_name);
- }
-
- array_init(return_value);
- if (zend_hash_num_elements(Z_ARRVAL_PP(input)) == 0)
- return;
-
- for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(input), &pos);
- zend_hash_get_current_data_ex(Z_ARRVAL_PP(input), (void **)&operand, &pos) == SUCCESS;
- zend_hash_move_forward_ex(Z_ARRVAL_PP(input), &pos)) {
-
- if (callback) {
- args[0] = operand;
- if (call_user_function_ex(EG(function_table), NULL, *callback, &retval, 1, args, 0, NULL TSRMLS_CC) == SUCCESS && retval) {
- if (!zend_is_true(retval)) {
- zval_ptr_dtor(&retval);
- continue;
- } else
- zval_ptr_dtor(&retval);
- } else {
- php_error(E_WARNING, "%s() had an error invoking the filter callback", get_active_function_name(TSRMLS_C));
- return;
- }
- } else if (!zend_is_true(*operand))
- continue;
-
- zval_add_ref(operand);
- switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(input), &string_key, &string_key_len, &num_key, 0, &pos)) {
- case HASH_KEY_IS_STRING:
- zend_hash_update(Z_ARRVAL_P(return_value), string_key,
- string_key_len, operand, sizeof(zval *), NULL);
- break;
-
- case HASH_KEY_IS_LONG:
- zend_hash_index_update(Z_ARRVAL_P(return_value), num_key,
- operand, sizeof(zval *), NULL);
- break;
- }
- }
-}
-/* }}} */
-
-
-/* {{{ proto array array_map(mixed callback, array input1 [, array input2 ,...])
- Applies the callback to the elements in given arrays. */
-PHP_FUNCTION(array_map)
-{
- zval ***args = NULL;
- zval ***params;
- zval *callback;
- zval *result, *null;
- char *callback_name;
- int i, k, maxlen = 0;
- int *array_len;
-
- if (ZEND_NUM_ARGS() < 2) {
- WRONG_PARAM_COUNT;
- }
-
- args = (zval ***)emalloc(ZEND_NUM_ARGS() * sizeof(zval **));
- if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- callback = *args[0];
- if (Z_TYPE_P(callback) != IS_NULL) {
- if (!zend_is_callable(callback, 0, &callback_name)) {
- php_error(E_WARNING, "%s() expects argument 1, '%s', to be either NULL or a valid callback", get_active_function_name(TSRMLS_C), callback_name);
- efree(callback_name);
- efree(args);
- return;
- }
- efree(callback_name);
- }
-
- /* Cache array sizes. */
- array_len = (int*)emalloc((ZEND_NUM_ARGS()-1) * sizeof(int));
-
- /* Check that arrays are indeed arrays and calculate maximum size. */
- for (i = 0; i < ZEND_NUM_ARGS()-1; i++) {
- if (Z_TYPE_PP(args[i+1]) != IS_ARRAY) {
- php_error(E_WARNING, "%s() expects argument %d to be an array",
- get_active_function_name(TSRMLS_C), i + 2);
- efree(array_len);
- efree(args);
- return;
- }
- array_len[i] = zend_hash_num_elements(Z_ARRVAL_PP(args[i+1]));
- if (array_len[i] > maxlen)
- maxlen = array_len[i];
- }
-
- /* Short-circuit: if no callback and only one array, just return it. */
- if (Z_TYPE_P(callback) == IS_NULL && ZEND_NUM_ARGS() == 2) {
- *return_value = **args[1];
- zval_copy_ctor(return_value);
- efree(array_len);
- efree(args);
- return;
- }
-
- array_init(return_value);
- params = (zval ***)emalloc((ZEND_NUM_ARGS()-1) * sizeof(zval **));
- MAKE_STD_ZVAL(null);
- ZVAL_NULL(null);
-
- /* We iterate through all the arrays at once. */
- for (k = 0; k < maxlen; k++) {
- /*
- * If no callback, the result will be an array, consisting of current
- * entries from all arrays.
- */
- if (Z_TYPE_P(callback) == IS_NULL) {
- MAKE_STD_ZVAL(result);
- array_init(result);
- }
-
- for (i = 0; i < ZEND_NUM_ARGS()-1; i++) {
- /*
- * If this array still hash elements, add the current one to the
- * parameter list, otherwise use null value.
- */
- if (k < array_len[i]) {
- zend_hash_index_find(Z_ARRVAL_PP(args[i+1]), k, (void **)&params[i]);
- } else {
- if (Z_TYPE_P(callback) == IS_NULL)
- zval_add_ref(&null);
- params[i] = &null;
- }
-
- if (Z_TYPE_P(callback) == IS_NULL)
- add_next_index_zval(result, *params[i]);
- }
-
- if (Z_TYPE_P(callback) != IS_NULL) {
- if (!call_user_function_ex(EG(function_table), NULL, callback, &result, ZEND_NUM_ARGS()-1, params, 0, NULL TSRMLS_CC) == SUCCESS && result) {
- php_error(E_WARNING, "%s() had an error invoking the map callback", get_active_function_name(TSRMLS_C));
- efree(array_len);
- efree(args);
- zval_dtor(return_value);
- RETURN_NULL();
- }
- }
-
- add_next_index_zval(return_value, result);
- }
-
- zval_ptr_dtor(&null);
- efree(params);
- efree(array_len);
- efree(args);
-}
-/* }}} */
-
-
-/* {{{ proto bool key_exists(mixed key, array search)
- Checks if the given key or index exists in the array */
-PHP_FUNCTION(key_exists)
-{
- zval **key, /* key to check for */
- **array; /* array to check in */
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &key, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(array) != IS_ARRAY && Z_TYPE_PP(array) != IS_OBJECT) {
- php_error(E_WARNING, "Wrong datatype for second argument in call to %s", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
-
- switch (Z_TYPE_PP(key)) {
- case IS_STRING:
- if (zend_hash_exists(HASH_OF(*array), Z_STRVAL_PP(key), Z_STRLEN_PP(key)+1)) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
-
- case IS_LONG:
- if (zend_hash_index_exists(HASH_OF(*array), Z_LVAL_PP(key))) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
-
- default:
- php_error(E_WARNING, "Wrong datatype for first argument in call to %s", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
- }
-
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/assert.c b/ext/standard/assert.c
deleted file mode 100644
index 05addfbdea..0000000000
--- a/ext/standard/assert.c
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/* {{{ includes/startup/misc */
-
-#include "php.h"
-#include "php_assert.h"
-#include "php_ini.h"
-
-typedef struct {
- long active;
- long bail;
- long warning;
- long quiet_eval;
- zval *callback;
-} php_assert_globals;
-
-#ifdef ZTS
-#define ASSERTG(v) TSRMG(assert_globals_id, php_assert_globals *, v)
-int assert_globals_id;
-#else
-#define ASSERTG(v) (assert_globals.v)
-php_assert_globals assert_globals;
-#endif
-
-#define SAFE_STRING(s) ((s)?(s):"")
-
-enum {
- ASSERT_ACTIVE=1,
- ASSERT_CALLBACK,
- ASSERT_BAIL,
- ASSERT_WARNING,
- ASSERT_QUIET_EVAL
-};
-
-static PHP_INI_MH(OnChangeCallback)
-{
- if (ASSERTG(callback)) {
- zval_ptr_dtor(&ASSERTG(callback));
- }
-
- MAKE_STD_ZVAL(ASSERTG(callback));
-
- if (new_value) {
- ZVAL_STRINGL(ASSERTG(callback), new_value, new_value_length, 1);
- } else {
- ZVAL_EMPTY_STRING(ASSERTG(callback));
- }
-
- return SUCCESS;
-}
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("assert.active", "1", PHP_INI_ALL, OnUpdateInt, active, php_assert_globals, assert_globals)
- STD_PHP_INI_ENTRY("assert.bail", "0", PHP_INI_ALL, OnUpdateInt, bail, php_assert_globals, assert_globals)
- STD_PHP_INI_ENTRY("assert.warning", "1", PHP_INI_ALL, OnUpdateInt, warning, php_assert_globals, assert_globals)
- PHP_INI_ENTRY ("assert.callback", NULL, PHP_INI_ALL, OnChangeCallback)
- STD_PHP_INI_ENTRY("assert.quiet_eval", "0", PHP_INI_ALL, OnUpdateInt, quiet_eval, php_assert_globals, assert_globals)
-PHP_INI_END()
-
-static void php_assert_init_globals(php_assert_globals *assert_globals_p TSRMLS_DC)
-{
- ASSERTG(callback) = NULL;
-}
-
-PHP_MINIT_FUNCTION(assert)
-{
-#ifdef ZTS
- ts_allocate_id(&assert_globals_id, sizeof(php_assert_globals), (ts_allocate_ctor) php_assert_init_globals, NULL);
-#else
- php_assert_init_globals(&assert_globals TSRMLS_CC);
-#endif
-
- REGISTER_INI_ENTRIES();
-
- REGISTER_LONG_CONSTANT("ASSERT_ACTIVE", ASSERT_ACTIVE, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ASSERT_CALLBACK", ASSERT_CALLBACK, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ASSERT_BAIL", ASSERT_BAIL, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ASSERT_WARNING", ASSERT_WARNING, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ASSERT_QUIET_EVAL", ASSERT_QUIET_EVAL, CONST_CS|CONST_PERSISTENT);
-
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(assert)
-{
- if (ASSERTG(callback)) {
- zval_ptr_dtor(&ASSERTG(callback));
- }
- return SUCCESS;
-}
-
-PHP_RSHUTDOWN_FUNCTION(assert)
-{
- if (ASSERTG(callback)) {
- zval_ptr_dtor(&ASSERTG(callback));
- ASSERTG(callback) = NULL;
- }
-
- return SUCCESS;
-}
-
-PHP_MINFO_FUNCTION(assert)
-{
- DISPLAY_INI_ENTRIES();
-}
-
-/* }}} */
-/* {{{ internal functions */
-/* }}} */
-/* {{{ proto int assert(string|bool assertion)
- Checks if assertion is false */
-
-PHP_FUNCTION(assert)
-{
- zval **assertion;
- int val;
- char *myeval = NULL;
- char *compiled_string_description;
-
- if (! ASSERTG(active)) {
- RETURN_TRUE;
- }
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &assertion) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if ((*assertion)->type == IS_STRING) {
- zval retval;
- int old_error_reporting = 0; /* shut up gcc! */
-
- myeval = Z_STRVAL_PP(assertion);
-
- if (ASSERTG(quiet_eval)) {
- old_error_reporting = EG(error_reporting);
- EG(error_reporting) = 0;
- }
-
- compiled_string_description = zend_make_compiled_string_description("assert code" TSRMLS_CC);
- if (zend_eval_string(myeval, &retval, compiled_string_description TSRMLS_CC) == FAILURE) {
- efree(compiled_string_description);
- zend_error(E_ERROR, "Failure evaluating code:\n%s\n", myeval);
- /* zend_error() does not return in this case. */
- }
- efree(compiled_string_description);
-
- if (ASSERTG(quiet_eval)) {
- EG(error_reporting) = old_error_reporting;
- }
-
- convert_to_boolean(&retval);
- val = Z_LVAL(retval);
- } else {
- convert_to_boolean_ex(assertion);
- val = Z_LVAL_PP(assertion);
- }
-
- if (val) {
- RETURN_TRUE;
- }
-
- if (ASSERTG(callback)) {
- zval *args[4];
- zval *retval;
- int i;
- uint lineno = zend_get_executed_lineno(TSRMLS_C);
- char *filename = zend_get_executed_filename(TSRMLS_C);
-
- MAKE_STD_ZVAL(args[0]);
- MAKE_STD_ZVAL(args[1]);
- MAKE_STD_ZVAL(args[2]);
-
- ZVAL_STRING(args[0], SAFE_STRING(filename), 1);
- ZVAL_LONG (args[1], lineno);
- ZVAL_STRING(args[2], SAFE_STRING(myeval), 1);
-
- MAKE_STD_ZVAL(retval);
- ZVAL_FALSE(retval);
-
- /* XXX do we want to check for error here? */
- call_user_function(CG(function_table), NULL, ASSERTG(callback), retval, 3, args TSRMLS_CC);
-
- for (i = 0; i <= 2; i++) {
- zval_ptr_dtor(&(args[i]));
- }
- zval_ptr_dtor(&retval);
- }
-
- if (ASSERTG(warning)) {
- if (myeval) {
- php_error(E_WARNING, "Assertion \"%s\" failed", myeval);
- } else {
- php_error(E_WARNING, "Assertion failed");
- }
- }
-
- if (ASSERTG(bail)) {
- zend_bailout();
- }
-}
-
-/* }}} */
-/* {{{ proto mixed assert_options(int what [, mixed value])
- Set/get the various assert flags */
-
-PHP_FUNCTION(assert_options)
-{
- pval **what, **value;
- int oldint;
- int ac = ZEND_NUM_ARGS();
-
- if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &what, &value) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(what);
-
- switch ((*what)->value.lval) {
- case ASSERT_ACTIVE:
- oldint = ASSERTG(active);
- if (ac == 2) {
- convert_to_long_ex(value);
- ASSERTG(active) = Z_LVAL_PP(value);
- }
- RETURN_LONG(oldint);
- break;
-
- case ASSERT_BAIL:
- oldint = ASSERTG(bail);
- if (ac == 2) {
- convert_to_long_ex(value);
- ASSERTG(bail) = Z_LVAL_PP(value);
- }
- RETURN_LONG(oldint);
- break;
-
- case ASSERT_QUIET_EVAL:
- oldint = ASSERTG(quiet_eval);
- if (ac == 2) {
- convert_to_long_ex(value);
- ASSERTG(quiet_eval) = Z_LVAL_PP(value);
- }
- RETURN_LONG(oldint);
- break;
-
- case ASSERT_WARNING:
- oldint = ASSERTG(warning);
- if (ac == 2) {
- convert_to_long_ex(value);
- ASSERTG(warning) = Z_LVAL_PP(value);
- }
- RETURN_LONG(oldint);
- break;
-
- case ASSERT_CALLBACK:
- if (ac == 2) {
- if (ASSERTG(callback)) {
- zval_ptr_dtor(&ASSERTG(callback));
- }
- ASSERTG(callback) = *value;
- zval_add_ref(value);
- }
- RETURN_TRUE;
- break;
-
- default:
- php_error(E_WARNING, "Unknown value %d.", Z_LVAL_PP(what));
- break;
- }
-
- RETURN_FALSE;
-}
-
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/base64.c b/ext/standard/base64.c
deleted file mode 100644
index acc12d7e44..0000000000
--- a/ext/standard/base64.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jim Winstead (jimw@php.net) |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <string.h>
-
-#include "php.h"
-#include "base64.h"
-
-static char base64_table[] =
- { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
- };
-static char base64_pad = '=';
-
-unsigned char *php_base64_encode(const unsigned char *str, int length, int *ret_length) {
- const unsigned char *current = str;
- int i = 0;
- unsigned char *result = (unsigned char *)emalloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
-
- while (length > 2) { /* keep going until we have less than 24 bits */
- result[i++] = base64_table[current[0] >> 2];
- result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
- result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
- result[i++] = base64_table[current[2] & 0x3f];
-
- current += 3;
- length -= 3; /* we just handle 3 octets of data */
- }
-
- /* now deal with the tail end of things */
- if (length != 0) {
- result[i++] = base64_table[current[0] >> 2];
- if (length > 1) {
- result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
- result[i++] = base64_table[(current[1] & 0x0f) << 2];
- result[i++] = base64_pad;
- }
- else {
- result[i++] = base64_table[(current[0] & 0x03) << 4];
- result[i++] = base64_pad;
- result[i++] = base64_pad;
- }
- }
- if(ret_length) {
- *ret_length = i;
- }
- result[i] = '\0';
- return result;
-}
-
-/* as above, but backwards. :) */
-unsigned char *php_base64_decode(const unsigned char *str, int length, int *ret_length) {
- const unsigned char *current = str;
- int ch, i = 0, j = 0, k;
- /* this sucks for threaded environments */
- static short reverse_table[256];
- static int table_built;
- unsigned char *result;
-
- if (++table_built == 1) {
- char *chp;
- for(ch = 0; ch < 256; ch++) {
- chp = strchr(base64_table, ch);
- if(chp) {
- reverse_table[ch] = chp - base64_table;
- } else {
- reverse_table[ch] = -1;
- }
- }
- }
-
- result = (unsigned char *)emalloc(length + 1);
- if (result == NULL) {
- return NULL;
- }
-
- /* run through the whole string, converting as we go */
- while ((ch = *current++) != '\0') {
- if (ch == base64_pad) break;
-
- /* When Base64 gets POSTed, all pluses are interpreted as spaces.
- This line changes them back. It's not exactly the Base64 spec,
- but it is completely compatible with it (the spec says that
- spaces are invalid). This will also save many people considerable
- headache. - Turadg Aleahmad <turadg@wise.berkeley.edu>
- */
-
- if (ch == ' ') ch = '+';
-
- ch = reverse_table[ch];
- if (ch < 0) continue;
-
- switch(i % 4) {
- case 0:
- result[j] = ch << 2;
- break;
- case 1:
- result[j++] |= ch >> 4;
- result[j] = (ch & 0x0f) << 4;
- break;
- case 2:
- result[j++] |= ch >>2;
- result[j] = (ch & 0x03) << 6;
- break;
- case 3:
- result[j++] |= ch;
- break;
- }
- i++;
- }
-
- k = j;
- /* mop things up if we ended on a boundary */
- if (ch == base64_pad) {
- switch(i % 4) {
- case 0:
- case 1:
- efree(result);
- return NULL;
- case 2:
- k++;
- case 3:
- result[k++] = 0;
- }
- }
- if(ret_length) {
- *ret_length = j;
- }
- result[k] = '\0';
- return result;
-}
-
-/* {{{ proto string base64_encode(string str)
- Encodes string using MIME base64 algorithm */
-PHP_FUNCTION(base64_encode)
-{
- pval **str;
- unsigned char *result;
- int ret_length;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- result = php_base64_encode(Z_STRVAL_PP(str), Z_STRLEN_PP(str), &ret_length);
- if (result != NULL) {
- RETVAL_STRINGL(result, ret_length, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto string base64_decode(string str)
- Decodes string using MIME base64 algorithm */
-PHP_FUNCTION(base64_decode)
-{
- pval **str;
- unsigned char *result;
- int ret_length;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- result = php_base64_decode(Z_STRVAL_PP(str), Z_STRLEN_PP(str), &ret_length);
- if (result != NULL) {
- RETVAL_STRINGL(result, ret_length, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vimo<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/base64.h b/ext/standard/base64.h
deleted file mode 100644
index 5db621e274..0000000000
--- a/ext/standard/base64.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jim Winstead (jimw@php.net) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef BASE64_H
-#define BASE64_H
-
-PHP_FUNCTION(base64_decode);
-PHP_FUNCTION(base64_encode);
-
-extern unsigned char *php_base64_encode(const unsigned char *, int, int *);
-extern unsigned char *php_base64_decode(const unsigned char *, int, int *);
-
-#endif /* BASE64_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
deleted file mode 100644
index 2fd601bf42..0000000000
--- a/ext/standard/basic_functions.c
+++ /dev/null
@@ -1,2710 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_main.h"
-#include "php_globals.h"
-#include "php_ini.h"
-#include "internal_functions_registry.h"
-#include "php_standard.h"
-#include "php_math.h"
-#include "php_incomplete_class.h"
-#include "ext/standard/info.h"
-#include "zend_operators.h"
-#include <stdarg.h>
-#include <stdlib.h>
-#include <math.h>
-#include <time.h>
-#include <stdio.h>
-#include <netdb.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#if HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif
-#include "safe_mode.h"
-#ifdef PHP_WIN32
-#include "win32/unistd.h"
-#endif
-#include "zend_globals.h"
-
-#include "php_globals.h"
-#include "SAPI.h"
-
-#include "php_ticks.h"
-
-#ifdef ZTS
-int basic_globals_id;
-#else
-php_basic_globals basic_globals;
-#endif
-
-#include "php_fopen_wrappers.h"
-
-static unsigned char second_and_third_args_force_ref[] = { 3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE };
-static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
-static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE };
-static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST };
-
-typedef struct _php_shutdown_function_entry {
- zval **arguments;
- int arg_count;
-} php_shutdown_function_entry;
-
-typedef struct _user_tick_function_entry {
- zval **arguments;
- int arg_count;
-} user_tick_function_entry;
-
-/* some prototypes for local functions */
-static void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry);
-static void user_tick_function_dtor(user_tick_function_entry *tick_function_entry);
-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(constant, NULL)
- PHP_FE(intval, NULL)
- PHP_FE(doubleval, NULL)
- PHP_FE(strval, NULL)
- PHP_FE(bin2hex, NULL)
- PHP_FE(sleep, NULL)
- PHP_FE(usleep, NULL)
-
- PHP_FE(time, NULL)
- PHP_FE(mktime, NULL)
- PHP_FE(gmmktime, NULL)
-#if HAVE_STRFTIME
- PHP_FE(strftime, NULL)
- PHP_FE(gmstrftime, NULL)
-#else
- PHP_FALIAS(strftime , warn_not_available, NULL)
- PHP_FALIAS(gmstrftime, warn_not_available, NULL)
-#endif
- PHP_FE(strtotime, NULL)
- PHP_FE(date, NULL)
- PHP_FE(gmdate, NULL)
- PHP_FE(getdate, NULL)
- PHP_FE(localtime, NULL)
- PHP_FE(checkdate, NULL)
-
- PHP_FE(flush, NULL)
-
- PHP_FE(gettype, NULL)
- PHP_FE(settype, first_arg_force_ref)
-
- PHP_FE(getimagesize, second_args_force_ref)
-
- PHP_FE(wordwrap, NULL)
- PHP_FE(htmlspecialchars, NULL)
- PHP_FE(htmlentities, NULL)
- PHP_FE(get_html_translation_table, NULL)
-
- PHP_NAMED_FE(md5, php_if_md5, NULL)
- PHP_NAMED_FE(crc32, php_if_crc32, NULL)
-
- PHP_FE(iptcparse, NULL)
- PHP_FE(iptcembed, NULL)
-
- PHP_FE(phpinfo, NULL)
- PHP_FE(phpversion, NULL)
- PHP_FE(phpcredits, NULL)
- PHP_FE(php_logo_guid, NULL)
- PHP_FE(zend_logo_guid, NULL)
- PHP_FE(php_sapi_name, NULL)
- PHP_FE(php_uname, NULL)
-
- PHP_FE(strnatcmp, NULL)
- PHP_FE(strnatcasecmp, NULL)
- PHP_FE(substr_count, NULL)
- PHP_FE(strspn, NULL)
- PHP_FE(strcspn, NULL)
- PHP_FE(strtok, NULL)
- PHP_FE(strtoupper, NULL)
- PHP_FE(strtolower, NULL)
- PHP_FE(strpos, NULL)
- PHP_FE(strrpos, NULL)
- PHP_FE(strrev, NULL)
- PHP_FE(hebrev, NULL)
- PHP_FE(hebrevc, NULL)
- PHP_FE(nl2br, NULL)
- PHP_FE(basename, NULL)
- PHP_FE(dirname, NULL)
- PHP_FE(pathinfo, NULL)
- PHP_FE(stripslashes, NULL)
- PHP_FE(stripcslashes, NULL)
- PHP_FE(strstr, NULL)
- PHP_FE(stristr, NULL)
- PHP_FE(strrchr, NULL)
-#ifdef HAVE_STRCOLL
- PHP_FE(strcoll, NULL)
-#else
- PHP_FALIAS(strcoll, warn_not_available, NULL)
-#endif
- PHP_FE(substr, NULL)
- PHP_FE(substr_replace, NULL)
- PHP_FE(quotemeta, NULL)
- PHP_FE(ucfirst, NULL)
- PHP_FE(ucwords, NULL)
- PHP_FE(strtr, NULL)
- PHP_FE(addslashes, NULL)
- PHP_FE(addcslashes, NULL)
- PHP_FE(chop, NULL)
- PHP_FE(str_replace, NULL)
- PHP_FE(str_repeat, NULL)
- PHP_FE(count_chars, NULL)
- PHP_FE(chunk_split, NULL)
- PHP_FE(trim, NULL)
- PHP_FE(ltrim, NULL)
- PHP_FE(strip_tags, NULL)
- PHP_FE(similar_text, third_arg_force_ref)
- PHP_FE(explode, NULL)
- PHP_FE(implode, NULL)
- PHP_FE(setlocale, NULL)
- PHP_FE(localeconv, NULL)
-#if HAVE_NL_LANGINFO
- PHP_FE(nl_langinfo, NULL)
-#else
- PHP_FALIAS(nl_langinfo, warn_not_available, NULL)
-#endif
- PHP_FE(soundex, NULL)
- PHP_FE(levenshtein, NULL)
- PHP_FE(chr, NULL)
- PHP_FE(ord, NULL)
- PHP_FE(parse_str, second_arg_force_ref)
- PHP_FE(str_pad, NULL)
- PHP_FALIAS(rtrim, chop, NULL)
- PHP_FALIAS(strchr, strstr, NULL)
- PHP_NAMED_FE(sprintf, PHP_FN(user_sprintf), NULL)
- PHP_NAMED_FE(printf, PHP_FN(user_printf), NULL)
- PHP_FE(vprintf, NULL)
- PHP_FE(vsprintf, NULL)
- PHP_FE(sscanf, third_and_rest_force_ref)
- PHP_FE(fscanf, third_and_rest_force_ref)
- PHP_FE(parse_url, NULL)
- PHP_FE(urlencode, NULL)
- PHP_FE(urldecode, NULL)
- PHP_FE(rawurlencode, NULL)
- PHP_FE(rawurldecode, NULL)
-
-#ifdef HAVE_SYMLINK
- PHP_FE(readlink, NULL)
- PHP_FE(linkinfo, NULL)
- PHP_FE(symlink, NULL)
- PHP_FE(link, NULL)
-#else
- PHP_FALIAS(readlink, warn_not_available, NULL)
- PHP_FALIAS(linkinfo, warn_not_available, NULL)
- PHP_FALIAS(symlink, warn_not_available, NULL)
- PHP_FALIAS(link, warn_not_available, NULL)
-#endif
- PHP_FE(unlink, NULL)
-
- PHP_FE(exec, second_and_third_args_force_ref)
- PHP_FE(system, second_arg_force_ref)
- PHP_FE(escapeshellcmd, NULL)
- PHP_FE(escapeshellarg, NULL)
- PHP_FE(passthru, second_arg_force_ref)
- PHP_FE(shell_exec, NULL)
-
- PHP_FE(rand, NULL)
- PHP_FE(srand, NULL)
- PHP_FE(getrandmax, NULL)
- PHP_FE(mt_rand, NULL)
- PHP_FE(mt_srand, NULL)
- PHP_FE(mt_getrandmax, NULL)
-
-#if HAVE_GETSERVBYNAME
- PHP_FE(getservbyname, NULL)
-#endif
-#if HAVE_GETSERVBYPORT
- PHP_FE(getservbyport, NULL)
-#endif
-#if HAVE_GETPROTOBYNAME
- PHP_FE(getprotobyname, NULL)
-#endif
-#if HAVE_GETPROTOBYNUMBER
- PHP_FE(getprotobynumber, NULL)
-#endif
-
- PHP_FE(gethostbyaddr, NULL)
- PHP_FE(gethostbyname, NULL)
- PHP_FE(gethostbynamel, NULL)
-#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
- PHP_FE(checkdnsrr, NULL)
- PHP_FE(getmxrr, second_and_third_args_force_ref)
-#else
- PHP_FALIAS(checkdnsrr, warn_not_available, NULL)
- PHP_FALIAS(getmxrr, warn_not_available, NULL)
-#endif
-
- PHP_FE(getmyuid, NULL)
- PHP_FE(getmygid, NULL)
- PHP_FE(getmypid, NULL)
- PHP_FE(getmyinode, NULL)
- PHP_FE(getlastmod, NULL)
-
- PHP_FE(base64_decode, NULL)
- PHP_FE(base64_encode, NULL)
-
- PHP_FE(abs, NULL)
- PHP_FE(ceil, NULL)
- PHP_FE(floor, NULL)
- PHP_FE(round, NULL)
- PHP_FE(sin, NULL)
- PHP_FE(cos, NULL)
- PHP_FE(tan, NULL)
- PHP_FE(asin, NULL)
- PHP_FE(acos, NULL)
- PHP_FE(atan, NULL)
- PHP_FE(atan2, NULL)
- PHP_FE(sinh, NULL)
- PHP_FE(cosh, NULL)
- PHP_FE(tanh, NULL)
-#ifndef PHP_WIN32
- PHP_FE(asinh, NULL)
- PHP_FE(acosh, NULL)
- PHP_FE(atanh, NULL)
-#endif
- 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(exp2, NULL)
- PHP_FE(exp10, NULL)
- PHP_FE(log2, NULL)
-#ifndef PHP_WIN32
- PHP_FE(cbrt, NULL)
-#endif
- PHP_FE(hypot, NULL)
-#ifndef PHP_WIN32
- PHP_FE(expm1, NULL)
- PHP_FE(log1p, NULL)
-#endif
- PHP_FE(deg2rad, NULL)
- PHP_FE(rad2deg, NULL)
- PHP_FE(bindec, NULL)
- PHP_FE(hexdec, NULL)
- PHP_FE(octdec, NULL)
- PHP_FE(decbin, NULL)
- PHP_FE(decoct, NULL)
- PHP_FE(dechex, NULL)
- PHP_FE(base_convert, NULL)
- PHP_FE(number_format, NULL)
- PHP_FE(ip2long, NULL)
- PHP_FE(long2ip, NULL)
-
- PHP_FE(getenv, NULL)
-#ifdef HAVE_PUTENV
- PHP_FE(putenv, NULL)
-#else
- PHP_FALIAS(putenv , warn_not_available, NULL)
-#endif
-
- PHP_FE(microtime, NULL)
- PHP_FE(gettimeofday, NULL)
-#ifdef HAVE_GETRUSAGE
- PHP_FE(getrusage, NULL)
-#else
- PHP_FALIAS(getrusage , warn_not_available, NULL)
-#endif
-
- PHP_FE(uniqid, NULL)
-
- PHP_FE(quoted_printable_decode, NULL)
-
- PHP_FE(convert_cyr_string, NULL)
- PHP_FE(get_current_user, NULL)
- PHP_FE(set_time_limit, NULL)
-
- PHP_FE(get_cfg_var, NULL)
- PHP_FALIAS(magic_quotes_runtime, set_magic_quotes_runtime, NULL)
- PHP_FE(set_magic_quotes_runtime, NULL)
- PHP_FE(get_magic_quotes_gpc, NULL)
- PHP_FE(get_magic_quotes_runtime, NULL)
-
- PHP_FE(is_null, NULL)
- PHP_FE(is_resource, NULL)
- PHP_FE(is_bool, NULL)
- PHP_FE(is_long, NULL)
- PHP_FALIAS(is_int, is_long, NULL)
- PHP_FALIAS(is_integer, is_long, NULL)
- PHP_FALIAS(is_float, is_double, NULL)
- PHP_FE(is_double, NULL)
- PHP_FALIAS(is_real, is_double, NULL)
- PHP_FE(is_numeric, NULL)
- PHP_FE(is_string, NULL)
- PHP_FE(is_array, NULL)
- PHP_FE(is_object, NULL)
- PHP_FE(is_scalar, NULL)
- PHP_FE(is_callable, third_arg_force_ref)
- PHP_FE(import_request_variables, NULL)
-
- PHP_FE(error_log, NULL)
- PHP_FE(call_user_func, NULL)
- PHP_FE(call_user_func_array, NULL)
- PHP_FE(call_user_method, second_arg_force_ref)
- PHP_FE(call_user_method_array, second_arg_force_ref)
-
- PHP_FE(var_dump, NULL)
- PHP_FE(serialize, NULL)
- PHP_FE(unserialize, NULL)
-
- PHP_FE(register_shutdown_function, NULL)
-
- PHP_FE(register_tick_function, NULL)
- PHP_FE(unregister_tick_function, NULL)
-
- PHP_FE(highlight_file, NULL)
- PHP_FALIAS(show_source, highlight_file , NULL)
- PHP_FE(highlight_string, NULL)
-
- PHP_FE(ini_get, NULL)
- PHP_FE(ini_set, NULL)
- PHP_FALIAS(ini_alter, ini_set, NULL)
- PHP_FE(ini_restore, NULL)
-
- PHP_FE(print_r, NULL)
-
- PHP_FE(setcookie, NULL)
- PHP_FE(header, NULL)
- PHP_FE(headers_sent, NULL)
-
- PHP_FE(connection_aborted, NULL)
- PHP_FE(connection_status, NULL)
- PHP_FE(ignore_user_abort, NULL)
-
- PHP_FE(parse_ini_file, NULL)
-
- PHP_FE(is_uploaded_file, NULL)
- PHP_FE(move_uploaded_file, NULL)
-
- /* functions from reg.c */
- PHP_FE(ereg, third_arg_force_ref)
- PHP_FE(ereg_replace, NULL)
- PHP_FE(eregi, third_arg_force_ref)
- PHP_FE(eregi_replace, NULL)
- PHP_FE(split, NULL)
- PHP_FE(spliti, NULL)
- PHP_FALIAS(join, implode, NULL)
- PHP_FE(sql_regcase, NULL)
-
- /* functions from dl.c */
- PHP_FE(dl, NULL)
-
-
- /* functions from file.c */
- PHP_FE(pclose, NULL)
- PHP_FE(popen, NULL)
- PHP_FE(readfile, NULL)
- PHP_FE(rewind, NULL)
- PHP_FE(rmdir, NULL)
- PHP_FE(umask, NULL)
- PHP_FE(fclose, NULL)
- PHP_FE(feof, NULL)
- PHP_FE(fgetc, NULL)
- PHP_FE(fgets, NULL)
- PHP_FE(fgetss, NULL)
- PHP_FE(fread, NULL)
- PHP_STATIC_FE("fopen", php_if_fopen, NULL)
- PHP_FE(fpassthru, NULL)
- PHP_STATIC_FE("ftruncate", php_if_ftruncate, NULL)
- PHP_STATIC_FE("fstat", php_if_fstat, NULL)
- PHP_FE(fseek, NULL)
- PHP_FE(ftell, NULL)
- PHP_FE(fflush, NULL)
- PHP_FE(fwrite, NULL)
- PHP_FALIAS(fputs, fwrite, NULL)
- PHP_FE(mkdir, NULL)
- PHP_FE(rename, NULL)
- PHP_FE(copy, NULL)
- PHP_FE(tempnam, NULL)
- PHP_STATIC_FE("tmpfile", php_if_tmpfile, NULL)
- PHP_FE(file, NULL)
- PHP_FE(fgetcsv, NULL)
- PHP_FE(flock, NULL)
- PHP_FE(get_meta_tags, NULL)
- PHP_FE(set_file_buffer, NULL)
- /* set_socket_blocking() is deprecated,
- use socket_set_blocking() instead */
- PHP_FE(set_socket_blocking, NULL)
- PHP_FE(socket_set_blocking, NULL)
-#if HAVE_PHP_STREAM
- PHP_FE(fopenstream, NULL)
-#else
- PHP_FALIAS(fopenstream, warn_not_available, NULL)
-#endif
-#if HAVE_SYS_TIME_H
- PHP_FE(socket_set_timeout, NULL)
-#else
- PHP_FALIAS(socket_set_timeout, warn_not_available, NULL)
-#endif
- PHP_FE(socket_get_status, NULL)
-#if (!defined(PHP_WIN32) && !defined(__BEOS__)) || defined(ZTS)
- PHP_FE(realpath, NULL)
-#else
- PHP_FALIAS(realpath, warn_not_available, NULL)
-#endif
-
- /* functions from fsock.c */
- PHP_FE(fsockopen, third_and_fourth_args_force_ref)
- PHP_FE(pfsockopen, third_and_fourth_args_force_ref)
-
- /* functions from pack.c */
- PHP_FE(pack, NULL)
- PHP_FE(unpack, NULL)
-
- /* functions from browscap.c */
- PHP_FE(get_browser, NULL)
-
-#if HAVE_CRYPT
- /* functions from crypt.c */
- PHP_FE(crypt, NULL)
-#else
- PHP_FALIAS(crypt , warn_not_available, NULL)
-#endif
-
- /* functions from dir.c */
- PHP_FE(opendir, NULL)
- PHP_FE(closedir, NULL)
- PHP_FE(chdir, NULL)
-#if defined(HAVE_CHROOT) && !defined(ZTS)
- PHP_FE(chroot, NULL)
-#else
- PHP_FALIAS(chroot, warn_not_available, NULL)
-#endif
- PHP_FE(getcwd, NULL)
- PHP_FE(rewinddir, NULL)
- PHP_STATIC_FE("readdir", php_if_readdir, NULL)
- PHP_FALIAS(dir, getdir, NULL)
-
- /* functions from filestat.c */
- PHP_FE(fileatime, NULL)
- PHP_FE(filectime, NULL)
- PHP_FE(filegroup, NULL)
- PHP_FE(fileinode, NULL)
- PHP_FE(filemtime, NULL)
- PHP_FE(fileowner, NULL)
- PHP_FE(fileperms, NULL)
- PHP_FE(filesize, NULL)
- PHP_FE(filetype, NULL)
- PHP_FE(file_exists, NULL)
- PHP_FE(is_writable, NULL)
- PHP_FALIAS(is_writeable, is_writable, NULL)
- PHP_FE(is_readable, NULL)
- PHP_FE(is_executable, NULL)
- PHP_FE(is_file, NULL)
- PHP_FE(is_dir, NULL)
- PHP_FE(is_link, NULL)
- PHP_STATIC_FE("stat", php_if_stat, NULL)
- PHP_STATIC_FE("lstat", php_if_lstat, NULL)
- PHP_FE(chown, NULL)
- PHP_FE(chgrp, NULL)
- PHP_FE(chmod, NULL)
- PHP_FE(touch, NULL)
- PHP_FE(clearstatcache, NULL)
- PHP_FE(disk_total_space, NULL)
- PHP_FE(disk_free_space, NULL)
- PHP_FALIAS(diskfreespace, disk_free_space, NULL)
-
- /* functions from mail.c */
-#ifdef HAVE_SENDMAIL
- PHP_FE(mail, NULL)
- PHP_FE(ezmlm_hash, NULL)
-#else
- PHP_FALIAS(mail, warn_not_available, NULL)
- PHP_FALIAS(ezmlm_hash, warn_not_available, NULL)
-#endif
-
- /* functions from syslog.c */
-#ifdef HAVE_SYSLOG_H
- PHP_FE(openlog, NULL)
- PHP_FE(syslog, NULL)
- PHP_FE(closelog, NULL)
- PHP_FE(define_syslog_variables, NULL)
-#endif
-
- /* functions from lcg.c */
- PHP_FE(lcg_value, NULL)
-
- /* functions from metaphone.c */
- PHP_FE(metaphone, NULL)
-
- /* functions from output.c */
- PHP_FE(ob_start, NULL)
- PHP_FE(ob_end_flush, NULL)
- PHP_FE(ob_end_clean, NULL)
- PHP_FE(ob_get_length, NULL)
- PHP_FE(ob_get_contents, NULL)
- PHP_FE(ob_implicit_flush, NULL)
-
- /* functions from array.c */
- PHP_FE(ksort, first_arg_force_ref)
- PHP_FE(krsort, first_arg_force_ref)
- PHP_FE(natsort, first_arg_force_ref)
- PHP_FE(natcasesort, first_arg_force_ref)
- PHP_FE(asort, first_arg_force_ref)
- PHP_FE(arsort, first_arg_force_ref)
- PHP_FE(sort, first_arg_force_ref)
- PHP_FE(rsort, first_arg_force_ref)
- PHP_FE(usort, first_arg_force_ref)
- PHP_FE(uasort, first_arg_force_ref)
- PHP_FE(uksort, first_arg_force_ref)
- PHP_FE(shuffle, first_arg_force_ref)
- PHP_FE(array_walk, first_arg_force_ref)
- PHP_FE(count, NULL)
- PHP_FE(end, first_arg_force_ref)
- PHP_FE(prev, first_arg_force_ref)
- PHP_FE(next, first_arg_force_ref)
- PHP_FE(reset, first_arg_force_ref)
- PHP_FE(current, first_arg_force_ref)
- PHP_FE(key, first_arg_force_ref)
- PHP_FE(min, NULL)
- PHP_FE(max, NULL)
- PHP_FE(in_array, NULL)
- PHP_FE(array_search, NULL)
- PHP_FE(extract, NULL)
- PHP_FE(compact, NULL)
- PHP_FE(range, NULL)
- PHP_FE(array_multisort, NULL)
- PHP_FE(array_push, first_arg_force_ref)
- PHP_FE(array_pop, first_arg_force_ref)
- PHP_FE(array_shift, first_arg_force_ref)
- PHP_FE(array_unshift, first_arg_force_ref)
- PHP_FE(array_splice, first_arg_force_ref)
- PHP_FE(array_slice, NULL)
- PHP_FE(array_merge, NULL)
- PHP_FE(array_merge_recursive, NULL)
- PHP_FE(array_keys, NULL)
- PHP_FE(array_values, NULL)
- PHP_FE(array_count_values, NULL)
- PHP_FE(array_reverse, NULL)
- PHP_FE(array_reduce, NULL)
- PHP_FE(array_pad, NULL)
- PHP_FE(array_flip, NULL)
- PHP_FE(array_rand, NULL)
- PHP_FE(array_unique, NULL)
- PHP_FE(array_intersect, NULL)
- PHP_FE(array_diff, NULL)
- PHP_FE(array_sum, NULL)
- PHP_FE(array_filter, NULL)
- PHP_FE(array_map, NULL)
- PHP_FE(key_exists, NULL)
-
- /* aliases from array.c */
- PHP_FALIAS(pos, current, first_arg_force_ref)
- PHP_FALIAS(sizeof, count, NULL)
-
- /* functions from assert.c */
- PHP_FE(assert, NULL)
- PHP_FE(assert_options, NULL)
-
- {NULL, NULL, NULL}
-};
-
-
-static PHP_INI_MH(OnUpdateSafeModeProtectedEnvVars)
-{
- char *protected_vars, *protected_var;
- char *token_buf;
- int dummy=1;
-
- protected_vars = estrndup(new_value, new_value_length);
- zend_hash_clean(&BG(sm_protected_env_vars));
-
- protected_var= php_strtok_r(protected_vars, ", ", &token_buf);
- while (protected_var) {
- zend_hash_update(&BG(sm_protected_env_vars), protected_var, strlen(protected_var), &dummy, sizeof(int), NULL);
- protected_var=php_strtok_r(NULL, ", ", &token_buf);
- }
- efree(protected_vars);
- return SUCCESS;
-}
-
-
-static PHP_INI_MH(OnUpdateSafeModeAllowedEnvVars)
-{
- if (BG(sm_allowed_env_vars)) {
- free(BG(sm_allowed_env_vars));
- }
- BG(sm_allowed_env_vars) = zend_strndup(new_value, new_value_length);
- return SUCCESS;
-}
-
-PHP_INI_BEGIN()
- PHP_INI_ENTRY_EX("safe_mode_protected_env_vars", SAFE_MODE_PROTECTED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeProtectedEnvVars, NULL)
- PHP_INI_ENTRY_EX("safe_mode_allowed_env_vars", SAFE_MODE_ALLOWED_ENV_VARS, PHP_INI_SYSTEM, OnUpdateSafeModeAllowedEnvVars, NULL)
- STD_PHP_INI_ENTRY("session.use_trans_sid", "1", PHP_INI_ALL, OnUpdateBool, use_trans_sid, php_basic_globals, basic_globals)
-PHP_INI_END()
-
-
-zend_module_entry basic_functions_module = {
- "standard", /* extension name */
- basic_functions, /* function list */
- PHP_MINIT(basic), /* process startup */
- PHP_MSHUTDOWN(basic), /* process shutdown */
- PHP_RINIT(basic), /* request startup */
- PHP_RSHUTDOWN(basic), /* request shutdown */
- PHP_MINFO(basic), /* extension info */
- STANDARD_MODULE_PROPERTIES
-};
-
-#if defined(HAVE_PUTENV)
-
-static void php_putenv_destructor(putenv_entry *pe)
-{
- if (pe->previous_value) {
- putenv(pe->previous_value);
- } else {
-# if HAVE_UNSETENV
- unsetenv(pe->key);
-# else
- char **env;
-
- for (env = environ; env != NULL && *env != NULL; env++) {
- if (!strncmp(*env, pe->key, pe->key_len) && (*env)[pe->key_len]=='=') { /* found it */
- *env = "";
- break;
- }
- }
-# endif
- }
- efree(pe->putenv_string);
- efree(pe->key);
-}
-#endif
-
-
-void test_class_startup(void);
-
-static void basic_globals_ctor(php_basic_globals *basic_globals_p TSRMLS_DC)
-{
- BG(next) = NULL;
- BG(left) = -1;
- BG(user_tick_functions) = NULL;
- zend_hash_init(&BG(sm_protected_env_vars), 5, NULL, NULL, 1);
- BG(sm_allowed_env_vars) = NULL;
-
-#ifdef TRANS_SID
- memset(&BG(url_adapt_state), 0, sizeof(BG(url_adapt_state)));
- memset(&BG(url_adapt_state_ex), 0, sizeof(BG(url_adapt_state_ex)));
-#endif
-
-#ifdef PHP_WIN32
- CoInitialize(NULL);
-#endif
-
- BG(incomplete_class) = php_create_incomplete_class(TSRMLS_C);
-}
-
-static void basic_globals_dtor(php_basic_globals *basic_globals_p TSRMLS_DC)
-{
- zend_hash_destroy(&BG(sm_protected_env_vars));
- if (BG(sm_allowed_env_vars)) {
- free(BG(sm_allowed_env_vars));
- }
-#ifdef PHP_WIN32
- CoUninitialize();
-#endif
-}
-
-
-PHP_MINIT_FUNCTION(basic)
-{
-#ifdef ZTS
- ts_allocate_id(&basic_globals_id, sizeof(php_basic_globals), (ts_allocate_ctor) basic_globals_ctor, (ts_allocate_dtor) basic_globals_dtor);
-#else
- basic_globals_ctor(&basic_globals TSRMLS_CC);
-#endif
-
- REGISTER_LONG_CONSTANT("CONNECTION_ABORTED", PHP_CONNECTION_ABORTED, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CONNECTION_NORMAL", PHP_CONNECTION_NORMAL, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CONNECTION_TIMEOUT", PHP_CONNECTION_TIMEOUT, CONST_CS | CONST_PERSISTENT);
-
-#define REGISTER_MATH_CONSTANT(x) REGISTER_DOUBLE_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
- REGISTER_MATH_CONSTANT(M_E);
- REGISTER_MATH_CONSTANT(M_LOG2E);
- REGISTER_MATH_CONSTANT(M_LOG10E);
- REGISTER_MATH_CONSTANT(M_LN2);
- REGISTER_MATH_CONSTANT(M_LN10);
- REGISTER_MATH_CONSTANT(M_PI);
- REGISTER_MATH_CONSTANT(M_PI_2);
- REGISTER_MATH_CONSTANT(M_PI_4);
- REGISTER_MATH_CONSTANT(M_1_PI);
- REGISTER_MATH_CONSTANT(M_2_PI);
- REGISTER_MATH_CONSTANT(M_2_SQRTPI);
- REGISTER_MATH_CONSTANT(M_SQRT2);
- REGISTER_MATH_CONSTANT(M_SQRT1_2);
-
-
- test_class_startup();
- REGISTER_INI_ENTRIES();
-
- register_phpinfo_constants(INIT_FUNC_ARGS_PASSTHRU);
- register_html_constants(INIT_FUNC_ARGS_PASSTHRU);
- register_string_constants(INIT_FUNC_ARGS_PASSTHRU);
-
- PHP_MINIT(regex)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(file)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(pack)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(browscap)(INIT_FUNC_ARGS_PASSTHRU);
-#if defined(HAVE_LOCALECONV) && defined(ZTS)
- PHP_MINIT(localeconv)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-#if defined(HAVE_NL_LANGINFO)
- PHP_MINIT(nl_langinfo)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-#if HAVE_CRYPT
- PHP_MINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-
-#ifdef ZTS
- PHP_MINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-
- PHP_MINIT(dir)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU);
-#ifdef TRANS_SID
- PHP_MINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-
-
- if(PG(allow_url_fopen)) {
- if (FAILURE==php_register_url_wrapper("http", php_fopen_url_wrap_http TSRMLS_CC)) {
- return FAILURE;
- }
- if (FAILURE==php_register_url_wrapper("ftp", php_fopen_url_wrap_ftp TSRMLS_CC)) {
- return FAILURE;
- }
- if (FAILURE==php_register_url_wrapper("php", php_fopen_url_wrap_php TSRMLS_CC)) {
- return FAILURE;
- }
- }
-
- return SUCCESS;
-}
-
-
-PHP_MSHUTDOWN_FUNCTION(basic)
-{
-#ifdef ZTS
- ts_free_id(basic_globals_id);
-#else
- basic_globals_dtor(&basic_globals TSRMLS_CC);
-#endif
-
- if(PG(allow_url_fopen)) {
- php_unregister_url_wrapper("http" TSRMLS_CC);
- php_unregister_url_wrapper("ftp" TSRMLS_CC);
- php_unregister_url_wrapper("php" TSRMLS_CC);
- }
-
- UNREGISTER_INI_ENTRIES();
-
- PHP_MSHUTDOWN(regex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#ifdef TRANS_SID
- PHP_MSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#endif
- PHP_MSHUTDOWN(file)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#if defined(HAVE_LOCALECONV) && defined(ZTS)
- PHP_MSHUTDOWN(localeconv)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#endif
-
- return SUCCESS;
-}
-
-
-PHP_RINIT_FUNCTION(basic)
-{
- memset(BG(strtok_table), 0, 256);
- BG(strtok_string) = NULL;
- BG(strtok_zval) = NULL;
- BG(locale_string) = NULL;
- BG(user_compare_func_name) = NULL;
- BG(array_walk_func_name) = NULL;
-#ifdef HAVE_MMAP
- BG(mmap_file) = NULL;
-#endif
- BG(page_uid) = -1;
- BG(page_gid) = -1;
- BG(page_inode) = -1;
- BG(page_mtime) = -1;
-#ifdef HAVE_PUTENV
- if (zend_hash_init(&BG(putenv_ht), 1, NULL, (void (*)(void *)) php_putenv_destructor, 0) == FAILURE) {
- return FAILURE;
- }
-#endif
- BG(user_shutdown_function_names)=NULL;
-
-#if HAVE_CRYPT
- PHP_RINIT(crypt)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-
-#ifndef ZTS
- PHP_RINIT(lcg)(INIT_FUNC_ARGS_PASSTHRU);
-#endif
-
- PHP_RINIT(filestat)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_RINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_RINIT(dir)(INIT_FUNC_ARGS_PASSTHRU);
-
-#ifdef TRANS_SID
- if (BG(use_trans_sid)) {
- PHP_RINIT(url_scanner)(INIT_FUNC_ARGS_PASSTHRU);
- PHP_RINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);
- }
-#endif
-
- return SUCCESS;
-}
-
-
-PHP_RSHUTDOWN_FUNCTION(basic)
-{
- if (BG(strtok_zval))
- zval_ptr_dtor(&BG(strtok_zval));
- BG(strtok_string) = NULL;
- BG(strtok_zval) = NULL;
-#ifdef HAVE_PUTENV
- zend_hash_destroy(&BG(putenv_ht));
-#endif
- /* Check if locale was changed and change it back
- to the value in startup environment */
- if (BG(locale_string) != NULL) {
- setlocale(LC_ALL, "C");
- setlocale(LC_CTYPE, "");
- }
- STR_FREE(BG(locale_string));
-
- PHP_RSHUTDOWN(fsock)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_RSHUTDOWN(filestat)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_RSHUTDOWN(syslog)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_RSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-
-#ifdef TRANS_SID
- PHP_RSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
- PHP_RSHUTDOWN(url_scanner)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
-#endif
-
- if (BG(user_tick_functions)) {
- zend_llist_destroy(BG(user_tick_functions));
- efree(BG(user_tick_functions));
- BG(user_tick_functions) = NULL;
- }
-
-#ifdef HAVE_MMAP
- if (BG(mmap_file)) {
- munmap(BG(mmap_file), BG(mmap_len));
- }
-#endif
-
- return SUCCESS;
-}
-
-
-PHP_MINFO_FUNCTION(basic)
-{
- php_info_print_table_start();
- PHP_MINFO(regex)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
- PHP_MINFO(dl)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
- PHP_MINFO(mail)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
- php_info_print_table_end();
- PHP_MINFO(assert)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);
-}
-
-/* {{{ proto mixed constant(string const_name)
- Given the name of a constant this function will return the constants associated value */
-PHP_FUNCTION(constant)
-{
- zval **const_name;
-
- if (ZEND_NUM_ARGS() != 1 ||
- zend_get_parameters_ex(1, &const_name) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(const_name);
-
- if (!zend_get_constant(Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value TSRMLS_CC)) {
- php_error(E_WARNING, "Couldn't find constant %s", Z_STRVAL_PP(const_name));
- RETURN_NULL();
- }
-}
-/* }}} */
-
-
-/* {{{ proto int ip2long(string ip_address)
- Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */
-PHP_FUNCTION(ip2long)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(str);
-
- RETURN_LONG(ntohl(inet_addr(Z_STRVAL_PP(str))));
-}
-/* }}} */
-
-/* {{{ proto string long2ip(int proper_address)
- Converts an (IPv4) Internet network address into a string in Internet standard dotted format */
-PHP_FUNCTION(long2ip)
-{
- zval **num;
- struct in_addr myaddr;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(num);
- myaddr.s_addr = htonl((unsigned long)Z_LVAL_PP(num));
-
- RETURN_STRING (inet_ntoa(myaddr), 1);
-}
-/* }}} */
-
-
-/********************
- * System Functions *
- ********************/
-
-/* {{{ proto string getenv(string varname)
- Get the value of an environment variable */
-PHP_FUNCTION(getenv)
-{
- pval **str;
- char *ptr;
-
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- if (Z_TYPE_PP(str) != IS_STRING) {
- RETURN_FALSE;
- }
-
-
- ptr = sapi_getenv(Z_STRVAL_PP(str), Z_STRLEN_PP(str) TSRMLS_CC);
- if (!ptr) {
- ptr = getenv(Z_STRVAL_PP(str));
- }
- if (ptr) {
- RETURN_STRING(ptr, 1);
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-#ifdef HAVE_PUTENV
-
-/* {{{ proto bool putenv(string setting)
- Set the value of an environment variable */
-PHP_FUNCTION(putenv)
-{
- pval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- if (Z_STRVAL_PP(str) && *(Z_STRVAL_PP(str))) {
- int ret;
- char *p, **env;
- putenv_entry pe;
-
- pe.putenv_string = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
- pe.key = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
- if ((p=strchr(pe.key,'='))) { /* nullify the '=' if there is one */
- *p='\0';
- }
- pe.key_len = strlen(pe.key);
-
- if (PG(safe_mode)) {
- /* Check the protected list */
- if (zend_hash_exists(&BG(sm_protected_env_vars), pe.key, pe.key_len)) {
- php_error(E_WARNING, "Safe Mode: Cannot override protected environment variable '%s'", pe.key);
- efree(pe.putenv_string);
- efree(pe.key);
- RETURN_FALSE;
- }
-
- /* Check the allowed list */
- if (BG(sm_allowed_env_vars) && *BG(sm_allowed_env_vars)) {
- char *allowed_env_vars = estrdup(BG(sm_allowed_env_vars));
- char *allowed_prefix = strtok(allowed_env_vars, ", ");
- zend_bool allowed=0;
-
- while (allowed_prefix) {
- if (!strncmp(allowed_prefix, pe.key, strlen(allowed_prefix))) {
- allowed=1;
- break;
- }
- allowed_prefix = strtok(NULL, ", ");
- }
- efree(allowed_env_vars);
- if (!allowed) {
- php_error(E_WARNING, "Safe Mode: Cannot set environment variable '%s' - it's not in the allowed list", pe.key);
- efree(pe.putenv_string);
- efree(pe.key);
- RETURN_FALSE;
- }
- }
- }
-
- zend_hash_del(&BG(putenv_ht), pe.key, pe.key_len+1);
-
- /* find previous value */
- pe.previous_value = NULL;
- for (env = environ; env != NULL && *env != NULL; env++) {
- if (!strncmp(*env, pe.key, pe.key_len) && (*env)[pe.key_len]=='=') { /* found it */
- pe.previous_value = *env;
- break;
- }
- }
-
- if ((ret=putenv(pe.putenv_string))==0) { /* success */
- zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL);
-#ifdef HAVE_TZSET
- if(!strncmp(pe.key, "TZ", 2)) tzset();
-#endif
- RETURN_TRUE;
- } else {
- efree(pe.putenv_string);
- efree(pe.key);
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-#endif
-
-
-/*******************
- * Basic Functions *
- *******************/
-/* {{{ proto int intval(mixed var [, int base])
- Get the integer value of a variable using the optional base for the conversion */
-PHP_FUNCTION(intval)
-{
- pval **num, **arg_base;
- int base;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- base = 10;
- break;
- case 2:
- if (zend_get_parameters_ex(2, &num, &arg_base) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg_base);
- base = Z_LVAL_PP(arg_base);
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- *return_value=**num;
- zval_copy_ctor(return_value);
- convert_to_long_base(return_value, base);
-}
-/* }}} */
-
-/* {{{ proto double doubleval(mixed var)
- Get the double-precision value of a variable */
-PHP_FUNCTION(doubleval)
-{
- pval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- *return_value=**num;
- zval_copy_ctor(return_value);
- convert_to_double(return_value);
-}
-/* }}} */
-
-/* {{{ proto string strval(mixed var)
- Get the string value of a variable */
-PHP_FUNCTION(strval)
-{
- pval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- *return_value=**num;
- zval_copy_ctor(return_value);
- convert_to_string(return_value);
-}
-/* }}} */
-
-/* {{{ proto void flush(void)
- Flush the output buffer */
-PHP_FUNCTION(flush)
-{
- sapi_flush(TSRMLS_C);
-}
-/* }}} */
-
-/* {{{ proto void sleep(int seconds)
- Delay for a given number of seconds */
-PHP_FUNCTION(sleep)
-{
- pval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(num);
- php_sleep(Z_LVAL_PP(num));
-}
-/* }}} */
-
-/* {{{ proto void usleep(int micro_seconds)
- Delay for a given number of micro seconds */
-PHP_FUNCTION(usleep)
-{
-#if HAVE_USLEEP
- pval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(num);
- usleep(Z_LVAL_PP(num));
-#endif
-}
-/* }}} */
-
-/* {{{ proto string gettype(mixed var)
- Returns the type of the variable */
-PHP_FUNCTION(gettype)
-{
- pval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (Z_TYPE_PP(arg)) {
- case IS_NULL:
- RETVAL_STRING("NULL", 1);
- break;
- case IS_BOOL:
- RETVAL_STRING("boolean", 1);
- break;
- case IS_LONG:
- RETVAL_STRING("integer", 1);
- break;
- case IS_RESOURCE:
- RETVAL_STRING("resource", 1);
- break;
- case IS_DOUBLE:
- RETVAL_STRING("double", 1);
- break;
- case IS_STRING:
- RETVAL_STRING("string", 1);
- break;
- case IS_ARRAY:
- RETVAL_STRING("array", 1);
- break;
- case IS_OBJECT:
- RETVAL_STRING("object", 1);
- break;
- /*
- {
- char *result;
- int res_len;
-
- res_len = sizeof("object of type ")-1 + arg->value.obj.ce->name_length;
- result = (char *) emalloc(res_len+1);
- sprintf(result, "object of type %s", arg->value.obj.ce->name);
- RETVAL_STRINGL(result, res_len, 0);
- }
- */
- break;
- default:
- RETVAL_STRING("unknown type", 1);
- }
-}
-/* }}} */
-
-/* {{{ proto bool settype(mixed var, string type)
- Set the type of the variable */
-PHP_FUNCTION(settype)
-{
- pval **var, **type;
- char *new_type;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &var, &type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(type);
- new_type = Z_STRVAL_PP(type);
-
- if (!strcasecmp(new_type, "integer")) {
- convert_to_long(*var);
- } else if (!strcasecmp(new_type, "double")) {
- convert_to_double(*var);
- } else if (!strcasecmp(new_type, "string")) {
- convert_to_string(*var);
- } else if (!strcasecmp(new_type, "array")) {
- convert_to_array(*var);
- } else if (!strcasecmp(new_type, "object")) {
- convert_to_object(*var);
- } else if (!strcasecmp(new_type, "boolean")) {
- convert_to_boolean(*var);
- } else if (!strcasecmp(new_type, "resource")) {
- php_error(E_WARNING, "settype: cannot convert to resource type");
- RETURN_FALSE;
- } else {
- php_error(E_WARNING, "settype: invalid type");
- RETURN_FALSE;
- }
- RETVAL_TRUE;
-}
-/* }}} */
-
-/* {{{ proto string get_current_user(void)
- Get the name of the owner of the current PHP script */
-PHP_FUNCTION(get_current_user)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRING(php_get_current_user(), 1);
-}
-/* }}} */
-
-/* {{{ proto string get_cfg_var(string option_name)
- Get the value of a PHP configuration option */
-PHP_FUNCTION(get_cfg_var)
-{
- pval **varname;
- char *value;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &varname)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(varname);
-
- if (cfg_get_string(Z_STRVAL_PP(varname), &value)==FAILURE) {
- RETURN_FALSE;
- }
- RETURN_STRING(value, 1);
-}
-/* }}} */
-
-/* {{{ proto bool set_magic_quotes_runtime(int new_setting)
- Set the current active configuration setting of magic_quotes_runtime and return previous */
-PHP_FUNCTION(set_magic_quotes_runtime)
-{
- pval **new_setting;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &new_setting)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_boolean_ex(new_setting);
-
- PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting);
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int get_magic_quotes_runtime(void)
- Get the current active configuration setting of magic_quotes_runtime */
-PHP_FUNCTION(get_magic_quotes_runtime)
-{
- RETURN_LONG(PG(magic_quotes_runtime));
-}
-/* }}} */
-
-/* {{{ proto int get_magic_quotes_gpc(void)
- Get the current active configuration setting of magic_quotes_gpc */
-PHP_FUNCTION(get_magic_quotes_gpc)
-{
- RETURN_LONG(PG(magic_quotes_gpc));
-}
-/* }}} */
-
-
-void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type)
-{
- pval **arg;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) {
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(arg) == type) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
-
-/* {{{ proto bool is_null(mixed var)
- Returns true if variable is null */
-PHP_FUNCTION(is_null)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_NULL);
-}
-/* }}} */
-
-/* {{{ proto bool is_resource(mixed var)
- Returns true if variable is a resource */
-PHP_FUNCTION(is_resource)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_RESOURCE);
-}
-/* }}} */
-
-/* {{{ proto bool is_bool(mixed var)
- Returns true if variable is a boolean */
-PHP_FUNCTION(is_bool)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_BOOL);
-}
-/* }}} */
-
-/* {{{ proto bool is_long(mixed var)
- Returns true if variable is a long (integer) */
-PHP_FUNCTION(is_long)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_LONG);
-}
-/* }}} */
-
-/* {{{ proto bool is_double(mixed var)
- Returns true if variable is a double */
-PHP_FUNCTION(is_double)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_DOUBLE);
-}
-/* }}} */
-
-/* {{{ proto bool is_string(mixed var)
- Returns true if variable is a string */
-PHP_FUNCTION(is_string)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_STRING);
-}
-/* }}} */
-
-/* {{{ proto bool is_array(mixed var)
- Returns true if variable is an array */
-PHP_FUNCTION(is_array)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_ARRAY);
-}
-/* }}} */
-
-/* {{{ proto bool is_object(mixed var)
- Returns true if variable is an object */
-PHP_FUNCTION(is_object)
-{
- php_is_type(INTERNAL_FUNCTION_PARAM_PASSTHRU, IS_OBJECT);
-}
-/* }}} */
-
-/* {{{ proto bool is_numeric(mixed value)
- Returns true if value is a number or a numeric string */
-PHP_FUNCTION(is_numeric)
-{
- zval **arg;
- int result;
-
- if (ZEND_NUM_ARGS() !=1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- switch (Z_TYPE_PP(arg)) {
- case IS_LONG:
- case IS_DOUBLE:
- RETURN_TRUE;
- break;
-
- case IS_STRING:
- result = is_numeric_string(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg), NULL, NULL, 0);
- if (result == IS_LONG || result == IS_DOUBLE) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- break;
-
- default:
- RETURN_FALSE;
- break;
- }
-}
-/* }}} */
-
-/* {{{ proto bool is_scalar (mixed value)
- Returns true if value is a scalar */
-PHP_FUNCTION(is_scalar)
-{
- zval **arg;
-
- if (ZEND_NUM_ARGS() !=1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- switch (Z_TYPE_PP(arg)) {
- case IS_BOOL:
- case IS_DOUBLE:
- case IS_LONG:
- case IS_STRING:
- RETURN_TRUE;
- break;
-
- default:
- RETURN_FALSE;
- break;
- }
-}
-/* }}} */
-
-/*
- 1st arg = error message
- 2nd arg = error option
- 3rd arg = optional parameters (email address or tcp address)
- 4th arg = used for additional headers if email
-
- error options
- 0 = send to php_error_log (uses syslog or file depending on ini setting)
- 1 = send via email to 3rd parameter 4th option = additional headers
- 2 = send via tcp/ip to 3rd parameter (name or ip:port)
- 3 = save to file in 3rd parameter
-*/
-
-/* {{{ proto bool error_log(string message, int message_type [, string destination] [, string extra_headers])
- Send an error message somewhere */
-PHP_FUNCTION(error_log)
-{
- pval **string, **erropt = NULL, **option = NULL, **emailhead = NULL;
- int opt_err = 0;
- char *message, *opt=NULL, *headers=NULL;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &string) == FAILURE) {
- php_error(E_WARNING, "Invalid argument 1 in error_log");
- RETURN_FALSE;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) {
- php_error(E_WARNING, "Invalid arguments in error_log");
- RETURN_FALSE;
- }
- convert_to_long_ex(erropt);
- opt_err=Z_LVAL_PP(erropt);
- break;
- case 3:
- if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE){
- php_error(E_WARNING, "Invalid arguments in error_log");
- RETURN_FALSE;
- }
- convert_to_long_ex(erropt);
- opt_err=Z_LVAL_PP(erropt);
- convert_to_string_ex(option);
- opt=Z_STRVAL_PP(option);
- break;
- case 4:
- if (zend_get_parameters_ex(4, &string, &erropt, &option, &emailhead) == FAILURE){
- php_error(E_WARNING, "Invalid arguments in error_log");
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(string);
- message=Z_STRVAL_PP(string);
- if (erropt != NULL) {
- convert_to_long_ex(erropt);
- opt_err=Z_LVAL_PP(erropt);
- }
- if (option != NULL) {
- convert_to_string_ex(option);
- opt=Z_STRVAL_PP(option);
- }
- if (emailhead != NULL) {
- convert_to_string_ex(emailhead);
- headers=Z_STRVAL_PP(emailhead);
- }
-
- if (_php_error_log(opt_err, message, opt, headers TSRMLS_CC)==FAILURE) {
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-/* }}} */
-
-PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC)
-{
- FILE *logfile;
- int issock=0, socketd=0;;
-
- switch(opt_err){
- case 1: /*send an email*/ {
-#if HAVE_SENDMAIL
- if (!php_mail(opt, "PHP error_log message", message, headers, NULL)){
- return FAILURE;
- }
-#else
- php_error(E_WARNING, "Mail option not available!");
- return FAILURE;
-#endif
- }
- break;
- case 2: /*send to an address */
- php_error(E_WARNING, "TCP/IP option not available!");
- return FAILURE;
- break;
- case 3: /*save to a file*/
- logfile=php_fopen_wrapper(opt, "a", (IGNORE_URL|ENFORCE_SAFE_MODE), &issock, &socketd, NULL TSRMLS_CC);
- if(!logfile) {
- php_error(E_WARNING, "error_log: Unable to write to %s", opt);
- return FAILURE;
- }
- fwrite(message, strlen(message), 1, logfile);
- fclose(logfile);
- break;
- default:
- php_log_err(message TSRMLS_CC);
- break;
- }
- return SUCCESS;
-}
-
-/* {{{ proto mixed call_user_func(string function_name [, mixed parmeter] [, mixed ...])
- Call a user function which is the first parameter */
-PHP_FUNCTION(call_user_func)
-{
- zval ***params;
- zval *retval_ptr;
- char *name;
- int argc = ZEND_NUM_ARGS();
-
- if (argc < 1) {
- WRONG_PARAM_COUNT;
- }
-
- params = emalloc(sizeof(zval **) * argc);
-
- if (zend_get_parameters_array_ex(argc, params)==FAILURE) {
- efree(params);
- RETURN_FALSE;
- }
-
- if (Z_TYPE_PP(params[0]) != IS_STRING && Z_TYPE_PP(params[0]) != IS_ARRAY) {
- SEPARATE_ZVAL(params[0]);
- convert_to_string_ex(params[0]);
- }
-
- if (!zend_is_callable(*params[0], 0, &name)) {
- php_error(E_WARNING, "%s() expects first argument, '%s', to be a valid callback",
- get_active_function_name(TSRMLS_C), name);
- efree(name);
- efree(params);
- RETURN_NULL();
- }
-
- if (call_user_function_ex(EG(function_table), NULL, *params[0], &retval_ptr, argc - 1, params + 1, 0, NULL TSRMLS_CC)==SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- php_error(E_WARNING, "Unable to call %s()", name);
- }
-
- efree(name);
- efree(params);
-}
-/* }}} */
-
-/* {{{ proto mixed call_user_func_array(string function_name, array parameters)
- Call a user function which is the first parameter with the arguments contained in array */
-PHP_FUNCTION(call_user_func_array)
-{
- zval ***func_params;
- zval **func;
- zval **params;
- zval *retval_ptr;
- HashTable *func_params_ht;
- char *name;
- int count;
- int current = 0;
-
- if (ZEND_NUM_ARGS() != 2 ||
- zend_get_parameters_ex(2, &func, &params) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- SEPARATE_ZVAL(params);
- convert_to_array_ex(params);
-
- if (Z_TYPE_PP(func) != IS_STRING && Z_TYPE_PP(func) != IS_ARRAY) {
- SEPARATE_ZVAL(func);
- convert_to_string_ex(func);
- }
-
- if (!zend_is_callable(*func, 0, &name)) {
- php_error(E_WARNING, "%s() expects first argument, '%s', to be a valid callback",
- get_active_function_name(TSRMLS_C), name);
- efree(name);
- RETURN_NULL();
- }
-
- func_params_ht = Z_ARRVAL_PP(params);
-
- count = zend_hash_num_elements(func_params_ht);
- func_params = emalloc(sizeof(zval **) * count);
-
- for (zend_hash_internal_pointer_reset(func_params_ht);
- zend_hash_get_current_data(func_params_ht, (void **) &func_params[current]) == SUCCESS;
- zend_hash_move_forward(func_params_ht)) {
- current++;
- }
-
- if (call_user_function_ex(EG(function_table), NULL, *func, &retval_ptr, count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- php_error(E_WARNING, "Unable to call %s()", name);
- }
-
- efree(name);
- efree(func_params);
-}
-/* }}} */
-
-#define _CUM_DEPREC "The %s() function is deprecated, use the call_user_func variety with the array(&$obj, \"method\") syntax instead"
-
-/* {{{ proto mixed call_user_method(string method_name, mixed object [, mixed parameter] [, mixed ...])
- Call a user method on a specific object or class */
-PHP_FUNCTION(call_user_method)
-{
- zval ***params;
- zval *retval_ptr;
- int arg_count=ZEND_NUM_ARGS();
-
- php_error(E_NOTICE, _CUM_DEPREC, "call_user_method");
-
- if (arg_count<2) {
- WRONG_PARAM_COUNT;
- }
- params = (zval ***) emalloc(sizeof(zval **) * arg_count);
-
- if (zend_get_parameters_array_ex(arg_count, params)==FAILURE) {
- efree(params);
- RETURN_FALSE;
- }
- if (Z_TYPE_PP(params[1]) != IS_OBJECT && Z_TYPE_PP(params[1]) != IS_STRING) {
- php_error(E_WARNING, "2nd argument is not an object or class name\n");
- efree(params);
- RETURN_FALSE;
- }
- SEPARATE_ZVAL(params[0]);
- convert_to_string(*params[0]);
- if (call_user_function_ex(EG(function_table), params[1], *params[0], &retval_ptr, arg_count-2, params+2, 0, NULL TSRMLS_CC)==SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- php_error(E_WARNING, "Unable to call %s()", Z_STRVAL_PP(params[0]));
- }
- efree(params);
-}
-/* }}} */
-
-/* {{{ proto mixed call_user_method_array(string method_name, mixed object, array params)
- Call a user method on a specific object or class using a parameter array */
-PHP_FUNCTION(call_user_method_array)
-{
- zval **method_name,
- **obj,
- **params,
- ***method_args = NULL,
- *retval_ptr;
- HashTable *params_ar;
- int num_elems,
- element = 0;
-
- php_error(E_NOTICE, _CUM_DEPREC, "call_user_method_array");
-
- if (ZEND_NUM_ARGS() != 3 ||
- zend_get_parameters_ex(3, &method_name, &obj, &params) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(obj) != IS_OBJECT && Z_TYPE_PP(obj) != IS_STRING) {
- php_error(E_WARNING, "2nd argument is not an object or class name\n");
- RETURN_FALSE;
- }
-
- SEPARATE_ZVAL(method_name);
- SEPARATE_ZVAL(params);
- convert_to_string_ex(method_name);
- convert_to_array_ex(params);
-
- params_ar = HASH_OF(*params);
- num_elems = zend_hash_num_elements(params_ar);
- method_args = (zval ***)emalloc(sizeof(zval **) * num_elems);
-
- for (zend_hash_internal_pointer_reset(params_ar);
- zend_hash_get_current_data(params_ar, (void **)&(method_args[element])) == SUCCESS;
- zend_hash_move_forward(params_ar))
- element++;
-
- if (call_user_function_ex(EG(function_table), obj, *method_name, &retval_ptr, num_elems, method_args, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) {
- COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr);
- } else {
- php_error(E_WARNING, "Unable to call %s()", Z_STRVAL_PP(method_name));
- }
-
- efree(method_args);
-}
-/* }}} */
-
-void user_shutdown_function_dtor(php_shutdown_function_entry *shutdown_function_entry)
-{
- int i;
-
- for (i=0; i<shutdown_function_entry->arg_count; i++) {
- zval_ptr_dtor(&shutdown_function_entry->arguments[i]);
- }
- efree(shutdown_function_entry->arguments);
-}
-
-void user_tick_function_dtor(user_tick_function_entry *tick_function_entry)
-{
- int i;
-
- for (i = 0; i < tick_function_entry->arg_count; i++) {
- zval_ptr_dtor(&tick_function_entry->arguments[i]);
- }
- efree(tick_function_entry->arguments);
-}
-
-static int user_shutdown_function_call(php_shutdown_function_entry *shutdown_function_entry TSRMLS_DC)
-{
- zval retval;
-
- if (call_user_function(EG(function_table), NULL, shutdown_function_entry->arguments[0], &retval, shutdown_function_entry->arg_count-1, shutdown_function_entry->arguments+1 TSRMLS_CC)==SUCCESS) {
- zval_dtor(&retval);
- } else {
- php_error(E_WARNING, "Unable to call %s() - function does not exist",
- Z_STRVAL_P(shutdown_function_entry->arguments[0]));
- }
- return 0;
-}
-
-static void user_tick_function_call(user_tick_function_entry *tick_fe TSRMLS_DC)
-{
- zval retval;
- zval *function = tick_fe->arguments[0];
-
- if (call_user_function(EG(function_table), NULL, function, &retval,
- tick_fe->arg_count - 1, tick_fe->arguments+1 TSRMLS_CC) == SUCCESS) {
- zval_dtor(&retval);
- } else {
- zval **obj, **method;
-
- if (Z_TYPE_P(function) == IS_STRING) {
- php_error(E_WARNING, "Unable to call %s() - function does not exist",
- Z_STRVAL_P(function));
- } else if (Z_TYPE_P(function) == IS_ARRAY &&
- zend_hash_index_find(Z_ARRVAL_P(function), 0, (void **) &obj) == SUCCESS &&
- zend_hash_index_find(Z_ARRVAL_P(function), 1, (void **) &method) == SUCCESS &&
- Z_TYPE_PP(obj) == IS_OBJECT &&
- Z_TYPE_PP(method) == IS_STRING) {
- php_error(E_WARNING, "Unable to call %s::%s() - function does not exist",
- Z_OBJCE_PP(obj)->name, Z_STRVAL_PP(method));
- } else
- php_error(E_WARNING, "Unable to call tick function");
- }
-}
-
-static void run_user_tick_functions(int tick_count)
-{
- TSRMLS_FETCH();
-
- zend_llist_apply(BG(user_tick_functions), (llist_apply_func_t) user_tick_function_call TSRMLS_CC);
-}
-
-static int user_tick_function_compare(user_tick_function_entry *tick_fe1,
- user_tick_function_entry *tick_fe2)
-{
- zval *func1 = tick_fe1->arguments[0];
- zval *func2 = tick_fe2->arguments[0];
- TSRMLS_FETCH();
-
- if (Z_TYPE_P(func1) == IS_STRING && Z_TYPE_P(func2) == IS_STRING) {
- return (zend_binary_zval_strcmp(func1, func2) == 0);
- } else if (Z_TYPE_P(func1) == IS_ARRAY && Z_TYPE_P(func2) == IS_ARRAY) {
- zval result;
- zend_compare_arrays(&result, func1, func2 TSRMLS_CC);
- return (Z_LVAL(result) == 0);
- } else
- return 0;
-}
-
-void php_call_shutdown_functions(void)
-{
- TSRMLS_FETCH();
-
- if (BG(user_shutdown_function_names)) zend_try {
- zend_hash_apply(BG(user_shutdown_function_names), (apply_func_t) user_shutdown_function_call TSRMLS_CC);
- memcpy(&EG(bailout), &orig_bailout, sizeof(jmp_buf));
- zend_hash_destroy(BG(user_shutdown_function_names));
- efree(BG(user_shutdown_function_names));
- } zend_end_try();
-}
-
-/* {{{ proto void register_shutdown_function(string function_name)
- Register a user-level function to be called on request termination */
-PHP_FUNCTION(register_shutdown_function)
-{
- php_shutdown_function_entry shutdown_function_entry;
- int i;
-
- shutdown_function_entry.arg_count = ZEND_NUM_ARGS();
-
- if (shutdown_function_entry.arg_count<1) {
- WRONG_PARAM_COUNT;
- }
- shutdown_function_entry.arguments = (pval **) emalloc(sizeof(pval *)*shutdown_function_entry.arg_count);
-
- if (zend_get_parameters_array(ht, shutdown_function_entry.arg_count, shutdown_function_entry.arguments)==FAILURE) {
- RETURN_FALSE;
- }
- if (!BG(user_shutdown_function_names)) {
- ALLOC_HASHTABLE(BG(user_shutdown_function_names));
- zend_hash_init(BG(user_shutdown_function_names), 0, NULL, (void (*)(void *))user_shutdown_function_dtor, 0);
- }
-
- for (i=0; i<shutdown_function_entry.arg_count; i++) {
- shutdown_function_entry.arguments[i]->refcount++;
- }
- zend_hash_next_index_insert(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry), NULL);
-}
-/* }}} */
-
-
-ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini)
-{
- syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment");
- syntax_highlighter_ini->highlight_default = INI_STR("highlight.default");
- syntax_highlighter_ini->highlight_html = INI_STR("highlight.html");
- syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword");
- syntax_highlighter_ini->highlight_string = INI_STR("highlight.string");
-}
-
-
-/* {{{ proto bool highlight_file(string file_name)
- Syntax highlight a source file */
-PHP_FUNCTION(highlight_file)
-{
- pval **filename;
- zend_syntax_highlighter_ini syntax_highlighter_ini;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &filename)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- php_get_highlight_struct(&syntax_highlighter_ini);
-
- if (highlight_file(Z_STRVAL_PP(filename), &syntax_highlighter_ini TSRMLS_CC)==FAILURE) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-
-/* {{{ proto bool highlight_string(string string)
- Syntax highlight a string */
-PHP_FUNCTION(highlight_string)
-{
- pval **expr;
- zend_syntax_highlighter_ini syntax_highlighter_ini;
- char *hicompiled_string_description;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &expr)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(expr);
-
- php_get_highlight_struct(&syntax_highlighter_ini);
-
- hicompiled_string_description = zend_make_compiled_string_description("highlighted code" TSRMLS_CC);
-
- if (highlight_string(*expr, &syntax_highlighter_ini, hicompiled_string_description TSRMLS_CC)==FAILURE) {
- efree(hicompiled_string_description);
- RETURN_FALSE;
- }
- efree(hicompiled_string_description);
- 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 (Z_TYPE_P(overloaded_property)) {
- case OE_IS_ARRAY:
- printf("Array offset: ");
- break;
- case OE_IS_OBJECT:
- printf("Object property: ");
- break;
- }
- switch (Z_TYPE(overloaded_property->element)) {
- case IS_LONG:
- printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element));
- break;
- case IS_STRING:
- printf("'%s'\n", Z_STRVAL(overloaded_property->element));
- break;
- }
- pval_destructor(&overloaded_property->element);
- }
-
- Z_STRVAL(result) = estrndup("testing", 7);
- Z_STRLEN(result) = 7;
- Z_TYPE(result) = IS_STRING;
- return result;
-}
-
-
-int test_class_set_property(zend_property_reference *property_reference, pval *value)
-{
- zend_overloaded_element *overloaded_property;
- zend_llist_element *element;
-
- printf("Writing to a property from a OverloadedTestClass object:\n");
- printf("Writing '");
- zend_print_variable(value);
- printf("'\n");
-
- for (element=property_reference->elements_list->head; element; element=element->next) {
- overloaded_property = (zend_overloaded_element *) element->data;
- switch (Z_TYPE_P(overloaded_property)) {
- case OE_IS_ARRAY:
- printf("Array offset: ");
- break;
- case OE_IS_OBJECT:
- printf("Object property: ");
- break;
- }
- switch (Z_TYPE(overloaded_property->element)) {
- case IS_LONG:
- printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element));
- break;
- case IS_STRING:
- printf("'%s'\n", Z_STRVAL(overloaded_property->element));
- break;
- }
- pval_destructor(&overloaded_property->element);
- }
-
- return 0;
-}
-
-
-
-void test_class_call_function(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference)
-{
- zend_overloaded_element *overloaded_property;
- zend_llist_element *element;
-
-
- printf("Invoking a method on OverloadedTestClass object:\n");
-
- for (element=property_reference->elements_list->head; element; element=element->next) {
- overloaded_property = (zend_overloaded_element *) element->data;
- switch (Z_TYPE_P(overloaded_property)) {
- case OE_IS_ARRAY:
- printf("Array offset: ");
- break;
- case OE_IS_OBJECT:
- printf("Object property: ");
- break;
- case OE_IS_METHOD:
- printf("Overloaded method: ");
- }
- switch (Z_TYPE(overloaded_property->element)) {
- case IS_LONG:
- printf("%ld (numeric)\n", Z_LVAL(overloaded_property->element));
- break;
- case IS_STRING:
- printf("'%s'\n", Z_STRVAL(overloaded_property->element));
- break;
- }
- pval_destructor(&overloaded_property->element);
- }
-
- printf("%d arguments\n", ZEND_NUM_ARGS());
- RETVAL_STRING("testing", 1);
-}
-
-
-void test_class_startup(void)
-{
- zend_class_entry test_class_entry;
- TSRMLS_FETCH();
-
- INIT_OVERLOADED_CLASS_ENTRY(test_class_entry, "OverloadedTestClass", NULL,
- test_class_call_function,
- test_class_get_property,
- test_class_set_property);
-
- zend_register_internal_class(&test_class_entry TSRMLS_CC);
-}
-
-/* {{{ proto string ini_get(string varname)
- Get a configuration option */
-PHP_FUNCTION(ini_get)
-{
- pval **varname;
- char *str;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &varname)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(varname);
-
- str = php_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0);
-
- if (!str) {
- RETURN_FALSE;
- }
-
- RETURN_STRING(str, 1);
-}
-/* }}} */
-
-/* {{{ proto string ini_set(string varname, string newvalue)
- Set a configuration option, returns false on error and the old value of the configuration option on success */
-PHP_FUNCTION(ini_set)
-{
- pval **varname, **new_value;
- char *old_value;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &varname, &new_value)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(varname);
- convert_to_string_ex(new_value);
-
- old_value = php_ini_string(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, 0);
- /* copy to return here, because alter might free it! */
- if (old_value) {
- RETVAL_STRING(old_value, 1);
- } else {
- RETVAL_FALSE;
- }
-
- if (zend_alter_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, Z_STRVAL_PP(new_value), Z_STRLEN_PP(new_value), PHP_INI_USER, PHP_INI_STAGE_RUNTIME)==FAILURE) {
- zval_dtor(return_value);
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string ini_restore(string varname)
- Restore the value of a configuration option specified by varname */
-PHP_FUNCTION(ini_restore)
-{
- pval **varname;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &varname)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(varname);
-
- zend_restore_ini_entry(Z_STRVAL_PP(varname), Z_STRLEN_PP(varname)+1, PHP_INI_STAGE_RUNTIME);
-}
-/* }}} */
-
-/* {{{ proto bool print_r(mixed var)
- Prints out information about the specified variable */
-PHP_FUNCTION(print_r)
-{
- pval **expr;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &expr)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- zend_print_pval_r(*expr, 0);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-
-/* This should go back to PHP */
-
-/* {{{ proto int connection_aborted(void)
- Returns true if client disconnected */
-PHP_FUNCTION(connection_aborted)
-{
- RETURN_LONG(PG(connection_status)&PHP_CONNECTION_ABORTED);
-}
-/* }}} */
-
-/* {{{ proto int connection_status(void)
- Returns the connection status bitfield */
-PHP_FUNCTION(connection_status)
-{
- RETURN_LONG(PG(connection_status));
-}
-/* }}} */
-
-/* {{{ proto int ignore_user_abort(boolean value)
- Set whether we want to ignore a user abort event or not */
-PHP_FUNCTION(ignore_user_abort)
-{
- pval **arg;
- int old_setting;
-
- old_setting = PG(ignore_user_abort);
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 1:
- if (zend_get_parameters_ex(1, &arg) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_boolean_ex(arg);
- PG(ignore_user_abort) = (zend_bool) Z_LVAL_PP(arg);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- RETURN_LONG(old_setting);
-}
-/* }}} */
-
-/* {{{ proto int getservbyname(string service, string protocol)
- Returns port associated with service. Protocol must be "tcp" or "udp". */
-#if HAVE_GETSERVBYNAME
-PHP_FUNCTION(getservbyname)
-{
- pval **name, **proto;
- struct servent *serv;
-
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &name, &proto) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(name);
- convert_to_string_ex(proto);
-
- serv = getservbyname(Z_STRVAL_PP(name), Z_STRVAL_PP(proto));
-
- if(serv == NULL)
- RETURN_FALSE;
-
- RETURN_LONG(ntohs(serv->s_port));
-}
-#endif
-/* }}} */
-
-
-/* {{{ proto string getservbyport(int port, string protocol)
- Returns service name associated with port. Protocol must be "tcp" or "udp". */
-#if HAVE_GETSERVBYPORT
-PHP_FUNCTION(getservbyport)
-{
- pval **port, **proto;
- struct servent *serv;
-
- if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &port, &proto) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(port);
- convert_to_string_ex(proto);
-
- serv = getservbyport(htons((unsigned short) Z_LVAL_PP(port)), Z_STRVAL_PP(proto));
-
- if(serv == NULL)
- RETURN_FALSE;
-
- RETURN_STRING(serv->s_name, 1);
-}
-#endif
-/* }}} */
-
-
-/* {{{ proto int getprotobyname(string name)
- Returns protocol number associated with name as per /etc/protocols */
-#if HAVE_GETPROTOBYNAME
-PHP_FUNCTION(getprotobyname)
-{
- pval **name;
- struct protoent *ent;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &name) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(name);
-
- ent = getprotobyname(Z_STRVAL_PP(name));
-
- if(ent == NULL) {
- Z_LVAL_P(return_value) = -1;
- Z_TYPE_P(return_value) = IS_LONG;
- return;
- }
-
- RETURN_LONG(ent->p_proto);
-}
-#endif
-/* }}} */
-
-
-/* {{{ proto string getprotobynumber(int proto)
- Returns protocol name associated with protocol number proto */
-#if HAVE_GETPROTOBYNUMBER
-PHP_FUNCTION(getprotobynumber)
-{
- pval **proto;
- struct protoent *ent;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &proto) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(proto);
-
- ent = getprotobynumber(Z_LVAL_PP(proto));
-
- if(ent == NULL)
- RETURN_FALSE;
-
- RETURN_STRING(ent->p_name, 1);
-}
-#endif
-/* }}} */
-
-
-/* {{{ proto bool register_tick_function(string function_name [, mixed arg [, ... ]])
- Registers a tick callback function */
-PHP_FUNCTION(register_tick_function)
-{
- user_tick_function_entry tick_fe;
- int i;
-
- tick_fe.arg_count = ZEND_NUM_ARGS();
- if (tick_fe.arg_count < 1) {
- WRONG_PARAM_COUNT;
- }
-
- tick_fe.arguments = (zval **)emalloc(sizeof(zval *) * tick_fe.arg_count);
- if (zend_get_parameters_array(ht, tick_fe.arg_count, tick_fe.arguments) == FAILURE) {
- RETURN_FALSE;
- }
-
- if (Z_TYPE_P(tick_fe.arguments[0]) != IS_ARRAY)
- convert_to_string_ex(&tick_fe.arguments[0]);
-
- if (!BG(user_tick_functions)) {
- BG(user_tick_functions) = (zend_llist *)emalloc(sizeof(zend_llist));
- zend_llist_init(BG(user_tick_functions), sizeof(user_tick_function_entry),
- (void (*)(void *))user_tick_function_dtor, 0);
- php_add_tick_function(run_user_tick_functions);
- }
-
- for (i = 0; i < tick_fe.arg_count; i++) {
- tick_fe.arguments[i]->refcount++;
- }
-
- zend_llist_add_element(BG(user_tick_functions), &tick_fe);
-
- RETURN_TRUE;
-}
-/* }}} */
-
-
-/* {{{ proto void unregister_tick_function(string function_name)
- Unregisters a tick callback function */
-PHP_FUNCTION(unregister_tick_function)
-{
- zval **function;
- user_tick_function_entry tick_fe;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &function)) {
- WRONG_PARAM_COUNT;
- }
-
- if (Z_TYPE_PP(function) != IS_ARRAY)
- convert_to_string_ex(function);
-
- tick_fe.arguments = (zval **)emalloc(sizeof(zval *));
- tick_fe.arguments[0] = *function;
- tick_fe.arg_count = 1;
- zend_llist_del_element(BG(user_tick_functions), &tick_fe,
- (int(*)(void*, void*))user_tick_function_compare);
- efree(tick_fe.arguments);
-}
-/* }}} */
-
-
-/* This function is not directly accessible to end users */
-PHPAPI PHP_FUNCTION(warn_not_available)
-{
- php_error(E_WARNING, "%s() is not supported in this PHP build", get_active_function_name(TSRMLS_C));
- RETURN_FALSE;
-}
-
-
-/* {{{ proto bool is_uploaded_file(string path)
- check if file was created by rfc1867 upload */
-PHP_FUNCTION(is_uploaded_file)
-{
- zval **path;
-
- if (!SG(rfc1867_uploaded_files)) {
- RETURN_FALSE;
- }
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)!=SUCCESS) {
- ZEND_WRONG_PARAM_COUNT();
- }
- convert_to_string_ex(path);
-
- if (zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto bool move_uploaded_file(string path, string new_path)
- move a file if and only if it was created by an upload */
-PHP_FUNCTION(move_uploaded_file)
-{
- zval **path, **new_path;
- zend_bool successful=0;
-
- if (!SG(rfc1867_uploaded_files)) {
- RETURN_FALSE;
- }
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &path, &new_path)!=SUCCESS) {
- ZEND_WRONG_PARAM_COUNT();
- }
- convert_to_string_ex(path);
- convert_to_string_ex(new_path);
-
- if (!zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1)) {
- RETURN_FALSE;
- }
-
- if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(new_path), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
-
- VCWD_UNLINK(Z_STRVAL_PP(new_path));
- if (rename(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path))==0) {
- successful=1;
- } else if (php_copy_file(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path) TSRMLS_CC)==SUCCESS) {
- VCWD_UNLINK(Z_STRVAL_PP(path));
- successful=1;
- }
-
- if (successful) {
- zend_hash_del(SG(rfc1867_uploaded_files), Z_STRVAL_PP(path), Z_STRLEN_PP(path)+1);
- } else {
- php_error(E_WARNING, "Unable to move '%s' to '%s'", Z_STRVAL_PP(path), Z_STRVAL_PP(new_path));
- }
- RETURN_BOOL(successful);
-}
-/* }}} */
-
-
-
-static void php_simple_ini_parser_cb(zval *arg1, zval *arg2, int callback_type, zval *arr)
-{
- zval *element;
-
- switch (callback_type) {
- case ZEND_INI_PARSER_ENTRY:
- ALLOC_ZVAL(element);
- *element = *arg2;
- zval_copy_ctor(element);
- INIT_PZVAL(element);
- zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
- break;
- case ZEND_INI_PARSER_SECTION:
- break;
- }
-}
-
-
-static void php_ini_parser_cb_with_sections(zval *arg1, zval *arg2, int callback_type, zval *arr)
-{
- zval *element;
- TSRMLS_FETCH();
-
- switch (callback_type) {
- case ZEND_INI_PARSER_ENTRY: {
- zval *active_arr;
-
- if (BG(active_ini_file_section)) {
- active_arr = BG(active_ini_file_section);
- } else {
- active_arr = arr;
- }
- ALLOC_ZVAL(element);
- *element = *arg2;
- zval_copy_ctor(element);
- INIT_PZVAL(element);
- zend_hash_update(Z_ARRVAL_P(active_arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &element, sizeof(zval *), NULL);
- }
- break;
- case ZEND_INI_PARSER_SECTION:
- MAKE_STD_ZVAL(BG(active_ini_file_section));
- array_init(BG(active_ini_file_section));
- zend_hash_update(Z_ARRVAL_P(arr), Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, &BG(active_ini_file_section), sizeof(zval *), NULL);
- break;
- }
-}
-
-
-/* {{{ proto array parse_ini_file(string filename [, boolean process_sections])
- Parse configuration file */
-PHP_FUNCTION(parse_ini_file)
-{
- zval **filename, **process_sections;
- zend_file_handle fh;
- zend_ini_parser_cb_t ini_parser_cb;
-
- switch (ARG_COUNT(ht)) {
- case 1:
- if (zend_get_parameters_ex(1, &filename)==FAILURE) {
- RETURN_FALSE;
- }
- ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
- break;
- case 2:
- if (zend_get_parameters_ex(2, &filename, &process_sections)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_boolean_ex(process_sections);
- if (Z_BVAL_PP(process_sections)) {
- TSRMLS_FETCH();
-
- BG(active_ini_file_section) = NULL;
- ini_parser_cb = (zend_ini_parser_cb_t) php_ini_parser_cb_with_sections;
- } else {
- ini_parser_cb = (zend_ini_parser_cb_t) php_simple_ini_parser_cb;
- }
- break;
- default:
- ZEND_WRONG_PARAM_COUNT();
- break;
- }
-
- convert_to_string_ex(filename);
- fh.handle.fp = VCWD_FOPEN(Z_STRVAL_PP(filename), "r");
- if (!fh.handle.fp) {
- php_error(E_WARNING, "Cannot open '%s' for reading", Z_STRVAL_PP(filename));
- return;
- }
- Z_TYPE(fh) = ZEND_HANDLE_FP;
- fh.filename = Z_STRVAL_PP(filename);
- array_init(return_value);
- zend_parse_ini_file(&fh, 0, ini_parser_cb, return_value);
-}
-/* }}} */
-
-
-/* {{{ proto bool is_callable(mixed var [, bool syntax_only [, string callable_name ]]) */
-PHP_FUNCTION(is_callable)
-{
- zval **var, **syntax_only, **callable_name;
- char *name;
- zend_bool retval;
- zend_bool syntax = 0;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 3 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &var, &syntax_only, &callable_name) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (ZEND_NUM_ARGS() > 1) {
- convert_to_boolean_ex(syntax_only);
- syntax = Z_BVAL_PP(syntax_only);
- }
-
- if (ZEND_NUM_ARGS() > 2) {
- retval = zend_is_callable(*var, syntax, &name);
- zval_dtor(*callable_name);
- ZVAL_STRING(*callable_name, name, 0);
- } else
- retval = zend_is_callable(*var, syntax, NULL);
-
- RETURN_BOOL(retval);
-}
-/* }}} */
-
-
-static int copy_request_variable(void *pDest, int num_args, va_list args, zend_hash_key *hash_key)
-{
- char *prefix, *new_key;
- uint prefix_len, new_key_len;
- zval **var = (zval **) pDest;
- TSRMLS_FETCH();
-
- if (num_args!=2) {
- return 0;
- }
-
- prefix = va_arg(args, char *);
- prefix_len = va_arg(args, uint);
-
- new_key_len = prefix_len + hash_key->nKeyLength;
- new_key = (char *) emalloc(new_key_len);
-
- memcpy(new_key, prefix, prefix_len);
- memcpy(new_key+prefix_len, hash_key->arKey, hash_key->nKeyLength);
-
- ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), new_key, new_key_len, *var, 0, 1);
-
- efree(new_key);
-
- return 0;
-}
-
-
-/* {{{ proto bool import_request_variables(string types, string prefix)
- Import GET/POST/Cookie variables into the global scope */
-PHP_FUNCTION(import_request_variables)
-{
- zval **z_types, **z_prefix;
- char *types, *prefix;
- uint prefix_len;
- char *p;
-
- switch (ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &z_types)==FAILURE) {
- RETURN_FALSE;
- }
- prefix = "";
- prefix_len = 0;
- break;
- case 2:
- if (zend_get_parameters_ex(2, &z_types, &z_prefix)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(z_prefix);
- prefix = Z_STRVAL_PP(z_prefix);
- prefix_len = Z_STRLEN_PP(z_prefix);
- break;
- default:
- ZEND_WRONG_PARAM_COUNT();
- }
-
- if (prefix_len==0) {
- zend_error(E_NOTICE, "No prefix specified in %s() - possible security hazard", get_active_function_name(TSRMLS_C));
- }
-
- convert_to_string_ex(z_types);
- types = Z_STRVAL_PP(z_types);
-
- for (p=types; p && *p; p++) {
- switch (*p) {
- case 'g':
- case 'G':
- zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_GET]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
- break;
- case 'p':
- case 'P':
- zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_POST]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
- zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_FILES]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
- break;
- case 'c':
- case 'C':
- zend_hash_apply_with_arguments(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_COOKIE]), (apply_func_args_t) copy_request_variable, 2, prefix, prefix_len);
- break;
- }
- }
-}
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h
deleted file mode 100644
index 6001628b66..0000000000
--- a/ext/standard/basic_functions.h
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef BASIC_FUNCTIONS_H
-#define BASIC_FUNCTIONS_H
-
-#include <sys/stat.h>
-
-#include "zend_highlight.h"
-
-#ifdef TRANS_SID
-# include "url_scanner.h"
-# include "url_scanner_ex.h"
-#endif
-
-extern zend_module_entry basic_functions_module;
-#define basic_functions_module_ptr &basic_functions_module
-
-PHP_MINIT_FUNCTION(basic);
-PHP_MSHUTDOWN_FUNCTION(basic);
-PHP_RINIT_FUNCTION(basic);
-PHP_RSHUTDOWN_FUNCTION(basic);
-PHP_MINFO_FUNCTION(basic);
-
-PHP_FUNCTION(constant);
-PHP_FUNCTION(intval);
-PHP_FUNCTION(doubleval);
-PHP_FUNCTION(strval);
-PHP_FUNCTION(toggle_short_open_tag);
-PHP_FUNCTION(sleep);
-PHP_FUNCTION(usleep);
-PHP_FUNCTION(flush);
-PHP_FUNCTION(gettype);
-PHP_FUNCTION(settype);
-PHP_FUNCTION(ip2long);
-PHP_FUNCTION(long2ip);
-
-/* system functions */
-PHP_FUNCTION(getenv);
-PHP_FUNCTION(putenv);
-
-PHP_FUNCTION(get_current_user);
-PHP_FUNCTION(set_time_limit);
-
-PHP_FUNCTION(get_cfg_var);
-PHP_FUNCTION(set_magic_quotes_runtime);
-PHP_FUNCTION(get_magic_quotes_runtime);
-PHP_FUNCTION(get_magic_quotes_gpc);
-
-void php_is_type(INTERNAL_FUNCTION_PARAMETERS, int type);
-PHP_FUNCTION(is_null);
-PHP_FUNCTION(is_resource);
-PHP_FUNCTION(is_bool);
-PHP_FUNCTION(is_long);
-PHP_FUNCTION(is_double);
-PHP_FUNCTION(is_numeric);
-PHP_FUNCTION(is_string);
-PHP_FUNCTION(is_array);
-PHP_FUNCTION(is_object);
-PHP_FUNCTION(is_scalar);
-PHP_FUNCTION(is_callable);
-PHP_FUNCTION(import_request_variables);
-
-PHP_FUNCTION(error_log);
-
-PHP_FUNCTION(call_user_func);
-PHP_FUNCTION(call_user_func_array);
-PHP_FUNCTION(call_user_method);
-PHP_FUNCTION(call_user_method_array);
-
-PHP_FUNCTION(register_shutdown_function);
-PHP_FUNCTION(highlight_file);
-PHP_FUNCTION(highlight_string);
-ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini);
-
-PHP_FUNCTION(ini_get);
-PHP_FUNCTION(ini_set);
-PHP_FUNCTION(ini_restore);
-
-PHP_FUNCTION(print_r);
-
-PHP_FUNCTION(connection_aborted);
-PHP_FUNCTION(connection_status);
-PHP_FUNCTION(ignore_user_abort);
-
-PHP_FUNCTION(getservbyname);
-PHP_FUNCTION(getservbyport);
-PHP_FUNCTION(getprotobyname);
-PHP_FUNCTION(getprotobynumber);
-
-PHP_NAMED_FUNCTION(php_if_crc32);
-
-PHP_FUNCTION(register_tick_function);
-PHP_FUNCTION(unregister_tick_function);
-
-PHP_FUNCTION(is_uploaded_file);
-PHP_FUNCTION(move_uploaded_file);
-
-/* From the INI parser */
-PHP_FUNCTION(parse_ini_file);
-
-#ifdef PHP_WIN32
-typedef unsigned int php_stat_len;
-#else
-typedef int php_stat_len;
-#endif
-
-PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers TSRMLS_DC);
-
-#if SIZEOF_INT == 4
-/* Most 32-bit and 64-bit systems have 32-bit ints */
-typedef unsigned int php_uint32;
-typedef signed int php_int32;
-#elif SIZEOF_LONG == 4
-/* 16-bit systems? */
-typedef unsigned long php_uint32;
-typedef signed int php_int32;
-#else
-#error Need type which holds 32 bits
-#endif
-
-#define MT_N (624)
-
-typedef struct {
- HashTable *user_shutdown_function_names;
- HashTable putenv_ht;
- zval *strtok_zval;
- char *strtok_string;
- char *locale_string;
- char *strtok_last;
- char strtok_table[256];
- ulong strtok_len;
- char str_ebuf[40];
- zval **array_walk_func_name;
- zval **user_compare_func_name;
- zend_llist *user_tick_functions;
-
- zval *active_ini_file_section;
-
- HashTable sm_protected_env_vars;
- char *sm_allowed_env_vars;
-
- /* pageinfo.c */
- long page_uid;
- long page_gid;
- long page_inode;
- long page_mtime;
-
- /* filestat.c */
- char *CurrentStatFile;
- php_stat_len CurrentStatLength;
- struct stat sb;
- struct stat lsb;
-
- /* rand.c */
- php_uint32 state[MT_N+1]; /* state vector + 1 extra to not violate ANSI C */
- php_uint32 *next; /* next random value is computed from here */
- int left; /* can *next++ this many times before reloading */
-
- /* syslog.c */
- int syslog_started;
- char *syslog_device;
-
- /* var.c */
- zend_class_entry *incomplete_class;
- zend_bool use_trans_sid;
-
-#ifdef TRANS_SID
- /* url_scanner.c */
- url_adapt_state_t url_adapt_state;
- /* url_scanner_ex.re */
- url_adapt_state_ex_t url_adapt_state_ex;
-#endif
-
-#ifdef HAVE_MMAP
- void *mmap_file;
- size_t mmap_len;
-#endif
-} php_basic_globals;
-
-#ifdef ZTS
-#define BG(v) TSRMG(basic_globals_id, php_basic_globals *, v)
-extern int basic_globals_id;
-#else
-#define BG(v) (basic_globals.v)
-extern php_basic_globals basic_globals;
-#endif
-
-#if HAVE_PUTENV
-typedef struct {
- char *putenv_string;
- char *previous_value;
- char *key;
- int key_len;
-} putenv_entry;
-#endif
-
-/* Values are comma-delimited
- */
-#define SAFE_MODE_PROTECTED_ENV_VARS "LD_LIBRARY_PATH"
-#define SAFE_MODE_ALLOWED_ENV_VARS "PHP_"
-
-#endif /* BASIC_FUNCTIONS_H */
diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c
deleted file mode 100644
index ac6923171a..0000000000
--- a/ext/standard/browscap.c
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_regex.h"
-#include "php_browscap.h"
-#include "php_ini.h"
-
-#include "zend_globals.h"
-
-static HashTable browser_hash;
-static zval *current_section;
-
-#define DEFAULT_SECTION_NAME "Default Browser Capability Settings"
-
-/* OBJECTS_FIXME: This whole extension needs going through. The use of objects looks pretty broken here */
-
-static void browscap_entry_dtor(zval *pvalue)
-{
- if (pvalue->type == IS_OBJECT) {
- zend_hash_destroy(Z_OBJPROP_P(pvalue));
- free(Z_OBJPROP_P(pvalue));
- }
-}
-
-/* {{{ convert_browscap_pattern
- */
-static void convert_browscap_pattern(zval *pattern)
-{
- register int i, j;
- char *t;
-
- for (i=0; i<pattern->value.str.len; i++) {
- if (pattern->value.str.val[i]=='*' || pattern->value.str.val[i]=='?' || pattern->value.str.val[i]=='.') {
- break;
- }
- }
-
- if (i==pattern->value.str.len) { /* no wildcards */
- pattern->value.str.val = zend_strndup(pattern->value.str.val, pattern->value.str.len);
- return;
- }
-
- t = (char *) malloc(pattern->value.str.len*2);
-
- for (i=0, j=0; i<pattern->value.str.len; i++, j++) {
- switch (pattern->value.str.val[i]) {
- case '?':
- t[j] = '.';
- break;
- case '*':
- t[j++] = '.';
- t[j] = '*';
- break;
- case '.':
- t[j++] = '\\';
- t[j] = '.';
- break;
- default:
- t[j] = pattern->value.str.val[i];
- break;
- }
- }
- t[j]=0;
- pattern->value.str.val = t;
- pattern->value.str.len = j;
-}
-/* }}} */
-
-/* {{{ php_browscap_parser_cb
- */
-static void php_browscap_parser_cb(zval *arg1, zval *arg2, int callback_type, void *arg)
-{
- switch (callback_type) {
- case ZEND_INI_PARSER_ENTRY:
- if (current_section) {
- zval *new_property;
- char *new_key;
-
- new_property = (zval *) malloc(sizeof(zval));
- INIT_PZVAL(new_property);
- new_property->value.str.val = Z_STRLEN_P(arg2)?zend_strndup(Z_STRVAL_P(arg2), Z_STRLEN_P(arg2)):"";
- new_property->value.str.len = Z_STRLEN_P(arg2);
- new_property->type = IS_STRING;
-
- new_key = zend_strndup(Z_STRVAL_P(arg1), Z_STRLEN_P(arg1));
- zend_str_tolower(new_key, Z_STRLEN_P(arg1));
- zend_hash_update(Z_OBJPROP_P(current_section), new_key, Z_STRLEN_P(arg1)+1, &new_property, sizeof(zval *), NULL);
- free(new_key);
- }
- break;
- case ZEND_INI_PARSER_SECTION: {
- zval *processed;
-
- /*printf("'%s' (%d)\n",$1.value.str.val,$1.value.str.len+1);*/
- current_section = (zval *) malloc(sizeof(zval));
- INIT_PZVAL(current_section);
- processed = (zval *) malloc(sizeof(zval));
- INIT_PZVAL(processed);
-
- /* OBJECTS_FIXME */
- Z_OBJCE_P(current_section) = &zend_standard_class_def;
- Z_OBJPROP_P(current_section) = (HashTable *) malloc(sizeof(HashTable));
- current_section->type = IS_OBJECT;
- zend_hash_init(Z_OBJPROP_P(current_section), 0, NULL, (dtor_func_t) browscap_entry_dtor, 1);
- zend_hash_update(&browser_hash, Z_STRVAL_P(arg1), Z_STRLEN_P(arg1)+1, (void *) &current_section, sizeof(zval *), NULL);
-
- processed->value.str.val = Z_STRVAL_P(arg1);
- processed->value.str.len = Z_STRLEN_P(arg1);
- processed->type = IS_STRING;
- convert_browscap_pattern(processed);
- zend_hash_update(Z_OBJPROP_P(current_section), "browser_name_pattern", sizeof("browser_name_pattern"), (void *) &processed, sizeof(zval *), NULL);
- }
- break;
- }
-}
-/* }}} */
-
-/* {{{ PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(browscap)
-{
- char *browscap = INI_STR("browscap");
-
- if (browscap) {
- zend_file_handle fh;
-
- if (zend_hash_init(&browser_hash, 0, NULL, (dtor_func_t) browscap_entry_dtor, 1)==FAILURE) {
- return FAILURE;
- }
-
- fh.handle.fp = VCWD_FOPEN(browscap, "r");
- if (!fh.handle.fp) {
- php_error(E_CORE_WARNING, "Cannot open '%s' for reading", browscap);
- return FAILURE;
- }
- fh.filename = browscap;
- fh.type = ZEND_HANDLE_FP;
- zend_parse_ini_file(&fh, 1, (zend_ini_parser_cb_t) php_browscap_parser_cb, &browser_hash);
- }
-
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ PHP_MSHUTDOWN_FUNCTION
- */
-PHP_MSHUTDOWN_FUNCTION(browscap)
-{
- if (INI_STR("browscap")) {
- zend_hash_destroy(&browser_hash);
- }
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ browser_reg_compare
- */
-static int browser_reg_compare(zval **browser, int num_args, va_list args, zend_hash_key *key)
-{
- zval **browser_name;
- regex_t r;
- char *lookup_browser_name = va_arg(args, char *);
- zval **found_browser_entry = va_arg(args, zval **);
-
- if (*found_browser_entry) { /* already found */
- return 0;
- }
- if(zend_hash_find(Z_OBJPROP_PP(browser), "browser_name_pattern", sizeof("browser_name_pattern"), (void **) &browser_name) == FAILURE) {
- return 0;
- }
-
- if (!strchr((*browser_name)->value.str.val,'*')) {
- return 0;
- }
- if (regcomp(&r, (*browser_name)->value.str.val, REG_NOSUB)!=0) {
- return 0;
- }
- if (regexec(&r, lookup_browser_name, 0, NULL, 0)==0) {
- *found_browser_entry = *browser;
- }
- regfree(&r);
- return 0;
-}
-/* }}} */
-
-/* {{{ proto object get_browser(string browser_name)
- Get information about the capabilities of a browser */
-PHP_FUNCTION(get_browser)
-{
- zval **agent_name, **agent;
- zval *found_browser_entry, *tmp_copy;
- char *lookup_browser_name;
-
- if (!INI_STR("browscap")) {
- RETURN_FALSE;
- }
-
- switch(ZEND_NUM_ARGS()) {
- case 0:
- if (!PG(http_globals)[TRACK_VARS_SERVER]
- || zend_hash_find(PG(http_globals)[TRACK_VARS_SERVER]->value.ht, "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &agent_name)==FAILURE) {
- zend_error(E_WARNING, "HTTP_USER_AGENT variable is not set, cannot determine user agent name");
- RETURN_FALSE;
- }
- break;
- case 1:
- if (zend_get_parameters_ex(1, &agent_name)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- convert_to_string_ex(agent_name);
-
- if (zend_hash_find(&browser_hash, (*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_with_arguments(&browser_hash, (apply_func_args_t) browser_reg_compare, 2, lookup_browser_name, &found_browser_entry);
-
- if (found_browser_entry) {
- agent = &found_browser_entry;
- } else if (zend_hash_find(&browser_hash, DEFAULT_SECTION_NAME, sizeof(DEFAULT_SECTION_NAME), (void **) &agent)==FAILURE) {
- RETURN_FALSE;
- }
- }
-
- object_init(return_value);
- zend_hash_copy(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *));
-
- while (zend_hash_find(Z_OBJPROP_PP(agent), "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) {
-
- if (zend_hash_find(&browser_hash, (*agent_name)->value.str.val, (*agent_name)->value.str.len+1, (void **)&agent)==FAILURE) {
- break;
- }
-
- zend_hash_merge(Z_OBJPROP_P(return_value), Z_OBJPROP_PP(agent), (copy_ctor_func_t) zval_add_ref, (void *) &tmp_copy, sizeof(zval *), 0);
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/config.m4 b/ext/standard/config.m4
deleted file mode 100644
index cdfa5269dc..0000000000
--- a/ext/standard/config.m4
+++ /dev/null
@@ -1,232 +0,0 @@
-dnl $Id$ -*- sh -*-
-
-divert(3)dnl
-
-dnl
-dnl Check if flush should be called explicitly after buffered io
-dnl
-AC_DEFUN(AC_FLUSH_IO,[
- AC_CACHE_CHECK([whether flush should be called explicitly after a bufferered io], ac_cv_flush_io,[
- AC_TRY_RUN( [
-#include <stdio.h>
-#include <stdlib.h>
-
-int main(int argc, char **argv)
-{
- char *filename = tmpnam(NULL);
- char buffer[64];
- int result = 0;
-
- FILE *fp = fopen(filename, "wb");
- if (NULL == fp)
- return 0;
- fputs("line 1\n", fp);
- fputs("line 2\n", fp);
- fclose(fp);
-
- fp = fopen(filename, "rb+");
- if (NULL == fp)
- return 0;
- fgets(buffer, sizeof(buffer), fp);
- fputs("line 3\n", fp);
- rewind(fp);
- fgets(buffer, sizeof(buffer), fp);
- if (0 != strcmp(buffer, "line 1\n"))
- result = 1;
- fgets(buffer, sizeof(buffer), fp);
- if (0 != strcmp(buffer, "line 3\n"))
- result = 1;
- fclose(fp);
- unlink(filename);
-
- exit(result);
-}
-],[
- ac_cv_flush_io=no
-],[
- ac_cv_flush_io=yes
-],[
- ac_cv_flush_io=no
-])])
- if test "$ac_cv_flush_io" = "yes"; then
- AC_DEFINE(HAVE_FLUSHIO, 1, [Define if flush should be called explicitly after a buffered io.])
- fi
-])
-
-dnl
-dnl Check for crypt() capabilities
-dnl
-AC_DEFUN(AC_CRYPT_CAP,[
-
- AC_CACHE_CHECK(for standard DES crypt, ac_cv_crypt_des,[
- AC_TRY_RUN([
-#if HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-
-main() {
-#if HAVE_CRYPT
- exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M"));
-#else
- exit(0);
-#endif
-}],[
- ac_cv_crypt_des=yes
- ],[
- ac_cv_crypt_des=no
- ],[
- ac_cv_crypt_des=yes
- ])
- ])
- if test "$ac_cv_crypt_des" = "yes"; then
- ac_result=1
- else
- ac_result=0
- fi
- AC_DEFINE_UNQUOTED(PHP_STD_DES_CRYPT, $ac_result, [Whether the system supports standard DES salt])
-
- AC_CACHE_CHECK(for extended DES crypt, ac_cv_crypt_ext_des,[
- AC_TRY_RUN([
-#if HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-
-main() {
-#if HAVE_CRYPT
- exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc"));
-#else
- exit(0);
-#endif
-}],[
- ac_cv_crypt_ext_des=yes
- ],[
- ac_cv_crypt_ext_des=no
- ],[
- ac_cv_crypt_ext_des=no
- ])
- ])
- if test "$ac_cv_crypt_ext_des" = "yes"; then
- ac_result=1
- else
- ac_result=0
- fi
- AC_DEFINE_UNQUOTED(PHP_EXT_DES_CRYPT, $ac_result, [Whether the system supports extended DES salt])
-
- AC_CACHE_CHECK(for MD5 crypt, ac_cv_crypt_md5,[
- AC_TRY_RUN([
-#if HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-
-main() {
-#if HAVE_CRYPT
- char salt[15], answer[40];
-
- salt[0]='$'; salt[1]='1'; salt[2]='$';
- salt[3]='r'; salt[4]='a'; salt[5]='s';
- salt[6]='m'; salt[7]='u'; salt[8]='s';
- salt[9]='l'; salt[10]='e'; salt[11]='$';
- salt[12]='\0';
- strcpy(answer,salt);
- strcat(answer,"rISCgZzpwk3UhDidwXvin0");
- exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
-#else
- exit(0);
-#endif
-}],[
- ac_cv_crypt_md5=yes
- ],[
- ac_cv_crypt_md5=no
- ],[
- ac_cv_crypt_md5=no
- ])
- ])
- if test "$ac_cv_crypt_md5" = "yes"; then
- ac_result=1
- else
- if test "$ac_cv_crypt_des" != "yes"; then
- PHP_DEBUG_MACRO(debug.log)
- fi
- ac_result=0
- fi
- AC_DEFINE_UNQUOTED(PHP_MD5_CRYPT, $ac_result, [Whether the system supports MD5 salt])
-
- AC_CACHE_CHECK(for Blowfish crypt, ac_cv_crypt_blowfish,[
- AC_TRY_RUN([
-#if HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-
-main() {
-#if HAVE_CRYPT
- char salt[30], answer[70];
-
- salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0';
- strcat(salt,"rasmuslerd............");
- strcpy(answer,salt);
- strcpy(&answer[29],"nIdrcHdxcUxWomQX9j6kvERCFjTg7Ra");
- exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
-#else
- exit(0);
-#endif
-}],[
- ac_cv_crypt_blowfish=yes
- ],[
- ac_cv_crypt_blowfish=no
- ],[
- ac_cv_crypt_blowfish=no
- ])
- ])
- if test "$ac_cv_crypt_blowfish" = "yes"; then
- ac_result=1
- else
- ac_result=0
- fi
- AC_DEFINE_UNQUOTED(PHP_BLOWFISH_CRYPT, $ac_result, [Whether the system supports BlowFish salt])
-])
-
-AC_CHECK_FUNC(dlopen, [AC_DEFINE(HAVE_LIBDL,1,[ ])])
-
-AC_CHECK_LIB(pam, pam_start, [
- EXTRA_LIBS="$EXTRA_LIBS -lpam"
- AC_DEFINE(HAVE_LIBPAM,1,[ ]) ], [])
-
-AC_CHECK_FUNCS(getcwd getwd)
-
-AC_CRYPT_CAP
-AC_FLUSH_IO
-
-divert(5)dnl
-
-AC_ARG_WITH(regex,
-[ --with-regex=TYPE regex library type: system, apache, php],
-[
- case $withval in
- system)
- REGEX_TYPE=system
- ;;
- apache)
- REGEX_TYPE=apache
- ;;
- php)
- REGEX_TYPE=php
- ;;
- *)
- REGEX_TYPE=php
- AC_MSG_WARN(Invalid regex library type. Using default value: php)
- ;;
- esac
-],[
- REGEX_TYPE=php
-])
-
-AC_ARG_WITH(system-regex,
-[ --with-system-regex (deprecated) Use system regex library],[
- if test "$withval" = "yes"; then
- REGEX_TYPE=system
- else
- REGEX_TYPE=php
- fi
-])
-
-PHP_EXTENSION(standard)
diff --git a/ext/standard/crc32.c b/ext/standard/crc32.c
deleted file mode 100644
index 86fe56cccc..0000000000
--- a/ext/standard/crc32.c
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "basic_functions.h"
-
-/*
- * This code implements the AUTODIN II polynomial
- * The variable corresponding to the macro argument "crc" should
- * be an unsigned long.
- * Oroginal code by Spencer Garrett <srg@quick.com>
- */
-
-#define CRC32(crc, ch) (crc = (crc >> 8) ^ crc32tab[(crc ^ (ch)) & 0xff])
-
-/* generated using the AUTODIN II polynomial
- * x^32 + x^26 + x^23 + x^22 + x^16 +
- * x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + 1
- */
-
-static const unsigned int crc32tab[256] = {
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
- 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
- 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
- 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940,
- 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116,
- 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a,
- 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818,
- 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c,
- 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
- 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086,
- 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4,
- 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
- 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe,
- 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252,
- 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60,
- 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04,
- 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
- 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e,
- 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
- 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0,
- 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6,
- 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
-};
-
-/* {{{ proto string crc32(string str)
- Calculate the crc32 polynomial of a string */
-PHP_NAMED_FUNCTION(php_if_crc32)
-{
- pval **arg;
- unsigned int crc = ~0;
- char *p ;
- int len, nr ;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- len = 0 ;
- nr=(*arg)->value.str.len;
- p = (*arg)->value.str.val;
- for (len += nr; nr--; ++p) {
- CRC32(crc, *p);
- }
- RETVAL_LONG(~crc);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/credits.c b/ext/standard/credits.c
deleted file mode 100644
index 2f2417385a..0000000000
--- a/ext/standard/credits.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "info.h"
-
-#define CREDIT_LINE(module, authors) php_info_print_table_row(2, module, authors)
-
-/* {{{ php_print_credits
- */
-PHPAPI void php_print_credits(int flag)
-{
- TSRMLS_FETCH();
-
- if (flag & PHP_CREDITS_FULLPAGE) {
- PUTS("<html><head><title>PHP Credits</title></head><body>\n");
- }
-
- php_info_print_style();
-
- PUTS("<h1 align=\"center\">PHP 4.0 Credits</h1>\n");
-
- if (flag & PHP_CREDITS_GROUP) {
- /* Group */
-
- php_info_print_table_start();
- php_info_print_table_header(1, "PHP Group");
- php_info_print_table_row(1, "Thies C. Arntzen, Stig Bakken, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski");
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_GENERAL) {
- /* Design & Concept */
- php_info_print_table_start();
- php_info_print_table_header(1, "Language Design & Concept");
- php_info_print_table_row(1, "Andi Gutmans, Rasmus Lerdorf, Zeev Suraski");
- php_info_print_table_end();
-
- /* PHP 4.0 Language */
- php_info_print_table_start();
- php_info_print_table_colspan_header(2, "PHP 4.0 Authors");
- php_info_print_table_header(2, "Contribution", "Authors");
- CREDIT_LINE("Zend Scripting Language Engine", "Andi Gutmans, Zeev Suraski");
- CREDIT_LINE("Extension Module API", "Andi Gutmans, Zeev Suraski, Andrei Zmievski");
- CREDIT_LINE("UNIX Build and Modularization", "Stig Bakken, Sascha Schumann");
- CREDIT_LINE("Win32 Port", "Shane Caraveo, Zeev Suraski");
- CREDIT_LINE("Server API (SAPI) Abstraction Layer", "Andi Gutmans, Shane Caraveo, Zeev Suraski");
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_SAPI) {
- /* SAPI Modules */
-
- php_info_print_table_start();
- php_info_print_table_colspan_header(2, "SAPI Modules");
- php_info_print_table_header(2, "Contribution", "Authors");
-#include "credits_sapi.h"
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_MODULES) {
- /* Modules */
-
- php_info_print_table_start();
- php_info_print_table_colspan_header(2, "Module Authors");
- php_info_print_table_header(2, "Module", "Authors");
-#include "credits_ext.h"
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_DOCS) {
- php_info_print_table_start();
- php_info_print_table_header(1, "PHP Documentation Team");
- php_info_print_table_row(1, "Jouni Ahto, Alexander Aulbach, Stig Bakken, Rasmus Lerdorf, Egon Schmid, Zeev Suraski, Lars Torben Wilson, Jim Winstead");
- php_info_print_table_row(1, "Edited by: Stig Bakken and Egon Schmid");
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_QA) {
- php_info_print_table_start();
- php_info_print_table_header(1, "PHP Quality Assurance Team");
- php_info_print_table_row(1, "Andre Langhorst, Hellekin O. Wolf, Jalal Pushman, James Moore, Jani Taskinen, Joey Smith, Olivier Cahagne, Phil Driscoll, Sebastian Bergmann, Zak Greant");
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_WEB) {
- /* Website Team */
- php_info_print_table_start();
- php_info_print_table_header(1, "PHP Website Team");
- php_info_print_table_row(1, "Hojtsy Gabor, Colin Viebrock, Jim Winstead");
- php_info_print_table_end();
- }
-
- if (flag & PHP_CREDITS_FULLPAGE) {
- PUTS("</body></html>\n");
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/credits.h b/ext/standard/credits.h
deleted file mode 100644
index 04210ac927..0000000000
--- a/ext/standard/credits.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef CREDITS_H
-#define CREDITS_H
-
-#ifndef HAVE_CREDITS_DEFS
-#define HAVE_CREDITS_DEFS
-
-#define PHP_CREDITS_GROUP (1<<0)
-#define PHP_CREDITS_GENERAL (1<<1)
-#define PHP_CREDITS_SAPI (1<<2)
-#define PHP_CREDITS_MODULES (1<<3)
-#define PHP_CREDITS_DOCS (1<<4)
-#define PHP_CREDITS_FULLPAGE (1<<5)
-#define PHP_CREDITS_QA (1<<6)
-#define PHP_CREDITS_WEB (1<<7)
-#define PHP_CREDITS_ALL 0xFFFFFFFF
-
-#endif /* HAVE_CREDITS_DEFS */
-
-PHPAPI void php_print_credits(int flag);
-
-#endif
diff --git a/ext/standard/credits_ext.h b/ext/standard/credits_ext.h
deleted file mode 100644
index 3dbeacbefc..0000000000
--- a/ext/standard/credits_ext.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- DO NOT EDIT THIS FILE!
-
- it has been automaticaly created by php4/scripts/credits from
- the information found in the various php4/ext/.../CREDITS and
- php4/sapi/.../CREDITS files
-
- if you want to change an entry you have to edit the appropriate
- CREDITS file instead
-
-*/
-
-CREDIT_LINE("aspell", "Rasmus Lerdorf");
-CREDIT_LINE("Assert", "Thies C. Arntzen");
-CREDIT_LINE("BC Math", "Andi Gutmans");
-CREDIT_LINE("bz2", "Sterling Hughes");
-CREDIT_LINE("ccvs", "Brendan W. McAdams, Doug DeJulio");
-CREDIT_LINE("cpdf", "Uwe Steinmann");
-CREDIT_LINE("crack", "Alexander Feldman");
-CREDIT_LINE("ctype", "Hartmut Holzgraefe");
-CREDIT_LINE("CURL", "Sterling Hughes");
-CREDIT_LINE("CyberCash", "Evan Klinger");
-CREDIT_LINE("DBA", "Sascha Schumann");
-CREDIT_LINE("dBase", "Jim Winstead");
-CREDIT_LINE("DBM", "Rasmus Lerdorf, Jim Winstead");
-CREDIT_LINE("domxml", "Uwe Steinmann");
-CREDIT_LINE("dotnet", "Sam Ruby");
-CREDIT_LINE("EXIF", "Rasmus Lerdorf");
-CREDIT_LINE("FBSQL", "Frank M. Kromann");
-CREDIT_LINE("FDF", "Uwe Steinmann");
-CREDIT_LINE("FilePro", "Chad Robinson");
-CREDIT_LINE("FTP", "Andrew Skalski");
-CREDIT_LINE("GD imaging", "Rasmus Lerdorf, Stig Bakken, Jim Winstead, Jouni Ahto");
-CREDIT_LINE("GetText", "Alex Plotnick");
-CREDIT_LINE("HyperWave", "Uwe Steinmann");
-CREDIT_LINE("icap", "Mark Musone");
-CREDIT_LINE("iisfunc", "Frank M. Kromann");
-CREDIT_LINE("IMAP", "Rex Logan, Mark Musone, Brian Wang, Kaj-Michael Lang, Antoni Pamies Olive, Rasmus Lerdorf, Andrew Skalski, Chuck Hagenbuch, Daniel R Kalowsky");
-CREDIT_LINE("Informix", "Danny Heijl, Christian Cartus");
-CREDIT_LINE("Ingres II", "David Hénot");
-CREDIT_LINE("InterBase", "Jouni Ahto, Andrew Avdeev");
-CREDIT_LINE("IRCG", "Sascha Schumann");
-CREDIT_LINE("Java", "Sam Ruby");
-CREDIT_LINE("LDAP", "Amitay Isaacs, Eric Warnke, Rasmus Lerdorf, Gerrit Thomson");
-CREDIT_LINE("Mailparse MIME parsing and manipulation functions", "Wez Furlong");
-CREDIT_LINE("MCAL", "Mark Musone, Chuck Hagenbuch");
-CREDIT_LINE("mcrypt", "Sascha Schumann, Derick Rethans");
-CREDIT_LINE("mhash", "Sascha Schumann");
-CREDIT_LINE("MING", "Dave Hayden");
-CREDIT_LINE("mnoGoSearch", "Alex Barkov, Ramil Kalimullin, Sergey Kartashoff");
-CREDIT_LINE("MS SQL", "Frank M. Kromann");
-CREDIT_LINE("mSQL", "Zeev Suraski");
-CREDIT_LINE("Multibyte (Japanese) String Functions", "Tsukada Takuya");
-CREDIT_LINE("MySQL", "Zeev Suraski");
-CREDIT_LINE("OCI8", "Stig Bakken, Thies C. Arntzen, Andy Sautins, David Benson");
-CREDIT_LINE("ODBC", "Stig Bakken, Andreas Karajannis, Frank M. Kromann, Daniel R. Kalowsky");
-CREDIT_LINE("OpenSSL", "Stig Venaas, Wez Furlong, Sascha Kettler");
-CREDIT_LINE("Oracle", "Stig Bakken, Mitch Golden, Rasmus Lerdorf, Andreas Karajannis, Thies C. Arntzen");
-CREDIT_LINE("Ovrimos", "Nikos Mavroyanopoulos");
-CREDIT_LINE("pcntl", "Jason Greene");
-CREDIT_LINE("PDF", "Uwe Steinmann");
-CREDIT_LINE("Perl Compatible Regexps", "Andrei Zmievski");
-CREDIT_LINE("Posix", "Kristian Köhntopp");
-CREDIT_LINE("PostgreSQL", "Jouni Ahto, Zeev Suraski");
-CREDIT_LINE("PRINTER", "Daniel Beulshausen, Frank M. Kromann");
-CREDIT_LINE("Pspell", "Vlad Krupin");
-CREDIT_LINE("qtdom", "Jan Borsodi");
-CREDIT_LINE("Readline", "Thies C. Arntzen");
-CREDIT_LINE("Recode", "Kristian Köhntopp");
-CREDIT_LINE("Sablotron XSLT", "Sterling Hughes");
-CREDIT_LINE("Satellite (CORBA)", "David Eriksson");
-CREDIT_LINE("Sessions", "Sascha Schumann, Andrei Zmievski");
-CREDIT_LINE("Shared Memory Operations", "Slava Poliakov, Ilia Alshanetsky");
-CREDIT_LINE("SNMP", "Rasmus Lerdorf");
-CREDIT_LINE("Sockets", "Chris Vandomelen, Sterling Hughes, Daniel Beulshausen");
-CREDIT_LINE("SWF", "Sterling Hughes");
-CREDIT_LINE("Sybase-CT", "Zeev Suraski, Tom May");
-CREDIT_LINE("Sybase-DB", "Zeev Suraski");
-CREDIT_LINE("System V Semaphores", "Tom May");
-CREDIT_LINE("System V Shared Memory", "Christian Cartus");
-CREDIT_LINE("Verisign Payflow Pro", "John Donagher, David Croft");
-CREDIT_LINE("Vpopmail", "David Croft, Boian Bonev");
-CREDIT_LINE("WDDX", "Andrei Zmievski");
-CREDIT_LINE("Win32 COM", "Zeev Suraski, Harald Radi");
-CREDIT_LINE("XML", "Stig Bakken, Thies C. Arntzen");
-CREDIT_LINE("YAZ", "Adam Dickmeiss");
-CREDIT_LINE("Yellow Pages", "Stephanie Wehner, Fredrik Ohrn");
-CREDIT_LINE("Zip", "Sterling Hughes");
-CREDIT_LINE("Zlib", "Rasmus Lerdorf, Stefan Roehrich");
diff --git a/ext/standard/credits_sapi.h b/ext/standard/credits_sapi.h
deleted file mode 100644
index 95383e2d7e..0000000000
--- a/ext/standard/credits_sapi.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- DO NOT EDIT THIS FILE!
-
- it has been automaticaly created by php4/scripts/credits from
- the information found in the various php4/ext/.../CREDITS and
- php4/sapi/.../CREDITS files
-
- if you want to change an entry you have to edit the appropriate
- CREDITS file instead
-
-*/
-
-CREDIT_LINE("AOLserver", "Sascha Schumann");
-CREDIT_LINE("Apache 1.3", "Rasmus Lerdorf, Zeev Suraski, Stig Bakken, David Sklar");
-CREDIT_LINE("Apache 2.0", "Sascha Schumann");
-CREDIT_LINE("Caudium / Roxen", "David Hedbor");
-CREDIT_LINE("CGI", "Rasmus Lerdorf, Stig Bakken");
-CREDIT_LINE("fhttpd", "Alex Belits");
-CREDIT_LINE("ISAPI", "Andi Gutmans, Zeev Suraski");
-CREDIT_LINE("Java Servlet", "Sam Ruby");
-CREDIT_LINE("NSAPI", "Jayakumar Muthukumarasamy");
-CREDIT_LINE("phttpd", "Thies C. Arntzen");
-CREDIT_LINE("pi3web", "Holger Zimmermann");
-CREDIT_LINE("thttpd", "Sascha Schumann");
diff --git a/ext/standard/crypt.c b/ext/standard/crypt.c
deleted file mode 100644
index 00490f78e4..0000000000
--- a/ext/standard/crypt.c
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Stig Bakken <ssb@gaurdian.no> |
- | Zeev Suraski <zeev@zend.com> |
- | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-#include <stdlib.h>
-
-#include "php.h"
-
-#if HAVE_CRYPT
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_CRYPT_H
-#include <crypt.h>
-#endif
-#if TM_IN_SYS_TIME
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
-#ifdef PHP_WIN32
-#include <process.h>
-extern char *crypt(char *__key, char *__salt);
-#endif
-
-#include "php_lcg.h"
-#include "php_crypt.h"
-#include "php_rand.h"
-
-/*
- The capabilities of the crypt() function is determined by the test programs
- run by configure from aclocal.m4. They will set PHP_STD_DES_CRYPT,
- PHP_EXT_DES_CRYPT, PHP_MD5_CRYPT and PHP_BLOWFISH_CRYPT as appropriate
- for the target platform
-*/
-#if PHP_STD_DES_CRYPT
-#define PHP_MAX_SALT_LEN 2
-#endif
-
-#if PHP_EXT_DES_CRYPT
-#undef PHP_MAX_SALT_LEN
-#define PHP_MAX_SALT_LEN 9
-#endif
-
-#if PHP_MD5_CRYPT
-#undef PHP_MAX_SALT_LEN
-#define PHP_MAX_SALT_LEN 12
-#endif
-
-#if PHP_BLOWFISH_CRYPT
-#undef PHP_MAX_SALT_LEN
-#define PHP_MAX_SALT_LEN 60
-#endif
-
- /*
- * If the configure-time checks fail, we provide DES.
- * XXX: This is a hack. Fix the real problem
- */
-
-#ifndef PHP_MAX_SALT_LEN
-#define PHP_MAX_SALT_LEN 2
-#undef PHP_STD_DES_CRYPT
-#define PHP_STD_DES_CRYPT 1
-#endif
-
-
-#define PHP_CRYPT_RAND php_rand()
-
-static int php_crypt_rand_seeded=0;
-
-PHP_MINIT_FUNCTION(crypt)
-{
- REGISTER_LONG_CONSTANT("CRYPT_SALT_LENGTH", PHP_MAX_SALT_LEN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CRYPT_STD_DES", PHP_STD_DES_CRYPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CRYPT_EXT_DES", PHP_EXT_DES_CRYPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CRYPT_MD5", PHP_MD5_CRYPT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CRYPT_BLOWFISH", PHP_BLOWFISH_CRYPT, CONST_CS | CONST_PERSISTENT);
-
- return SUCCESS;
-}
-
-
-PHP_RINIT_FUNCTION(crypt)
-{
- if(!php_crypt_rand_seeded) {
- php_srand(time(0) * getpid() * (php_combined_lcg(TSRMLS_C) * 10000.0));
- php_crypt_rand_seeded=1;
- }
- return SUCCESS;
-}
-
-
-static unsigned char itoa64[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
-
-static void php_to64(char *s, long v, int n) {
- while (--n >= 0) {
- *s++ = itoa64[v&0x3f];
- v >>= 6;
- }
-}
-
-/* {{{ proto string crypt(string str [, string salt])
- Encrypt a string */
-PHP_FUNCTION(crypt)
-{
- char salt[PHP_MAX_SALT_LEN+1];
- pval **arg1, **arg2;
-
- salt[0]=salt[PHP_MAX_SALT_LEN]='\0';
- /* This will produce suitable results if people depend on DES-encryption
- available (passing always 2-character salt). At least for glibc6.1 */
- memset(&salt[1], '$', PHP_MAX_SALT_LEN-1);
-
- switch (ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &arg1)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(arg2);
- memcpy(salt, Z_STRVAL_PP(arg2), MIN(PHP_MAX_SALT_LEN, Z_STRLEN_PP(arg2)));
- 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 PHP_MD5_CRYPT
- strcpy(salt, "$1$");
- php_to64(&salt[3], PHP_CRYPT_RAND, 4);
- php_to64(&salt[7], PHP_CRYPT_RAND, 4);
- strcpy(&salt[11], "$");
-#elif PHP_STD_DES_CRYPT
- php_to64(&salt[0], PHP_CRYPT_RAND, 2);
- salt[2] = '\0';
-#endif
- }
-
- RETVAL_STRING(crypt(Z_STRVAL_PP(arg1), salt), 1);
-}
-/* }}} */
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/cyr_convert.c b/ext/standard/cyr_convert.c
deleted file mode 100644
index 44bb49a8d6..0000000000
--- a/ext/standard/cyr_convert.c
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Kirill Maximov <kir@rus.net> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <stdlib.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include "php.h"
-#include "cyr_convert.h"
-
-#include <stdio.h>
-
-/*****************************************************************************
-* This is codetables for different Cyrillic charsets (relative to koi8-r).
-* Each table contains data for 128-255 symbols from ASCII table.
-* First 256 symbols are for conversion from koi8-r to corresponding charset,
-* second 256 symbols are for reverse conversion, from charset to koi8-r.
-*
-* Here we have the following tables:
-* _cyr_win1251 - for windows-1251 charset
-* _cyr_iso88595 - for iso8859-5 charset
-* _cyr_cp866 - for x-cp866 charset
-* _cyr_mac - for x-mac-cyrillic charset
-*
-*****************************************************************************/
-
-typedef unsigned char _cyr_charset_table[512];
-
-/* {{{ const static _cyr_charset_table _cyr_win1251
- */
-const static _cyr_charset_table _cyr_win1251 = {
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
-46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
-154,174,190,46,159,189,46,46,179,191,180,157,46,46,156,183,
-46,46,182,166,173,46,46,158,163,152,164,155,46,46,46,167,
-225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
-242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
-193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
-210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,184,186,32,179,191,32,32,32,32,32,180,162,32,
-32,32,32,168,170,32,178,175,32,32,32,32,32,165,161,169,
-254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
-239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
-222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
-207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218,
-},
-_cyr_cp866 = {
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
-242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
-193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
-35,35,35,124,124,124,124,43,43,124,124,43,43,43,43,43,
-43,45,45,124,45,43,124,124,43,43,45,45,124,45,43,45,
-45,45,45,43,43,43,43,43,43,43,43,35,35,124,124,35,
-210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
-179,163,180,164,183,167,190,174,32,149,158,32,152,159,148,154,
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-205,186,213,241,243,201,32,245,187,212,211,200,190,32,247,198,
-199,204,181,240,242,185,32,244,203,207,208,202,216,32,246,32,
-238,160,161,230,164,165,228,163,229,168,169,170,171,172,173,174,
-175,239,224,225,226,227,166,162,236,235,167,232,237,233,231,234,
-158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
-143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154,
-},
-_cyr_iso88595 = {
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,179,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
-242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
-193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
-210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
-32,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,241,32,32,32,32,32,32,32,32,32,32,32,32,
-32,32,32,161,32,32,32,32,32,32,32,32,32,32,32,32,
-238,208,209,230,212,213,228,211,229,216,217,218,219,220,221,222,
-223,239,224,225,226,227,214,210,236,235,215,232,237,233,231,234,
-206,176,177,198,180,181,196,179,197,184,185,186,187,188,189,190,
-191,207,192,193,194,195,182,178,204,203,183,200,205,201,199,202,
-},
-_cyr_mac = {
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
-242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
-160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
-176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
-128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
-144,145,146,147,148,149,150,151,152,153,154,155,156,179,163,209,
-193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
-210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,255,
-0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
-16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
-32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
-48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
-64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
-80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
-96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
-112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
-208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
-160,161,162,222,164,165,166,167,168,169,170,171,172,173,174,175,
-176,177,178,221,180,181,182,183,184,185,186,187,188,189,190,191,
-254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
-239,223,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
-158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
-143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154,
-};
-/* }}} */
-
-/* {{{ php_convert_cyr_string
-* This is the function that performs real in-place conversion of the string
-* between charsets.
-* Parameters:
-* str - string to be converted
-* from,to - one-symbol label of source and destination charset
-* The following symbols are used as labels:
-* k - koi8-r
-* w - windows-1251
-* i - iso8859-5
-* a - x-cp866
-* d - x-cp866
-* m - x-mac-cyrillic
-*****************************************************************************/
-static char * php_convert_cyr_string(unsigned char *str, int length, char from, char to)
-{
- 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; i<length; i++)
- {
- tmp = (from_table == NULL)? str[i] : from_table[ str[i] ];
- str[i] = (to_table == NULL) ? tmp : to_table[tmp + 256];
- }
- return (char *)str;
-}
-/* }}} */
-
-/* {{{ proto string convert_cyr_string(string str, string from, string to)
- Convert from one Cyrillic character set to another */
-PHP_FUNCTION(convert_cyr_string)
-{
- pval **str_arg, **fr_cs, **to_cs;
- unsigned char *str;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3,&str_arg,&fr_cs, &to_cs)==FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str_arg);
- convert_to_string_ex(fr_cs);
- convert_to_string_ex(to_cs);
-
- str = (unsigned char*) estrndup((*str_arg)->value.str.val, (*str_arg)->value.str.len);
-
- php_convert_cyr_string(str, (*str_arg)->value.str.len, (*fr_cs)->value.str.val[0], (*to_cs)->value.str.val[0]);
- RETVAL_STRING((char *)str, 0)
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/cyr_convert.h b/ext/standard/cyr_convert.h
deleted file mode 100644
index ab75c8dfe9..0000000000
--- a/ext/standard/cyr_convert.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Kirill Maximov (kir@rus.net) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#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 8f9ed8f593..0000000000
--- a/ext/standard/datetime.c
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- | Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
- */
-
-
-/* $Id$ */
-
-
-#include "php.h"
-#include "zend_operators.h"
-#include "datetime.h"
-#include "php_globals.h"
-
-#include <time.h>
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-#include <stdio.h>
-
-#include "php_parsedate.h"
-
-char *mon_full_names[] =
-{
- "January", "February", "March", "April",
- "May", "June", "July", "August",
- "September", "October", "November", "December"
-};
-char *mon_short_names[] =
-{
- "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
-char *day_full_names[] =
-{
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
-};
-char *day_short_names[] =
-{
- "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-
-#if !defined(HAVE_TM_ZONE) && !defined(_TIMEZONE) && !defined(HAVE_DECLARED_TIMEZONE)
-extern time_t timezone;
-extern int daylight;
-#endif
-
-static int phpday_tab[2][12] =
-{
- {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
- {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
-};
-
-#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
-
-/* {{{ proto int time(void)
- Return current UNIX timestamp */
-PHP_FUNCTION(time)
-{
- RETURN_LONG((long)time(NULL));
-}
-/* }}} */
-
-/* {{{ php_mktime
- */
-void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm)
-{
- pval **arguments[7];
- struct tm *ta, tmbuf;
- time_t t;
- int i, gmadjust, seconds, arg_count = ZEND_NUM_ARGS();
- int is_dst = -1;
-
- if (arg_count > 7 || zend_get_parameters_array_ex(arg_count, arguments) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* convert supplied arguments to longs */
- for (i = 0; i < arg_count; i++) {
- convert_to_long_ex(arguments[i]);
- }
- t = time(NULL);
-#ifdef HAVE_TZSET
- tzset();
-#endif
- /*
- ** Set default time parameters with local time values,
- ** EVEN when some GMT time parameters are specified!
- ** This may give strange result, with PHP gmmktime(0, 0, 0),
- ** which is assumed to return GMT midnight time
- ** for today (in localtime), so that the result time may be
- ** AFTER or BEFORE the current time.
- ** May be we should initialize tn using gmtime(), so that
- ** default parameters for PHP gmmktime would be the current
- ** GMT time values...
- */
- ta = php_localtime_r(&t, &tmbuf);
-
- /* Let DST be unknown. mktime() should compute the right value
- ** and behave correctly. Unless the user overrides this.
- */
- ta->tm_isdst = -1;
-
- /*
- ** Now change date values with supplied parameters.
- */
- switch(arg_count) {
- case 7:
- ta->tm_isdst = is_dst = (*arguments[6])->value.lval;
- /* fall-through */
- case 6:
- /* special case:
- a zero in year, month and day is considered illegal
- as it would be interpreted as 30.11.1999 otherwise
- */
- if ( ( (*arguments[5])->value.lval==0)
- &&((*arguments[4])->value.lval==0)
- &&((*arguments[3])->value.lval==0)
- ) {
- RETURN_LONG(-1);
- }
-
- /*
- ** Accept parameter in range 0..1000 interpreted as 1900..2900
- ** (if 100 is given, it means year 2000)
- ** or in range 1001..9999 interpreted as is (this will store
- ** negative tm_year for years in range 1001..1899)
- ** This function is then Y2K ready, and accepts a wide range of
- ** dates including the whole gregorian calendar.
- ** But it cannot represent ancestral dates prior to year 1001.
- ** Additionally, input parameters of 0..70 are mapped to 100..170
- */
- if ((*arguments[5])->value.lval < 70)
- ta->tm_year = (*arguments[5])->value.lval + 100;
- else
- ta->tm_year = (*arguments[5])->value.lval
- - (((*arguments[5])->value.lval > 1000) ? 1900 : 0);
- /* fall-through */
- case 5:
- ta->tm_mday = (*arguments[4])->value.lval;
- /* fall-through */
- case 4:
- ta->tm_mon = (*arguments[3])->value.lval - 1;
- /* fall-through */
- case 3:
- ta->tm_sec = (*arguments[2])->value.lval;
- /* fall-through */
- case 2:
- ta->tm_min = (*arguments[1])->value.lval;
- /* fall-through */
- case 1:
- ta->tm_hour = (*arguments[0])->value.lval;
- /* fall-through */
- case 0:
- break;
- }
-
- seconds = mktime(ta);
- if (is_dst == -1)
- is_dst = ta->tm_isdst;
-
- if (gm) {
-#if HAVE_TM_GMTOFF
- /*
- ** mktime(ta) very nicely just filled ta->tm_gmtoff with
- ** the exactly right value for adjustment if we want GMT.
- */
- gmadjust = ta->tm_gmtoff;
-#else
- /*
- ** If correcting for daylight savings time, we set the adjustment to
- ** the value of timezone - 3600 seconds. Otherwise, we need to overcorrect and
- ** set the adjustment to the main timezone + 3600 seconds.
- */
- gmadjust = -(is_dst ? timezone - 3600 : timezone + 3600);
-#endif
- seconds += gmadjust;
- }
-
- RETURN_LONG(seconds);
-}
-/* }}} */
-
-/* {{{ proto int mktime(int hour, int min, int sec, int mon, int day, int year)
- Get UNIX timestamp for a date */
-PHP_FUNCTION(mktime)
-{
- php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto int gmmktime(int hour, int min, int sec, int mon, int day, int year)
- Get UNIX timestamp for a GMT date */
-PHP_FUNCTION(gmmktime)
-{
- php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ php_date
- */
-static void
-php_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
-{
- pval **format, **timestamp;
- time_t the_time;
- struct tm *ta, tmbuf;
- int i, size = 0, length, h, beat, fd, wd, yd, wk;
- char tmp_buff[32];
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &format) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- the_time = time(NULL);
- break;
- case 2:
- if (zend_get_parameters_ex(2, &format, &timestamp) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(timestamp);
- the_time = (*timestamp)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(format);
-
- if (gm) {
- ta = php_gmtime_r(&the_time, &tmbuf);
- } else {
- ta = php_localtime_r(&the_time, &tmbuf);
- }
-
- if (!ta) { /* that really shouldn't happen... */
- php_error(E_WARNING, "unexpected error in date()");
- RETURN_FALSE;
- }
- for (i = 0; i < (*format)->value.str.len; i++) {
- switch ((*format)->value.str.val[i]) {
- case 'r': /* rfc822 format */
- size += 31;
- break;
- case 'U': /* seconds since the epoch */
- size += 10;
- break;
- case 'F': /* month, textual, full */
- case 'l': /* day (of the week), textual */
- size += 28;
- break;
- case 'T': /* timezone name */
-#if HAVE_TM_ZONE
- size += strlen(ta->tm_zone);
-#elif HAVE_TZNAME
- size += strlen(tzname[0]);
-#endif
- break;
- case 'Z': /* timezone offset in seconds */
- size += 6;
- break;
- case 'O': /* GMT offset in [+-]HHMM format */
- size += 5;
- break;
- case 'Y': /* year, numeric, 4 digits */
- size += 4;
- break;
- case 'M': /* month, textual, 3 letters */
- case 'D': /* day, textual, 3 letters */
- case 'z': /* day of the year, 1 to 366 */
- case 'B': /* Swatch Beat, 3 digits */
- size += 3;
- break;
- case 'y': /* year, numeric, 2 digits */
- case 'm': /* month, numeric */
- case 'n': /* month, numeric, no leading zeroes */
- case 'd': /* day of the month, numeric */
- case 'j': /* day of the month, numeric, no leading zeros */
- case 'H': /* hour, numeric, 24 hour format */
- case 'h': /* hour, numeric, 12 hour format */
- case 'G': /* hour, numeric, 24 hour format, no leading zeroes */
- case 'g': /* hour, numeric, 12 hour format, no leading zeroes */
- case 'i': /* minutes, numeric */
- case 's': /* seconds, numeric */
- case 'A': /* AM/PM */
- case 'a': /* am/pm */
- case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */
- case 't': /* days in current month */
- case 'W': /* ISO-8601 week number of year, weeks starting on Monday */
- size += 2;
- break;
- case '\\':
- if(i < (*format)->value.str.len-1) {
- i++;
- }
- size ++;
- break;
- case 'L': /* boolean for leap year */
- case 'w': /* day of the week, numeric */
- case 'I': /* DST? */
- default:
- size++;
- break;
- }
- }
-
- return_value->value.str.val = (char *) emalloc(size + 1);
- return_value->value.str.val[0] = '\0';
-
- for (i = 0; i < (*format)->value.str.len; i++) {
- switch ((*format)->value.str.val[i]) {
- case '\\':
- if(i < (*format)->value.str.len-1) {
- char ch[2];
- ch[0]=(*format)->value.str.val[i+1];
- ch[1]='\0';
- strcat(return_value->value.str.val, ch);
- i++;
- }
- break;
- case 'U': /* seconds since the epoch */
- sprintf(tmp_buff, "%ld", (long)the_time); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'F': /* month, textual, full */
- strcat(return_value->value.str.val, mon_full_names[ta->tm_mon]);
- break;
- case 'l': /* day (of the week), textual, full */
- strcat(return_value->value.str.val, day_full_names[ta->tm_wday]);
- break;
- case 'Y': /* year, numeric, 4 digits */
- sprintf(tmp_buff, "%d", ta->tm_year + 1900); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'M': /* month, textual, 3 letters */
- strcat(return_value->value.str.val, mon_short_names[ta->tm_mon]);
- break;
- case 'D': /* day (of the week), textual, 3 letters */
- strcat(return_value->value.str.val, day_short_names[ta->tm_wday]);
- break;
- case 'z': /* day (of the year) */
- sprintf(tmp_buff, "%d", ta->tm_yday); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'y': /* year, numeric, 2 digits */
- sprintf(tmp_buff, "%02d", ((ta->tm_year)%100)); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'm': /* month, numeric */
- sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'n': /* month, numeric, no leading zeros */
- sprintf(tmp_buff, "%d", ta->tm_mon + 1); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'd': /* day of the month, numeric */
- sprintf(tmp_buff, "%02d", ta->tm_mday); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'j':
- sprintf(tmp_buff, "%d", ta->tm_mday); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'H': /* hour, numeric, 24 hour format */
- sprintf(tmp_buff, "%02d", ta->tm_hour); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'h': /* hour, numeric, 12 hour format */
- h = ta->tm_hour % 12; if (h==0) h = 12;
- sprintf(tmp_buff, "%02d", h); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'G': /* hour, numeric, 24 hour format, no leading zeros */
- sprintf(tmp_buff, "%d", ta->tm_hour); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'g': /* hour, numeric, 12 hour format, no leading zeros */
- h = ta->tm_hour % 12; if (h==0) h = 12;
- sprintf(tmp_buff, "%d", h); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'i': /* minutes, numeric */
- sprintf(tmp_buff, "%02d", ta->tm_min); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 's': /* seconds, numeric */
- sprintf(tmp_buff, "%02d", ta->tm_sec); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'A': /* AM/PM */
- strcat(return_value->value.str.val, (ta->tm_hour >= 12 ? "PM" : "AM"));
- break;
- case 'a': /* am/pm */
- strcat(return_value->value.str.val, (ta->tm_hour >= 12 ? "pm" : "am"));
- break;
- case 'S': /* standard english suffix, e.g. 2nd/3rd for the day of the month */
- if (ta->tm_mday >= 10 && ta->tm_mday <= 19) {
- strcat(return_value->value.str.val, "th");
- } else {
- switch (ta->tm_mday % 10) {
- case 1:
- strcat(return_value->value.str.val, "st");
- break;
- case 2:
- strcat(return_value->value.str.val, "nd");
- break;
- case 3:
- strcat(return_value->value.str.val, "rd");
- break;
- default:
- strcat(return_value->value.str.val, "th");
- break;
- }
- }
- break;
- case 't': /* days in current month */
- sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+1900))][ta->tm_mon] );
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'w': /* day of the week, numeric EXTENSION */
- sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'O': /* GMT offset in [+-]HHMM format */
-#if HAVE_TM_GMTOFF
- sprintf(tmp_buff, "%c%02d%02d", (ta->tm_gmtoff < 0) ? '-' : '+', abs(ta->tm_gmtoff / 3600), abs( ta->tm_gmtoff % 3600));
-#else
- sprintf(tmp_buff, "%c%02d%02d", ((ta->tm_isdst ? timezone - 3600:timezone)>0)?'-':'+', abs((ta->tm_isdst ? timezone - 3600 : timezone) / 3600), abs((ta->tm_isdst ? timezone - 3600 : timezone) % 3600));
-#endif
- 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", ta->tm_isdst ? -(timezone - 3600) : -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);
-#elif HAVE_TZNAME
- 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);
- while (beat < 0) {
- beat += 1000;
- }
- beat = beat % 1000;
- sprintf(tmp_buff, "%03d", beat); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'I':
- sprintf(tmp_buff, "%d", ta->tm_isdst);
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'r':
-#if HAVE_TM_GMTOFF
- sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
- day_short_names[ta->tm_wday],
- ta->tm_mday,
- mon_short_names[ta->tm_mon],
- ta->tm_year + 1900,
- ta->tm_hour,
- ta->tm_min,
- ta->tm_sec,
- (ta->tm_gmtoff < 0) ? '-' : '+',
- abs(ta->tm_gmtoff / 3600),
- abs( ta->tm_gmtoff % 3600)
- );
-#else
- sprintf(tmp_buff, "%3s, %2d %3s %04d %02d:%02d:%02d %c%02d%02d",
- day_short_names[ta->tm_wday],
- ta->tm_mday,
- mon_short_names[ta->tm_mon],
- ta->tm_year + 1900,
- ta->tm_hour,
- ta->tm_min,
- ta->tm_sec,
- ((ta->tm_isdst ? timezone - 3600 : timezone) > 0) ? '-' : '+',
- abs((ta->tm_isdst ? timezone - 3600 : timezone) / 3600),
- abs((ta->tm_isdst ? timezone - 3600 : timezone) % 3600)
- );
-#endif
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'W': /* ISO-8601 week number of year, weeks starting on Monday */
- wd = ta->tm_wday==0 ? 7 : ta->tm_wday;
- yd = ta->tm_yday + 1;
- fd = (7 + (wd - yd) % 7 ) % 7;
- wk = ( (yd + fd - 1) / 7 ) + 1;
- if (fd>3) {
- wk--;
- }
- sprintf(tmp_buff, "%d", wk); /* 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;
-}
-/* }}} */
-
-/* {{{ proto string date(string format [, int timestamp])
- Format a local time/date */
-PHP_FUNCTION(date)
-{
- php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto string gmdate(string format [, int timestamp])
- Format a GMT/UTC date/time */
-PHP_FUNCTION(gmdate)
-{
- php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ proto array localtime([int timestamp [, bool associative_array]])
- Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */
-PHP_FUNCTION(localtime)
-{
- zval **timestamp_arg, **assoc_array_arg;
- struct tm *ta, tmbuf;
- time_t timestamp;
- int assoc_array = 0;
- int arg_count = ZEND_NUM_ARGS();
-
- if (arg_count < 0 || arg_count > 2 ||
- zend_get_parameters_ex(arg_count, &timestamp_arg, &assoc_array_arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- switch (arg_count) {
- case 0:
- timestamp = (long)time(NULL);
- break;
- case 1:
- convert_to_long_ex(timestamp_arg);
- timestamp = (*timestamp_arg)->value.lval;
- break;
- case 2:
- convert_to_long_ex(timestamp_arg);
- convert_to_long_ex(assoc_array_arg);
- timestamp = (*timestamp_arg)->value.lval;
- assoc_array = (*assoc_array_arg)->value.lval;
- break;
- }
- ta = php_localtime_r(&timestamp, &tmbuf);
- if (array_init(return_value) == FAILURE) {
- php_error(E_ERROR, "Cannot prepare return array from localtime");
- RETURN_FALSE;
- }
-
- if (assoc_array) {
- add_assoc_long(return_value, "tm_sec", ta->tm_sec);
- add_assoc_long(return_value, "tm_min", ta->tm_min);
- add_assoc_long(return_value, "tm_hour", ta->tm_hour);
- add_assoc_long(return_value, "tm_mday", ta->tm_mday);
- add_assoc_long(return_value, "tm_mon", ta->tm_mon);
- add_assoc_long(return_value, "tm_year", ta->tm_year);
- add_assoc_long(return_value, "tm_wday", ta->tm_wday);
- add_assoc_long(return_value, "tm_yday", ta->tm_yday);
- add_assoc_long(return_value, "tm_isdst", ta->tm_isdst);
- } else {
- add_next_index_long(return_value, ta->tm_sec);
- add_next_index_long(return_value, ta->tm_min);
- add_next_index_long(return_value, ta->tm_hour);
- add_next_index_long(return_value, ta->tm_mday);
- add_next_index_long(return_value, ta->tm_mon);
- add_next_index_long(return_value, ta->tm_year);
- add_next_index_long(return_value, ta->tm_wday);
- add_next_index_long(return_value, ta->tm_yday);
- add_next_index_long(return_value, ta->tm_isdst);
- }
-}
-/* }}} */
-
-/* {{{ proto array getdate([int timestamp])
- Get date/time information */
-PHP_FUNCTION(getdate)
-{
- pval **timestamp_arg;
- struct tm *ta, tmbuf;
- time_t timestamp;
-
- if (ZEND_NUM_ARGS() == 0) {
- timestamp = time(NULL);
- } else if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &timestamp_arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- } else {
- convert_to_long_ex(timestamp_arg);
- timestamp = (*timestamp_arg)->value.lval;
- }
-
- ta = php_localtime_r(&timestamp, &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);
-}
-/* }}} */
-
-/* {{{ php_std_date
- Return date string in standard format for http headers */
-char *php_std_date(time_t t)
-{
- struct tm *tm1, tmbuf;
- char *str;
- TSRMLS_FETCH();
-
- tm1 = php_gmtime_r(&t, &tmbuf);
- str = emalloc(81);
- if (PG(y2k_compliance)) {
- snprintf(str, 80, "%s, %02d-%s-%04d %02d:%02d:%02d GMT",
- day_short_names[tm1->tm_wday],
- tm1->tm_mday,
- mon_short_names[tm1->tm_mon],
- tm1->tm_year+1900,
- tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
- } else {
- snprintf(str, 80, "%s, %02d-%s-%02d %02d:%02d:%02d GMT",
- day_short_names[tm1->tm_wday],
- tm1->tm_mday,
- mon_short_names[tm1->tm_mon],
- ((tm1->tm_year)%100),
- tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
- }
-
- str[79]=0;
- return (str);
-}
-/* }}} */
-
-/* {{{ proto bool checkdate(int month, int day, int year)
- Returns true(1) if it is a valid date in gregorian calendar */
-PHP_FUNCTION(checkdate)
-{
- pval **month, **day, **year;
- int m, d, y, res=0;
-
- if (ZEND_NUM_ARGS() != 3 ||
- zend_get_parameters_ex(3, &month, &day, &year) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if((*year)->type == IS_STRING) {
- res = is_numeric_string((*year)->value.str.val, (*year)->value.str.len, NULL, NULL, 0);
- if(res!=IS_LONG && res !=IS_DOUBLE) {
- RETURN_FALSE;
- }
- }
- convert_to_long_ex(day);
- convert_to_long_ex(month);
- convert_to_long_ex(year);
- y = (*year)->value.lval;
- m = (*month)->value.lval;
- d = (*day)->value.lval;
-
- if (y < 1 || y > 32767) {
- RETURN_FALSE;
- }
- if (m < 1 || m > 12) {
- RETURN_FALSE;
- }
- if (d < 1 || d > phpday_tab[isleap(y)][m - 1]) {
- RETURN_FALSE;
- }
- RETURN_TRUE; /* True : This month, day, year arguments are valid */
-}
-/* }}} */
-
-#if HAVE_STRFTIME
-/* {{{ _php_strftime
- */
-void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm)
-{
- pval **format_arg, **timestamp_arg;
- char *format, *buf;
- time_t timestamp;
- struct tm *ta, tmbuf;
- int max_reallocs = 5;
- size_t buf_len=64, real_len;
-
- switch (ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &format_arg)==FAILURE) {
- RETURN_FALSE;
- }
- time(&timestamp);
- break;
- case 2:
- if (zend_get_parameters_ex(2, &format_arg, &timestamp_arg)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(timestamp_arg);
- timestamp = (*timestamp_arg)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- convert_to_string_ex(format_arg);
- if ((*format_arg)->value.str.len==0) {
- RETURN_FALSE;
- }
- if (timestamp < 0) {
- RETURN_FALSE;
- }
- format = (*format_arg)->value.str.val;
- if (gm) {
- ta = php_gmtime_r(&timestamp, &tmbuf);
- } else {
- ta = php_localtime_r(&timestamp, &tmbuf);
- }
-
- buf = (char *) emalloc(buf_len);
- while ((real_len=strftime(buf, buf_len, format, ta))==buf_len || real_len==0) {
- buf_len *= 2;
- buf = (char *) erealloc(buf, buf_len);
- if(!--max_reallocs) break;
- }
-
- if(real_len && real_len != buf_len) {
- buf = (char *) erealloc(buf, real_len+1);
- RETURN_STRINGL(buf, real_len, 0);
- }
- efree(buf);
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto string strftime(string format [, int timestamp])
- Format a local time/date according to locale settings */
-PHP_FUNCTION(strftime)
-{
- _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto string gmstrftime(string format [, int timestamp])
- Format a GMT/UCT time/date according to locale settings */
-PHP_FUNCTION(gmstrftime)
-{
- _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-#endif
-
-/* {{{ proto int strtotime(string time, int now)
- Convert string representation of date and time to a timestamp */
-PHP_FUNCTION(strtotime)
-{
- zval **z_time, **z_now;
- int argc;
- time_t now;
-
- argc = ZEND_NUM_ARGS();
-
- if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &z_time, &z_now)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(z_time);
- if (Z_STRLEN_PP(z_time) == 0)
- php_error (E_NOTICE, "strtotime() called with empty time parameter");
- if (argc == 2) {
- convert_to_long_ex(z_now);
- now = Z_LVAL_PP(z_now);
- RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), &now));
- } else {
- RETURN_LONG(php_parse_date(Z_STRVAL_PP(z_time), NULL));
- }
-}
-/* }}} */
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h
deleted file mode 100644
index daa3710306..0000000000
--- a/ext/standard/datetime.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef DATETIME_H
-#define DATETIME_H
-
-PHP_FUNCTION(time);
-PHP_FUNCTION(mktime);
-PHP_FUNCTION(gmmktime);
-PHP_FUNCTION(date);
-PHP_FUNCTION(gmdate);
-PHP_FUNCTION(localtime);
-PHP_FUNCTION(getdate);
-PHP_FUNCTION(checkdate);
-#if HAVE_STRFTIME
-PHP_FUNCTION(strftime);
-PHP_FUNCTION(gmstrftime);
-#endif
-PHP_FUNCTION(strtotime);
-
-extern char *php_std_date(time_t t);
-void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm);
-#if HAVE_STRFTIME
-void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
-#endif
-
-#endif /* DATETIME_H */
diff --git a/ext/standard/dir.c b/ext/standard/dir.c
deleted file mode 100644
index 8ebc48f233..0000000000
--- a/ext/standard/dir.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- | PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/* {{{ includes/startup/misc */
-
-#include "php.h"
-#include "fopen_wrappers.h"
-
-#include "php_dir.h"
-
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <errno.h>
-
-#ifdef PHP_WIN32
-#include "win32/readdir.h"
-#endif
-
-typedef struct {
- int default_dir;
-} php_dir_globals;
-
-#ifdef ZTS
-#define DIRG(v) TSRMG(dir_globals_id, php_dir_globals *, v)
-int dir_globals_id;
-#else
-#define DIRG(v) (dir_globals.v)
-php_dir_globals dir_globals;
-#endif
-
-typedef struct {
- int id;
- DIR *dir;
-} php_dir;
-
-static int le_dirp;
-
-static zend_class_entry *dir_class_entry_ptr;
-
-#define FETCH_DIRP() \
- if (ZEND_NUM_ARGS() == 0) { \
- myself = getThis(); \
- if (myself) { \
- if (zend_hash_find(Z_OBJPROP_P(myself), "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, DIRG(default_dir), "Directory", le_dirp); \
- } \
- } else if ((ZEND_NUM_ARGS() != 1) || zend_get_parameters_ex(1, &id) == FAILURE) { \
- WRONG_PARAM_COUNT; \
- } else { \
- ZEND_FETCH_RESOURCE(dirp, php_dir *, id,-1, "Directory", le_dirp); \
- }
-
-static zend_function_entry php_dir_class_functions[] = {
- PHP_FALIAS(close, closedir, NULL)
- PHP_FALIAS(rewind, rewinddir, NULL)
- PHP_STATIC_FE("read", php_if_readdir, NULL)
- {NULL, NULL, NULL}
-};
-
-
-static void php_set_default_dir(int id TSRMLS_DC)
-{
- if (DIRG(default_dir)!=-1) {
- zend_list_delete(DIRG(default_dir));
- }
-
- if (id != -1) {
- zend_list_addref(id);
- }
-
- DIRG(default_dir) = id;
-}
-
-
-static void _dir_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- php_dir *dirp = (php_dir *)rsrc->ptr;
-
- closedir(dirp->dir);
- efree(dirp);
-}
-
-PHP_RINIT_FUNCTION(dir)
-{
- DIRG(default_dir) = -1;
- return SUCCESS;
-}
-
-PHP_MINIT_FUNCTION(dir)
-{
- static char tmpstr[2];
- zend_class_entry dir_class_entry;
-
- le_dirp = zend_register_list_destructors_ex(_dir_dtor, NULL, "dir", module_number);
-
- INIT_CLASS_ENTRY(dir_class_entry, "Directory", php_dir_class_functions);
- dir_class_entry_ptr = zend_register_internal_class(&dir_class_entry TSRMLS_CC);
-
-#ifdef ZTS
- ts_allocate_id(&dir_globals_id, sizeof(php_dir_globals), NULL, NULL);
-#endif
- tmpstr[0] = DEFAULT_SLASH;
- tmpstr[1] = '\0';
- REGISTER_STRING_CONSTANT("DIRECTORY_SEPARATOR", tmpstr, CONST_CS|CONST_PERSISTENT);
-
- return SUCCESS;
-}
-
-/* }}} */
-/* {{{ internal functions */
-
-static void _php_do_opendir(INTERNAL_FUNCTION_PARAMETERS, int createobject)
-{
- pval **arg;
- php_dir *dirp;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (php_check_open_basedir((*arg)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- dirp = emalloc(sizeof(php_dir));
-
- dirp->dir = VCWD_OPENDIR((*arg)->value.str.val);
-
-#ifdef PHP_WIN32
- if (!dirp->dir || dirp->dir->finished) {
- if (dirp->dir) {
- closedir(dirp->dir);
- }
-#else
- if (!dirp->dir) {
-#endif
- efree(dirp);
- php_error(E_WARNING, "OpenDir: %s (errno %d)", strerror(errno), errno);
- RETURN_FALSE;
- }
-
- dirp->id = zend_list_insert(dirp, le_dirp);
-
- php_set_default_dir(dirp->id TSRMLS_CC);
-
- 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;
-
- FETCH_DIRP();
-
- zend_list_delete(dirp->id);
-
- if (dirp->id == DIRG(default_dir)) {
- php_set_default_dir(-1 TSRMLS_CC);
- }
-}
-
-/* }}} */
-
-#if defined(HAVE_CHROOT) && !defined(ZTS)
-/* {{{ proto int chroot(string directory)
- Change root directory */
-
-PHP_FUNCTION(chroot)
-{
- pval **arg;
- int ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- ret = chroot((*arg)->value.str.val);
-
- if (ret != 0) {
- php_error(E_WARNING, "chroot: %s (errno %d)", strerror(errno), errno);
- RETURN_FALSE;
- }
-
- ret = chdir("/");
-
- if (ret != 0) {
- php_error(E_WARNING, "chdir: %s (errno %d)", strerror(errno), errno);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-
-/* }}} */
-#endif
-
-/* {{{ proto int chdir(string directory)
- Change the current directory */
-
-PHP_FUNCTION(chdir)
-{
- pval **arg;
- int ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (PG(safe_mode) && !php_checkuid((*arg)->value.str.val, NULL, CHECKUID_ALLOW_ONLY_FILE)) {
- RETURN_FALSE;
- }
- ret = VCWD_CHDIR((*arg)->value.str.val);
-
- if (ret != 0) {
- php_error(E_WARNING, "ChDir: %s (errno %d)", strerror(errno), errno);
- RETURN_FALSE;
- }
-
- RETURN_TRUE;
-}
-
-/* }}} */
-/* {{{ proto string getcwd(void)
- Gets the current directory */
-
-PHP_FUNCTION(getcwd)
-{
- char path[MAXPATHLEN];
- char *ret=NULL;
-
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
-#if HAVE_GETCWD
- ret = VCWD_GETCWD(path, MAXPATHLEN);
-#elif HAVE_GETWD
- ret = VCWD_GETWD(path);
-/*
- * #warning is not ANSI C
- * #else
- * #warning no proper getcwd support for your site
- */
-#endif
-
- if (ret) {
- RETURN_STRING(path, 1);
- } else {
- RETURN_FALSE;
- }
-}
-
-/* }}} */
-/* {{{ proto void rewinddir([int dir_handle])
- Rewind dir_handle back to the start */
-
-PHP_FUNCTION(rewinddir)
-{
- pval **id, **tmp, *myself;
- php_dir *dirp;
-
- FETCH_DIRP();
-
- rewinddir(dirp->dir);
-}
-/* }}} */
-/* {{{ proto string readdir([int dir_handle])
- Read directory entry from dir_handle */
-
-PHP_NAMED_FUNCTION(php_if_readdir)
-{
- pval **id, **tmp, *myself;
- php_dir *dirp;
- char entry[sizeof(struct dirent)+MAXPATHLEN];
- struct dirent *result = (struct dirent *)&entry; /* patch for libc5 readdir problems */
-
- FETCH_DIRP();
-
- if (php_readdir_r(dirp->dir, (struct dirent *) entry, &result) == 0 && result) {
- RETURN_STRINGL(result->d_name, strlen(result->d_name), 1);
- }
- RETURN_FALSE;
-}
-
-/* }}} */
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/dl.c b/ext/standard/dl.c
deleted file mode 100644
index cb8ed73322..0000000000
--- a/ext/standard/dl.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Brian Schaffner <brian@tool.net> |
- | Shane Caraveo <shane@caraveo.com> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "dl.h"
-#include "php_globals.h"
-#include "ext/standard/info.h"
-#include "SAPI.h"
-
-#ifndef PHP_WIN32
-#include "build-defs.h"
-#endif
-
-#ifdef HAVE_LIBDL
-#include <stdlib.h>
-#include <stdio.h>
-
-#if HAVE_STRING_H
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-#ifdef PHP_WIN32
-#include "win32/param.h"
-#include "win32/winutil.h"
-#define GET_DL_ERROR() php_win_err()
-#else
-#include <sys/param.h>
-#define GET_DL_ERROR() dlerror()
-#endif
-
-#endif
-
-
-/* {{{ proto int dl(string extension_filename)
- Load a PHP extension at runtime */
-PHP_FUNCTION(dl)
-{
- pval **file;
-
-#ifdef ZTS
- if (strcmp(sapi_module.name, "cgi")!=0) {
- php_error(E_ERROR, "dl() is not supported in multithreaded Web servers - use extension statements in your php.ini");
- }
-#endif
-
- /* obtain arguments */
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(file);
-
- if (!PG(enable_dl)) {
- php_error(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 TSRMLS_CC);
- }
-}
-
-/* }}} */
-
-
-#ifdef HAVE_LIBDL
-
-#ifdef ZTS
-#define USING_ZTS 1
-#else
-#define USING_ZTS 0
-#endif
-
-/* {{{ php_dl
- */
-void php_dl(pval *file, int type, pval *return_value TSRMLS_DC)
-{
- void *handle;
- char *libpath;
- zend_module_entry *module_entry, *tmp;
- zend_module_entry *(*get_module)(void);
- int error_type;
- char *extension_dir;
-
- if (type==MODULE_PERSISTENT) {
- /* Use the configuration hash directly, the INI mechanism is not yet initialized */
- if (cfg_get_string("extension_dir", &extension_dir)==FAILURE) {
- extension_dir = PHP_EXTENSION_DIR;
- }
- } else {
- extension_dir = PG(extension_dir);
- }
-
- if (type==MODULE_TEMPORARY) {
- error_type = E_WARNING;
- } else {
- error_type = E_CORE_WARNING;
- }
-
- if (extension_dir && extension_dir[0]){
- int extension_dir_len = strlen(extension_dir);
-
- libpath = emalloc(extension_dir_len+file->value.str.len+2);
-
- if (IS_SLASH(extension_dir[extension_dir_len-1])) {
- sprintf(libpath, "%s%s", extension_dir, file->value.str.val); /* SAFE */
- } else {
- sprintf(libpath, "%s/%s", extension_dir, file->value.str.val); /* SAFE */
- }
- } else {
- libpath = estrndup(file->value.str.val, file->value.str.len);
- }
-
- /* load dynamic symbol */
- handle = DL_LOAD(libpath);
- if (!handle) {
- php_error(error_type, "Unable to load dynamic library '%s' - %s", libpath, GET_DL_ERROR());
- efree(libpath);
- RETURN_FALSE;
- }
-
- efree(libpath);
-
-
- get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");
-
- /*
- * some OS prepend _ to symbol names while their dynamic linker
- * does not do that automatically. Thus we check manually for
- * _get_module.
- */
-
- if (!get_module)
- get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module");
-
- if (!get_module) {
- DL_UNLOAD(handle);
- php_error(error_type, "Invalid library (maybe not a PHP library) '%s' ", file->value.str.val);
- RETURN_FALSE;
- }
- module_entry = get_module();
- if ((module_entry->zend_debug != ZEND_DEBUG) || (module_entry->zts != USING_ZTS)
- || (module_entry->zend_api != ZEND_MODULE_API_NO)) {
- php_error(error_type,
- "%s: Unable to initialize module\n"
- "Module compiled with debug=%d, thread-safety=%d module API=%d\n"
- "PHP compiled with debug=%d, thread-safety=%d module API=%d\n"
- "These options need to match\n",
- module_entry->name, module_entry->zend_debug, module_entry->zts, module_entry->zend_api,
- ZEND_DEBUG, USING_ZTS, ZEND_MODULE_API_NO);
- DL_UNLOAD(handle);
- RETURN_FALSE;
- }
- module_entry->type = type;
- module_entry->module_number = zend_next_free_module();
- if (module_entry->module_startup_func) {
- if (module_entry->module_startup_func(type, module_entry->module_number TSRMLS_CC)==FAILURE) {
- php_error(error_type, "%s: Unable to initialize module", module_entry->name);
- DL_UNLOAD(handle);
- RETURN_FALSE;
- }
- }
- zend_register_module(module_entry);
-
- if ((type == MODULE_TEMPORARY) && module_entry->request_startup_func) {
- if (module_entry->request_startup_func(type, module_entry->module_number TSRMLS_CC)) {
- php_error(error_type, "%s: Unable to initialize module", module_entry->name);
- DL_UNLOAD(handle);
- RETURN_FALSE;
- }
- }
-
- /* update the .request_started property... */
- if (zend_hash_find(&module_registry, module_entry->name, strlen(module_entry->name)+1, (void **) &tmp)==FAILURE) {
- php_error(error_type, "%s: Loaded module got lost", module_entry->name);
- RETURN_FALSE;
- }
- tmp->handle = handle;
-
- RETURN_TRUE;
-}
-/* }}} */
-
-PHP_MINFO_FUNCTION(dl)
-{
- php_info_print_table_row(2, "Dynamic Library Support", "enabled");
-}
-
-#else
-
-void php_dl(pval *file, int type, pval *return_value)
-{
- php_error(E_WARNING, "Cannot dynamically load %s - dynamic modules are not supported", file->value.str.val);
- RETURN_FALSE;
-}
-
-PHP_MINFO_FUNCTION(dl)
-{
- PUTS("Dynamic Library support not available<br>.\n");
-}
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/dl.h b/ext/standard/dl.h
deleted file mode 100644
index d80d82e0ea..0000000000
--- a/ext/standard/dl.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Brian Schaffner <brian@tool.net> |
- | Shane Caraveo <shane@caraveo.com> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef DL_H
-#define DL_H
-
-void php_dl(pval *file,int type,pval *return_value TSRMLS_DC);
-
-
-/* dynamic loading functions */
-PHP_FUNCTION(dl);
-
-PHP_MINFO_FUNCTION(dl);
-
-#endif /* DL_H */
diff --git a/ext/standard/dns.c b/ext/standard/dns.c
deleted file mode 100644
index 1b30965a52..0000000000
--- a/ext/standard/dns.c
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/* {{{ includes
- */
-#include "php.h"
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef PHP_WIN32
-#if HAVE_LIBBIND
-#ifndef WINNT
-#define WINNT 1
-#endif
-/* located in www.php.net/extra/bindlib.zip */
-#if HAVE_ARPA_INET_H
-#include "arpa/inet.h"
-#endif
-#include "netdb.h"
-#if HAVE_ARPA_NAMESERV_H
-#include "arpa/nameser.h"
-#endif
-#if HAVE_RESOLV_H
-#include "resolv.h"
-#endif
-#endif
-#include <winsock.h>
-#else
-#include <netinet/in.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#include <netdb.h>
-#ifdef _OSD_POSIX
-#undef STATUS
-#undef T_UNSPEC
-#endif
-#if HAVE_ARPA_NAMESER_H
-#include <arpa/nameser.h>
-#endif
-#if HAVE_RESOLV_H
-#include <resolv.h>
-#endif
-#endif
-
-#include "dns.h"
-/* }}} */
-
-static char *php_gethostbyaddr(char *ip);
-static char *php_gethostbyname(char *name);
-
-/* {{{ proto string gethostbyaddr(string ip_address)
- Get the Internet host name corresponding to a given IP address */
-PHP_FUNCTION(gethostbyaddr)
-{
- zval **arg;
- char *addr;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- ZEND_WRONG_PARAM_COUNT();
- }
-
- convert_to_string_ex(arg);
-
- addr = php_gethostbyaddr(Z_STRVAL_PP(arg));
-
- if(addr == NULL) {
- php_error(E_WARNING, "Address is not in a.b.c.d form");
- RETVAL_FALSE;
- } else {
- RETVAL_STRING(addr, 0);
- }
-}
-/* }}} */
-
-/* {{{ php_gethostbyaddr
- */
-static char *php_gethostbyaddr(char *ip)
-{
- struct in_addr addr;
- struct hostent *hp;
-
- addr.s_addr = inet_addr(ip);
-
- if (addr.s_addr == -1) {
- return NULL;
- }
-
- hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
-
- if (!hp) {
- return estrdup(ip);
- }
-
- return estrdup(hp->h_name);
-}
-/* }}} */
-
-/* {{{ proto string gethostbyname(string hostname)
- Get the IP address corresponding to a given Internet host name */
-PHP_FUNCTION(gethostbyname)
-{
- zval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- ZEND_WRONG_PARAM_COUNT();
- }
-
- convert_to_string_ex(arg);
-
- RETVAL_STRING(php_gethostbyname(Z_STRVAL_PP(arg)), 0);
-}
-/* }}} */
-
-/* {{{ proto array gethostbynamel(string hostname)
- Return a list of IP addresses that a given hostname resolves to. */
-PHP_FUNCTION(gethostbynamel)
-{
- zval **arg;
- struct hostent *hp;
- struct in_addr in;
- int i;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- ZEND_WRONG_PARAM_COUNT();
- }
- convert_to_string_ex(arg);
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- hp = gethostbyname(Z_STRVAL_PP(arg));
- if (hp == NULL || hp->h_addr_list == NULL) {
- RETURN_FALSE;
- }
-
- for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) {
- in = *(struct in_addr *) hp->h_addr_list[i];
- add_next_index_string(return_value, inet_ntoa(in), 1);
- }
-}
-/* }}} */
-
-/* {{{ php_gethostbyname
- */
-static char *php_gethostbyname(char *name)
-{
- struct hostent *hp;
- struct in_addr in;
-
- hp = gethostbyname(name);
-
- if (!hp || !hp->h_addr_list) {
- return estrdup(name);
- }
-
- memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));
-
- return estrdup(inet_ntoa(in));
-}
-/* }}} */
-
-#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
-
-/* {{{ proto int checkdnsrr(string host [, string type])
- Check DNS records corresponding to a given Internet host name or IP address */
-PHP_FUNCTION(checkdnsrr)
-{
- zval **arg1, **arg2;
- int type, i;
-#ifndef MAXPACKET
-#define MAXPACKET 8192 /* max packet size used internally by BIND */
-#endif
- u_char ans[MAXPACKET];
-
- switch (ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- type = T_MX;
- convert_to_string_ex(arg1);
- break;
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- convert_to_string_ex(arg2);
- if ( !strcasecmp("A", Z_STRVAL_PP(arg2)) ) type = T_A;
- else if ( !strcasecmp("NS", Z_STRVAL_PP(arg2)) ) type = T_NS;
- else if ( !strcasecmp("MX", Z_STRVAL_PP(arg2)) ) type = T_MX;
- else if ( !strcasecmp("PTR", Z_STRVAL_PP(arg2)) ) type = T_PTR;
- else if ( !strcasecmp("ANY", Z_STRVAL_PP(arg2)) ) type = T_ANY;
- else if ( !strcasecmp("SOA", Z_STRVAL_PP(arg2)) ) type = T_SOA;
- else if ( !strcasecmp("CNAME", Z_STRVAL_PP(arg2)) ) type = T_CNAME;
- else {
- php_error(E_WARNING, "Type '%s' not supported", Z_STRVAL_PP(arg2));
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- i = res_search(Z_STRVAL_PP(arg1), C_IN, type, ans, sizeof(ans));
- if ( i < 0 ) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-#ifndef HFIXEDSZ
-#define HFIXEDSZ 12 /* fixed data in header <arpa/nameser.h> */
-#endif /* HFIXEDSZ */
-
-#ifndef QFIXEDSZ
-#define QFIXEDSZ 4 /* fixed data in query <arpa/nameser.h> */
-#endif /* QFIXEDSZ */
-
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif /* MAXHOSTNAMELEN */
-
-/* {{{ proto int getmxrr(string hostname, array mxhosts [, array weight])
- Get MX records corresponding to a given Internet host name */
-PHP_FUNCTION(getmxrr)
-{
- pval *host, *mx_list, *weight_list;
- int need_weight = 0;
- int count, qdc;
- u_short type, weight;
- u_char ans[MAXPACKET];
- char buf[MAXHOSTNAMELEN];
- HEADER *hp;
- u_char *cp, *end;
- int i;
-
- switch(ZEND_NUM_ARGS()) {
- case 2:
- if (zend_get_parameters(ht, 2, &host, &mx_list) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 3:
- if (zend_get_parameters(ht, 3, &host, &mx_list, &weight_list) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- need_weight = 1;
- pval_destructor(weight_list); /* start with clean array */
- 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(Z_STRVAL_P(host), C_IN, T_MX, (u_char *)&ans, sizeof(ans));
- if ( i < 0 ) {
- RETURN_FALSE;
- }
- if ( i > sizeof(ans) ) i = sizeof(ans);
- hp = (HEADER *)&ans;
- cp = (u_char *)&ans + HFIXEDSZ;
- end = (u_char *)&ans +i;
- for ( qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
- if ( (i = dn_skipname(cp, end)) < 0 ) {
- RETURN_FALSE;
- }
- }
- count = ntohs((unsigned short)hp->ancount);
- while ( --count >= 0 && cp < end ) {
- if ( (i = dn_skipname(cp, end)) < 0 ) {
- RETURN_FALSE;
- }
- cp += i;
- GETSHORT(type, cp);
- cp += INT16SZ + INT32SZ;
- GETSHORT(i, cp);
- if ( type != T_MX ) {
- cp += i;
- continue;
- }
- GETSHORT(weight, cp);
- if ( (i = dn_expand(ans, end, cp, buf, sizeof(buf)-1)) < 0 ) {
- RETURN_FALSE;
- }
- cp += i;
- add_next_index_string(mx_list, buf, 1);
- if ( need_weight ) {
- add_next_index_long(weight_list, weight);
- }
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-#endif
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/dns.h b/ext/standard/dns.h
deleted file mode 100644
index cb0a4eeb57..0000000000
--- a/ext/standard/dns.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- | |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef DNS_H
-#define DNS_H
-
-PHP_FUNCTION(gethostbyaddr);
-PHP_FUNCTION(gethostbyname);
-PHP_FUNCTION(gethostbynamel);
-
-#if HAVE_RES_SEARCH && !(defined(__BEOS__)||defined(PHP_WIN32))
-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 11e3ffbe73..0000000000
--- a/ext/standard/exec.c
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Rasmus Lerdorf |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdio.h>
-#include "php.h"
-#include <ctype.h>
-#include "php_string.h"
-#include "safe_mode.h"
-#include "ext/standard/head.h"
-#include "ext/standard/file.h"
-#include "exec.h"
-#include "php_globals.h"
-#include "SAPI.h"
-
-#if HAVE_SYS_WAIT_H
-#include <sys/wait.h>
-#endif
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif
-
-/* {{{ php_Exec
- * If type==0, only last line of output is returned (exec)
- * If type==1, all lines will be printed and last lined returned (system)
- * If type==2, all lines will be saved to given array (exec with &$array)
- * If type==3, output will be printed binary, no lines will be saved or returned (passthru)
- *
- */
-int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC)
-{
- FILE *fp;
- char *buf, *tmp=NULL;
- int buflen = 0;
- int t, l, output=1;
- int overflow_limit, lcmd, ldir;
- int rsrc_id;
- char *b, *c, *d=NULL;
-#if PHP_SIGCHILD
- void (*sig_handler)();
-#endif
-
- 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, PHP_DIR_SEPARATOR);
- if (b) {
- strcat(d, b);
- overflow_limit -= strlen(b);
- } else {
- strcat(d, "/");
- strcat(d, cmd);
- overflow_limit-=(strlen(cmd)+1);
- }
- if (c) {
- *c = ' ';
- strncat(d, c, overflow_limit);
- }
- tmp = php_escape_shell_cmd(d);
- efree(d);
- d = tmp;
-#if PHP_SIGCHILD
- sig_handler = signal (SIGCHLD, SIG_DFL);
-#endif
-#ifdef PHP_WIN32
- fp = VCWD_POPEN(d, "rb");
-#else
- fp = VCWD_POPEN(d, "r");
-#endif
- if (!fp) {
- php_error(E_WARNING, "Unable to fork [%s]", d);
- efree(d);
- efree(buf);
-#if PHP_SIGCHILD
- signal (SIGCHLD, sig_handler);
-#endif
- return -1;
- }
- } else { /* not safe_mode */
-#if PHP_SIGCHILD
- sig_handler = signal (SIGCHLD, SIG_DFL);
-#endif
-#ifdef PHP_WIN32
- fp = VCWD_POPEN(cmd, "rb");
-#else
- fp = VCWD_POPEN(cmd, "r");
-#endif
- if (!fp) {
- php_error(E_WARNING, "Unable to fork [%s]", cmd);
- efree(buf);
-#if PHP_SIGCHILD
- signal (SIGCHLD, sig_handler);
-#endif
- return -1;
- }
- }
- buf[0] = '\0';
- if (type==2) {
- if (Z_TYPE_P(array) != IS_ARRAY) {
- pval_destructor(array);
- array_init(array);
- }
- }
-
- /* we register the resource so that case of an aborted connection the
- * fd gets pclosed
- */
-
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_popen());
-
- 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);
-#if PHP_SIGCHILD
- signal (SIGCHLD, sig_handler);
-#endif
- return -1;
- }
- buflen += EXEC_INPUT_BUF;
- }
-
- if ( fgets(&(buf[l]), buflen - l, fp) == NULL ) {
- /* eof */
- break;
- }
- l += strlen(&(buf[l]));
- } while ( (l > 0) && (buf[l-1] != '\n') );
-
- if ( feof(fp) && (l == 0) ) {
- break;
- }
-
-
- if (type == 1) {
- if (output) PUTS(buf);
- sapi_flush(TSRMLS_C);
- }
- 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 - 1])) {
- l--;
- }
- if (l < t) buf[l] = '\0';
-
- /* Return last line from the shell command */
- if (PG(magic_quotes_runtime)) {
- int len;
-
- tmp = php_addslashes(buf, 0, &len, 0 TSRMLS_CC);
- RETVAL_STRINGL(tmp, len, 0);
- } else {
- RETVAL_STRINGL(buf, l, 1);
- }
- } else {
- int b, i;
-
- while ((b = fread(buf, 1, buflen, fp)) > 0) {
- for (i = 0; i < b; i++)
- if (output) (void)PUTC(buf[i]);
- }
- }
-
- /* the zend_list_delete will pclose our popen'ed process */
- zend_list_delete(rsrc_id);
-
-#if HAVE_SYS_WAIT_H
- if (WIFEXITED(FG(pclose_ret))) {
- FG(pclose_ret) = WEXITSTATUS(FG(pclose_ret));
- }
-#endif
-#if PHP_SIGCHILD
- signal (SIGCHLD, sig_handler);
-#endif
- if (d) {
- efree(d);
- }
- efree(buf);
- return FG(pclose_ret);
-}
-/* }}} */
-
-/* {{{ proto string exec(string command [, array output [, int return_value]])
- Execute an external program */
-PHP_FUNCTION(exec)
-{
- pval **arg1, **arg2, **arg3;
- int arg_count = ZEND_NUM_ARGS();
- int ret;
-
- if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, &arg2, &arg3) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (arg_count) {
- case 1:
- ret = php_Exec(0, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC);
- break;
- case 2:
- ret = php_Exec(2, Z_STRVAL_PP(arg1), *arg2, return_value TSRMLS_CC);
- break;
- case 3:
- ret = php_Exec(2, Z_STRVAL_PP(arg1), *arg2, return_value TSRMLS_CC);
- Z_TYPE_PP(arg3) = IS_LONG;
- Z_LVAL_PP(arg3)=ret;
- break;
- }
-}
-
-/* }}} */
-
-/* {{{ proto int system(string command [, int return_value])
- Execute an external program and display output */
-PHP_FUNCTION(system)
-{
- pval **arg1, **arg2;
- int arg_count = ZEND_NUM_ARGS();
- int ret;
-
- if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (arg_count) {
- case 1:
- ret = php_Exec(1, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC);
- break;
- case 2:
- ret = php_Exec(1, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC);
- Z_TYPE_PP(arg2) = IS_LONG;
- Z_LVAL_PP(arg2)=ret;
- break;
- }
-}
-/* }}} */
-
-/* {{{ proto void passthru(string command [, int return_value])
- Execute an external program and display raw output */
-PHP_FUNCTION(passthru)
-{
- pval **arg1, **arg2;
- int arg_count = ZEND_NUM_ARGS();
- int ret;
-
- if (arg_count > 2 || zend_get_parameters_ex(arg_count, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (arg_count) {
- case 1:
- ret = php_Exec(3, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC);
- break;
- case 2:
- ret = php_Exec(3, Z_STRVAL_PP(arg1), NULL, return_value TSRMLS_CC);
- Z_TYPE_PP(arg2) = IS_LONG;
- Z_LVAL_PP(arg2)=ret;
- break;
- }
-}
-/* }}} */
-
-/* {{{ php_escape_shell_cmd
- Escape all chars that could possibly be used to
- break out of a shell command
-
- This function emalloc's a string and returns the pointer.
- Remember to efree it when done with it.
-
- *NOT* safe for binary strings
-*/
-char *php_escape_shell_cmd(char *str) {
- register int x, y, l;
- char *cmd;
-
- l = strlen(str);
- cmd = emalloc(2 * l + 1);
-
- for (x = 0, y = 0; x < l; x++) {
- switch (str[x]) {
- case '#': /* This is character-set independent */
- case '&':
- case ';':
- case '`':
- case '\'':
- case '"':
- case '|':
- case '*':
- case '?':
- case '~':
- case '<':
- case '>':
- case '^':
- case '(':
- case ')':
- case '[':
- case ']':
- case '{':
- case '}':
- case '$':
- case '\\':
- case '\x0A': /* excluding these two */
- case '\xFF':
- cmd[y++] = '\\';
- /* fall-through */
- default:
- cmd[y++] = str[x];
-
- }
- }
- cmd[y] = '\0';
- return cmd;
-}
-/* }}} */
-
-/* {{{ php_escape_shell_arg
- */
-char *php_escape_shell_arg(char *str) {
- int x, y, l;
- char *cmd;
-
- y = 0;
- l = strlen(str);
-
- cmd = emalloc(4 * l + 3); /* worst case */
-
- cmd[y++] = '\'';
-
- for (x = 0; x < l; x++) {
- switch (str[x]) {
- case '\'':
- cmd[y++] = '\'';
- cmd[y++] = '\\';
- cmd[y++] = '\'';
- /* fall-through */
- default:
- cmd[y++] = str[x];
- }
- }
- cmd[y++] = '\'';
- cmd[y] = '\0';
- return cmd;
-}
-/* }}} */
-
-/* {{{ proto string escapeshellcmd(string command)
- Escape shell metacharacters */
-PHP_FUNCTION(escapeshellcmd)
-{
- pval **arg1;
- char *cmd = NULL;
-
- if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg1);
- if (Z_STRLEN_PP(arg1)) {
- cmd = php_escape_shell_cmd(Z_STRVAL_PP(arg1));
- RETVAL_STRING(cmd, 1);
- efree(cmd);
- }
-}
-/* }}} */
-
-/* {{{ proto string escapeshellarg(string arg)
- Quote and escape an argument for use in a shell command */
-PHP_FUNCTION(escapeshellarg)
-{
- pval **arg1;
- char *cmd = NULL;
-
- if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg1);
- if (Z_STRLEN_PP(arg1)) {
- cmd = php_escape_shell_arg(Z_STRVAL_PP(arg1));
- RETVAL_STRING(cmd, 1);
- efree(cmd);
- }
-}
-/* }}} */
-
-/* {{{ proto string shell_exec(string cmd)
- Use pclose() for FILE* that has been opened via popen() */
-PHP_FUNCTION(shell_exec)
-{
- FILE *in;
- int readbytes, total_readbytes=0, allocated_space;
- pval **cmd;
- char *ret;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &cmd)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (PG(safe_mode)) {
- php_error(E_WARNING, "Cannot execute using backquotes in safe mode");
- RETURN_FALSE;
- }
-
- convert_to_string_ex(cmd);
-#ifdef PHP_WIN32
- if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "rt"))==NULL) {
-#else
- if ((in=VCWD_POPEN(Z_STRVAL_PP(cmd), "r"))==NULL) {
-#endif
- php_error(E_WARNING, "Unable to execute '%s'", Z_STRVAL_PP(cmd));
- }
- allocated_space = EXEC_INPUT_BUF;
- ret = (char *) emalloc(allocated_space);
- while (1) {
- readbytes = fread(ret+total_readbytes, 1, EXEC_INPUT_BUF, in);
- if (readbytes<=0) {
- break;
- }
- total_readbytes += readbytes;
- allocated_space = total_readbytes+EXEC_INPUT_BUF;
- ret = (char *) erealloc(ret, allocated_space);
- }
- pclose(in);
-
- RETVAL_STRINGL(ret, total_readbytes, 0);
- Z_STRVAL_P(return_value)[total_readbytes] = '\0';
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/exec.h b/ext/standard/exec.h
deleted file mode 100644
index ea156283ac..0000000000
--- a/ext/standard/exec.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef EXEC_H
-#define EXEC_H
-
-PHP_FUNCTION(system);
-PHP_FUNCTION(exec);
-PHP_FUNCTION(escapeshellcmd);
-PHP_FUNCTION(escapeshellarg);
-PHP_FUNCTION(passthru);
-PHP_FUNCTION(shell_exec);
-
-char *php_escape_shell_cmd(char *);
-char *php_escape_shell_arg(char *);
-int php_Exec(int type, char *cmd, pval *array, pval *return_value TSRMLS_DC);
-
-#endif /* EXEC_H */
diff --git a/ext/standard/file.c b/ext/standard/file.c
deleted file mode 100644
index 39cd424574..0000000000
--- a/ext/standard/file.c
+++ /dev/null
@@ -1,2492 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Bakken <ssb@fast.no> |
- | Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- | PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
- | PHP 4.1 streams by Wez Furlong (wez@thebrainroom.com) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
-
-/* {{{ includes */
-
-#include "php.h"
-#include "php_globals.h"
-#include "ext/standard/flock_compat.h"
-#include "ext/standard/exec.h"
-#include "ext/standard/php_filestat.h"
-#include "php_open_temporary_file.h"
-#include "ext/standard/basic_functions.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifdef PHP_WIN32
-#include <windows.h>
-#include <winsock.h>
-#define O_RDONLY _O_RDONLY
-#include "win32/param.h"
-#include "win32/winutil.h"
-#else
-#include <sys/param.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#endif
-#include "ext/standard/head.h"
-#include "safe_mode.h"
-#include "php_string.h"
-#include "file.h"
-#if HAVE_PWD_H
-#ifdef PHP_WIN32
-#include "win32/pwd.h"
-#else
-#include <pwd.h>
-#endif
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#include "fsock.h"
-#include "fopen_wrappers.h"
-#include "php_globals.h"
-
-#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
-#endif
-
-#if MISSING_FCLOSE_DECL
-extern int fclose(FILE *);
-#endif
-
-#ifdef HAVE_SYS_MMAN_H
-#include <sys/mman.h>
-#endif
-
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *) -1)
-#endif
-
-#include "scanf.h"
-#include "zend_API.h"
-
-#ifdef ZTS
-int file_globals_id;
-#else
-php_file_globals file_globals;
-#endif
-
-/* }}} */
-/* {{{ ZTS-stuff / Globals / Prototypes */
-
-/* sharing globals is *evil* */
-static int le_fopen, le_popen, le_socket;
-/* sorry folks; including this even if you haven't enabled streams
- saves a zillion ifdefs */
-static int le_stream = FAILURE;
-
-
-/* }}} */
-/* {{{ Module-Stuff */
-
-static void _file_popen_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- FILE *pipe = (FILE *)rsrc->ptr;
-
- FG(pclose_ret) = pclose(pipe);
-}
-
-
-static void _file_socket_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- int *sock = (int *)rsrc->ptr;
-
- SOCK_FCLOSE(*sock);
-#if HAVE_SHUTDOWN
- shutdown(*sock, 0);
-#endif
- efree(sock);
-}
-
-#if HAVE_PHP_STREAM
-static void _file_stream_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- php_stream *stream = (php_stream*)rsrc->ptr;
-
- php_stream_close(stream);
-}
-#endif
-
-PHPAPI int php_file_le_stream(void)
-{
- return le_stream;
-}
-
-static void _file_fopen_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC)
-{
- FILE *fp = (FILE *)rsrc->ptr;
-
- fclose(fp);
-}
-
-
-PHPAPI int php_file_le_fopen(void) /* XXX doe we really want this???? */
-{
- return le_fopen;
-}
-
-PHPAPI int php_file_le_popen(void) /* XXX you may not like this, but I need it. -- KK */
-{
- return le_popen;
-}
-
-
-PHPAPI int php_file_le_socket(void) /* XXX doe we really want this???? */
-{
- return le_socket;
-}
-
-
-static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
-{
- zend_hash_init(&FG(ht_fsock_keys), 0, NULL, NULL, 1);
- zend_hash_init(&FG(ht_fsock_socks), 0, NULL, (void (*)(void *))php_msock_destroy, 1);
- FG(def_chunk_size) = PHP_FSOCK_CHUNK_SIZE;
- FG(phpsockbuf) = NULL;
- FG(fgetss_state) = 0;
- FG(pclose_ret) = 0;
-}
-
-
-static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC)
-{
- zend_hash_destroy(&FG(ht_fsock_socks));
- zend_hash_destroy(&FG(ht_fsock_keys));
- php_cleanup_sockbuf(1 TSRMLS_CC);
-}
-
-
-PHP_MINIT_FUNCTION(file)
-{
- le_fopen = zend_register_list_destructors_ex(_file_fopen_dtor, NULL, "file", module_number);
- le_popen = zend_register_list_destructors_ex(_file_popen_dtor, NULL, "pipe", module_number);
- le_socket = zend_register_list_destructors_ex(_file_socket_dtor, NULL, "socket", module_number);
-
-#if HAVE_PHP_STREAM
- le_stream = zend_register_list_destructors_ex(_file_stream_dtor, NULL, "stream", module_number);
-#endif
-
-#ifdef ZTS
- ts_allocate_id(&file_globals_id, sizeof(php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor);
-#else
- file_globals_ctor(&file_globals TSRMLS_CC);
-#endif
-
- REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SEEK_CUR", SEEK_CUR, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("SEEK_END", SEEK_END, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOCK_SH", 1, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOCK_EX", 2, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOCK_UN", 3, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOCK_NB", 4, CONST_CS | CONST_PERSISTENT);
-
- return SUCCESS;
-}
-
-/* }}} */
-
-PHP_MSHUTDOWN_FUNCTION(file)
-{
-#ifndef ZTS
- file_globals_dtor(&file_globals TSRMLS_CC);
-#endif
- return SUCCESS;
-}
-
-
-
-/* {{{ proto bool flock(int fp, int operation [, int wouldblock])
- Portable file locking */
-
-static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
-
-PHP_FUNCTION(flock)
-{
- pval **arg1, **arg2, **arg3;
- int type, fd, act, ret, arg_count = ARG_COUNT(ht);
- void *what;
-
- if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, &arg2, &arg3) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_FD, (void*)&fd, 1) == FAILURE) {
- RETURN_FALSE;
- }
- } else
-#endif
- if (type == le_socket) {
- fd = *(int *) what;
- } else {
- fd = fileno((FILE*) what);
- }
-
- convert_to_long_ex(arg2);
-
- act = (*arg2)->value.lval & 3;
- if (act < 1 || act > 3) {
- php_error(E_WARNING, "Illegal operation argument");
- RETURN_FALSE;
- }
-
- /* flock_values contains all possible actions
- if (arg2 & 4) we won't block on the lock */
- act = flock_values[act - 1] | ((*arg2)->value.lval & 4 ? LOCK_NB : 0);
- if ((ret=flock(fd, act)) == -1) {
- RETURN_FALSE;
- }
- if(ret==-1 && errno==EWOULDBLOCK && arg_count==3) {
- (*arg3)->type = IS_LONG;
- (*arg3)->value.lval=1;
- }
- RETURN_TRUE;
-}
-
-/* }}} */
-
-#define PHP_META_UNSAFE ".\\+*?[^]$() "
-
-/* {{{ 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;
- int use_include_path = 0;
- int in_tag=0, in_meta_tag=0, done=0;
- int looking_for_val=0, have_name=0, have_content=0;
- int saw_name=0, saw_content=0;
- char *name=NULL, *value=NULL, *temp=NULL;
- php_meta_tags_token tok, tok_last;
- php_meta_tags_data md;
-
- /* check args */
- switch (ARG_COUNT(ht)) {
- case 1:
- if (zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &filename, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg2);
- use_include_path = (*arg2)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- md.fp = php_fopen_wrapper((*filename)->value.str.val, "rb", use_include_path|ENFORCE_SAFE_MODE, &md.issock, &md.socketd, NULL TSRMLS_CC);
- if (!md.fp && !md.socketd) {
- if (md.issock != BAD_URL) {
- char *tmp = estrndup(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename));
- php_strip_url_passwd(tmp);
- php_error(E_WARNING, "get_meta_tags(\"%s\") - %s", tmp, strerror(errno));
- efree(tmp);
- }
- RETURN_FALSE;
- }
-
- if (array_init(return_value)==FAILURE) {
- if (md.issock) {
- SOCK_FCLOSE(md.socketd);
- } else {
- fclose(md.fp);
- }
- RETURN_FALSE;
- }
-
- tok_last = TOK_EOF;
-
- md.ulc = 0;
- md.token_data = NULL;
- md.token_len = 0;
-
- while (!done && (tok = php_next_meta_token(&md)) != TOK_EOF) {
-
- if (tok == TOK_ID) {
- if (tok_last == TOK_OPENTAG) {
- in_meta_tag = !strcasecmp("meta", md.token_data);
- md.in_meta = in_meta_tag;
- } else if (tok_last == TOK_SLASH && in_tag) {
- if (strcasecmp("head", md.token_data) == 0) {
- /* We are done here! */
- done = 1;
- }
- } else if (tok_last == TOK_EQUAL && looking_for_val) {
- if (saw_name) {
- /* Get the NAME attr (Single word attr, non-quoted) */
- temp = name = estrndup(md.token_data, md.token_len);
-
- while (temp && *temp) {
- if (strchr(PHP_META_UNSAFE, *temp)) {
- *temp = '_';
- }
- temp++;
- }
-
- have_name = 1;
- } else if (saw_content) {
- /* Get the CONTENT attr (Single word attr, non-quoted) */
- if (PG(magic_quotes_runtime)) {
- value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC);
- } else {
- value = estrndup(md.token_data, md.token_len);
- }
-
- have_content = 1;
- }
-
- looking_for_val = 0;
- } else {
- if (in_meta_tag) {
- if (strcasecmp("name", md.token_data) == 0) {
- saw_name = 1;
- saw_content = 0;
- looking_for_val = 1;
- } else if (strcasecmp("content", md.token_data) == 0) {
- saw_name = 0;
- saw_content = 1;
- looking_for_val = 1;
- }
- }
- }
- } else if (tok == TOK_STRING && tok_last == TOK_EQUAL && looking_for_val) {
- if (saw_name) {
- /* Get the NAME attr (Quoted single/double) */
- temp = name = estrndup(md.token_data, md.token_len);
-
- while (temp && *temp) {
- if (strchr(PHP_META_UNSAFE, *temp)) {
- *temp = '_';
- }
- temp++;
- }
-
- have_name = 1;
- } else if (saw_content) {
- /* Get the CONTENT attr (Single word attr, non-quoted) */
- if (PG(magic_quotes_runtime)) {
- value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC);
- } else {
- value = estrndup(md.token_data, md.token_len);
- }
-
- have_content = 1;
- }
-
- looking_for_val = 0;
- } else if (tok == TOK_OPENTAG) {
- if (looking_for_val) {
- looking_for_val = 0;
- have_name = saw_name = 0;
- have_content = saw_content = 0;
- }
- in_tag = 1;
- } else if (tok == TOK_CLOSETAG) {
- if (have_name) {
- /* For BC */
- php_strtolower(name, strlen(name));
- if (have_content) {
- add_assoc_string(return_value, name, value, 0);
- } else {
- add_assoc_string(return_value, name, empty_string, 0);
- }
-
- efree(name);
- } else if (have_content) {
- efree(value);
- }
-
- name = value = NULL;
-
- /* Reset all of our flags */
- in_tag = in_meta_tag = looking_for_val = 0;
- have_name = saw_name = 0;
- have_content = saw_content = 0;
- md.in_meta = 0;
- }
-
- tok_last = tok;
-
- if (md.token_data)
- efree(md.token_data);
-
- md.token_data = NULL;
- }
-
- if (md.issock) {
- SOCK_FCLOSE(md.socketd);
- } else {
- fclose(md.fp);
- }
-}
-
-/* }}} */
-/* {{{ proto array file(string filename [, int use_include_path])
- Read entire file into an array */
-
-#define PHP_FILE_BUF_SIZE 80
-
-PHP_FUNCTION(file)
-{
- pval **filename, **arg2;
- FILE *fp;
- char *slashed, *target_buf;
- register int i=0;
- int use_include_path = 0;
- int issock=0, socketd=0;
- int target_len, len;
- zend_bool reached_eof=0;
-
- /* check args */
- switch (ARG_COUNT(ht)) {
- case 1:
- if (zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &filename, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg2);
- use_include_path = (*arg2)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- fp = php_fopen_wrapper((*filename)->value.str.val, "rb", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
- if (!fp && !socketd) {
- if (issock != BAD_URL) {
- char *tmp = estrndup(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename));
- php_strip_url_passwd(tmp);
- php_error(E_WARNING, "file(\"%s\") - %s", tmp, strerror(errno));
- efree(tmp);
- }
- RETURN_FALSE;
- }
-
- /* Initialize return array */
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- /* Now loop through the file and do the magic quotes thing if needed */
- target_len = 0;
- target_buf = NULL;
- while (1) {
- if (!target_buf) {
- target_buf = (char *) emalloc(PHP_FILE_BUF_SIZE+1);
- target_buf[PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */
- } else {
- target_buf = (char *) erealloc(target_buf, target_len+PHP_FILE_BUF_SIZE+1);
- target_buf[target_len+PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */
- }
- if (FP_FGETS(target_buf+target_len, PHP_FILE_BUF_SIZE, socketd, fp, issock)==NULL) {
- if (target_len==0) {
- efree(target_buf);
- break;
- } else {
- reached_eof = 1;
- }
- }
- if (!reached_eof) {
- target_len += strlen(target_buf+target_len);
- if (target_buf[target_len-1]!='\n') {
- continue;
- }
- }
- if (PG(magic_quotes_runtime)) {
- slashed = php_addslashes(target_buf, target_len, &len, 1 TSRMLS_CC); /* 1 = free source string */
- add_index_stringl(return_value, i++, slashed, len, 0);
- } else {
- target_buf = erealloc(target_buf, target_len+1); /* do we really want to do that? */
- add_index_stringl(return_value, i++, target_buf, target_len, 0);
- }
- if (reached_eof) {
- break;
- }
- target_buf = NULL;
- target_len = 0;
- }
- 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 *opened_path;
- char p[64];
- FILE *fp;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- convert_to_string_ex(arg2);
- d = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
- strlcpy(p, Z_STRVAL_PP(arg2), sizeof(p));
-
- if ((fp = php_open_temporary_file(d, p, &opened_path TSRMLS_CC))) {
- fclose(fp);
- RETVAL_STRING(opened_path, 0);
- } else {
- RETVAL_FALSE;
- }
- efree(d);
-}
-
-/* }}} */
-/* {{{ proto int tmpfile(void)
- Create a temporary file that will be deleted automatically after use */
-PHP_NAMED_FUNCTION(php_if_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);
-}
-/* }}} */
-
-#if HAVE_PHP_STREAM
-/* {{{ PHP_FUNCTION
- */
-PHP_FUNCTION(fopenstream)
-{
- zval ** zfilename, ** zmode;
- php_stream * stream;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &zfilename, &zmode) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(zfilename);
- convert_to_string_ex(zmode);
-
- stream = php_stream_fopen(Z_STRVAL_PP(zfilename), Z_STRVAL_PP(zmode));
-
- if (stream == NULL) {
- zend_error(E_WARNING, "%s(): unable to open %s: %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(zfilename), strerror(errno));
- RETURN_FALSE;
- }
- ZEND_REGISTER_RESOURCE(return_value, stream, le_stream);
-}
-/* }}} */
-#endif
-
-/* {{{ proto int fopen(string filename, string mode [, int use_include_path])
- Open a file or a URL and return a file pointer */
-
-PHP_NAMED_FUNCTION(php_if_fopen)
-{
- pval **arg1, **arg2, **arg3;
- FILE *fp;
- char *p;
- int *sock;
- int use_include_path = 0;
- int issock=0, socketd=0;
-
- switch(ARG_COUNT(ht)) {
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 3:
- if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg3);
- use_include_path = (*arg3)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- convert_to_string_ex(arg2);
- p = estrndup((*arg2)->value.str.val, (*arg2)->value.str.len);
-
- /*
- * We need a better way of returning error messages from
- * php_fopen_wrapper().
- */
- fp = php_fopen_wrapper((*arg1)->value.str.val, p, use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
- if (!fp && !socketd) {
- if (issock != BAD_URL) {
- char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
- php_strip_url_passwd(tmp);
- php_error(E_WARNING, "fopen(\"%s\", \"%s\") - %s", tmp, p, strerror(errno));
- efree(tmp);
- }
- efree(p);
- RETURN_FALSE;
- }
-
- efree(p);
- FG(fgetss_state)=0;
-
- if (issock) {
- sock=emalloc(sizeof(int));
- *sock=socketd;
- ZEND_REGISTER_RESOURCE(return_value, sock, le_socket);
- } else {
- ZEND_REGISTER_RESOURCE(return_value, fp, le_fopen);
- }
-}
-
-/* }}} */
-/* {{{ proto int fclose(int fp)
- Close an open file pointer */
-
-PHP_FUNCTION(fclose)
-{
- pval **arg1;
- int type;
- void *what;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 3, le_fopen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- zend_list_delete((*arg1)->value.lval);
- RETURN_TRUE;
-}
-
-/* }}} */
-/* {{{ proto int popen(string command, string mode)
- Execute a command and open either a read or a write pipe to it */
-
-PHP_FUNCTION(popen)
-{
- pval **arg1, **arg2;
- FILE *fp;
- char *p, *tmp = NULL;
- char *b, buf[1024];
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- convert_to_string_ex(arg2);
- p = estrndup((*arg2)->value.str.val, (*arg2)->value.str.len);
- if (PG(safe_mode)){
- b = strchr((*arg1)->value.str.val,' ');
- if (!b) {
- b = strrchr((*arg1)->value.str.val,'/');
- } else {
- char *c;
- c = (*arg1)->value.str.val;
- while((*b!='/')&&(b!=c)) {
- b--;
- }
- if (b==c) {
- b=NULL;
- }
- }
- if (b) {
- snprintf(buf, sizeof(buf), "%s%s", PG(safe_mode_exec_dir), b);
- } else {
- snprintf(buf, sizeof(buf), "%s/%s", PG(safe_mode_exec_dir), (*arg1)->value.str.val);
- }
-
- tmp = php_escape_shell_cmd(buf);
- fp = VCWD_POPEN(tmp, p);
- efree(tmp);
-
- if (!fp) {
- php_error(E_WARNING, "popen(\"%s\", \"%s\") - %s", buf, p, strerror(errno));
- RETURN_FALSE;
- }
- } else {
- fp = VCWD_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;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", NULL, 1, le_popen);
- ZEND_VERIFY_RESOURCE(what);
-
- zend_list_delete((*arg1)->value.lval);
- RETURN_LONG(FG(pclose_ret));
-}
-
-/* }}} */
-/* {{{ proto int feof(int fp)
- Test for end-of-file on a file pointer */
-
-PHP_FUNCTION(feof)
-{
- pval **arg1;
- int type;
- int issock=0;
- int socketd=0;
- void *what;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- if (type == le_socket) {
- issock=1;
- socketd=*(int *) what;
- }
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- if (php_stream_eof((php_stream*)what))
- {
- RETURN_TRUE;
- }
- RETURN_FALSE;
- }
- else
-#endif
- {
- if (FP_FEOF(socketd, (FILE*)what, issock)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
- }
-}
-/* }}} */
-
-
-/* {{{ proto int set_socket_blocking(int socket_descriptor, int mode)
- Set blocking/non-blocking mode on a socket */
-PHPAPI int php_set_sock_blocking(int socketd, int block)
-{
- int ret = SUCCESS;
- int flags;
- int myflag = 0;
-
-#ifdef PHP_WIN32
- /* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */
- flags = !block;
- if (ioctlsocket(socketd, FIONBIO, &flags)==SOCKET_ERROR){
- php_error(E_WARNING, "%s", WSAGetLastError());
- ret = FALSE;
- }
-#else
- flags = fcntl(socketd, F_GETFL);
-#ifdef O_NONBLOCK
- myflag = O_NONBLOCK; /* POSIX version */
-#elif defined(O_NDELAY)
- myflag = O_NDELAY; /* old non-POSIX version */
-#endif
- if (!block) {
- flags |= myflag;
- } else {
- flags &= ~myflag;
- }
- fcntl(socketd, F_SETFL, flags);
-#endif
- return ret;
-}
-
-PHP_FUNCTION(socket_set_blocking)
-{
- pval **arg1, **arg2;
- int block, type;
- int socketd = 0;
- void *what;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 2, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- convert_to_long_ex(arg2);
- block = (*arg2)->value.lval;
-
- if (type == le_socket) {
- socketd = *(int*)what;
- }
-#if HAVE_PHP_STREAM
- else if (type == le_stream) {
- if (php_stream_cast((php_stream*)what, PHP_STREAM_AS_SOCKETD, (void*)&socketd, 1) == FAILURE) {
- RETURN_FALSE;
- }
- }
-#endif
- if (php_set_sock_blocking(socketd, block) == FAILURE)
- RETURN_FALSE;
-
- php_sockset_blocking(socketd, block == 0 ? 0 : 1);
-
- RETURN_TRUE;
-}
-
-/* }}} */
-
-PHP_FUNCTION(set_socket_blocking)
-{
- php_error(E_NOTICE, "set_socket_blocking() is deprecated, use socket_set_blocking() instead");
- PHP_FN(socket_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
-}
-
-/* {{{ proto bool socket_set_timeout(int socket_descriptor, int seconds, int microseconds)
- Set timeout on socket read to seconds + microseonds */
-PHP_FUNCTION(socket_set_timeout)
-{
-#if HAVE_SYS_TIME_H
- zval **socket, **seconds, **microseconds;
- int type;
- void *what;
- int socketd = 0;
- struct timeval t;
-
- if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, &microseconds)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
- what = zend_fetch_resource(socket TSRMLS_CC, -1, "File-Handle", &type, 1, le_socket);
- ZEND_VERIFY_RESOURCE(what);
- socketd = *(int *)what;
-
- convert_to_long_ex(seconds);
- t.tv_sec = (*seconds)->value.lval;
-
- if (ZEND_NUM_ARGS() == 3) {
- convert_to_long_ex(microseconds);
- t.tv_usec = (*microseconds)->value.lval % 1000000;
- t.tv_sec += (*microseconds)->value.lval / 1000000;
- }
- else
- t.tv_usec = 0;
-
- php_sockset_timeout(socketd, &t);
- RETURN_TRUE;
-#endif /* HAVE_SYS_TIME_H */
-}
-
-/* }}} */
-
-
-/* {{{ proto array socket_get_status(resource socket_descriptor)
- Return an array describing socket status */
-PHP_FUNCTION(socket_get_status)
-{
- zval **socket;
- int type;
- void *what;
- int socketd = 0;
- struct php_sockbuf *sock;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(socket TSRMLS_CC, -1, "File-Handle", &type, 1, le_socket);
- ZEND_VERIFY_RESOURCE(what);
- socketd = *(int *)what;
- sock = php_get_socket(socketd);
-
- array_init(return_value);
-
- add_assoc_bool(return_value, "timed_out", sock->timeout_event);
- add_assoc_bool(return_value, "blocked", sock->is_blocked);
- add_assoc_bool(return_value, "eof", sock->eof);
- add_assoc_long(return_value, "unread_bytes", sock->writepos - sock->readpos);
-}
-/* }}} */
-
-
-/* {{{ proto string fgets(int fp, int length)
- Get a line from file pointer */
-
-PHP_FUNCTION(fgets)
-{
- pval **arg1, **arg2;
- int len, type;
- char *buf;
- int issock=0;
- int socketd=0;
- void *what;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- convert_to_long_ex(arg2);
- len = (*arg2)->value.lval;
-
- if (len < 0) {
- php_error(E_WARNING, "length parameter to fgets() may not be negative");
- RETURN_FALSE;
- }
-
- 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 HAVE_PHP_STREAM
- if (type == le_stream) {
- if (php_stream_gets((php_stream*)what, buf, len) == NULL)
- goto exit_failed;
- }
- else
-#endif
- {
- if (type == le_socket) {
- issock=1;
- socketd=*(int*)what;
- }
-#ifdef HAVE_FLUSHIO
- if (type == le_fopen) {
- fseek((FILE*)what, 0, SEEK_CUR);
- }
-#endif
- if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL)
- goto exit_failed;
- }
-
- if (PG(magic_quotes_runtime)) {
- return_value->value.str.val = php_addslashes(buf, 0, &return_value->value.str.len, 1 TSRMLS_CC);
- } else {
- return_value->value.str.val = buf;
- return_value->value.str.len = strlen(return_value->value.str.val);
- /* resize buffer if it's much larger than the result */
- if(return_value->value.str.len < len/2) {
- return_value->value.str.val = erealloc(buf, return_value->value.str.len+1);
- }
- }
- return_value->type = IS_STRING;
- return;
-
-exit_failed:
- RETVAL_FALSE;
- efree(buf);
-}
-
-/* }}} */
-/* {{{ 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;
- int result;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- if (type == le_socket) {
- issock=1;
- socketd=*(int*)what;
- }
-
-#ifdef HAVE_FLUSHIO
- if (type == le_fopen) {
- fseek((FILE*)what, 0, SEEK_CUR);
- }
-#endif
- buf = emalloc(sizeof(int));
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- result = php_stream_getc((php_stream*)what);
- }
- else
-#endif
- result = FP_FGETC(socketd, (FILE*)what, issock);
-
-
- if (result == EOF) {
- efree(buf);
- RETVAL_FALSE;
- } else {
- buf[0]=result;
- buf[1]='\0';
- return_value->value.str.val = buf;
- return_value->value.str.len = 1;
- return_value->type = IS_STRING;
- }
-}
-
-/* }}} */
-
-/* {{{ proto string fgetss(int fp, int length [, string allowable_tags])
- Get a line from file pointer and strip HTML tags */
-
-PHP_FUNCTION(fgetss)
-{
- pval **fd, **bytes, **allow=NULL;
- int len, type;
- char *buf;
- int issock=0;
- int socketd=0;
- void *what;
- char *allowed_tags=NULL;
- int allowed_tags_len=0;
-
- switch(ARG_COUNT(ht)) {
- case 2:
- if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 3:
- if (zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(allow);
- allowed_tags = (*allow)->value.str.val;
- allowed_tags_len = (*allow)->value.str.len;
- break;
- default:
- WRONG_PARAM_COUNT;
- /* NOTREACHED */
- break;
- }
-
- what = zend_fetch_resource(fd TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
- if (type == le_socket) {
- issock=1;
- socketd=*(int*)what;
- }
-
- convert_to_long_ex(bytes);
- len = (*bytes)->value.lval;
- if (len < 0) {
- php_error(E_WARNING, "length parameter to fgetss() may not be negative");
- RETURN_FALSE;
- }
-
- buf = emalloc(sizeof(char) * (len + 1));
- /*needed because recv doesnt set null char at end*/
- memset(buf, 0, len + 1);
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- if (php_stream_gets((php_stream*)what, buf, len) == NULL) {
- efree(buf);
- RETURN_FALSE;
- }
- }
- else
-#endif
- 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), FG(fgetss_state), allowed_tags, allowed_tags_len);
-
- RETURN_STRING(buf, 0);
-}
-
-/* }}} */
-/* {{{ proto mixed fscanf(string str, string format [, string ...])
- Implements a mostly ANSI compatible fscanf() */
-PHP_FUNCTION(fscanf)
-{
- int result;
- pval **file_handle, **format_string;
- int len, type;
- char *buf;
- int issock=0;
- int socketd=0;
- void *what;
-
- zval ***args;
- int argCount;
-
- argCount = ZEND_NUM_ARGS();
- if (argCount < 2) {
- WRONG_PARAM_COUNT;
- }
- args = (zval ***)emalloc(argCount * sizeof(zval **));
- if (!args || (zend_get_parameters_array_ex(argCount, args) == FAILURE)) {
- efree( args );
- WRONG_PARAM_COUNT;
- }
-
- file_handle = args[0];
- format_string = args[1];
-
- what = zend_fetch_resource(file_handle TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
-
- /*
- * we can't do a ZEND_VERIFY_RESOURCE(what), otherwise we end up
- * with a leak if we have an invalid filehandle. This needs changing
- * if the code behind ZEND_VERIFY_RESOURCE changed. - cc
- */
- if (!what) {
- efree(args);
- RETURN_FALSE;
- }
-
- len = SCAN_MAX_FSCANF_BUFSIZE;
-
- if (type == le_socket) {
- issock=1;
- socketd=*(int*)what;
- }
- buf = emalloc(sizeof(char) * (len + 1));
- /* needed because recv doesnt put a null at the end*/
- memset(buf, 0, len+1);
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- if (php_stream_gets((php_stream*)what, buf, len) == NULL) {
- efree(buf);
- RETURN_FALSE;
- }
- }
- else
-#endif
-
- if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
- efree(buf);
- RETURN_FALSE;
- }
-
- convert_to_string_ex( format_string );
- result = php_sscanf_internal( buf, (*format_string)->value.str.val,
- argCount, args, 2, &return_value TSRMLS_CC);
- efree(args);
- efree(buf);
- if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
- WRONG_PARAM_COUNT
- }
-
-
-}
-/* }}} */
-
-/* {{{ proto int fwrite(int fp, string str [, int length])
- Binary-safe file write */
-
-PHP_FUNCTION(fwrite)
-{
- pval **arg1, **arg2, **arg3=NULL;
- int ret, type;
- int num_bytes;
- int issock=0;
- int socketd=0;
- void *what;
-
- switch (ARG_COUNT(ht)) {
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(arg2);
- num_bytes = (*arg2)->value.str.len;
- break;
- case 3:
- if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(arg2);
- convert_to_long_ex(arg3);
- num_bytes = MIN((*arg3)->value.lval, (*arg2)->value.str.len);
- break;
- default:
- WRONG_PARAM_COUNT;
- /* NOTREACHED */
- break;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC, -1, "File-Handle", &type, 4, le_fopen,
- le_popen, le_socket, le_stream);
- 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(Z_STRVAL_PP(arg2), &num_bytes TSRMLS_CC);
- }
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- ret = php_stream_write((php_stream*)what, Z_STRVAL_PP(arg2), num_bytes);
- }
- else
-#endif
-
- if (issock){
- ret = SOCK_WRITEL((*arg2)->value.str.val, num_bytes, socketd);
- } else {
-#ifdef HAVE_FLUSHIO
- if (type == le_fopen) {
- fseek((FILE*)what, 0, SEEK_CUR);
- }
-#endif
- ret = fwrite((*arg2)->value.str.val, 1, num_bytes, (FILE*)what);
- }
- RETURN_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto int fflush(int fp)
- Flushes output */
-
-PHP_FUNCTION(fflush)
-{
- pval **arg1;
- int ret, type;
- int issock=0;
- int socketd=0;
- void *what;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", &type, 4, le_fopen, le_popen, le_socket, le_stream);
- ZEND_VERIFY_RESOURCE(what);
-
-#if HAVE_PHP_STREAM
- if (type == le_stream) {
- ret = php_stream_flush((php_stream*)what);
- if (ret) {
- RETURN_FALSE;
- }
- RETURN_TRUE;
- }
-#endif
-
- if (type == le_socket) {
- issock=1;
- socketd=*(int*)what;
- }
-
- if (issock){
- ret = fsync(socketd);
- } else {
- ret = fflush((FILE*)what);
- }
-
- if (ret) {
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
-}
-
-/* }}} */
-/* {{{ proto int set_file_buffer(int fp, int buffer)
- Set file write buffer */
-
-PHP_FUNCTION(set_file_buffer)
-{
- pval **arg1, **arg2;
- int ret, type, buff;
- void *what;
-
- switch (ARG_COUNT(ht)) {
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- /* NOTREACHED */
- break;
- }
-
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", &type, 2, le_fopen, le_popen);
- ZEND_VERIFY_RESOURCE(what);
-
- convert_to_long_ex(arg2);
- buff = (*arg2)->value.lval;
-
- /* if buff is 0 then set to non-buffered */
- if (buff == 0){
- ret = setvbuf((FILE*)what, NULL, _IONBF, 0);
- } else {
- ret = setvbuf((FILE*)what, NULL, _IOFBF, buff);
- }
-
- RETURN_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto int rewind(int fp)
- Rewind the position of a file pointer */
-
-PHP_FUNCTION(rewind)
-{
- pval **arg1;
- void *what;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-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;
- long ret;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", NULL, 2, le_fopen, le_popen);
- ZEND_VERIFY_RESOURCE(what);
-
- ret = ftell((FILE*) what);
- if(ret == -1) {
- RETURN_FALSE;
- }
-
- RETURN_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto int fseek(int fp, int offset [, int whence])
- Seek on a file pointer */
-
-PHP_FUNCTION(fseek)
-{
- zval **arg1, **arg2, **arg3;
- int argcount = ARG_COUNT(ht), whence = SEEK_SET;
- void *what;
-
- if (argcount < 2 || argcount > 3 ||
- zend_get_parameters_ex(argcount, &arg1, &arg2, &arg3) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", NULL, 2, le_fopen, le_popen);
- ZEND_VERIFY_RESOURCE(what);
-
- convert_to_long_ex(arg2);
- if (argcount > 2) {
- convert_to_long_ex(arg3);
- whence = (*arg3)->value.lval;
- }
-
- RETURN_LONG(fseek((FILE*)what, (*arg2)->value.lval, whence));
-}
-
-/* }}} */
-/* {{{ proto int mkdir(string pathname, int mode)
- Create a directory */
-
-PHP_FUNCTION(mkdir)
-{
- pval **arg1, **arg2;
- int ret;
- mode_t mode;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- convert_to_long_ex(arg2);
- mode = (mode_t) (*arg2)->value.lval;
- if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val, NULL, CHECKUID_ALLOW_ONLY_DIR))) {
- RETURN_FALSE;
- }
- ret = VCWD_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;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
- RETURN_FALSE;
- }
- ret = VCWD_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 TSRMLS_DC)
-{
- size_t bcount = 0;
- int ready = 0;
- char buf[8192];
- /* XXX: add stream support --Wez. */
-
-#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_SHARED, fd, off);
- if (p != (void *) MAP_FAILED) {
- BG(mmap_file) = p;
- BG(mmap_len) = len;
- PHPWRITE(p, len);
- BG(mmap_file) = NULL;
- 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;
- int rsrc_id;
-
- /* check args */
- switch (ARG_COUNT(ht)) {
- case 1:
- if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg2);
- use_include_path = (*arg2)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
-
- /*
- * We need a better way of returning error messages from
- * php_fopen_wrapper().
- */
- fp = php_fopen_wrapper((*arg1)->value.str.val, "rb", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
- if (!fp && !socketd){
- if (issock != BAD_URL) {
- char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
- php_strip_url_passwd(tmp);
- php_error(E_WARNING, "readfile(\"%s\") - %s", tmp, strerror(errno));
- efree(tmp);
- }
- RETURN_FALSE;
- }
-
- if (issock) {
- int *sock=emalloc(sizeof(int));
- *sock = socketd;
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, sock, php_file_le_socket());
- } else {
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_fopen());
- }
-
- size = php_passthru_fd(socketd, fp, issock TSRMLS_CC);
-
- zend_list_delete(rsrc_id);
-
- RETURN_LONG(size);
-}
-
-/* }}} */
-/* {{{ proto int umask([int mask])
- Return or change the umask */
-
-PHP_FUNCTION(umask)
-{
- pval **arg1;
- int oldumask;
- int arg_count = ARG_COUNT(ht);
-
- oldumask = umask(077);
-
- if (arg_count == 0) {
- umask(oldumask);
- } else {
- if (arg_count > 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg1);
- umask((*arg1)->value.lval);
- }
-
- /* XXX we should maybe reset the umask after each request! */
-
- RETURN_LONG(oldumask);
-}
-
-/* }}} */
-/* {{{ proto int fpassthru(int fp)
- Output all remaining data from a file pointer */
-
-PHP_FUNCTION(fpassthru)
-{
- pval **arg1;
- int size, type;
- int issock=0;
- int socketd=0;
- void *what;
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- /* XXX: add stream support --Wez. */
- what = zend_fetch_resource(arg1 TSRMLS_CC,-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 = php_passthru_fd(socketd, (FILE*) what, issock TSRMLS_CC);
-
- zend_list_delete((*arg1)->value.lval);
-
- RETURN_LONG(size);
-}
-/* }}} */
-
-/* {{{ proto int rename(string old_name, string new_name)
- Rename a file */
-PHP_FUNCTION(rename)
-{
- pval **old_arg, **new_arg;
- char *old_name, *new_name;
- int ret;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &old_arg, &new_arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(old_arg);
- convert_to_string_ex(new_arg);
-
- old_name = (*old_arg)->value.str.val;
- new_name = (*new_arg)->value.str.val;
-
- if (PG(safe_mode) &&(!php_checkuid(old_name, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
- ret = VCWD_RENAME(old_name, new_name);
-
- if (ret == -1) {
- php_error(E_WARNING, "Rename failed (%s)", strerror(errno));
- RETURN_FALSE;
- }
-
- RETVAL_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int unlink(string filename)
- Delete a file */
-PHP_FUNCTION(unlink)
-{
- pval **filename;
- int ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- if (PG(safe_mode) && !php_checkuid((*filename)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR)) {
- RETURN_FALSE;
- }
-
- ret = VCWD_UNLINK((*filename)->value.str.val);
- if (ret == -1) {
- php_error(E_WARNING, "Unlink failed (%s)", strerror(errno));
- RETURN_FALSE;
- }
- /* Clear stat cache */
- PHP_FN(clearstatcache)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int ftruncate (int fp, int size)
- Truncate file to 'size' length */
-PHP_NAMED_FUNCTION(php_if_ftruncate)
-{
- zval **fp , **size;
- short int ret;
- int type;
- void *what;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(fp TSRMLS_CC,-1, "File-Handle", &type, 3, le_fopen, le_popen, le_socket);
- ZEND_VERIFY_RESOURCE(what);
-
- if (type == le_socket)
- {
- php_error(E_WARNING, "can't truncate sockets!");
- RETURN_FALSE;
- }
-
- convert_to_long_ex(size);
-
- ret = ftruncate(fileno((FILE *)what), (*size)->value.lval);
- RETURN_LONG(ret + 1);
-}
-/* }}} */
-
-/* {{{ proto int fstat(int fp)
- Stat() on a filehandle */
-PHP_NAMED_FUNCTION(php_if_fstat)
-{
- zval **fp;
- zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev,
- *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks;
- int type;
- void *what;
- struct stat stat_sb;
-
- char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
- "size", "atime", "mtime", "ctime", "blksize", "blocks"};
-
- if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(fp TSRMLS_CC,-1, "File-Handle", &type, 3, le_fopen, le_popen, le_socket);
- ZEND_VERIFY_RESOURCE(what);
-
- if (fstat(fileno((FILE *) what ), &stat_sb)) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
-
- MAKE_LONG_ZVAL_INCREF(stat_dev, stat_sb.st_dev);
- MAKE_LONG_ZVAL_INCREF(stat_ino, stat_sb.st_ino);
- MAKE_LONG_ZVAL_INCREF(stat_mode, stat_sb.st_mode);
- MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_sb.st_nlink);
- MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb.st_uid);
- MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb.st_gid);
-#ifdef HAVE_ST_RDEV
- MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb.st_rdev);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_rdev, -1);
-#endif
- MAKE_LONG_ZVAL_INCREF(stat_size, stat_sb.st_size);
- MAKE_LONG_ZVAL_INCREF(stat_atime, stat_sb.st_atime);
- MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_sb.st_mtime);
- MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_sb.st_ctime);
-#ifdef HAVE_ST_BLKSIZE
- MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_sb.st_blksize);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_blksize,-1);
-#endif
-#ifdef HAVE_ST_BLOCKS
- MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_sb.st_blocks);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_blocks,-1);
-#endif
- /* Store numeric indexes in propper order */
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL);
-
- /* Store string indexes referencing the same zval*/
- zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *)&stat_dev, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *)&stat_ino, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *)&stat_mode, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *)&stat_nlink, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *)&stat_uid, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *)&stat_gid, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *)&stat_rdev, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *)&stat_size, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *)&stat_atime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *)&stat_mtime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *)&stat_ctime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *)&stat_blksize, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *)&stat_blocks, sizeof(zval *), NULL);
-}
-/* }}} */
-
-/* {{{ proto int copy(string source_file, string destination_file)
- Copy a file */
-
-PHP_FUNCTION(copy)
-{
- pval **source, **target;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &source, &target) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(source);
- convert_to_string_ex(target);
-
- if (PG(safe_mode) &&(!php_checkuid((*source)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
-
- if (php_check_open_basedir((*source)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- if (PG(safe_mode) &&(!php_checkuid((*target)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
-
- if (php_check_open_basedir((*target)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- if (php_copy_file(Z_STRVAL_PP(source), Z_STRVAL_PP(target) TSRMLS_CC)==SUCCESS) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
-
-/* }}} */
-
-/* {{{ php_copy_file
- */
-PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC)
-{
- char buffer[8192];
- int fd_s, fd_t, read_bytes;
- int ret = FAILURE;
-
-#ifdef PHP_WIN32
- if ((fd_s=VCWD_OPEN(src, O_RDONLY|_O_BINARY))==-1) {
-#else
- if ((fd_s=VCWD_OPEN(src, O_RDONLY))==-1) {
-#endif
- php_error(E_WARNING, "Unable to open '%s' for reading: %s", src, strerror(errno));
- return FAILURE;
- }
-#ifdef PHP_WIN32
- if ((fd_t=VCWD_OPEN_MODE(dest, _O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY, _S_IREAD|_S_IWRITE))==-1) {
-#else
- if ((fd_t=VCWD_CREAT(dest, 0777))==-1) {
-#endif
- php_error(E_WARNING, "Unable to create '%s': %s", dest, strerror(errno));
- close(fd_s);
- return FAILURE;
- }
-
-#ifdef HAVE_MMAP
- {
- void *srcfile;
- struct stat sbuf;
-
- if (fstat(fd_s, &sbuf)) {
- goto cleanup;
- }
- srcfile = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd_s, 0);
- if (srcfile != (void *) MAP_FAILED) {
- if (write(fd_t, srcfile, sbuf.st_size) == sbuf.st_size)
- ret = SUCCESS;
- munmap(srcfile, sbuf.st_size);
- goto cleanup;
- }
- }
-#endif
-
- 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", dest, strerror(errno));
- goto cleanup;
- }
- }
- ret = SUCCESS;
-
-cleanup:
- close(fd_s);
- close(fd_t);
- return ret;
-}
-/* }}} */
-
-/* {{{ proto string 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;
-
- if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(arg1 TSRMLS_CC,-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;
- if (len < 0) {
- php_error(E_WARNING, "length parameter to fread() may not be negative");
- RETURN_FALSE;
- }
-
- return_value->value.str.val = emalloc(sizeof(char) * (len + 1));
- /* needed because recv doesnt put a null at the end*/
-
- if (!issock) {
-#ifdef HAVE_FLUSHIO
- if (type == le_fopen) {
- fseek((FILE*)what, 0, SEEK_CUR);
- }
-#endif
- return_value->value.str.len = fread(return_value->value.str.val, 1, len, (FILE*)what);
- } else {
- return_value->value.str.len = SOCK_FREAD(return_value->value.str.val, len, socketd);
- }
- return_value->value.str.val[return_value->value.str.len] = 0;
- 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 TSRMLS_CC);
- }
- return_value->type = IS_STRING;
-}
-
-/* }}} */
-
-/* {{{ proto array fgetcsv(int fp, int length [, string delimiter])
- Get line from file pointer and parse for CSV fields */
-
-PHP_FUNCTION(fgetcsv)
-{
- char *temp, *tptr, *bptr, *lineEnd;
- char delimiter = ','; /* allow this to be set as parameter */
-
- /* first section exactly as php_fgetss */
-
- pval **fd, **bytes, **p_delim;
- int len, type;
- char *buf;
- int issock=0;
- int socketd=0;
- void *what;
-
- switch(ARG_COUNT(ht)) {
- case 2:
- if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
-
- case 3:
- if (zend_get_parameters_ex(3, &fd, &bytes, &p_delim) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(p_delim);
- /* Make sure that there is at least one character in string */
- if ((*p_delim)->value.str.len < 1) {
- WRONG_PARAM_COUNT;
- }
- /* use first character from string */
- delimiter = (*p_delim)->value.str.val[0];
- break;
-
- default:
- WRONG_PARAM_COUNT;
- /* NOTREACHED */
- break;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(fd TSRMLS_CC,-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;
- if (len < 0) {
- php_error(E_WARNING, "length parameter to fgetcsv() may not be negative");
- RETURN_FALSE;
- }
-
- buf = emalloc(sizeof(char) * (len + 1));
- /*needed because recv doesnt set null char at end*/
- memset(buf, 0, len + 1);
- if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
- efree(buf);
- RETURN_FALSE;
- }
-
- /* Now into new section that parses buf for comma/quote delimited fields */
-
- /* Strip trailing space from buf, saving end of line in case required for quoted field */
-
- lineEnd = emalloc(sizeof(char) * (len + 1));
- bptr = buf;
- tptr = buf + strlen(buf) -1;
- while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--;
- tptr++;
- strcpy(lineEnd, tptr);
-
- /* add single space - makes it easier to parse trailing null field */
- *tptr++ = ' ';
- *tptr = 0;
-
- /* reserve workspace for building each individual field */
-
- temp = emalloc(sizeof(char) * len); /* unlikely but possible! */
- tptr = temp;
-
- /* Initialize return array */
- if (array_init(return_value) == FAILURE) {
- efree(lineEnd);
- efree(temp);
- efree(buf);
- RETURN_FALSE;
- }
-
- /* Main loop to read CSV fields */
- /* NB this routine will return a single null entry for a blank line */
-
- do {
- /* 1. Strip any leading space */
- while(isspace((int)*bptr) && (*bptr!=delimiter)) bptr++;
- /* 2. Read field, leaving bptr pointing at start of next field */
- if (*bptr == '"') {
- /* 2A. handle quote delimited field */
- bptr++; /* move on to first character in field */
- while (*bptr) {
- if (*bptr == '"') {
- /* handle the double-quote */
- if ( *(bptr+1) == '"') {
- /* embedded double quotes */
- *tptr++ = *bptr; bptr +=2;
- } else {
- /* must be end of string - skip to start of next field or end */
- while ( (*bptr != delimiter) && *bptr ) bptr++;
- if (*bptr == delimiter) bptr++;
- *tptr=0; /* terminate temporary string */
- break; /* .. from handling this field - resumes at 3. */
- }
- } else {
- /* normal character */
- *tptr++ = *bptr++;
-
- if (*bptr == 0) { /* embedded line end? */
- *(tptr-1)=0; /* remove space character added on reading line */
- strcat(temp, lineEnd); /* add the embedded line end to the field */
-
- /* read a new line from input, as at start of routine */
- memset(buf, 0, len+1);
- if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
- efree(lineEnd); efree(temp); efree(buf);
- zval_dtor(return_value);
- RETURN_FALSE;
- }
- bptr = buf;
- tptr = buf + strlen(buf) -1;
- while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--;
- tptr++; strcpy(lineEnd, tptr);
- *tptr++ = ' '; *tptr = 0;
-
- tptr=temp; /* reset temp pointer to end of field as read so far */
- while (*tptr) tptr++;
- }
- }
- }
- } else {
- /* 2B. Handle non-quoted field */
- while ( (*bptr != delimiter) && *bptr ) *tptr++ = *bptr++;
- *tptr=0; /* terminate temporary string */
- if (strlen(temp)) {
- tptr--;
- while (isspace((int)*tptr) && (*tptr!=delimiter)) *tptr-- = 0; /* strip any trailing spaces */
- }
- if (*bptr == delimiter) bptr++;
- }
- /* 3. Now pass our field back to php */
- add_next_index_string(return_value, temp, 1);
- tptr=temp;
- } while (*bptr);
-
- efree(lineEnd);
- efree(temp);
- efree(buf);
-}
-
-/* }}} */
-
-
-#if (!defined(PHP_WIN32) && !defined(__BEOS__)) || defined(ZTS)
-/* {{{ proto string realpath(string path)
- Return the resolved path */
-PHP_FUNCTION(realpath)
-{
- zval **path;
- char resolved_path_buff[MAXPATHLEN];
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(path);
-
- if (VCWD_REALPATH((*path)->value.str.val, resolved_path_buff)) {
- RETURN_STRING(resolved_path_buff, 1);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-#endif
-
-
-#if 0
-
-static fd_set readfd;
-static int max_fd;
-/* {{{ PHP_FUNCTION(fd_set)
- */
-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" );
- return_value->type = IS_NULL;
- return;
- }
- else if(ARG_COUNT(ht) == 1) {
- if(zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
- what = zend_fetch_resource(arg TSRMLS_CC,-1, "select", &type, 3, le_fopen, le_socket, le_popen);
- ZEND_VERIFY_RESOURCE(what);
- if(type == le_socket) {
- fd = *(int *)what;
- } else {
- fd = fileno((FILE *)what);
- }
- max_fd = fd;
- FD_ZERO(&readfd);
- FD_SET(max_fd, &readfd);
- }
- else {
- pval ***args = (pval ***) emalloc(sizeof(pval **) * ARG_COUNT(ht));
- int i;
- if(zend_get_parameters_array_ex(ARG_COUNT(ht), args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
- FD_ZERO(&readfd);
- for(i = 0; i < ARG_COUNT(ht); i++) {
- /* XXX: add stream support --Wez. */
- what = zend_fetch_resource(*args TSRMLS_CC,-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)
- */
-PHP_FUNCTION(select)
-{
- pval **timeout;
- struct timeval tv;
-
- if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &timeout) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(timeout);
-
- tv.tv_sec = (*timeout)->value.lval / 1000000;
- tv.tv_usec = (*timeout)->value.lval % 1000000;
- /* XXX: add stream support --Wez. */
-
- RETURN_LONG(select(max_fd + 1, &readfd, NULL, NULL, ((*timeout)->value.lval <= 0) ? NULL : &tv));
-}
-/* }}} */
-
-/* {{{ PHP_FUNCTION(fd_isset)
- */
-PHP_FUNCTION(fd_isset)
-{
- pval **fdarg;
- void *what;
- int type, fd;
-
- if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fdarg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* XXX: add stream support --Wez. */
-
- what = zend_fetch_resource(fdarg TSRMLS_CC,-1, "select", &type, 3, le_fopen, le_socket, le_popen);
- ZEND_VERIFY_RESOURCE(what);
-
- if(type == le_socket) {
- fd = *(int *)what;
- } else {
- fd = fileno((FILE *)what);
- }
-
- if(FD_ISSET(fd, &readfd)) {
- RETURN_TRUE;
- }
- RETURN_FALSE;
-}
-/* }}} */
-
-#endif
-
-/* {{{ php_fread_all
- Function reads all data from file or socket and puts it into the buffer */
-size_t php_fread_all(char **buf, int socket, FILE *fp, int issock) {
- size_t ret;
- char *ptr;
- size_t len = 0, max_len;
- int step = PHP_FSOCK_CHUNK_SIZE;
- int min_room = PHP_FSOCK_CHUNK_SIZE/4;
-
- ptr = *buf = emalloc(step);
- max_len = step;
- /* XXX: add stream support --Wez. */
-
- while((ret = FP_FREAD(ptr, max_len - len, socket, fp, issock))) {
- len += ret;
- if(len + min_room >= max_len) {
- *buf = erealloc(*buf, max_len + step);
- max_len += step;
- ptr = *buf + len;
- }
- }
-
- if(len) {
- *buf = erealloc(*buf, len);
- } else {
- efree(*buf);
- *buf = NULL;
- }
-
- return len;
-}
-/* }}} */
-
-/* See http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 */
-#define PHP_META_HTML401_CHARS "-_.:"
-
-/* {{{ php_next_meta_token
- Tokenizes an HTML file for get_meta_tags */
-php_meta_tags_token php_next_meta_token(php_meta_tags_data *md)
-{
- int ch = 0, compliment;
- char buff[META_DEF_BUFSIZE + 1];
-
- memset((void *)buff, 0, META_DEF_BUFSIZE + 1);
-
- while (md->ulc || (!FP_FEOF(md->socketd, md->fp, md->issock) && (ch = FP_FGETC(md->socketd, md->fp, md->issock)))) {
-
- if(FP_FEOF(md->socketd, md->fp, md->issock))
- break;
-
- if (md->ulc) {
- ch = md->lc;
- md->ulc = 0;
- }
-
- switch (ch) {
- case '<':
- return TOK_OPENTAG;
- break;
- case '>':
- return TOK_CLOSETAG;
- break;
- case '=':
- return TOK_EQUAL;
- break;
- case '/':
- return TOK_SLASH;
- break;
- case '\'':
- case '"':
- compliment = ch;
- md->token_len = 0;
- while (!FP_FEOF(md->socketd, md->fp, md->issock) &&
- (ch = FP_FGETC(md->socketd, md->fp, md->issock)) &&
- ch != compliment && ch != '<' && ch != '>') {
-
- buff[(md->token_len)++] = ch;
-
- if (md->token_len == META_DEF_BUFSIZE)
- break;
- }
-
- if (ch == '<' || ch == '>') {
- /* Was just an apostrohpe */
- md->ulc = 1;
- md->lc = ch;
- }
-
- /* We don't need to alloc unless we are in a meta tag */
- if (md->in_meta) {
- md->token_data = (char *) emalloc(md->token_len + 1);
- memcpy(md->token_data, buff, md->token_len+1);
- }
-
- return TOK_STRING;
- break;
- case '\n':
- case '\r':
- case '\t':
- break;
- case ' ':
- return TOK_SPACE;
- break;
- default:
- if (isalnum(ch)) {
- md->token_len = 0;
- buff[(md->token_len)++] = ch;
- while (!FP_FEOF(md->socketd, md->fp, md->issock) &&
- (ch = FP_FGETC(md->socketd, md->fp, md->issock)) &&
- (isalnum(ch) || strchr(PHP_META_HTML401_CHARS, ch))) {
-
- buff[(md->token_len)++] = ch;
-
- if (md->token_len == META_DEF_BUFSIZE)
- break;
- }
-
- /* This is ugly, but we have to replace ungetc */
- if (!isalpha(ch) && ch != '-') {
- md->ulc = 1;
- md->lc = ch;
- }
-
- md->token_data = (char *) emalloc(md->token_len + 1);
- memcpy(md->token_data, buff, md->token_len+1);
-
- return TOK_ID;
- } else {
- return TOK_OTHER;
- }
- break;
- }
- }
-
- return TOK_EOF;
-}
-
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: tw=78 sw=4 ts=4 fdm=marker
- * vim<600: tw=78 sw=4 ts=4
- */
diff --git a/ext/standard/file.h b/ext/standard/file.h
deleted file mode 100644
index b12a72838c..0000000000
--- a/ext/standard/file.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
-
-#ifndef FILE_H
-#define FILE_H
-
-PHP_MINIT_FUNCTION(file);
-PHP_MSHUTDOWN_FUNCTION(file);
-
-PHP_FUNCTION(tempnam);
-PHP_NAMED_FUNCTION(php_if_tmpfile);
-PHP_NAMED_FUNCTION(php_if_fopen);
-PHP_FUNCTION(fclose);
-PHP_FUNCTION(popen);
-PHP_FUNCTION(pclose);
-PHP_FUNCTION(feof);
-PHP_FUNCTION(fread);
-PHP_FUNCTION(fgetc);
-PHP_FUNCTION(fgets);
-PHP_FUNCTION(fscanf);
-PHP_FUNCTION(fgetss);
-PHP_FUNCTION(fgetcsv);
-PHP_FUNCTION(fwrite);
-PHP_FUNCTION(fflush);
-PHP_FUNCTION(rewind);
-PHP_FUNCTION(ftell);
-PHP_FUNCTION(fseek);
-PHP_FUNCTION(mkdir);
-PHP_FUNCTION(rmdir);
-PHP_FUNCTION(fpassthru);
-PHP_FUNCTION(readfile);
-PHP_FUNCTION(umask);
-PHP_FUNCTION(rename);
-PHP_FUNCTION(unlink);
-PHP_FUNCTION(copy);
-PHP_FUNCTION(file);
-PHP_FUNCTION(set_socket_blocking); /* deprecated */
-PHP_FUNCTION(socket_set_blocking);
-PHP_FUNCTION(socket_set_timeout);
-PHP_FUNCTION(socket_get_status);
-PHP_FUNCTION(set_file_buffer);
-PHP_FUNCTION(get_meta_tags);
-PHP_FUNCTION(flock);
-PHP_FUNCTION(fd_set);
-PHP_FUNCTION(fd_isset);
-PHP_FUNCTION(select);
-PHP_FUNCTION(realpath);
-PHP_NAMED_FUNCTION(php_if_ftruncate);
-PHP_NAMED_FUNCTION(php_if_fstat);
-
-/* temporary function for testing streams */
-PHP_FUNCTION(fopenstream);
-
-PHPAPI int php_set_sock_blocking(int socketd, int block);
-PHPAPI int php_file_le_fopen(void);
-PHPAPI int php_file_le_stream(void);
-PHPAPI int php_file_le_popen(void);
-PHPAPI int php_file_le_socket(void);
-PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC);
-
-#define META_DEF_BUFSIZE 8192
-
-typedef enum _php_meta_tags_token {
- TOK_EOF = 0,
- TOK_OPENTAG,
- TOK_CLOSETAG,
- TOK_SLASH,
- TOK_EQUAL,
- TOK_SPACE,
- TOK_ID,
- TOK_STRING,
- TOK_OTHER
-} php_meta_tags_token;
-
-typedef struct _php_meta_tags_data {
- FILE *fp;
- int socketd;
- int issock;
- int ulc;
- int lc;
- char *input_buffer;
- char *token_data;
- int token_len;
- int in_meta;
-} php_meta_tags_data;
-
-php_meta_tags_token php_next_meta_token(php_meta_tags_data *);
-
-typedef struct {
- int fgetss_state;
- int pclose_ret;
- HashTable ht_fsock_keys;
- HashTable ht_fsock_socks;
- struct php_sockbuf *phpsockbuf;
- size_t def_chunk_size;
-} php_file_globals;
-
-#ifdef ZTS
-#define FG(v) TSRMG(file_globals_id, php_file_globals *, v)
-extern int file_globals_id;
-#else
-#define FG(v) (file_globals.v)
-extern php_file_globals file_globals;
-#endif
-
-
-#endif /* FILE_H */
-
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
deleted file mode 100644
index 0ee0b910c8..0000000000
--- a/ext/standard/filestat.c
+++ /dev/null
@@ -1,875 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jim Winstead <jimw@php.net> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "safe_mode.h"
-#include "fopen_wrappers.h"
-#include "php_globals.h"
-
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-#include <time.h>
-
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#if HAVE_SYS_VFS_H
-# include <sys/vfs.h>
-#endif
-
-#ifdef OS2
-# define INCL_DOS
-# include <os2.h>
-#endif
-
-#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
-# include <sys/statvfs.h>
-#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS)
-# include <sys/statfs.h>
-#elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_STATFS)
-# include <sys/mount.h>
-#endif
-
-#if HAVE_PWD_H
-# ifdef PHP_WIN32
-# include "win32/pwd.h"
-# else
-# include <pwd.h>
-# endif
-#endif
-
-#if HAVE_GRP_H
-# ifdef PHP_WIN32
-# include "win32/grp.h"
-# else
-# include <grp.h>
-# endif
-#endif
-
-#if HAVE_UTIME
-# ifdef PHP_WIN32
-# include <sys/utime.h>
-# else
-# include <utime.h>
-# endif
-#endif
-
-#include "basic_functions.h"
-#include "php_filestat.h"
-
-#ifndef S_ISDIR
-#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
-#endif
-#ifndef S_ISREG
-#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
-#endif
-#ifndef S_ISLNK
-#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
-#endif
-
-#define S_IXROOT ( S_IXUSR | S_IXGRP | S_IXOTH )
-
-/* Switches for various filestat functions: */
-#define FS_PERMS 0
-#define FS_INODE 1
-#define FS_SIZE 2
-#define FS_OWNER 3
-#define FS_GROUP 4
-#define FS_ATIME 5
-#define FS_MTIME 6
-#define FS_CTIME 7
-#define FS_TYPE 8
-#define FS_IS_W 9
-#define FS_IS_R 10
-#define FS_IS_X 11
-#define FS_IS_FILE 12
-#define FS_IS_DIR 13
-#define FS_IS_LINK 14
-#define FS_EXISTS 15
-#define FS_LSTAT 16
-#define FS_STAT 17
-
-
-PHP_RINIT_FUNCTION(filestat)
-{
- BG(CurrentStatFile)=NULL;
- BG(CurrentStatLength)=0;
- return SUCCESS;
-}
-
-PHP_RSHUTDOWN_FUNCTION(filestat) {
- if (BG(CurrentStatFile)) {
- efree (BG(CurrentStatFile));
- }
- return SUCCESS;
-}
-
-/* {{{ proto double disk_total_space(string path)
- Get total disk space for filesystem that path is on */
-PHP_FUNCTION(disk_total_space)
-{
- pval **path;
-#ifdef WINDOWS
- double bytestotal;
-
- HINSTANCE kernel32;
- FARPROC gdfse;
- typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
- gdfse_func func;
-
- /* These are used by GetDiskFreeSpaceEx, if available. */
- ULARGE_INTEGER FreeBytesAvailableToCaller;
- ULARGE_INTEGER TotalNumberOfBytes;
- ULARGE_INTEGER TotalNumberOfFreeBytes;
-
- /* These are used by GetDiskFreeSpace otherwise. */
- DWORD SectorsPerCluster;
- DWORD BytesPerSector;
- DWORD NumberOfFreeClusters;
- DWORD TotalNumberOfClusters;
-
-#else /* not - WINDOWS */
-#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
- struct statvfs buf;
-#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
- struct statfs buf;
-#endif
- double bytestotal = 0;
-#endif /* WINDOWS */
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(path);
-
- if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
-#ifdef WINDOWS
- /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2,
- so we have to jump through some hoops to see if the function
- exists. */
- kernel32 = LoadLibrary("kernel32.dll");
- if (kernel32) {
- gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
- /* It's available, so we can call it. */
- if (gdfse) {
- func = (gdfse_func)gdfse;
- if (func((*path)->value.str.val,
- &FreeBytesAvailableToCaller,
- &TotalNumberOfBytes,
- &TotalNumberOfFreeBytes) == 0) RETURN_FALSE;
-
- /* i know - this is ugly, but i works (thies@thieso.net) */
- bytestotal = TotalNumberOfBytes.HighPart *
- (double) (((unsigned long)1) << 31) * 2.0 +
- TotalNumberOfBytes.LowPart;
- }
- /* If it's not available, we just use GetDiskFreeSpace */
- else {
- if (GetDiskFreeSpace((*path)->value.str.val,
- &SectorsPerCluster, &BytesPerSector,
- &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE;
- bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector;
- }
- }
- else {
- php_error(E_WARNING, "Unable to load kernel32.dll");
- RETURN_FALSE;
- }
-
-#elif defined(OS2)
- {
- FSALLOCATE fsinfo;
- char drive = (*path)->value.str.val[0] & 95;
-
- if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0)
- bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit;
- }
-#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) {
- bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize));
- } else {
- bytestotal = (((double)buf.f_blocks) * ((double)buf.f_bsize));
- }
-
-#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
- if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE;
- bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks));
-#endif
-#endif /* WINDOWS */
-
- RETURN_DOUBLE(bytestotal);
-}
-/* }}} */
-
-/* {{{ proto double disk_free_space(string path)
- Get free disk space for filesystem that path is on */
-PHP_FUNCTION(disk_free_space)
-{
- pval **path;
-#ifdef WINDOWS
- double bytesfree;
-
- HINSTANCE kernel32;
- FARPROC gdfse;
- typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
- gdfse_func func;
-
- /* These are used by GetDiskFreeSpaceEx, if available. */
- ULARGE_INTEGER FreeBytesAvailableToCaller;
- ULARGE_INTEGER TotalNumberOfBytes;
- ULARGE_INTEGER TotalNumberOfFreeBytes;
-
- /* These are used by GetDiskFreeSpace otherwise. */
- DWORD SectorsPerCluster;
- DWORD BytesPerSector;
- DWORD NumberOfFreeClusters;
- DWORD TotalNumberOfClusters;
-
-#else /* not - WINDOWS */
-#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
- struct statvfs buf;
-#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
- struct statfs buf;
-#endif
- double bytesfree = 0;
-#endif /* WINDOWS */
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &path)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(path);
-
- if (php_check_open_basedir((*path)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
-#ifdef WINDOWS
- /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2,
- so we have to jump through some hoops to see if the function
- exists. */
- kernel32 = LoadLibrary("kernel32.dll");
- if (kernel32) {
- gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
- /* It's available, so we can call it. */
- if (gdfse) {
- func = (gdfse_func)gdfse;
- if (func((*path)->value.str.val,
- &FreeBytesAvailableToCaller,
- &TotalNumberOfBytes,
- &TotalNumberOfFreeBytes) == 0) RETURN_FALSE;
-
- /* i know - this is ugly, but i works (thies@thieso.net) */
- bytesfree = FreeBytesAvailableToCaller.HighPart *
- (double) (((unsigned long)1) << 31) * 2.0 +
- FreeBytesAvailableToCaller.LowPart;
- }
- /* If it's not available, we just use GetDiskFreeSpace */
- else {
- if (GetDiskFreeSpace((*path)->value.str.val,
- &SectorsPerCluster, &BytesPerSector,
- &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE;
- bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector;
- }
- }
- else {
- php_error(E_WARNING, "Unable to load kernel32.dll");
- RETURN_FALSE;
- }
-
-#elif defined(OS2)
- {
- FSALLOCATE fsinfo;
- char drive = (*path)->value.str.val[0] & 95;
-
- if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0)
- bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail;
- }
-#else /* WINDOWS, OS/2 */
-#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
- if (statvfs((*path)->value.str.val, &buf)) RETURN_FALSE;
- if (buf.f_frsize) {
- bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize));
- } else {
- bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize));
- }
-#elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
- if (statfs((*path)->value.str.val, &buf)) RETURN_FALSE;
- bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail));
-#endif
-#endif /* WINDOWS */
-
- RETURN_DOUBLE(bytesfree);
-}
-/* }}} */
-
-/* {{{ proto bool chgrp(string filename, mixed group)
- Change file group */
-PHP_FUNCTION(chgrp)
-{
-#ifndef WINDOWS
- pval **filename, **group;
- gid_t gid;
- struct group *gr=NULL;
- int ret;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &group)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
- if ((*group)->type == IS_STRING) {
- gr = getgrnam((*group)->value.str.val);
- if (!gr) {
- php_error(E_WARNING, "unable to find gid for %s",
- (*group)->value.str.val);
- RETURN_FALSE;
- }
- gid = gr->gr_gid;
- } else {
- convert_to_long_ex(group);
- gid = (*group)->value.lval;
- }
-
- if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
- RETURN_FALSE;
- }
-
- /* Check the basedir */
- if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- ret = VCWD_CHOWN((*filename)->value.str.val, -1, gid);
- if (ret == -1) {
- php_error(E_WARNING, "chgrp failed: %s", strerror(errno));
- RETURN_FALSE;
- }
- RETURN_TRUE;
-#else
- RETURN_FALSE;
-#endif
-}
-/* }}} */
-
-/* {{{ proto bool chown (string filename, mixed user)
- Change file owner */
-PHP_FUNCTION(chown)
-{
-#ifndef WINDOWS
- pval **filename, **user;
- int ret;
- uid_t uid;
- struct passwd *pw = NULL;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &user)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
- if ((*user)->type == IS_STRING) {
- pw = getpwnam((*user)->value.str.val);
- if (!pw) {
- php_error(E_WARNING, "unable to find uid for %s",
- (*user)->value.str.val);
- RETURN_FALSE;
- }
- uid = pw->pw_uid;
- } else {
- convert_to_long_ex(user);
- uid = (*user)->value.lval;
- }
-
- if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
- RETURN_FALSE;
- }
-
- /* Check the basedir */
- if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- ret = VCWD_CHOWN((*filename)->value.str.val, uid, -1);
- if (ret == -1) {
- php_error(E_WARNING, "chown failed: %s", strerror(errno));
- RETURN_FALSE;
- }
-#endif
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool chmod(string filename, int mode)
- Change file mode */
-PHP_FUNCTION(chmod)
-{
- pval **filename, **mode;
- int ret;
- mode_t imode;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &mode)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
- convert_to_long_ex(mode);
-
- if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
- RETURN_FALSE;
- }
-
- /* Check the basedir */
- if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- imode = (mode_t) (*mode)->value.lval;
- /* in safe mode, do not allow to setuid files.
- Setuiding files could allow users to gain privileges
- that safe mode doesn't give them.
- */
- if(PG(safe_mode))
- imode &= 0777;
-
- ret = VCWD_CHMOD((*filename)->value.str.val, imode);
- if (ret == -1) {
- php_error(E_WARNING, "chmod failed: %s", strerror(errno));
- RETURN_FALSE;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto bool touch(string filename [, int time])
- Set modification time of file */
-PHP_FUNCTION(touch)
-{
-#if HAVE_UTIME
- pval **filename, **filetime;
- int ret;
- struct stat sb;
- FILE *file;
- struct utimbuf *newtime = NULL;
- int ac = ZEND_NUM_ARGS();
-
- if (ac == 1 && zend_get_parameters_ex(1, &filename) != FAILURE) {
-#ifndef HAVE_UTIME_NULL
- newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
- if (!newtime) {
- php_error(E_WARNING, "unable to emalloc memory for changing time");
- return;
- }
- newtime->actime = time(NULL);
- newtime->modtime = newtime->actime;
-#endif
- } else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) {
- newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
- if (!newtime) {
- php_error(E_WARNING, "unable to emalloc memory for changing time");
- return;
- }
- convert_to_long_ex(filetime);
- newtime->actime = (*filetime)->value.lval;
- newtime->modtime = (*filetime)->value.lval;
- } else {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- if (PG(safe_mode) &&(!php_checkuid((*filename)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- if (newtime) efree(newtime);
- RETURN_FALSE;
- }
-
- /* Check the basedir */
- if (php_check_open_basedir((*filename)->value.str.val TSRMLS_CC)) {
- if (newtime) {
- efree(newtime);
- }
- RETURN_FALSE;
- }
-
- /* create the file if it doesn't exist already */
- ret = VCWD_STAT((*filename)->value.str.val, &sb);
- if (ret == -1) {
- file = VCWD_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 = VCWD_UTIME((*filename)->value.str.val, newtime);
- if (newtime) efree(newtime);
- if (ret == -1) {
- php_error(E_WARNING, "utime failed: %s", strerror(errno));
- RETURN_FALSE;
- } else {
- RETURN_TRUE;
- }
-#endif
-}
-/* }}} */
-
-/* {{{ proto void clearstatcache(void)
- Clear file stat cache */
-PHP_FUNCTION(clearstatcache)
-{
- if (BG(CurrentStatFile)) {
- efree(BG(CurrentStatFile));
- BG(CurrentStatFile) = NULL;
- }
-}
-/* }}} */
-
-#define IS_LINK_OPERATION() (type == 8 /* filetype */ || type == 14 /* is_link */ || type == 16 /* lstat */)
-
-/* {{{ php_stat
- */
-static void php_stat(const char *filename, php_stat_len filename_length, int type, pval *return_value)
-{
- zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev,
- *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks;
- struct stat *stat_sb;
- int rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */
- char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
- "size", "atime", "mtime", "ctime", "blksize", "blocks"};
- TSRMLS_FETCH();
-
- stat_sb = &BG(sb);
-
- if (!BG(CurrentStatFile) || strcmp(filename, BG(CurrentStatFile))) {
- if (!BG(CurrentStatFile) || filename_length > BG(CurrentStatLength)) {
- if (BG(CurrentStatFile)) {
- efree(BG(CurrentStatFile));
- }
- BG(CurrentStatLength) = filename_length;
- BG(CurrentStatFile) = estrndup(filename, filename_length);
- } else {
- memcpy(BG(CurrentStatFile), filename, filename_length+1);
- }
-#if HAVE_SYMLINK
- BG(lsb).st_mode = 0; /* mark lstat buf invalid */
-#endif
- if (VCWD_STAT(BG(CurrentStatFile), &BG(sb)) == -1) {
- if (!IS_LINK_OPERATION() && (type != FS_EXISTS || errno != ENOENT)) { /* fileexists() test must print no error */
- php_error(E_WARNING, "stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno));
- }
- efree(BG(CurrentStatFile));
- BG(CurrentStatFile) = NULL;
- if (!IS_LINK_OPERATION()) { /* Don't require success for link operation */
- RETURN_FALSE;
- }
- }
- }
-
-#if HAVE_SYMLINK
- if (IS_LINK_OPERATION() && !BG(lsb).st_mode) {
- /* do lstat if the buffer is empty */
- if (VCWD_LSTAT(filename, &BG(lsb)) == -1) {
- php_error(E_WARNING, "lstat failed for %s (errno=%d - %s)", filename, errno, strerror(errno));
- RETURN_FALSE;
- }
- }
-#endif
-
-
- if (type >= FS_IS_W && type <= FS_IS_X) {
- if(BG(sb).st_uid==getuid()) {
- rmask=S_IRUSR;
- wmask=S_IWUSR;
- xmask=S_IXUSR;
- } else if(BG(sb).st_gid==getgid()) {
- rmask=S_IRGRP;
- wmask=S_IWGRP;
- xmask=S_IXGRP;
- } else {
- int groups, n, i;
- gid_t *gids;
-
- groups = getgroups(0, NULL);
- if(groups) {
- gids=(gid_t *)emalloc(groups*sizeof(gid_t));
- n=getgroups(groups, gids);
- for(i=0;i<n;i++){
- if(BG(sb).st_gid==gids[i]) {
- rmask=S_IRGRP;
- wmask=S_IWGRP;
- xmask=S_IXGRP;
- break;
- }
- }
- efree(gids);
- }
- }
- }
-
- switch (type) {
- case FS_PERMS:
- RETURN_LONG((long)BG(sb).st_mode);
- case FS_INODE:
- RETURN_LONG((long)BG(sb).st_ino);
- case FS_SIZE:
- RETURN_LONG((long)BG(sb).st_size);
- case FS_OWNER:
- RETURN_LONG((long)BG(sb).st_uid);
- case FS_GROUP:
- RETURN_LONG((long)BG(sb).st_gid);
- case FS_ATIME:
- RETURN_LONG((long)BG(sb).st_atime);
- case FS_MTIME:
- RETURN_LONG((long)BG(sb).st_mtime);
- case FS_CTIME:
- RETURN_LONG((long)BG(sb).st_ctime);
- case FS_TYPE:
-#if HAVE_SYMLINK
- if (S_ISLNK(BG(lsb).st_mode)) {
- RETURN_STRING("link", 1);
- }
-#endif
- switch(BG(sb).st_mode&S_IFMT) {
- case S_IFIFO: RETURN_STRING("fifo", 1);
- case S_IFCHR: RETURN_STRING("char", 1);
- case S_IFDIR: RETURN_STRING("dir", 1);
- case S_IFBLK: RETURN_STRING("block", 1);
- case S_IFREG: RETURN_STRING("file", 1);
-#if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__)
- case S_IFSOCK: RETURN_STRING("socket", 1);
-#endif
- }
- php_error(E_WARNING, "Unknown file type (%d)", BG(sb).st_mode&S_IFMT);
- RETURN_STRING("unknown", 1);
- case FS_IS_W:
- if (getuid()==0) {
- RETURN_LONG(1); /* root */
- }
- RETURN_LONG((BG(sb).st_mode & wmask) != 0);
- case FS_IS_R:
- if (getuid()==0) {
- RETURN_LONG(1); /* root */
- }
- RETURN_LONG((BG(sb).st_mode&rmask)!=0);
- case FS_IS_X:
- if (getuid()==0) {
- xmask = S_IXROOT; /* root */
- }
- RETURN_LONG((BG(sb).st_mode&xmask)!=0 && !S_ISDIR(BG(sb).st_mode));
- case FS_IS_FILE:
- RETURN_LONG(S_ISREG(BG(sb).st_mode));
- case FS_IS_DIR:
- RETURN_LONG(S_ISDIR(BG(sb).st_mode));
- case FS_IS_LINK:
-#if HAVE_SYMLINK
- RETURN_LONG(S_ISLNK(BG(lsb).st_mode));
-#else
- RETURN_FALSE;
-#endif
- case FS_EXISTS:
- RETURN_TRUE; /* the false case was done earlier */
- case FS_LSTAT:
-#if HAVE_SYMLINK
- stat_sb = &BG(lsb);
-#endif
- /* FALLTHROUGH */
- case FS_STAT:
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- MAKE_LONG_ZVAL_INCREF(stat_dev, stat_sb->st_dev);
- MAKE_LONG_ZVAL_INCREF(stat_ino, stat_sb->st_ino);
- MAKE_LONG_ZVAL_INCREF(stat_mode, stat_sb->st_mode);
- MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_sb->st_nlink);
- MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb->st_uid);
- MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb->st_gid);
-#ifdef HAVE_ST_RDEV
- MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_rdev, -1);
-#endif
- MAKE_LONG_ZVAL_INCREF(stat_size, stat_sb->st_size);
- MAKE_LONG_ZVAL_INCREF(stat_atime, stat_sb->st_atime);
- MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_sb->st_mtime);
- MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_sb->st_ctime);
-#ifdef HAVE_ST_BLKSIZE
- MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_sb->st_blksize);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_blksize,-1);
-#endif
-#ifdef HAVE_ST_BLOCKS
- MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_sb->st_blocks);
-#else
- MAKE_LONG_ZVAL_INCREF(stat_blocks,-1);
-#endif
- /* Store numeric indexes in propper order */
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL);
- zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL);
-
- /* Store string indexes referencing the same zval*/
- zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *) &stat_dev, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *) &stat_ino, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *) &stat_mode, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *) &stat_nlink, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *) &stat_uid, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *) &stat_gid, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *) &stat_rdev, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *) &stat_size, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *) &stat_atime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *) &stat_mtime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *) &stat_ctime, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *) &stat_blksize, sizeof(zval *), NULL);
- zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *) &stat_blocks, sizeof(zval *), NULL);
-
- return;
- }
- php_error(E_WARNING, "didn't understand stat call");
- RETURN_FALSE;
-}
-/* }}} */
-
-/* another quickie macro to make defining similar functions easier */
-#define FileFunction(name, funcnum) \
-void name(INTERNAL_FUNCTION_PARAMETERS) { \
- pval **filename; \
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { \
- WRONG_PARAM_COUNT; \
- } \
- convert_to_string_ex(filename); \
- php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value); \
-}
-
-/* {{{ proto int fileperms(string filename)
- Get file permissions */
-FileFunction(PHP_FN(fileperms), FS_PERMS)
-/* }}} */
-
-/* {{{ proto int fileinode(string filename)
- Get file inode */
-FileFunction(PHP_FN(fileinode), FS_INODE)
-/* }}} */
-
-/* {{{ proto int filesize(string filename)
- Get file size */
-FileFunction(PHP_FN(filesize), FS_SIZE)
-/* }}} */
-
-/* {{{ proto int fileowner(string filename)
- Get file owner */
-FileFunction(PHP_FN(fileowner), FS_OWNER)
-/* }}} */
-
-/* {{{ proto int filegroup(string filename)
- Get file group */
-FileFunction(PHP_FN(filegroup), FS_GROUP)
-/* }}} */
-
-/* {{{ proto int fileatime(string filename)
- Get last access time of file */
-FileFunction(PHP_FN(fileatime), FS_ATIME)
-/* }}} */
-
-/* {{{ proto int filemtime(string filename)
- Get last modification time of file */
-FileFunction(PHP_FN(filemtime), FS_MTIME)
-/* }}} */
-
-/* {{{ proto int filectime(string filename)
- Get inode modification time of file */
-FileFunction(PHP_FN(filectime), FS_CTIME)
-/* }}} */
-
-/* {{{ proto string filetype(string filename)
- Get file type */
-FileFunction(PHP_FN(filetype), FS_TYPE)
-/* }}} */
-
-/* {{{ proto int is_writable(string filename)
- Returns true if file can be written */
-FileFunction(PHP_FN(is_writable), FS_IS_W)
-/* }}} */
-
-/* {{{ proto int is_readable(string filename)
- Returns true if file can be read */
-FileFunction(PHP_FN(is_readable), FS_IS_R)
-/* }}} */
-
-/* {{{ proto int is_executable(string filename)
- Returns true if file is executable */
-FileFunction(PHP_FN(is_executable), FS_IS_X)
-/* }}} */
-
-/* {{{ proto int is_file(string filename)
- Returns true if file is a regular file */
-FileFunction(PHP_FN(is_file), FS_IS_FILE)
-/* }}} */
-
-/* {{{ proto int is_dir(string filename)
- Returns true if file is directory */
-FileFunction(PHP_FN(is_dir), FS_IS_DIR)
-/* }}} */
-
-/* {{{ proto int is_link(string filename)
- Returns true if file is symbolic link */
-FileFunction(PHP_FN(is_link), FS_IS_LINK)
-/* }}} */
-
-/* {{{ proto bool file_exists(string filename)
- Returns true if filename exists */
-FileFunction(PHP_FN(file_exists), FS_EXISTS)
-/* }}} */
-
-/* {{{ proto array lstat(string filename)
- Give information about a file or symbolic link */
-FileFunction(php_if_lstat, FS_LSTAT)
-/* }}} */
-
-/* {{{ proto array stat(string filename)
- Give information about a file */
-FileFunction(php_if_stat, FS_SIZE)
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/flock_compat.c b/ext/standard/flock_compat.c
deleted file mode 100644
index 38b387f8b2..0000000000
--- a/ext/standard/flock_compat.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include <php.h>
-#include <errno.h>
-#include "ext/standard/flock_compat.h"
-
-#if HAVE_STRUCT_FLOCK
-#include <unistd.h>
-#include <fcntl.h>
-#endif
-
-#ifdef PHP_WIN32
-#include <windows.h>
-#include <io.h>
-#endif
-
-#ifndef HAVE_FLOCK
-int flock(int fd, int operation)
-#if HAVE_STRUCT_FLOCK
-{
- struct flock flck;
- int ret;
-
- flck.l_start = flck.l_len = 0;
- flck.l_whence = SEEK_SET;
-
- if (operation & LOCK_SH)
- flck.l_type = F_RDLCK;
- else if (operation & LOCK_EX)
- flck.l_type = F_WRLCK;
- else if (operation & LOCK_UN)
- flck.l_type = F_UNLCK;
- else {
- errno = EINVAL;
- return -1;
- }
-
- ret = fcntl(fd, operation & LOCK_NB ? F_SETLK : F_SETLKW, &flck);
-
- if (operation & LOCK_NB && ret == -1 &&
- (errno == EACCES || errno == EAGAIN))
- errno = EWOULDBLOCK;
-
- if (ret != -1) ret = 0;
-
- return ret;
-}
-#elif defined(PHP_WIN32)
-/*
- * Program: Unix compatibility routines
- *
- * Author: Mark Crispin
- * Networks and Distributed Computing
- * Computing & Communications
- * University of Washington
- * Administration Building, AG-44
- * Seattle, WA 98195
- * Internet: MRC@CAC.Washington.EDU
- *
- * Date: 14 September 1996
- * Last Edited: 14 August 1997
- *
- * Copyright 1997 by the University of Washington
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appears in all copies and that both the
- * above copyright notice and this permission notice appear in supporting
- * documentation, and that the name of the University of Washington not be
- * used in advertising or publicity pertaining to distribution of the software
- * without specific, written prior permission. This software is made available
- * "as is", and
- * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
- * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
- * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
- * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- */
-/* DEDICATION
-
- * This file is dedicated to my dog, Unix, also known as Yun-chan and
- * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix
- * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
- * a two-month bout with cirrhosis of the liver.
- *
- * He was a dear friend, and I miss him terribly.
- *
- * Lift a leg, Yunie. Luv ya forever!!!!
- */
-{
- HANDLE hdl = (HANDLE) _get_osfhandle(fd);
- DWORD low = 1, high = 0;
- OVERLAPPED offset =
- {0, 0, 0, 0, NULL};
- if (hdl < 0)
- return -1; /* error in file descriptor */
- /* bug for bug compatible with Unix */
- UnlockFileEx(hdl, 0, low, high, &offset);
- switch (operation & ~LOCK_NB) { /* translate to LockFileEx() op */
- case LOCK_EX: /* exclusive */
- if (LockFileEx(hdl, LOCKFILE_EXCLUSIVE_LOCK +
- ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
- 0, low, high, &offset))
- return 0;
- break;
- case LOCK_SH: /* shared */
- if (LockFileEx(hdl, ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0),
- 0, low, high, &offset))
- return 0;
- break;
- case LOCK_UN: /* unlock */
- return 0; /* always succeeds */
- default: /* default */
- break;
- }
- /* Under Win32 MT library, errno is not a variable but a function call,
- * which cannot be assigned to.
- */
-#if !defined(PHP_WIN32)
- errno = EINVAL; /* bad call */
-#endif
- return -1;
-}
-#else
-#warning no proper flock support for your site
-{
- errno = 0;
- return 0;
-}
-#endif
-#endif /* !defined(HAVE_FLOCK) */
-
-#if !(HAVE_INET_ATON)
-/* {{{ inet_aton
- * Check whether "cp" is a valid ascii representation
- * of an Internet address and convert to a binary address.
- * Returns 1 if the address is valid, 0 if not.
- * This replaces inet_addr, the return value from which
- * cannot distinguish between failure and a local broadcast address.
- */
-int inet_aton(const char *cp, struct in_addr *ap)
-{
- int dots = 0;
- register unsigned long acc = 0, addr = 0;
-
- do {
- register char cc = *cp;
-
- switch (cc) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- acc = acc * 10 + (cc - '0');
- break;
-
- case '.':
- if (++dots > 3) {
- return 0;
- }
- /* Fall through */
-
- case '\0':
- if (acc > 255) {
- return 0;
- }
- addr = addr << 8 | acc;
- acc = 0;
- break;
-
- default:
- return 0;
- }
- } while (*cp++) ;
-
- /* Normalize the address */
- if (dots < 3) {
- addr <<= 8 * (3 - dots) ;
- }
-
- /* Store it if requested */
- if (ap) {
- ap->s_addr = htonl(addr);
- }
-
- return 1;
-}
-/* }}} */
-#endif /* !HAVE_INET_ATON */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/flock_compat.h b/ext/standard/flock_compat.h
deleted file mode 100644
index 8783132a2d..0000000000
--- a/ext/standard/flock_compat.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef FLOCK_COMPAT_H
-#define FLOCK_COMPAT_H
-
-#ifndef HAVE_FLOCK
-# define LOCK_SH 1
-# define LOCK_EX 2
-# define LOCK_NB 4
-# define LOCK_UN 8
-int flock(int fd, int operation);
-#endif
-
-#ifdef PHP_WIN32
-#define EWOULDBLOCK WSAEWOULDBLOCK
-# define fsync _commit
-# define ftruncate(a, b) chsize(a, b)
-#endif /* defined(PHP_WIN32) */
-
-#if !HAVE_INET_ATON
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-extern int inet_aton(const char *, struct in_addr *);
-#endif
-
-#endif /* FLOCK_COMPAT_H */
diff --git a/ext/standard/formatted_print.c b/ext/standard/formatted_print.c
deleted file mode 100644
index e34dda1ad8..0000000000
--- a/ext/standard/formatted_print.c
+++ /dev/null
@@ -1,712 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Stig Sæther Bakken <ssb@guardian.no> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <math.h> /* modf() */
-#include "php.h"
-#include "ext/standard/head.h"
-#include "php_string.h"
-#include "zend_execute.h"
-#include <stdio.h>
-
-#define ALIGN_LEFT 0
-#define ALIGN_RIGHT 1
-#define ADJ_WIDTH 1
-#define ADJ_PRECISION 2
-#define NUM_BUF_SIZE 500
-#define NDIG 80
-#define FLOAT_DIGITS 6
-#define FLOAT_PRECISION 6
-#define MAX_FLOAT_DIGITS 38
-#define MAX_FLOAT_PRECISION 40
-
-#if 0
-/* trick to control varargs functions through cpp */
-# define PRINTF_DEBUG(arg) php_printf arg
-#else
-# define PRINTF_DEBUG(arg)
-#endif
-
-static char hexchars[] = "0123456789abcdef";
-static char HEXCHARS[] = "0123456789ABCDEF";
-
-
-/*
- * cvt.c - IEEE floating point formatting routines for FreeBSD
- * from GNU libc-4.6.27
- */
-
-/*
- * php_convert_to_decimal converts to decimal
- * the number of digits is specified by ndigit
- * decpt is set to the position of the decimal point
- * sign is set to 0 for positive, 1 for negative
- */
-static char *php_convert_to_decimal(double arg, int ndigits, int *decpt, int *sign, int eflag)
-{
- register int r2;
- double fi, fj;
- register char *p, *p1;
- /*THREADX*/
-#ifndef THREAD_SAFE
- static char cvt_buf[NDIG];
-#endif
-
- if (ndigits >= NDIG - 1)
- ndigits = NDIG - 2;
- r2 = 0;
- *sign = 0;
- p = &cvt_buf[0];
- if (arg < 0) {
- *sign = 1;
- arg = -arg;
- }
- arg = modf(arg, &fi);
- p1 = &cvt_buf[NDIG];
- /*
- * Do integer part
- */
- if (fi != 0) {
- p1 = &cvt_buf[NDIG];
- while (fi != 0) {
- fj = modf(fi / 10, &fi);
- *--p1 = (int) ((fj + .03) * 10) + '0';
- r2++;
- }
- while (p1 < &cvt_buf[NDIG])
- *p++ = *p1++;
- } else if (arg > 0) {
- while ((fj = arg * 10.0) < 0.9999999) {
- arg = fj;
- r2--;
- }
- }
- p1 = &cvt_buf[ndigits];
- if (eflag == 0)
- p1 += r2;
- *decpt = r2;
- if (p1 < &cvt_buf[0]) {
- cvt_buf[0] = '\0';
- return (cvt_buf);
- }
- while (p <= p1 && p < &cvt_buf[NDIG]) {
- arg *= 10;
- arg = modf(arg, &fj);
- *p++ = (int) fj + '0';
- }
- if (p1 >= &cvt_buf[NDIG]) {
- cvt_buf[NDIG - 1] = '\0';
- return (cvt_buf);
- }
- p = p1;
- *p1 += 5;
- while (*p1 > '9') {
- *p1 = '0';
- if (p1 > cvt_buf)
- ++ * --p1;
- else {
- *p1 = '1';
- (*decpt)++;
- if (eflag == 0) {
- if (p > cvt_buf)
- *p = '0';
- p++;
- }
- }
- }
- *p = '\0';
- return (cvt_buf);
-}
-
-
-inline static void
-php_sprintf_appendchar(char **buffer, int *pos, int *size, char add TSRMLS_DC)
-{
- if ((*pos + 1) >= *size) {
- *size <<= 1;
- PRINTF_DEBUG(("%s: ereallocing buffer to %d bytes\n", get_active_function_name(TSRMLS_C), *size));
- *buffer = erealloc(*buffer, *size);
- }
- PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
- (*buffer)[(*pos)++] = add;
-}
-
-
-inline static void
-php_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
- int min_width, int max_width, char padding,
- int alignment, int len, int sign, int expprec)
-{
- register int npad;
-
- npad = min_width - MIN(len, (expprec ? 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) && (! expprec)) {
- max_width = MAX(min_width, len);
- }
- if ((*pos + max_width) >= *size) {
- while ((*pos + max_width) >= *size) {
- *size <<= 1;
- }
- PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size));
- *buffer = erealloc(*buffer, *size);
- }
- if (alignment == ALIGN_RIGHT) {
- if (sign && padding=='0') {
- (*buffer)[(*pos)++] = '-';
- add++;
- len--;
- }
- while (npad-- > 0) {
- (*buffer)[(*pos)++] = padding;
- }
- }
- PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add));
- memcpy(&(*buffer)[*pos], add, MIN(max_width, len)+1);
- *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, long number,
- int width, char padding, int alignment)
-{
- char numbuf[NUM_BUF_SIZE];
- register unsigned long magn, nmagn;
- register unsigned int i = NUM_BUF_SIZE - 1, neg = 0;
-
- PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n",
- *buffer, pos, size, number, width, padding, alignment));
- if (number < 0) {
- neg = 1;
- magn = ((unsigned long) -(number + 1)) + 1;
- } else {
- magn = (unsigned long) number;
- }
-
- /* Can't right-pad 0's on integers */
- if(alignment==0 && padding=='0') padding=' ';
-
- numbuf[i] = '\0';
-
- do {
- nmagn = magn / 10;
-
- numbuf[--i] = (unsigned char)(magn - (nmagn * 10)) + '0';
- magn = nmagn;
- }
- while (magn > 0 && i > 0);
- if (neg) {
- numbuf[--i] = '-';
- }
- PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n",
- number, &numbuf[i], i));
- php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
- padding, alignment, (NUM_BUF_SIZE - 1) - i,
- neg, 0);
-}
-
-inline static void
-php_sprintf_appenduint(char **buffer, int *pos, int *size,
- unsigned long number,
- int width, char padding, int alignment)
-{
- char numbuf[NUM_BUF_SIZE];
- register unsigned long magn, nmagn;
- register unsigned int i = NUM_BUF_SIZE - 1;
-
- PRINTF_DEBUG(("sprintf: appenduint(%x, %x, %x, %d, %d, '%c', %d)\n",
- *buffer, pos, size, number, width, padding, alignment));
- magn = (unsigned int) number;
-
- /* Can't right-pad 0's on integers */
- if (alignment == 0 && padding == '0') padding = ' ';
-
- numbuf[i] = '\0';
-
- do {
- nmagn = magn / 10;
-
- numbuf[--i] = (unsigned char)(magn - (nmagn * 10)) + '0';
- magn = nmagn;
- }
- while (magn > 0 && i > 0);
- PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n", number, &numbuf[i], i));
- php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
- padding, alignment, (NUM_BUF_SIZE - 1) - i, 0, 0);
-}
-
-inline static void
-php_sprintf_appenddouble(char **buffer, int *pos,
- int *size, double number,
- int width, char padding,
- int alignment, int precision,
- int adjust, char fmt)
-{
- 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;
- }
-
- if (zend_isnan(number)) {
- sign = (number<0);
- php_sprintf_appendstring(buffer, pos, size, "NaN", 3, 0, padding,
- alignment, precision, sign, 0);
- return;
- }
-
- if (zend_isinf(number)) {
- sign = (number<0);
- php_sprintf_appendstring(buffer, pos, size, "INF", 3, 0, padding,
- alignment, precision, sign, 0);
- return;
- }
-
- cvt = php_convert_to_decimal(number, precision, &decpt, &sign, (fmt == 'e'));
-
- if (sign) {
- numbuf[i++] = '-';
- }
-
- 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, 0);
-}
-
-
-inline static void
-php_sprintf_append2n(char **buffer, int *pos, int *size, long number,
- int width, char padding, int alignment, int n,
- char *chartable, int expprec)
-{
- char numbuf[NUM_BUF_SIZE];
- register unsigned long num;
- register unsigned int i = NUM_BUF_SIZE - 1;
- register int andbits = (1 << n) - 1;
-
- PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n",
- *buffer, pos, size, number, width, padding, alignment, n,
- chartable));
- PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits));
-
- num = (unsigned long) number;
- numbuf[i] = '\0';
-
- do {
- numbuf[--i] = chartable[(num & andbits)];
- num >>= n;
- }
- while (num > 0);
-
- php_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
- padding, alignment, (NUM_BUF_SIZE - 1) - i,
- 0, expprec);
-}
-
-
-inline static long
-php_sprintf_getnumber(char *buffer, int *pos)
-{
- char *endptr;
- register long num = strtol(&buffer[*pos], &endptr, 10);
- register int i = 0;
-
- if (endptr != NULL) {
- i = (endptr - &buffer[*pos]);
- }
- PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i));
- *pos += i;
- return num;
-}
-
-/* {{{ php_formatted_print
- * New sprintf implementation for PHP.
- *
- * Modifiers:
- *
- * " " pad integers with spaces
- * "-" left adjusted field
- * n field size
- * "."n precision (floats only)
- *
- * Type specifiers:
- *
- * "%" literal "%", modifiers are ignored.
- * "b" integer argument is printed as binary
- * "c" integer argument is printed as a single character
- * "d" argument is an integer
- * "f" the argument is a float
- * "o" integer argument is printed as octal
- * "s" argument is a string
- * "x" integer argument is printed as lowercase hexadecimal
- * "X" integer argument is printed as uppercase hexadecimal
- *
- */
-static char *
-php_formatted_print(int ht, int *len, int use_array TSRMLS_DC)
-{
- zval ***args, **z_format, **array;
- int argc, size = 240, inpos = 0, outpos = 0, temppos;
- int alignment, width, precision, currarg, adjusting, argnum;
- char *format, *result, padding;
-
- argc = ZEND_NUM_ARGS();
-
- if (use_array) {
- int i = 1;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(argc, &z_format, &array) == FAILURE) {
- WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
- }
- SEPARATE_ZVAL(array);
- convert_to_array_ex(array);
- argc = 1 + zend_hash_num_elements(Z_ARRVAL_PP(array));
- args = (zval ***)emalloc(argc * sizeof(zval *));
- args[0] = z_format;
- for (zend_hash_internal_pointer_reset(Z_ARRVAL_PP(array));
- zend_hash_get_current_data(Z_ARRVAL_PP(array), (void **)&args[i++]) == SUCCESS;
- zend_hash_move_forward(Z_ARRVAL_PP(array)));
- } else {
- if (argc < 1) {
- WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
- }
-
- args = (zval ***)emalloc(argc * sizeof(zval *));
-
- if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
- }
- }
- convert_to_string_ex(args[0]);
- format = (*args[0])->value.str.val;
- result = emalloc(size);
-
- currarg = 1;
-
- while (inpos<(*args[0])->value.str.len) {
- int expprec = 0;
-
- PRINTF_DEBUG(("sprintf: format[%d]='%c'\n", inpos, format[inpos]));
- PRINTF_DEBUG(("sprintf: outpos=%d\n", outpos));
- if (format[inpos] != '%') {
- php_sprintf_appendchar(&result, &outpos, &size, format[inpos++] TSRMLS_CC);
- } else if (format[inpos + 1] == '%') {
- php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC);
- inpos += 2;
- } else {
- if (currarg >= argc && format[inpos + 1] != '%') {
- efree(result);
- efree(args);
- php_error(E_WARNING, "%s(): too few arguments", get_active_function_name(TSRMLS_C));
- 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 argnum */
- temppos = inpos;
- while (isdigit((int)format[temppos])) temppos++;
- if (format[temppos] == '$') {
- argnum = php_sprintf_getnumber(format, &inpos);
- inpos++; /* skip the '$' */
- } else {
- argnum = currarg++;
- }
- if (argnum >= argc) {
- efree(result);
- efree(args);
- php_error(E_WARNING, "%s(): too few arguments", get_active_function_name(TSRMLS_C));
- return NULL;
- }
-
- /* after argnum comes modifiers */
- PRINTF_DEBUG(("sprintf: looking for modifiers\n"
- "sprintf: now looking at '%c', inpos=%d\n",
- format[inpos], inpos));
- for (;; inpos++) {
- if (format[inpos] == ' ' || format[inpos] == '0') {
- padding = format[inpos];
- } else if (format[inpos] == '-') {
- alignment = ALIGN_LEFT;
- /* space padding, the default */
- } else if (format[inpos] == '\'') {
- padding = format[++inpos];
- } else {
- PRINTF_DEBUG(("sprintf: end of modifiers\n"));
- break;
- }
- }
- PRINTF_DEBUG(("sprintf: padding='%c'\n", padding));
- PRINTF_DEBUG(("sprintf: alignment=%s\n",
- (alignment == ALIGN_LEFT) ? "left" : "right"));
-
-
- /* after modifiers comes width */
- if (isdigit((int)format[inpos])) {
- PRINTF_DEBUG(("sprintf: getting width\n"));
- width = php_sprintf_getnumber(format, &inpos);
- adjusting |= ADJ_WIDTH;
- } else {
- width = 0;
- }
- PRINTF_DEBUG(("sprintf: width=%d\n", width));
-
- /* after width and argnum comes precision */
- if (format[inpos] == '.') {
- inpos++;
- PRINTF_DEBUG(("sprintf: getting precision\n"));
- if (isdigit((int)format[inpos])) {
- precision = php_sprintf_getnumber(format, &inpos);
- adjusting |= ADJ_PRECISION;
- expprec = 1;
- } else {
- precision = 0;
- }
- } else {
- precision = 0;
- }
- PRINTF_DEBUG(("sprintf: precision=%d\n", precision));
- } else {
- width = precision = 0;
- argnum = currarg++;
- }
-
- if (format[inpos] == 'l') {
- inpos++;
- }
- PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos]));
- /* now we expect to find a type specifier */
- switch (format[inpos]) {
- case 's':
- convert_to_string_ex(args[argnum]);
- php_sprintf_appendstring(&result, &outpos, &size,
- (*args[argnum])->value.str.val,
- width, precision, padding,
- alignment,
- (*args[argnum])->value.str.len,
- 0, expprec);
- break;
-
- case 'd':
- convert_to_long_ex(args[argnum]);
- php_sprintf_appendint(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment);
- break;
-
- case 'u':
- convert_to_long_ex(args[argnum]);
- php_sprintf_appenduint(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment);
- break;
-
- case 'e':
- case 'f':
- /* XXX not done */
- convert_to_double_ex(args[argnum]);
- php_sprintf_appenddouble(&result, &outpos, &size,
- (*args[argnum])->value.dval,
- width, padding, alignment,
- precision, adjusting,
- format[inpos]);
- break;
-
- case 'c':
- convert_to_long_ex(args[argnum]);
- php_sprintf_appendchar(&result, &outpos, &size,
- (char) (*args[argnum])->value.lval TSRMLS_CC);
- break;
-
- case 'o':
- convert_to_long_ex(args[argnum]);
- php_sprintf_append2n(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment, 3,
- hexchars, expprec);
- break;
-
- case 'x':
- convert_to_long_ex(args[argnum]);
- php_sprintf_append2n(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment, 4,
- hexchars, expprec);
- break;
-
- case 'X':
- convert_to_long_ex(args[argnum]);
- php_sprintf_append2n(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment, 4,
- HEXCHARS, expprec);
- break;
-
- case 'b':
- convert_to_long_ex(args[argnum]);
- php_sprintf_append2n(&result, &outpos, &size,
- (*args[argnum])->value.lval,
- width, padding, alignment, 1,
- hexchars, expprec);
- break;
-
- case '%':
- php_sprintf_appendchar(&result, &outpos, &size, '%' TSRMLS_CC);
-
- break;
- default:
- break;
- }
- inpos++;
- }
- }
-
- efree(args);
-
- /* possibly, we have to make sure we have room for the terminating null? */
- result[outpos]=0;
- *len = outpos;
- return result;
-}
-/* }}} */
-
-/* {{{ proto string sprintf(string format [, mixed arg1 [, mixed ...]])
- Return a formatted string */
-PHP_FUNCTION(user_sprintf)
-{
- char *result;
- int len;
-
- if ((result=php_formatted_print(ht, &len, 0 TSRMLS_CC))==NULL) {
- RETURN_FALSE;
- }
- RETVAL_STRINGL(result, len, 1);
- efree(result);
-}
-/* }}} */
-
-/* {{{ proto string vsprintf(string format, array args)
- Return a formatted string */
-PHP_FUNCTION(vsprintf)
-{
- char *result;
- int len;
-
- if ((result=php_formatted_print(ht, &len, 1 TSRMLS_CC))==NULL) {
- RETURN_FALSE;
- }
- RETVAL_STRINGL(result, len, 1);
- efree(result);
-}
-/* }}} */
-
-/* {{{ proto int printf(string format [, mixed arg1 [, mixed ...]])
- Output a formatted string */
-PHP_FUNCTION(user_printf)
-{
- char *result;
- int len;
-
- if ((result=php_formatted_print(ht, &len, 0 TSRMLS_CC))==NULL) {
- RETURN_FALSE;
- }
- PHPWRITE(result, len);
- efree(result);
-}
-/* }}} */
-
-/* {{{ proto int printf(string format, array args)
- Output a formatted string */
-PHP_FUNCTION(vprintf)
-{
- char *result;
- int len;
-
- if ((result=php_formatted_print(ht, &len, 1 TSRMLS_CC))==NULL) {
- RETURN_FALSE;
- }
- PHPWRITE(result, len);
- efree(result);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
deleted file mode 100644
index abb46a2774..0000000000
--- a/ext/standard/fsock.c
+++ /dev/null
@@ -1,774 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Paul Panotzki - Bunyip Information Systems |
- | Jim Winstead <jimw@php.net> |
- | Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.121 1999-06-18 [ssb] */
-/* Synced with php 3.0 revision 1.133 1999-07-21 [sas] */
-
-#include "php.h"
-#include "php_globals.h"
-#include <stdlib.h>
-#include <stddef.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef PHP_WIN32
-#include <winsock.h>
-#else
-#include <netinet/in.h>
-#include <netdb.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#endif
-#ifdef PHP_WIN32
-#undef AF_UNIX
-#endif
-#if defined(AF_UNIX)
-#include <sys/un.h>
-#endif
-#ifdef HAVE_SYS_SELECT_H
-#include <sys/select.h>
-#endif
-
-#include <string.h>
-#include <errno.h>
-
-#include "base64.h"
-#include "file.h"
-#include "url.h"
-#include "fsock.h"
-
-#include "php_network.h"
-
-#ifdef ZTS
-static int fsock_globals_id;
-#else
-extern int le_fp;
-#endif
-
-#define CLOSE_SOCK(free_sock) \
- if(socketd >= 0) { \
- close(socketd); \
- } \
- if (free_sock) { \
- efree(sock); \
- } \
- if (key) { \
- efree(key); \
- }
-
-#define SEARCHCR() do { \
- if (TOREAD(sock)) { \
- for (p = READPTR(sock), pe = p + MIN(TOREAD(sock), maxlen); \
- *p != '\n'; ) \
- if (++p >= pe) { \
- p = NULL; \
- break; \
- } \
- } else \
- p = NULL; \
-} while (0)
-
-#ifdef PHP_WIN32
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#else
-#include "build-defs.h"
-#endif
-
-/* {{{ php_lookup_hostname */
-
-/*
- * Converts a host name to an IP address.
- */
-PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in)
-{
- struct hostent *host_info;
-
- if (!inet_aton(addr, in)) {
- /* XXX NOT THREAD SAFE */
- host_info = gethostbyname(addr);
- if (host_info == 0) {
- /* Error: unknown host */
- return -1;
- }
- *in = *((struct in_addr *) host_info->h_addr);
- }
- return 0;
-}
-/* }}} */
-/* {{{ php_is_persistent_sock */
-
-PHPAPI int php_is_persistent_sock(int sock)
-{
- char *key;
- TSRMLS_FETCH();
-
- if (zend_hash_find(&FG(ht_fsock_socks), (char *) &sock, sizeof(sock),
- (void **) &key) == SUCCESS) {
- return 1;
- }
- return 0;
-}
-/* }}} */
-/* {{{ php_fsockopen() */
-
-/*
- This function takes an optional third argument which should be
- passed by reference. The error code from the connect call is written
- to this variable.
-*/
-static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
- pval **args[5];
- int *sock=emalloc(sizeof(int));
- int *sockp;
- int arg_count=ZEND_NUM_ARGS();
- int socketd = -1;
- unsigned char udp = 0;
- struct timeval timeout = { 60, 0 };
- unsigned short portno;
- unsigned long conv;
- char *key = NULL;
-
- if (arg_count > 5 || arg_count < 2 || zend_get_parameters_array_ex(arg_count, args)==FAILURE) {
- CLOSE_SOCK(1);
- WRONG_PARAM_COUNT;
- }
- switch(arg_count) {
- case 5:
- convert_to_double_ex(args[4]);
- conv = (unsigned long) ((*args[4])->value.dval * 1000000.0);
- timeout.tv_sec = conv / 1000000;
- timeout.tv_usec = conv % 1000000;
- /* fall-through */
- case 4:
- zval_dtor(*args[3]);
- ZVAL_STRING(*args[3], "", 1);
- /* fall-through */
- case 3:
- zval_dtor(*args[2]);
- ZVAL_LONG(*args[2], 0);
- break;
- }
- convert_to_string_ex(args[0]);
- convert_to_long_ex(args[1]);
- portno = (unsigned short) (*args[1])->value.lval;
-
- key = emalloc((*args[0])->value.str.len + 10);
- sprintf(key, "%s:%d", (*args[0])->value.str.val, portno);
-
- if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1,
- (void *) &sockp) == SUCCESS) {
- CLOSE_SOCK(0);
- *sock = *sockp;
- ZEND_REGISTER_RESOURCE(return_value, sock, php_file_le_socket());
- return;
- }
-
- if (portno) {
- struct sockaddr_in server;
-
- memset(&server, 0, sizeof(server));
- if(Z_STRLEN_PP(args[0]) >= 6 && !memcmp(Z_STRVAL_PP(args[0]), "udp://", sizeof("udp://")-1)) {
- udp = 1;
- }
-
- socketd = socket(AF_INET, udp ? SOCK_DGRAM : SOCK_STREAM, 0);
-
- if (socketd == SOCK_ERR) {
- CLOSE_SOCK(1);
- RETURN_FALSE;
- }
-
- server.sin_family = AF_INET;
-
- if(php_lookup_hostname(udp ? &(*args[0])->value.str.val[6] : (*args[0])->value.str.val, &server.sin_addr)) {
- CLOSE_SOCK(1);
- RETURN_FALSE;
- }
-
- server.sin_port = htons(portno);
-
- if (php_connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) {
- CLOSE_SOCK(1);
-
- if (arg_count>2) {
- zval_dtor(*args[2]);
- ZVAL_LONG(*args[2], errno);
- }
- if (arg_count>3) {
- zval_dtor(*args[3]);
- ZVAL_STRING(*args[3], strerror(errno), 1);
- }
- RETURN_FALSE;
- }
-#if defined(AF_UNIX)
- } else {
- /* Unix domain socket. s->strval is socket name. */
- struct sockaddr_un unix_addr;
- socketd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (socketd == SOCK_ERR) {
- CLOSE_SOCK(1);
- RETURN_FALSE;
- }
-
- memset(&unix_addr, (char)0, sizeof(unix_addr));
- unix_addr.sun_family = AF_UNIX;
- strlcpy(unix_addr.sun_path, (*args[0])->value.str.val, sizeof(unix_addr.sun_path));
-
- if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) {
- CLOSE_SOCK(1);
- if (arg_count>2) {
- zval_dtor(*args[2]);
- ZVAL_LONG(*args[2], errno);
- }
- if (arg_count>3) {
- zval_dtor(*args[3]);
- ZVAL_STRING(*args[3], strerror(errno), 1);
- }
- RETURN_FALSE;
- }
-#endif /* AF_UNIX */
- }
-
-#if 0
- if ((fp = fdopen (socketd, "r+")) == NULL){
- RETURN_LONG(-6); /* FIXME */
- }
-
-#ifdef HAVE_SETVBUF
- if ((setvbuf(fp, NULL, _IONBF, 0)) != 0){
- RETURN_LONG(-7); /* FIXME */
- }
-#endif
-#endif
-
- *sock=socketd;
- if (persistent) {
- zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1,
- sock, sizeof(*sock), NULL);
- zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock),
- key, strlen(key) + 1, NULL);
- }
- if(key) efree(key);
-
- ZEND_REGISTER_RESOURCE(return_value, sock, php_file_le_socket());
-}
-/* }}} */
-
-/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]])
- Open Internet or Unix domain socket connection */
-PHP_FUNCTION(fsockopen)
-{
- php_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]])
- Open persistent Internet or Unix domain socket connection */
-PHP_FUNCTION(pfsockopen)
-{
- php_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-#define 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)
-
-PHPAPI void php_cleanup_sockbuf(int persistent TSRMLS_DC)
-{
- php_sockbuf *now, *next;
-
- for(now = FG(phpsockbuf); now; now = next) {
- next = now->next;
- if(now->persistent == persistent) {
- SOCK_DESTROY(now);
- }
- }
-}
-
-#define TOREAD(sock) ((sock)->writepos - (sock)->readpos)
-#define READPTR(sock) ((sock)->readbuf + (sock)->readpos)
-#define WRITEPTR(sock) ((sock)->readbuf + (sock)->writepos)
-#define SOCK_FIND(sock, socket) \
- php_sockbuf *sock; \
- TSRMLS_FETCH(); \
- sock = php_sockfind(socket TSRMLS_CC); \
- if(!sock) sock = php_sockcreate(socket TSRMLS_CC)
-
-static php_sockbuf *php_sockfind(int socket TSRMLS_DC)
-{
- php_sockbuf *buf = NULL, *tmp;
-
- for(tmp = FG(phpsockbuf); tmp; tmp = tmp->next)
- if(tmp->socket == socket) {
- buf = tmp;
- break;
- }
-
- return buf;
-}
-
-static php_sockbuf *php_sockcreate(int socket TSRMLS_DC)
-{
- php_sockbuf *sock;
- int persistent = php_is_persistent_sock(socket);
-
- sock = pecalloc(sizeof(*sock), 1, persistent);
- sock->socket = socket;
- if((sock->next = FG(phpsockbuf)))
- FG(phpsockbuf)->prev = sock;
- sock->persistent = persistent;
- sock->is_blocked = 1;
- sock->chunk_size = FG(def_chunk_size);
- sock->timeout.tv_sec = -1;
- FG(phpsockbuf) = sock;
-
- return sock;
-}
-
-PHPAPI php_sockbuf *php_get_socket(int socket)
-{
- SOCK_FIND(sock, socket);
- return sock;
-}
-
-PHPAPI size_t php_sock_set_def_chunk_size(size_t size)
-{
- size_t old;
- TSRMLS_FETCH();
-
- old = FG(def_chunk_size);
-
- if(size <= PHP_FSOCK_CHUNK_SIZE || size > 0)
- FG(def_chunk_size) = size;
-
- return old;
-}
-
-PHPAPI int php_sockdestroy(int socket)
-{
- int ret = 0;
- php_sockbuf *sock;
- TSRMLS_FETCH();
-
- sock = php_sockfind(socket TSRMLS_CC);
- if(sock) {
- ret = 1;
- SOCK_DESTROY(sock);
- }
-
- return ret;
-}
-
-#if !defined(PHP_WIN32)
-#undef closesocket
-#define closesocket close
-#endif
-
-#ifndef HAVE_SHUTDOWN
-#undef shutdown
-#define shutdown
-#endif
-
-#define SOCK_CLOSE(s) shutdown(s, 0); closesocket(s)
-
-PHPAPI int php_sock_close(int socket)
-{
- int ret = 0;
- php_sockbuf *sock;
- TSRMLS_FETCH();
-
- sock = php_sockfind(socket TSRMLS_CC);
- if(sock) {
- if(!sock->persistent) {
- SOCK_CLOSE(sock->socket);
- SOCK_DESTROY(sock);
- }
- } else {
- SOCK_CLOSE(socket);
- }
-
- return ret;
-}
-
-#define MAX_CHUNKS_PER_READ 10
-
-static void php_sockwait_for_data(php_sockbuf *sock)
-{
- fd_set fdr, tfdr;
- int retval;
- struct timeval timeout, *ptimeout;
-
- FD_ZERO(&fdr);
- FD_SET(sock->socket, &fdr);
- sock->timeout_event = 0;
-
- if (sock->timeout.tv_sec == -1)
- ptimeout = NULL;
- else
- ptimeout = &timeout;
-
- while(1) {
- tfdr = fdr;
- timeout = sock->timeout;
-
- retval = select(sock->socket + 1, &tfdr, NULL, NULL, ptimeout);
-
- if (retval == 0)
- sock->timeout_event = 1;
-
- if (retval >= 0)
- break;
- }
-}
-
-static size_t php_sockread_internal(php_sockbuf *sock)
-{
- char buf[PHP_FSOCK_CHUNK_SIZE];
- int nr_bytes;
- size_t nr_read = 0;
-
- /* For blocking sockets, we wait until there is some
- data to read (real data or EOF)
-
- Otherwise, recv() may time out and return 0 and
- therefore sock->eof would be set errornously.
- */
-
-
- if(sock->is_blocked) {
- php_sockwait_for_data(sock);
- if (sock->timeout_event)
- return 0;
- }
-
- /* read at a maximum sock->chunk_size */
- nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0);
- if(nr_bytes > 0) {
- if(sock->writepos + nr_bytes > sock->readbuflen) {
- sock->readbuflen += sock->chunk_size;
- sock->readbuf = perealloc(sock->readbuf, sock->readbuflen,
- sock->persistent);
- }
- memcpy(WRITEPTR(sock), buf, nr_bytes);
- sock->writepos += nr_bytes;
- nr_read = nr_bytes;
- } else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
- sock->eof = 1;
- }
-
- return nr_read;
-}
-
-static void php_sockread_total(php_sockbuf *sock, size_t maxread)
-{
- while(!sock->eof && TOREAD(sock) < maxread && !sock->timeout_event) {
- php_sockread_internal(sock);
- }
-}
-
-static size_t php_sockread(php_sockbuf *sock)
-{
- size_t nr_bytes;
- size_t nr_read = 0;
- int i;
-
- for(i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) {
- nr_bytes = php_sockread_internal(sock);
- if(nr_bytes == 0) break;
- nr_read += nr_bytes;
- }
-
- return nr_read;
-}
-
-PHPAPI int php_sockset_blocking(int socket, int mode)
-{
- int old;
- SOCK_FIND(sock, socket);
-
- old = sock->is_blocked;
-
- sock->is_blocked = mode;
-
- return old;
-}
-
-PHPAPI void php_sockset_timeout(int socket, struct timeval *timeout)
-{
- SOCK_FIND(sock, socket);
-
- sock->timeout = *timeout;
- sock->timeout_event = 0;
-}
-
-#define SOCK_FIND_AND_READ_MAX(max) \
- SOCK_FIND(sock, socket); \
- if(sock->is_blocked) php_sockread_total(sock, max); else php_sockread(sock)
-
-/* {{{ php_sock_fgets() */
-/*
- * FIXME: fgets depends on '\n' as line delimiter
- */
-static char * php_sock_fgets_internal(char * buf, size_t maxlen, php_sockbuf * sock)
-{
- char *p = NULL, *pe;
- char *ret = NULL;
- size_t amount = 0;
-
- if (maxlen==0) {
- buf[0] = 0;
- return buf;
- }
-
- SEARCHCR();
-
- if(!p) {
- if(sock->is_blocked) {
- while(!p && !sock->eof && !sock->timeout_event && TOREAD(sock) < maxlen) {
- php_sockread_internal(sock);
- SEARCHCR();
- }
- } else {
- php_sockread(sock);
- SEARCHCR();
- }
- }
-
-
- if(p) {
- amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1;
- } else {
- amount = TOREAD(sock);
- }
-
- amount = MIN(amount, maxlen);
-
- if(amount > 0) {
- memcpy(buf, READPTR(sock), amount);
- sock->readpos += amount;
- }
- buf[amount] = '\0';
-
- /* signal error only, if we don't return data from this call and
- if there is no data to read and if the eof flag is set */
- if(amount || TOREAD(sock) || !sock->eof) {
- ret = buf;
- }
-
- return ret;
-}
-PHPAPI char *php_sock_fgets(char *buf, size_t maxlen, int socket)
-{
- SOCK_FIND(sock, socket);
- return php_sock_fgets_internal(buf, maxlen, sock);
-}
-
-
-/* }}} */
-
-/*
- * 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
- */
-
-PHPAPI int php_sock_fgetc(int socket)
-{
- int ret = EOF;
- SOCK_FIND_AND_READ_MAX(1);
-
- if(TOREAD(sock) > 0) {
- ret = *READPTR(sock);
- sock->readpos++;
- }
-
- return ret;
-}
-
-PHPAPI int php_sock_feof(int socket)
-{
- int ret = 0;
- SOCK_FIND(sock, socket);
-
- if(!sock->is_blocked)
- php_sockread(sock);
-
- if(!TOREAD(sock) && sock->eof)
- ret = 1;
-
- return ret;
-}
-
-/* {{{ stream abstraction */
-#if HAVE_PHP_STREAM
-static size_t php_sockop_write(php_stream * stream, const char * buf, size_t count)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
- return send(sock->socket, buf, count, 0);
-}
-
-static size_t php_sockop_read(php_stream * stream, char * buf, size_t count)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
- size_t ret = 0;
-
- if (sock->is_blocked)
- php_sockread_total(sock, count);
- else
- php_sockread(sock);
-
- if(count < 0)
- return ret;
-
- ret = MIN(TOREAD(sock), count);
- if (ret) {
- memcpy(buf, READPTR(sock), ret);
- sock->readpos += ret;
- }
-
- return ret;
-}
-
-static int php_sockop_close(php_stream * stream)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
-
- SOCK_CLOSE(sock->socket);
- SOCK_DESTROY(sock);
-
- return 0;
-}
-
-static int php_sockop_flush(php_stream * stream)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
- return fsync(sock->socket);
-}
-
-static int php_sockop_cast(php_stream * stream, int castas, void ** ret)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
- TSRMLS_FETCH();
-
- switch(castas) {
- case PHP_STREAM_AS_STDIO:
- if (ret) {
- /* DANGER!: data buffered in stream->readbuf will be forgotten! */
- if (TOREAD(sock) > 0)
- zend_error(E_WARNING, "%s(): buffered data lost during conversion to FILE*!", get_active_function_name(TSRMLS_C));
- *ret = fdopen(sock->socket, stream->mode);
- if (*ret)
- return SUCCESS;
- return FAILURE;
- }
- return SUCCESS;
- case PHP_STREAM_AS_FD:
- case PHP_STREAM_AS_SOCKETD:
- if (ret)
- *ret = (void*)sock->socket;
- return SUCCESS;
- default:
- return FAILURE;
- }
-}
-
-static char * php_sockop_gets(php_stream * stream, char *buf, size_t size)
-{
- php_sockbuf * sock = (php_sockbuf*)stream->abstract;
- return php_sock_fgets_internal(buf, size, sock);
-}
-
-php_stream_ops php_stream_socket_ops = {
- php_sockop_write, php_sockop_read,
- php_sockop_close, php_sockop_flush,
- NULL, php_sockop_gets,
- php_sockop_cast,
- "socket"
-};
-#endif
-/* }}} */
-
-/* {{{ php_sock_fread() */
-
-PHPAPI size_t php_sock_fread(char *ptr, size_t size, int socket)
-{
- size_t ret = 0;
- SOCK_FIND_AND_READ_MAX(size);
-
- if(size < 0)
- return ret;
-
- ret = MIN(TOREAD(sock), size);
- if(ret) {
- memcpy(ptr, READPTR(sock), ret);
- sock->readpos += ret;
- }
-
- return ret;
-}
-
-/* }}} */
-
-/* {{{ module start/shutdown functions */
-
- /* {{{ php_msock_destroy */
-PHPAPI void php_msock_destroy(int *data)
-{
- close(*data);
-}
-/* }}} */
-
-
-
-PHP_RSHUTDOWN_FUNCTION(fsock)
-{
- php_cleanup_sockbuf(0 TSRMLS_CC);
- return SUCCESS;
-}
-/* }}} */
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/fsock.h b/ext/standard/fsock.h
deleted file mode 100644
index 814e442412..0000000000
--- a/ext/standard/fsock.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Paul Panotzki - Bunyip Information Systems |
- | Jim Winstead (jimw@php.net) |
- | Wez Furlong |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.24 1999-06-18 [ssb] */
-
-#ifndef FSOCK_H
-#define FSOCK_H
-
-#include "file.h"
-
-#define PHP_FSOCK_CHUNK_SIZE 8192
-
-#include "php_network.h"
-
-#if HAVE_PHP_STREAM
-extern php_stream_ops php_stream_socket_ops;
-#endif
-
-/* stream->abstract points to an instance of this */
-struct php_sockbuf {
- int socket;
- unsigned char *readbuf;
- size_t readbuflen;
- size_t readpos;
- size_t writepos;
- struct php_sockbuf *next;
- struct php_sockbuf *prev;
- char eof;
- char persistent;
- char is_blocked;
- size_t chunk_size;
- struct timeval timeout;
- char timeout_event;
-#if HAVE_PHP_STREAM
- php_stream * stream;
-#endif
-};
-
-typedef struct php_sockbuf php_sockbuf;
-
-PHP_FUNCTION(fsockopen);
-PHP_FUNCTION(pfsockopen);
-
-PHPAPI int php_lookup_hostname(const char *addr, struct in_addr *in);
-PHPAPI char *php_sock_fgets(char *buf, size_t maxlen, int socket);
-PHPAPI size_t php_sock_fread(char *buf, size_t maxlen, int socket);
-PHPAPI int php_sock_feof(int socket);
-PHPAPI int php_sock_fgetc(int socket);
-PHPAPI int php_is_persistent_sock(int);
-PHPAPI int php_sockset_blocking(int socket, int mode);
-PHPAPI void php_sockset_timeout(int socket, struct timeval *timeout);
-PHPAPI int php_sockdestroy(int socket);
-PHPAPI int php_sock_close(int socket);
-PHPAPI size_t php_sock_set_def_chunk_size(size_t size);
-PHPAPI void php_msock_destroy(int *data);
-PHPAPI void php_cleanup_sockbuf(int persistent TSRMLS_DC);
-
-PHPAPI struct php_sockbuf *php_get_socket(int socket);
-
-PHP_RSHUTDOWN_FUNCTION(fsock);
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim: sw=4 ts=4 tw=78
- */
-#endif /* FSOCK_H */
diff --git a/ext/standard/ftp_fopen_wrapper.c b/ext/standard/ftp_fopen_wrapper.c
deleted file mode 100644
index 8bd3f6d783..0000000000
--- a/ext/standard/ftp_fopen_wrapper.c
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jim Winstead <jimw@php.net> |
- | Hartmut Holzgraefe <hholzgra@php.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_network.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#ifdef PHP_WIN32
-#include <windows.h>
-#include <winsock.h>
-#define O_RDONLY _O_RDONLY
-#include "win32/param.h"
-#else
-#include <sys/param.h>
-#endif
-
-#include "php_standard.h"
-
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef PHP_WIN32
-#include <winsock.h>
-#else
-#include <netinet/in.h>
-#include <netdb.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#endif
-
-#ifdef PHP_WIN32
-#undef AF_UNIX
-#endif
-
-#if defined(AF_UNIX)
-#include <sys/un.h>
-#endif
-
-#include "php_fopen_wrappers.h"
-
-static int php_get_ftp_result(int socketd)
-{
- char tmp_line[513];
-
- while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, socketd) &&
- !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) &&
- isdigit((int) tmp_line[2]) && tmp_line[3] == ' '));
-
- return strtol(tmp_line, NULL, 10);
-}
-
-/* {{{ php_fopen_url_wrap_ftp
- */
-FILE *php_fopen_url_wrap_ftp(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path TSRMLS_DC)
-{
- FILE *fp=NULL;
- php_url *resource=NULL;
- char tmp_line[512];
- unsigned short portno;
- char *scratch;
- int result;
- int i;
- char *tpath, *ttpath;
-
- resource = php_url_parse((char *) path);
- if (resource == NULL) {
- php_error(E_WARNING, "Invalid URL specified, %s", path);
- *issock = BAD_URL;
- return NULL;
- } else if (resource->path == NULL) {
- php_error(E_WARNING, "No file-path specified");
- php_url_free(resource);
- *issock = BAD_URL;
- return NULL;
- }
- /* use port 21 if one wasn't specified */
- if (resource->port == 0)
- resource->port = 21;
-
- *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0);
- if (*socketd == -1)
- goto errexit;
-#if 0
- if ((fpc = fdopen(*socketd, "r+")) == NULL) {
- php_url_free(resource);
- return NULL;
- }
-#ifdef HAVE_SETVBUF
- if ((setvbuf(fpc, NULL, _IONBF, 0)) != 0) {
- php_url_free(resource);
- fclose(fpc);
- return NULL;
- }
-#endif
-#endif
-
- /* Start talking to ftp server */
- result = php_get_ftp_result(*socketd);
- if (result > 299 || result < 200)
- goto errexit;
-
- /* send the user name */
- SOCK_WRITE("USER ", *socketd);
- if (resource->user != NULL) {
- php_raw_url_decode(resource->user, strlen(resource->user));
- SOCK_WRITE(resource->user, *socketd);
- } else {
- SOCK_WRITE("anonymous", *socketd);
- }
- SOCK_WRITE("\r\n", *socketd);
-
- /* get the response */
- result = php_get_ftp_result(*socketd);
-
- /* if a password is required, send it */
- if (result >= 300 && result <= 399) {
- SOCK_WRITE("PASS ", *socketd);
- if (resource->pass != NULL) {
- php_raw_url_decode(resource->pass, strlen(resource->pass));
- SOCK_WRITE(resource->pass, *socketd);
- } else {
- /* if the user has configured who they are,
- send that as the password */
- if (cfg_get_string("from", &scratch) == SUCCESS) {
- SOCK_WRITE(scratch, *socketd);
- } else {
- SOCK_WRITE("anonymous", *socketd);
- }
- }
- SOCK_WRITE("\r\n", *socketd);
-
- /* read the response */
- result = php_get_ftp_result(*socketd);
- }
- if (result > 299 || result < 200)
- goto errexit;
-
- /* set the connection to be binary */
- SOCK_WRITE("TYPE I\r\n", *socketd);
- result = php_get_ftp_result(*socketd);
- if (result > 299 || result < 200)
- goto errexit;
-
- /* find out the size of the file (verifying it exists) */
- SOCK_WRITE("SIZE ", *socketd);
- SOCK_WRITE(resource->path, *socketd);
- SOCK_WRITE("\r\n", *socketd);
-
- /* read the response */
- result = php_get_ftp_result(*socketd);
- if (mode[0] == 'r') {
- /* when reading file, it must exist */
- if (result > 299 || result < 200) {
- php_error(E_WARNING, "File not found");
- php_url_free(resource);
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- errno = ENOENT;
- return NULL;
- }
- } else {
- /* when writing file, it must NOT exist */
- if (result <= 299 && result >= 200) {
- php_error(E_WARNING, "File already exists");
- php_url_free(resource);
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- errno = EEXIST;
- return NULL;
- }
- }
-
- /* set up the passive connection */
-
- /* We try EPSV first, needed for IPv6 and works on some IPv4 servers */
- SOCK_WRITE("EPSV\r\n", *socketd);
- while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) &&
- !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) &&
- isdigit((int) tmp_line[2]) && tmp_line[3] == ' '));
-
- /* check if we got a 229 response */
- if (strncmp(tmp_line, "229", 3)) {
- /* EPSV failed, let's try PASV */
- SOCK_WRITE("PASV\r\n", *socketd);
- while (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) &&
- !(isdigit((int) tmp_line[0]) && isdigit((int) tmp_line[1]) &&
- isdigit((int) tmp_line[2]) && tmp_line[3] == ' '));
- /* make sure we got a 227 response */
- if (strncmp(tmp_line, "227", 3))
- goto errexit;
- /* parse pasv command (129, 80, 95, 25, 13, 221) */
- tpath = tmp_line;
- /* skip over the "227 Some message " part */
- for (tpath += 4; *tpath && !isdigit((int) *tpath); tpath++);
- if (!*tpath)
- goto errexit;
- /* skip over the host ip, we just assume it's the same */
- for (i = 0; i < 4; i++) {
- for (; isdigit((int) *tpath); tpath++);
- if (*tpath != ',')
- goto errexit;
- tpath++;
- }
- /* pull out the MSB of the port */
- portno = (unsigned short) strtol(tpath, &ttpath, 10) * 256;
- if (ttpath == NULL) {
- /* didn't get correct response from PASV */
- goto errexit;
- }
- tpath = ttpath;
- if (*tpath != ',')
- goto errexit;
- tpath++;
- /* pull out the LSB of the port */
- portno += (unsigned short) strtol(tpath, &ttpath, 10);
- } else {
- /* parse epsv command (|||6446|) */
- for (i = 0, tpath = tmp_line + 4; *tpath; tpath++) {
- if (*tpath == '|') {
- i++;
- if (i == 3)
- break;
- }
- }
- if (i < 3)
- goto errexit;
- /* pull out the port */
- portno = (unsigned short) strtol(tpath + 1, &ttpath, 10);
- }
-
- if (ttpath == NULL) {
- /* didn't get correct response from EPSV/PASV */
- goto errexit;
- }
-
- if (mode[0] == 'r') {
- /* retrieve file */
- SOCK_WRITE("RETR ", *socketd);
- } else {
- /* store file */
- SOCK_WRITE("STOR ", *socketd);
- }
- if (resource->path != NULL) {
- SOCK_WRITE(resource->path, *socketd);
- } else {
- SOCK_WRITE("/", *socketd);
- }
-
- /* close control connection */
- SOCK_WRITE("\r\nQUIT\r\n", *socketd);
- SOCK_FCLOSE(*socketd);
-
- /* open the data channel */
- *socketd = php_hostconnect(resource->host, portno, SOCK_STREAM, 0);
- if (*socketd == -1)
- goto errexit;
-#if 0
- if (mode[0] == 'r') {
- if ((fp = fdopen(*socketd, "r+")) == NULL) {
- php_url_free(resource);
- return NULL;
- }
- } else {
- if ((fp = fdopen(*socketd, "w+")) == NULL) {
- php_url_free(resource);
- return NULL;
- }
- }
-#ifdef HAVE_SETVBUF
- if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) {
- php_url_free(resource);
- fclose(fp);
- return NULL;
- }
-#endif
-#endif
- php_url_free(resource);
- *issock = 1;
- return (fp);
-
- errexit:
- php_url_free(resource);
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- return NULL;
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/head.c b/ext/standard/head.c
deleted file mode 100644
index 38f8438f7f..0000000000
--- a/ext/standard/head.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdio.h>
-#include "php.h"
-#include "ext/standard/php_standard.h"
-#include "SAPI.h"
-#include "php_main.h"
-#include "head.h"
-#include "SAPI.h"
-#ifdef TM_IN_SYS_TIME
-#include <sys/time.h>
-#else
-#include <time.h>
-#endif
-
-#include "php_globals.h"
-#include "safe_mode.h"
-
-
-/* Implementation of the language Header() function */
-/* {{{ proto void header(string header[, bool replace])
- Send a raw HTTP header */
-PHP_FUNCTION(header)
-{
- pval **arg1, **arg2;
- zend_bool replace = 1;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2
- || zend_get_parameters_ex(ZEND_NUM_ARGS(), &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (ZEND_NUM_ARGS()) {
- case 2:
- convert_to_boolean_ex(arg2);
- replace = Z_BVAL_PP(arg2);
- case 1:
- convert_to_string_ex(arg1);
- }
- sapi_add_header_ex(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1), 1, replace TSRMLS_CC);
-}
-/* }}} */
-
-PHPAPI int php_header()
-{
- TSRMLS_FETCH();
-
- if (sapi_send_headers(TSRMLS_C)==FAILURE || SG(request_info).headers_only) {
- return 0; /* don't allow output */
- } else {
- return 1; /* allow output */
- }
-}
-
-
-
-/* php_set_cookie(name, value, expires, path, domain, secure) */
-/* {{{ proto void setcookie(string name [, string value [, int expires [, string path [, string domain [, string secure]]]]])
- Send a cookie */
-PHP_FUNCTION(setcookie)
-{
- char *cookie, *encoded_value = NULL;
- int len=sizeof("Set-Cookie: ");
- time_t t;
- char *dt;
- time_t expires = 0;
- int secure = 0;
- pval **arg[6];
- int arg_count;
- zval **z_name=NULL, **z_value=NULL, **z_path=NULL, **z_domain=NULL;
-
- arg_count = ZEND_NUM_ARGS();
- if (arg_count < 1 || arg_count > 6 || zend_get_parameters_array_ex(arg_count, arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- switch (arg_count) {
- case 6:
- convert_to_boolean_ex(arg[5]);
- secure = Z_LVAL_PP(arg[5]);
- /* break missing intentionally */
- case 5:
- convert_to_string_ex(arg[4]);
- z_domain = arg[4];
- /* break missing intentionally */
- case 4:
- convert_to_string_ex(arg[3]);
- z_path = arg[3];
- /* break missing intentionally */
- case 3:
- convert_to_long_ex(arg[2]);
- expires = Z_LVAL_PP(arg[2]);
- /* break missing intentionally */
- case 2:
- convert_to_string_ex(arg[1]);
- z_value = arg[1];
- /* break missing intentionally */
- case 1:
- convert_to_string_ex(arg[0]);
- z_name = arg[0];
- break;
- }
- if (z_name) {
- len += Z_STRLEN_PP(z_name);
- }
- if (z_value) {
- int encoded_value_len;
-
- encoded_value = php_url_encode(Z_STRVAL_PP(z_value), Z_STRLEN_PP(z_value), &encoded_value_len);
- len += encoded_value_len;
- }
- if (z_path) {
- len += Z_STRLEN_PP(z_path);
- }
- if (z_domain) {
- len += Z_STRLEN_PP(z_domain);
- }
- cookie = emalloc(len + 100);
- if (z_value && Z_STRLEN_PP(z_value)==0) {
- /*
- * MSIE doesn't delete a cookie when you set it to a null value
- * so in order to force cookies to be deleted, even on MSIE, we
- * pick an expiry date 1 year and 1 second in the past
- */
- t = time(NULL) - 31536001;
- dt = php_std_date(t);
- sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", Z_STRVAL_PP(z_name), dt);
- efree(dt);
- } else {
- sprintf(cookie, "Set-Cookie: %s=%s", Z_STRVAL_PP(z_name), (z_value && Z_STRVAL_PP(z_value)) ? encoded_value : "");
- if (expires > 0) {
- strcat(cookie, "; expires=");
- dt = php_std_date(expires);
- strcat(cookie, dt);
- efree(dt);
- }
- }
-
- if (encoded_value) {
- efree(encoded_value);
- }
-
- if (z_path && Z_STRLEN_PP(z_path)>0) {
- strcat(cookie, "; path=");
- strcat(cookie, Z_STRVAL_PP(z_path));
- }
- if (z_domain && Z_STRLEN_PP(z_domain)>0) {
- strcat(cookie, "; domain=");
- strcat(cookie, Z_STRVAL_PP(z_domain));
- }
- if (secure) {
- strcat(cookie, "; secure");
- }
-
- if (sapi_add_header(cookie, strlen(cookie), 0)==SUCCESS) {
- RETVAL_TRUE;
- } else {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-
-/* {{{ proto int headers_sent(void)
- Return true if headers have already been sent, false otherwise */
-PHP_FUNCTION(headers_sent)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- if (SG(headers_sent)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78 * End:
- */
diff --git a/ext/standard/head.h b/ext/standard/head.h
deleted file mode 100644
index 1de1a5b379..0000000000
--- a/ext/standard/head.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef HEAD_H
-#define HEAD_H
-
-extern PHP_RINIT_FUNCTION(head);
-PHP_FUNCTION(header);
-PHP_FUNCTION(setcookie);
-PHP_FUNCTION(headers_sent);
-
-PHPAPI int php_header(void);
-
-#endif
diff --git a/ext/standard/html.c b/ext/standard/html.c
deleted file mode 100644
index 68c29c4e6c..0000000000
--- a/ext/standard/html.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jaakko Hyvätti <jaakko.hyvatti@iki.fi> |
- | Wez Furlong <wez@thebrainroom.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "reg.h"
-#include "html.h"
-
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#if HAVE_LANGINFO_H
-#include <langinfo.h>
-#endif
-
-/* This must be fixed to handle the input string according to LC_CTYPE.
- Defaults to ISO-8859-1 for now. */
-
-enum entity_charset { cs_terminator, cs_8859_1, cs_cp1252,
- cs_8859_15, cs_utf_8 };
-typedef const char * entity_table_t;
-
-/* codepage 1252 is a Windows extension to iso-8859-1. */
-static entity_table_t ent_cp_1252[] = {
- NULL, NULL, "sbquo", "fnof", "bdquo", "hellip", "dagger",
- "Dagger", "circ", "permil", "Scaron", "lsaquo", "OElig",
- NULL, NULL, NULL, NULL, "lsquo", "rsquo", "ldquo", "rdquo",
- "bull", "ndash", "mdash", "tilde", "trade", "scaron", "rsaquo",
- "oelig", NULL, NULL, "Yuml"
-};
-
-static entity_table_t ent_iso_8859_1[] = {
- "nbsp", "iexcl", "cent", "pound", "curren", "yen", "brvbar",
- "sect", "uml", "copy", "ordf", "laquo", "not", "shy", "reg",
- "macr", "deg", "plusmn", "sup2", "sup3", "acute", "micro",
- "para", "middot", "cedil", "sup1", "ordm", "raquo", "frac14",
- "frac12", "frac34", "iquest", "Agrave", "Aacute", "Acirc",
- "Atilde", "Auml", "Aring", "AElig", "Ccedil", "Egrave",
- "Eacute", "Ecirc", "Euml", "Igrave", "Iacute", "Icirc",
- "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc", "Otilde",
- "Ouml", "times", "Oslash", "Ugrave", "Uacute", "Ucirc", "Uuml",
- "Yacute", "THORN", "szlig", "agrave", "aacute", "acirc",
- "atilde", "auml", "aring", "aelig", "ccedil", "egrave",
- "eacute", "ecirc", "euml", "igrave", "iacute", "icirc",
- "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc", "otilde",
- "ouml", "divide", "oslash", "ugrave", "uacute", "ucirc",
- "uuml", "yacute", "thorn", "yuml"
-};
-
-static entity_table_t ent_iso_8859_15[] = {
- "nbsp", "iexcl", "cent", "pound", "euro", "yen", "Scaron",
- "sect", "scaron", "copy", "ordf", "laquo", "not", "shy", "reg",
- "macr", "deg", "plusmn", "sup2", "sup3", NULL, /* Zcaron */
- "micro", "para", "middot", NULL, /* zcaron */ "sup1", "ordm",
- "raquo", "OElig", "oelig", "Yuml", "iquest", "Agrave", "Aacute",
- "Acirc", "Atilde", "Auml", "Aring", "AElig", "Ccedil", "Egrave",
- "Eacute", "Ecirc", "Euml", "Igrave", "Iacute", "Icirc",
- "Iuml", "ETH", "Ntilde", "Ograve", "Oacute", "Ocirc", "Otilde",
- "Ouml", "times", "Oslash", "Ugrave", "Uacute", "Ucirc", "Uuml",
- "Yacute", "THORN", "szlig", "agrave", "aacute", "acirc",
- "atilde", "auml", "aring", "aelig", "ccedil", "egrave",
- "eacute", "ecirc", "euml", "igrave", "iacute", "icirc",
- "iuml", "eth", "ntilde", "ograve", "oacute", "ocirc", "otilde",
- "ouml", "divide", "oslash", "ugrave", "uacute", "ucirc",
- "uuml", "yacute", "thorn", "yuml"
-};
-
-struct html_entity_map {
- enum entity_charset charset; /* charset identifier */
- unsigned short basechar; /* char code at start of table */
- unsigned short endchar; /* last char code in the table */
- entity_table_t * table; /* the table of mappings */
-};
-
-static const struct html_entity_map entity_map[] = {
- { cs_cp1252, 0x80, 0x9f, ent_cp_1252 },
- { cs_cp1252, 0xa0, 0xff, ent_iso_8859_1 },
- { cs_8859_1, 0xa0, 0xff, ent_iso_8859_1 },
- { cs_8859_15, 0xa0, 0xff, ent_iso_8859_15 },
- { cs_utf_8, 0xa0, 0xff, ent_iso_8859_1 },
- { cs_terminator }
-};
-
-static const struct {
- const char * codeset;
- enum entity_charset charset;
-} charset_map[] = {
- { "ISO-8859-1", cs_8859_1 },
- { "ISO-8859-15", cs_8859_15 },
- { "utf-8", cs_utf_8 },
- { "cp1252", cs_cp1252 },
- { NULL }
-};
-
-/* {{{ get_next_char
- */
-inline static unsigned short get_next_char(enum entity_charset charset,
- unsigned char * str,
- int * newpos,
- unsigned char * mbseq,
- int * mbseqlen
-)
-{
- int pos = *newpos;
- int mbpos = 0;
- unsigned short this_char = str[pos++];
-
- mbseq[mbpos++] = (unsigned char)this_char;
-
- if (charset == cs_utf_8) {
- unsigned long utf = 0;
- int stat = 0;
- int more = 1;
-
- /* unpack utf-8 encoding into a wide char.
- * Code stolen from the mbstring extension */
-
- do {
- if (this_char < 0x80) {
- more = 0;
- break;
- }
- else if (this_char < 0xc0) {
- switch(stat) {
- case 0x10: /* 2, 2nd */
- case 0x21: /* 3, 3rd */
- case 0x32: /* 4, 4th */
- case 0x43: /* 5, 5th */
- case 0x54: /* 6, 6th */
- /* last byte in sequence */
- more = 0;
- utf |= (this_char & 0x3f);
- this_char = (unsigned short)utf;
- break;
- case 0x20: /* 3, 2nd */
- case 0x31: /* 4, 3rd */
- case 0x42: /* 5, 4th */
- case 0x53: /* 6, 5th */
- /* penultimate char */
- utf |= ((this_char & 0x3f) << 6);
- stat++;
- break;
- case 0x30: /* 4, 2nd */
- case 0x41: /* 5, 3rd */
- case 0x52: /* 6, 4th */
- utf |= ((this_char & 0x3f) << 12);
- stat++;
- break;
- case 0x40: /* 5, 2nd */
- case 0x51:
- utf |= ((this_char & 0x3f) << 18);
- stat++;
- break;
- case 0x50: /* 6, 2nd */
- utf |= ((this_char & 0x3f) << 24);
- stat++;
- default:
- /* invalid */
- more = 0;
- }
- }
- /* lead byte */
- else if (this_char < 0xe0) {
- stat = 0x10; /* 2 byte */
- utf = (this_char & 0x1f) << 6;
- } else if (this_char < 0xf0) {
- stat = 0x20; /* 3 byte */
- utf = (this_char & 0xf) << 12;
- } else if (this_char < 0xf8) {
- stat = 0x30; /* 4 byte */
- utf = (this_char & 0x7) << 18;
- } else if (this_char < 0xfc) {
- stat = 0x40; /* 5 byte */
- utf = (this_char & 0x3) << 24;
- } else if (this_char < 0xfe) {
- stat = 0x50; /* 6 byte */
- utf = (this_char & 0x1) << 30;
- }
- else {
- /* invalid; bail */
- more = 0;
- break;
- }
- if (more)
- {
- this_char = str[pos++];
- mbseq[mbpos++] = (unsigned char)this_char;
- }
- } while(more);
- }
- *newpos = pos;
- mbseq[mbpos] = '\0';
- *mbseqlen = mbpos;
- return this_char;
-}
-/* }}} */
-
-/* {{{ entity_charset determine_charset
- * returns the charset identifier based on current locale or a hint.
- * defaults to iso-8859-1 */
-static enum entity_charset determine_charset(char * charset_hint)
-{
- int i;
- enum entity_charset charset = cs_8859_1;
- int len;
-
- /* Guarantee default behaviour */
- if (charset_hint == NULL)
- return cs_8859_1;
-
- if (strlen(charset_hint) == 0) {
- /* try to detect the charset for the locale */
-#if HAVE_NL_LANGINFO && HAVE_LOCALE_H && defined(CODESET)
- charset_hint = nl_langinfo(CODESET);
-#endif
-#if HAVE_LOCALE_H
- if (charset_hint == NULL)
- {
- /* try to figure out the charset from the locale */
- char * localename;
- char * dot, * at;
-
- /* lang[_territory][.codeset][@modifier] */
- localename = setlocale(LC_CTYPE, NULL);
-
- dot = strchr(localename, '.');
- if (dot) {
- dot++;
- /* locale specifies a codeset */
- at = strchr(dot, '@');
- if (at)
- len = at - dot;
- else
- len = strlen(dot);
- charset_hint = dot;
- }
- else {
- /* no explicit name; see if the name itself
- * is the charset */
- charset_hint = localename;
- len = strlen(charset_hint);
- }
- }
- else
- len = strlen(charset_hint);
-#else
- if (charset_hint)
- len = strlen(charset_hint);
-#endif
- }
- if (charset_hint) {
- /* now walk the charset map and look for the codeset */
- for (i = 0; charset_map[i].codeset; i++) {
- if (strncasecmp(charset_hint, charset_map[i].codeset, len) == 0) {
- charset = charset_map[i].charset;
- break;
- }
- }
- }
- return charset;
-}
-/* }}} */
-
-/* {{{ php_escape_html_entities
- */
-PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char * hint_charset)
-{
- int i, maxlen, len;
- char *new;
- enum entity_charset charset = determine_charset(hint_charset);
-
- maxlen = 2 * oldlen;
- if (maxlen < 128)
- maxlen = 128;
- new = emalloc (maxlen);
- len = 0;
-
- i = 0;
- while (i < oldlen) {
- int mbseqlen;
- unsigned char mbsequence[16]; /* allow up to 15 characters
- in a multibyte sequence
- it should be more than enough.. */
- unsigned short this_char = get_next_char(charset, old, &i, mbsequence, &mbseqlen);
- int matches_map = 0;
-
- if (len + 9 > maxlen)
- new = erealloc (new, maxlen += 128);
-
- if (all) {
- /* look for a match in the maps for this charset */
- int j;
- unsigned char * rep;
-
- for (j=0; entity_map[j].charset != cs_terminator; j++) {
- if (entity_map[j].charset == charset
- && this_char >= entity_map[j].basechar
- && this_char <= entity_map[j].endchar)
- {
- rep = (unsigned char*)entity_map[j].table[this_char - entity_map[j].basechar];
- if (rep == NULL) {
- /* there is no entity for this position; fall through and
- * just output the character itself */
- break;
- }
-
- matches_map = 1;
- break;
- }
- }
-
- if (matches_map) {
- new[len++] = '&';
- strcpy(new + len, rep);
- len += strlen(rep);
- new[len++] = ';';
- }
- }
- if (!matches_map) {
- if (38 == this_char) {
- memcpy (new + len, "&amp;", 5);
- len += 5;
- } else if (34 == this_char && !(quote_style&ENT_NOQUOTES)) {
- memcpy (new + len, "&quot;", 6);
- len += 6;
- } else if (39 == this_char && (quote_style&ENT_QUOTES)) {
- memcpy (new + len, "&#039;", 6);
- len += 6;
- } else if (60 == this_char) {
- memcpy (new + len, "&lt;", 4);
- len += 4;
- } else if (62 == this_char) {
- memcpy (new + len, "&gt;", 4);
- len += 4;
- } else if (this_char > 0xff) {
- /* a wide char without a named entity; pass through the original sequence */
- memcpy(new + len, mbsequence, mbseqlen);
- len += mbseqlen;
- } else {
- new [len++] = (unsigned char)this_char;
- }
- }
- }
- new [len] = '\0';
- *newlen = len;
-
- return new;
-
-
-}
-/* }}} */
-
-/* {{{ php_html_entities
- */
-static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
-{
- zval **arg, **quotes, **charset;
- int len, quote_style = ENT_COMPAT;
- int ac = ZEND_NUM_ARGS();
- char *hint_charset = NULL;
- char *new;
-
- if (ac < 1 || ac > 3 || zend_get_parameters_ex(ac, &arg, &quotes, &charset) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg);
- if(ac==2) {
- convert_to_long_ex(quotes);
- quote_style = (*quotes)->value.lval;
- }
- if (ac == 3) {
- convert_to_string_ex(charset);
- hint_charset = Z_STRVAL_PP(charset);
- }
-
-
- new = php_escape_html_entities((*arg)->value.str.val, (*arg)->value.str.len, &len, all, quote_style, hint_charset);
- RETVAL_STRINGL(new, len, 0);
-}
-/* }}} */
-
-#define HTML_SPECIALCHARS 0
-#define HTML_ENTITIES 1
-
-/* {{{ register_html_constants
- */
-void register_html_constants(INIT_FUNC_ARGS)
-{
- REGISTER_LONG_CONSTANT("HTML_SPECIALCHARS", HTML_SPECIALCHARS, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("HTML_ENTITIES", HTML_ENTITIES, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("ENT_COMPAT", ENT_COMPAT, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("ENT_QUOTES", ENT_QUOTES, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("ENT_NOQUOTES", ENT_NOQUOTES, CONST_PERSISTENT|CONST_CS);
-}
-/* }}} */
-
-/* {{{ proto string htmlspecialchars(string string [, int quote_style][, string charset])
- Convert special characters to HTML entities */
-PHP_FUNCTION(htmlspecialchars)
-{
- php_html_entities(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto string htmlentities(string string [, int quote_style][, string charset])
- Convert all applicable characters to HTML entities */
-PHP_FUNCTION(htmlentities)
-{
- php_html_entities(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ proto array get_html_translation_table([int table [, int quote_style][, string charset]])
- Returns the internal translation table used by htmlspecialchars and htmlentities */
-PHP_FUNCTION(get_html_translation_table)
-{
- zval **whichone, **quotes;
- int which = HTML_SPECIALCHARS, quote_style = ENT_COMPAT;
- int ac = ZEND_NUM_ARGS();
- int i, j;
- char ind[ 2 ];
- enum entity_charset charset = determine_charset(NULL);
-
- if (ac < 0 || ac > 2 || zend_get_parameters_ex(ac, &whichone, &quotes) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (ac > 0) {
- convert_to_long_ex(whichone);
- which = (*whichone)->value.lval;
- }
- if (ac == 2) {
- convert_to_long_ex(quotes);
- quote_style = (*quotes)->value.lval;
- }
-
- array_init(return_value);
-
- ind[1] = 0;
-
- switch (which) {
- case HTML_ENTITIES:
- for (j=0; entity_map[j].charset != cs_terminator; j++) {
- if (entity_map[j].charset != charset)
- continue;
- for (i = 0; i < entity_map[j].endchar - entity_map[j].basechar; i++)
- {
- char buffer[16];
-
- if (entity_map[j].table[i] == NULL)
- continue;
- /* what about wide chars here ?? */
- ind[0] = i + entity_map[j].basechar;
- sprintf(buffer, "&%s;", entity_map[j].table[i]);
- add_assoc_string(return_value, ind, buffer, 1);
-
- }
- }
- /* break thru */
-
- case HTML_SPECIALCHARS:
- ind[0]=38; add_assoc_string(return_value, ind, "&amp;", 1);
- if(quote_style&ENT_QUOTES) {
- ind[0]=39; add_assoc_string(return_value, ind, "&#039;", 1);
- }
- if(!(quote_style&ENT_NOQUOTES)) {
- ind[0]=34; add_assoc_string(return_value, ind, "&quot;", 1);
- }
- ind[0]=60; add_assoc_string(return_value, ind, "&lt;", 1);
- ind[0]=62; add_assoc_string(return_value, ind, "&gt;", 1);
- break;
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/html.h b/ext/standard/html.h
deleted file mode 100644
index 682ced2273..0000000000
--- a/ext/standard/html.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef HTML_H
-#define HTML_H
-
-#define ENT_COMPAT 1
-#define ENT_QUOTES 2
-#define ENT_NOQUOTES 4
-
-void register_html_constants(INIT_FUNC_ARGS);
-
-PHP_FUNCTION(htmlspecialchars);
-PHP_FUNCTION(htmlentities);
-PHP_FUNCTION(get_html_translation_table);
-
-PHPAPI char *php_escape_html_entities(unsigned char *old, int oldlen, int *newlen, int all, int quote_style, char * hint_charset);
-
-#endif /* HTML_H */
diff --git a/ext/standard/http_fopen_wrapper.c b/ext/standard/http_fopen_wrapper.c
deleted file mode 100644
index 253a75f413..0000000000
--- a/ext/standard/http_fopen_wrapper.c
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jim Winstead <jimw@php.net> |
- | Hartmut Holzgraefe <hholzgra@php.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_network.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#ifdef PHP_WIN32
-#include <windows.h>
-#include <winsock.h>
-#define O_RDONLY _O_RDONLY
-#include "win32/param.h"
-#else
-#include <sys/param.h>
-#endif
-
-#include "php_standard.h"
-
-#include <sys/types.h>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-
-#ifdef PHP_WIN32
-#include <winsock.h>
-#else
-#include <netinet/in.h>
-#include <netdb.h>
-#if HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-#endif
-
-#ifdef PHP_WIN32
-#undef AF_UNIX
-#endif
-
-#if defined(AF_UNIX)
-#include <sys/un.h>
-#endif
-
-#include "php_fopen_wrappers.h"
-
-#define HTTP_HEADER_BLOCK_SIZE 128
-
-/* {{{ php_fopen_url_wrap_http
- */
-FILE *php_fopen_url_wrap_http(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path TSRMLS_DC)
-{
- FILE *fp=NULL;
- php_url *resource=NULL;
- char tmp_line[128];
- char location[512];
- char hdr_line[8192];
- int body = 0;
- char *scratch;
- unsigned char *tmp;
- int len;
- int reqok = 0;
- zval *response_header;
- char *http_header_line;
- int http_header_line_length, http_header_line_size;
-
- resource = php_url_parse((char *) path);
- if (resource == NULL) {
- php_error(E_WARNING, "Invalid URL specified, %s", path);
- *issock = BAD_URL;
- return NULL;
- }
- /* use port 80 if one wasn't specified */
- if (resource->port == 0) {
- resource->port = 80;
- }
-
- *socketd = php_hostconnect(resource->host, resource->port, SOCK_STREAM, 0);
- if (*socketd == -1) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- php_url_free(resource);
- return NULL;
- }
-#if 0
- if ((fp = fdopen(*socketd, "r+")) == NULL) {
- php_url_free(resource);
- return NULL;
- }
-#ifdef HAVE_SETVBUF
- if ((setvbuf(fp, NULL, _IONBF, 0)) != 0) {
- php_url_free(resource);
- return NULL;
- }
-#endif
-#endif /*win32 */
-
- strcpy(hdr_line, "GET ");
-
- /* tell remote http which file to get */
- if (resource->path != NULL && *resource->path) {
- strlcat(hdr_line, resource->path, sizeof(hdr_line));
- } else {
- strlcat(hdr_line, "/", sizeof(hdr_line));
- }
- /* append the query string, if any */
- if (resource->query != NULL) {
- strlcat(hdr_line, "?", sizeof(hdr_line));
- strlcat(hdr_line, resource->query, sizeof(hdr_line));
- }
- strlcat(hdr_line, " HTTP/1.0\r\n", sizeof(hdr_line));
- SOCK_WRITE(hdr_line, *socketd);
-
- /* send authorization header if we have user/pass */
- if (resource->user != NULL && resource->pass != NULL) {
- scratch = (char *) emalloc(strlen(resource->user) + strlen(resource->pass) + 2);
- if (!scratch) {
- php_url_free(resource);
- return NULL;
- }
- strcpy(scratch, resource->user);
- strcat(scratch, ":");
- strcat(scratch, resource->pass);
- tmp = php_base64_encode((unsigned char *)scratch, strlen(scratch), NULL);
-
- if (snprintf(hdr_line, sizeof(hdr_line),
- "Authorization: Basic %s\r\n", tmp) > 0) {
- SOCK_WRITE(hdr_line, *socketd);
- }
-
- efree(scratch);
- efree(tmp);
- }
- /* if the user has configured who they are, send a From: line */
- if (cfg_get_string("from", &scratch) == SUCCESS) {
- if (snprintf(hdr_line, sizeof(hdr_line),
- "From: %s\r\n", scratch) > 0) {
- SOCK_WRITE(hdr_line, *socketd);
- }
-
- }
- /* send a Host: header so name-based virtual hosts work */
- if (resource->port != 80) {
- len = snprintf(hdr_line, sizeof(hdr_line),
- "Host: %s:%i\r\n", resource->host, resource->port);
- } else {
- len = snprintf(hdr_line, sizeof(hdr_line),
- "Host: %s\r\n", resource->host);
- }
- if(len > sizeof(hdr_line) - 1) {
- len = sizeof(hdr_line) - 1;
- }
- if (len > 0) {
- SOCK_WRITE(hdr_line, *socketd);
- }
-
- /* identify ourselves and end the headers */
- SOCK_WRITE("User-Agent: PHP/" PHP_VERSION "\r\n\r\n", *socketd);
-
- body = 0;
- location[0] = '\0';
-
- MAKE_STD_ZVAL(response_header);
- array_init(response_header);
-
- if (!SOCK_FEOF(*socketd)) {
- /* get response header */
- if (SOCK_FGETS(tmp_line, sizeof(tmp_line)-1, *socketd) != NULL) {
- zval *http_response;
-
- MAKE_STD_ZVAL(http_response);
- if (strncmp(tmp_line + 8, " 200 ", 5) == 0) {
- reqok = 1;
- }
- Z_STRLEN_P(http_response) = strlen(tmp_line);
- Z_STRVAL_P(http_response) = estrndup(tmp_line, Z_STRLEN_P(http_response));
- if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\n') {
- Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0;
- Z_STRLEN_P(http_response)--;
- if (Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=='\r') {
- Z_STRVAL_P(http_response)[Z_STRLEN_P(http_response)-1]=0;
- Z_STRLEN_P(http_response)--;
- }
- }
- Z_TYPE_P(http_response) = IS_STRING;
- zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response, sizeof(zval *), NULL);
- }
- }
-
-
- /* Read past HTTP headers */
- while (!body && !SOCK_FEOF(*socketd)) {
- http_header_line = emalloc(HTTP_HEADER_BLOCK_SIZE);
- http_header_line_size = HTTP_HEADER_BLOCK_SIZE;
- http_header_line_length = 0;
- if (SOCK_FGETS(http_header_line, HTTP_HEADER_BLOCK_SIZE-1, *socketd) != NULL) {
- char *p;
- zend_bool found_eol=0;
- zval *http_header;
-
- http_header_line[HTTP_HEADER_BLOCK_SIZE-1] = '\0';
-
- do {
- p = http_header_line+http_header_line_length;
- while (*p) {
- while (*p == '\n' || *p == '\r') {
- *p = '\0';
- p--;
- found_eol=1;
- }
- if (found_eol) {
- break;
- }
- p++;
- }
- if (!found_eol) {
- http_header_line_size += HTTP_HEADER_BLOCK_SIZE;
- http_header_line_length += HTTP_HEADER_BLOCK_SIZE-1;
- http_header_line = erealloc(http_header_line, http_header_line_size);
- if (SOCK_FGETS(http_header_line+http_header_line_length, HTTP_HEADER_BLOCK_SIZE-1, *socketd)==NULL) {
- http_header_line[http_header_line_length] = 0;
- break;
- }
- } else {
- http_header_line_length = p-http_header_line+1;
- }
- } while (!found_eol);
-
- if (!strncasecmp(http_header_line, "Location: ", 10)) {
- strlcpy(location, http_header_line + 10, sizeof(location));
- }
-
- if (http_header_line[0] == '\0') {
- body = 1;
- }
-
- if (http_header_line_length>0) {
- MAKE_STD_ZVAL(http_header);
- Z_STRVAL_P(http_header) = http_header_line;
- Z_STRLEN_P(http_header) = http_header_line_length;
- Z_TYPE_P(http_header) = IS_STRING;
- zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_header, sizeof(zval *), NULL);
- } else {
- efree(http_header_line);
- }
- }
- }
-
- if (!reqok) {
- SOCK_FCLOSE(*socketd);
- *socketd = 0;
- php_url_free(resource);
- if (location[0] != '\0') {
- zval **response_header_new, *entry, **entryp;
-
- fp = php_fopen_url_wrap_http(location, mode, options, issock, socketd, opened_path TSRMLS_CC);
- if (zend_hash_find(EG(active_symbol_table), "http_response_header", sizeof("http_response_header"), (void **) &response_header_new) == SUCCESS) {
- entryp = &entry;
- MAKE_STD_ZVAL(entry);
- ZVAL_EMPTY_STRING(entry);
- zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL);
- zend_hash_internal_pointer_reset(Z_ARRVAL_PP(response_header_new));
- while (zend_hash_get_current_data(Z_ARRVAL_PP(response_header_new), (void **)&entryp) == SUCCESS) {
- zval_add_ref(entryp);
- zend_hash_next_index_insert(Z_ARRVAL_P(response_header), entryp, sizeof(zval *), NULL);
- zend_hash_move_forward(Z_ARRVAL_PP(response_header_new));
- }
- }
- goto out;
- } else {
- fp = NULL;
- goto out;
- }
- }
- php_url_free(resource);
- *issock = 1;
- out:
- {
- ZEND_SET_SYMBOL(EG(active_symbol_table), "http_response_header", response_header);
- }
- return (fp);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/image.c b/ext/standard/image.c
deleted file mode 100644
index 4a23bdff7e..0000000000
--- a/ext/standard/image.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-/*
- * Based on Daniel Schmitt's imageinfo.c which carried the following
- * Copyright notice.
- */
-
-/*
- * imageinfo.c
- *
- * Simple routines to extract image width/height data from GIF/JPEG files.
- *
- * Copyright (c) 1997 Daniel Schmitt, opal online publishing, Bonn, Germany.
- *
- * Includes code snippets from rdjpgcom.c,
- * Copyright (c) 1994-1995 Thomas G. Lane
- * from release 6a of the Independent JPEG Group's software.
- *
- * Legal status: see GNU General Public License version 2 or later.
- *
- */
-
-#include "php.h"
-#include <stdio.h>
-#if HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-#include "fopen_wrappers.h"
-#include "ext/standard/fsock.h"
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include "php_image.h"
-
-/* file type markers */
-PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'};
-PHPAPI const char php_sig_psd[4] = {'8', 'B', 'P', 'S'};
-PHPAPI const char php_sig_bmp[2] = {'B', 'M'};
-PHPAPI const char php_sig_swf[3] = {'F', 'W', 'S'};
-PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff};
-PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47,
-(char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a};
-
-/* return info as a struct, to make expansion easier */
-
-struct gfxinfo {
- unsigned int width;
- unsigned int height;
- unsigned int bits;
- unsigned int channels;
-};
-
-/* {{{ php_handle_gif
- * routine to handle GIF files. If only everything were that easy... ;} */
-static struct gfxinfo *php_handle_gif (int socketd, FILE *fp, int issock)
-{
- struct gfxinfo *result = NULL;
- unsigned char a[2];
- char temp[3];
-
- result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
-
- FP_FREAD(temp, 3, socketd, fp, issock); /* fseek(fp, 6L, SEEK_SET); */
-
- FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
- result->width = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
-
- FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
- result->height = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
-
- return result;
-}
-/* }}} */
-
-/* {{{ php_handle_psd
- */
-static struct gfxinfo *php_handle_psd (int socketd, FILE *fp, int issock)
-{
- struct gfxinfo *result = NULL;
- unsigned char a[8];
- char temp[11];
- unsigned long in_width, in_height;
-
- result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
- FP_FREAD(temp, sizeof(temp), socketd, fp, issock);
-
- if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) {
- in_height = 0;
- in_width = 0;
- } else {
- in_height = (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]);
- in_width = (((unsigned long) a[ 4 ]) << 24) + (((unsigned long) a[ 5 ]) << 16) + (((unsigned long) a[ 6 ]) << 8) + ((unsigned long) a[ 7 ]);
- }
-
- result->width = (unsigned int) in_width;
- result->height = (unsigned int) in_height;
-
- return result;
-}
-/* }}} */
-
-/* {{{ php_handle_bmp
- */
-static struct gfxinfo *php_handle_bmp (int socketd, FILE *fp, int issock)
-{
- struct gfxinfo *result = NULL;
- char temp[15];
-
- struct {
- unsigned long in_width, in_height;
- } dim;
-
- result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
-
- FP_FREAD(temp, sizeof(temp), socketd, fp, issock);
- FP_FREAD((char*) &dim, sizeof(dim), socketd, fp, issock);
- result->width = dim.in_width;
- result->height = dim.in_height;
-
- return result;
-}
-/* }}} */
-
-/* {{{ php_swf_get_bits
- * routines to handle SWF files. */
-static unsigned long int php_swf_get_bits (unsigned char* buffer, unsigned int pos, unsigned int count)
-{
- unsigned int loop;
- unsigned long int result = 0;
-
- for (loop = pos; loop < pos + count; loop++)
- {
- result = result +
- ((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1));
- }
- return result;
-}
-/* }}} */
-
-/* {{{ php_handle_swf
- */
-static struct gfxinfo *php_handle_swf (int socketd, FILE *fp, int issock)
-{
- struct gfxinfo *result = NULL;
- long bits;
- unsigned char a[32];
- char temp[5];
-
- result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
- FP_FREAD(temp, 5, socketd, fp, issock); /* fseek(fp, 8L, SEEK_SET); */
-
- FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
- bits = php_swf_get_bits (a, 0, 5);
- result->width = (php_swf_get_bits (a, 5 + bits, bits) -
- php_swf_get_bits (a, 5, bits)) / 20;
- result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) -
- php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20;
- return result;
-}
-/* }}} */
-
-/* {{{ php_handle_png
- * routine to handle PNG files */
-static struct gfxinfo *php_handle_png (int socketd, FILE *fp, int issock)
-{
- struct gfxinfo *result = NULL;
- unsigned long in_width, in_height;
- char temp[8];
- unsigned char a[8];
-
- result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
-
- FP_FREAD(temp, sizeof(temp), socketd, fp, issock); /* fseek(fp, 16L, SEEK_SET); */
-
- if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) {
- in_width = 0;
- in_height = 0;
- } else {
- in_width = (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]);
- in_height = (((unsigned long) a[ 4 ]) << 24) + (((unsigned long) a[ 5 ]) << 16) + (((unsigned long) a[ 6 ]) << 8) + ((unsigned long) a[ 7 ]);
- }
-
- 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
-
-/* {{{ php_read2
- */
-static unsigned short php_read2(int socketd, FILE *fp, int issock)
-{
- unsigned char a[2];
-
- /* just return 0 if we hit the end-of-file */
- if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) return 0;
-
- return (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]);
-}
-/* }}} */
-
-/* {{{ php_next_marker
- */
-static unsigned int php_next_marker(int socketd, FILE *fp, int issock)
- /* get next marker byte from file */
-{
- int c;
-
- /* get marker byte, swallowing possible padding */
- do {
- if ((c = FP_FGETC(socketd, fp, issock)) == EOF)
- return M_EOI; /* we hit EOF */
- } while (c == 0xff);
-
- return (unsigned int) c;
-}
-/* }}} */
-
-/* {{{ php_skip_variable
- */
-static void php_skip_variable(int socketd, FILE *fp, int issock)
- /* skip over a variable-length block; assumes proper length marker */
-{
- unsigned short length;
- char *tmp;
-
- length = php_read2(socketd, fp, issock);
- length -= 2; /* length includes itself */
-
- tmp = emalloc(length);
- FP_FREAD(tmp, (long) length, socketd, fp, issock); /* skip the header */
- efree(tmp);
-}
-/* }}} */
-
-/* {{{ php_read_APP
- */
-static void php_read_APP(int socketd, FILE *fp, int issock, unsigned int marker, pval *info)
-{
- unsigned short length;
- unsigned char *buffer;
- unsigned char markername[ 16 ];
- zval *tmp;
-
- length = php_read2(socketd, fp, issock);
- length -= 2; /* length includes itself */
-
- buffer = emalloc(length);
-
- if (FP_FREAD(buffer, (long) length, socketd, fp, issock) <= 0) {
- efree(buffer);
- return;
- }
-
- sprintf(markername, "APP%d", marker - M_APP0);
-
- if (zend_hash_find(info->value.ht, markername, strlen(markername)+1, (void **) &tmp) == FAILURE) {
- /* XXX we onyl catch the 1st tag of it's kind! */
- add_assoc_stringl(info, markername, buffer, length, 1);
- }
-
- efree(buffer);
-}
-/* }}} */
-
-/* {{{ php_handle_jpeg
- main loop to parse JPEG structure */
-static struct gfxinfo *php_handle_jpeg (int socketd, FILE *fp, int issock, pval *info)
-{
- struct gfxinfo *result = NULL;
- unsigned int marker;
- char tmp[2];
- unsigned char a[4];
-
- for (;;) {
- marker = php_next_marker(socketd, fp, issock);
- 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));
- FP_FREAD(tmp, sizeof(tmp), socketd, fp, issock);
- result->bits = FP_FGETC(socketd, fp, issock);
- FP_FREAD(a, sizeof(a), socketd, fp, issock);
- result->height = (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]);
- result->width = (((unsigned short) a[ 2 ]) << 8) + ((unsigned short) a[ 3 ]);
- result->channels = FP_FGETC(socketd, fp, issock);
-
- if (! info) /* if we don't want an extanded info -> return */
- return result;
- } else {
- php_skip_variable(socketd, fp, issock);
- }
- break;
-
- case M_APP0:
- case M_APP1:
- case M_APP2:
- case M_APP3:
- case M_APP4:
- case M_APP5:
- case M_APP6:
- case M_APP7:
- case M_APP8:
- case M_APP9:
- case M_APP10:
- case M_APP11:
- case M_APP12:
- case M_APP13:
- case M_APP14:
- case M_APP15:
- if (info) {
- php_read_APP(socketd, fp, issock, marker, info); /* read all the app markes... */
- } else {
- php_skip_variable(socketd, fp, issock);
- }
- break;
-
- case M_SOS:
- case M_EOI:
- return result; /* we're about to hit image data, or are at EOF. stop processing. */
- break;
-
- default:
- php_skip_variable(socketd, fp, issock); /* anything else isn't interesting */
- break;
- }
- }
-
- return NULL;
-}
-/* }}} */
-
-/* main function */
-
-/* {{{ proto array getimagesize(string imagefile [, array info])
- Get the size of an image as 4-element array */
-PHP_FUNCTION(getimagesize)
-{
- pval **arg1, **info = 0;
- FILE *fp;
- int issock=0, socketd=0, rsrc_id;
- int itype = 0;
- char filetype[8];
- char temp[64];
- struct gfxinfo *result = NULL;
-
- switch(ZEND_NUM_ARGS()) {
-
- case 1:
- if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
- break;
-
- case 2:
- if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- zval_dtor(*info);
-
- if (array_init(*info) == FAILURE) {
- return;
- }
-
- convert_to_string_ex(arg1);
- break;
-
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- fp = php_fopen_wrapper(Z_STRVAL_PP(arg1), "rb", IGNORE_PATH|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
-
- if (!fp && !socketd) {
- if (issock != BAD_URL) {
- char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
- php_strip_url_passwd(tmp);
- php_error(E_WARNING, "getimagesize: Unable to open '%s' for reading.", tmp);
- efree(tmp);
- }
- RETURN_FALSE;
- }
-
- if (issock) {
- int *sock=emalloc(sizeof(int));
- *sock = socketd;
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, sock, php_file_le_socket());
- } else {
- rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_fopen());
- }
-
- if((FP_FREAD(filetype, 3, socketd, fp, issock)) <= 0) {
- php_error(E_WARNING, "getimagesize: Read error!");
- RETURN_FALSE;
- }
-
- if (!memcmp(filetype, php_sig_gif, 3)) {
- result = php_handle_gif (socketd, fp, issock);
- itype = 1;
- } else if (!memcmp(filetype, php_sig_jpg, 3)) {
- if (info) {
- result = php_handle_jpeg(socketd, fp, issock, *info);
- } else {
- result = php_handle_jpeg(socketd, fp, issock, NULL);
- }
- itype = 2;
- } else if (!memcmp(filetype, php_sig_png, 3)) {
- FP_FREAD(filetype+3, 5, socketd, fp, issock);
- if (!memcmp(filetype, php_sig_png, 8)) {
- result = php_handle_png(socketd, fp, issock);
- itype = 3;
- } else {
- php_error(E_WARNING, "PNG file corrupted by ASCII conversion");
- }
- } else if (!memcmp(filetype, php_sig_swf, 3)) {
- result = php_handle_swf(socketd, fp, issock);
- itype = 4;
- } else if (!memcmp(filetype, php_sig_psd, 3)) {
- result = php_handle_psd(socketd, fp, issock);
- itype = 5;
- } else if (!memcmp(filetype, php_sig_bmp, 2)) {
- result = php_handle_bmp(socketd, fp, issock);
- itype = 6;
- }
-
- zend_list_delete(rsrc_id);
-
- if (result) {
- if (array_init(return_value) == FAILURE) {
- php_error(E_ERROR, "Unable to initialize array");
- 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);
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/incomplete_class.c b/ext/standard/incomplete_class.c
deleted file mode 100644
index 246e8d556c..0000000000
--- a/ext/standard/incomplete_class.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-
-/* $Id$ */
-
-#include "php.h"
-#include "basic_functions.h"
-#include "php_incomplete_class.h"
-
-#define INCOMPLETE_CLASS_MSG \
- "The script tried to execute a method or " \
- "access a property of an incomplete object. " \
- "Please ensure that the class definition <b>%s</b> of the object " \
- "you are trying to operate on was loaded _before_ " \
- "the session was started"
-
-#define INCOMPLETE_CLASS "__PHP_Incomplete_Class"
-#define MAGIC_MEMBER "__PHP_Incomplete_Class_Name"
-
-/* {{{ incomplete_class_message
- */
-static void incomplete_class_message(zend_property_reference *ref)
-{
- char buf[1024];
- char *class_name;
-
- class_name = php_lookup_class_name(ref->object, NULL, 0);
-
- if (!class_name)
- class_name = estrdup("unknown");
-
- snprintf(buf, 1023, INCOMPLETE_CLASS_MSG, class_name);
-
- efree(class_name);
-
- php_error(E_ERROR, "%s", buf);
-}
-/* }}} */
-
-/* {{{ incomplete_class_call_func
- */
-static void incomplete_class_call_func(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference)
-{
- incomplete_class_message(property_reference);
-}
-/* }}} */
-
-/* {{{ incomplete_class_set_property
- */
-static int incomplete_class_set_property(zend_property_reference *property_reference, zval *value)
-{
- incomplete_class_message(property_reference);
-
- /* does not reach this point */
- return (0);
-}
-/* }}} */
-
-/* {{{ incomplete_class_get_property
- */
-static zval incomplete_class_get_property(zend_property_reference *property_reference)
-{
- zval foo;
-
- incomplete_class_message(property_reference);
-
- /* does not reach this point */
- memset(&foo, 0, sizeof(zval)); /* shut warnings up */
- return (foo);
-}
-/* }}} */
-
-/* {{{ php_create_incomplete_class
- */
-zend_class_entry *php_create_incomplete_class(TSRMLS_D)
-{
- zend_class_entry incomplete_class;
-
- INIT_OVERLOADED_CLASS_ENTRY(incomplete_class, INCOMPLETE_CLASS, NULL,
- incomplete_class_call_func,
- incomplete_class_get_property,
- incomplete_class_set_property);
-
- return zend_register_internal_class(&incomplete_class TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ php_lookup_class_name
- */
-char *php_lookup_class_name(zval *object, size_t *nlen, zend_bool del)
-{
- zval **val;
- char *retval = NULL;
- HashTable *object_properties;
-
- object_properties = Z_OBJPROP_P(object);
-
- if (zend_hash_find(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER), (void **) &val) == SUCCESS) {
- retval = estrndup(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
-
- if (nlen)
- *nlen = Z_STRLEN_PP(val);
-
- if (del)
- zend_hash_del(object_properties, MAGIC_MEMBER, sizeof(MAGIC_MEMBER));
- }
-
- return (retval);
-}
-/* }}} */
-
-/* {{{ php_store_class_name
- */
-void php_store_class_name(zval *object, const char *name, size_t len)
-{
- zval *val;
-
- MAKE_STD_ZVAL(val);
-
- Z_TYPE_P(val) = IS_STRING;
- Z_STRVAL_P(val) = estrndup(name, len);
- Z_STRLEN_P(val) = len;
-
- zend_hash_update(Z_OBJPROP_P(object), MAGIC_MEMBER, sizeof(MAGIC_MEMBER), &val, sizeof(val), NULL);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/info.c b/ext/standard/info.c
deleted file mode 100644
index 0fa5414a1d..0000000000
--- a/ext/standard/info.c
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_ini.h"
-#include "php_globals.h"
-#include "ext/standard/head.h"
-#include "info.h"
-#include "credits.h"
-#include "SAPI.h"
-#include <time.h>
-#if !defined(PHP_WIN32)
-#include "build-defs.h"
-#endif
-#include "zend_globals.h" /* needs ELS */
-#include "zend_highlight.h"
-
-#define SECTION(name) PUTS("<h2 align=\"center\">" name "</h2>\n")
-
-PHPAPI extern char *php_ini_opened_path;
-
-/* {{{ _display_module_info
- */
-static int _display_module_info(zend_module_entry *module, void *arg TSRMLS_DC)
-{
- int show_info_func = *((int *) arg);
-
- if (show_info_func && module->info_func) {
- php_printf("<h2 align=\"center\"><a name=\"module_%s\">%s</a></h2>\n", module->name, module->name);
- module->info_func(module TSRMLS_CC);
- } else if (!show_info_func && !module->info_func) {
- php_printf("<tr valign=\"baseline\" bgcolor=\"" PHP_CONTENTS_COLOR "\">");
- php_printf("<td>");
- php_printf("%s", module->name);
- php_printf("</td></tr>\n");
- }
- return 0;
-}
-/* }}} */
-
-/* {{{ php_print_gpcse_array
- */
-static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
-{
- zval **data, **tmp, tmp2;
- char *string_key;
- ulong num_key;
-
- if (zend_hash_find(&EG(symbol_table), name, name_length+1, (void **) &data)!=FAILURE
- && ((*data)->type==IS_ARRAY)) {
- zend_hash_internal_pointer_reset((*data)->value.ht);
- while (zend_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) {
- PUTS("<tr valign=\"baseline\" bgcolor=\"" PHP_CONTENTS_COLOR "\">");
- PUTS("<td bgcolor=\"" PHP_ENTRY_NAME_COLOR "\"><b>");
- PUTS(name);
- PUTS("[\"");
- switch (zend_hash_get_current_key((*data)->value.ht, &string_key, &num_key, 0)) {
- case HASH_KEY_IS_STRING:
- zend_html_puts(string_key, strlen(string_key));
- break;
- case HASH_KEY_IS_LONG:
- php_printf("%ld", num_key);
- break;
- }
- PUTS("\"]</b></td><td>");
- if ((*tmp)->type == IS_ARRAY) {
- PUTS("<pre>");
- zend_print_zval_r(*tmp, 0);
- PUTS("</pre>");
- } else if ((*tmp)->type != IS_STRING) {
- tmp2 = **tmp;
- zval_copy_ctor(&tmp2);
- convert_to_string(&tmp2);
- zend_html_puts(tmp2.value.str.val, tmp2.value.str.len);
- zval_dtor(&tmp2);
- } else {
- zend_html_puts((*tmp)->value.str.val, (*tmp)->value.str.len);
- }
- PUTS("&nbsp;</td></tr>\n");
- zend_hash_move_forward((*data)->value.ht);
- }
- }
-}
-/* }}} */
-
-/* {{{ php_info_print_style
- */
-void php_info_print_style(void)
-{
- php_printf("<style type=\"text/css\"><!--\n");
- php_printf("a { text-decoration: none; }\n");
- php_printf("a:hover { text-decoration: underline; }\n");
- php_printf("h1 { font-family: arial, helvetica, sans-serif; font-size: 18pt; font-weight: bold;}\n");
- php_printf("h2 { font-family: arial, helvetica, sans-serif; font-size: 14pt; font-weight: bold;}\n");
- php_printf("body, td { font-family: arial, helvetica, sans-serif; font-size: 10pt; }\n");
- php_printf("th { font-family: arial, helvetica, sans-serif; font-size: 11pt; font-weight: bold; }\n");
- php_printf("//--></style>\n");
-}
-/* }}} */
-
-/* {{{ php_get_uname
- */
-PHPAPI char *php_get_uname()
-{
- char *php_uname;
-#ifdef PHP_WIN32
- char php_windows_uname[256];
- DWORD dwBuild=0;
- DWORD dwVersion = GetVersion();
- DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
- DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
-
- /* Get build numbers for Windows NT or Win95 */
- if (dwVersion < 0x80000000){
- dwBuild = (DWORD)(HIWORD(dwVersion));
- snprintf(php_windows_uname, 255, "%s %d.%d build %d", "Windows NT", dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild);
- } else {
- snprintf(php_windows_uname, 255, "%s %d.%d", "Windows 95/98", dwWindowsMajorVersion, dwWindowsMinorVersion);
- }
- php_uname = php_windows_uname;
-#else
- php_uname=PHP_UNAME;
-#endif
- return estrdup(php_uname);
-}
-/* }}} */
-
-/* {{{ php_print_info
- */
-PHPAPI void php_print_info(int flag TSRMLS_DC)
-{
- char **env, *tmp1, *tmp2;
- char *php_uname;
- int expose_php = INI_INT("expose_php");
- time_t the_time;
- struct tm *ta, tmbuf;
-
- the_time = time(NULL);
- ta = php_localtime_r(&the_time, &tmbuf);
-
- PUTS("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n<html>\n");
-
- if (flag & PHP_INFO_GENERAL) {
- char *zend_version = get_zend_version();
-
- php_uname = php_get_uname();
- PUTS("<head>");
- php_info_print_style();
- PUTS("<title>phpinfo()</title></head><body>");
-
- php_info_print_box_start(1);
- if (expose_php) {
- PUTS("<a href=\"http://www.php.net/\"><img src=\"");
- if (SG(request_info).request_uri) {
- PUTS(SG(request_info).request_uri);
- }
- if ((ta->tm_mon==3) && (ta->tm_mday==1)) {
- PUTS("?="PHP_EGG_LOGO_GUID"\" border=0 align=\"right\" alt=\"Thies!\"></a>");
- } else {
- PUTS("?="PHP_LOGO_GUID"\" border=0 align=\"right\" alt=\"PHP Logo\"></a>");
- }
- }
- php_printf("<h1>PHP Version %s</h1>\n", PHP_VERSION);
- php_info_print_box_end();
- php_info_print_table_start();
- php_info_print_table_row(2, "System", php_uname );
- php_info_print_table_row(2, "Build Date", __DATE__ );
-#ifdef CONFIGURE_COMMAND
- php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
-#endif
- if (sapi_module.pretty_name) {
- php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
- }
-
-#ifdef VIRTUAL_DIR
- php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
-#else
- php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
-#endif
-
- php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH);
-
-#if ZEND_DEBUG
- php_info_print_table_row(2, "ZEND_DEBUG", "enabled" );
-#else
- php_info_print_table_row(2, "ZEND_DEBUG", "disabled" );
-#endif
-
-#ifdef ZTS
- php_info_print_table_row(2, "Thread Safety", "enabled" );
-#else
- php_info_print_table_row(2, "Thread Safety", "disabled" );
-#endif
-
-#if HAVE_PHP_STREAM
- php_info_print_table_row(2, "Experimental PHP Streams", "enabled");
-#endif
-
- php_info_print_table_end();
-
- /* Zend Engine */
- php_info_print_box_start(0);
- if (expose_php) {
- PUTS("<a href=\"http://www.zend.com/\"><img src=\"");
- if (SG(request_info).request_uri) {
- PUTS(SG(request_info).request_uri);
- }
- PUTS("?="ZEND_LOGO_GUID"\" border=\"0\" align=\"right\" alt=\"Zend logo\"></a>\n");
- }
- php_printf("This program makes use of the Zend Scripting Language Engine:<br>");
- zend_html_puts(zend_version, strlen(zend_version));
- php_info_print_box_end();
- efree(php_uname);
- }
-
- if ((flag & PHP_INFO_CREDITS) && expose_php) {
- php_info_print_hr();
- PUTS("<h1 align=\"center\"><a href=\"");
- if (SG(request_info).request_uri) {
- PUTS(SG(request_info).request_uri);
- }
- PUTS("?=PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000\">");
- PUTS("PHP 4.0 Credits");
- PUTS("</a></h1>\n");
- }
-
- zend_ini_sort_entries(TSRMLS_C);
-
- if (flag & PHP_INFO_CONFIGURATION) {
- php_info_print_hr();
- PUTS("<h1 align=\"center\">Configuration</h1>\n");
- SECTION("PHP Core\n");
- display_ini_entries(NULL);
- }
-
- if (flag & PHP_INFO_MODULES) {
- int show_info_func;
-
- show_info_func = 1;
- zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _display_module_info, &show_info_func TSRMLS_CC);
-
- SECTION("Additional Modules");
- php_info_print_table_start();
- show_info_func = 0;
- zend_hash_apply_with_argument(&module_registry, (apply_func_arg_t) _display_module_info, &show_info_func TSRMLS_CC);
- php_info_print_table_end();
- }
-
- if (flag & PHP_INFO_ENVIRONMENT) {
- SECTION("Environment");
- php_info_print_table_start();
- php_info_print_table_header(2, "Variable", "Value");
- for (env=environ; env!=NULL && *env !=NULL; env++) {
- tmp1 = estrdup(*env);
- if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
- efree(tmp1);
- continue;
- }
- *tmp2 = 0;
- tmp2++;
- php_info_print_table_row(2, tmp1, tmp2);
- efree(tmp1);
- }
- php_info_print_table_end();
- }
-
- if (flag & PHP_INFO_VARIABLES) {
- pval **data;
-
- SECTION("PHP Variables");
-
- php_info_print_table_start();
- php_info_print_table_header(2, "Variable", "Value");
- if (zend_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) {
- php_info_print_table_row(2, "PHP_SELF", (*data)->value.str.val);
- }
- if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) {
- php_info_print_table_row(2, "PHP_AUTH_TYPE", (*data)->value.str.val);
- }
- if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) {
- php_info_print_table_row(2, "PHP_AUTH_USER", (*data)->value.str.val);
- }
- if (zend_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) {
- php_info_print_table_row(2, "PHP_AUTH_PW", (*data)->value.str.val);
- }
- php_print_gpcse_array("_FORM", sizeof("_FORM")-1 TSRMLS_CC);
- php_print_gpcse_array("_GET", sizeof("_GET")-1 TSRMLS_CC);
- php_print_gpcse_array("_POST", sizeof("_POST")-1 TSRMLS_CC);
- php_print_gpcse_array("_FILES", sizeof("_FILES")-1 TSRMLS_CC);
- php_print_gpcse_array("_COOKIE", sizeof("_COOKIE")-1 TSRMLS_CC);
- php_print_gpcse_array("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC);
- php_print_gpcse_array("_ENV", sizeof("_ENV")-1 TSRMLS_CC);
- php_info_print_table_end();
- }
-
- if (flag & PHP_INFO_LICENSE) {
- SECTION("PHP License");
- php_info_print_box_start(0);
- PUTS("<p>\n");
- PUTS("This program is free software; you can redistribute it and/or modify ");
- PUTS("it under the terms of the PHP License as published by the PHP Group ");
- PUTS("and included in the distribution in the file: LICENSE\n");
- PUTS("</p>\n");
- PUTS("<p>");
- PUTS("This program is distributed in the hope that it will be useful, ");
- PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
- PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
- PUTS("</p>\n");
- PUTS("<p>");
- PUTS("If you did not receive a copy of the PHP license, or have any questions about ");
- PUTS("PHP licensing, please contact license@php.net.\n");
- PUTS("</p>\n");
- php_info_print_box_end();
- }
-
- PUTS("</body></html>");
-}
-/* }}} */
-
-
-PHPAPI void php_info_print_table_start()
-{
- php_printf("<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"600\" bgcolor=\"#000000\" align=\"center\">\n");
-}
-
-PHPAPI void php_info_print_table_end()
-{
- php_printf("</table><br>\n");
-
-}
-
-PHPAPI void php_info_print_box_start(int flag)
-{
- php_info_print_table_start();
- if (flag) {
- php_printf("<tr valign=\"middle\" bgcolor=\"" PHP_HEADER_COLOR "\"><td align=\"left\">\n");
- } else {
- php_printf("<tr valign=\"top\" bgcolor=\"" PHP_CONTENTS_COLOR "\"><td align=\"left\">\n");
- }
-}
-
-PHPAPI void php_info_print_box_end()
-{
- php_printf("</td></tr>\n");
- php_info_print_table_end();
-}
-
-PHPAPI void php_info_print_hr()
-{
- php_printf("<hr noshade size=\"1\" width=\"600\">\n");
-}
-
-PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header)
-{
- php_printf("<tr bgcolor=\"" PHP_HEADER_COLOR "\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
-}
-
-/* {{{ php_info_print_table_header
- */
-PHPAPI void php_info_print_table_header(int num_cols, ...)
-{
- int i;
- va_list row_elements;
- char *row_element;
-
- va_start(row_elements, num_cols);
-
- php_printf("<tr valign=\"middle\" bgcolor=\"" PHP_HEADER_COLOR "\">");
- for (i=0; i<num_cols; i++) {
- row_element = va_arg(row_elements, char *);
- if (!row_element || !*row_element) {
- row_element = "&nbsp;";
- }
- php_printf("<th>%s</th>", row_element);
- }
- php_printf("</tr>\n");
-
- va_end(row_elements);
-}
-/* }}} */
-
-/* {{{ php_info_print_table_row
- */
-PHPAPI void php_info_print_table_row(int num_cols, ...)
-{
- int i;
- va_list row_elements;
- char *row_element;
-
- va_start(row_elements, num_cols);
-
- php_printf("<tr valign=\"baseline\" bgcolor=\"" PHP_CONTENTS_COLOR "\">");
- for (i=0; i<num_cols; i++) {
- php_printf("<td %s>%s",
- (i==0?"bgcolor=\"" PHP_ENTRY_NAME_COLOR "\" ":"align=\"left\""),
- (i==0?"<b>":""));
-
- row_element = va_arg(row_elements, char *);
- if (!row_element || !*row_element) {
- php_printf("&nbsp;");
- } else {
- zend_html_puts(row_element, strlen(row_element));
- }
-
- php_printf("%s</td>", (i==0?"</b>":""));
- }
- php_printf("</tr>\n");
-
- va_end(row_elements);
-}
-/* }}} */
-
-/* {{{ register_phpinfo_constants
- */
-void register_phpinfo_constants(INIT_FUNC_ARGS)
-{
- REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_GENERAL", PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_SAPI", PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_MODULES", PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_DOCS", PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE", PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_QA", PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
- REGISTER_LONG_CONSTANT("CREDITS_ALL", PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
-}
-/* }}} */
-
-/* {{{ proto void phpinfo([int what])
- Output a page of useful information about PHP and the current request */
-PHP_FUNCTION(phpinfo)
-{
- int argc = ZEND_NUM_ARGS();
- long flag;
-
- if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
- return;
-
- if(!argc) {
- flag = 0xFFFFFFFF;
- }
-
- php_print_info(flag TSRMLS_CC);
-
- RETURN_TRUE;
-}
-
-/* }}} */
-
-/* {{{ proto string phpversion(void)
- Return the current PHP version */
-PHP_FUNCTION(phpversion)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRING(PHP_VERSION, 1);
-}
-/* }}} */
-
-/* {{{ proto void phpcredits([int flag])
- Prints the list of people who've contributed to the PHP project */
-PHP_FUNCTION(phpcredits)
-{
- int argc = ZEND_NUM_ARGS();
- long flag;
-
- if (zend_parse_parameters(argc, "|l", &flag) == FAILURE)
- return;
-
- if(!argc) {
- flag = 0xFFFFFFFF;
- }
-
- php_print_credits(flag);
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto string php_logo_guid(void)
- Return the special ID used to request the PHP logo in phpinfo screens*/
-PHP_FUNCTION(php_logo_guid)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRINGL(PHP_LOGO_GUID, sizeof(PHP_LOGO_GUID)-1, 1);
-}
-/* }}} */
-
-/* {{{ proto string php_egg_logo_guid(void)
- Return the special ID used to request the PHP logo in phpinfo screens*/
-PHP_FUNCTION(php_egg_logo_guid)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRINGL(PHP_EGG_LOGO_GUID, sizeof(PHP_EGG_LOGO_GUID)-1, 1);
-}
-/* }}} */
-
-/* {{{ proto string zend_logo_guid(void)
- Return the special ID used to request the Zend logo in phpinfo screens*/
-PHP_FUNCTION(zend_logo_guid)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRINGL(ZEND_LOGO_GUID, sizeof(ZEND_LOGO_GUID)-1, 1);
-}
-/* }}} */
-
-/* {{{ proto string php_sapi_name(void)
- Return the current SAPI module name */
-PHP_FUNCTION(php_sapi_name)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- if (sapi_module.name) {
- RETURN_STRING(sapi_module.name, 1);
- } else {
- RETURN_FALSE;
- }
-}
-
-/* }}} */
-
-/* {{{ proto string php_uname(void)
- Return information about the system PHP was built on */
-PHP_FUNCTION(php_uname)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- RETURN_STRING(php_get_uname(), 0);
-}
-
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/info.h b/ext/standard/info.h
deleted file mode 100644
index e18fba16b0..0000000000
--- a/ext/standard/info.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef INFO_H
-#define INFO_H
-
-#define PHP_ENTRY_NAME_COLOR "#ccccff"
-#define PHP_CONTENTS_COLOR "#cccccc"
-#define PHP_HEADER_COLOR "#9999cc"
-
-#define PHP_INFO_GENERAL (1<<0)
-#define PHP_INFO_CREDITS (1<<1)
-#define PHP_INFO_CONFIGURATION (1<<2)
-#define PHP_INFO_MODULES (1<<3)
-#define PHP_INFO_ENVIRONMENT (1<<4)
-#define PHP_INFO_VARIABLES (1<<5)
-#define PHP_INFO_LICENSE (1<<6)
-#define PHP_INFO_ALL 0xFFFFFFFF
-
-#ifndef HAVE_CREDITS_DEFS
-#define HAVE_CREDITS_DEFS
-
-#define PHP_CREDITS_GROUP (1<<0)
-#define PHP_CREDITS_GENERAL (1<<1)
-#define PHP_CREDITS_SAPI (1<<2)
-#define PHP_CREDITS_MODULES (1<<3)
-#define PHP_CREDITS_DOCS (1<<4)
-#define PHP_CREDITS_FULLPAGE (1<<5)
-#define PHP_CREDITS_QA (1<<6)
-#define PHP_CREDITS_WEB (1<<7)
-#define PHP_CREDITS_ALL 0xFFFFFFFF
-
-#endif /* HAVE_CREDITS_DEFS */
-
-#define PHP_LOGO_GUID "PHPE9568F34-D428-11d2-A769-00AA001ACF42"
-#define PHP_EGG_LOGO_GUID "PHPE9568F36-D428-11d2-A769-00AA001ACF42"
-#define ZEND_LOGO_GUID "PHPE9568F35-D428-11d2-A769-00AA001ACF42"
-#define PHP_CREDITS_GUID "PHPB8B5F2A0-3C92-11d3-A3A9-4C7B08C10000"
-
-PHP_FUNCTION(phpversion);
-PHP_FUNCTION(phpinfo);
-PHP_FUNCTION(phpcredits);
-PHP_FUNCTION(php_logo_guid);
-PHP_FUNCTION(zend_logo_guid);
-PHP_FUNCTION(php_egg_logo_guid);
-PHP_FUNCTION(php_sapi_name);
-PHP_FUNCTION(php_uname);
-PHPAPI void php_print_info(int flag TSRMLS_DC);
-PHPAPI void php_print_style(void);
-PHPAPI void php_info_print_style(void);
-PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header);
-PHPAPI void php_info_print_table_header(int num_cols, ...);
-PHPAPI void php_info_print_table_row(int num_cols, ...);
-PHPAPI void php_info_print_table_start(void);
-PHPAPI void php_info_print_table_end(void);
-PHPAPI void php_info_print_box_start(int bg);
-PHPAPI void php_info_print_box_end(void);
-PHPAPI void php_info_print_hr(void);
-
-void register_phpinfo_constants(INIT_FUNC_ARGS);
-
-#endif /* INFO_H */
diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c
deleted file mode 100644
index e828e5338a..0000000000
--- a/ext/standard/iptc.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/*
- * Functions to parse & compse IPTC data.
- * PhotoShop >= 3.0 can read and write textual data to JPEG files.
- * ... more to come .....
- *
- * i know, parts of this is now duplicated in image.c
- * but in this case i think it's okay!
- */
-
-/*
- * TODO:
- * - add IPTC translation table
- */
-
-#include "php.h"
-#include "php_iptc.h"
-#include "ext/standard/head.h"
-
-#include <sys/stat.h>
-
-
-/* some defines for the different JPEG block types */
-#define M_SOF0 0xC0 /* Start Of Frame N */
-#define M_SOF1 0xC1 /* N indicates which compression process */
-#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
-#define M_SOF3 0xC3
-#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
-#define M_SOF6 0xC6
-#define M_SOF7 0xC7
-#define M_SOF9 0xC9
-#define M_SOF10 0xCA
-#define M_SOF11 0xCB
-#define M_SOF13 0xCD
-#define M_SOF14 0xCE
-#define M_SOF15 0xCF
-#define M_SOI 0xD8
-#define M_EOI 0xD9 /* End Of Image (end of datastream) */
-#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
-#define M_APP0 0xe0
-#define M_APP1 0xe1
-#define M_APP2 0xe2
-#define M_APP3 0xe3
-#define M_APP4 0xe4
-#define M_APP5 0xe5
-#define M_APP6 0xe6
-#define M_APP7 0xe7
-#define M_APP8 0xe8
-#define M_APP9 0xe9
-#define M_APP10 0xea
-#define M_APP11 0xeb
-#define M_APP12 0xec
-#define M_APP13 0xed
-#define M_APP14 0xee
-#define M_APP15 0xef
-
-/* {{{ php_iptc_put1
- */
-static int php_iptc_put1(FILE *fp, int spool, unsigned char c, unsigned char **spoolbuf TSRMLS_DC)
-{
- if (spool > 0)
- PUTC(c);
-
- if (spoolbuf) *(*spoolbuf)++ = c;
-
- return c;
-}
-/* }}} */
-
-/* {{{ php_iptc_get1
- */
-static int php_iptc_get1(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC)
-{
- int c;
- char cc;
-
- c = getc(fp);
-
- if (c == EOF) return EOF;
-
- if (spool > 0) {
- cc = c;
- PUTC(cc);
- }
-
- if (spoolbuf) *(*spoolbuf)++ = c;
-
- return c;
-}
-/* }}} */
-
-/* {{{ php_iptc_read_remaining
- */
-static int php_iptc_read_remaining(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC)
-{
- int c;
-
- while ((c = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) != EOF) continue;
-
- return M_EOI;
-}
-/* }}} */
-
-/* {{{ php_iptc_skip_variable
- */
-static int php_iptc_skip_variable(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC)
-{
- unsigned int length;
- int c1, c2;
-
- if ((c1 = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF) return M_EOI;
-
- if ((c2 = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF) return M_EOI;
-
- length = (((unsigned char) c1) << 8) + ((unsigned char) c2);
-
- length -= 2;
-
- while (length--)
- if (php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC) == EOF) return M_EOI;
-
- return 0;
-}
-/* }}} */
-
-/* {{{ php_iptc_next_marker
- */
-static int php_iptc_next_marker(FILE *fp, int spool, unsigned char **spoolbuf TSRMLS_DC)
-{
- int c;
-
- /* skip unimportant stuff */
-
- c = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC);
-
- if (c == EOF) return M_EOI;
-
- while (c != 0xff) {
- if ((c = php_iptc_get1(fp, spool, spoolbuf TSRMLS_CC)) == EOF)
- return M_EOI; /* we hit EOF */
- }
-
- /* get marker byte, swallowing possible padding */
- do {
- c = php_iptc_get1(fp, 0, 0 TSRMLS_CC);
- if (c == EOF)
- return M_EOI; /* we hit EOF */
- else
- if (c == 0xff)
- php_iptc_put1(fp, spool, (unsigned char)c, spoolbuf TSRMLS_CC);
- } while (c == 0xff);
-
- return (unsigned int) c;
-}
-/* }}} */
-
-static char psheader[] = "\xFF\xED\0\0Photoshop 3.0\08BIM\x04\x04\0\0\0\0";
-
-/* {{{ proto array iptcembed(string iptcdata, string jpeg_file_name [, int spool])
- Embed binary IPTC data into a JPEG image. */
-PHP_FUNCTION(iptcembed)
-{
- zval **iptcdata, **jpeg_file, **spool_flag;
- FILE *fp;
- unsigned int marker;
- unsigned int spool = 0, done = 0, inx, len;
- unsigned char *spoolbuf=0, *poi=0;
- struct stat sb;
-
- switch(ZEND_NUM_ARGS()){
- case 3:
- if (zend_get_parameters_ex(3, &iptcdata, &jpeg_file, &spool_flag) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(iptcdata);
- convert_to_string_ex(jpeg_file);
- convert_to_long_ex(spool_flag);
- spool = (*spool_flag)->value.lval;
- break;
-
- case 2:
- if (zend_get_parameters_ex(2, &iptcdata, &jpeg_file) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(iptcdata);
- convert_to_string_ex(jpeg_file);
- break;
-
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- if (php_check_open_basedir((*jpeg_file)->value.str.val TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- if ((fp = VCWD_FOPEN((*jpeg_file)->value.str.val, "rb")) == 0) {
- php_error(E_WARNING, "Unable to open %s", (*jpeg_file)->value.str.val);
- RETURN_FALSE;
- }
-
- len = (*iptcdata)->value.str.len;
-
- if (spool < 2) {
- fstat(fileno(fp), &sb);
-
- poi = spoolbuf = emalloc(len + sizeof(psheader) + sb.st_size + 1024);
-
- if (! spoolbuf) {
- fclose(fp);
- RETURN_FALSE;
- }
- }
-
- if (php_iptc_get1(fp, spool, poi?&poi:0 TSRMLS_CC) != 0xFF) {
- fclose(fp);
- RETURN_FALSE;
- }
-
- if (php_iptc_get1(fp, spool, poi?&poi:0 TSRMLS_CC) != 0xD8) {
- fclose(fp);
- RETURN_FALSE;
- }
-
- while (!done) {
- marker = php_iptc_next_marker(fp, spool, poi?&poi:0 TSRMLS_CC);
-
- if (marker == M_EOI) { /* EOF */
- break;
- } else if (marker != M_APP13) {
- php_iptc_put1(fp, spool, (unsigned char)marker, poi?&poi:0 TSRMLS_CC);
- }
-
- switch (marker) {
- case M_APP13:
- /* we are going to write a new APP13 marker, so don't output the old one */
- php_iptc_skip_variable(fp, 0, 0 TSRMLS_CC);
- php_iptc_read_remaining(fp, spool, poi?&poi:0 TSRMLS_CC);
- done = 1;
- break;
-
- case M_APP0:
- /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */
- php_iptc_skip_variable(fp, spool, poi?&poi:0 TSRMLS_CC);
-
- if (len & 1) len++; /* make the length even */
-
- psheader[ 2 ] = (len+28)>>8;
- psheader[ 3 ] = (len+28)&0xff;
-
- for (inx = 0; inx < 28; inx++)
- php_iptc_put1(fp, spool, psheader[inx], poi?&poi:0 TSRMLS_CC);
-
- php_iptc_put1(fp, spool, (unsigned char)(len>>8), poi?&poi:0 TSRMLS_CC);
- php_iptc_put1(fp, spool, (unsigned char)(len&0xff), poi?&poi:0 TSRMLS_CC);
-
- for (inx = 0; inx < len; inx++)
- php_iptc_put1(fp, spool, (*iptcdata)->value.str.val[inx], poi?&poi:0 TSRMLS_CC);
- break;
-
- case M_SOS:
- /* we hit data, no more marker-inserting can be done! */
- php_iptc_read_remaining(fp, spool, poi?&poi:0 TSRMLS_CC);
- done = 1;
- break;
-
- default:
- php_iptc_skip_variable(fp, spool, poi?&poi:0 TSRMLS_CC);
- break;
- }
- }
-
- fclose(fp);
-
- if (spool < 2) {
- RETVAL_STRINGL(spoolbuf, poi - spoolbuf, 0);
- } else {
- RETURN_TRUE;
- }
-}
-/* }}} */
-
-/* {{{ proto array iptcparse(string iptcdata)
- Parse binary IPTC-data into associative array */
-PHP_FUNCTION(iptcparse)
-{
- unsigned int length, inx, len, inheader, tagsfound;
- unsigned char *buffer;
- unsigned char recnum, dataset;
- unsigned char key[ 16 ];
- zval *values, **str, **element;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- inx = 0;
- length = (*str)->value.str.len;
- buffer = (*str)->value.str.val;
-
- inheader = 0; /* have we already found the IPTC-Header??? */
- tagsfound = 0; /* number of tags already found */
-
- while (inx < length) { /* find 1st tag */
- if ((buffer[inx] == 0x1c) && (buffer[inx+1] == 0x02)){
- break;
- } else {
- inx++;
- }
- }
-
- while (inx < length) {
- if (buffer[ inx++ ] != 0x1c) {
- break; /* we ran against some data which does not conform to IPTC - stop parsing! */
- }
-
- if ((inx + 4) >= length)
- break;
-
- dataset = buffer[ inx++ ];
- recnum = buffer[ inx++ ];
-
- if (buffer[ inx ] & (unsigned char) 0x80) { /* long tag */
- len = (((long) buffer[ inx + 2 ]) << 24) + (((long) buffer[ inx + 3 ]) << 16) +
- (((long) buffer[ inx + 4 ]) << 8) + (((long) buffer[ inx + 5 ]));
- inx += 6;
- } else { /* short tag */
- len = (((unsigned short) buffer[ inx ])<<8) | (unsigned short)buffer[ inx+1 ];
- inx += 2;
- }
-
- sprintf(key, "%d#%03d", (unsigned int) dataset, (unsigned int) recnum);
-
- if ((len > length) || (inx + len) > length)
- break;
-
- if (tagsfound == 0) { /* found the 1st tag - initialize the return array */
- if (array_init(return_value) == FAILURE) {
- php_error(E_ERROR, "Unable to initialize array");
- RETURN_FALSE;
- }
- }
-
- if (zend_hash_find(return_value->value.ht, key, strlen(key) + 1, (void **) &element) == FAILURE) {
- ALLOC_ZVAL(values);
- INIT_PZVAL(values);
- if (array_init(values) == FAILURE) {
- php_error(E_ERROR, "Unable to initialize array");
- RETURN_FALSE;
- }
-
- zend_hash_update(return_value->value.ht, key, strlen(key)+1, (void *) &values, sizeof(pval*), (void **) &element);
- }
-
- add_next_index_stringl(*element, buffer+inx, len, 1);
-
- inx += len;
-
- tagsfound++;
- }
-
- if (! tagsfound) {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/lcg.c b/ext/standard/lcg.c
deleted file mode 100644
index 7ae45a0ef0..0000000000
--- a/ext/standard/lcg.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#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;
-static int php_lcg_initialized = 0;
-#endif
-
-
-#ifdef PHP_WIN32
-#include <process.h>
-#endif
-
-/*
- * combinedLCG() returns a pseudo random number in the range of (0, 1).
- * The function combines two CGs with periods of
- * 2^31 - 85 and 2^31 - 249. The period of this function
- * is equal to the product of both primes.
- */
-
-#define MODMULT(a, b, c, m, s) q = s/a;s=b*(s-a*q)-c*q;if(s<0)s+=m
-
-double php_combined_lcg(TSRMLS_D)
-{
- php_int32 q;
- php_int32 z;
-
- MODMULT(53668, 40014, 12211, 2147483563L, LCG(s1));
- MODMULT(52774, 40692, 3791, 2147483399L, LCG(s2));
-
- z = LCG(s1) - LCG(s2);
- if(z < 1) {
- z += 2147483562;
- }
-
- return z * 4.656613e-10;
-}
-
-static void lcg_init_globals(php_lcg_globals *lcg_globals_p TSRMLS_DC)
-{
- LCG(s1) = 1;
-#ifdef ZTS
- LCG(s2) = (long) tsrm_thread_id();
-#else
- LCG(s2) = (long) getpid();
-#endif
-}
-
-#ifdef ZTS
-PHP_MINIT_FUNCTION(lcg)
-{
- ts_allocate_id(&lcg_globals_id, sizeof(php_lcg_globals), (ts_allocate_ctor) lcg_init_globals, NULL);
- return SUCCESS;
-}
-#else
-PHP_RINIT_FUNCTION(lcg)
-{
- if (!php_lcg_initialized) {
- lcg_init_globals(&lcg_globals TSRMLS_CC);
- php_lcg_initialized = 1;
- }
- return SUCCESS;
-}
-#endif
-
-/* {{{ proto double lcg_value()
- Returns a value from the combined linear congruential generator */
-PHP_FUNCTION(lcg_value)
-{
- RETURN_DOUBLE(php_combined_lcg(TSRMLS_C));
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/levenshtein.c b/ext/standard/levenshtein.c
deleted file mode 100644
index a8c25986e7..0000000000
--- a/ext/standard/levenshtein.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Hartmut Holzgraefe <hartmut@six.de> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
-#include "php_string.h"
-
-#define LEVENSHTEIN_MAX_LENTH 255
-
-/* {{{ reference_levdist
- * reference implementation, only optimized for memory usage, not speed */
-static int reference_levdist(const char *s1, int l1,
- const char *s2, int l2,
- int cost_ins, int cost_rep, int cost_del )
-{
- int *p1, *p2, *tmp;
- int i1, i2, c0, c1, c2;
-
- if(l1==0) return l2*cost_ins;
- if(l2==0) return l1*cost_del;
-
- if((l1>LEVENSHTEIN_MAX_LENTH)||(l2>LEVENSHTEIN_MAX_LENTH))
- return -1;
-
- if(!(p1=emalloc(l2*sizeof(int)))) {
- return -2;
- }
- if(!(p2=emalloc(l2*sizeof(int)))) {
- free(p1);
- return -2;
- }
-
- p1[0]=(s1[0]==s2[0])?0:cost_rep;
-
- for(i2=1;i2<l2;i2++)
- p1[i2]=i2*cost_ins;
-
- for(i1=1;i1<l1;i1++)
- {
- p2[0]=i1*cost_del;
- for(i2=1;i2<l2;i2++)
- {
- c0=p1[i2-1]+((s1[i1]==s2[i2])?0:cost_rep);
- c1=p1[i2]+cost_del; if(c1<c0) c0=c1;
- c2=p2[i2-1]+cost_ins; if(c2<c0) c0=c2;
- p2[i2]=c0;
- }
- tmp=p1; p1=p2; p2=tmp;
- }
-
- c0=p1[l2-1];
-
- efree(p1);
- efree(p2);
-
- return c0;
-}
-/* }}} */
-
-/* {{{ custom_levdist
- */
-static int custom_levdist(char *str1, char *str2, char *callback_name)
-{
- php_error(E_WARNING, "the general Levenshtein support is not there yet");
- /* not there yet */
-
- return -1;
-}
-/* }}} */
-
-/* {{{ proto int levenshtein(string str1, string str2)
- Calculate Levenshtein distance between two strings */
-PHP_FUNCTION(levenshtein)
-{
- zval **str1, **str2, **cost_ins, **cost_rep, **cost_del, **callback_name;
- int distance=-1;
-
- switch(ZEND_NUM_ARGS()) {
- case 2: /* just two string: use maximum performance version */
- if (zend_get_parameters_ex(2, &str1, &str2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str1);
- convert_to_string_ex(str2);
-
- distance = reference_levdist((*str1)->value.str.val, (*str1)->value.str.len,
- (*str2)->value.str.val, (*str2)->value.str.len,
- 1, 1, 1);
-
- break;
-
- case 5: /* more general version: calc cost by ins/rep/del weights */
- if (zend_get_parameters_ex(5, &str1, &str2, &cost_ins, &cost_rep, &cost_del) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str1);
- convert_to_string_ex(str2);
- convert_to_long_ex(cost_ins);
- convert_to_long_ex(cost_rep);
- convert_to_long_ex(cost_del);
-
- distance = reference_levdist((*str1)->value.str.val, (*str1)->value.str.len,
- (*str2)->value.str.val, (*str2)->value.str.len,
- (*cost_ins)->value.lval,
- (*cost_rep)->value.lval,
- (*cost_del)->value.lval
- );
-
- break;
-
- case 3: /* most general version: calc cost by user-supplied function */
- if (zend_get_parameters_ex(3, &str1, &str2, &callback_name) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str1);
- convert_to_string_ex(str2);
- convert_to_string_ex(callback_name);
-
- distance = custom_levdist((*str1)->value.str.val
- , (*str2)->value.str.val
- , (*callback_name)->value.str.val
- );
- break;
-
- default:
- WRONG_PARAM_COUNT;
- }
-
- if(distance<0) {
- php_error(E_WARNING, "levenshtein(): argument string(s) too long");
- }
-
- RETURN_LONG(distance);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/link.c b/ext/standard/link.c
deleted file mode 100644
index 69b28ba9c6..0000000000
--- a/ext/standard/link.c
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_filestat.h"
-#include "php_globals.h"
-
-#ifdef HAVE_SYMLINK
-
-#include <stdlib.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <sys/stat.h>
-#include <string.h>
-#if HAVE_PWD_H
-#ifdef PHP_WIN32
-#include "win32/pwd.h"
-#else
-#include <pwd.h>
-#endif
-#endif
-#if HAVE_GRP_H
-#ifdef PHP_WIN32
-#include "win32/grp.h"
-#else
-#include <grp.h>
-#endif
-#endif
-#include <errno.h>
-#include <ctype.h>
-
-#include "safe_mode.h"
-#include "php_link.h"
-
-/* {{{ proto string readlink(string filename)
- Return the target of a symbolic link */
-PHP_FUNCTION(readlink)
-{
- pval **filename;
- char buff[256];
- int ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- ret = readlink((*filename)->value.str.val, buff, 255);
- if (ret == -1) {
- php_error(E_WARNING, "readlink failed (%s)", strerror(errno));
- RETURN_FALSE;
- }
- /* Append NULL to the end of the string */
- buff[ret] = '\0';
- RETURN_STRING(buff, 1);
-}
-/* }}} */
-
-/* {{{ proto int linkinfo(string filename)
- Returns the st_dev field of the UNIX C stat structure describing the link */
-PHP_FUNCTION(linkinfo)
-{
- pval **filename;
- struct stat sb;
- int ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(filename);
-
- ret = VCWD_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);
-}
-/* }}} */
-
-/* {{{ proto int symlink(string target, string link)
- Create a symbolic link */
-PHP_FUNCTION(symlink)
-{
- pval **topath, **frompath;
- int ret;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &topath, &frompath) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(topath);
- convert_to_string_ex(frompath);
-
- if (PG(safe_mode) && !php_checkuid((*topath)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR)) {
- 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;
-}
-/* }}} */
-
-/* {{{ proto int link(string target, string link)
- Create a hard link */
-PHP_FUNCTION(link)
-{
- pval **topath, **frompath;
- int ret;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &topath, &frompath) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(topath);
- convert_to_string_ex(frompath);
-
- if (PG(safe_mode) && !php_checkuid((*topath)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR)) {
- 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
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
deleted file mode 100644
index 3e37ca8336..0000000000
--- a/ext/standard/mail.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdio.h>
-#include "php.h"
-#include "ext/standard/info.h"
-#if !defined(PHP_WIN32)
-#include "build-defs.h"
-#if HAVE_SYSEXITS_H
-#include <sysexits.h>
-#endif
-#if HAVE_SYS_SYSEXITS_H
-#include <sys/sysexits.h>
-#endif
-#endif
-#include "php_mail.h"
-#include "php_ini.h"
-#include "safe_mode.h"
-#include "exec.h"
-
-#if HAVE_SENDMAIL
-#ifdef PHP_WIN32
-#include "win32/sendmail.h"
-#endif
-
-/* {{{ proto int ezmlm_hash(string addr)
- Calculate EZMLM list hash value. */
-PHP_FUNCTION(ezmlm_hash)
-{
- pval **pstr = NULL;
- char *str=NULL;
- unsigned long h = 5381L;
- int j, l;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &pstr) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(pstr);
- if ((*pstr)->value.str.val) {
- str = (*pstr)->value.str.val;
- } else {
- php_error(E_WARNING, "Must give string parameter to ezmlm_hash()");
- RETURN_FALSE;
- }
-
- l = strlen(str);
- for (j=0; j<l; j++) {
- h = (h + (h<<5)) ^ (unsigned long) (unsigned char) tolower(str[j]);
- }
-
- h = (h%53);
-
- RETURN_LONG((int) h);
-}
-/* }}} */
-
-/* {{{ proto int mail(string to, string subject, string message [, string additional_headers [, string additional_parameters]])
- Send an email message */
-PHP_FUNCTION(mail)
-{
- pval **argv[5];
- char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *extra_cmd=NULL;
- int argc;
-
- argc = ZEND_NUM_ARGS();
- if (argc < 3 || argc > 5 || zend_get_parameters_array_ex(argc, argv) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* To: */
- convert_to_string_ex(argv[0]);
- if ((*argv[0])->value.str.val) {
- to = (*argv[0])->value.str.val;
- } else {
- php_error(E_WARNING, "No to field in mail command");
- RETURN_FALSE;
- }
-
- /* Subject: */
- convert_to_string_ex(argv[1]);
- if ((*argv[1])->value.str.val) {
- subject = Z_STRVAL_PP(argv[1]);
- } 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 = Z_STRVAL_PP(argv[2]);
- } 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 = Z_STRVAL_PP(argv[3]);
- }
-
- if (argc == 5) { /* extra options that get passed to the mailer */
- convert_to_string_ex(argv[4]);
- extra_cmd = php_escape_shell_arg(Z_STRVAL_PP(argv[4]));
- }
-
- if (php_mail(to, subject, message, headers, extra_cmd)) {
- RETVAL_TRUE;
- } else {
- RETVAL_FALSE;
- }
- if (extra_cmd) efree (extra_cmd);
-}
-/* }}} */
-
-/* {{{ php_mail
- */
-PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd)
-{
-#ifdef PHP_WIN32
- int tsm_err;
-#endif
- FILE *sendmail;
- int ret;
- char *sendmail_path = INI_STR("sendmail_path");
- char *sendmail_cmd = NULL;
-
- if (!sendmail_path) {
-#ifdef PHP_WIN32
- /* handle old style win smtp sending */
- if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
- php_error(E_WARNING, GetSMErrorText(tsm_err));
- return 0;
- }
- return 1;
-#else
- return 0;
-#endif
- }
- if (extra_cmd != NULL) {
- sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2);
- strcpy (sendmail_cmd, sendmail_path);
- strcat (sendmail_cmd, " ");
- strcat (sendmail_cmd, extra_cmd);
- } else {
- sendmail_cmd = sendmail_path;
- }
-
-#ifdef PHP_WIN32
- sendmail = popen(sendmail_cmd, "wb");
-#else
- sendmail = popen(sendmail_cmd, "w");
-#endif
- if (extra_cmd != NULL)
- efree (sendmail_cmd);
-
- 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);
-#ifdef PHP_WIN32
- if (ret == -1)
-#else
-#if defined(EX_TEMPFAIL)
- if ((ret != EX_OK)&&(ret != EX_TEMPFAIL))
-#else
- if (ret != EX_OK)
-#endif
-#endif
- {
- return 0;
- } else {
- return 1;
- }
- } else {
- php_error(E_WARNING, "Could not execute mail delivery program");
- return 0;
- }
- return 1;
-}
-/* }}} */
-
-/* {{{ PHP_MINFO_FUNCTION
- */
-PHP_MINFO_FUNCTION(mail)
-{
- char *sendmail_path = INI_STR("sendmail_path");
-
-#ifdef PHP_WIN32
- if (!sendmail_path) {
- php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled");
- } else {
- php_info_print_table_row(2, "Path to sendmail", sendmail_path);
- }
-#else
- php_info_print_table_row(2, "Path to sendmail", sendmail_path);
-#endif
-}
-/* }}} */
-
-#else
-
-PHP_FUNCTION(mail) {}
-PHP_MINFO_FUNCTION(mail) {}
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/math.c b/ext/standard/math.c
deleted file mode 100644
index 678f737759..0000000000
--- a/ext/standard/math.c
+++ /dev/null
@@ -1,1067 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jim Winstead (jimw@php.net) |
- | Stig Sæther Bakken <ssb@guardian.no> |
- | Zeev Suraski <zeev@zend.com> |
- | PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "php_math.h"
-
-#include <math.h>
-#include <float.h>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-
-char *_php_math_number_format(double, int, char , char);
-
-/* {{{ proto int abs(int number)
- Return the absolute value of the number */
-PHP_FUNCTION(abs)
-{
- zval **value;
-
- if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_scalar_to_number_ex(value);
-
- if (Z_TYPE_PP(value) == IS_DOUBLE) {
- RETURN_DOUBLE(fabs(Z_DVAL_PP(value)));
- } else if (Z_TYPE_PP(value) == IS_LONG) {
- if (Z_LVAL_PP(value) == LONG_MIN) {
- RETURN_DOUBLE(-(double)LONG_MIN);
- } else {
- RETURN_LONG(Z_LVAL_PP(value) < 0 ? -Z_LVAL_PP(value) : Z_LVAL_PP(value));
- }
- }
-
- RETURN_FALSE;
-}
-
-/* }}} */
-/* {{{ proto double ceil(double number)
- Returns the next highest integer value of the number */
-PHP_FUNCTION(ceil)
-{
- zval **value;
-
- if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_scalar_to_number_ex(value);
-
- if (Z_TYPE_PP(value) == IS_DOUBLE) {
- RETURN_DOUBLE(ceil(Z_DVAL_PP(value)));
- } else if (Z_TYPE_PP(value) == IS_LONG) {
- RETURN_LONG(Z_LVAL_PP(value));
- }
-
- RETURN_FALSE;
-}
-
-/* }}} */
-/* {{{ proto double floor(double number)
- Returns the next lowest integer value from the number */
-
-PHP_FUNCTION(floor)
-{
- zval **value;
-
- if (ZEND_NUM_ARGS()!=1||zend_get_parameters_ex(1, &value)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_scalar_to_number_ex(value);
-
- if (Z_TYPE_PP(value) == IS_DOUBLE) {
- RETURN_DOUBLE(floor(Z_DVAL_PP(value)));
- } else if (Z_TYPE_PP(value) == IS_LONG) {
- RETURN_LONG(Z_LVAL_PP(value));
- }
-
- RETURN_FALSE;
-}
-
-/* }}} */
-
-
-/* {{{ proto double round(double number [, int precision])
- Returns the number rounded to specified precision. */
-PHP_FUNCTION(round)
-{
- zval **value, **precision;
- int places = 0;
- double f, return_val;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &value, &precision) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (ZEND_NUM_ARGS() == 2) {
- convert_to_long_ex(precision);
- places = (int) Z_LVAL_PP(precision);
- }
-
- convert_scalar_to_number_ex(value);
-
- switch (Z_TYPE_PP(value)) {
- case IS_LONG:
- /* Simple case - long that doesn't need to be rounded. */
- if (places >= 0) {
- RETURN_DOUBLE((double) Z_LVAL_PP(value));
- }
- /* break omitted intentionally */
-
- case IS_DOUBLE:
- return_val = (Z_TYPE_PP(value) == IS_LONG) ?
- (double)Z_LVAL_PP(value) : Z_DVAL_PP(value);
-
- f = pow(10.0, places);
-
- return_val *= f;
- if (return_val >= 0.0)
- return_val = floor(return_val + 0.5);
- else
- return_val = ceil(return_val - 0.5);
- return_val /= f;
-
- RETURN_DOUBLE(return_val);
- break;
-
- default:
- RETURN_FALSE;
- break;
- }
-}
-/* }}} */
-/* {{{ proto double sin(double number)
- Returns the sine of the number in radians */
-
-PHP_FUNCTION(sin)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = sin(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double cos(double number)
- Returns the cosine of the number in radians */
-
-PHP_FUNCTION(cos)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = cos(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-/* }}} */
-/* {{{ proto double tan(double number)
- Returns the tangent of the number in radians */
-PHP_FUNCTION(tan)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = tan(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double asin(double number)
- Returns the arc sine of the number in radians */
-
-PHP_FUNCTION(asin)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = asin(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double acos(double number)
- Return the arc cosine of the number in radians */
-
-PHP_FUNCTION(acos)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = acos(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double atan(double number)
- Returns the arc tangent of the number in radians */
-
-PHP_FUNCTION(atan)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = atan(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double atan2(double y, double x)
- Returns the arc tangent of y/x, with the resulting quadrant determined by the signs of y and x */
-
-PHP_FUNCTION(atan2)
-{
- zval **num1, **num2;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &num1, &num2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num1);
- convert_to_double_ex(num2);
- Z_DVAL_P(return_value) = atan2(Z_DVAL_PP(num1), Z_DVAL_PP(num2));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double sinh(double number)
- Returns the hyperbolic sine of the number,
- defined as (exp(number) - exp(-number))/2 */
-
-PHP_FUNCTION(sinh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = sinh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double cosh(double number)
- Returns the hyperbolic cosine of the number,
- defined as (exp(number) + exp(-number))/2 */
-
-PHP_FUNCTION(cosh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = cosh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-/* }}} */
-/* {{{ proto double tanh(double number)
- Returns the hyperbolic tangent of the number,
- defined as sinh(number)/cosh(number) */
-PHP_FUNCTION(tanh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = tanh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-#ifndef PHP_WIN32
-/* {{{ proto double asinh(double number)
- Returns the inverse hyperbolic sine of the number,
- i.e. the value whose hyperbolic sine is number */
-
-PHP_FUNCTION(asinh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = asinh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double acosh(double number)
- Returns the inverse hyperbolic cosine of the number,
- i.e. the value whose hyperbolic cosine is number */
-
-PHP_FUNCTION(acosh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = acosh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double atanh(double number)
- Returns the inverse hyperbolic tangent of the number,
- i.e. the value whose hyperbolic tangent is number */
-
-PHP_FUNCTION(atanh)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = atanh(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-#endif
-
-/* {{{ proto double pi(void)
- Returns an approximation of pi */
-
-PHP_FUNCTION(pi)
-{
- Z_DVAL_P(return_value) = M_PI;
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-/* {{{ proto number pow(number base, number exponent)
- Returns base raised to the power of exponent. Returns
- integer result when possible. */
-
-PHP_FUNCTION(pow)
-{
- /* FIXME: What is our policy on float-overflow? With pow, it's
- * extremely easy to request results that won't fit in any double.
- */
-
- zval **zbase, **zexp;
- long lbase, lexp;
- double dval;
-
- if (ZEND_NUM_ARGS() != 2) {
- WRONG_PARAM_COUNT;
- }
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &zbase, &zexp);
- convert_scalar_to_number_ex(zbase);
- convert_scalar_to_number_ex(zexp);
- if ((Z_TYPE_PP(zbase) != IS_LONG && Z_TYPE_PP(zbase) != IS_DOUBLE) ||
- (Z_TYPE_PP(zexp ) != IS_LONG && Z_TYPE_PP(zexp ) != IS_DOUBLE)) {
- php_error(E_WARNING, "Invalid argument(s) passed to pow()");
- RETURN_FALSE;
- }
-
- if (Z_TYPE_PP(zexp) == IS_DOUBLE) {
- /* pow(?, float), this is the ^^ case */
- convert_to_double_ex(zbase);
-
- if ( Z_DVAL_PP(zbase) <= 0.0 ) {
- /* Note that with the old behaviour, php pow() returned bogus
- results. Try pow(-1, 2.5) in PHP <= 4.0.6 ... */
- php_error(E_WARNING, "Trying to raise a nonpositive value to a broken power");
- RETURN_FALSE;
- }
- RETURN_DOUBLE(exp(log(Z_DVAL_PP(zbase)) * Z_DVAL_PP(zexp)));
- }
-
- /* pow(?, int), this is the ** case */
-
- lexp = Z_LVAL_PP(zexp);
-
-
- if (Z_TYPE_PP(zbase) == IS_DOUBLE) {
- /* pow(float, int) */
- if (lexp == 0) {
- RETURN_DOUBLE(1.0);
- }
- if (Z_DVAL_PP(zbase) > 0.0) {
- RETURN_DOUBLE(exp(log(Z_DVAL_PP(zbase)) * lexp));
- } else if (Z_DVAL_PP(zbase) == 0.0) {
- if (lexp < 0) {
- php_error(E_WARNING,
- "Division by zero: pow(0.0, [negative integer])");
- RETURN_FALSE;
- } else {
- RETURN_DOUBLE(0.0);
- }
- } else { /* lbase < 0.0 */
- dval = exp(log(-Z_DVAL_PP(zbase)) * (double)lexp);
- RETURN_DOUBLE(lexp & 1 ? -dval : dval);
- }
-
- }
-
- /* pow(int, int) */
- if (lexp == 0) {
- RETURN_LONG(1);
- }
-
- lbase = Z_LVAL_PP(zbase);
-
- /* lexp != 0 */
- switch (lbase) {
- case -1:
- RETURN_LONG( lexp & 1 ? -1 : 1 ); /* if lexp=odd ... */
- case 0:
- if (lexp < 0) {
- php_error(E_WARNING,
- "Division by zero: pow(0, [negative integer])");
- RETURN_FALSE;
- } else {
- RETURN_LONG(0);
- }
- case 1:
- RETURN_LONG(1);
- default:
- /* abs(lbase) > 1 */
- dval = exp(log(lbase>0? (double)lbase : -(double)lbase ) *
- (double) lexp);
- if (lexp < 0 || dval > (double) LONG_MAX) {
- /* 1/n ( abs(n) > 1 ) || overflow */
- RETURN_DOUBLE(((lexp & 1) && lbase<0) ? -dval : dval);
- }
-
- Z_TYPE_P(return_value) = IS_LONG;
- Z_LVAL_P(return_value) = 1;
-
- /* loop runs at most log(log(LONG_MAX)) times, i.e. ~ 5 */
- while (lexp > 0) {
- if (lexp & 1) /* odd */
- Z_LVAL_P(return_value) *= lbase;
- lexp >>= 1;
- lbase *= lbase;
- }
- /* return */
- }
-}
-
-/* }}} */
-/* {{{ proto double exp(double number)
- Returns e raised to the power of the number */
-
-PHP_FUNCTION(exp)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = exp(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double exp2(double number)
- Returns 2 raised to the power of the number */
-
-PHP_FUNCTION(exp2)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- // libc function is broken in RH Linux 6.1, glibc 2.1.3
- //Z_DVAL_P(return_value) = exp2(Z_DVAL_PP(num));
- Z_DVAL_P(return_value) = pow(2.0, Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double exp10(double number)
- Returns 10 raised to the power of the number */
-
-PHP_FUNCTION(exp10)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- // libc function is broken in RH Linux 6.1, glibc 2.1.3
- //Z_DVAL_P(return_value) = exp10(Z_DVAL_PP(num));
- Z_DVAL_P(return_value) = pow(10.0, Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-#ifndef PHP_WIN32
-/* {{{ proto double expm1(double number)
- Returns exp(number) - 1, computed in a way that accurate even when
- the value of number is close to zero */
-
-PHP_FUNCTION(expm1)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = expm1(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double log1p(double number)
- Returns log(1 + number), computed in a way that accurate even when
- the value of number is close to zero */
-
-PHP_FUNCTION(log1p)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = log1p(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-#endif
-/* {{{ proto double log(double number)
- Returns the natural logarithm of the number */
-
-PHP_FUNCTION(log)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = log(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double log2(double number)
- Returns the base-2 logarithm of the number */
-
-PHP_FUNCTION(log2)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- // libc function is broken in RH Linux 6.1, glibc 2.1.3
- //Z_DVAL_P(return_value) = log2(Z_DVAL_PP(num));
- Z_DVAL_P(return_value) = log(Z_DVAL_PP(num))/log(2.0);
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double log10(double number)
- Returns the base-10 logarithm of the number */
-
-PHP_FUNCTION(log10)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = log10(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-/* {{{ proto double sqrt(double number)
- Returns the square root of the number */
-
-PHP_FUNCTION(sqrt)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = sqrt(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-#ifndef PHP_WIN32
-/* {{{ proto double cbrt(double number)
- Returns the cubic root of the number */
-
-PHP_FUNCTION(cbrt)
-{
- zval **num;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num);
- Z_DVAL_P(return_value) = cbrt(Z_DVAL_PP(num));
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-#endif
-
-/* {{{ proto double hypot(double num1, double num2)
- Returns sqrt( num1*num1 + num2*num2) */
-
-PHP_FUNCTION(hypot)
-{
- zval **num1, **num2;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &num1, &num2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(num1);
- convert_to_double_ex(num2);
- Z_DVAL_P(return_value) = hypot((*num1)->value.dval, (*num2)->value.dval);
- Z_TYPE_P(return_value) = IS_DOUBLE;
-}
-
-/* }}} */
-
-/* {{{ proto double deg2rad(double number)
- Converts the number in degrees to the radian equivalent */
-
-PHP_FUNCTION(deg2rad)
-{
- zval **deg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &deg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(deg);
- RETVAL_DOUBLE((Z_DVAL_PP(deg) / 180.0) * M_PI);
-}
-
-/* }}} */
-/* {{{ proto double rad2deg(double number)
- Converts the radian number to the equivalent number in degrees */
-
-PHP_FUNCTION(rad2deg)
-{
- zval **rad;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &rad) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_double_ex(rad);
- RETVAL_DOUBLE((Z_DVAL_PP(rad) / M_PI) * 180);
-}
-
-/* }}} */
-/* {{{ _php_math_basetolong */
-
-/*
- * Convert a string representation of a base(2-36) number to a long.
- */
-PHPAPI long
-_php_math_basetolong(zval *arg, int base) {
- long mult = 1, num = 0, digit;
- int i;
- char c, *s;
-
- if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) {
- return 0;
- }
-
- s = Z_STRVAL_P(arg);
-
- for (i = Z_STRLEN_P(arg) - 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;
- }
- if(!mult || digit > LONG_MAX/mult || num > LONG_MAX-mult*digit) {
- php_error(E_WARNING, "base_to_long: number '%s' is too big to fit in long", s);
- return LONG_MAX;
- }
- num += mult * digit;
- }
-
- return num;
-}
-
-/* }}} */
-/* {{{ _php_math_longtobase */
-
-/*
- * Convert a long to a string containing a base(2-36) representation of
- * the number.
- */
-PHPAPI char *
-_php_math_longtobase(zval *arg, int base)
-{
- static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
- char *result, *ptr, *ret;
- int len, digit;
- unsigned long value;
-
- if (Z_TYPE_P(arg) != IS_LONG || base < 2 || base > 36) {
- return empty_string;
- }
-
- value = Z_LVAL_P(arg);
-
- /* allocates space for the longest possible result with the lowest base */
- len = (sizeof(Z_LVAL_P(arg)) * 8) + 1;
- result = emalloc((sizeof(Z_LVAL_P(arg)) * 8) + 1);
-
- ptr = result + len - 1;
- *ptr-- = '\0';
-
- do {
- digit = value % base;
- *ptr = digits[digit];
- value /= base;
- }
- while (ptr-- > result && value);
- ptr++;
- ret = estrdup(ptr);
- efree(result);
-
- return ret;
-}
-
-/* }}} */
-/* {{{ proto int bindec(string binary_number)
- Returns the decimal equivalent of the binary number */
-
-PHP_FUNCTION(bindec)
-{
- zval **arg;
- long ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg);
- ret = _php_math_basetolong(*arg, 2);
-
- RETVAL_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto int hexdec(string hexadecimal_number)
- Returns the decimal equivalent of the hexadecimal number */
-
-PHP_FUNCTION(hexdec)
-{
- zval **arg;
- long ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg);
-
- ret = _php_math_basetolong(*arg, 16);
- RETVAL_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto int octdec(string octal_number)
- Returns the decimal equivalent of an octal string */
-
-PHP_FUNCTION(octdec)
-{
- zval **arg;
- long ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg);
-
- ret = _php_math_basetolong(*arg, 8);
- RETVAL_LONG(ret);
-}
-
-/* }}} */
-/* {{{ proto string decbin(int decimal_number)
- Returns a string containing a binary representation of the number */
-
-PHP_FUNCTION(decbin)
-{
- zval **arg;
- char *result;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(arg);
-
- result = _php_math_longtobase(*arg, 2);
- Z_TYPE_P(return_value) = IS_STRING;
- Z_STRLEN_P(return_value) = strlen(result);
- Z_STRVAL_P(return_value) = result;
-}
-
-/* }}} */
-/* {{{ proto string decoct(int decimal_number)
- Returns a string containing an octal representation of the given number */
-
-PHP_FUNCTION(decoct)
-{
- zval **arg;
- char *result;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(arg);
-
- result = _php_math_longtobase(*arg, 8);
- Z_TYPE_P(return_value) = IS_STRING;
- Z_STRLEN_P(return_value) = strlen(result);
- Z_STRVAL_P(return_value) = result;
-}
-
-/* }}} */
-/* {{{ proto string dechex(int decimal_number)
- Returns a string containing a hexadecimal representation of the given number */
-
-PHP_FUNCTION(dechex)
-{
- zval **arg;
- char *result;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_long_ex(arg);
-
- result = _php_math_longtobase(*arg, 16);
- Z_TYPE_P(return_value) = IS_STRING;
- Z_STRLEN_P(return_value) = strlen(result);
- Z_STRVAL_P(return_value) = result;
-}
-
-/* }}} */
-/* {{{ proto string base_convert(string number, int frombase, int tobase)
- Converts a number in a string from any base <= 36 to any base <= 36.
-*/
-
-PHP_FUNCTION(base_convert)
-{
- zval **number, **frombase, **tobase, temp;
- char *result;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &number, &frombase, &tobase) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(number);
- convert_to_long_ex(frombase);
- convert_to_long_ex(tobase);
- if (Z_LVAL_PP(frombase) < 2 || Z_LVAL_PP(frombase) > 36) {
- php_error(E_WARNING, "base_convert: invalid `from base' (%d)", Z_LVAL_PP(frombase));
- RETURN_FALSE;
- }
- if (Z_LVAL_PP(tobase) < 2 || Z_LVAL_PP(tobase) > 36) {
- php_error(E_WARNING, "base_convert: invalid `to base' (%d)", Z_LVAL_PP(tobase));
- RETURN_FALSE;
- }
- Z_TYPE(temp) = IS_LONG;
- Z_LVAL(temp) = _php_math_basetolong(*number, Z_LVAL_PP(frombase));
- result = _php_math_longtobase(&temp, Z_LVAL_PP(tobase));
- RETVAL_STRING(result, 0);
-}
-
-/* }}} */
-/* {{{ _php_math_number_format */
-
-char *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep)
-{
- char *tmpbuf, *resbuf;
- char *s, *t; /* source, target */
- int tmplen, reslen=0;
- int count=0;
- int is_negative=0;
-
- if (d<0) {
- is_negative=1;
- d = -d;
- }
- dec = MAX(0, dec);
- tmpbuf = (char *) emalloc(1+DBL_MAX_10_EXP+1+dec+1);
-
- tmplen=sprintf(tmpbuf, "%.*f", dec, d);
-
- if (!isdigit((int)tmpbuf[0])) {
- return tmpbuf;
- }
-
- if (dec) {
- reslen = dec+1 + (tmplen-dec-1) + ((thousand_sep) ? (tmplen-1-dec-1)/3 : 0);
- } else {
- reslen = tmplen+((thousand_sep) ? (tmplen-1)/3 : 0);
- }
- if (is_negative) {
- reslen++;
- }
- resbuf = (char *) emalloc(reslen+1);
-
- s = tmpbuf+tmplen-1;
- t = resbuf+reslen;
- *t-- = 0;
-
- if (dec) {
- while (isdigit((int)*s)) {
- *t-- = *s--;
- }
- *t-- = dec_point; /* copy that dot */
- s--;
- }
-
- while(s>=tmpbuf) {
- *t-- = *s--;
- if (thousand_sep && (++count%3)==0 && s>=tmpbuf) {
- *t-- = thousand_sep;
- }
- }
- if (is_negative) {
- *t-- = '-';
- }
- efree(tmpbuf);
- return resbuf;
-}
-
-/* }}} */
-/* {{{ proto string number_format(double number [, int num_decimal_places [, string dec_seperator, string thousands_seperator]])
- Formats a number with grouped thousands */
-
-PHP_FUNCTION(number_format)
-{
- zval **num, **dec, **t_s, **d_p;
- char thousand_sep=',', dec_point='.';
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &num)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_double_ex(num);
- RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), 0, dec_point, thousand_sep), 0);
- break;
- case 2:
- if (zend_get_parameters_ex(2, &num, &dec)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_double_ex(num);
- convert_to_long_ex(dec);
- RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep), 0);
- break;
- case 4:
- if (zend_get_parameters_ex(4, &num, &dec, &d_p, &t_s)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_double_ex(num);
- convert_to_long_ex(dec);
- convert_to_string_ex(d_p);
- convert_to_string_ex(t_s);
- if (Z_STRLEN_PP(d_p)==1) {
- dec_point=Z_STRVAL_PP(d_p)[0];
- }
- if (Z_STRLEN_PP(t_s)==1) {
- thousand_sep=Z_STRVAL_PP(t_s)[0];
- } else if(Z_STRLEN_PP(t_s)==0) {
- thousand_sep=0;
- }
- RETURN_STRING(_php_math_number_format(Z_DVAL_PP(num), Z_LVAL_PP(dec), dec_point, thousand_sep), 0);
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/md5.c b/ext/standard/md5.c
deleted file mode 100644
index a6d922157f..0000000000
--- a/ext/standard/md5.c
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Lachlan Roche |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/*
- * md5.c - Copyright 1997 Lachlan Roche
- */
-
-#include <stdio.h>
-#include "php.h"
-
-#include "md5.h"
-
-/* {{{ proto string md5(string str)
- Calculate the md5 hash of a string */
-PHP_NAMED_FUNCTION(php_if_md5)
-{
- pval **arg;
- char md5str[33];
- PHP_MD5_CTX context;
- unsigned char digest[16];
- int i;
- char *r;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- md5str[0] = '\0';
- PHP_MD5Init(&context);
- PHP_MD5Update(&context, (*arg)->value.str.val, (*arg)->value.str.len);
- PHP_MD5Final(digest, &context);
- for (i = 0, r = md5str; i < 16; i++, r += 2) {
- sprintf(r, "%02x", digest[i]);
- }
- *r = '\0';
- RETVAL_STRING(md5str, 1);
-}
-/* }}} */
-
-/*
- * The remaining code is the reference MD5 code (md5c.c) from rfc1321
- */
-/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
- */
-
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
- rights reserved.
-
- License to copy and use this software is granted provided that it
- is identified as the "RSA Data Security, Inc. MD5 Message-Digest
- Algorithm" in all material mentioning or referencing this software
- or this function.
-
- License is also granted to make and use derivative works provided
- that such works are identified as "derived from the RSA Data
- Security, Inc. MD5 Message-Digest Algorithm" in all material
- mentioning or referencing the derived work.
-
- RSA Data Security, Inc. makes no representations concerning either
- the merchantability of this software or the suitability of this
- software for any particular purpose. It is provided "as is"
- without express or implied warranty of any kind.
-
- These notices must be retained in any copies of any part of this
- documentation and/or software.
- */
-
-/* Constants for MD5Transform routine.
- */
-
-
-#define S11 7
-#define S12 12
-#define S13 17
-#define S14 22
-#define S21 5
-#define S22 9
-#define S23 14
-#define S24 20
-#define S31 4
-#define S32 11
-#define S33 16
-#define S34 23
-#define S41 6
-#define S42 10
-#define S43 15
-#define S44 21
-
-static void MD5Transform(php_uint32[4], const unsigned char[64]);
-static void Encode(unsigned char *, php_uint32 *, unsigned int);
-static void Decode(php_uint32 *, const unsigned char *, unsigned int);
-
-static unsigned char PADDING[64] =
-{
- 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
-/* F, G, H and I are basic MD5 functions.
- */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define I(x, y, z) ((y) ^ ((x) | (~z)))
-
-/* ROTATE_LEFT rotates x left n bits.
- */
-#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
-
-/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
- Rotation is separate from addition to prevent recomputation.
- */
-#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + (php_uint32)(ac); \
- (a) = ROTATE_LEFT ((a), (s)); \
- (a) += (b); \
- }
-
-/* {{{ PHP_MD5Init
- * MD5 initialization. Begins an MD5 operation, writing a new context.
- */
-void PHP_MD5Init(PHP_MD5_CTX * context)
-{
- context->count[0] = context->count[1] = 0;
- /* Load magic initialization constants.
- */
- context->state[0] = 0x67452301;
- context->state[1] = 0xefcdab89;
- context->state[2] = 0x98badcfe;
- context->state[3] = 0x10325476;
-}
-/* }}} */
-
-/* {{{ PHP_MD5Update
- MD5 block update operation. Continues an MD5 message-digest
- operation, processing another message block, and updating the
- context.
- */
-void PHP_MD5Update(PHP_MD5_CTX * context, const unsigned char *input,
- unsigned int inputLen)
-{
- unsigned int i, index, partLen;
-
- /* Compute number of bytes mod 64 */
- index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
-
- /* Update number of bits */
- if ((context->count[0] += ((php_uint32) inputLen << 3))
- < ((php_uint32) inputLen << 3))
- context->count[1]++;
- context->count[1] += ((php_uint32) inputLen >> 29);
-
- partLen = 64 - index;
-
- /* Transform as many times as possible.
- */
- if (inputLen >= partLen) {
- memcpy
- ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen);
- MD5Transform(context->state, context->buffer);
-
- for (i = partLen; i + 63 < inputLen; i += 64)
- MD5Transform(context->state, &input[i]);
-
- index = 0;
- } else
- i = 0;
-
- /* Buffer remaining input */
- memcpy
- ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i],
- inputLen - i);
-}
-/* }}} */
-
-/* {{{ PHP_MD5Final
- MD5 finalization. Ends an MD5 message-digest operation, writing the
- the message digest and zeroizing the context.
- */
-void PHP_MD5Final(unsigned char digest[16], PHP_MD5_CTX * context)
-{
- unsigned char bits[8];
- unsigned int index, padLen;
-
- /* Save number of bits */
- Encode(bits, context->count, 8);
-
- /* Pad out to 56 mod 64.
- */
- index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
- padLen = (index < 56) ? (56 - index) : (120 - index);
- PHP_MD5Update(context, PADDING, padLen);
-
- /* Append length (before padding) */
- PHP_MD5Update(context, bits, 8);
-
- /* Store state in digest */
- Encode(digest, context->state, 16);
-
- /* Zeroize sensitive information.
- */
- memset((unsigned char*) context, 0, sizeof(*context));
-}
-/* }}} */
-
-/* {{{ MD5Transform
- * MD5 basic transformation. Transforms state based on block.
- */
-static void MD5Transform(state, block)
-php_uint32 state[4];
-const unsigned char block[64];
-{
- php_uint32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-
- Decode(x, block, 64);
-
- /* Round 1 */
- FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
- FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
- FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
- FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
- FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
- FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
- FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
- FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
- FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
- FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
- FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
- FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
- FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
- FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
- FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
- FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
-
- /* Round 2 */
- GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
- GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
- GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
- GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
- GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
- GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
- GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
- GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
- GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
- GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
- GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
- GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
- GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
- GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
- GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
- GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
-
- /* Round 3 */
- HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
- HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
- HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
- HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
- HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
- HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
- HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
- HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
- HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
- HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
- HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
- HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
- HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
- HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
- HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
- HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
-
- /* Round 4 */
- II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
- II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
- II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
- II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
- II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
- II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
- II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
- II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
- II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
- II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
- II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
- II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
- II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
- II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
- II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
- II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
-
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
-
- /* Zeroize sensitive information. */
- memset((unsigned char*) x, 0, sizeof(x));
-}
-/* }}} */
-
-/* {{{ Encode
- Encodes input (php_uint32) into output (unsigned char). Assumes len is
- a multiple of 4.
- */
-static void Encode(output, input, len)
-unsigned char *output;
-php_uint32 *input;
-unsigned int len;
-{
- unsigned int i, j;
-
- for (i = 0, j = 0; j < len; i++, j += 4) {
- output[j] = (unsigned char) (input[i] & 0xff);
- output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff);
- output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff);
- output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff);
- }
-}
-/* }}} */
-
-/* {{{ Decode
- Decodes input (unsigned char) into output (php_uint32). Assumes len is
- a multiple of 4.
- */
-static void Decode(output, input, len)
-php_uint32 *output;
-const unsigned char *input;
-unsigned int len;
-{
- unsigned int i, j;
-
- for (i = 0, j = 0; j < len; i++, j += 4)
- output[i] = ((php_uint32) input[j]) | (((php_uint32) input[j + 1]) << 8) |
- (((php_uint32) input[j + 2]) << 16) | (((php_uint32) input[j + 3]) << 24);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/md5.h b/ext/standard/md5.h
deleted file mode 100644
index b4c09e498a..0000000000
--- a/ext/standard/md5.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef MD5_H
-#define MD5_H
-/* MD5.H - header file for MD5C.C
- */
-
-/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
- rights reserved.
-
- License to copy and use this software is granted provided that it
- is identified as the "RSA Data Security, Inc. MD5 Message-Digest
- Algorithm" in all material mentioning or referencing this software
- or this function.
-
- License is also granted to make and use derivative works provided
- that such works are identified as "derived from the RSA Data
- Security, Inc. MD5 Message-Digest Algorithm" in all material
- mentioning or referencing the derived work.
-
- RSA Data Security, Inc. makes no representations concerning either
- the merchantability of this software or the suitability of this
- software for any particular purpose. It is provided "as is"
- without express or implied warranty of any kind.
-
- These notices must be retained in any copies of any part of this
- documentation and/or software.
- */
-
-#include "ext/standard/basic_functions.h"
-
-/* MD5 context. */
-typedef struct {
- php_uint32 state[4]; /* state (ABCD) */
- php_uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */
- unsigned char buffer[64]; /* input buffer */
-} PHP_MD5_CTX;
-
-void PHP_MD5Init(PHP_MD5_CTX *);
-void PHP_MD5Update(PHP_MD5_CTX *, const unsigned char *, unsigned int);
-void PHP_MD5Final(unsigned char[16], PHP_MD5_CTX *);
-
-PHP_NAMED_FUNCTION(php_if_md5);
-
-#endif
diff --git a/ext/standard/metaphone.c b/ext/standard/metaphone.c
deleted file mode 100644
index 545bda300c..0000000000
--- a/ext/standard/metaphone.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Thies C. Arntzen <thies@thieso.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/*
- Based on CPANs "Text-Metaphone-1.96" by Michael G Schwern <schwern@pobox.com>
-*/
-
-#include "php.h"
-#include "php_metaphone.h"
-
-static int metaphone(char *word, int max_phonemes, char **phoned_word, int traditional);
-
-PHP_FUNCTION(metaphone);
-
-/* {{{ proto string metaphone(string text, int phones)
- Break english phrases down into their phonemes */
-PHP_FUNCTION(metaphone)
-{
- pval **pstr, **pphones;
- char *result = 0;
- int phones = 0;
-
- if (zend_get_parameters_ex(2, &pstr, &pphones) == SUCCESS) {
- convert_to_long_ex(pphones);
- phones = (*pphones)->value.lval;
- } else if (zend_get_parameters_ex(1, &pstr) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(pstr);
-
- if (metaphone((*pstr)->value.str.val, phones, &result, 1) == 0) {
- RETVAL_STRING(result, 0);
- } else {
- if (result) {
- efree(result);
- }
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/*
- this is now the original code by Michael G Schwern:
- i've changed it just a slightly bit (use emalloc,
- get rid of includes etc)
- - thies - 13.09.1999
-*/
-
-/*----------------------------- */
-/* this used to be "metaphone.h" */
-/*----------------------------- */
-
-/* Special encodings */
-#define SH 'X'
-#define TH '0'
-
-/*----------------------------- */
-/* end of "metaphone.h" */
-/*----------------------------- */
-
-/*----------------------------- */
-/* this used to be "metachar.h" */
-/*----------------------------- */
-
-/* Metachar.h ... little bits about characters for metaphone */
-/*-- Character encoding array & accessing macros --*/
-/* Stolen directly out of the book... */
-char _codes[26] =
-{
- 1, 16, 4, 16, 9, 2, 4, 16, 9, 2, 0, 2, 2, 2, 1, 4, 0, 2, 4, 4, 1, 0, 0, 0, 8, 0
-/* a b c d e f g h i j k l m n o p q r s t u v w x y z */
-};
-
-
-#define ENCODE(c) (isalpha(c) ? _codes[((toupper(c)) - 'A')] : 0)
-
-#define isvowel(c) (ENCODE(c) & 1) /* AEIOU */
-
-/* These letters are passed through unchanged */
-#define NOCHANGE(c) (ENCODE(c) & 2) /* FJMNR */
-
-/* These form dipthongs when preceding H */
-#define AFFECTH(c) (ENCODE(c) & 4) /* CGPST */
-
-/* These make C and G soft */
-#define MAKESOFT(c) (ENCODE(c) & 8) /* EIY */
-
-/* These prevent GH from becoming F */
-#define NOGHTOF(c) (ENCODE(c) & 16) /* BDH */
-
-/*----------------------------- */
-/* end of "metachar.h" */
-/*----------------------------- */
-
-/* I suppose I could have been using a character pointer instead of
- * accesssing the array directly... */
-
-/* Look at the next letter in the word */
-#define Next_Letter (toupper(word[w_idx+1]))
-/* Look at the current letter in the word */
-#define Curr_Letter (toupper(word[w_idx]))
-/* Go N letters back. */
-#define Look_Back_Letter(n) (w_idx >= n ? toupper(word[w_idx-n]) : '\0')
-/* Previous letter. I dunno, should this return null on failure? */
-#define Prev_Letter (Look_Back_Letter(1))
-/* Look two letters down. It makes sure you don't walk off the string. */
-#define After_Next_Letter (Next_Letter != '\0' ? toupper(word[w_idx+2]) \
- : '\0')
-#define Look_Ahead_Letter(n) (toupper(Lookahead(word+w_idx, n)))
-
-
-/* Allows us to safely look ahead an arbitrary # of letters */
-/* I probably could have just used strlen... */
-static char Lookahead(char *word, int how_far)
-{
- char letter_ahead = '\0'; /* null by default */
- int idx;
- for (idx = 0; word[idx] != '\0' && idx < how_far; idx++);
- /* Edge forward in the string... */
-
- letter_ahead = word[idx]; /* idx will be either == to how_far or
- * at the end of the string
- */
- return letter_ahead;
-}
-
-
-/* phonize one letter */
-#define Phonize(c) {(*phoned_word)[p_idx++] = c;}
-/* Slap a null character on the end of the phoned word */
-#define End_Phoned_Word {(*phoned_word)[p_idx] = '\0';}
-/* How long is the phoned word? */
-#define Phone_Len (p_idx)
-
-/* Note is a letter is a 'break' in the word */
-#define Isbreak(c) (!isalpha(c))
-
-/* {{{ metaphone
- */
-static int metaphone(char *word, int max_phonemes, char **phoned_word, int traditional)
-{
- int w_idx = 0; /* point in the phonization we're at. */
- int p_idx = 0; /* end of the phoned phrase */
-
-/*-- Parameter checks --*/
- /* Negative phoneme length is meaningless */
-
- if (max_phonemes < 0)
- return -1;
-
- /* Empty/null string is meaningless */
- /* Overly paranoid */
- /* assert(word != NULL && word[0] != '\0'); */
-
- if (word == NULL)
- return -1;
-
-/*-- Allocate memory for our phoned_phrase --*/
- if (max_phonemes == 0) { /* Assume largest possible */
- *phoned_word = emalloc(sizeof(char) * strlen(word) + 1);
- if (!*phoned_word)
- return -1;
- } else {
- *phoned_word = emalloc(sizeof(char) * max_phonemes + 1);
- if (!*phoned_word)
- return -1;
- }
-
-
-/*-- The first phoneme has to be processed specially. --*/
- /* Find our first letter */
- for (; !isalpha(Curr_Letter); w_idx++) {
- /* On the off chance we were given nothing but crap... */
- if (Curr_Letter == '\0') {
- End_Phoned_Word
- return SUCCESS; /* For testing */
- }
- }
-
- switch (Curr_Letter) {
- /* AE becomes E */
- case 'A':
- if (Next_Letter == 'E') {
- Phonize('E');
- w_idx += 2;
- }
- /* Remember, preserve vowels at the beginning */
- else {
- Phonize('A');
- w_idx++;
- }
- break;
- /* [GKP]N becomes N */
- case 'G':
- case 'K':
- case 'P':
- if (Next_Letter == 'N') {
- Phonize('N');
- w_idx += 2;
- }
- break;
- /* WH becomes H,
- WR becomes R
- W if followed by a vowel */
- case 'W':
- if (Next_Letter == 'H' ||
- Next_Letter == 'R') {
- Phonize(Next_Letter);
- w_idx += 2;
- } else if (isvowel(Next_Letter)) {
- Phonize('W');
- w_idx += 2;
- }
- /* else ignore */
- break;
- /* X becomes S */
- case 'X':
- Phonize('S');
- w_idx++;
- break;
- /* Vowels are kept */
- /* We did A already
- case 'A':
- case 'a':
- */
- case 'E':
- case 'I':
- case 'O':
- case 'U':
- Phonize(Curr_Letter);
- w_idx++;
- break;
- default:
- /* do nothing */
- break;
- }
-
-
-
- /* On to the metaphoning */
- for (; Curr_Letter != '\0' &&
- (max_phonemes == 0 || Phone_Len < max_phonemes);
- w_idx++) {
- /* How many letters to skip because an eariler encoding handled
- * multiple letters */
- unsigned short int skip_letter = 0;
-
-
- /* THOUGHT: It would be nice if, rather than having things like...
- * well, SCI. For SCI you encode the S, then have to remember
- * to skip the C. So the phonome SCI invades both S and C. It would
- * be better, IMHO, to skip the C from the S part of the encoding.
- * Hell, I'm trying it.
- */
-
- /* Ignore non-alphas */
- if (!isalpha(Curr_Letter))
- continue;
-
- /* Drop duplicates, except CC */
- if (Curr_Letter == Prev_Letter &&
- Curr_Letter != 'C')
- continue;
-
- switch (Curr_Letter) {
- /* B -> B unless in MB */
- case 'B':
- if (Prev_Letter != 'M')
- Phonize('B');
- break;
- /* 'sh' if -CIA- or -CH, but not SCH, except SCHW.
- * (SCHW is handled in S)
- * S if -CI-, -CE- or -CY-
- * dropped if -SCI-, SCE-, -SCY- (handed in S)
- * else K
- */
- case 'C':
- if (MAKESOFT(Next_Letter)) { /* C[IEY] */
- if (After_Next_Letter == 'A' &&
- Next_Letter == 'I') { /* CIA */
- Phonize(SH);
- }
- /* SC[IEY] */
- else if (Prev_Letter == 'S') {
- /* Dropped */
- } else {
- Phonize('S');
- }
- } else if (Next_Letter == 'H') {
- if ((!traditional) && (After_Next_Letter == 'R' || Prev_Letter == 'S')) { /* Christ, School */
- Phonize('K');
- } else {
- Phonize(SH);
- }
- skip_letter++;
- } else {
- Phonize('K');
- }
- break;
- /* J if in -DGE-, -DGI- or -DGY-
- * else T
- */
- case 'D':
- if (Next_Letter == 'G' &&
- MAKESOFT(After_Next_Letter)) {
- Phonize('J');
- skip_letter++;
- } else
- Phonize('T');
- break;
- /* F if in -GH and not B--GH, D--GH, -H--GH, -H---GH
- * else dropped if -GNED, -GN,
- * else dropped if -DGE-, -DGI- or -DGY- (handled in D)
- * else J if in -GE-, -GI, -GY and not GG
- * else K
- */
- case 'G':
- if (Next_Letter == 'H') {
- if (!(NOGHTOF(Look_Back_Letter(3)) ||
- Look_Back_Letter(4) == 'H')) {
- Phonize('F');
- skip_letter++;
- } else {
- /* silent */
- }
- } else if (Next_Letter == 'N') {
- if (Isbreak(After_Next_Letter) ||
- (After_Next_Letter == 'E' &&
- Look_Ahead_Letter(3) == 'D')) {
- /* dropped */
- } else
- Phonize('K');
- } else if (MAKESOFT(Next_Letter) &&
- Prev_Letter != 'G') {
- Phonize('J');
- } else {
- Phonize('K');
- }
- break;
- /* H if before a vowel and not after C,G,P,S,T */
- case 'H':
- if (isvowel(Next_Letter) &&
- !AFFECTH(Prev_Letter))
- Phonize('H');
- break;
- /* dropped if after C
- * else K
- */
- case 'K':
- if (Prev_Letter != 'C')
- Phonize('K');
- break;
- /* F if before H
- * else P
- */
- case 'P':
- if (Next_Letter == 'H') {
- Phonize('F');
- } else {
- Phonize('P');
- }
- break;
- /* K
- */
- case 'Q':
- Phonize('K');
- break;
- /* 'sh' in -SH-, -SIO- or -SIA- or -SCHW-
- * else S
- */
- case 'S':
- if (Next_Letter == 'I' &&
- (After_Next_Letter == 'O' ||
- After_Next_Letter == 'A')) {
- Phonize(SH);
- } else if (Next_Letter == 'H') {
- Phonize(SH);
- skip_letter++;
- } else if ((!traditional) && (Next_Letter == 'C' && Look_Ahead_Letter(2) == 'H' && Look_Ahead_Letter(3) == 'W')) {
- Phonize(SH);
- skip_letter += 2;
- } else {
- Phonize('S');
- }
- break;
- /* 'sh' in -TIA- or -TIO-
- * else 'th' before H
- * else T
- */
- case 'T':
- if (Next_Letter == 'I' &&
- (After_Next_Letter == 'O' ||
- After_Next_Letter == 'A')) {
- Phonize(SH);
- } else if (Next_Letter == 'H') {
- Phonize(TH);
- skip_letter++;
- } else {
- Phonize('T');
- }
- break;
- /* F */
- case 'V':
- Phonize('F');
- break;
- /* W before a vowel, else dropped */
- case 'W':
- if (isvowel(Next_Letter))
- Phonize('W');
- break;
- /* KS */
- case 'X':
- Phonize('K');
- Phonize('S');
- break;
- /* Y if followed by a vowel */
- case 'Y':
- if (isvowel(Next_Letter))
- Phonize('Y');
- break;
- /* S */
- case 'Z':
- Phonize('S');
- break;
- /* No transformation */
- case 'F':
- case 'J':
- case 'L':
- case 'M':
- case 'N':
- case 'R':
- Phonize(Curr_Letter);
- break;
- default:
- /* nothing */
- break;
- } /* END SWITCH */
-
- w_idx += skip_letter;
- } /* END FOR */
-
- End_Phoned_Word;
-
- return 0;
-} /* END metaphone */
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/microtime.c b/ext/standard/microtime.c
deleted file mode 100644
index 0850c6cf2c..0000000000
--- a/ext/standard/microtime.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Paul Panotzki - Bunyip Information Systems |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef PHP_WIN32
-#include "win32/time.h"
-#else
-#include <sys/time.h>
-#endif
-#ifdef HAVE_SYS_RESOURCE_H
-#include <sys/resource.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include "microtime.h"
-
-#define NUL '\0'
-#define MICRO_IN_SEC 1000000.00
-
-/* {{{ proto string microtime(void)
- Returns a string containing the current time in seconds and microseconds */
-PHP_FUNCTION(microtime)
-{
-#ifdef HAVE_GETTIMEOFDAY
- struct timeval tp;
- long sec = 0L;
- double msec = 0.0;
- char ret[100];
-
- if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
- msec = (double) (tp.tv_usec / MICRO_IN_SEC);
- sec = tp.tv_sec;
-
- if (msec >= 1.0) msec -= (long) msec;
- snprintf(ret, 100, "%.8f %ld", msec, sec);
- RETVAL_STRING(ret,1);
- } else
-#endif
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto array gettimeofday(void)
- Returns the current time as array */
-PHP_FUNCTION(gettimeofday)
-{
-#ifdef HAVE_GETTIMEOFDAY
- struct timeval tp;
- struct timezone tz;
-
- memset(&tp, 0, sizeof(tp));
- memset(&tz, 0, sizeof(tz));
- if(gettimeofday(&tp, &tz) == 0) {
- array_init(return_value);
- add_assoc_long(return_value, "sec", tp.tv_sec);
- add_assoc_long(return_value, "usec", tp.tv_usec);
- add_assoc_long(return_value, "minuteswest", tz.tz_minuteswest);
- add_assoc_long(return_value, "dsttime", tz.tz_dsttime);
- return;
- } else
-#endif
- RETURN_FALSE;
-}
-/* }}} */
-
-#ifdef HAVE_GETRUSAGE
-/* {{{ proto array getrusage([int who])
- Returns an array of usage statistics */
-PHP_FUNCTION(getrusage)
-{
- struct rusage usg;
- int ac = ZEND_NUM_ARGS();
- pval **pwho;
- int who = RUSAGE_SELF;
-
- if(ac == 1 &&
- zend_get_parameters_ex(ac, &pwho) != FAILURE) {
- convert_to_long_ex(pwho);
- if((*pwho)->value.lval == 1)
- who = RUSAGE_CHILDREN;
- }
-
- memset(&usg, 0, sizeof(usg));
- if(getrusage(who, &usg) == -1) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
-#define PHP_RUSAGE_PARA(a) \
- add_assoc_long(return_value, #a, usg.a)
-#if !defined( _OSD_POSIX) && !defined(__BEOS__) /* BS2000 has only a few fields in the rusage struct */
- PHP_RUSAGE_PARA(ru_oublock);
- PHP_RUSAGE_PARA(ru_inblock);
- PHP_RUSAGE_PARA(ru_msgsnd);
- PHP_RUSAGE_PARA(ru_msgrcv);
- PHP_RUSAGE_PARA(ru_maxrss);
- PHP_RUSAGE_PARA(ru_ixrss);
- PHP_RUSAGE_PARA(ru_idrss);
- PHP_RUSAGE_PARA(ru_minflt);
- PHP_RUSAGE_PARA(ru_majflt);
- PHP_RUSAGE_PARA(ru_nsignals);
- PHP_RUSAGE_PARA(ru_nvcsw);
- PHP_RUSAGE_PARA(ru_nivcsw);
-#endif /*_OSD_POSIX*/
- PHP_RUSAGE_PARA(ru_utime.tv_usec);
- PHP_RUSAGE_PARA(ru_utime.tv_sec);
- PHP_RUSAGE_PARA(ru_stime.tv_usec);
- PHP_RUSAGE_PARA(ru_stime.tv_sec);
-#undef PHP_RUSAGE_PARA
-}
-#endif /* HAVE_GETRUSAGE */
-
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/microtime.h b/ext/standard/microtime.h
deleted file mode 100644
index e7b06def5f..0000000000
--- a/ext/standard/microtime.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Paul Panotzki - Bunyip Information Systems |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef MICROTIME_H
-#define MICROTIME_H
-
-PHP_FUNCTION(microtime);
-PHP_FUNCTION(gettimeofday);
-PHP_FUNCTION(getrusage);
-
-#endif /* MICROTIME_H */
diff --git a/ext/standard/pack.c b/ext/standard/pack.c
deleted file mode 100644
index cf4a55108a..0000000000
--- a/ext/standard/pack.c
+++ /dev/null
@@ -1,877 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Chris Schneider <cschneid@relog.ch> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#ifdef PHP_WIN32
-#include <windows.h>
-#include <winsock.h>
-#define O_RDONLY _O_RDONLY
-#include "win32/param.h"
-#else
-#include <sys/param.h>
-#endif
-#include "ext/standard/head.h"
-#include "safe_mode.h"
-#include "php_string.h"
-#include "pack.h"
-#if HAVE_PWD_H
-#ifdef PHP_WIN32
-#include "win32/pwd.h"
-#else
-#include <pwd.h>
-#endif
-#endif
-#include "fsock.h"
-#if HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
-/* Whether machine is little endian */
-char machine_little_endian;
-
-/* Mapping of byte from char (8bit) to long for machine endian */
-static int byte_map[1];
-
-/* Mappings of bytes from int (machine dependant) to int for machine endian */
-static int int_map[sizeof(int)];
-
-/* Mappings of bytes from shorts (16bit) for all endian environments */
-static int machine_endian_short_map[2];
-static int big_endian_short_map[2];
-static int little_endian_short_map[2];
-
-/* Mappings of bytes from longs (32bit) for all endian environments */
-static int machine_endian_long_map[4];
-static int big_endian_long_map[4];
-static int little_endian_long_map[4];
-
-/* {{{ php_pack
- */
-static void php_pack(pval **val, int size, int *map, char *output)
-{
- int i;
- char *v;
-
- convert_to_long_ex(val);
- v = (char *)&(*val)->value.lval;
-
- for (i = 0; i < size; i++) {
- *(output++) = v[map[i]];
- }
-}
-/* }}} */
-
-/* pack() idea stolen from Perl (implemented formats behave the same as there)
- * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @.
- */
-/* {{{ proto string pack(string format, mixed arg1 [, mixed arg2 [, mixed ...]])
- Takes one or more arguments and packs them into a binary string according to the format argument */
-PHP_FUNCTION(pack)
-{
- pval ***argv;
- int argc, i;
- int currentarg;
- char *format;
- int formatlen;
- char *formatcodes;
- int *formatargs;
- int formatcount = 0;
- int outputpos = 0, outputsize = 0;
- char *output;
-
- argc = ZEND_NUM_ARGS();
-
- if (argc < 1) {
- WRONG_PARAM_COUNT;
- }
-
- argv = emalloc(argc * sizeof(pval **));
-
- if (zend_get_parameters_array_ex(argc, argv) == FAILURE) {
- efree(argv);
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(argv[0]);
- format = (*argv[0])->value.str.val;
- formatlen = (*argv[0])->value.str.len;
-
- /* We have a maximum of <formatlen> format codes to deal with */
- formatcodes = emalloc(formatlen * sizeof(*formatcodes));
- formatargs = emalloc(formatlen * sizeof(*formatargs));
- currentarg = 1;
-
- /* Preprocess format into formatcodes and formatargs */
- for (i = 0; i < formatlen; formatcount++) {
- char code = format[i++];
- int arg = 1;
-
- /* Handle format arguments if any */
- if (i < formatlen) {
- char c = format[i];
-
- if (c == '*') {
- arg = -1;
- i++;
- }
- else if ((c >= '0') && (c <= '9')) {
- arg = atoi(&format[i]);
-
- while (format[i] >= '0' && format[i] <= '9' && i < formatlen) {
- i++;
- }
- }
- }
-
- /* Handle special arg '*' for all codes and check argv overflows */
- switch ((int)code) {
- /* Never uses any args */
- case 'x': case 'X': case '@': {
- if (arg < 0) {
- php_error(E_WARNING, "pack type %c: '*' ignored", code);
- arg = 1;
- }
- break;
- }
-
- /* Always uses one arg */
- case 'a': case 'A': case 'h': case 'H': {
- if (currentarg >= argc) {
- efree(argv);
- efree(formatcodes);
- efree(formatargs);
- php_error(E_ERROR, "pack type %c: not enough arguments", code);
- RETURN_FALSE;
- }
-
- if (arg < 0) {
- arg = (*argv[currentarg])->value.str.len;
- }
-
- currentarg++;
- break;
- }
-
- /* Use as many args as specified */
- case 'c': case 'C': case 's': case 'S': case 'i': case 'I':
- case 'l': case 'L': case 'n': case 'N': case 'v': case 'V':
- case 'f': case 'd': {
- if (arg < 0) {
- arg = argc - currentarg;
- }
-
- currentarg += arg;
-
- if (currentarg > argc) {
- efree(argv);
- efree(formatcodes);
- efree(formatargs);
- php_error(E_ERROR, "pack type %c: too few arguments", code);
- RETURN_FALSE;
- }
- break;
- }
-
- default: {
- php_error(E_ERROR, "pack type %c: unknown format code", code);
- RETURN_FALSE;
- }
- }
-
- formatcodes[formatcount] = code;
- formatargs[formatcount] = arg;
- }
-
- if (currentarg < argc) {
- php_error(E_WARNING, "pack %d arguments unused", (argc - currentarg));
- }
-
- /* Calculate output length and upper bound while processing*/
- for (i = 0; i < formatcount; i++) {
- int code = (int)formatcodes[i];
- int arg = formatargs[i];
-
- switch ((int)code) {
- case 'h': case 'H': {
- outputpos += (arg + 1) / 2; /* 4 bit per arg */
- break;
- }
-
- case 'a': case 'A':
- case 'c': case 'C':
- case 'x': {
- outputpos += arg; /* 8 bit per arg */
- break;
- }
-
- case 's': case 'S': case 'n': case 'v': {
- outputpos += arg * 2; /* 16 bit per arg */
- break;
- }
-
- case 'i': case 'I': {
- outputpos += arg * sizeof(int);
- break;
- }
-
- case 'l': case 'L': case 'N': case 'V': {
- outputpos += arg * 4; /* 32 bit per arg */
- break;
- }
-
- case 'f': {
- outputpos += arg * sizeof(float);
- break;
- }
-
- case 'd': {
- outputpos += arg * sizeof(double);
- break;
- }
-
- case 'X': {
- outputpos -= arg;
-
- if (outputpos < 0) {
- php_error(E_WARNING, "pack type %c: outside of string", code);
- outputpos = 0;
- }
- break;
- }
-
- case '@': {
- outputpos = arg;
- break;
- }
- }
-
- if (outputsize < outputpos) {
- outputsize = outputpos;
- }
- }
-
- output = emalloc(outputsize + 1);
- outputpos = 0;
- currentarg = 1;
-
- /* Do actual packing */
- for (i = 0; i < formatcount; i++) {
- int code = (int)formatcodes[i];
- int arg = formatargs[i];
- pval **val;
-
- switch ((int)code) {
- case 'a': case 'A': {
- memset(&output[outputpos], (code == 'a') ? '\0' : ' ', arg);
- val = argv[currentarg++];
- convert_to_string_ex(val);
- memcpy(&output[outputpos], (*val)->value.str.val,
- ((*val)->value.str.len < arg) ? (*val)->value.str.len : arg);
- outputpos += arg;
- break;
- }
-
- case 'h': case 'H': {
- int nibbleshift = (code == 'h') ? 0 : 4;
- int first = 1;
- char *v;
-
- val = argv[currentarg++];
- convert_to_string_ex(val);
- v = (*val)->value.str.val;
- outputpos--;
- if(arg > (*val)->value.str.len) {
- php_error(E_WARNING, "pack type %c: not enough characters in string", code);
- arg = (*val)->value.str.len;
- }
-
- while (arg-- > 0) {
- char n = *(v++);
-
- if ((n >= '0') && (n <= '9')) {
- n -= '0';
- } else if ((n >= 'A') && (n <= 'F')) {
- n -= ('A' - 10);
- } else if ((n >= 'a') && (n <= 'f')) {
- n -= ('a' - 10);
- } else {
- php_error(E_WARNING, "pack type %c: illegal hex digit %c", code, n);
- n = 0;
- }
-
- if (first--) {
- output[++outputpos] = 0;
- } else {
- first = 1;
- }
-
- output[outputpos] |= (n << nibbleshift);
- nibbleshift = (nibbleshift + 4) & 7;
- }
-
- outputpos++;
- break;
- }
-
- case 'c': case 'C': {
- while (arg-- > 0) {
- php_pack(argv[currentarg++], 1, byte_map, &output[outputpos]);
- outputpos++;
- }
- break;
- }
-
- case 's': case 'S': case 'n': case 'v': {
- int *map = machine_endian_short_map;
-
- if (code == 'n') {
- map = big_endian_short_map;
- } else if (code == 'v') {
- map = little_endian_short_map;
- }
-
- while (arg-- > 0) {
- php_pack(argv[currentarg++], 2, map, &output[outputpos]);
- outputpos += 2;
- }
- break;
- }
-
- case 'i': case 'I': {
- while (arg-- > 0) {
- php_pack(argv[currentarg++], sizeof(int), int_map, &output[outputpos]);
- outputpos += sizeof(int);
- }
- break;
- }
-
- case 'l': case 'L': case 'N': case 'V': {
- int *map = machine_endian_long_map;
-
- if (code == 'N') {
- map = big_endian_long_map;
- } else if (code == 'V') {
- map = little_endian_long_map;
- }
-
- while (arg-- > 0) {
- php_pack(argv[currentarg++], 4, map, &output[outputpos]);
- outputpos += 4;
- }
- break;
- }
-
- case 'f': {
- float v;
-
- while (arg-- > 0) {
- val = argv[currentarg++];
- convert_to_double_ex(val);
- v = (float)(*val)->value.dval;
- memcpy(&output[outputpos], &v, sizeof(v));
- outputpos += sizeof(v);
- }
- break;
- }
-
- case 'd': {
- double v;
-
- while (arg-- > 0) {
- val = argv[currentarg++];
- convert_to_double_ex(val);
- v = (double)(*val)->value.dval;
- memcpy(&output[outputpos], &v, sizeof(v));
- outputpos += sizeof(v);
- }
- break;
- }
-
- case 'x': {
- memset(&output[outputpos], '\0', arg);
- outputpos += arg;
- break;
- }
-
- case 'X': {
- outputpos -= arg;
-
- if (outputpos < 0) {
- outputpos = 0;
- }
- break;
- }
-
- case '@': {
- if (arg > outputpos) {
- memset(&output[outputpos], '\0', arg - outputpos);
- }
- outputpos = arg;
- break;
- }
- }
- }
-
- efree(argv);
- efree(formatcodes);
- efree(formatargs);
- output[outputpos] = '\0';
- RETVAL_STRINGL(output, outputpos, 1);
- efree(output);
-}
-/* }}} */
-
-/* {{{ php_unpack
- */
-static long php_unpack(char *data, int size, int issigned, int *map)
-{
- long result;
- char *cresult = (char *)&result;
- int i;
-
- result = issigned ? -1 : 0;
-
- for (i = 0; i < size; i++) {
- cresult[map[i]] = *(data++);
- }
-
- return result;
-}
-/* }}} */
-
-/* unpack() is based on Perl's unpack(), but is modified a bit from there.
- * Rather than depending on error-prone ordered lists or syntactically
- * unpleasant pass-by-reference, we return an object with named paramters
- * (like *_fetch_object()). Syntax is "f[repeat]name/...", where "f" is the
- * formatter char (like pack()), "[repeat]" is the optional repeater argument,
- * and "name" is the name of the variable to use.
- * Example: "c2chars/nints" will return an object with fields
- * chars1, chars2, and ints.
- * Numeric pack types will return numbers, a and A will return strings,
- * f and d will return doubles.
- * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @.
- */
-/* {{{ proto array unpack(string format, string input)
- Unpack binary string into named array elements according to format argument */
-PHP_FUNCTION(unpack)
-{
- pval **formatarg;
- pval **inputarg;
- char *format;
- char *input;
- int formatlen;
- int inputpos, inputlen;
- int i;
-
- if ((ZEND_NUM_ARGS() != 2) || zend_get_parameters_ex(2, &formatarg, &inputarg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(formatarg);
- convert_to_string_ex(inputarg);
-
- format = (*formatarg)->value.str.val;
- formatlen = (*formatarg)->value.str.len;
- input = (*inputarg)->value.str.val;
- inputlen = (*inputarg)->value.str.len;
- inputpos = 0;
-
- if (array_init(return_value) == FAILURE)
- return;
-
- while (formatlen-- > 0) {
- char type = *(format++);
- char c;
- int arg = 1;
- char *name;
- int namelen;
- int size=0;
-
- /* Handle format arguments if any */
- if (formatlen > 0) {
- c = *format;
-
- if ((c >= '0') && (c <= '9')) {
- arg = atoi(format);
-
- while ((formatlen > 0) && (*format >= '0') && (*format <= '9')) {
- format++;
- formatlen--;
- }
- } else if (c == '*') {
- arg = -1;
- format++;
- formatlen--;
- }
- }
-
- /* Get of new value in array */
- name = format;
-
- while ((formatlen > 0) && (*format != '/')) {
- formatlen--;
- format++;
- }
-
- namelen = format - name;
-
- if (namelen > 200)
- namelen = 200;
-
- switch ((int)type) {
- /* Never use any input */
- case 'X': {
- size = -1;
- break;
- }
-
- case '@': {
- size = 0;
- break;
- }
-
- case 'a': case 'A': {
- size = arg;
- arg = 1;
- break;
- }
-
- case 'h': case 'H': {
- size = (arg>0)?arg/2:arg;
- arg = 1;
- break;
- }
-
- /* Use 1 byte of input */
- case 'c': case 'C': case 'x': {
- size = 1;
- break;
- }
-
- /* Use 2 bytes of input */
- case 's': case 'S': case 'n': case 'v': {
- size = 2;
- break;
- }
-
- /* Use sizeof(int) bytes of input */
- case 'i': case 'I': {
- size = sizeof(int);
- break;
- }
-
- /* Use 4 bytes of input */
- case 'l': case 'L': case 'N': case 'V': {
- size = 4;
- break;
- }
-
- /* Use sizeof(float) bytes of input */
- case 'f': {
- size = sizeof(float);
- break;
- }
-
- /* Use sizeof(double) bytes of input */
- case 'd': {
- size = sizeof(double);
- break;
- }
- }
-
- /* Do actual unpacking */
- for (i = 0; (i != arg); i++ ) {
- /* Space for name + number, safe as namelen is ensured <= 200 */
- char n[256];
-
- if (arg != 1) {
- /* Need to add element number to name */
- sprintf(n, "%.*s%d", namelen, name, i + 1);
- } else {
- /* Truncate name to next format code or end of string */
- sprintf(n, "%.*s", namelen, name);
- }
-
- if ((inputpos + size) <= inputlen) {
- switch ((int)type) {
- case 'a': case 'A': {
- char pad = (type == 'a') ? '\0' : ' ';
- int len = inputlen - inputpos; /* Remaining string */
-
- /* If size was given take minimum of len and size */
- if ((size >= 0) && (len > size)) {
- len = size;
- }
-
- size = len;
-
- /* Remove padding chars from unpacked data */
- while (--len >= 0) {
- if (input[inputpos + len] != pad)
- break;
- }
-
- add_assoc_stringl(return_value, n, &input[inputpos], len + 1, 1);
- break;
- }
-
- case 'h': case 'H': {
- int len = (inputlen - inputpos) * 2; /* Remaining */
- int nibbleshift = (type == 'h') ? 0 : 4;
- int first = 1;
- char *buf;
- int ipos, opos;
-
- /* If size was given take minimum of len and size */
- if ((size >= 0) && (len > size*2)) {
- len = size*2;
- }
-
- buf = emalloc(len + 1);
-
- for (ipos = opos = 0; opos < len; opos++) {
- char c = (input[inputpos + ipos] >> nibbleshift) & 0xf;
-
- if (c < 10) {
- c += '0';
- } else {
- c += 'a' - 10;
- }
-
- buf[opos] = c;
- nibbleshift = (nibbleshift + 4) & 7;
-
- if (first-- == 0) {
- ipos++;
- first = 1;
- }
- }
-
- buf[len] = '\0';
- add_assoc_stringl(return_value, n, buf, len, 1);
- efree(buf);
- break;
- }
-
- case 'c': case 'C': {
- int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0;
- long v = php_unpack(&input[inputpos], 1, issigned, byte_map);
- add_assoc_long(return_value, n, v);
- break;
- }
-
- case 's': case 'S': case 'n': case 'v': {
- long v;
- int issigned = 0;
- int *map = machine_endian_short_map;
-
- if (type == 's') {
- issigned = input[inputpos + (machine_little_endian ? 1 : 0)] & 0x80;
- } else if (type == 'n') {
- map = big_endian_short_map;
- } else if (type == 'v') {
- map = little_endian_short_map;
- }
-
- v = php_unpack(&input[inputpos], 2, issigned, map);
- add_assoc_long(return_value, n, v);
- break;
- }
-
- case 'i': case 'I': {
- long v;
- int issigned = 0;
-
- if (type == 'i') {
- issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80;
- }
-
- v = php_unpack(&input[inputpos], sizeof(int), issigned, int_map);
- add_assoc_long(return_value, n, v);
- break;
- }
-
- case 'l': case 'L': case 'N': case 'V': {
- int issigned = 0;
- int *map = machine_endian_long_map;
- long v;
-
- if (type == 'l') {
- issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80;
- } else if (type == 'N') {
- map = big_endian_long_map;
- } else if (type == 'V') {
- map = little_endian_long_map;
- }
-
- v = php_unpack(&input[inputpos], 4, issigned, map);
- add_assoc_long(return_value, n, v);
- break;
- }
-
- case 'f': {
- float v;
-
- memcpy(&v, &input[inputpos], sizeof(float));
- add_assoc_double(return_value, n, (double)v);
- break;
- }
-
- case 'd': {
- double v;
-
- memcpy(&v, &input[inputpos], sizeof(double));
- add_assoc_double(return_value, n, v);
- break;
- }
-
- case 'x': {
- /* Do nothing with input, just skip it */
- break;
- }
-
- case 'X': {
- if (inputpos < size) {
- inputpos = -size;
- i = arg - 1; /* Break out of for loop */
-
- if (arg >= 0) {
- php_error(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
- */
-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
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/pack.h b/ext/standard/pack.h
deleted file mode 100644
index 681331619d..0000000000
--- a/ext/standard/pack.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PACK_H
-#define PACK_H
-
-PHP_MINIT_FUNCTION(pack);
-PHP_FUNCTION(pack);
-PHP_FUNCTION(unpack);
-
-#endif /* PACK_H */
diff --git a/ext/standard/pageinfo.c b/ext/standard/pageinfo.c
deleted file mode 100644
index cc5e8451e1..0000000000
--- a/ext/standard/pageinfo.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jim Winstead <jimw@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "pageinfo.h"
-#include "SAPI.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#if HAVE_PWD_H
-#ifdef PHP_WIN32
-#include "win32/pwd.h"
-#else
-#include <pwd.h>
-#endif
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <sys/stat.h>
-#ifdef PHP_WIN32
-#include <process.h>
-#endif
-
-#include "ext/standard/basic_functions.h"
-
-/* {{{ php_statpage
- */
-static void php_statpage(TSRMLS_D)
-{
- struct stat *pstat;
-
- pstat = sapi_get_stat(TSRMLS_C);
-
- if (BG(page_uid)==-1 || BG(page_gid)==-1) {
- if(pstat) {
- BG(page_uid) = pstat->st_uid;
- BG(page_gid) = pstat->st_gid;
- BG(page_inode) = pstat->st_ino;
- BG(page_mtime) = pstat->st_mtime;
- }
- }
-}
-/* }}} */
-
-/* {{{ php_getuid
- */
-long php_getuid(void)
-{
- TSRMLS_FETCH();
-
- php_statpage(TSRMLS_C);
- return (BG(page_uid));
-}
-/* }}} */
-
-long php_getgid(void)
-{
- TSRMLS_FETCH();
-
- php_statpage(TSRMLS_C);
- return (BG(page_gid));
-}
-
-/* {{{ proto int getmyuid(void)
- Get PHP script owner's UID */
-PHP_FUNCTION(getmyuid)
-{
- long uid;
-
- uid = php_getuid();
- if (uid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(uid);
- }
-}
-/* }}} */
-
-/* {{{ proto int getmygid(void)
- Get PHP script owner's GID */
-PHP_FUNCTION(getmygid)
-{
- long gid;
-
- gid = php_getgid();
- if (gid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(gid);
- }
-}
-/* }}} */
-
-/* {{{ proto int getmypid(void)
- Get current process ID */
-PHP_FUNCTION(getmypid)
-{
- int pid;
-
- pid = getpid();
- if (pid < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG((long) pid);
- }
-}
-/* }}} */
-
-/* {{{ proto int getmyinode(void)
- Get the inode of the current script being parsed */
-PHP_FUNCTION(getmyinode)
-{
- php_statpage(TSRMLS_C);
- if (BG(page_inode) < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(BG(page_inode));
- }
-}
-/* }}} */
-
-/* {{{ proto int getlastmod(void)
- Get time of last page modification */
-PHP_FUNCTION(getlastmod)
-{
- php_statpage(TSRMLS_C);
- if (BG(page_mtime) < 0) {
- RETURN_FALSE;
- } else {
- RETURN_LONG(BG(page_mtime));
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/pageinfo.h b/ext/standard/pageinfo.h
deleted file mode 100644
index 89d3e08051..0000000000
--- a/ext/standard/pageinfo.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jim Winstead <jimw@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PAGEINFO_H
-#define PAGEINFO_H
-
-PHP_FUNCTION(getmyuid);
-PHP_FUNCTION(getmygid);
-PHP_FUNCTION(getmypid);
-PHP_FUNCTION(getmyinode);
-PHP_FUNCTION(getlastmod);
-
-extern long php_getuid(void);
-extern long php_getgid(void);
-
-#endif
diff --git a/ext/standard/parsedate.y b/ext/standard/parsedate.y
deleted file mode 100644
index 6cd7ba38d8..0000000000
--- a/ext/standard/parsedate.y
+++ /dev/null
@@ -1,1028 +0,0 @@
-%{
-/*
-** Originally written by Steven M. Bellovin <smb@research.att.com> while
-** at the University of North Carolina at Chapel Hill. Later tweaked by
-** a couple of people on Usenet. Completely overhauled by Rich $alz
-** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990.
-**
-** This code is in the public domain and has no copyright.
-*/
-
-#include "php.h"
-
-#ifdef PHP_WIN32
-#include <malloc.h>
-#endif
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <time.h>
-#include <ctype.h>
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-#ifdef PHP_WIN32
-# include "win32/time.h"
-#endif
-
-#include "php_parsedate.h"
-
-#if HAVE_STDLIB_H
-# include <stdlib.h> /* for `free'; used by Bison 1.27 */
-#endif
-
-#if defined(_HPUX_SOURCE)
-#include <alloca.h>
-#endif
-
-#if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
-# define IN_CTYPE_DOMAIN(c) 1
-#else
-# define IN_CTYPE_DOMAIN(c) isascii(c)
-#endif
-
-#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
-#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
-#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
-#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
-
-/* ISDIGIT differs from ISDIGIT_LOCALE, as follows:
- - Its arg may be any int or unsigned int; it need not be an unsigned char.
- - It's guaranteed to evaluate its argument exactly once.
- - It's typically faster.
- Posix 1003.2-1992 section 2.5.2.1 page 50 lines 1556-1558 says that
- only '0' through '9' are digits. Prefer ISDIGIT to ISDIGIT_LOCALE unless
- it's important to use the locale's definition of `digit' even when the
- host does not conform to Posix. */
-#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
-
-#if defined (STDC_HEADERS) || defined (USG)
-# include <string.h>
-#endif
-
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
-# define __attribute__(x)
-#endif
-
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif
-
-/* Some old versions of bison generate parsers that use bcopy.
- That loses on systems that don't provide the function, so we have
- to redefine it here. */
-#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
-# define bcopy(from, to, len) memcpy ((to), (from), (len))
-#endif
-
-/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
- as well as gratuitiously global symbol names, so we can have multiple
- yacc generated parsers in the same program. Note that these are only
- the variables produced by yacc. If other parser generators (bison,
- byacc, etc) produce additional global names that conflict at link time,
- then those parser generators need to be fixed instead of adding those
- names to this list. */
-
-#define yymaxdepth php_gd_maxdepth
-#define yyparse php_gd_parse
-#define yylex php_gd_lex
-#define yyerror php_gd_error
-#define yylval php_gd_lval
-#define yychar php_gd_char
-#define yydebug php_gd_debug
-#define yypact php_gd_pact
-#define yyr1 php_gd_r1
-#define yyr2 php_gd_r2
-#define yydef php_gd_def
-#define yychk php_gd_chk
-#define yypgo php_gd_pgo
-#define yyact php_gd_act
-#define yyexca php_gd_exca
-#define yyerrflag php_gd_errflag
-#define yynerrs php_gd_nerrs
-#define yyps php_gd_ps
-#define yypv php_gd_pv
-#define yys php_gd_s
-#define yy_yys php_gd_yys
-#define yystate php_gd_state
-#define yytmp php_gd_tmp
-#define yyv php_gd_v
-#define yy_yyv php_gd_yyv
-#define yyval php_gd_val
-#define yylloc php_gd_lloc
-#define yyreds php_gd_reds /* With YYDEBUG defined */
-#define yytoks php_gd_toks /* With YYDEBUG defined */
-#define yylhs php_gd_yylhs
-#define yylen php_gd_yylen
-#define yydefred php_gd_yydefred
-#define yydgoto php_gd_yydgoto
-#define yysindex php_gd_yysindex
-#define yyrindex php_gd_yyrindex
-#define yygindex php_gd_yygindex
-#define yytable php_gd_yytable
-#define yycheck php_gd_yycheck
-
-static int yylex ();
-static int yyerror ();
-
-#define EPOCH 1970
-#define HOUR(x) ((x) * 60)
-
-#define MAX_BUFF_LEN 128 /* size of buffer to read the date into */
-
-/*
-** An entry in the lexical lookup table.
-*/
-typedef struct _TABLE {
- const char *name;
- int type;
- int value;
-} TABLE;
-
-
-/*
-** Meridian: am, pm, or 24-hour style.
-*/
-typedef enum _MERIDIAN {
- MERam, MERpm, MER24
-} MERIDIAN;
-
-
-/*
-** Global variables. We could get rid of most of these by using a good
-** union as the yacc stack. (This routine was originally written before
-** yacc had the %union construct.) Maybe someday; right now we only use
-** the %union very rarely.
-*/
-static const char *yyInput;
-static int yyDayOrdinal;
-static int yyDayNumber;
-static int yyHaveDate;
-static int yyHaveDay;
-static int yyHaveRel;
-static int yyHaveTime;
-static int yyHaveZone;
-static int yyTimezone;
-static int yyDay;
-static int yyHour;
-static int yyMinutes;
-static int yyMonth;
-static int yySeconds;
-static int yyYear;
-static MERIDIAN yyMeridian;
-static int yyRelDay;
-static int yyRelHour;
-static int yyRelMinutes;
-static int yyRelMonth;
-static int yyRelSeconds;
-static int yyRelYear;
-
-%}
-
-/* This grammar has 14 shift/reduce conflicts. */
-%expect 14
-
-%union {
- int Number;
- enum _MERIDIAN Meridian;
-}
-
-%token tAGO tDAY tDAY_UNIT tDAYZONE tDST tHOUR_UNIT tID
-%token tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
-%token tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
-
-%type <Number> tDAY tDAY_UNIT tDAYZONE tHOUR_UNIT tMINUTE_UNIT
-%type <Number> tMONTH tMONTH_UNIT
-%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tYEAR_UNIT tZONE
-%type <Meridian> tMERIDIAN o_merid
-
-%%
-
-spec : /* NULL */
- | spec item
- ;
-
-item : time {
- yyHaveTime++;
- }
- | zone {
- yyHaveZone++;
- }
- | date {
- yyHaveDate++;
- }
- | day {
- yyHaveDay++;
- }
- | rel {
- yyHaveRel++;
- }
- | number
- ;
-
-time : tUNUMBER tMERIDIAN {
- yyHour = $1;
- yyMinutes = 0;
- yySeconds = 0;
- yyMeridian = $2;
- }
- | tUNUMBER ':' tUNUMBER o_merid {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = 0;
- yyMeridian = $4;
- }
- | tUNUMBER ':' tUNUMBER tSNUMBER {
- yyHour = $1;
- yyMinutes = $3;
- yyMeridian = MER24;
- yyHaveZone++;
- yyTimezone = ($4 < 0
- ? -$4 % 100 + (-$4 / 100) * 60
- : - ($4 % 100 + ($4 / 100) * 60));
- }
- | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = $5;
- yyMeridian = $6;
- }
- | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
- yyHour = $1;
- yyMinutes = $3;
- yySeconds = $5;
- yyMeridian = MER24;
- yyHaveZone++;
- yyTimezone = ($6 < 0
- ? -$6 % 100 + (-$6 / 100) * 60
- : - ($6 % 100 + ($6 / 100) * 60));
- }
- ;
-
-zone : tZONE {
- yyTimezone = $1;
- }
- | tDAYZONE {
- yyTimezone = $1 - 60;
- }
- |
- tZONE tDST {
- yyTimezone = $1 - 60;
- }
- ;
-
-day : tDAY {
- yyDayOrdinal = 1;
- yyDayNumber = $1;
- }
- | tDAY ',' {
- yyDayOrdinal = 1;
- yyDayNumber = $1;
- }
- | tUNUMBER tDAY {
- yyDayOrdinal = $1;
- yyDayNumber = $2;
- }
- ;
-
-date : tUNUMBER '/' tUNUMBER {
- yyMonth = $1;
- yyDay = $3;
- }
- | tUNUMBER '/' tUNUMBER '/' tUNUMBER {
- /* Interpret as YYYY/MM/DD if $1 >= 1000, otherwise as MM/DD/YY.
- The goal in recognizing YYYY/MM/DD is solely to support legacy
- machine-generated dates like those in an RCS log listing. If
- you want portability, use the ISO 8601 format. */
- if ($1 >= 1000)
- {
- yyYear = $1;
- yyMonth = $3;
- yyDay = $5;
- }
- else
- {
- yyMonth = $1;
- yyDay = $3;
- yyYear = $5;
- }
- }
- | tUNUMBER tSNUMBER tSNUMBER {
- /* ISO 8601 format. yyyy-mm-dd. */
- yyYear = $1;
- yyMonth = -$2;
- yyDay = -$3;
- }
- | tUNUMBER tMONTH tSNUMBER {
- /* e.g. 17-JUN-1992. */
- yyDay = $1;
- yyMonth = $2;
- yyYear = -$3;
- }
- | tMONTH tUNUMBER tUNUMBER {
- yyMonth = $1;
- yyDay = $2;
- yyYear = $3;
- }
- | tMONTH tUNUMBER {
- yyMonth = $1;
- yyDay = $2;
- }
- | tMONTH tUNUMBER ',' tUNUMBER {
- yyMonth = $1;
- yyDay = $2;
- yyYear = $4;
- }
- | tUNUMBER tMONTH {
- yyMonth = $2;
- yyDay = $1;
- }
- | tUNUMBER tMONTH tUNUMBER {
- yyMonth = $2;
- yyDay = $1;
- yyYear = $3;
- }
- ;
-
-rel : relunit tAGO {
- yyRelSeconds = -yyRelSeconds;
- yyRelMinutes = -yyRelMinutes;
- yyRelHour = -yyRelHour;
- yyRelDay = -yyRelDay;
- yyRelMonth = -yyRelMonth;
- yyRelYear = -yyRelYear;
- }
- | relunit
- ;
-
-relunit : tUNUMBER tYEAR_UNIT {
- yyRelYear += $1 * $2;
- }
- | tSNUMBER tYEAR_UNIT {
- yyRelYear += $1 * $2;
- }
- | tYEAR_UNIT {
- yyRelYear += $1;
- }
- | tUNUMBER tMONTH_UNIT {
- yyRelMonth += $1 * $2;
- }
- | tSNUMBER tMONTH_UNIT {
- yyRelMonth += $1 * $2;
- }
- | tMONTH_UNIT {
- yyRelMonth += $1;
- }
- | tUNUMBER tDAY_UNIT {
- yyRelDay += $1 * $2;
- }
- | tSNUMBER tDAY_UNIT {
- yyRelDay += $1 * $2;
- }
- | tDAY_UNIT {
- yyRelDay += $1;
- }
- | tUNUMBER tHOUR_UNIT {
- yyRelHour += $1 * $2;
- }
- | tSNUMBER tHOUR_UNIT {
- yyRelHour += $1 * $2;
- }
- | tHOUR_UNIT {
- yyRelHour += $1;
- }
- | tUNUMBER tMINUTE_UNIT {
- yyRelMinutes += $1 * $2;
- }
- | tSNUMBER tMINUTE_UNIT {
- yyRelMinutes += $1 * $2;
- }
- | tMINUTE_UNIT {
- yyRelMinutes += $1;
- }
- | tUNUMBER tSEC_UNIT {
- yyRelSeconds += $1 * $2;
- }
- | tSNUMBER tSEC_UNIT {
- yyRelSeconds += $1 * $2;
- }
- | tSEC_UNIT {
- yyRelSeconds += $1;
- }
- ;
-
-number : tUNUMBER
- {
- if (yyHaveTime && yyHaveDate && !yyHaveRel)
- yyYear = $1;
- else
- {
- if ($1>10000)
- {
- yyHaveDate++;
- yyDay= ($1)%100;
- yyMonth= ($1/100)%100;
- yyYear = $1/10000;
- }
- else
- {
- yyHaveTime++;
- if ($1 < 100)
- {
- yyHour = $1;
- yyMinutes = 0;
- }
- else
- {
- yyHour = $1 / 100;
- yyMinutes = $1 % 100;
- }
- yySeconds = 0;
- yyMeridian = MER24;
- }
- }
- }
- ;
-
-o_merid : /* NULL */
- {
- $$ = MER24;
- }
- | tMERIDIAN
- {
- $$ = $1;
- }
- ;
-
-%%
-
-time_t get_date (char *p, time_t *now);
-
-#ifndef PHP_WIN32
-extern struct tm *gmtime();
-extern struct tm *localtime();
-extern time_t mktime();
-#endif
-
-/* Month and day table. */
-static TABLE const MonthDayTable[] = {
- { "january", tMONTH, 1 },
- { "february", tMONTH, 2 },
- { "march", tMONTH, 3 },
- { "april", tMONTH, 4 },
- { "may", tMONTH, 5 },
- { "june", tMONTH, 6 },
- { "july", tMONTH, 7 },
- { "august", tMONTH, 8 },
- { "september", tMONTH, 9 },
- { "sept", tMONTH, 9 },
- { "october", tMONTH, 10 },
- { "november", tMONTH, 11 },
- { "december", tMONTH, 12 },
- { "sunday", tDAY, 0 },
- { "monday", tDAY, 1 },
- { "tuesday", tDAY, 2 },
- { "tues", tDAY, 2 },
- { "wednesday", tDAY, 3 },
- { "wednes", tDAY, 3 },
- { "thursday", tDAY, 4 },
- { "thur", tDAY, 4 },
- { "thurs", tDAY, 4 },
- { "friday", tDAY, 5 },
- { "saturday", tDAY, 6 },
- { NULL, 0, 0 }
-};
-
-/* Time units table. */
-static TABLE const UnitsTable[] = {
- { "year", tYEAR_UNIT, 1 },
- { "month", tMONTH_UNIT, 1 },
- { "fortnight", tDAY_UNIT, 14 },
- { "week", tDAY_UNIT, 7 },
- { "day", tDAY_UNIT, 1 },
- { "hour", tHOUR_UNIT, 1 },
- { "minute", tMINUTE_UNIT, 1 },
- { "min", tMINUTE_UNIT, 1 },
- { "second", tSEC_UNIT, 1 },
- { "sec", tSEC_UNIT, 1 },
- { NULL, 0, 0 }
-};
-
-/* Assorted relative-time words. */
-static TABLE const OtherTable[] = {
- { "tomorrow", tDAY_UNIT, 1 },
- { "yesterday", tDAY_UNIT, -1 },
- { "today", tDAY_UNIT, 0 },
- { "now", tDAY_UNIT, 0 },
- { "last", tUNUMBER, -1 },
- { "this", tMINUTE_UNIT, 0 },
- { "next", tUNUMBER, 1 },
- { "first", tUNUMBER, 1 },
-/* { "second", tUNUMBER, 2 }, */
- { "third", tUNUMBER, 3 },
- { "fourth", tUNUMBER, 4 },
- { "fifth", tUNUMBER, 5 },
- { "sixth", tUNUMBER, 6 },
- { "seventh", tUNUMBER, 7 },
- { "eighth", tUNUMBER, 8 },
- { "ninth", tUNUMBER, 9 },
- { "tenth", tUNUMBER, 10 },
- { "eleventh", tUNUMBER, 11 },
- { "twelfth", tUNUMBER, 12 },
- { "ago", tAGO, 1 },
- { NULL, 0, 0 }
-};
-
-/* The timezone table. */
-static TABLE const TimezoneTable[] = {
- { "gmt", tZONE, HOUR ( 0) }, /* Greenwich Mean */
- { "ut", tZONE, HOUR ( 0) }, /* Universal (Coordinated) */
- { "utc", tZONE, HOUR ( 0) },
- { "wet", tZONE, HOUR ( 0) }, /* Western European */
- { "bst", tDAYZONE, HOUR ( 0) }, /* British Summer */
- { "wat", tZONE, HOUR ( 1) }, /* West Africa */
- { "at", tZONE, HOUR ( 2) }, /* Azores */
-#if 0
- /* For completeness. BST is also British Summer, and GST is
- * also Guam Standard. */
- { "bst", tZONE, HOUR ( 3) }, /* Brazil Standard */
- { "gst", tZONE, HOUR ( 3) }, /* Greenland Standard */
-#endif
-#if 0
- { "nft", tZONE, HOUR (3.5) }, /* Newfoundland */
- { "nst", tZONE, HOUR (3.5) }, /* Newfoundland Standard */
- { "ndt", tDAYZONE, HOUR (3.5) }, /* Newfoundland Daylight */
-#endif
- { "ast", tZONE, HOUR ( 4) }, /* Atlantic Standard */
- { "adt", tDAYZONE, HOUR ( 4) }, /* Atlantic Daylight */
- { "est", tZONE, HOUR ( 5) }, /* Eastern Standard */
- { "edt", tDAYZONE, HOUR ( 5) }, /* Eastern Daylight */
- { "cst", tZONE, HOUR ( 6) }, /* Central Standard */
- { "cdt", tDAYZONE, HOUR ( 6) }, /* Central Daylight */
- { "mst", tZONE, HOUR ( 7) }, /* Mountain Standard */
- { "mdt", tDAYZONE, HOUR ( 7) }, /* Mountain Daylight */
- { "pst", tZONE, HOUR ( 8) }, /* Pacific Standard */
- { "pdt", tDAYZONE, HOUR ( 8) }, /* Pacific Daylight */
- { "yst", tZONE, HOUR ( 9) }, /* Yukon Standard */
- { "ydt", tDAYZONE, HOUR ( 9) }, /* Yukon Daylight */
- { "hst", tZONE, HOUR (10) }, /* Hawaii Standard */
- { "hdt", tDAYZONE, HOUR (10) }, /* Hawaii Daylight */
- { "cat", tZONE, HOUR (10) }, /* Central Alaska */
- { "akst", tZONE, HOUR (10) }, /* Alaska Standard */
- { "akdt", tZONE, HOUR (10) }, /* Alaska Daylight */
- { "ahst", tZONE, HOUR (10) }, /* Alaska-Hawaii Standard */
- { "nt", tZONE, HOUR (11) }, /* Nome */
- { "idlw", tZONE, HOUR (12) }, /* International Date Line West */
- { "cet", tZONE, -HOUR (1) }, /* Central European */
- { "met", tZONE, -HOUR (1) }, /* Middle European */
- { "mewt", tZONE, -HOUR (1) }, /* Middle European Winter */
- { "mest", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
- { "mesz", tDAYZONE, -HOUR (1) }, /* Middle European Summer */
- { "swt", tZONE, -HOUR (1) }, /* Swedish Winter */
- { "sst", tDAYZONE, -HOUR (1) }, /* Swedish Summer */
- { "fwt", tZONE, -HOUR (1) }, /* French Winter */
- { "fst", tDAYZONE, -HOUR (1) }, /* French Summer */
- { "eet", tZONE, -HOUR (2) }, /* Eastern Europe, USSR Zone 1 */
- { "bt", tZONE, -HOUR (3) }, /* Baghdad, USSR Zone 2 */
-#if 0
- { "it", tZONE, -HOUR (3.5) },/* Iran */
-#endif
- { "zp4", tZONE, -HOUR (4) }, /* USSR Zone 3 */
- { "zp5", tZONE, -HOUR (5) }, /* USSR Zone 4 */
-#if 0
- { "ist", tZONE, -HOUR (5.5) },/* Indian Standard */
-#endif
- { "zp6", tZONE, -HOUR (6) }, /* USSR Zone 5 */
-#if 0
- /* For completeness. NST is also Newfoundland Standard, and SST is
- * also Swedish Summer. */
- { "nst", tZONE, -HOUR (6.5) },/* North Sumatra */
- { "sst", tZONE, -HOUR (7) }, /* South Sumatra, USSR Zone 6 */
-#endif /* 0 */
- { "wast", tZONE, -HOUR (7) }, /* West Australian Standard */
- { "wadt", tDAYZONE, -HOUR (7) }, /* West Australian Daylight */
-#if 0
- { "jt", tZONE, -HOUR (7.5) },/* Java (3pm in Cronusland!) */
-#endif
- { "cct", tZONE, -HOUR (8) }, /* China Coast, USSR Zone 7 */
- { "jst", tZONE, -HOUR (9) }, /* Japan Standard, USSR Zone 8 */
-#if 0
- { "cast", tZONE, -HOUR (9.5) },/* Central Australian Standard */
- { "cadt", tDAYZONE, -HOUR (9.5) },/* Central Australian Daylight */
-#endif
- { "east", tZONE, -HOUR (10) }, /* Eastern Australian Standard */
- { "eadt", tDAYZONE, -HOUR (10) }, /* Eastern Australian Daylight */
- { "gst", tZONE, -HOUR (10) }, /* Guam Standard, USSR Zone 9 */
- { "nzt", tZONE, -HOUR (12) }, /* New Zealand */
- { "nzst", tZONE, -HOUR (12) }, /* New Zealand Standard */
- { "nzdt", tDAYZONE, -HOUR (12) }, /* New Zealand Daylight */
- { "idle", tZONE, -HOUR (12) }, /* International Date Line East */
- { NULL, 0, 0 }
-};
-
-/* Military timezone table. */
-static TABLE const MilitaryTable[] = {
- { "a", tZONE, HOUR ( 1) },
- { "b", tZONE, HOUR ( 2) },
- { "c", tZONE, HOUR ( 3) },
- { "d", tZONE, HOUR ( 4) },
- { "e", tZONE, HOUR ( 5) },
- { "f", tZONE, HOUR ( 6) },
- { "g", tZONE, HOUR ( 7) },
- { "h", tZONE, HOUR ( 8) },
- { "i", tZONE, HOUR ( 9) },
- { "k", tZONE, HOUR ( 10) },
- { "l", tZONE, HOUR ( 11) },
- { "m", tZONE, HOUR ( 12) },
- { "n", tZONE, HOUR (- 1) },
- { "o", tZONE, HOUR (- 2) },
- { "p", tZONE, HOUR (- 3) },
- { "q", tZONE, HOUR (- 4) },
- { "r", tZONE, HOUR (- 5) },
- { "s", tZONE, HOUR (- 6) },
- { "t", tZONE, HOUR (- 7) },
- { "u", tZONE, HOUR (- 8) },
- { "v", tZONE, HOUR (- 9) },
- { "w", tZONE, HOUR (-10) },
- { "x", tZONE, HOUR (-11) },
- { "y", tZONE, HOUR (-12) },
- { "z", tZONE, HOUR ( 0) },
- { NULL, 0, 0 }
-};
-
-
-
-
-/* ARGSUSED */
-static int
-yyerror (s)
- char *s ATTRIBUTE_UNUSED;
-{
- return 0;
-}
-
-static int
-ToHour (Hours, Meridian)
- int Hours;
- MERIDIAN Meridian;
-{
- switch (Meridian)
- {
- case MER24:
- if (Hours < 0 || Hours > 23)
- return -1;
- return Hours;
- case MERam:
- if (Hours < 1 || Hours > 12)
- return -1;
- if (Hours == 12)
- Hours = 0;
- return Hours;
- case MERpm:
- if (Hours < 1 || Hours > 12)
- return -1;
- if (Hours == 12)
- Hours = 0;
- return Hours + 12;
- default:
- abort ();
- }
- /* NOTREACHED */
-}
-
-static int
-ToYear (Year)
- int Year;
-{
- if (Year < 0)
- Year = -Year;
-
- /* XPG4 suggests that years 00-68 map to 2000-2068, and
- years 69-99 map to 1969-1999. */
- if (Year < 69)
- Year += 2000;
- else if (Year < 100)
- Year += 1900;
-
- return Year;
-}
-
-static int
-LookupWord (buff)
- char *buff;
-{
- register char *p;
- register char *q;
- register const TABLE *tp;
- int i;
- int abbrev;
-
- /* Make it lowercase. */
- for (p = buff; *p; p++)
- if (ISUPPER ((unsigned char) *p))
- *p = tolower (*p);
-
- if (strcmp (buff, "am") == 0 || strcmp (buff, "a.m.") == 0)
- {
- yylval.Meridian = MERam;
- return tMERIDIAN;
- }
- if (strcmp (buff, "pm") == 0 || strcmp (buff, "p.m.") == 0)
- {
- yylval.Meridian = MERpm;
- return tMERIDIAN;
- }
-
- /* See if we have an abbreviation for a month. */
- if (strlen (buff) == 3)
- abbrev = 1;
- else if (strlen (buff) == 4 && buff[3] == '.')
- {
- abbrev = 1;
- buff[3] = '\0';
- }
- else
- abbrev = 0;
-
- for (tp = MonthDayTable; tp->name; tp++)
- {
- if (abbrev)
- {
- if (strncmp (buff, tp->name, 3) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
- }
- else if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
- }
-
- for (tp = TimezoneTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
-
- if (strcmp (buff, "dst") == 0)
- return tDST;
-
- for (tp = UnitsTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
-
- /* Strip off any plural and try the units table again. */
- i = strlen (buff) - 1;
- if (buff[i] == 's')
- {
- buff[i] = '\0';
- for (tp = UnitsTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
- buff[i] = 's'; /* Put back for "this" in OtherTable. */
- }
-
- for (tp = OtherTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
-
- /* Military timezones. */
- if (buff[1] == '\0' && ISALPHA ((unsigned char) *buff))
- {
- for (tp = MilitaryTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
- }
-
- /* Drop out any periods and try the timezone table again. */
- for (i = 0, p = q = buff; *q; q++)
- if (*q != '.')
- *p++ = *q;
- else
- i++;
- *p = '\0';
- if (i)
- for (tp = TimezoneTable; tp->name; tp++)
- if (strcmp (buff, tp->name) == 0)
- {
- yylval.Number = tp->value;
- return tp->type;
- }
-
- return tID;
-}
-
-static int
-yylex ()
-{
- register unsigned char c;
- register char *p;
- char buff[20];
- int Count;
- int sign;
-
- for (;;)
- {
- while (ISSPACE ((unsigned char) *yyInput))
- yyInput++;
-
- if (ISDIGIT (c = *yyInput) || c == '-' || c == '+')
- {
- if (c == '-' || c == '+')
- {
- sign = c == '-' ? -1 : 1;
- if (!ISDIGIT (*++yyInput))
- /* skip the '-' sign */
- continue;
- }
- else
- sign = 0;
- for (yylval.Number = 0; ISDIGIT (c = *yyInput++);)
- yylval.Number = 10 * yylval.Number + c - '0';
- yyInput--;
- if (sign < 0)
- yylval.Number = -yylval.Number;
- return sign ? tSNUMBER : tUNUMBER;
- }
- if (ISALPHA (c))
- {
- for (p = buff; (c = *yyInput++, ISALPHA (c)) || c == '.';)
- if (p < &buff[sizeof buff - 1])
- *p++ = c;
- *p = '\0';
- yyInput--;
- return LookupWord (buff);
- }
- if (c != '(')
- return *yyInput++;
- Count = 0;
- do
- {
- c = *yyInput++;
- if (c == '\0')
- return c;
- if (c == '(')
- Count++;
- else if (c == ')')
- Count--;
- }
- while (Count > 0);
- }
-}
-
-#define TM_YEAR_ORIGIN 1900
-
-/* Yield A - B, measured in seconds. */
-static long
-difftm (struct tm *a, struct tm *b)
-{
- int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
- int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
- long days = (
- /* difference in day of year */
- a->tm_yday - b->tm_yday
- /* + intervening leap days */
- + ((ay >> 2) - (by >> 2))
- - (ay / 100 - by / 100)
- + ((ay / 100 >> 2) - (by / 100 >> 2))
- /* + difference in years * 365 */
- + (long) (ay - by) * 365
- );
- return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour))
- + (a->tm_min - b->tm_min))
- + (a->tm_sec - b->tm_sec));
-}
-
-time_t php_parse_date(char *p, time_t *now)
-{
- struct tm tm, tm0, *tmp;
- time_t Start;
-
- yyInput = p;
- Start = now ? *now : time ((time_t *) NULL);
- tmp = localtime (&Start);
- if (!tmp)
- return -1;
- yyYear = tmp->tm_year + TM_YEAR_ORIGIN;
- yyMonth = tmp->tm_mon + 1;
- yyDay = tmp->tm_mday;
- yyHour = tmp->tm_hour;
- yyMinutes = tmp->tm_min;
- yySeconds = tmp->tm_sec;
- tm.tm_isdst = tmp->tm_isdst;
- yyMeridian = MER24;
- yyRelSeconds = 0;
- yyRelMinutes = 0;
- yyRelHour = 0;
- yyRelDay = 0;
- yyRelMonth = 0;
- yyRelYear = 0;
- yyHaveDate = 0;
- yyHaveDay = 0;
- yyHaveRel = 0;
- yyHaveTime = 0;
- yyHaveZone = 0;
-
- if (yyparse ()
- || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
- return -1;
-
- tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear;
- tm.tm_mon = yyMonth - 1 + yyRelMonth;
- tm.tm_mday = yyDay + yyRelDay;
- if (yyHaveTime || (yyHaveRel && !yyHaveDate && !yyHaveDay))
- {
- tm.tm_hour = ToHour (yyHour, yyMeridian);
- if (tm.tm_hour < 0)
- return -1;
- tm.tm_min = yyMinutes;
- tm.tm_sec = yySeconds;
- }
- else
- {
- tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
- }
- tm.tm_hour += yyRelHour;
- tm.tm_min += yyRelMinutes;
- tm.tm_sec += yyRelSeconds;
-
- /* Let mktime deduce tm_isdst if we have an absolute timestamp,
- or if the relative timestamp mentions days, months, or years. */
- if (yyHaveDate | yyHaveDay | yyHaveTime | yyRelDay | yyRelMonth | yyRelYear)
- tm.tm_isdst = -1;
-
- tm0 = tm;
-
- Start = mktime (&tm);
-
- if (Start == (time_t) -1)
- {
-
- /* Guard against falsely reporting errors near the time_t boundaries
- when parsing times in other time zones. For example, if the min
- time_t value is 1970-01-01 00:00:00 UTC and we are 8 hours ahead
- of UTC, then the min localtime value is 1970-01-01 08:00:00; if
- we apply mktime to 1970-01-01 00:00:00 we will get an error, so
- we apply mktime to 1970-01-02 08:00:00 instead and adjust the time
- zone by 24 hours to compensate. This algorithm assumes that
- there is no DST transition within a day of the time_t boundaries. */
- if (yyHaveZone)
- {
- tm = tm0;
- if (tm.tm_year <= EPOCH - TM_YEAR_ORIGIN)
- {
- tm.tm_mday++;
- yyTimezone -= 24 * 60;
- }
- else
- {
- tm.tm_mday--;
- yyTimezone += 24 * 60;
- }
- Start = mktime (&tm);
- }
-
- if (Start == (time_t) -1)
- return Start;
- }
-
- if (yyHaveDay && !yyHaveDate)
- {
- tm.tm_mday += ((yyDayNumber - tm.tm_wday + 7) % 7
- + 7 * (yyDayOrdinal - (0 < yyDayOrdinal)));
- Start = mktime (&tm);
- if (Start == (time_t) -1)
- return Start;
- }
-
- if (yyHaveZone)
- {
- long delta;
- struct tm *gmt = gmtime (&Start);
- if (!gmt)
- return -1;
- delta = yyTimezone * 60L + difftm (&tm, gmt);
- if ((Start + delta < Start) != (delta < 0))
- return -1; /* time_t overflow */
- Start += delta;
- }
-
- return Start;
-}
diff --git a/ext/standard/php_array.h b/ext/standard/php_array.h
deleted file mode 100644
index e96899af50..0000000000
--- a/ext/standard/php_array.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Zeev Suraski <zeev@zend.com> |
- | Rasmus Lerdorf <rasmus@php.net> |
- | Andrei Zmievski <andrei@ispi.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_ARRAY_H
-#define PHP_ARRAY_H
-
-PHP_MINIT_FUNCTION(array);
-PHP_MSHUTDOWN_FUNCTION(array);
-
-PHP_FUNCTION(ksort);
-PHP_FUNCTION(krsort);
-PHP_FUNCTION(natsort);
-PHP_FUNCTION(natcasesort);
-PHP_FUNCTION(asort);
-PHP_FUNCTION(arsort);
-PHP_FUNCTION(sort);
-PHP_FUNCTION(rsort);
-PHP_FUNCTION(usort);
-PHP_FUNCTION(uasort);
-PHP_FUNCTION(uksort);
-PHP_FUNCTION(array_walk);
-PHP_FUNCTION(count);
-PHP_FUNCTION(end);
-PHP_FUNCTION(prev);
-PHP_FUNCTION(next);
-PHP_FUNCTION(reset);
-PHP_FUNCTION(current);
-PHP_FUNCTION(key);
-PHP_FUNCTION(min);
-PHP_FUNCTION(max);
-PHP_FUNCTION(in_array);
-PHP_FUNCTION(array_search);
-PHP_FUNCTION(extract);
-PHP_FUNCTION(compact);
-PHP_FUNCTION(range);
-PHP_FUNCTION(shuffle);
-PHP_FUNCTION(array_multisort);
-PHP_FUNCTION(array_push);
-PHP_FUNCTION(array_pop);
-PHP_FUNCTION(array_shift);
-PHP_FUNCTION(array_unshift);
-PHP_FUNCTION(array_splice);
-PHP_FUNCTION(array_slice);
-PHP_FUNCTION(array_merge);
-PHP_FUNCTION(array_merge_recursive);
-PHP_FUNCTION(array_keys);
-PHP_FUNCTION(array_values);
-PHP_FUNCTION(array_count_values);
-PHP_FUNCTION(array_reverse);
-PHP_FUNCTION(array_reduce);
-PHP_FUNCTION(array_pad);
-PHP_FUNCTION(array_flip);
-PHP_FUNCTION(array_rand);
-PHP_FUNCTION(array_unique);
-PHP_FUNCTION(array_intersect);
-PHP_FUNCTION(array_diff);
-PHP_FUNCTION(array_sum);
-PHP_FUNCTION(array_filter);
-PHP_FUNCTION(array_map);
-PHP_FUNCTION(key_exists);
-
-HashTable* php_splice(HashTable *, int, int, zval ***, int, HashTable **);
-PHPAPI void php_array_merge(HashTable *dest, HashTable *src, int recursive);
-int multisort_compare(const void *a, const void *b);
-
-typedef struct {
- int *multisort_flags[2];
- int (*compare_func)(zval *result, zval *op1, zval *op2 TSRMLS_DC);
-} php_array_globals;
-
-#ifdef ZTS
-#define ARRAYG(v) TSRMG(array_globals_id, php_array_globals *, v)
-extern int array_globals_id;
-#else
-#define ARRAYG(v) (array_globals.v)
-extern php_array_globals array_globals;
-#endif
-
-#endif /* PHP_ARRAY_H */
diff --git a/ext/standard/php_assert.h b/ext/standard/php_assert.h
deleted file mode 100644
index bde80a8114..0000000000
--- a/ext/standard/php_assert.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_ASSERT_H
-#define PHP_ASSERT_H
-
-PHP_MINIT_FUNCTION(assert);
-PHP_MSHUTDOWN_FUNCTION(assert);
-PHP_RINIT_FUNCTION(assert);
-PHP_RSHUTDOWN_FUNCTION(assert);
-PHP_MINFO_FUNCTION(assert);
-PHP_FUNCTION(assert);
-PHP_FUNCTION(assert_options);
-
-#endif /* PHP_ASSERT_H */
diff --git a/ext/standard/php_browscap.h b/ext/standard/php_browscap.h
deleted file mode 100644
index 52436b459a..0000000000
--- a/ext/standard/php_browscap.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_BROWSCAP_H
-#define PHP_BROWSCAP_H
-
-PHP_MINIT_FUNCTION(browscap);
-PHP_MSHUTDOWN_FUNCTION(browscap);
-
-PHP_FUNCTION(get_browser);
-
-#endif /* PHP_BROWSCAP_H */
diff --git a/ext/standard/php_crypt.h b/ext/standard/php_crypt.h
deleted file mode 100644
index b4b04bbd51..0000000000
--- a/ext/standard/php_crypt.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Stig Bakken <ssb@gaurdian.no> |
- | Zeev Suraski <zeev@zend.com> |
- | Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_CRYPT_H
-#define PHP_CRYPT_H
-
-PHP_FUNCTION(crypt);
-#if HAVE_CRYPT
-PHP_MINIT_FUNCTION(crypt);
-PHP_RINIT_FUNCTION(crypt);
-#endif
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/ext/standard/php_dir.h b/ext/standard/php_dir.h
deleted file mode 100644
index 186a7cdc89..0000000000
--- a/ext/standard/php_dir.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- | PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef PHP_DIR_H
-#define PHP_DIR_H
-
-/* directory functions */
-PHP_MINIT_FUNCTION(dir);
-PHP_RINIT_FUNCTION(dir);
-PHP_FUNCTION(opendir);
-PHP_FUNCTION(closedir);
-PHP_FUNCTION(chdir);
-#if defined(HAVE_CHROOT) && !defined(ZTS)
-PHP_FUNCTION(chroot);
-#endif
-PHP_FUNCTION(getcwd);
-PHP_FUNCTION(rewinddir);
-PHP_NAMED_FUNCTION(php_if_readdir);
-PHP_FUNCTION(getdir);
-
-#endif /* PHP_DIR_H */
diff --git a/ext/standard/php_ext_syslog.h b/ext/standard/php_ext_syslog.h
deleted file mode 100644
index bf22f7e015..0000000000
--- a/ext/standard/php_ext_syslog.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Stig Sæther Bakken <ssb@fast.no> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_EXT_SYSLOG_H
-#define PHP_EXT_SYSLOG_H
-
-#ifdef HAVE_SYSLOG_H
-
-#include "php_syslog.h"
-
-PHP_MINIT_FUNCTION(syslog);
-PHP_RINIT_FUNCTION(syslog);
-PHP_RSHUTDOWN_FUNCTION(syslog);
-
-PHP_FUNCTION(openlog);
-PHP_FUNCTION(syslog);
-PHP_FUNCTION(closelog);
-PHP_FUNCTION(define_syslog_variables);
-
-#endif
-
-#endif /* PHP_EXT_SYSLOG_H */
diff --git a/ext/standard/php_filestat.h b/ext/standard/php_filestat.h
deleted file mode 100644
index d88421d951..0000000000
--- a/ext/standard/php_filestat.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jim Winstead <jimw@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_FILESTAT_H
-#define PHP_FILESTAT_H
-
-PHP_RINIT_FUNCTION(filestat);
-PHP_RSHUTDOWN_FUNCTION(filestat);
-
-PHP_FUNCTION(clearstatcache);
-PHP_FUNCTION(fileatime);
-PHP_FUNCTION(filectime);
-PHP_FUNCTION(filegroup);
-PHP_FUNCTION(fileinode);
-PHP_FUNCTION(filemtime);
-PHP_FUNCTION(fileowner);
-PHP_FUNCTION(fileperms);
-PHP_FUNCTION(filesize);
-PHP_FUNCTION(filetype);
-PHP_FUNCTION(is_writable);
-PHP_FUNCTION(is_readable);
-PHP_FUNCTION(is_executable);
-PHP_FUNCTION(is_file);
-PHP_FUNCTION(is_dir);
-PHP_FUNCTION(is_link);
-PHP_FUNCTION(file_exists);
-PHP_NAMED_FUNCTION(php_if_stat);
-PHP_NAMED_FUNCTION(php_if_lstat);
-PHP_FUNCTION(disk_total_space);
-PHP_FUNCTION(disk_free_space);
-PHP_FUNCTION(chown);
-PHP_FUNCTION(chgrp);
-PHP_FUNCTION(chmod);
-PHP_FUNCTION(touch);
-PHP_FUNCTION(clearstatcache);
-
-#define MAKE_LONG_ZVAL_INCREF(name, val)\
- MAKE_STD_ZVAL(name); \
- ZVAL_LONG(name, val); \
- name->refcount++;
-
-#ifdef PHP_WIN32
-#define S_IRUSR S_IREAD
-#define S_IWUSR S_IWRITE
-#define S_IXUSR S_IEXEC
-#define S_IRGRP S_IREAD
-#define S_IWGRP S_IWRITE
-#define S_IXGRP S_IEXEC
-#define S_IROTH S_IREAD
-#define S_IWOTH S_IWRITE
-#define S_IXOTH S_IEXEC
-
-#undef getgid
-#define getgroups(a, b) 0
-#define getgid() 1
-#define getuid() 1
-#endif
-
-#endif /* PHP_FILESTAT_H */
diff --git a/ext/standard/php_fopen_wrapper.c b/ext/standard/php_fopen_wrapper.c
deleted file mode 100644
index 82f70ac244..0000000000
--- a/ext/standard/php_fopen_wrapper.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jim Winstead <jimw@php.net> |
- | Hartmut Holzgraefe <hholzgra@php.net> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdio.h>
-#include <stdlib.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "php.h"
-#include "php_globals.h"
-#include "php_standard.h"
-#include "php_fopen_wrappers.h"
-
-
-/* {{{ php_fopen_url_wrap_php
- */
-FILE *php_fopen_url_wrap_php(const char *path, char *mode, int options, int *issock, int *socketd, char **opened_path TSRMLS_DC)
-{
- const char *res = path + 6;
-
- *issock = 0;
-
- if (!strcasecmp(res, "stdin")) {
- return fdopen(dup(STDIN_FILENO), mode);
- } else if (!strcasecmp(res, "stdout")) {
- return fdopen(dup(STDOUT_FILENO), mode);
- } else if (!strcasecmp(res, "stderr")) {
- return fdopen(dup(STDERR_FILENO), mode);
- }
-
- return NULL;
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/php_fopen_wrappers.h b/ext/standard/php_fopen_wrappers.h
deleted file mode 100644
index 40daf3d1c2..0000000000
--- a/ext/standard/php_fopen_wrappers.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jim Winstead <jimw@php.net> |
- | Hartmut Holzgraefe <hholzgra@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_FOPEN_WRAPPERS_H
-#define PHP_FOPEN_WRAPPERS_H
-
-FILE *php_fopen_url_wrap_http(const char *, char *, int, int *, int *, char ** TSRMLS_DC);
-FILE *php_fopen_url_wrap_ftp(const char *, char *, int, int *, int *, char ** TSRMLS_DC);
-FILE *php_fopen_url_wrap_php(const char *, char *, int, int *, int *, char ** TSRMLS_DC);
-
-#endif
diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h
deleted file mode 100644
index e47dab9898..0000000000
--- a/ext/standard/php_image.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_IMAGE_H
-#define PHP_IMAGE_H
-
-PHP_FUNCTION(getimagesize);
-
-#endif /* PHP_IMAGE_H */
diff --git a/ext/standard/php_incomplete_class.h b/ext/standard/php_incomplete_class.h
deleted file mode 100644
index 47d54b7b04..0000000000
--- a/ext/standard/php_incomplete_class.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_INCOMPLETE_CLASS_H
-#define PHP_INCOMPLETE_CLASS_H
-
-#include "ext/standard/basic_functions.h"
-
-#define PHP_IC_ENTRY \
- BG(incomplete_class)
-
-#define PHP_SET_CLASS_ATTRIBUTES(struc) \
- /* OBJECTS_FIXME: Fix for new object model */ \
- if (Z_OBJCE_P(struc) == BG(incomplete_class)) { \
- class_name = php_lookup_class_name(struc, &name_len, 1); \
- free_class_name = 1; \
- } else { \
- class_name = Z_OBJCE_P(struc)->name; \
- name_len = Z_OBJCE_P(struc)->name_length; \
- }
-
-#define PHP_CLEANUP_CLASS_ATTRIBUTES() \
- if (free_class_name) efree(class_name)
-
-#define PHP_CLASS_ATTRIBUTES \
- char *class_name; \
- size_t name_len; \
- zend_bool free_class_name = 0 \
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-zend_class_entry *php_create_incomplete_class(TSRMLS_D);
-
-char *php_lookup_class_name(zval *object, size_t *nlen, zend_bool del);
-void php_store_class_name(zval *object, const char *name, size_t len);
-
-#ifdef __cplusplus
-};
-#endif
-
-#endif
diff --git a/ext/standard/php_iptc.h b/ext/standard/php_iptc.h
deleted file mode 100644
index 434c0c13e5..0000000000
--- a/ext/standard/php_iptc.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Thies C. Arntzen <thies@thieso.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_IPTC_H
-#define PHP_IPTC_H
-
-PHP_FUNCTION(iptcparse);
-PHP_FUNCTION(iptcembed);
-
-#endif /* PHP_IPTC_H */
diff --git a/ext/standard/php_lcg.h b/ext/standard/php_lcg.h
deleted file mode 100644
index 05bcc83c44..0000000000
--- a/ext/standard/php_lcg.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_LCG_H
-#define PHP_LCG_H
-
-#include "ext/standard/basic_functions.h"
-
-typedef struct {
- php_int32 s1;
- php_int32 s2;
-} php_lcg_globals;
-
-double php_combined_lcg(TSRMLS_D);
-PHP_FUNCTION(lcg_value);
-
-#ifdef ZTS
-PHP_MINIT_FUNCTION(lcg);
-#define LCG(v) TSRMG(lcg_globals_id, php_lcg_globals *, v)
-#else
-PHP_RINIT_FUNCTION(lcg);
-#define LCG(v) (lcg_globals.v)
-#endif
-
-#endif
diff --git a/ext/standard/php_link.h b/ext/standard/php_link.h
deleted file mode 100644
index 298708540e..0000000000
--- a/ext/standard/php_link.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_LINK_H
-#define PHP_LINK_H
-
-#ifdef HAVE_SYMLINK
-
-PHP_FUNCTION(link);
-PHP_FUNCTION(readlink);
-PHP_FUNCTION(linkinfo);
-PHP_FUNCTION(symlink);
-
-#endif
-
-#endif /* PHP_LINK_H */
diff --git a/ext/standard/php_mail.h b/ext/standard/php_mail.h
deleted file mode 100644
index 5e5a0e54ca..0000000000
--- a/ext/standard/php_mail.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_MAIL_H
-#define PHP_MAIL_H
-
-#if HAVE_SENDMAIL
-
-PHP_FUNCTION(mail);
-PHP_FUNCTION(ezmlm_hash);
-PHP_MINFO_FUNCTION(mail);
-PHPAPI extern int php_mail(char *to, char *subject, char *message, char *headers, char *extra_cmd);
-
-#endif
-
-#endif /* PHP_MAIL_H */
diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h
deleted file mode 100644
index 7ccc384630..0000000000
--- a/ext/standard/php_math.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jim Winstead (jimw@php.net) |
- | Stig Sæther Bakken <ssb@guardian.no> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_MATH_H
-#define PHP_MATH_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);
-
-PHP_FUNCTION(exp2);
-PHP_FUNCTION(exp10);
-PHP_FUNCTION(log2);
-PHP_FUNCTION(cbrt);
-PHP_FUNCTION(hypot);
-PHP_FUNCTION(expm1);
-PHP_FUNCTION(log1p);
-PHP_FUNCTION(sinh);
-PHP_FUNCTION(cosh);
-PHP_FUNCTION(tanh);
-PHP_FUNCTION(asinh);
-PHP_FUNCTION(acosh);
-PHP_FUNCTION(atanh);
-
-#include <math.h>
-
-#ifndef M_E
-#define M_E 2.7182818284590452354 /* e */
-#endif
-
-#ifndef M_LOG2E
-#define M_LOG2E 1.4426950408889634074 /* log_2 e */
-#endif
-
-#ifndef M_LOG10E
-#define M_LOG10E 0.43429448190325182765 /* log_10 e */
-#endif
-
-#ifndef M_LN2
-#define M_LN2 0.69314718055994530942 /* log_e 2 */
-#endif
-
-#ifndef M_LN10
-#define M_LN10 2.30258509299404568402 /* log_e 10 */
-#endif
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846 /* pi */
-#endif
-
-#ifndef M_PI_2
-#define M_PI_2 1.57079632679489661923 /* pi/2 */
-#endif
-
-#ifndef M_PI_4
-#define M_PI_4 0.78539816339744830962 /* pi/4 */
-#endif
-
-#ifndef M_1_PI
-#define M_1_PI 0.31830988618379067154 /* 1/pi */
-#endif
-
-#ifndef M_2_PI
-#define M_2_PI 0.63661977236758134308 /* 2/pi */
-#endif
-
-#ifndef M_SQRTPI
-#define M_SQRTPI 1.77245385090551602729 /* sqrt(pi) */
-#endif
-
-#ifndef M_2_SQRTPI
-#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
-#endif
-
-#ifndef M_LNPI
-#define M_LNPI 1.14472988584940017414 /* ln(pi) */
-#endif
-
-#ifndef M_EULER
-#define M_EULER 0.57721566490153286061 /* Euler constant */
-#endif
-
-#ifndef M_SQRT2
-#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
-#endif
-
-#ifndef M_SQRT1_2
-#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
-#endif
-
-#ifndef M_SQRT3
-#define M_SQRT3 1.73205080756887729352 /* sqrt(3) */
-#endif
-
-#endif /* PHP_MATH_H */
diff --git a/ext/standard/php_metaphone.h b/ext/standard/php_metaphone.h
deleted file mode 100644
index eb888c6791..0000000000
--- a/ext/standard/php_metaphone.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Thies C. Arntzen <thies@thieso.net> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#ifndef PHP_METAPHONE_H
-#define PHP_METAPHONE_H
-
-PHP_FUNCTION(metaphone);
-
-#endif
diff --git a/ext/standard/php_parsedate.h b/ext/standard/php_parsedate.h
deleted file mode 100644
index e4a6af7714..0000000000
--- a/ext/standard/php_parsedate.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef PHP_PARSEDATE_H
-#define PHP_PARSEDATE_H
-
-#include <time.h>
-
-time_t php_parse_date(char *p, time_t *now);
-
-#endif
diff --git a/ext/standard/php_rand.h b/ext/standard/php_rand.h
deleted file mode 100644
index b4d7e991d0..0000000000
--- a/ext/standard/php_rand.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- | Pedro Melo <melo@ip.pt> |
- | |
- | Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#ifndef PHP_RAND_H
-#define PHP_RAND_H
-
-#include <stdlib.h>
-
-#ifndef RAND_MAX
-#define RAND_MAX (1<<15)
-#endif
-
-#if HAVE_LRAND48
-#define PHP_RAND_MAX 2147483647
-#else
-#define PHP_RAND_MAX RAND_MAX
-#endif
-
-/* Define rand Function wrapper */
-#ifdef HAVE_RANDOM
-#define php_rand() random()
-#else
-#ifdef HAVE_LRAND48
-#define php_rand() lrand48()
-#else
-#define php_rand() rand()
-#endif
-#endif
-
-/* Define srand Function wrapper */
-#ifdef HAVE_SRANDOM
-#define php_srand(seed) srandom((unsigned int)seed)
-#else
-#ifdef HAVE_SRAND48
-#define php_srand(seed) srand48((long)seed)
-#else
-#define php_srand(seed) srand((unsigned int)seed)
-#endif
-#endif
-
-#endif /* PHP_RAND_H */
diff --git a/ext/standard/php_smart_str.h b/ext/standard/php_smart_str.h
deleted file mode 100644
index 167fc1b643..0000000000
--- a/ext/standard/php_smart_str.h
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef PHP_SMART_STR_H
-#define PHP_SMART_STR_H
-
-#include "php_smart_str_public.h"
-
-#include <stdlib.h>
-#include <zend.h>
-
-#define smart_str_0(x) ((x)->c[(x)->len] = '\0')
-
-#ifndef SMART_STR_PREALLOC
-#define SMART_STR_PREALLOC 128
-#endif
-
-#define smart_str_alloc(d, n, what) {\
- if (!d->c) d->len = d->a = 0; \
- newlen = d->len + n; \
- if (newlen >= d->a) {\
- d->c = perealloc(d->c, newlen + SMART_STR_PREALLOC + 1, what); \
- d->a = newlen + SMART_STR_PREALLOC; \
- }\
-}
-
-#define smart_str_appends_ex(dest, src, what) smart_str_appendl_ex(dest, src, strlen(src), what)
-#define smart_str_appends(dest, src) smart_str_appendl(dest, src, strlen(src))
-
-#define smart_str_appendc(dest, c) smart_str_appendc_ex(dest, c, 0)
-#define smart_str_free(s) smart_str_free_ex(s, 0)
-#define smart_str_appendl(dest, src, len) smart_str_appendl_ex(dest, src, len, 0)
-#define smart_str_append(dest, src) smart_str_append_ex(dest, src, 0)
-#define smart_str_append_long(dest, val) smart_str_append_long_ex(dest, val, 0)
-
-static inline void smart_str_appendc_ex(smart_str *dest, char c, int what)
-{
- size_t newlen;
-
- smart_str_alloc(dest, 1, what);
- dest->len = newlen;
- dest->c[dest->len - 1] = c;
-}
-
-
-static inline void smart_str_free_ex(smart_str *s, int what)
-{
- if (s->c) {
- pefree(s->c, what);
- s->c = NULL;
- }
- s->a = s->len = 0;
-}
-
-static inline void smart_str_appendl_ex(smart_str *dest, const char *src, size_t len, int what)
-{
- size_t newlen;
-
- smart_str_alloc(dest, len, what);
- memcpy(dest->c + dest->len, src, len);
- dest->len = newlen;
-}
-
-static inline char *smart_str_print_long(char *buf, long num)
-{
- char *p = buf;
- long tmp = 0;
- int n = 0;
-
- if (num < 0) {
- num = -num;
- *p++ = '-';
- }
-
- while (num > 0) {
- tmp = tmp * 10 + (num % 10);
- num /= 10;
- n++;
- }
-
- do {
- *p++ = (tmp % 10) + '0';
- tmp /= 10;
- } while (--n > 0);
-
- return p;
-}
-
-static inline void smart_str_append_long_ex(smart_str *dest, long num, int type)
-{
- char buf[32];
- char *p = smart_str_print_long(buf, num);
- smart_str_appendl_ex(dest, buf, p - buf, type);
-}
-
-static inline void smart_str_append_ex(smart_str *dest, smart_str *src, int what)
-{
- smart_str_appendl_ex(dest, src->c, src->len, what);
-}
-
-static inline void smart_str_setl(smart_str *dest, const char *src, size_t len)
-{
- dest->len = len;
- dest->a = len + 1;
- dest->c = (char *) src;
-}
-
-static inline void smart_str_sets(smart_str *dest, const char *src)
-{
- smart_str_setl(dest, src, strlen(src));
-}
-
-#endif
diff --git a/ext/standard/php_smart_str_public.h b/ext/standard/php_smart_str_public.h
deleted file mode 100644
index 8093f3ed99..0000000000
--- a/ext/standard/php_smart_str_public.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-
-#ifndef PHP_SMART_STR_PUBLIC_H
-#define PHP_SMART_STR_PUBLIC_H
-
-#include <sys/types.h>
-
-typedef struct {
- char *c;
- size_t len;
- size_t a;
-} smart_str;
-
-#endif
diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h
deleted file mode 100644
index 536c13807e..0000000000
--- a/ext/standard/php_standard.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "basic_functions.h"
-#include "php_math.h"
-#include "php_string.h"
-#include "base64.h"
-#include "php_dir.h"
-#include "dns.h"
-#include "reg.h"
-#include "php_mail.h"
-#include "md5.h"
-#include "html.h"
-#include "exec.h"
-#include "file.h"
-#include "php_ext_syslog.h"
-#include "php_filestat.h"
-#include "php_browscap.h"
-#include "pack.h"
-#include "datetime.h"
-#include "microtime.h"
-#include "url.h"
-#include "pageinfo.h"
-#include "cyr_convert.h"
-#include "php_link.h"
-#include "fsock.h"
-#include "php_image.h"
-#include "php_iptc.h"
-#include "info.h"
-#include "uniqid.h"
-#include "php_var.h"
-#include "quot_print.h"
-#include "type.h"
-#include "dl.h"
-#include "php_crypt.h"
-#include "head.h"
-#include "php_lcg.h"
-#include "php_metaphone.h"
-#include "php_output.h"
-#include "php_array.h"
-#include "php_assert.h"
-
-#define phpext_standard_ptr basic_functions_module_ptr
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
deleted file mode 100644
index 5bc6bef0f8..0000000000
--- a/ext/standard/php_string.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Stig Sæther Bakken <ssb@guardian.no> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
-
-#ifndef PHP_STRING_H
-#define PHP_STRING_H
-
-PHP_FUNCTION(strspn);
-PHP_FUNCTION(strcspn);
-PHP_FUNCTION(str_replace);
-PHP_FUNCTION(chop);
-PHP_FUNCTION(trim);
-PHP_FUNCTION(ltrim);
-PHP_FUNCTION(soundex);
-PHP_FUNCTION(levenshtein);
-
-PHP_FUNCTION(count_chars);
-PHP_FUNCTION(wordwrap);
-PHP_FUNCTION(explode);
-PHP_FUNCTION(implode);
-PHP_FUNCTION(strtok);
-PHP_FUNCTION(strtoupper);
-PHP_FUNCTION(strtolower);
-PHP_FUNCTION(basename);
-PHP_FUNCTION(dirname);
-PHP_FUNCTION(pathinfo);
-PHP_FUNCTION(strstr);
-PHP_FUNCTION(strpos);
-PHP_FUNCTION(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(vprintf);
-PHP_FUNCTION(vsprintf);
-PHP_FUNCTION(addcslashes);
-PHP_FUNCTION(addslashes);
-PHP_FUNCTION(stripcslashes);
-PHP_FUNCTION(stripslashes);
-PHP_FUNCTION(chr);
-PHP_FUNCTION(ord);
-PHP_FUNCTION(nl2br);
-PHP_FUNCTION(setlocale);
-PHP_FUNCTION(localeconv);
-PHP_FUNCTION(nl_langinfo);
-PHP_FUNCTION(stristr);
-PHP_FUNCTION(chunk_split);
-PHP_FUNCTION(parse_str);
-PHP_FUNCTION(bin2hex);
-PHP_FUNCTION(similar_text);
-PHP_FUNCTION(strip_tags);
-PHP_FUNCTION(str_repeat);
-PHP_FUNCTION(substr_replace);
-PHP_FUNCTION(strnatcmp);
-PHP_FUNCTION(strnatcasecmp);
-PHP_FUNCTION(substr_count);
-PHP_FUNCTION(str_pad);
-PHP_FUNCTION(sscanf);
-#ifdef HAVE_STRCOLL
-PHP_FUNCTION(strcoll);
-#endif
-
-
-#if defined(HAVE_LOCALECONV) && defined(ZTS)
-PHP_MINIT_FUNCTION(localeconv);
-PHP_MSHUTDOWN_FUNCTION(localeconv);
-#endif
-#if HAVE_NL_LANGINFO
-PHP_MINIT_FUNCTION(nl_langinfo);
-#endif
-
-#define strnatcmp(a, b) \
- strnatcmp_ex(a, strlen(a), b, strlen(b), 0)
-#define strnatcasecmp(a, b) \
- strnatcmp_ex(a, strlen(a), b, strlen(b), 1)
-PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case);
-
-PHPAPI char *php_strtoupper(char *s, size_t len);
-PHPAPI char *php_strtolower(char *s, size_t len);
-PHPAPI char *php_strtr(char *str, int len, char *str_from, char *str_to, int trlen);
-PHPAPI char *php_addslashes(char *str, int length, int *new_length, int freeit TSRMLS_DC);
-PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int freeit, char *what, int wlength TSRMLS_DC);
-PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC);
-PHPAPI void php_stripcslashes(char *str, int *len);
-PHPAPI char *php_basename(char *str, size_t len , char *suffix, size_t sufflen);
-PHPAPI void php_dirname(char *str, int len);
-PHPAPI char *php_stristr(unsigned char *s, unsigned char *t, size_t s_len, size_t t_len);
-PHPAPI char *php_str_to_str(char *haystack, int length, char *needle,
- int needle_len, char *str, int str_len, int *_new_length);
-PHPAPI void php_trim(pval *str, pval *return_value, int mode TSRMLS_DC);
-PHPAPI void php_trim2(zval *str, zval *what, zval *return_value, int mode TSRMLS_DC);
-PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len);
-
-PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result);
-
-PHPAPI void php_implode(pval *delim, pval *arr, pval *return_value);
-PHPAPI void php_explode(pval *delim, pval *str, pval *return_value, int limit);
-
-static inline char *
-php_memnstr(char *haystack, char *needle, int needle_len, char *end)
-{
- char *p = haystack;
- char first = *needle;
-
- /* let end point to the last character where needle may start */
- end -= needle_len;
-
- while (p <= end) {
- while (*p != first)
- if (++p > end)
- return NULL;
- if (memcmp(p, needle, needle_len) == 0)
- return p;
- p++;
- }
- return NULL;
-}
-
-PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end);
-PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end);
-
-#ifndef HAVE_STRERROR
-PHPAPI char *php_strerror(int errnum);
-#define strerror php_strerror
-#endif
-
-void register_string_constants(INIT_FUNC_ARGS);
-int php_charmask(unsigned char *input, int len, char *mask TSRMLS_DC);
-
-#endif /* PHP_STRING_H */
diff --git a/ext/standard/php_var.h b/ext/standard/php_var.h
deleted file mode 100644
index f957d37e33..0000000000
--- a/ext/standard/php_var.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jani Lehtimäki <jkl@njet.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef PHP_VAR_H
-#define PHP_VAR_H
-
-#include "ext/standard/php_smart_str_public.h"
-
-PHP_FUNCTION(var_dump);
-PHP_FUNCTION(serialize);
-PHP_FUNCTION(unserialize);
-
-void php_var_dump(zval **struc, int level TSRMLS_DC);
-
-/* typdef HashTable php_serialize_data_t; */
-#define php_serialize_data_t HashTable
-
-PHPAPI void php_var_serialize(smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC);
-PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, php_serialize_data_t *var_hash TSRMLS_DC);
-
-#define PHP_VAR_SERIALIZE_INIT(var_hash) \
- zend_hash_init(&(var_hash), 10, NULL, NULL, 0)
-#define PHP_VAR_SERIALIZE_DESTROY(var_hash) \
- zend_hash_destroy(&(var_hash))
-
-#define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
- zend_hash_init(&(var_hash), 10, NULL, NULL, 0)
-#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
- zend_hash_destroy(&(var_hash))
-
-#define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \
-if (var_hash) { \
- HashPosition pos; \
- zval **zval_ref; \
- zend_hash_internal_pointer_reset_ex(var_hash, &pos); \
- while (zend_hash_get_current_data_ex(var_hash, (void **) &zval_ref, &pos) == SUCCESS) { \
- if (*zval_ref == ozval) { \
- char *string_key; \
- ulong str_key_len; \
- ulong num_key; \
- zend_hash_get_current_key_ex(var_hash, &string_key, &str_key_len, &num_key, 1, &pos); \
- /* this is our hash and it _will_ be number indexed! */ \
- zend_hash_index_update(var_hash, num_key, &nzval, sizeof(zval *), NULL); \
- break; \
- } \
- zend_hash_move_forward_ex(var_hash, &pos); \
- } \
-}
-
-PHPAPI zend_class_entry *php_create_empty_class(char *class_name, int len);
-
-#endif /* PHP_VAR_H */
diff --git a/ext/standard/quot_print.c b/ext/standard/quot_print.c
deleted file mode 100644
index 3926938e0f..0000000000
--- a/ext/standard/quot_print.c
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Kirill Maximov <kir@actimind.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include <stdlib.h>
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <string.h>
-#include <errno.h>
-
-#include "php.h"
-#include "quot_print.h"
-
-#include <stdio.h>
-
-/*
-* Converting HEX char to INT value
-*/
-static char php_hex2int(int c)
-{
- if ( isdigit(c) )
- {
- return c - '0';
- }
- else if ( c >= 'A' && c <= 'F' )
- {
- return c - 'A' + 10;
- }
- else
- {
- 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_in, *str_out;
- int i = 0, j = 0, k;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1)==FAILURE)
- {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg1);
-
- if((*arg1)->value.str.len == 0) {
- /* shortcut */
- RETURN_EMPTY_STRING();
- }
-
- str_in = (*arg1)->value.str.val;
- str_out = emalloc((*arg1)->value.str.len+1);
- while ( str_in[i] )
- {
- switch (str_in[i])
- {
- case '=':
- if (str_in[i+1] && str_in[i+2] &&
- isxdigit((int)str_in[i+1]) &&
- isxdigit((int)str_in[i+1]) )
- {
- str_out[j++] = (php_hex2int((int)str_in[i+1]) << 4 )
- + php_hex2int((int)str_in[i+2]);
- i += 3;
- }
- else /* check for soft line break according to RFC 2045*/
- {
- k = 1;
- while ( str_in[i+k] && ((str_in[i+k] == 32) || (str_in[i+k] == 9)) )
- {
- /* Possibly, skip spaces/tabs at the end of line */
- k++;
- }
- if (!str_in[i+k])
- {
- /* End of line reached */
- i += k;
- }
- else if ( (str_in[i+k] == 10) && (str_in[i+k+1] == 13))
- {
- /* CRLF */
- i += k+2;
- }
- else if ( (str_in[i+k] == 13) || (str_in[i+k] == 10) )
- {
- /* CR or LF */
- i += k+1;
- }
- else
- {
- str_out[j++] = str_in[i++];
- }
- }
- break;
- default:
- str_out[j++] = str_in[i++];
- }
- }
- str_out[j] = '\0';
-
- RETVAL_STRINGL(str_out, j, 0);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/quot_print.h b/ext/standard/quot_print.h
deleted file mode 100644
index 79f9f871b9..0000000000
--- a/ext/standard/quot_print.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Kirill Maximov (kir@rus.net) |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#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 4ac3bc0507..0000000000
--- a/ext/standard/rand.c
+++ /dev/null
@@ -1,365 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Zeev Suraski <zeev@zend.com> |
- | Pedro Melo <melo@ip.pt> |
- | |
- | Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdlib.h>
-
-#include "php.h"
-#include "php_math.h"
-#include "php_rand.h"
-
-#include "basic_functions.h"
-
-/*
- This is the ``Mersenne Twister'' random number generator MT19937, which
- generates pseudorandom integers uniformly distributed in 0..(2^32 - 1)
- starting from any odd seed in 0..(2^32 - 1). This version is a recode
- by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by
- Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in
- July-August 1997).
-
- Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha
- running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to
- generate 300 million random numbers; after recoding: 24.0 sec. for the same
- (i.e., 46.5% of original time), so speed is now about 12.5 million random
- number generations per second on this machine.
-
- According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html>
- (and paraphrasing a bit in places), the Mersenne Twister is ``designed
- with consideration of the flaws of various existing generators,'' has
- a period of 2^19937 - 1, gives a sequence that is 623-dimensionally
- equidistributed, and ``has passed many stringent tests, including the
- die-hard test of G. Marsaglia and the load test of P. Hellekalek and
- S. Wegenkittl.'' It is efficient in memory usage (typically using 2506
- to 5012 bytes of static data, depending on data type sizes, and the code
- is quite short as well). It generates random numbers in batches of 624
- at a time, so the caching and pipelining of modern systems is exploited.
- It is also divide- and mod-free.
-
- This library is free software; you can redistribute it and/or modify it
- under the terms of the GNU Library General Public License as published by
- the Free Software Foundation (either version 2 of the License or, at your
- option, any later version). This library is distributed in the hope that
- it will be useful, but WITHOUT ANY WARRANTY, without even the implied
- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- the GNU Library General Public License for more details. You should have
- received a copy of the GNU Library General Public License along with this
- library; if not, write to the Free Software Foundation, Inc., 59 Temple
- Place, Suite 330, Boston, MA 02111-1307, USA.
-
- The code as Shawn received it included the following notice:
-
- Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When
- you use this, send an e-mail to <matumoto@math.keio.ac.jp> with
- an appropriate reference to your work.
-
- It would be nice to CC: <Cokus@math.washington.edu> when you write.
-
-
-
- php_uint32 must be an unsigned integer type capable of holding at least 32
- bits; exactly 32 should be fastest, but 64 is better on an Alpha with
- GCC at -O3 optimization so try your options and see what's best for you
-
- Melo: we should put some ifdefs here to catch those alphas...
-*/
-
-
-#define N MT_N /* length of state vector */
-#define M (397) /* a period parameter */
-#define K (0x9908B0DFU) /* a magic constant */
-#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */
-#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */
-#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */
-#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */
-
-#define MT_RAND_MAX ((long)(0x7FFFFFFF)) /* (1<<31) - 1 */
-
-/* {{{ seedMT
- */
-static void seedMT(php_uint32 seed TSRMLS_DC)
-{
- /*
- We initialize state[0..(N-1)] via the generator
-
- x_new = (69069 * x_old) mod 2^32
-
- from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's
- _The Art of Computer Programming_, Volume 2, 3rd ed.
-
- Notes (SJC): I do not know what the initial state requirements
- of the Mersenne Twister are, but it seems this seeding generator
- could be better. It achieves the maximum period for its modulus
- (2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if
- x_initial can be even, you have sequences like 0, 0, 0, ...;
- 2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31,
- 2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below.
-
- Even if x_initial is odd, if x_initial is 1 mod 4 then
-
- the lowest bit of x is always 1,
- the next-to-lowest bit of x is always 0,
- the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
- the 3rd-from-lowest bit of x 4-cycles ... 0 1 1 0 0 1 1 0 ... ,
- the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... ,
- ...
-
- and if x_initial is 3 mod 4 then
-
- the lowest bit of x is always 1,
- the next-to-lowest bit of x is always 1,
- the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
- the 3rd-from-lowest bit of x 4-cycles ... 0 0 1 1 0 0 1 1 ... ,
- the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... ,
- ...
-
- The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is
- 16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It
- also does well in the dimension 2..5 spectral tests, but it could be
- better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth).
-
- Note that the random number user does not see the values generated
- here directly since reloadMT() will always munge them first, so maybe
- none of all of this matters. In fact, the seed values made here could
- even be extra-special desirable if the Mersenne Twister theory says
- so-- that's why the only change I made is to restrict to odd seeds.
- */
-
- register php_uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = BG(state);
- register int j;
-
- for(BG(left)=0, *s++=x, j=N; --j;
- *s++ = (x*=69069U) & 0xFFFFFFFFU);
-}
-/* }}} */
-
-static php_uint32 reloadMT(TSRMLS_D)
-{
- register php_uint32 *p0=BG(state), *p2=BG(state)+2, *pM=BG(state)+M, s0, s1;
- register int j;
-
- if(BG(left) < -1)
- seedMT(4357U TSRMLS_CC);
-
- BG(left)=N-1, BG(next)=BG(state)+1;
-
- for(s0=BG(state)[0], s1=BG(state)[1], j=N-M+1; --j; s0=s1, s1=*p2++)
- *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
-
- for(pM=BG(state), j=M; --j; s0=s1, s1=*p2++)
- *p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
-
- s1=BG(state)[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
- s1 ^= (s1 >> 11);
- s1 ^= (s1 << 7) & 0x9D2C5680U;
- s1 ^= (s1 << 15) & 0xEFC60000U;
- return(s1 ^ (s1 >> 18));
-}
-
-
-static inline php_uint32 randomMT(void)
-{
- php_uint32 y;
- TSRMLS_FETCH();
-
- if(--BG(left) < 0)
- return(reloadMT(TSRMLS_C));
-
- y = *BG(next)++;
- y ^= (y >> 11);
- y ^= (y << 7) & 0x9D2C5680U;
- y ^= (y << 15) & 0xEFC60000U;
- return(y ^ (y >> 18));
-}
-
-/* {{{ proto void srand(int seed)
- Seeds random number generator */
-PHP_FUNCTION(srand)
-{
- pval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg);
- php_srand((*arg)->value.lval);
-}
-/* }}} */
-
-/* {{{ proto void mt_srand(int seed)
- Seeds Mersenne Twister random number generator */
-PHP_FUNCTION(mt_srand)
-{
- pval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(arg);
- seedMT((*arg)->value.lval TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ proto int rand([int min, int max])
- Returns a random number */
-PHP_FUNCTION(rand)
-{
- pval **p_min=NULL, **p_max=NULL;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 2:
- if (zend_get_parameters_ex(2, &p_min, &p_max)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(p_min);
- convert_to_long_ex(p_max);
- if ((*p_max)->value.lval-(*p_min)->value.lval < 0) {
- php_error(E_WARNING, "rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
- } else if ((*p_max)->value.lval-(*p_min)->value.lval > PHP_RAND_MAX){
- php3_error(E_WARNING, "rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- return_value->type = IS_LONG;
-
- return_value->value.lval = php_rand();
-
- /*
- * A bit of tricky math here. We want to avoid using a modulus because
- * that simply tosses the high-order bits and might skew the distribution
- * of random values over the range. Instead we map the range directly.
- *
- * We need to map the range from 0...M evenly to the range a...b
- * Let n = the random number and n' = the mapped random number
- *
- * Then we have: n' = a + n(b-a)/M
- *
- * We have a problem here in that only n==M will get mapped to b which
- # means the chances of getting b is much much less than getting any of
- # the other values in the range. We can fix this by increasing our range
- # artifically and using:
- #
- # n' = a + n(b-a+1)/M
- *
- # Now we only have a problem if n==M which would cause us to produce a
- # number of b+1 which would be bad. So we bump M up by one to make sure
- # this will never happen, and the final algorithm looks like this:
- #
- # n' = a + n(b-a+1)/(M+1)
- *
- * -RL
- */
- if (p_min && p_max) { /* implement range */
- return_value->value.lval = (*p_min)->value.lval +
- (int)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1.0) * return_value->value.lval/(PHP_RAND_MAX+1.0));
- }
-}
-/* }}} */
-
-/* {{{ proto int mt_rand([int min, int max])
- Returns a random number from Mersenne Twister */
-PHP_FUNCTION(mt_rand)
-{
- pval **p_min=NULL, **p_max=NULL;
-
- switch (ZEND_NUM_ARGS()) {
- case 0:
- break;
- case 2:
- if (zend_get_parameters_ex(2, &p_min, &p_max)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(p_min);
- convert_to_long_ex(p_max);
- if ((*p_max)->value.lval-(*p_min)->value.lval <= 0) {
- php_error(E_WARNING, "mt_rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
- }else if ((*p_max)->value.lval-(*p_min)->value.lval > MT_RAND_MAX){
- php3_error(E_WARNING, "mt_rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- return_value->type = IS_LONG;
- /*
- * Melo: hmms.. randomMT() returns 32 random bits...
- * Yet, the previous php_rand only returns 31 at most.
- * So I put a right shift to loose the lsb. It *seems*
- * better than clearing the msb.
- * Update:
- * I talked with Cokus via email and it won't ruin the algorithm
- */
- return_value->value.lval = (long)(randomMT() >> 1);
-
- if (p_min && p_max) { /* implement range */
- return_value->value.lval = (*p_min)->value.lval +
- (long)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1.0) * return_value->value.lval/(MT_RAND_MAX+1.0));
- }
-}
-/* }}} */
-
-/* {{{ proto int getrandmax(void)
- Returns the maximum value a random number can have */
-PHP_FUNCTION(getrandmax)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- 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)
-{
- if (ZEND_NUM_ARGS() != 0) {
- WRONG_PARAM_COUNT;
- }
-
- return_value->type = IS_LONG;
- /*
- * Melo: it could be 2^^32 but we only use 2^^31 to maintain
- * compatibility with the previous php_rand
- */
- return_value->value.lval = MT_RAND_MAX; /* 2^^31 */
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/reg.c b/ext/standard/reg.c
deleted file mode 100644
index fff3a4e855..0000000000
--- a/ext/standard/reg.c
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- | Jim Winstead <jimw@php.net> |
- | Jaakko Hyvätti <jaakko@hyvatti.iki.fi> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdio.h>
-#include "php.h"
-#include "php_string.h"
-#include "reg.h"
-#include "ext/standard/info.h"
-
-#if 0
-zend_module_entry regexp_module_entry = {
- "Regular Expressions",
- reg_functions,
- PHP_MINIT(regex), PHP_MSHUTDOWN(regex),
- NULL, NULL, PHP_MINFO(regex),
- STANDARD_MODULE_PROPERTIES
-};
-#endif
-
-#ifdef ZTS
-int reg_globals_id;
-#else
-static php_reg_globals reg_globals;
-#endif
-
-typedef struct {
- regex_t preg;
- int cflags;
-} reg_cache;
-
-/* {{{ _php_regcomp
- */
-static int _php_regcomp(regex_t *preg, const char *pattern, int cflags)
-{
- int r = 0;
- int patlen = strlen(pattern);
- reg_cache *rc = NULL;
- TSRMLS_FETCH();
-
- if(zend_hash_find(&REG(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(&REG(ht_rc), (char *) pattern, patlen+1,
- (void *) &rcp, sizeof(rcp), NULL);
- }
- } else {
- memcpy(preg, &rc->preg, sizeof(*preg));
- }
-
- return r;
-}
-/* }}} */
-
-static void _free_reg_cache(reg_cache *rc)
-{
- regfree(&rc->preg);
-}
-
-#undef regfree
-#define regfree(a);
-#undef regcomp
-#define regcomp(a, b, c) _php_regcomp(a, b, c)
-
-static void php_reg_init_globals(php_reg_globals *reg_globals TSRMLS_DC)
-{
- zend_hash_init(&reg_globals->ht_rc, 0, NULL, (void (*)(void *)) _free_reg_cache, 1);
-}
-
-PHP_MINIT_FUNCTION(regex)
-{
-#ifdef ZTS
- ts_allocate_id(&reg_globals_id, sizeof(php_reg_globals), (ts_allocate_ctor) php_reg_init_globals, NULL);
-#else
- php_reg_init_globals(&reg_globals TSRMLS_CC);
-#endif
-
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(regex)
-{
- zend_hash_destroy(&REG(ht_rc));
- return SUCCESS;
-}
-
-PHP_MINFO_FUNCTION(regex)
-{
-#if HSREGEX
- php_info_print_table_row(2, "Regex Library", "Bundled library enabled");
-#else
- php_info_print_table_row(2, "Regex Library", "System library enabled");
-#endif
-}
-
-
-/* This is the maximum number of (..) constructs we'll generate from a
- call to ereg() or eregi() with the optional third argument. */
-#define NS 10
-
-/* {{{ php_reg_eprint
- * php_reg_eprint - convert error number to name
- */
-static void php_reg_eprint(int err, regex_t *re) {
- char *buf = NULL, *message = NULL;
- size_t len;
- size_t buf_len;
-
-#ifdef REG_ITOA
- /* get the length of the message */
- buf_len = regerror(REG_ITOA | err, re, NULL, 0);
- if (buf_len) {
- buf = (char *)emalloc(buf_len * sizeof(char));
- if (!buf) return; /* fail silently */
- /* finally, get the error message */
- regerror(REG_ITOA | err, re, buf, buf_len);
- }
-#else
- buf_len = 0;
-#endif
- len = regerror(err, re, NULL, 0);
- if (len) {
- message = (char *)emalloc((buf_len + len + 2) * sizeof(char));
- if (!message) {
- return; /* fail silently */
- }
- if (buf_len) {
- snprintf(message, buf_len, "%s: ", buf);
- buf_len += 1; /* so pointer math below works */
- }
- /* drop the message into place */
- regerror(err, re, message + buf_len, len);
-
- php_error(E_WARNING, "%s", message);
- }
-
- STR_FREE(buf);
- STR_FREE(message);
-}
-/* }}} */
-
-/* {{{ php_ereg
- */
-static void php_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase)
-{
- pval **regex, /* Regular expression */
- **findin, /* String to apply expression to */
- **array = NULL; /* Optional register array */
- regex_t re;
- regmatch_t subs[NS];
- int err, i, match_len, string_len;
- int copts = 0;
- off_t start, end;
- char *buf = NULL;
- char *string = NULL;
-
- if (icase)
- copts |= REG_ICASE;
-
- switch(ZEND_NUM_ARGS()) {
- case 2:
- if (zend_get_parameters_ex(2, &regex, &findin) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- /* don't bother doing substring matching if we're not going
- to make use of the information */
- copts |= REG_NOSUB;
- break;
- case 3:
- if (zend_get_parameters_ex(3, &regex, &findin, &array) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
-
- /* compile the regular expression from the supplied regex */
- if ((*regex)->type == IS_STRING) {
- err = regcomp(&re, (*regex)->value.str.val, REG_EXTENDED | copts);
- } else {
- /* we convert numbers to integers and treat them as a string */
- if ((*regex)->type == IS_DOUBLE)
- convert_to_long_ex(regex); /* get rid of decimal places */
- convert_to_string_ex(regex);
- /* don't bother doing an extended regex with just a number */
- err = regcomp(&re, (*regex)->value.str.val, copts);
- }
-
- if (err) {
- php_reg_eprint(err, &re);
- RETURN_FALSE;
- }
-
- /* make a copy of the string we're looking in */
- convert_to_string_ex(findin);
- string = estrndup((*findin)->value.str.val, (*findin)->value.str.len);
-
- /* actually execute the regular expression */
- err = regexec(&re, string, (size_t) NS, subs, 0);
- if (err && err != REG_NOMATCH) {
- php_reg_eprint(err, &re);
- regfree(&re);
- RETURN_FALSE;
- }
- match_len = 1;
-
- if (array && err != REG_NOMATCH) {
- match_len = (int) (subs[0].rm_eo - subs[0].rm_so);
- string_len = strlen(string) + 1;
-
- buf = emalloc(string_len);
- if (!buf) {
- php_error(E_WARNING, "Unable to allocate memory in php_ereg");
- RETURN_FALSE;
- }
-
- pval_destructor(*array); /* start with clean array */
- array_init(*array);
-
- for (i = 0; i < NS; i++) {
- start = subs[i].rm_so;
- end = subs[i].rm_eo;
- if (start != -1 && end > 0 && start < string_len && end < string_len && start < end) {
- add_index_stringl(*array, i, string+start, end-start, 1);
- } else {
- add_index_bool(*array, i, 0);
- }
- }
- efree(buf);
- }
-
- efree(string);
- if (err == REG_NOMATCH) {
- RETVAL_FALSE;
- } else {
- if (match_len == 0)
- match_len = 1;
- RETVAL_LONG(match_len);
- }
- regfree(&re);
-}
-/* }}} */
-
-/* {{{ proto int ereg(string pattern, string string [, array registers])
- Regular expression match */
-PHP_FUNCTION(ereg)
-{
- php_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto int eregi(string pattern, string string [, array registers])
- Case-insensitive regular expression match */
-PHP_FUNCTION(eregi)
-{
- php_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ php_reg_replace
- * this is the meat and potatoes of regex replacement! */
-char *php_reg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended)
-{
- regex_t re;
- regmatch_t subs[NS];
-
- char *buf, /* buf is where we build the replaced string */
- *nbuf, /* nbuf is used when we grow the buffer */
- *walkbuf; /* used to walk buf when replacing backrefs */
- const char *walk; /* used to walk replacement string for backrefs */
- int buf_len;
- int pos, tmp, string_len, new_l;
- int err, copts = 0;
-
- string_len = strlen(string);
-
- if (icase)
- copts = REG_ICASE;
- if (extended)
- copts |= REG_EXTENDED;
- err = regcomp(&re, pattern, copts);
- if (err) {
- php_reg_eprint(err, &re);
- return ((char *) -1);
- }
-
- /* start with a buffer that is twice the size of the stringo
- we're doing replacements in */
- buf_len = 2 * string_len + 1;
- buf = emalloc(buf_len * sizeof(char));
- if (!buf) {
- php_error(E_WARNING, "Unable to allocate memory in php_reg_replace");
- regfree(&re);
- return ((char *) -1);
- }
-
- err = pos = 0;
- buf[0] = '\0';
-
- while (!err) {
- err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0));
-
- if (err && err != REG_NOMATCH) {
- php_reg_eprint(err, &re);
- regfree(&re);
- return ((char *) -1);
- }
- if (!err) {
- /* backref replacement is done in two passes:
- 1) find out how long the string will be, and allocate buf
- 2) copy the part before match, replacement and backrefs to buf
-
- Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi>
- */
-
- new_l = strlen(buf) + subs[0].rm_so; /* part before the match */
- walk = replace;
- while (*walk)
- if ('\\' == *walk
- && '0' <= walk[1] && '9' >= walk[1]
- && subs[walk[1] - '0'].rm_so > -1
- && subs[walk[1] - '0'].rm_eo > -1) {
- new_l += subs[walk[1] - '0'].rm_eo
- - subs[walk[1] - '0'].rm_so;
- walk += 2;
- } else {
- new_l++;
- walk++;
- }
-
- if (new_l + 1 > buf_len) {
- buf_len = 1 + buf_len + 2 * new_l;
- nbuf = emalloc(buf_len);
- strcpy(nbuf, buf);
- efree(buf);
- buf = nbuf;
- }
- tmp = strlen(buf);
- /* copy the part of the string before the match */
- strncat(buf, &string[pos], subs[0].rm_so);
-
- /* copy replacement and backrefs */
- walkbuf = &buf[tmp + subs[0].rm_so];
- walk = replace;
- while (*walk)
- if ('\\' == *walk
- && '0' <= walk[1] && '9' >= walk[1]
- && subs[walk[1] - '0'].rm_so > -1
- && subs[walk[1] - '0'].rm_eo > -1) {
- tmp = subs[walk[1] - '0'].rm_eo
- - subs[walk[1] - '0'].rm_so;
- memcpy (walkbuf,
- &string[pos + subs[walk[1] - '0'].rm_so],
- tmp);
- walkbuf += tmp;
- walk += 2;
- } else
- *walkbuf++ = *walk++;
- *walkbuf = '\0';
-
- /* and get ready to keep looking for replacements */
- if (subs[0].rm_so == subs[0].rm_eo) {
- if (subs[0].rm_so + pos >= string_len)
- break;
- new_l = strlen (buf) + 1;
- if (new_l + 1 > buf_len) {
- buf_len = 1 + buf_len + 2 * new_l;
- nbuf = emalloc(buf_len * sizeof(char));
- strcpy(nbuf, buf);
- efree(buf);
- buf = nbuf;
- }
- pos += subs[0].rm_eo + 1;
- buf [new_l-1] = string [pos-1];
- buf [new_l] = '\0';
- } else {
- pos += subs[0].rm_eo;
- }
- } else { /* REG_NOMATCH */
- new_l = strlen(buf) + strlen(&string[pos]);
- if (new_l + 1 > buf_len) {
- buf_len = new_l + 1; /* now we know exactly how long it is */
- nbuf = emalloc(buf_len * sizeof(char));
- strcpy(nbuf, buf);
- efree(buf);
- buf = nbuf;
- }
- /* stick that last bit of string on our output */
- strcat(buf, &string[pos]);
- }
- }
-
- /* don't want to leak memory .. */
- regfree(&re);
-
- /* whew. */
- return (buf);
-}
-/* }}} */
-
-/* {{{ php_ereg_replace
- */
-static void php_ereg_replace(INTERNAL_FUNCTION_PARAMETERS, int icase)
-{
- pval **arg_pattern,
- **arg_replace,
- **arg_string;
- char *pattern;
- char *string;
- char *replace;
- char *ret;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if ((*arg_pattern)->type == IS_STRING) {
- if ((*arg_pattern)->value.str.val && (*arg_pattern)->value.str.len)
- pattern = estrndup((*arg_pattern)->value.str.val, (*arg_pattern)->value.str.len);
- else
- pattern = empty_string;
- } else {
- convert_to_long_ex(arg_pattern);
- pattern = emalloc(2);
- pattern[0] = (char) (*arg_pattern)->value.lval;
- pattern[1] = '\0';
- }
-
- if ((*arg_replace)->type == IS_STRING) {
- if ((*arg_replace)->value.str.val && (*arg_replace)->value.str.len)
- replace = estrndup((*arg_replace)->value.str.val, (*arg_replace)->value.str.len);
- else
- replace = empty_string;
- } else {
- convert_to_long_ex(arg_replace);
- replace = emalloc(2);
- replace[0] = (char) (*arg_replace)->value.lval;
- replace[1] = '\0';
- }
-
- convert_to_string_ex(arg_string);
- if ((*arg_string)->value.str.val && (*arg_string)->value.str.len)
- string = estrndup((*arg_string)->value.str.val, (*arg_string)->value.str.len);
- else
- string = empty_string;
-
- /* do the actual work */
- ret = php_reg_replace(pattern, replace, string, icase, 1);
- if (ret == (char *) -1) {
- RETVAL_FALSE;
- } else {
- RETVAL_STRING(ret, 1);
- STR_FREE(ret);
- }
- STR_FREE(string);
- STR_FREE(replace);
- STR_FREE(pattern);
-}
-/* }}} */
-
-/* {{{ proto string ereg_replace(string pattern, string replacement, string string)
- Replace regular expression */
-PHP_FUNCTION(ereg_replace)
-{
- php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto string eregi_replace(string pattern, string replacement, string string)
- Case insensitive replace regular expression */
-PHP_FUNCTION(eregi_replace)
-{
- php_ereg_replace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ php_split
- */
-static void php_split(INTERNAL_FUNCTION_PARAMETERS, int icase)
-{
- pval **spliton, **str, **arg_count = NULL;
- regex_t re;
- regmatch_t subs[1];
- char *strp, *endp;
- int err, size, count, copts = 0;
-
- if (icase)
- copts = REG_ICASE;
-
- switch (ZEND_NUM_ARGS()) {
- case 2:
- if (zend_get_parameters_ex(2, &spliton, &str) == FAILURE)
- WRONG_PARAM_COUNT;
- count = -1;
- break;
- case 3:
- if (zend_get_parameters_ex(3, &spliton, &str, &arg_count) == FAILURE)
- WRONG_PARAM_COUNT;
- convert_to_long_ex(arg_count);
- count = (*arg_count)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(spliton);
- convert_to_string_ex(str);
-
- strp = (*str)->value.str.val;
- endp = (*str)->value.str.val + strlen((*str)->value.str.val);
-
- err = regcomp(&re, (*spliton)->value.str.val, REG_EXTENDED | copts);
- 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);
-}
-/* }}} */
-
-/* ("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)
-{
- php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-
-/* }}} */
-
-/* {{{ proto array spliti(string pattern, string string [, int limit])
- Split string into array by regular expression case-insensitive */
-
-PHP_FUNCTION(spliti)
-{
- php_split(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-
-/* }}} */
-
-/* {{{ proto string sql_regcase(string string)
- Make regular expression for case insensitive match */
-PHPAPI PHP_FUNCTION(sql_regcase)
-{
- pval **string;
- char *tmp;
- unsigned char c;
- register int i, j;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &string)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(string);
-
- tmp = (char *) emalloc((*string)->value.str.len*4+1);
-
- for (i=j=0; i<(*string)->value.str.len; i++) {
- c = (unsigned char) (*string)->value.str.val[i];
- if(isalpha(c)) {
- tmp[j++] = '[';
- tmp[j++] = toupper(c);
- tmp[j++] = tolower(c);
- tmp[j++] = ']';
- } else {
- tmp[j++] = c;
- }
- }
- tmp[j]=0;
-
- tmp = erealloc(tmp, j + 1);
-
- RETVAL_STRINGL(tmp, j, 0);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/reg.h b/ext/standard/reg.h
deleted file mode 100644
index c8adf74956..0000000000
--- a/ext/standard/reg.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-
-/* $Id$ */
-
-#ifndef REG_H
-#define REG_H
-
-char *php_reg_replace(const char *pattern, const char *replace, const char *string, int icase, int extended);
-
-PHP_FUNCTION(ereg);
-PHP_FUNCTION(eregi);
-PHP_FUNCTION(eregi_replace);
-PHP_FUNCTION(ereg_replace);
-PHP_FUNCTION(split);
-PHP_FUNCTION(spliti);
-PHPAPI PHP_FUNCTION(sql_regcase);
-
-typedef struct {
- HashTable ht_rc;
-} php_reg_globals;
-
-PHP_MINIT_FUNCTION(regex);
-PHP_MSHUTDOWN_FUNCTION(regex);
-PHP_MINFO_FUNCTION(regex);
-
-
-#ifdef ZTS
-#define REG(v) TSRMG(reg_globals_id, php_reg_globals *, v)
-#else
-#define REG(v) (reg_globals.v)
-#endif
-
-#endif /* REG_H */
diff --git a/ext/standard/scanf.c b/ext/standard/scanf.c
deleted file mode 100644
index 2d43829918..0000000000
--- a/ext/standard/scanf.c
+++ /dev/null
@@ -1,1253 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: clayton collie <clcollie@mindspring.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-/*
- scanf.c --
-
- This file contains the base code which implements sscanf and by extension
- fscanf. Original code is from TCL8.3.0 and bears the following copyright
-
-
-
- This software is copyrighted by the Regents of the University of
- California, Sun Microsystems, Inc., Scriptics Corporation,
- and other parties. The following terms apply to all files associated
- with the software unless explicitly disclaimed in individual files.
-
- The authors hereby grant permission to use, copy, modify, distribute,
- and license this software and its documentation for any purpose, provided
- that existing copyright notices are retained in all copies and that this
- notice is included verbatim in any distributions. No written agreement,
- license, or royalty fee is required for any of the authorized uses.
- Modifications to this software may be copyrighted by their authors
- and need not follow the licensing terms described here, provided that
- the new terms are clearly indicated on the first page of each file where
- they apply.
-
- IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
- FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
- ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
- DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
- THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
- IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
- NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
- MODIFICATIONS.
-
- GOVERNMENT USE: If you are acquiring this software on behalf of the
- U.S. government, the Government shall have only "Restricted Rights"
- in the software and related documentation as defined in the Federal
- Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
- are acquiring the software on behalf of the Department of Defense, the
- software shall be classified as "Commercial Computer Software" and the
- Government shall have only "Restricted Rights" as defined in Clause
- 252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
- authors grant the U.S. Government and others acting in its behalf
- permission to use and distribute the software in accordance with the
- terms specified in this license.
-
- */
-
-#include <stdio.h>
-#include <limits.h>
-#include <ctype.h>
-#include "php.h"
-#include "php_variables.h"
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-#include "zend_execute.h"
-#include "zend_operators.h"
-#include "php_globals.h"
-#include "basic_functions.h"
-#include "scanf.h"
-
-/*
- * Flag values used internally by [f|s]canf.
- */
-
-#define SCAN_NOSKIP 0x1 /* Don't skip blanks. */
-#define SCAN_SUPPRESS 0x2 /* Suppress assignment. */
-#define SCAN_UNSIGNED 0x4 /* Read an unsigned value. */
-#define SCAN_WIDTH 0x8 /* A width value was supplied. */
-
-#define SCAN_SIGNOK 0x10 /* A +/- character is allowed. */
-#define SCAN_NODIGITS 0x20 /* No digits have been scanned. */
-#define SCAN_NOZERO 0x40 /* No zero digits have been scanned. */
-#define SCAN_XOK 0x80 /* An 'x' is allowed. */
-#define SCAN_PTOK 0x100 /* Decimal point is allowed. */
-#define SCAN_EXPOK 0x200 /* An exponent is allowed. */
-
-#define UCHAR(x) (zend_uchar)(x)
-
-
-
-/*
- * The following structure contains the information associated with
- * a character set.
- */
-
-typedef struct CharSet {
- int exclude; /* 1 if this is an exclusion set. */
- int nchars;
- char *chars;
- int nranges;
- struct Range {
- char start;
- char end;
- } *ranges;
-} CharSet;
-
-/*
- * Declarations for functions used only in this file.
- */
-
-static char *BuildCharSet(CharSet *cset, char *format);
-static int CharInSet(CharSet *cset, int ch);
-static void ReleaseCharSet(CharSet *cset);
-static inline void scan_set_error_return(int numVars, pval **return_value);
-
-
-/* {{{ BuildCharSet
- *----------------------------------------------------------------------
- *
- * BuildCharSet --
- *
- * This function examines a character set format specification
- * and builds a CharSet containing the individual characters and
- * character ranges specified.
- *
- * Results:
- * Returns the next format position.
- *
- * Side effects:
- * Initializes the charset.
- *
- *----------------------------------------------------------------------
- */
-static char * BuildCharSet(CharSet *cset, char *format)
-{
- char *ch, start;
- int nranges;
- char *end;
-
- memset(cset, 0, sizeof(CharSet));
-
- ch = format;
- if (*ch == '^') {
- cset->exclude = 1;
- ch = ++format;
- }
- end = format + 1; /* verify this - cc */
-
- /*
- * Find the close bracket so we can overallocate the set.
- */
-
- if (*ch == ']') {
- ch = end++;
- }
- nranges = 0;
- while (*ch != ']') {
- if (*ch == '-') {
- nranges++;
- }
- ch = end++;
- }
-
- cset->chars = (char *) emalloc(sizeof(char) * (end - format - 1));
- if (nranges > 0) {
- cset->ranges = (struct Range *) emalloc(sizeof(struct Range)*nranges);
- } else {
- cset->ranges = NULL;
- }
-
- /*
- * Now build the character set.
- */
-
- cset->nchars = cset->nranges = 0;
- ch = format++;
- start = *ch;
- if (*ch == ']' || *ch == '-') {
- cset->chars[cset->nchars++] = *ch;
- ch = format++;
- }
- while (*ch != ']') {
- if (*format == '-') {
- /*
- * This may be the first character of a range, so don't add
- * it yet.
- */
-
- start = *ch;
- } else if (*ch == '-') {
- /*
- * Check to see if this is the last character in the set, in which
- * case it is not a range and we should add the previous character
- * as well as the dash.
- */
-
- if (*format == ']') {
- cset->chars[cset->nchars++] = start;
- cset->chars[cset->nchars++] = *ch;
- } else {
- ch = format++;
-
- /*
- * Check to see if the range is in reverse order.
- */
-
- if (start < *ch) {
- cset->ranges[cset->nranges].start = start;
- cset->ranges[cset->nranges].end = *ch;
- } else {
- cset->ranges[cset->nranges].start = *ch;
- cset->ranges[cset->nranges].end = start;
- }
- cset->nranges++;
- }
- } else {
- cset->chars[cset->nchars++] = *ch;
- }
- ch = format++;
- }
- return format;
-}
-/* }}} */
-
-/* {{{ CharInSet
- *----------------------------------------------------------------------
- *
- * CharInSet --
- *
- * Check to see if a character matches the given set.
- *
- * Results:
- * Returns non-zero if the character matches the given set.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-static int CharInSet(CharSet *cset, int c)
-{
- char ch = (char) c;
- int i, match = 0;
-
- for (i = 0; i < cset->nchars; i++) {
- if (cset->chars[i] == ch) {
- match = 1;
- break;
- }
- }
- if (!match) {
- for (i = 0; i < cset->nranges; i++) {
- if ((cset->ranges[i].start <= ch)
- && (ch <= cset->ranges[i].end)) {
- match = 1;
- break;
- }
- }
- }
- return (cset->exclude ? !match : match);
-}
-/* }}} */
-
-/* {{{ ReleaseCharSet
- *----------------------------------------------------------------------
- *
- * ReleaseCharSet --
- *
- * Free the storage associated with a character set.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-static void ReleaseCharSet(CharSet *cset)
-{
- efree((char *)cset->chars);
- if (cset->ranges) {
- efree((char *)cset->ranges);
- }
-}
-/* }}} */
-
-/* {{{ ValidateFormat
- *----------------------------------------------------------------------
- *
- * ValidateFormat --
- *
- * Parse the format string and verify that it is properly formed
- * and that there are exactly enough variables on the command line.
- *
- * Results:
- * FAILURE or SUCCESS.
- *
- * Side effects:
- * May set php_error based on abnormal conditions.
- *
- * Parameters :
- * format The format string.
- * numVars The number of variables passed to the scan command.
- * totalSubs The number of variables that will be required.
- *
- *----------------------------------------------------------------------
-*/
-PHPAPI int ValidateFormat(char *format, int numVars, int *totalSubs)
-{
-#define STATIC_LIST_SIZE 16
- int gotXpg, gotSequential, value, i, flags;
- char *end, *ch = NULL;
- int staticAssign[STATIC_LIST_SIZE];
- int *nassign = staticAssign;
- int objIndex, xpgSize, nspace = STATIC_LIST_SIZE;
- TSRMLS_FETCH();
-
- /*
- * Initialize an array that records the number of times a variable
- * is assigned to by the format string. We use this to detect if
- * a variable is multiply assigned or left unassigned.
- */
-
- if (numVars > nspace) {
- nassign = (int*)emalloc(sizeof(int) * numVars);
- nspace = numVars;
- }
- for (i = 0; i < nspace; i++) {
- nassign[i] = 0;
- }
-
- xpgSize = objIndex = gotXpg = gotSequential = 0;
-
- while (*format != '\0') {
- ch = format++;
- flags = 0;
-
- if (*ch != '%') {
- continue;
- }
- ch = format++;
- if (*ch == '%') {
- continue;
- }
- if (*ch == '*') {
- flags |= SCAN_SUPPRESS;
- ch = format++;
- goto xpgCheckDone;
- }
-
- if ( isdigit( (int)*ch ) ) {
- /*
- * Check for an XPG3-style %n$ specification. Note: there
- * must not be a mixture of XPG3 specs and non-XPG3 specs
- * in the same format string.
- */
-
- value = strtoul(format-1, &end, 10);
- if (*end != '$') {
- goto notXpg;
- }
- format = end+1;
- ch = format++;
- gotXpg = 1;
- if (gotSequential) {
- goto mixedXPG;
- }
- objIndex = value - 1;
- if ((objIndex < 0) || (numVars && (objIndex >= numVars))) {
- goto badIndex;
- } else if (numVars == 0) {
- /*
- * In the case where no vars are specified, the user can
- * specify %9999$ legally, so we have to consider special
- * rules for growing the assign array. 'value' is
- * guaranteed to be > 0.
- */
-
- /* set a lower artificial limit on this
- * in the interest of security and resource friendliness
- * 255 arguments should be more than enough. - cc
- */
- if (value > SCAN_MAX_ARGS) {
- goto badIndex;
- }
-
- xpgSize = (xpgSize > value) ? xpgSize : value;
- }
- goto xpgCheckDone;
- }
-
- notXpg:
- gotSequential = 1;
- if (gotXpg) {
- mixedXPG:
- php_error(E_WARNING,
- "cannot mix \"%\" and \"%n$\" conversion specifiers in %s", get_active_function_name(TSRMLS_C) );
- goto error;
- }
-
- xpgCheckDone:
- /*
- * Parse any width specifier.
- */
-
- if (isdigit(UCHAR(*ch))) {
- value = strtoul(format-1, &format, 10);
- flags |= SCAN_WIDTH;
- ch = format++;
- }
-
- /*
- * Ignore size specifier.
- */
-
- if ((*ch == 'l') || (*ch == 'L') || (*ch == 'h')) {
- ch = format++;
- }
-
- if (!(flags & SCAN_SUPPRESS) && numVars && (objIndex >= numVars)) {
- goto badIndex;
- }
-
- /*
- * Handle the various field types.
- */
-
- switch (*ch) {
- case 'n':
- case 'd':
- case 'D':
- case 'i':
- case 'o':
- case 'x':
- case 'X':
- case 'u':
- case 'f':
- case 'e':
- case 'E':
- case 'g':
- case 's':
- break;
- case 'c':
- /* we differ here with the TCL implementation in allowing for */
- /* a character width specification, to be more consistent with */
- /* ANSI. since Zend auto allocates space for vars, this is no */
- /* problem - cc */
- /*
- if (flags & SCAN_WIDTH) {
- php_error(E_WARNING, "field width may not be specified in %c conversion");
- goto error;
- }
- */
- break;
- case '[':
- if (*format == '\0') {
- goto badSet;
- }
- ch = format++;
- if (*ch == '^') {
- if (*format == '\0') {
- goto badSet;
- }
- ch = format++;
- }
- if (*ch == ']') {
- if (*format == '\0') {
- goto badSet;
- }
- ch = format++;
- }
- while (*ch != ']') {
- if (*format == '\0') {
- goto badSet;
- }
- ch = format++;
- }
- break;
- badSet:
- php_error(E_WARNING, "unmatched [ in format string");
- goto error;
- default:
- {
- php_error(E_WARNING, "bad scan conversion character \"%c\"", ch);
- goto error;
- }
- }
- if (!(flags & SCAN_SUPPRESS)) {
- if (objIndex >= nspace) {
- /*
- * Expand the nassign buffer. If we are using XPG specifiers,
- * make sure that we grow to a large enough size. xpgSize is
- * guaranteed to be at least one larger than objIndex.
- */
- value = nspace;
- if (xpgSize) {
- nspace = xpgSize;
- } else {
- nspace += STATIC_LIST_SIZE;
- }
- if (nassign == staticAssign) {
- nassign = (void *)emalloc(nspace * sizeof(int));
- for (i = 0; i < STATIC_LIST_SIZE; ++i) {
- nassign[i] = staticAssign[i];
- }
- } else {
- nassign = (void *)erealloc((void *)nassign, nspace * sizeof(int));
- }
- for (i = value; i < nspace; i++) {
- nassign[i] = 0;
- }
- }
- nassign[objIndex]++;
- objIndex++;
- }
- } /* while (*format != '\0') */
-
- /*
- * Verify that all of the variable were assigned exactly once.
- */
-
- if (numVars == 0) {
- if (xpgSize) {
- numVars = xpgSize;
- } else {
- numVars = objIndex;
- }
- }
- if (totalSubs) {
- *totalSubs = numVars;
- }
- for (i = 0; i < numVars; i++) {
- if (nassign[i] > 1) {
- php_error(E_WARNING, "variable is assigned by multiple \"%n$\" conversion specifiers");
- goto error;
- } else if (!xpgSize && (nassign[i] == 0)) {
- /*
- * If the space is empty, and xpgSize is 0 (means XPG wasn't
- * used, and/or numVars != 0), then too many vars were given
- */
- php_error(E_WARNING, "variable is not assigned by any conversion specifiers");
- goto error;
- }
- }
-
- if (nassign != staticAssign) {
- efree((char *)nassign);
- }
- return SCAN_SUCCESS;
-
- badIndex:
- if (gotXpg) {
- php_error(E_WARNING, "\"%n$\" argument index out of range");
- } else {
- php_error(E_WARNING, "different numbers of variable names and field specifiers");
- }
-
- error:
- if (nassign != staticAssign) {
- efree((char *)nassign);
- }
- return SCAN_ERROR_INVALID_FORMAT;
-#undef STATIC_LIST_SIZE
-}
-/* }}} */
-
-/* {{{ php_sscanf_internal
- * This is the internal function which does processing on behalf of
- * both sscanf() and fscanf()
- *
- * parameters :
- * string literal string to be processed
- * format format string
- * argCount total number of elements in the args array
- * args arguments passed in from user function (f|s)scanf
- * varStart offset (in args) of 1st variable passed in to (f|s)scanf
- * return_value set with the results of the scan
- */
-
-PHPAPI int php_sscanf_internal( char *string, char *format,
- int argCount, zval ***args,
- int varStart, pval **return_value TSRMLS_DC)
-{
- int numVars, nconversions, totalVars = -1;
- int i, value, result;
- int objIndex;
- char *end, *baseString;
- zval **current;
- char op = 0;
- int base = 0;
- int underflow = 0;
- size_t width;
- long (*fn)() = NULL;
- char *ch, sch;
- int flags;
- char buf[64]; /* Temporary buffer to hold scanned
- * number strings before they are
- * passed to strtoul. */
-
-
- /* do some sanity checking */
- if ((varStart > argCount) || (varStart < 0)){
- varStart = SCAN_MAX_ARGS + 1;
- }
- numVars = argCount - varStart;
- if (numVars < 0) {
- numVars = 0;
- }
-
-#if 0
- zend_printf("<br>in sscanf_internal : <br> string is \"%s\", format = \"%s\"<br> NumVars = %d. VarStart = %d<br>-------------------------<br>",
- string, format, numVars, varStart);
-#endif
- /*
- * Check for errors in the format string.
- */
- if (ValidateFormat(format, numVars, &totalVars) != SCAN_SUCCESS) {
- scan_set_error_return( numVars, return_value );
- return SCAN_ERROR_INVALID_FORMAT;
- }
-
- objIndex = numVars ? varStart : 0;
-
- /*
- * If any variables are passed, make sure they are all passed by reference
- */
- if (numVars) {
- for (i = varStart;i < argCount;i++){
- if ( ! PZVAL_IS_REF( *args[ i ] ) ) {
- php_error(E_WARNING, "Parameter %d to %s() must be passed by reference",
- i, get_active_function_name(TSRMLS_C));
- scan_set_error_return(numVars, return_value);
- return SCAN_ERROR_VAR_PASSED_BYVAL;
- }
- }
- }
-
-
- /*
- * Allocate space for the result objects. Only happens when no variables
- * are specified
- */
-
- if (!numVars) {
- /* allocate an array for return */
- if (array_init(*return_value) == FAILURE) {
- scan_set_error_return(0, return_value);
- return FAILURE;
- }
- for (i = 0; i < totalVars; i++) {
- if (add_next_index_null(*return_value) == FAILURE) {
- scan_set_error_return(0, return_value);
- return FAILURE;
- }
- }
- }
-
- baseString = string;
-
- /*
- * Iterate over the format string filling in the result objects until
- * we reach the end of input, the end of the format string, or there
- * is a mismatch.
- */
-
- nconversions = 0;
- /* note ! - we need to limit the loop for objIndex to keep it in bounds */
-
- while (*format != '\0') {
-
- ch = format++;
-
- flags = 0;
-
- /*
- * If we see whitespace in the format, skip whitespace in the string.
- */
-
- if ( isspace( (int)*ch ) ) {
- sch = *string;
- while ( isspace( (int)sch ) ) {
- if (*string == '\0') {
- goto done;
- }
- string++;
- sch = *string;
- }
- continue;
- }
-
- if (*ch != '%') {
- literal:
- if (*string == '\0') {
- underflow = 1;
- goto done;
- }
- sch = *string;
- string++;
- if (*ch != sch) {
- goto done;
- }
- continue;
- }
-
- ch = format++;
- if (*ch == '%') {
- goto literal;
- }
-
- /*
- * Check for assignment suppression ('*') or an XPG3-style
- * assignment ('%n$').
- */
-
- if (*ch == '*') {
- flags |= SCAN_SUPPRESS;
- ch = format++;
- } else if ( isdigit(UCHAR(*ch))) {
- value = strtoul(format-1, &end, 10);
- if (*end == '$') {
- format = end+1;
- ch = format++;
- objIndex = varStart + value;
- }
- }
-
- /*
- * Parse any width specifier.
- */
-
- if ( isdigit(UCHAR(*ch))) {
- width = strtoul(format-1, &format, 10);
- ch = format++;
- } else {
- width = 0;
- }
-
- /*
- * Ignore size specifier.
- */
-
- if ((*ch == 'l') || (*ch == 'L') || (*ch == 'h')) {
- ch = format++;
- }
-
- /*
- * Handle the various field types.
- */
-
- switch (*ch) {
- case 'n':
- if (!(flags & SCAN_SUPPRESS)) {
- if (numVars) {
- current = args[objIndex++];
- convert_to_long( *current );
- ZVAL_STRINGL( *current, string, end-string, 1);
- } else {
- add_index_long(*return_value, objIndex++, string - baseString);
- }
- }
- nconversions++;
- continue;
-
- case 'd':
- case 'D':
- op = 'i';
- base = 10;
- fn = (long (*)())strtol;
- break;
- case 'i':
- op = 'i';
- base = 0;
- fn = (long (*)())strtol;
- break;
- case 'o':
- op = 'i';
- base = 8;
- fn = (long (*)())strtol;
- break;
- case 'x':
- op = 'i';
- base = 16;
- fn = (long (*)())strtol;
- break;
- case 'u':
- op = 'i';
- base = 10;
- flags |= SCAN_UNSIGNED;
- fn = (long (*)())strtoul;
- break;
-
- case 'f':
- case 'e':
- case 'E':
- case 'g':
- op = 'f';
- break;
-
- case 's':
- op = 's';
- break;
-
- case 'c':
- op = 's';
- flags |= SCAN_NOSKIP;
- /*-cc-*/
- if (0 == width) {
- width = 1;
- }
- /*-cc-*/
- break;
- case '[':
- op = '[';
- flags |= SCAN_NOSKIP;
- break;
- } /* switch */
-
- /*
- * At this point, we will need additional characters from the
- * string to proceed.
- */
-
- if (*string == '\0') {
- underflow = 1;
- goto done;
- }
-
- /*
- * Skip any leading whitespace at the beginning of a field unless
- * the format suppresses this behavior.
- */
-
- if (!(flags & SCAN_NOSKIP)) {
- while (*string != '\0') {
- sch = *string;
- if (! isspace((int)sch) ) {
- break;
- }
- string++;
- }
- if (*string == '\0') {
- underflow = 1;
- goto done;
- }
- }
-
- /*
- * Perform the requested scanning operation.
- */
-
- switch (op) {
- case 'c':
- case 's':
- /*
- * Scan a string up to width characters or whitespace.
- */
-
- if (width == 0) {
- width = (size_t) ~0;
- }
- end = string;
- while (*end != '\0') {
- sch = *end;
- if ( isspace( (int)sch ) ) {
- break;
- }
- end++;
- if (--width == 0) {
- break;
- }
- }
- if (!(flags & SCAN_SUPPRESS)) {
- if (numVars) {
- current = args[objIndex++];
- convert_to_string( *current );
- ZVAL_STRINGL( *current, string, end-string, 1);
- } else {
- add_index_stringl( *return_value, objIndex++, string, end-string, 1);
- }
- }
- string = end;
- break;
-
- case '[': {
- CharSet cset;
-
- if (width == 0) {
- width = (size_t) ~0;
- }
- end = string;
-
- format = BuildCharSet(&cset, format);
- while (*end != '\0') {
- sch = *end;
- if (!CharInSet(&cset, (int)sch)) {
- break;
- }
- end++;
- if (--width == 0) {
- break;
- }
- }
- ReleaseCharSet(&cset);
-
- if (string == end) {
- /*
- * Nothing matched the range, stop processing
- */
- goto done;
- }
- if (!(flags & SCAN_SUPPRESS)) {
- if (numVars) {
- current = args[objIndex++];
- convert_to_string( *current );
- ZVAL_STRINGL( *current, string, end-string, 1);
- } else {
- add_index_stringl(*return_value, objIndex++, string, end-string, 1);
- }
- }
- string = end;
-
- break;
- }
- /*
- case 'c':
- / Scan a single character./
-
- sch = *string;
- string++;
- if (!(flags & SCAN_SUPPRESS)) {
- if (numVars) {
- char __buf[2];
- __buf[0] = sch;
- __buf[1] = '\0';;
- current = args[objIndex++];
- convert_to_string_ex( current );
- ZVAL_STRINGL( *current, __buf, 1, 1);
- } else {
- add_index_stringl(*return_value, objIndex++, &sch, 1, 1);
- }
- }
- break;
- */
- case 'i':
- /*
- * Scan an unsigned or signed integer.
- */
-
- /*-cc-*/
- buf[0] = '\0';
- /*-cc-*/
- if ((width == 0) || (width > sizeof(buf) - 1)) {
- width = sizeof(buf) - 1;
- }
-
- flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO;
- for (end = buf; width > 0; width--) {
- switch (*string) {
- /*
- * The 0 digit has special meaning at the beginning of
- * a number. If we are unsure of the base, it
- * indicates that we are in base 8 or base 16 (if it is
- * followed by an 'x').
- */
- case '0':
- /*-cc-*/
- if (base == 16) {
- flags |= SCAN_XOK;
- }
- /*-cc-*/
- if (base == 0) {
- base = 8;
- flags |= SCAN_XOK;
- }
- if (flags & SCAN_NOZERO) {
- flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS | SCAN_NOZERO);
- } else {
- flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS);
- }
- goto addToInt;
-
- case '1': case '2': case '3': case '4':
- case '5': case '6': case '7':
- if (base == 0) {
- base = 10;
- }
- flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS);
- goto addToInt;
-
- case '8': case '9':
- if (base == 0) {
- base = 10;
- }
- if (base <= 8) {
- break;
- }
- flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS);
- goto addToInt;
-
- case 'A': case 'B': case 'C':
- case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c':
- case 'd': case 'e': case 'f':
- if (base <= 10) {
- break;
- }
- flags &= ~(SCAN_SIGNOK | SCAN_XOK | SCAN_NODIGITS);
- goto addToInt;
-
- case '+': case '-':
- if (flags & SCAN_SIGNOK) {
- flags &= ~SCAN_SIGNOK;
- goto addToInt;
- }
- break;
-
- case 'x': case 'X':
- if ((flags & SCAN_XOK) && (end == buf+1)) {
- base = 16;
- flags &= ~SCAN_XOK;
- goto addToInt;
- }
- break;
- }
-
- /*
- * We got an illegal character so we are done accumulating.
- */
-
- break;
-
- addToInt:
- /*
- * Add the character to the temporary buffer.
- */
- *end++ = *string++;
- if (*string == '\0') {
- break;
- }
- }
-
- /*
- * Check to see if we need to back up because we only got a
- * sign or a trailing x after a 0.
- */
-
- if (flags & SCAN_NODIGITS) {
- if (*string == '\0') {
- underflow = 1;
- }
- goto done;
- } else if (end[-1] == 'x' || end[-1] == 'X') {
- end--;
- string--;
- }
-
-
- /*
- * Scan the value from the temporary buffer. If we are
- * returning a large unsigned value, we have to convert it back
- * to a string since PHP only supports signed values.
- */
-
- if (!(flags & SCAN_SUPPRESS)) {
- *end = '\0';
- value = (int) (*fn)(buf, NULL, base);
- if ((flags & SCAN_UNSIGNED) && (value < 0)) {
- sprintf(buf, "%u", value); /* INTL: ISO digit */
- if (numVars) {
- /* change passed value type to string */
- current = args[objIndex++];
- convert_to_string( *current );
- ZVAL_STRING( *current, buf, 1 );
- } else {
- add_index_string(*return_value, objIndex++, buf, 1);
- }
- } else {
- if (numVars) {
- current = args[objIndex++];
- convert_to_long( *current );
- Z_LVAL(**current) = value;
- } else {
- add_index_long(*return_value, objIndex++, value);
- }
- }
- }
-
- break;
-
- case 'f':
- /*
- * Scan a floating point number
- */
- buf[0] = '\0'; /* call me pedantic */
- if ((width == 0) || (width > sizeof(buf) - 1)) {
- width = sizeof(buf) - 1;
- }
- flags |= SCAN_SIGNOK | SCAN_NODIGITS | SCAN_PTOK | SCAN_EXPOK;
- for (end = buf; width > 0; width--) {
- switch (*string) {
- case '0': case '1': case '2': case '3':
- case '4': case '5': case '6': case '7':
- case '8': case '9':
- flags &= ~(SCAN_SIGNOK | SCAN_NODIGITS);
- goto addToFloat;
- case '+': case '-':
- if (flags & SCAN_SIGNOK) {
- flags &= ~SCAN_SIGNOK;
- goto addToFloat;
- }
- break;
- case '.':
- if (flags & SCAN_PTOK) {
- flags &= ~(SCAN_SIGNOK | SCAN_PTOK);
- goto addToFloat;
- }
- break;
- case 'e': case 'E':
- /*
- * An exponent is not allowed until there has
- * been at least one digit.
- */
-
- if ((flags & (SCAN_NODIGITS | SCAN_EXPOK)) == SCAN_EXPOK) {
- flags = (flags & ~(SCAN_EXPOK|SCAN_PTOK))
- | SCAN_SIGNOK | SCAN_NODIGITS;
- goto addToFloat;
- }
- break;
- }
-
- /*
- * We got an illegal character so we are done accumulating.
- */
-
- break;
-
- addToFloat:
- /*
- * Add the character to the temporary buffer.
- */
-
- *end++ = *string++;
- if (*string == '\0') {
- break;
- }
- }
-
- /*
- * Check to see if we need to back up because we saw a
- * trailing 'e' or sign.
- */
-
- if (flags & SCAN_NODIGITS) {
- if (flags & SCAN_EXPOK) {
- /*
- * There were no digits at all so scanning has
- * failed and we are done.
- */
- if (*string == '\0') {
- underflow = 1;
- }
- goto done;
- }
-
- /*
- * We got a bad exponent ('e' and maybe a sign).
- */
-
- end--;
- string--;
- if (*end != 'e' && *end != 'E') {
- end--;
- string--;
- }
- }
-
- /*
- * Scan the value from the temporary buffer.
- */
-
- if (!(flags & SCAN_SUPPRESS)) {
- double dvalue;
- *end = '\0';
- dvalue = strtod(buf, NULL);
- if (numVars) {
- current = args[objIndex++];
- convert_to_double( *current );
- Z_DVAL_PP( current ) = dvalue;
- } else {
- add_index_double( *return_value, objIndex++, dvalue );
- }
- }
- break;
- } /* switch (op) */
- nconversions++;
- } /* while (*format != '\0') */
-
- done:
- result = SCAN_SUCCESS;
-
- if (underflow && (0==nconversions)) {
- scan_set_error_return( numVars, return_value );
- result = SCAN_ERROR_EOF;
- } else if (numVars) {
- convert_to_long( *return_value );
- (*return_value)->value.lval = nconversions;
- } else if (nconversions < totalVars) {
- /* to do : not all elements converted. we need to prune the list - cc
- */
- }
-
- return result;
-}
-/* }}} */
-
-/* the compiler choked when i tried to make this a macro */
-static inline void scan_set_error_return(int numVars, pval **return_value)
-{
- if (numVars) {
- (*return_value)->type = IS_LONG;
- (*return_value)->value.lval = SCAN_ERROR_EOF; /* EOF marker */
- } else {
- /* pval_destructor( *return_value ); */
- /* convert_to_null calls destructor */
- convert_to_null( *return_value );
- }
-}
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/scanf.h b/ext/standard/scanf.h
deleted file mode 100644
index 8375d93237..0000000000
--- a/ext/standard/scanf.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: clayton collie <clcollie@mindspring.com> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef SCANF_H
-#define SCANF_H
-
-
-#define SCAN_MAX_ARGS 0xFF /* Maximum number of variable which can be */
- /* passed to (f|s)scanf. This is an artifical */
- /* upper limit to keep resources in check and */
- /* minimize the possibility of exploits */
-
-#define SCAN_MAX_FSCANF_BUFSIZE 512 /* Max input buffer allocated for fscanf */
-#define SCAN_SUCCESS SUCCESS
-#define SCAN_ERROR_EOF -1 /* indicates premature termination of scan */
- /* can be caused by bad parameters or format*/
- /* string. */
-#define SCAN_ERROR_INVALID_FORMAT (SCAN_ERROR_EOF - 1)
-#define SCAN_ERROR_VAR_PASSED_BYVAL (SCAN_ERROR_INVALID_FORMAT - 1)
-#define SCAN_ERROR_WRONG_PARAM_COUNT (SCAN_ERROR_VAR_PASSED_BYVAL - 1)
-#define SCAN_ERROR_INTERNAL (SCAN_ERROR_WRONG_PARAM_COUNT - 1)
-
-
-/*
- * The following are here solely for the benefit of the scanf type functions
- * e.g. fscanf
- */
-PHPAPI int ValidateFormat(char *format, int numVars, int *totalVars);
-PHPAPI int php_sscanf_internal(char *string,char *format,int argCount,zval ***args,
- int varStart, pval **return_value TSRMLS_DC);
-
-
-#endif /* SCANF_H */
diff --git a/ext/standard/soundex.c b/ext/standard/soundex.c
deleted file mode 100644
index a67462b1a0..0000000000
--- a/ext/standard/soundex.c
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-#include <stdlib.h>
-#include <errno.h>
-#include <ctype.h>
-#include "php_string.h"
-
-/* Simple soundex algorithm as described by Knuth in TAOCP, vol 3 */
-/* {{{ proto string soundex(string str)
- Calculate the soundex key of a string */
-PHP_FUNCTION(soundex)
-{
- char *somestring;
- int i, _small, len, code, last;
- pval *arg, **parg;
- char soundex[4 + 1];
-
- static char soundex_table[26] =
- {0, /* A */
- '1', /* B */
- '2', /* C */
- '3', /* D */
- 0, /* E */
- '1', /* F */
- '2', /* G */
- 0, /* H */
- 0, /* I */
- '2', /* J */
- '2', /* K */
- '4', /* L */
- '5', /* M */
- '5', /* N */
- 0, /* O */
- '1', /* P */
- '2', /* Q */
- '6', /* R */
- '2', /* S */
- '3', /* T */
- 0, /* U */
- '1', /* V */
- 0, /* W */
- '2', /* X */
- 0, /* Y */
- '2'}; /* Z */
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &parg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(parg);
- arg = *parg;
- if (arg->value.str.len==0) {
- RETURN_FALSE;
- }
- somestring = arg->value.str.val;
- len = arg->value.str.len;
-
- /* build soundex string */
- last = -1;
- for (i = 0, _small = 0; i < len && _small < 4; i++) {
- /* convert chars to upper case and strip non-letter chars */
- /* BUG: should also map here accented letters used in non */
- /* English words or names (also found in English text!): */
- /* esstsett, thorn, n-tilde, c-cedilla, s-caron, ... */
- code = toupper(somestring[i]);
- if (code >= 'A' && code <= 'Z') {
- if (_small == 0) {
- /* remember first valid char */
- soundex[_small++] = code;
- last = soundex_table[code - 'A'];
- }
- else {
- /* ignore sequences of consonants with same soundex */
- /* code in trail, and vowels unless they separate */
- /* consonant letters */
- code = soundex_table[code - 'A'];
- if (code != last) {
- if (code != 0) {
- soundex[_small++] = code;
- }
- last = code;
- }
- }
- }
- }
- /* pad with '0' and terminate with 0 ;-) */
- while (_small < 4) {
- soundex[_small++] = '0';
- }
- soundex[_small] = '\0';
-
- return_value->value.str.val = estrndup(soundex, _small);
- return_value->value.str.len = _small;
- return_value->type = IS_STRING;
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/string.c b/ext/standard/string.c
deleted file mode 100644
index 45e3d4451c..0000000000
--- a/ext/standard/string.c
+++ /dev/null
@@ -1,3753 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- | Stig Sæther Bakken <ssb@fast.no> |
- | Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
-
-#include <stdio.h>
-#include "php.h"
-#include "reg.h"
-#include "php_string.h"
-#include "php_variables.h"
-#ifdef HAVE_LOCALE_H
-# include <locale.h>
-#endif
-#ifdef HAVE_LANGINFO_H
-# include <langinfo.h>
-#endif
-#include "scanf.h"
-#include "zend_API.h"
-#include "zend_execute.h"
-#include "php_globals.h"
-#include "basic_functions.h"
-#include "php_smart_str.h"
-#ifdef ZTS
-#include "TSRM.h"
-#endif
-
-#define STR_PAD_LEFT 0
-#define STR_PAD_RIGHT 1
-#define STR_PAD_BOTH 2
-#define PHP_PATHINFO_DIRNAME 0
-#define PHP_PATHINFO_BASENAME 1
-#define PHP_PATHINFO_EXTENSION 2
-
-/* {{{ register_string_constants
- */
-void register_string_constants(INIT_FUNC_ARGS)
-{
- REGISTER_LONG_CONSTANT("STR_PAD_LEFT", STR_PAD_LEFT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", STR_PAD_RIGHT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("STR_PAD_BOTH", STR_PAD_BOTH, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("PATHINFO_DIRNAME", PHP_PATHINFO_DIRNAME, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("PATHINFO_BASENAME", PHP_PATHINFO_BASENAME, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("PATHINFO_EXTENSION", PHP_PATHINFO_EXTENSION, CONST_CS | CONST_PERSISTENT);
-
-#ifdef HAVE_LOCALECONV
- /* If last members of struct lconv equal CHAR_MAX, no grouping is done */
-
-/* This is bad, but since we are going to be hardcoding in the POSIX stuff anyway... */
-# ifndef HAVE_LIMITS_H
-# define CHAR_MAX 127
-# endif
-
- REGISTER_LONG_CONSTANT("CHAR_MAX", CHAR_MAX, CONST_CS | CONST_PERSISTENT);
-#endif
-
-#ifdef HAVE_LOCALE_H
- REGISTER_LONG_CONSTANT("LC_CTYPE", LC_CTYPE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LC_NUMERIC", LC_NUMERIC, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LC_TIME", LC_TIME, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LC_COLLATE", LC_COLLATE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LC_MONETARY", LC_MONETARY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LC_ALL", LC_ALL, CONST_CS | CONST_PERSISTENT);
-# ifdef LC_MESSAGES
- REGISTER_LONG_CONSTANT("LC_MESSAGES", LC_MESSAGES, CONST_CS | CONST_PERSISTENT);
-# endif
-#endif
-
-}
-/* }}} */
-
-int php_tag_find(char *tag, int len, char *set);
-
-/* this is read-only, so it's ok */
-static char hexconvtab[] = "0123456789abcdef";
-
-/* localeconv mutex */
-#ifdef ZTS
-static MUTEX_T locale_mutex = NULL;
-#endif
-
-/* {{{ php_bin2hex
- */
-static char *php_bin2hex(const unsigned char *old, const size_t oldlen, size_t *newlen)
-{
- unsigned char *result = NULL;
- size_t i, j;
-
- result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1);
- if(!result) {
- return result;
- }
-
- for(i = j = 0; i < oldlen; i++) {
- result[j++] = hexconvtab[old[i] >> 4];
- result[j++] = hexconvtab[old[i] & 15];
- }
- result[j] = '\0';
-
- if(newlen) *newlen = oldlen * 2 * sizeof(char);
-
- return result;
-}
-/* }}} */
-
-#ifdef HAVE_LOCALECONV
-/* {{{ localeconv_r
- * glibc's localeconv is not reentrant, so lets make it so ... sorta */
-struct lconv *localeconv_r(struct lconv *out)
-{
- struct lconv *res;
-
-# ifdef ZTS
- tsrm_mutex_lock( locale_mutex );
-# endif
-
- /* localeconv doesn't return an error condition */
- res = localeconv();
-
- *out = *res;
-
-# ifdef ZTS
- tsrm_mutex_unlock( locale_mutex );
-# endif
-
- return out;
-}
-/* }}} */
-
-# ifdef ZTS
-/* {{{ PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(localeconv)
-{
- locale_mutex = tsrm_mutex_alloc();
- return SUCCESS;
-}
-/* }}} */
-
-/* {{{ PHP_MSHUTDOWN_FUNCTION
- */
-PHP_MSHUTDOWN_FUNCTION(localeconv)
-{
- tsrm_mutex_free( locale_mutex );
- locale_mutex = NULL;
- return SUCCESS;
-}
-/* }}} */
-# endif
-#endif
-
-/* {{{ proto string bin2hex(string data)
- Converts the binary representation of data to hex */
-PHP_FUNCTION(bin2hex)
-{
- zval **data;
- char *result;
- size_t newlen;
-
- if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(data);
-
- result = php_bin2hex((*data)->value.str.val, (*data)->value.str.len, &newlen);
-
- if(!result) {
- RETURN_FALSE;
- }
-
- RETURN_STRINGL(result, newlen, 0);
-}
-/* }}} */
-
-/* {{{ proto int strspn(string str, string mask)
- Find length of initial segment consisting entirely of characters found in mask */
-PHP_FUNCTION(strspn)
-{
- zval **s1, **s2;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(s1);
- convert_to_string_ex(s2);
- RETURN_LONG(php_strspn((*s1)->value.str.val, (*s2)->value.str.val,
- (*s1)->value.str.val + (*s1)->value.str.len,
- (*s2)->value.str.val + (*s2)->value.str.len));
-}
-/* }}} */
-
-/* {{{ proto int strcspn(string str, string mask)
- Find length of initial segment consisting entirely of characters not found in mask */
-PHP_FUNCTION(strcspn)
-{
- zval **s1, **s2;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(s1);
- convert_to_string_ex(s2);
- RETURN_LONG(php_strcspn((*s1)->value.str.val, (*s2)->value.str.val,
- (*s1)->value.str.val + (*s1)->value.str.len,
- (*s2)->value.str.val + (*s2)->value.str.len));
-}
-/* }}} */
-
-/* {{{ PHP_MINIT_FUNCTION(nl_langinfo) */
-#if HAVE_NL_LANGINFO
-PHP_MINIT_FUNCTION(nl_langinfo)
-{
-#define REGISTER_NL_LANGINFO_CONSTANT(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS | CONST_PERSISTENT)
-#ifdef ABDAY_1
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_1);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_2);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_3);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_4);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_5);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_6);
- REGISTER_NL_LANGINFO_CONSTANT(ABDAY_7);
-#endif
-#ifdef DAY_1
- REGISTER_NL_LANGINFO_CONSTANT(DAY_1);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_2);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_3);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_4);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_5);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_6);
- REGISTER_NL_LANGINFO_CONSTANT(DAY_7);
-#endif
-#ifdef ABMON_1
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_1);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_2);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_3);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_4);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_5);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_6);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_7);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_8);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_9);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_10);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_11);
- REGISTER_NL_LANGINFO_CONSTANT(ABMON_12);
-#endif
-#ifdef MON_1
- REGISTER_NL_LANGINFO_CONSTANT(MON_1);
- REGISTER_NL_LANGINFO_CONSTANT(MON_2);
- REGISTER_NL_LANGINFO_CONSTANT(MON_3);
- REGISTER_NL_LANGINFO_CONSTANT(MON_4);
- REGISTER_NL_LANGINFO_CONSTANT(MON_5);
- REGISTER_NL_LANGINFO_CONSTANT(MON_6);
- REGISTER_NL_LANGINFO_CONSTANT(MON_7);
- REGISTER_NL_LANGINFO_CONSTANT(MON_8);
- REGISTER_NL_LANGINFO_CONSTANT(MON_9);
- REGISTER_NL_LANGINFO_CONSTANT(MON_10);
- REGISTER_NL_LANGINFO_CONSTANT(MON_11);
- REGISTER_NL_LANGINFO_CONSTANT(MON_12);
-#endif
-#ifdef AM_STR
- REGISTER_NL_LANGINFO_CONSTANT(AM_STR);
-#endif
-#ifdef PM_STR
- REGISTER_NL_LANGINFO_CONSTANT(PM_STR);
-#endif
-#ifdef D_T_FMT
- REGISTER_NL_LANGINFO_CONSTANT(D_T_FMT);
-#endif
-#ifdef D_FMT
- REGISTER_NL_LANGINFO_CONSTANT(D_FMT);
-#endif
-#ifdef T_FMT
- REGISTER_NL_LANGINFO_CONSTANT(T_FMT);
-#endif
-#ifdef T_FMT_AMPM
- REGISTER_NL_LANGINFO_CONSTANT(T_FMT_AMPM);
-#endif
-#ifdef ERA
- REGISTER_NL_LANGINFO_CONSTANT(ERA);
-#endif
-#ifdef ERA_YEAR
- REGISTER_NL_LANGINFO_CONSTANT(ERA_YEAR);
-#endif
-#ifdef ERA_D_T_FMT
- REGISTER_NL_LANGINFO_CONSTANT(ERA_D_T_FMT);
-#endif
-#ifdef ERA_D_FMT
- REGISTER_NL_LANGINFO_CONSTANT(ERA_D_FMT);
-#endif
-#ifdef ERA_T_FMT
- REGISTER_NL_LANGINFO_CONSTANT(ERA_T_FMT);
-#endif
-#ifdef ALT_DIGITS
- REGISTER_NL_LANGINFO_CONSTANT(ALT_DIGITS);
-#endif
-#ifdef INT_CURR_SYMBOL
- REGISTER_NL_LANGINFO_CONSTANT(INT_CURR_SYMBOL);
-#endif
-#ifdef CURRENCY_SYMBOL
- REGISTER_NL_LANGINFO_CONSTANT(CURRENCY_SYMBOL);
-#endif
-#ifdef CRNCYSTR
- REGISTER_NL_LANGINFO_CONSTANT(CRNCYSTR);
-#endif
-#ifdef MON_DECIMAL_POINT
- REGISTER_NL_LANGINFO_CONSTANT(MON_DECIMAL_POINT);
-#endif
-#ifdef MON_THOUSANDS_SEP
- REGISTER_NL_LANGINFO_CONSTANT(MON_THOUSANDS_SEP);
-#endif
-#ifdef MON_GROUPING
- REGISTER_NL_LANGINFO_CONSTANT(MON_GROUPING);
-#endif
-#ifdef POSITIVE_SIGN
- REGISTER_NL_LANGINFO_CONSTANT(POSITIVE_SIGN);
-#endif
-#ifdef NEGATIVE_SIGN
- REGISTER_NL_LANGINFO_CONSTANT(NEGATIVE_SIGN);
-#endif
-#ifdef INT_FRAC_DIGITS
- REGISTER_NL_LANGINFO_CONSTANT(INT_FRAC_DIGITS);
-#endif
-#ifdef FRAC_DIGITS
- REGISTER_NL_LANGINFO_CONSTANT(FRAC_DIGITS);
-#endif
-#ifdef P_CS_PRECEDES
- REGISTER_NL_LANGINFO_CONSTANT(P_CS_PRECEDES);
-#endif
-#ifdef P_SEP_BY_SPACE
- REGISTER_NL_LANGINFO_CONSTANT(P_SEP_BY_SPACE);
-#endif
-#ifdef N_CS_PRECEDES
- REGISTER_NL_LANGINFO_CONSTANT(N_CS_PRECEDES);
-#endif
-#ifdef N_SEP_BY_SPACE
- REGISTER_NL_LANGINFO_CONSTANT(N_SEP_BY_SPACE);
-#endif
-#ifdef P_SIGN_POSN
- REGISTER_NL_LANGINFO_CONSTANT(P_SIGN_POSN);
-#endif
-#ifdef N_SIGN_POSN
- REGISTER_NL_LANGINFO_CONSTANT(N_SIGN_POSN);
-#endif
-#ifdef DECIMAL_POINT
- REGISTER_NL_LANGINFO_CONSTANT(DECIMAL_POINT);
-#endif
-#ifdef RADIXCHAR
- REGISTER_NL_LANGINFO_CONSTANT(RADIXCHAR);
-#endif
-#ifdef THOUSANDS_SEP
- REGISTER_NL_LANGINFO_CONSTANT(THOUSANDS_SEP);
-#endif
-#ifdef THOUSEP
- REGISTER_NL_LANGINFO_CONSTANT(THOUSEP);
-#endif
-#ifdef GROUPING
- REGISTER_NL_LANGINFO_CONSTANT(GROUPING);
-#endif
-#ifdef YESEXPR
- REGISTER_NL_LANGINFO_CONSTANT(YESEXPR);
-#endif
-#ifdef NOEXPR
- REGISTER_NL_LANGINFO_CONSTANT(NOEXPR);
-#endif
-#ifdef YESSTR
- REGISTER_NL_LANGINFO_CONSTANT(YESSTR);
-#endif
-#ifdef NOSTR
- REGISTER_NL_LANGINFO_CONSTANT(NOSTR);
-#endif
-#ifdef CODESET
- REGISTER_NL_LANGINFO_CONSTANT(CODESET);
-#endif
-#undef REGISTER_NL_LANGINFO_CONSTANT
- return SUCCESS;
-}
-/* }}} */
-
-PHP_FUNCTION(nl_langinfo)
-{
- zval ** item;
- char * value;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &item) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(item);
- value = nl_langinfo(Z_LVAL_PP(item));
- if (value == NULL) {
- RETURN_FALSE;
- }
- else {
- RETURN_STRING(value, 1);
- }
-}
-#endif
-
-#ifdef HAVE_STRCOLL
-/* {{{ proto int strcoll(string str1, string str2)
- Compare two strings using the current locale */
-PHP_FUNCTION(strcoll)
-{
- zval **s1, **s2;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(s1);
- convert_to_string_ex(s2);
-
- RETURN_LONG(strcoll((const char *)(*s1)->value.str.val, (const char *)(*s2)->value.str.val));
-}
-/* }}} */
-#endif
-
-/* {{{ php_charmask
- * Fills a 256-byte bytemask with input. You can specify a range like 'a..z',
- * it needs to be incrementing.
- * Returns: FAILURE/SUCCESS wether the input was correct (i.e. no range errors)
- */
-int php_charmask(unsigned char *input, int len, char *mask TSRMLS_DC)
-{
- unsigned char *end;
- unsigned char c;
- int result = SUCCESS;
-
- memset(mask, 0, 256);
- for (end=input+len; input<end; input++) {
- c=*input;
- if (input+3<end && input[1] == '.' && input[2] == '.'
- && input[3] >= c) {
- memset(mask+c, 1, input[3] - c + 1);
- input+=3;
- } else if (input+1<end && input[0] == '.' && input[1] == '.') {
- /* Error, try to be as helpful as possible:
- (a range ending/starting with '.' won't be captured here) */
- if (end-len>=input) { /* there was no 'left' char */
- php_error(E_WARNING, "Invalid '..'-range passed to %s(), no character to the left of '..'", get_active_function_name(TSRMLS_C));
- result = FAILURE;
- continue;
- }
- if (input+2>=end) { /* there is no 'right' char */
- php_error(E_WARNING, "Invalid '..'-range passed to %s(), no character to the right of '..'", get_active_function_name(TSRMLS_C));
- result = FAILURE;
- continue;
- }
- if (input[-1] > input[2]) { /* wrong order */
- php_error(E_WARNING, "Invalid '..'-range passed to %s(), '..'-range needs to be incrementing", get_active_function_name(TSRMLS_C));
- result = FAILURE;
- continue;
- }
- /* FIXME: better error (a..b..c is the only left possibility?) */
- php_error(E_WARNING, "Invalid '..'-range passed to %s()", get_active_function_name(TSRMLS_C));
- result = FAILURE;
- continue;
- } else {
- mask[c]=1;
- }
- }
- return result;
-}
-/* }}} */
-
-/* {{{ php_trim
- Compatibility function, ports old-API to new one. (DEPRECATED)
-*/
-void php_trim(zval *str, zval *return_value, int mode TSRMLS_DC)
-{
- php_trim2(str, NULL, return_value, mode TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ php_trim2
- */
-PHPAPI void php_trim2(zval *str, zval *what, zval *return_value, int mode TSRMLS_DC)
-/* mode 1 : trim left
- mode 2 : trim right
- mode 3 : trim left and right
-
- what indicates which chars are to be trimmed. NULL->default (' \t\n\r\v\0')
-*/
-{
- register int i;
- int len = str->value.str.len;
- int trimmed = 0;
- char *c = str->value.str.val;
- char mask[256];
-
- if (what) {
- php_charmask(what->value.str.val, what->value.str.len, mask TSRMLS_CC);
- } else {
- php_charmask(" \n\r\t\v\0", 6, mask TSRMLS_CC);
- }
-
- if (mode & 1) {
- for (i = 0; i < len; i++) {
- if (mask[(unsigned char)c[i]]) {
- trimmed++;
- } else {
- break;
- }
- }
- len -= trimmed;
- c += trimmed;
- }
- if (mode & 2) {
- for (i = len - 1; i >= 0; i--) {
- if (mask[(unsigned char)c[i]]) {
- len--;
- } else {
- break;
- }
- }
- }
- RETVAL_STRINGL(c, len, 1);
-}
-/* }}} */
-
-/* {{{ proto string rtrim(string str)
- An alias for chop */
-/* }}} */
-
-/* {{{ proto string chop(string str)
- Remove trailing whitespace */
-PHP_FUNCTION(chop)
-{
- zval **str, **what;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2)
- WRONG_PARAM_COUNT;
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &str, &what);
- convert_to_string_ex(str);
- if (ZEND_NUM_ARGS() == 2)
- convert_to_string_ex(str);
-
- /* convert_to_string_ex never fails (last line: op->type = IS_STRING),
- so, not checking for that. */
-
- php_trim2(*str, ZEND_NUM_ARGS()==2?*what:NULL, return_value, 2 TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ proto string trim(string str)
- Strip whitespace from the beginning and end of a string */
-PHP_FUNCTION(trim)
-{
- zval **str, **what;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2)
- WRONG_PARAM_COUNT;
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &str, &what);
- convert_to_string_ex(str);
- if (ZEND_NUM_ARGS() == 2)
- convert_to_string_ex(str);
-
- php_trim2(*str, ZEND_NUM_ARGS()==2?*what:NULL, return_value, 3 TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ proto string ltrim(string str)
- Strip whitespace from the beginning of a string */
-PHP_FUNCTION(ltrim)
-{
- zval **str, **what;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2)
- WRONG_PARAM_COUNT;
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &str, &what);
- convert_to_string_ex(str);
- if (ZEND_NUM_ARGS() == 2)
- convert_to_string_ex(str);
-
- php_trim2(*str, ZEND_NUM_ARGS()==2?*what:NULL, return_value, 1 TSRMLS_CC);
-}
-/* }}} */
-
-/* {{{ proto string wordwrap(string str [, int width [, string break [, int cut]]])
- Wrap buffer to selected number of characters using string break char */
-PHP_FUNCTION(wordwrap)
-{
- pval **ptext, **plinelength, **pbreakchar, **cut;
- long i=0, l=0, pgr=0, linelength=0, last=0, breakcharlen, docut=0;
- char *text, *breakchar, *newtext;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 4 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &ptext, &plinelength, &pbreakchar, &cut) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(ptext);
-
- if (Z_STRVAL_PP(ptext) == 0)
- RETVAL_FALSE;
-
- text = (*ptext)->value.str.val;
-
- if (ZEND_NUM_ARGS() > 1) {
- convert_to_long_ex(plinelength);
- linelength = (*plinelength)->value.lval;
- }
- else {
- linelength = 75;
- }
-
- if (ZEND_NUM_ARGS() > 2) {
- convert_to_string_ex(pbreakchar);
- breakchar = (*pbreakchar)->value.str.val;
- breakcharlen = (*pbreakchar)->value.str.len;
- }
- else {
- breakchar = "\n";
- breakcharlen = 1;
- }
-
- if (ZEND_NUM_ARGS() > 3) {
- convert_to_long_ex(cut);
- docut = (*cut)->value.lval;
- }
-
- /* Special case for a single-character break as it needs no
- additional storage space */
-
- if (breakcharlen == 1 && docut == 0) {
- newtext = estrdup (text);
- while (newtext[i] != '\0') {
- /* prescan line to see if it is greater than linelength */
- l = 0;
- while (newtext[i+l] != breakchar[0]) {
- if (newtext[i+l] == '\0') {
- l--;
- break;
- }
- l++;
- }
- if (l >= linelength) {
- pgr = l;
- l = linelength;
- /* needs breaking; work backwards to find previous word */
- while (l >= 0) {
- if (newtext[i+l] == ' ') {
- newtext[i+l] = breakchar[0];
- break;
- }
- l--;
- }
- if (l == -1) {
- /* couldn't break is backwards, try looking forwards */
- l = linelength;
- while (l <= pgr) {
- if(newtext[i+l] == ' ') {
- newtext[i+l] = breakchar[0];
- break;
- }
- l++;
- }
- }
- }
- i += l+1;
- }
- RETVAL_STRINGL(newtext, strlen(newtext), 1);
- efree(newtext);
- }
- else {
- /* Multiple character line break */
- newtext = emalloc((*ptext)->value.str.len * (breakcharlen+1)+1);
- newtext[0] = '\0';
-
- i = 0;
- while (text[i] != '\0') {
- /* prescan line to see if it is greater than linelength */
- l = 0;
- while (text[i+l] != '\0') {
- if (text[i+l] == breakchar[0]) {
- if (breakcharlen == 1 || strncmp(text+i+l, breakchar, breakcharlen)==0)
- break;
- }
- l++;
- }
- if (l >= linelength) {
- pgr = l;
- l = linelength;
-
- /* needs breaking; work backwards to find previous word */
- while (l >= 0) {
- if (text[i+l] == ' ') {
- strncat(newtext, text+last, i+l-last);
- strcat(newtext, breakchar);
- last = i + l + 1;
- break;
- }
- l--;
- }
- if (l == -1) {
- /* couldn't break it backwards, try looking forwards */
- l = linelength - 1;
- while (l <= pgr) {
- if (docut == 0)
- {
- if (text[i+l] == ' ') {
- strncat(newtext, text+last, i+l-last);
- strcat(newtext, breakchar);
- last = i + l + 1;
- break;
- }
- }
- if (docut == 1)
- {
- if (text[i+l] == ' ' || l > i-last) {
- strncat(newtext, text+last, i+l-last+1);
- strcat(newtext, breakchar);
- last = i + l + 1;
- break;
- }
- }
- l++;
- }
- }
- i += l+1;
- }
- else {
- i += (l ? l : 1);
- }
- }
-
- if (i+l > last) {
- strcat(newtext, text+last);
- }
-
- RETVAL_STRINGL(newtext, strlen(newtext), 1);
- efree(newtext);
- }
-}
-/* }}} */
-
-/* {{{ php_explode
- */
-PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit)
-{
- char *p1, *p2, *endp;
-
- endp = str->value.str.val + str->value.str.len;
-
- p1 = str->value.str.val;
- p2 = php_memnstr(str->value.str.val, delim->value.str.val, delim->value.str.len, endp);
-
- if (p2 == NULL) {
- add_next_index_stringl(return_value, p1, str->value.str.len, 1);
- } else {
- do {
- add_next_index_stringl(return_value, p1, p2-p1, 1);
- p1 = p2 + delim->value.str.len;
- } while ((p2 = php_memnstr(p1, delim->value.str.val, delim->value.str.len, endp)) != NULL &&
- (limit == -1 || --limit > 1));
-
- if (p1 <= endp)
- add_next_index_stringl(return_value, p1, endp-p1, 1);
- }
-}
-/* }}} */
-
-/* {{{ proto array explode(string separator, string str [, int limit])
- Split a string on string separator and return array of components */
-PHP_FUNCTION(explode)
-{
- zval **str, **delim, **zlimit = NULL;
- int limit;
-
- switch (ZEND_NUM_ARGS()) {
- case 2:
- if (zend_get_parameters_ex(2, &delim, &str) == FAILURE)
- WRONG_PARAM_COUNT;
- limit=-1;
- break;
- case 3:
- if (zend_get_parameters_ex(3, &delim, &str, &zlimit) == FAILURE)
- WRONG_PARAM_COUNT;
- convert_to_long_ex(zlimit);
- limit = (*zlimit)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(str);
- convert_to_string_ex(delim);
-
- if (! (*delim)->value.str.len) {
- php_error(E_WARNING, "Empty delimiter");
- RETURN_FALSE;
- }
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- if(limit==0 || limit==1) {
- add_index_stringl(return_value, 0, (*str)->value.str.val, (*str)->value.str.len, 1);
- } else {
- php_explode(*delim, *str, return_value, limit);
- }
-}
-/* }}} */
-
-/* {{{ proto string join(array src, string glue)
- An alias for implode */
-/* }}} */
-
-/* {{{ php_implode
- */
-PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
-{
- zval **tmp;
- int len = 0, count = 0, target = 0;
- HashPosition pos;
-
- /* convert everything to strings, and calculate length */
- zend_hash_internal_pointer_reset_ex(arr->value.ht, &pos);
- while (zend_hash_get_current_data_ex(arr->value.ht, (void **) &tmp, &pos) == SUCCESS) {
- convert_to_string_ex(tmp);
- len += (*tmp)->value.str.len;
- if (count>0) {
- len += delim->value.str.len;
- }
- count++;
- zend_hash_move_forward_ex(arr->value.ht, &pos);
- }
-
- /* 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_ex(arr->value.ht, &pos);
- while (zend_hash_get_current_data_ex(arr->value.ht, (void **) &tmp, &pos) == 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_ex(arr->value.ht, &pos);
- }
- return_value->type = IS_STRING;
- return_value->value.str.len = len;
-}
-/* }}} */
-
-/* {{{ proto string implode(array src, string glue)
- Join array elements placing glue string between items and return one string */
-PHP_FUNCTION(implode)
-{
- zval **arg1, **arg2, *delim, *arr;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if ((*arg1)->type == IS_ARRAY) {
- SEPARATE_ZVAL(arg1);
- arr = *arg1;
- convert_to_string_ex(arg2);
- 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(TSRMLS_C));
- return;
- }
- php_implode(delim, arr, return_value);
-}
-/* }}} */
-
-#define STRTOK_TABLE(p) BG(strtok_table)[(unsigned char) *p]
-
-/* {{{ proto string strtok([string str, ] string token)
- Tokenize a string */
-PHP_FUNCTION(strtok)
-{
- zval **args[2];
- zval **tok, **str;
- char *token;
- char *token_end;
- char *p;
- char *pe;
-
- if (ZEND_NUM_ARGS() < 1 || ZEND_NUM_ARGS() > 2 ||
- zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE)
- WRONG_PARAM_COUNT;
-
- switch (ZEND_NUM_ARGS()) {
- case 1:
- tok = args[0];
- break;
- case 2:
- str = args[0];
- tok = args[1];
- convert_to_string_ex(str);
-
- zval_add_ref(str);
- if (BG(strtok_zval))
- zval_ptr_dtor(&BG(strtok_zval));
- BG(strtok_zval) = *str;
-
- BG(strtok_last) = BG(strtok_string) = Z_STRVAL_PP(str);
- BG(strtok_len) = Z_STRLEN_PP(str);
- break;
- }
-
- p = BG(strtok_last); /* Where we start to search */
- pe = BG(strtok_string) + BG(strtok_len);
-
- if (!p || p >= pe)
- RETURN_FALSE;
-
- convert_to_string_ex(tok);
-
- token = Z_STRVAL_PP(tok);
- token_end = token + Z_STRLEN_PP(tok);
-
- while (token < token_end)
- STRTOK_TABLE(token++) = 1;
-
- /* Skip leading delimiters */
- while (STRTOK_TABLE(p))
- if (++p >= pe) {
- /* no other chars left */
- BG(strtok_last) = NULL;
- RETVAL_FALSE;
- goto restore;
- }
-
- /* We know at this place that *p is no delimiter, so skip it */
- while (++p < pe)
- if (STRTOK_TABLE(p))
- goto return_token;
-
- if (p - BG(strtok_last)) {
-return_token:
- RETVAL_STRINGL(BG(strtok_last), p - BG(strtok_last), 1);
- BG(strtok_last) = p + 1;
- } else {
- RETVAL_FALSE;
- BG(strtok_last) = NULL;
- }
-
- /* Restore table -- usually faster then memset'ing the table
- on every invocation */
-restore:
- token = Z_STRVAL_PP(tok);
-
- while (token < token_end)
- STRTOK_TABLE(token++) = 0;
-}
-/* }}} */
-
-/* {{{ php_strtoupper
- */
-PHPAPI char *php_strtoupper(char *s, size_t len)
-{
- char *c;
- int ch;
- size_t i;
-
- c = s;
- for (i=0; i<len; i++) {
- ch = toupper((unsigned char)*c);
- *c++ = ch;
- }
- return (s);
-}
-/* }}} */
-
-/* {{{ proto string strtoupper(string str)
- Make a string uppercase */
-PHP_FUNCTION(strtoupper)
-{
- zval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg)) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- *return_value = **arg;
- zval_copy_ctor(return_value);
- php_strtoupper(return_value->value.str.val, return_value->value.str.len);
-}
-/* }}} */
-
-/* {{{ php_strtolower
- */
-PHPAPI char *php_strtolower(char *s, size_t len)
-{
- register int ch;
- char *c;
- size_t i;
-
- c = s;
- for (i=0; i<len; i++) {
- ch = tolower((unsigned char)*c);
- *c++ = ch;
- }
- return (s);
-}
-/* }}} */
-
-/* {{{ proto string strtolower(string str)
- Make a string lowercase */
-PHP_FUNCTION(strtolower)
-{
- zval **str;
- char *ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str)) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- *return_value = **str;
- zval_copy_ctor(return_value);
- ret = php_strtolower(return_value->value.str.val, return_value->value.str.len);
-}
-/* }}} */
-
-/* {{{ php_basename
- */
-PHPAPI char *php_basename(char *s, size_t len, char *suffix, size_t sufflen)
-{
- char *ret=NULL, *c, *p=NULL, buf='\0';
- c = s + len - 1;
-
- /* do suffix removal as the unix command does */
- if(suffix && (len > sufflen)) {
- if(!strncmp(suffix, c-sufflen+1, sufflen)) {
- c -= sufflen;
- *(c + 1) = '\0';
- }
- }
-
-
- /* strip trailing slashes */
- while (*c == '/'
-#ifdef PHP_WIN32
- || *c == '\\'
-#endif
- )
- c--;
- if(c < s+len-1) {
- buf = *(c + 1); /* Save overwritten char */
- *(c + 1) = '\0'; /* overwrite char */
- p = c + 1; /* Save pointer to overwritten char */
- }
-
- if ((c = strrchr(s, '/'))
-#ifdef PHP_WIN32
- || (c = strrchr(s, '\\'))
-#endif
- ) {
- ret = estrdup(c + 1);
- } else {
- ret = estrdup(s);
- }
- if(buf) *p = buf;
- return (ret);
-}
-/* }}} */
-
-/* {{{ proto string basename(string path [, string suffix])
- Return the filename component of the path */
-PHP_FUNCTION(basename)
-{
- zval **str, **suffix;
- char *ret;
-
- switch(ZEND_NUM_ARGS()) {
- case 2:
- if(zend_get_parameters_ex(2, &str, &suffix)) WRONG_PARAM_COUNT;
- convert_to_string_ex(str);
- convert_to_string_ex(suffix);
- break;
- case 1:
- if(zend_get_parameters_ex(1, &str)) WRONG_PARAM_COUNT;
- convert_to_string_ex(str);
- suffix=NULL;
- break;
- default: WRONG_PARAM_COUNT;
- }
-
- ret = php_basename(Z_STRVAL_PP(str)
- , Z_STRLEN_PP(str)
- , (suffix)?Z_STRVAL_PP(suffix):NULL
- , (suffix)?Z_STRLEN_PP(suffix):0
- );
- RETVAL_STRING(ret, 0)
-}
-/* }}} */
-
-/* {{{ php_dirname
- *
- * This function doesn't work with absolute paths in Win32 such as C:\foo
- * (and it didn't before either). This needs to be fixed
- */
-PHPAPI void php_dirname(char *path, int len)
-{
- register char *end = path + len - 1;
-
- if (len <= 0) {
- /* Illegal use of this function */
- return;
- }
-
- /* Strip trailing slashes */
- while (end >= path && IS_SLASH(*end)) {
- end--;
- }
- if (end < path) {
- /* The path only contained slashes */
- path[0] = DEFAULT_SLASH;
- path[1] = '\0';
- return;
- }
-
- /* Strip filename */
- while (end >= path && !IS_SLASH(*end)) {
- end--;
- }
- if (end < path) {
- /* No slash found, therefore return '.' */
- path[0] = '.';
- path[1] = '\0';
- return;
- }
-
- /* Strip slashes which came before the file name */
- while (end >= path && IS_SLASH(*end)) {
- end--;
- }
- if (end < path) {
- path[0] = DEFAULT_SLASH;
- path[1] = '\0';
- return;
- }
- *(end+1) = '\0';
-}
-/* }}} */
-
-/* {{{ proto string dirname(string path)
- Return the directory name component of the path */
-PHP_FUNCTION(dirname)
-{
- zval **str;
- char *ret;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- ret = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));
- php_dirname(ret, Z_STRLEN_PP(str));
- RETVAL_STRING(ret, 0);
-}
-/* }}} */
-
-/* {{{ proto array pathinfo(string path)
- Return information about a certain string */
-PHP_FUNCTION(pathinfo)
-{
- zval **path, **uopt, *tmp;
- char *ret;
- int argc = ZEND_NUM_ARGS(), opt, len;
-
- if (argc < 1 || argc > 2 ||
- zend_get_parameters_ex(argc, &path, &uopt) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(path);
- len = Z_STRLEN_PP(path);
-
- if (argc > 1) {
- convert_to_long_ex(uopt);
- opt = Z_LVAL_PP(uopt);
- if (opt < PHP_PATHINFO_DIRNAME || opt > PHP_PATHINFO_EXTENSION) {
- php_error(E_WARNING, "Invalid option in call to %s()",
- get_active_function_name(TSRMLS_C));
- return;
- }
- }
-
- MAKE_STD_ZVAL(tmp);
- array_init(tmp);
-
- if (argc < 2 || opt == PHP_PATHINFO_DIRNAME) {
- ret = estrndup(Z_STRVAL_PP(path), len);
- php_dirname(ret, len);
- if (*ret)
- add_assoc_string(tmp, "dirname", ret, 1);
- efree(ret);
- }
-
- if (argc < 2 || opt == PHP_PATHINFO_BASENAME) {
- ret = php_basename(Z_STRVAL_PP(path), len, NULL, 0);
- add_assoc_string(tmp, "basename", ret, 0);
- }
-
- if (argc < 2 || opt == PHP_PATHINFO_EXTENSION) {
- char *p;
- int idx;
-
- p = strrchr(Z_STRVAL_PP(path), '.');
- if (p) {
- idx = p - Z_STRVAL_PP(path);
- add_assoc_stringl(tmp, "extension", Z_STRVAL_PP(path) + idx + 1, len - idx - 1, 1);
- }
- }
-
- if (argc == 2) {
- zval **element;
- zend_hash_get_current_data(Z_ARRVAL_P(tmp), (void **)&element);
- *return_value = **element;
- } else {
- *return_value = *tmp;
- }
-
- zval_copy_ctor(return_value);
- zval_dtor(tmp);
- efree(tmp);
-}
-/* }}} */
-
-/* {{{ php_stristr
- * case insensitve strstr */
-PHPAPI char *php_stristr(unsigned char *s, unsigned char *t,
- size_t s_len, size_t t_len)
-{
- php_strtolower(s, s_len);
- php_strtolower(t, t_len);
- return php_memnstr(s, t, t_len, s + s_len);
-}
-/* }}} */
-
-/* {{{ php_strspn
- */
-PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end)
-{
- register const char *p = s1, *spanp;
- register char c = *p;
-
-cont:
- for (spanp = s2; p != s1_end && spanp != s2_end;)
- if (*spanp++ == c) {
- c = *(++p);
- goto cont;
- }
- return (p - s1);
-}
-/* }}} */
-
-/* {{{ php_strcspn
- */
-PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end)
-{
- register const char *p, *spanp;
- register char c = *s1;
-
- for (p = s1;;) {
- spanp = s2;
- do {
- if (*spanp == c || p == s1_end)
- return (p - s1);
- } while (spanp++ < s2_end);
- c = *(++p);
- }
- /* NOTREACHED */
-}
-/* }}} */
-
-/* {{{ proto string stristr(string haystack, string needle)
- Find first occurrence of a string within another, case insensitive */
-PHP_FUNCTION(stristr)
-{
- zval **haystack, **needle;
- char *found = NULL;
- int found_offset;
- char *haystack_orig;
- char needle_char[2];
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) ==
- FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- SEPARATE_ZVAL(haystack);
- SEPARATE_ZVAL(needle);
- convert_to_string_ex(haystack);
- haystack_orig = estrndup((*haystack)->value.str.val,
- (*haystack)->value.str.len);
-
- if ((*needle)->type == IS_STRING) {
- if ((*needle)->value.str.len==0) {
- php_error(E_WARNING, "Empty delimiter");
- efree(haystack_orig);
- RETURN_FALSE;
- }
-
- found = php_stristr((*haystack)->value.str.val, (*needle)->value.str.val,
- (*haystack)->value.str.len, (*needle)->value.str.len);
- } else {
- convert_to_long_ex(needle);
- needle_char[0] = tolower((char) (*needle)->value.lval);
- needle_char[1] = '\0';
-
- found = php_stristr((*haystack)->value.str.val, needle_char,
- (*haystack)->value.str.len, 1);
- }
-
- if (found) {
- found_offset = found - (*haystack)->value.str.val;
- RETVAL_STRINGL(haystack_orig + found_offset,
- (*haystack)->value.str.len - found_offset, 1);
- } else {
- RETVAL_FALSE;
- }
- efree(haystack_orig);
-}
-/* }}} */
-
-/* {{{ proto string strstr(string haystack, string needle)
- Find first occurrence of a string within another */
-PHP_FUNCTION(strstr)
-{
- zval **haystack, **needle;
- char *haystack_end;
- char *found = NULL;
- char needle_char[2];
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) ==
- FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(haystack);
- haystack_end = (*haystack)->value.str.val + (*haystack)->value.str.len;
-
- if ((*needle)->type == IS_STRING) {
- if ((*needle)->value.str.len==0) {
- php_error(E_WARNING, "Empty delimiter");
- RETURN_FALSE;
- }
- found = php_memnstr((*haystack)->value.str.val, (*needle)->value.str.val,
- (*needle)->value.str.len, haystack_end);
- } else {
- convert_to_long_ex(needle);
- needle_char[0] = (char) (*needle)->value.lval;
- needle_char[1] = '\0';
- found = php_memnstr((*haystack)->value.str.val, needle_char, 1, haystack_end);
- }
-
-
- if (found) {
- RETVAL_STRING(found, 1);
- } else {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string strchr(string haystack, string needle)
- An alias for strstr */
-/* }}} */
-
-/* {{{ proto int strpos(string haystack, string needle [, int offset])
- Find position of first occurrence of a string within another */
-PHP_FUNCTION(strpos)
-{
- zval **haystack, **needle, **OFFSET;
- int offset = 0;
- char *found = NULL;
- char *endp;
- char *startp;
-
- switch(ZEND_NUM_ARGS()) {
- case 2:
- if (zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- break;
- case 3:
- if (zend_get_parameters_ex(3, &haystack, &needle, &OFFSET) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(OFFSET);
- offset = (*OFFSET)->value.lval;
- if (offset < 0) {
- php_error(E_WARNING, "offset not contained in string");
- RETURN_FALSE;
- }
- break;
- default:
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(haystack);
-
- if (offset > (*haystack)->value.str.len) {
- php_error(E_WARNING, "offset not contained in string");
- RETURN_FALSE;
- }
-
- startp = (*haystack)->value.str.val;
- startp+= offset;
-
- endp = (*haystack)->value.str.val;
- endp+= (*haystack)->value.str.len;
-
- if ((*needle)->type == IS_STRING) {
- if ((*needle)->value.str.len==0) {
- php_error(E_WARNING, "Empty delimiter");
- RETURN_FALSE;
- }
- found = php_memnstr(startp, (*needle)->value.str.val, (*needle)->value.str.len, endp);
- } else {
- char buf;
-
- convert_to_long_ex(needle);
- buf = (char) (*needle)->value.lval;
-
- found = php_memnstr(startp, &buf, 1, endp);
- }
-
- if (found) {
- RETVAL_LONG(found - (*haystack)->value.str.val);
- } else {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto int strrpos(string haystack, string needle)
- Find position of last occurrence of a character in a string within another */
-PHP_FUNCTION(strrpos)
-{
- zval **haystack, **needle;
- char *found = NULL;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(haystack);
-
- if ((*needle)->type == IS_STRING) {
- found = strrchr((*haystack)->value.str.val, *(*needle)->value.str.val);
- } else {
- convert_to_long_ex(needle);
- found = strrchr((*haystack)->value.str.val, (char) (*needle)->value.lval);
- }
-
- if (found) {
- RETVAL_LONG((*haystack)->value.str.len - strlen(found));
- } else {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string strrchr(string haystack, string needle)
- Find the last occurrence of a character in a string within another */
-PHP_FUNCTION(strrchr)
-{
- zval **haystack, **needle;
- char *found = NULL;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) ==
- FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(haystack);
-
- if ((*needle)->type == IS_STRING) {
- found = strrchr((*haystack)->value.str.val, *(*needle)->value.str.val);
- } else {
-
- convert_to_long_ex(needle);
- found = strrchr((*haystack)->value.str.val, (*needle)->value.lval);
- }
-
-
- if (found) {
- RETVAL_STRING(found, 1);
- } else {
- RETVAL_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ php_chunk_split
- */
-static char *php_chunk_split(char *src, int srclen, char *end, int endlen,
- int chunklen, int *destlen)
-{
- char *dest;
- char *p, *q;
- int chunks; /* complete chunks! */
- int restlen;
-
- chunks = srclen / chunklen;
- restlen = srclen - chunks * chunklen; /* srclen % chunklen */
-
- dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char));
-
- for(p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
- memcpy(q, p, chunklen);
- q += chunklen;
- memcpy(q, end, endlen);
- q += endlen;
- p += chunklen;
- }
-
- if(restlen) {
- memcpy(q, p, restlen);
- q += restlen;
- memcpy(q, end, endlen);
- q += endlen;
- }
-
- *q = '\0';
- if (destlen) {
- *destlen = q - dest;
- }
-
- return(dest);
-}
-/* }}} */
-
-/* {{{ proto string chunk_split(string str [, int chunklen [, string ending]])
- Return split line */
-PHP_FUNCTION(chunk_split)
-{
- zval **p_str, **p_chunklen, **p_ending;
- int argc;
- char *result;
- char *end = "\r\n";
- int endlen = 2;
- int chunklen = 76;
- int result_len;
-
- argc = ZEND_NUM_ARGS();
-
- if (argc < 1 || argc > 3 ||
- zend_get_parameters_ex(argc, &p_str, &p_chunklen, &p_ending) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- switch(argc) {
- case 3:
- convert_to_string_ex(p_ending);
- end = (*p_ending)->value.str.val;
- endlen = (*p_ending)->value.str.len;
- case 2:
- convert_to_long_ex(p_chunklen);
- chunklen = (*p_chunklen)->value.lval;
- case 1:
- convert_to_string_ex(p_str);
- }
-
- if(chunklen <= 0) {
- php_error(E_WARNING, "Chunk length should be greater than zero");
- RETURN_FALSE;
- }
-
- if((*p_str)->value.str.len == 0) {
- RETURN_EMPTY_STRING();
- }
-
- result = php_chunk_split((*p_str)->value.str.val, (*p_str)->value.str.len,
- end, endlen, chunklen, &result_len);
-
- if(result) {
- RETVAL_STRINGL(result, result_len, 0);
- } else {
- RETURN_FALSE;
- }
-}
-/* }}} */
-
-/* {{{ proto string substr(string str, int start [, int length])
- Return part of a string */
-PHP_FUNCTION(substr)
-{
- zval **str, **from, **len;
- int argc, l;
- int f;
-
- argc = ZEND_NUM_ARGS();
-
- if ((argc == 2 && zend_get_parameters_ex(2, &str, &from) == FAILURE) ||
- (argc == 3 && zend_get_parameters_ex(3, &str, &from, &len) == FAILURE) ||
- argc < 2 || argc > 3) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- convert_to_long_ex(from);
- f = (*from)->value.lval;
-
- if (argc == 2) {
- l = (*str)->value.str.len;
- } else {
- convert_to_long_ex(len);
- l = (*len)->value.lval;
- }
-
- /* if "from" position is negative, count start position from the end
- * of the string
- */
- if (f < 0) {
- f = (*str)->value.str.len + f;
- if (f < 0) {
- f = 0;
- }
- }
-
- /* if "length" position is negative, set it to the length
- * needed to stop that many chars from the end of the string
- */
- if (l < 0) {
- l = ((*str)->value.str.len - f) + l;
- if (l < 0) {
- l = 0;
- }
- }
-
- if (f >= (int)(*str)->value.str.len) {
- RETURN_FALSE;
- }
-
- if((f+l) > (int)(*str)->value.str.len) {
- l = (int)(*str)->value.str.len - f;
- }
-
- RETVAL_STRINGL((*str)->value.str.val + f, l, 1);
-}
-/* }}} */
-
-/* {{{ proto string substr_replace(string str, string repl, int start [, int length])
- Replace part of a string with another string */
-PHP_FUNCTION(substr_replace)
-{
- zval** str;
- zval** from;
- zval** len;
- zval** repl;
- char* result;
- int result_len;
- int argc;
- int l;
- int f;
-
- argc = ZEND_NUM_ARGS();
-
- if ((argc == 3 && zend_get_parameters_ex(3, &str, &repl, &from) == FAILURE) ||
- (argc == 4 && zend_get_parameters_ex(4, &str, &repl, &from, &len) == FAILURE) ||
- argc < 3 || argc > 4) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(str);
- convert_to_string_ex(repl);
- convert_to_long_ex(from);
- f = (*from)->value.lval;
-
- if (argc == 3) {
- l = (*str)->value.str.len;
- } else {
- convert_to_long_ex(len);
- l = (*len)->value.lval;
- }
-
- /* if "from" position is negative, count start position from the end
- * of the string
- */
- if (f < 0) {
- f = (*str)->value.str.len + f;
- if (f < 0) {
- f = 0;
- }
- } else if (f > (int)(*str)->value.str.len)
- f = (int)(*str)->value.str.len;
-
-
- /* if "length" position is negative, set it to the length
- * needed to stop that many chars from the end of the string
- */
- if (l < 0) {
- l = ((*str)->value.str.len - f) + l;
- if (l < 0) {
- l = 0;
- }
- }
-
- if((f+l) > (int)(*str)->value.str.len) {
- l = (int)(*str)->value.str.len - f;
- }
-
- result_len = (*str)->value.str.len - l + (*repl)->value.str.len;
- result = (char *)ecalloc(result_len + 1, sizeof(char *));
-
- memcpy(result, (*str)->value.str.val, f);
- memcpy(&result[f], (*repl)->value.str.val, (*repl)->value.str.len);
- memcpy(&result[f + (*repl)->value.str.len], (*str)->value.str.val + f + l,
- (*str)->value.str.len - f - l);
-
- RETVAL_STRINGL(result, result_len, 0);
-}
-/* }}} */
-
-/* {{{ proto string quotemeta(string str)
- Quote meta characters */
-PHP_FUNCTION(quotemeta)
-{
- zval **arg;
- char *str, *old;
- char *old_end;
- char *p, *q;
- char c;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- old = (*arg)->value.str.val;
- old_end = (*arg)->value.str.val + (*arg)->value.str.len;
-
- if (old == old_end) {
- RETURN_FALSE;
- }
-
- str = emalloc(2 * (*arg)->value.str.len + 1);
-
- for(p = old, q = str; p != old_end; p++) {
- c = *p;
- switch(c) {
- case '.':
- case '\\':
- case '+':
- case '*':
- case '?':
- case '[':
- case '^':
- case ']':
- case '$':
- case '(':
- case ')':
- *q++ = '\\';
- /* break is missing _intentionally_ */
- default:
- *q++ = c;
- }
- }
- *q = 0;
- RETVAL_STRINGL(erealloc(str, q - str + 1), q - str, 0);
-}
-/* }}} */
-
-/* {{{ proto int ord(string character)
- Return ASCII value of character */
-PHP_FUNCTION(ord)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- RETVAL_LONG((unsigned char)(*str)->value.str.val[0]);
-}
-/* }}} */
-
-/* {{{ proto string chr(int ascii)
- Convert ASCII code to a character */
-PHP_FUNCTION(chr)
-{
- zval **num;
- char temp[2];
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &num) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(num);
- temp[0] = (char) (*num)->value.lval;
- temp[1] = '\0';
- RETVAL_STRINGL(temp, 1, 1);
-}
-/* }}} */
-
-/* {{{ proto string ucfirst(string str)
- Make a string's first character uppercase */
-PHP_FUNCTION(ucfirst)
-{
- zval **arg;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (!*(*arg)->value.str.val) {
- RETURN_FALSE;
- }
-
- *return_value=**arg;
- zval_copy_ctor(return_value);
- *return_value->value.str.val = toupper((unsigned char)*return_value->value.str.val);
-}
-/* }}} */
-
-/* {{{ proto string ucwords(string str)
- Uppercase the first character of every word in a string */
-PHP_FUNCTION(ucwords)
-{
- zval **str;
- register char *r, *r_end;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- if (!Z_STRLEN_PP(str)) {
- RETURN_FALSE;
- }
- *return_value=**str;
- zval_copy_ctor(return_value);
-
- r=return_value->value.str.val;
- *r=toupper((unsigned char)*r);
- for(r_end = r + return_value->value.str.len - 1 ; r < r_end ; ) {
- if(isspace((int)*r++)) {
- *r=toupper((unsigned char)*r);
- }
- }
-}
-/* }}} */
-
-/* {{{ php_strtr
- */
-PHPAPI char *php_strtr(char *str, int len, char *str_from,
- char *str_to, int trlen)
-{
- int i;
- unsigned char xlat[256];
-
- if ((trlen < 1) || (len < 1)) {
- return str;
- }
-
- for (i = 0; i < 256; xlat[i] = i, i++);
-
- for (i = 0; i < trlen; i++) {
- xlat[(unsigned char) str_from[i]] = str_to[i];
- }
-
- for (i = 0; i < len; i++) {
- str[i] = xlat[(unsigned char) str[i]];
- }
-
- return str;
-}
-/* }}} */
-
-/* {{{ php_strtr_array
- */
-static void php_strtr_array(zval *return_value, char *str, int slen, HashTable *hash)
-{
- zval *entry;
- char *string_key;
- zval **trans;
- zval ctmp;
- ulong num_key;
- int minlen = 128*1024;
- int maxlen = 0, pos, len, found;
- char *key;
- HashPosition hpos;
- smart_str result = {0};
-
- zend_hash_internal_pointer_reset_ex(hash, &hpos);
- while (zend_hash_get_current_data_ex(hash, (void **)&entry, &hpos) == SUCCESS) {
- switch (zend_hash_get_current_key_ex(hash, &string_key, NULL, &num_key, 0, &hpos)) {
- case HASH_KEY_IS_STRING:
- len = strlen(string_key);
- if (len > maxlen) maxlen = len;
- if (len < minlen) minlen = len;
- 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_ex(hash, &hpos);
- }
-
- key = emalloc(maxlen+1);
- pos = 0;
-
- while (pos < slen) {
- if ((pos + maxlen) > slen) {
- maxlen = slen - pos;
- }
-
- found = 0;
- memcpy(key, str+pos, maxlen);
-
- for (len = maxlen; len >= minlen; len--) {
- key[ len ]=0;
-
- if (zend_hash_find(hash, key, len+1, (void**)&trans) == SUCCESS) {
- char *tval;
- int tlen;
- zval tmp;
-
- if ((*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;
- }
-
- smart_str_appendl(&result, tval, tlen);
- pos += len;
- found = 1;
-
- if ((*trans)->type != IS_STRING) {
- zval_dtor(&tmp);
- }
- break;
- }
- }
-
- if (! found) {
- smart_str_appendc(&result, str[pos++]);
- }
- }
-
- efree(key);
- smart_str_0(&result);
- RETVAL_STRINGL(result.c, result.len, 0);
-}
-/* }}} */
-
-/* {{{ proto string strtr(string str, string from, string to)
- Translate characters in str using given translation tables */
-PHP_FUNCTION(strtr)
-{ /* strtr(STRING, FROM, TO) */
- zval **str, **from, **to;
- int ac = ZEND_NUM_ARGS();
-
- if (ac < 2 || ac > 3 || zend_get_parameters_ex(ac, &str, &from, &to) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if (ac == 2 && (*from)->type != IS_ARRAY) {
- php_error(E_WARNING, "arg2 must be passed an array");
- RETURN_FALSE;
- }
-
- convert_to_string_ex(str);
-
- /* shortcut for empty string */
- if(Z_STRLEN_PP(str) == 0) {
- RETURN_EMPTY_STRING();
- }
-
- if (ac == 2) {
- php_strtr_array(return_value, (*str)->value.str.val, (*str)->value.str.len, HASH_OF(*from));
- } else {
- convert_to_string_ex(from);
- convert_to_string_ex(to);
-
- *return_value=**str;
- zval_copy_ctor(return_value);
-
- php_strtr(return_value->value.str.val,
- return_value->value.str.len,
- (*from)->value.str.val,
- (*to)->value.str.val,
- MIN((*from)->value.str.len, (*to)->value.str.len));
- }
-}
-/* }}} */
-
-/* {{{ proto string strrev(string str)
- Reverse a string */
-PHP_FUNCTION(strrev)
-{
- zval **str;
- int i, len;
- char c;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(str);
-
- *return_value = **str;
- zval_copy_ctor(return_value);
-
- len = return_value->value.str.len;
-
- for (i=0; i<len-1-i; i++) {
- c=return_value->value.str.val[i];
- return_value->value.str.val[i] = return_value->value.str.val[len-1-i];
- return_value->value.str.val[len-1-i]=c;
- }
-}
-/* }}} */
-
-/* {{{ php_similar_str
- */
-static void php_similar_str(const char *txt1, int len1, const char *txt2,
- int len2, int *pos1, int *pos2, int *max)
-{
- char *p, *q;
- char *end1 = (char *) txt1 + len1;
- char *end2 = (char *) txt2 + len2;
- int l;
-
- *max = 0;
- for (p = (char *) txt1; p < end1; p++) {
- for (q = (char *) txt2; q < end2; q++) {
- for (l = 0; (p + l < end1) && (q + l < end2) && (p[l] == q[l]);
- l++);
- if (l > *max) {
- *max = l;
- *pos1 = p - txt1;
- *pos2 = q - txt2;
- }
- }
- }
-}
-/* }}} */
-
-/* {{{ php_similar_char
- */
-static int php_similar_char(const char *txt1, int len1,
- const char *txt2, int len2)
-{
- int sum;
- int pos1, pos2, max;
-
- php_similar_str(txt1, len1, txt2, len2, &pos1, &pos2, &max);
- if ((sum = max)) {
- if (pos1 && pos2)
- sum += php_similar_char(txt1, pos1, txt2, pos2);
- if ((pos1 + max < len1) && (pos2 + max < len2))
- sum += php_similar_char(txt1 + pos1 + max, len1 - pos1 - max,
- txt2 + pos2 + max, len2 - pos2 - max);
- }
- return sum;
-}
-/* }}} */
-
-/* {{{ proto int similar_text(string str1, string str2 [, double percent])
- Calculates the similarity between two strings */
-PHP_FUNCTION(similar_text)
-{
- zval **t1, **t2, **percent;
- int ac = ZEND_NUM_ARGS();
- int sim;
-
- if (ac < 2 || ac > 3 ||
- zend_get_parameters_ex(ac, &t1, &t2, &percent) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(t1);
- convert_to_string_ex(t2);
- if (ac > 2) {
- convert_to_double_ex(percent);
- }
-
- if (((*t1)->value.str.len + (*t2)->value.str.len) == 0) {
- if(ac > 2) {
- (*percent)->value.dval = 0;
- }
- RETURN_LONG(0);
- }
-
- sim = php_similar_char((*t1)->value.str.val, (*t1)->value.str.len,
- (*t2)->value.str.val, (*t2)->value.str.len);
-
- if (ac > 2) {
- (*percent)->value.dval = sim * 200.0 / ((*t1)->value.str.len + (*t2)->value.str.len);
- }
-
- RETURN_LONG(sim);
-}
-/* }}} */
-
-/* {{{ php_stripslashes
- *
- * be careful, this edits the string in-place */
-PHPAPI void php_stripslashes(char *str, int *len TSRMLS_DC)
-{
- char *s, *t;
- int l;
- char escape_char='\\';
-
- if (PG(magic_quotes_sybase)) {
- escape_char='\'';
- }
-
- if (len != NULL) {
- l = *len;
- } else {
- l = strlen(str);
- }
- s = str;
- t = str;
- while (l > 0) {
- if (*t == escape_char) {
- t++; /* skip the slash */
- if (len != NULL)
- (*len)--;
- l--;
- if (l > 0) {
- if(*t=='0') {
- *s++='\0';
- t++;
- } else {
- *s++ = *t++; /* preserve the next character */
- }
- l--;
- }
- } else {
- if (s != t)
- *s++ = *t++;
- else {
- s++;
- t++;
- }
- l--;
- }
- }
- if (s != t) {
- *s = '\0';
- }
-}
-/* }}} */
-
-/* {{{ proto string addcslashes(string str, string charlist)
- Escape all chars mentioned in charlist with backslash. It creates octal representations if asked to backslash characters with 8th bit set or with ASCII<32 (except '\n', '\r', '\t' etc...) */
-PHP_FUNCTION(addcslashes)
-{
- zval **str, **what;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &str, &what) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
- convert_to_string_ex(what);
-
- if (Z_STRLEN_PP(str) == 0) {
- RETURN_EMPTY_STRING();
- }
-
- if (Z_STRLEN_PP(what) == 0) {
- RETURN_STRINGL(Z_STRVAL_PP(str), Z_STRLEN_PP(str), 1);
- }
-
- Z_STRVAL_P(return_value) = php_addcslashes(Z_STRVAL_PP(str),
- Z_STRLEN_PP(str), &Z_STRLEN_P(return_value), 0, Z_STRVAL_PP(what),
- Z_STRLEN_PP(what) TSRMLS_CC);
- return_value->type = IS_STRING;
-}
-/* }}} */
-
-/* {{{ proto string addslashes(string str)
- Escape single quote, double quotes and backslash characters in a string with backslashes */
-PHP_FUNCTION(addslashes)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- if (Z_STRLEN_PP(str) == 0) {
- RETURN_EMPTY_STRING();
- }
-
- Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_PP(str),
- Z_STRLEN_PP(str), &Z_STRLEN_P(return_value), 0 TSRMLS_CC);
- Z_TYPE_P(return_value) = IS_STRING;
-}
-/* }}} */
-
-/* {{{ proto string stripcslashes(string str)
- Strip backslashes from a string. Uses C-style conventions */
-PHP_FUNCTION(stripcslashes)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- *return_value = **str;
- zval_copy_ctor(return_value);
- php_stripcslashes(return_value->value.str.val, &return_value->value.str.len);
-}
-/* }}} */
-
-/* {{{ proto string stripslashes(string str)
- Strip backslashes from a string */
-PHP_FUNCTION(stripslashes)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- *return_value = **str;
- zval_copy_ctor(return_value);
- php_stripslashes(Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value) TSRMLS_CC);
-}
-/* }}} */
-
-#ifndef HAVE_STRERROR
-/* {{{ php_strerror
- */
-char *php_strerror(int errnum)
-{
- extern int sys_nerr;
- extern char *sys_errlist[];
- TSRMLS_FETCH();
-
- if ((unsigned int)errnum < sys_nerr) return(sys_errlist[errnum]);
- (void)sprintf(BG(str_ebuf), "Unknown error: %d", errnum);
- return(BG(str_ebuf));
-}
-/* }}} */
-#endif
-
-/* {{{ php_stripcslashes
- */
-PHPAPI void php_stripcslashes(char *str, int *len)
-{
- char *source, *target, *end;
- int nlen = *len, i;
- char numtmp[4];
-
- for (source=str, end=str+nlen, target=str; source<end; source++) {
- if (*source == '\\' && source+1<end) {
- source++;
- switch (*source) {
- case 'n': *target++='\n'; nlen--; break;
- case 'r': *target++='\r'; nlen--; break;
- case 'a': *target++='\a'; nlen--; break;
- case 't': *target++='\t'; nlen--; break;
- case 'v': *target++='\v'; nlen--; break;
- case 'b': *target++='\b'; nlen--; break;
- case 'f': *target++='\f'; nlen--; break;
- case '\\': *target++='\\'; nlen--; break;
- case 'x': if (source+1<end && isxdigit((int)(*(source+1)))) {
- numtmp[0] = *++source;
- if (source+1<end && isxdigit((int)(*(source+1)))) {
- numtmp[1] = *++source;
- numtmp[2] = '\0';
- nlen-=3;
- } else {
- numtmp[1] = '\0';
- nlen-=2;
- }
- *target++=(char)strtol(numtmp, NULL, 16);
- break;
- }
- /* break is left intentionally */
- default: i=0;
- while (source<end && *source>='0' && *source<='7' && i<3) {
- numtmp[i++] = *source++;
- }
- if (i) {
- numtmp[i]='\0';
- *target++=(char)strtol(numtmp, NULL, 8);
- nlen-=i;
- source--;
- } else {
- *target++=*source;
- nlen--;
- }
- }
- } else {
- *target++=*source;
- }
- }
-
- if(nlen != 0) {
- *target='\0';
- }
-
- *len = nlen;
-}
-/* }}} */
-
-/* {{{ php_addcslashes
- */
-PHPAPI char *php_addcslashes(char *str, int length, int *new_length, int should_free, char *what, int wlength TSRMLS_DC)
-{
- char flags[256];
- char *new_str = emalloc((length?length:(length=strlen(str)))*4+1);
- char *source, *target;
- char *end;
- char c;
- int newlen;
-
- if (!wlength) {
- wlength = strlen(what);
- }
-
- if (!length) {
- length = strlen(str);
- }
-
- php_charmask(what, wlength, flags TSRMLS_CC);
-
- for (source=str, end=source+length, target=new_str; (c=*source) || source<end; source++) {
- if (flags[(unsigned char)c]) {
- if ((unsigned char)c<32 || (unsigned char)c>126) {
- *target++ = '\\';
- switch (c) {
- case '\n': *target++ = 'n'; break;
- case '\t': *target++ = 't'; break;
- case '\r': *target++ = 'r'; break;
- case '\a': *target++ = 'a'; break;
- case '\v': *target++ = 'v'; break;
- case '\b': *target++ = 'b'; break;
- case '\f': *target++ = 'f'; break;
- default: target += sprintf(target, "%03o", (unsigned char)c);
- }
- continue;
- }
- *target++ = '\\';
- }
- *target++ = c;
- }
- *target = 0;
- newlen = target-new_str;
- if (target-new_str<length*4) {
- new_str = erealloc(new_str, newlen+1);
- }
- if (new_length) {
- *new_length = newlen;
- }
- if (should_free) {
- STR_FREE(str);
- }
- return new_str;
-}
-/* }}} */
-
-/* {{{ php_addslashes
- */
-PHPAPI char *php_addslashes(char *str, int length, int *new_length, int should_free TSRMLS_DC)
-{
- /* maximum string length, worst case situation */
- char *new_str;
- char *source, *target;
- char *end;
- char c;
-
- if (!str) {
- *new_length = 0;
- return str;
- }
- new_str = (char *) emalloc((length?length:(length=strlen(str)))*2+1);
- for (source=str, end=source+length, target=new_str; source<end; source++) {
- c = *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)
-
-/* {{{ php_char_to_str
- */
-PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result)
-{
- int char_count=0;
- char *source, *target, *tmp, *source_end=str+len, *tmp_end=NULL;
-
- for (source=str; source<source_end; source++) {
- if (*source==from) {
- char_count++;
- }
- }
-
- result->type = IS_STRING;
-
- if (char_count==0) {
- result->value.str.val = estrndup(str, len);
- result->value.str.len = len;
- return;
- }
-
- result->value.str.len = len+char_count*(to_len-1);
- result->value.str.val = target = (char *) emalloc(result->value.str.len+1);
-
- for (source=str; source<source_end; source++) {
- if (*source==from) {
- for (tmp=to, tmp_end=tmp+to_len; tmp<tmp_end; tmp++) {
- *target = *tmp;
- target++;
- }
- } else {
- *target = *source;
- target++;
- }
- }
- *target = 0;
-}
-/* }}} */
-
-/* {{{ boyer_str_to_str */
-static char *boyer_str_to_str(char *haystack, int length,
- char *needle, int needle_len, char *str,
- int str_len, int *new_length)
-{
- char *p, *pe, *cursor, *end, *r;
- int off;
- char jump_table[256];
- smart_str result = {0};
-
- /*
- * We implement only the first half of the Boyer-Moore algorithm,
- * because the second half is too expensive to compute during run-time.
- * TODO: Split matching into compile-/match-stage.
- */
-
- /* Prepare the jump_table which contains the skip offsets */
- memset(jump_table, needle_len, 256);
-
- off = needle_len - 1;
-
- /* Calculate the default start where each comparison starts */
- pe = needle + off;
-
- /* Assign skip offsets based on the pattern */
- for (p = needle; p <= pe; p++)
- jump_table[(unsigned char) *p] = off--;
-
- /* Start to look at the first possible position for the pattern */
- cursor = haystack + needle_len - 1;
-
- /* The cursor must not cross this limit */
- end = haystack + length;
-
- /* Start to copy at haystack */
- r = haystack;
-
-nextiter:
- while (cursor < end) {
- p = pe; /* Compare from right to left */
- while (*p == *cursor) {
- if (--p < needle) { /* Found the pattern */
-
- /* Append whatever was not matched */
- smart_str_appendl(&result, r, cursor - r);
-
- /* Append replacement string */
- smart_str_appendl(&result, str, str_len);
-
- /* Update copy pointer */
- r = cursor + needle_len;
-
- /* needle_len was substracted from cursor for
- * this comparison, add it back. Also add
- * needle_len - 1 which is the default search
- * offset.
- */
- cursor += (needle_len << 1) - 1;
-
- /* Next iteration */
- goto nextiter;
- }
- cursor--;
- }
-
- cursor += jump_table[(unsigned char) *cursor];
- }
-
- if (r < end) /* Copy the remaining data */
- smart_str_appendl(&result, r, end - r);
-
- smart_str_0(&result); /* NUL-ify result */
-
- if (new_length)
- *new_length = result.len;
-
- return result.c;
-}
-/* }}} */
-
-/* {{{ php_str_to_str
- */
-PHPAPI char *php_str_to_str(char *haystack, int length,
- char *needle, int needle_len, char *str, int str_len, int *_new_length)
-{
- char *p;
- char *r;
- char *end = haystack + length;
- smart_str result = {0};
-
- for (p = haystack;
- (r = php_memnstr(p, needle, needle_len, end));
- p = r + needle_len) {
- smart_str_appendl(&result, p, r - p);
- smart_str_appendl(&result, str, str_len);
- }
-
- if (p < end)
- smart_str_appendl(&result, p, end - p);
-
- smart_str_0(&result);
-
- if (_new_length) *_new_length = result.len;
-
- return result.c;
-}
-/* }}} */
-
-/* {{{ php_str_replace_in_subject
- */
-static void php_str_replace_in_subject(zval *search, zval *replace, zval **subject, zval *result, int boyer)
-{
- zval **search_entry,
- **replace_entry = NULL,
- temp_result;
- char *replace_value = NULL;
- int replace_len = 0;
- char *(*str_to_str)(char *, int, char *, int, char *, int, int *);
-
- str_to_str = boyer ? boyer_str_to_str : php_str_to_str;
-
- /* Make sure we're dealing with strings. */
- convert_to_string_ex(subject);
- Z_TYPE_P(result) = IS_STRING;
- if (Z_STRLEN_PP(subject) == 0) {
- ZVAL_STRINGL(result, empty_string, 0, 1);
- return;
- }
-
- /* If search is an array */
- if (Z_TYPE_P(search) == IS_ARRAY) {
- /* Duplicate subject string for repeated replacement */
- *result = **subject;
- zval_copy_ctor(result);
-
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(search));
-
- if (Z_TYPE_P(replace) == IS_ARRAY) {
- zend_hash_internal_pointer_reset(Z_ARRVAL_P(replace));
- } else {
- /* Set replacement value to the passed one */
- replace_value = Z_STRVAL_P(replace);
- replace_len = Z_STRLEN_P(replace);
- }
-
- /* For each entry in the search array, get the entry */
- while (zend_hash_get_current_data(Z_ARRVAL_P(search), (void **)&search_entry) == SUCCESS) {
- /* Make sure we're dealing with strings. */
- convert_to_string_ex(search_entry);
- if(Z_STRLEN_PP(search_entry) == 0) {
- zend_hash_move_forward(Z_ARRVAL_P(search));
- continue;
- }
-
- /* If replace is an array. */
- if (Z_TYPE_P(replace) == IS_ARRAY) {
- /* Get current entry */
- if (zend_hash_get_current_data(Z_ARRVAL_P(replace), (void **)&replace_entry) == SUCCESS) {
- /* Make sure we're dealing with strings. */
- convert_to_string_ex(replace_entry);
-
- /* Set replacement value to the one we got from array */
- replace_value = Z_STRVAL_PP(replace_entry);
- replace_len = Z_STRLEN_PP(replace_entry);
-
- zend_hash_move_forward(Z_ARRVAL_P(replace));
- } else {
- /* We've run out of replacement strings, so use an empty one. */
- replace_value = empty_string;
- replace_len = 0;
- }
- }
-
- if(Z_STRLEN_PP(search_entry) == 1) {
- php_char_to_str(Z_STRVAL_P(result),
- Z_STRLEN_P(result),
- Z_STRVAL_PP(search_entry)[0],
- replace_value,
- replace_len,
- &temp_result);
- } else if (Z_STRLEN_PP(search_entry) > 1) {
- Z_STRVAL(temp_result) = str_to_str(Z_STRVAL_P(result), Z_STRLEN_P(result),
- Z_STRVAL_PP(search_entry), Z_STRLEN_PP(search_entry),
- replace_value, replace_len, &Z_STRLEN(temp_result));
- }
-
- efree(Z_STRVAL_P(result));
- Z_STRVAL_P(result) = Z_STRVAL(temp_result);
- Z_STRLEN_P(result) = Z_STRLEN(temp_result);
-
- zend_hash_move_forward(Z_ARRVAL_P(search));
- }
- } else {
- if (Z_STRLEN_P(search) == 1) {
- php_char_to_str(Z_STRVAL_PP(subject),
- Z_STRLEN_PP(subject),
- Z_STRVAL_P(search)[0],
- Z_STRVAL_P(replace),
- Z_STRLEN_P(replace),
- result);
- } else if (Z_STRLEN_P(search) > 1) {
- Z_STRVAL_P(result) = str_to_str(Z_STRVAL_PP(subject), Z_STRLEN_PP(subject),
- Z_STRVAL_P(search), Z_STRLEN_P(search),
- Z_STRVAL_P(replace), Z_STRLEN_P(replace), &Z_STRLEN_P(result));
- } else {
- *result = **subject;
- zval_copy_ctor(result);
- }
- }
-}
-/* }}} */
-
-/* {{{ proto mixed str_replace(mixed search, mixed replace, mixed subject[, bool boyer])
- Replace all occurrences of search in haystack with replace */
-PHP_FUNCTION(str_replace)
-{
- zval **subject, **search, **replace, **subject_entry, **pboyer;
- zval *result;
- char *string_key;
- ulong string_key_len, num_key;
- int boyer = 0;
-
- if(ZEND_NUM_ARGS() < 3 ||
- ZEND_NUM_ARGS() > 4 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &search,
- &replace, &subject, &pboyer) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- switch (ZEND_NUM_ARGS()) {
- case 4:
- convert_to_boolean_ex(pboyer);
- if (Z_BVAL_PP(pboyer))
- boyer = 1;
- break;
- }
-
- SEPARATE_ZVAL(search);
- SEPARATE_ZVAL(replace);
- SEPARATE_ZVAL(subject);
-
- /* Make sure we're dealing with strings and do the replacement. */
- if (Z_TYPE_PP(search) != IS_ARRAY) {
- convert_to_string_ex(search);
- convert_to_string_ex(replace);
- } else if (Z_TYPE_PP(replace) != IS_ARRAY)
- convert_to_string_ex(replace);
-
- /* if subject is an array */
- if (Z_TYPE_PP(subject) == IS_ARRAY) {
- array_init(return_value);
- zend_hash_internal_pointer_reset(Z_ARRVAL_PP(subject));
-
- /* For each subject entry, convert it to string, then perform replacement
- and add the result to the return_value array. */
- while (zend_hash_get_current_data(Z_ARRVAL_PP(subject), (void **)&subject_entry) == SUCCESS) {
- MAKE_STD_ZVAL(result);
- php_str_replace_in_subject(*search, *replace, subject_entry, result, boyer);
- /* Add to return array */
- switch(zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), &string_key,
- &string_key_len, &num_key, 0, NULL)) {
- case HASH_KEY_IS_STRING:
- add_assoc_zval_ex(return_value, string_key, string_key_len, result);
- break;
-
- case HASH_KEY_IS_LONG:
- add_index_zval(return_value, num_key, result);
- break;
- }
-
- zend_hash_move_forward(Z_ARRVAL_PP(subject));
- }
- } else { /* if subject is not an array */
- php_str_replace_in_subject(*search, *replace, subject, return_value, boyer);
- }
-}
-/* }}} */
-
-/* {{{ php_hebrev
- *
- * Converts Logical Hebrew text (Hebrew Windows style) to Visual text
- * Cheers/complaints/flames - Zeev Suraski <zeev@php.net>
- */
-static void php_hebrev(INTERNAL_FUNCTION_PARAMETERS, int convert_newlines)
-{
- zval **str, **max_chars_per_line;
- char *heb_str, *tmp, *target, *opposite_target, *broken_str;
- int block_start, block_end, block_type, block_length, i;
- int block_ended;
- long max_chars=0;
- int begin, end, char_count, orig_begin;
-
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if (zend_get_parameters_ex(1, &str)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 2:
- if (zend_get_parameters_ex(2, &str, &max_chars_per_line)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_long_ex(max_chars_per_line);
- max_chars = (*max_chars_per_line)->value.lval;
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
-
- convert_to_string_ex(str);
-
- if ((*str)->value.str.len==0) {
- RETURN_FALSE;
- }
-
- tmp = (*str)->value.str.val;
- block_start=block_end=0;
- block_ended=0;
-
- heb_str = (char *) emalloc((*str)->value.str.len+1);
- target = heb_str+(*str)->value.str.len;
- opposite_target = heb_str;
- *target = 0;
- target--;
-
- block_length=0;
-
- if (isheb(*tmp)) {
- block_type = _HEB_BLOCK_TYPE_HEB;
- } else {
- block_type = _HEB_BLOCK_TYPE_ENG;
- }
-
- do {
- if (block_type==_HEB_BLOCK_TYPE_HEB) {
- while((isheb((int)*(tmp+1)) || _isblank((int)*(tmp+1)) || ispunct((int)*(tmp+1)) || (int)*(tmp+1)=='\n' ) && block_end<(*str)->value.str.len-1) {
- tmp++;
- block_end++;
- block_length++;
- }
- for (i=block_start; i<=block_end; i++) {
- *target = (*str)->value.str.val[i];
- switch (*target) {
- case '(':
- *target = ')';
- break;
- case ')':
- *target = '(';
- break;
- default:
- break;
- }
- target--;
- }
- block_type = _HEB_BLOCK_TYPE_ENG;
- } else {
- while(!isheb(*(tmp+1)) && (int)*(tmp+1)!='\n' && block_end<(*str)->value.str.len-1) {
- tmp++;
- block_end++;
- block_length++;
- }
- while ((_isblank((int)*tmp) || ispunct((int)*tmp)) && *tmp!='/' && *tmp!='-' && block_end>block_start) {
- tmp--;
- block_end--;
- }
- for (i=block_end; i>=block_start; i--) {
- *target = (*str)->value.str.val[i];
- target--;
- }
- block_type = _HEB_BLOCK_TYPE_HEB;
- }
- block_start=block_end+1;
- } while(block_end<(*str)->value.str.len-1);
-
-
- broken_str = (char *) emalloc((*str)->value.str.len+1);
- begin=end=(*str)->value.str.len-1;
- target = broken_str;
-
- while (1) {
- char_count=0;
- while ((!max_chars || char_count<max_chars) && begin>0) {
- char_count++;
- begin--;
- if (begin<=0 || _isnewline(heb_str[begin])) {
- while(begin>0 && _isnewline(heb_str[begin-1])) {
- begin--;
- char_count++;
- }
- break;
- }
- }
- if (char_count==max_chars) { /* try to avoid breaking words */
- int new_char_count=char_count, new_begin=begin;
-
- while (new_char_count>0) {
- if (_isblank(heb_str[new_begin]) || _isnewline(heb_str[new_begin])) {
- break;
- }
- new_begin++;
- new_char_count--;
- }
- if (new_char_count>0) {
- char_count=new_char_count;
- begin=new_begin;
- }
- }
- orig_begin=begin;
-
- if (_isblank(heb_str[begin])) {
- heb_str[begin]='\n';
- }
- while (begin<=end && _isnewline(heb_str[begin])) { /* skip leading newlines */
- begin++;
- }
- for (i=begin; i<=end; i++) { /* copy content */
- *target = heb_str[i];
- target++;
- }
- for (i=orig_begin; i<=end && _isnewline(heb_str[i]); i++) {
- *target = heb_str[i];
- target++;
- }
- begin=orig_begin;
-
- if (begin<=0) {
- *target = 0;
- break;
- }
- begin--;
- end=begin;
- }
- efree(heb_str);
-
- if (convert_newlines) {
- php_char_to_str(broken_str, (*str)->value.str.len,'\n', "<br>\n", 5, return_value);
- efree(broken_str);
- } else {
- return_value->value.str.val = broken_str;
- return_value->value.str.len = (*str)->value.str.len;
- return_value->type = IS_STRING;
- }
-}
-/* }}} */
-
-/* {{{ proto string hebrev(string str [, int max_chars_per_line])
- Convert logical Hebrew text to visual text */
-PHP_FUNCTION(hebrev)
-{
- php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto string hebrevc(string str [, int max_chars_per_line])
- Convert logical Hebrew text to visual text with newline conversion */
-PHP_FUNCTION(hebrevc)
-{
- php_hebrev(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ proto string nl2br(string str)
- Converts newlines to HTML line breaks */
-PHP_FUNCTION(nl2br)
-{
- zval **str;
-
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str)==FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(str);
-
- php_char_to_str((*str)->value.str.val, (*str)->value.str.len,'\n', "<br />\n", 7, return_value);
-}
-/* }}} */
-
-/* {{{ proto string strip_tags(string str [, string allowable_tags])
- Strips HTML and PHP tags from a string */
-PHP_FUNCTION(strip_tags)
-{
- char *buf;
- zval **str, **allow=NULL;
- char *allowed_tags=NULL;
- int allowed_tags_len=0;
-
- switch(ZEND_NUM_ARGS()) {
- case 1:
- if(zend_get_parameters_ex(1, &str)==FAILURE) {
- RETURN_FALSE;
- }
- break;
- case 2:
- if(zend_get_parameters_ex(2, &str, &allow)==FAILURE) {
- RETURN_FALSE;
- }
- convert_to_string_ex(allow);
- allowed_tags = (*allow)->value.str.val;
- allowed_tags_len = (*allow)->value.str.len;
- break;
- default:
- WRONG_PARAM_COUNT;
- break;
- }
- convert_to_string_ex(str);
- buf = estrndup((*str)->value.str.val, (*str)->value.str.len);
- php_strip_tags(buf, (*str)->value.str.len, 0, allowed_tags, allowed_tags_len);
- RETURN_STRING(buf, 0);
-}
-/* }}} */
-
-/* {{{ proto string setlocale(mixed category, string locale)
- Set locale information */
-PHP_FUNCTION(setlocale)
-{
- zval **pcategory, **plocale;
- zval *category, *locale;
- int cat;
- char *loc, *retval;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &pcategory, &plocale)==FAILURE)
- WRONG_PARAM_COUNT;
-#ifdef HAVE_SETLOCALE
- convert_to_string_ex(plocale);
- locale = *plocale;
-
- if (Z_TYPE_PP(pcategory) == IS_LONG) {
- convert_to_long_ex(pcategory);
- cat = Z_LVAL_PP(pcategory);
- } else { /* FIXME: The following behaviour should be removed. */
- php_error(E_NOTICE, "Passing locale category name as string is deprecated. Use the LC_* -constants instead.");
- convert_to_string_ex(pcategory);
- category = *pcategory;
-
- 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;
-#ifdef LC_MESSAGES
- else if (!strcasecmp ("LC_MESSAGES", category->value.str.val))
- cat = LC_MESSAGES;
-#endif
- else if (!strcasecmp ("LC_MONETARY", category->value.str.val))
- cat = LC_MONETARY;
- else if (!strcasecmp ("LC_NUMERIC", category->value.str.val))
- cat = LC_NUMERIC;
- else if (!strcasecmp ("LC_TIME", category->value.str.val))
- cat = LC_TIME;
- else {
- php_error(E_WARNING, "Invalid locale category name %s, must be one of LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC or LC_TIME", category->value.str.val);
- RETURN_FALSE;
- }
- }
- if (!strcmp ("0", locale->value.str.val)) {
- loc = NULL;
- } else {
- loc = locale->value.str.val;
- }
-
- retval = setlocale (cat, loc);
- if (retval) {
- /* Remember if locale was changed */
- if (loc) {
- STR_FREE(BG(locale_string));
- BG(locale_string) = estrdup(retval);
- }
-
- RETVAL_STRING(retval, 1);
- return;
- }
-#endif
- RETURN_FALSE;
-}
-/* }}} */
-
-/* {{{ proto void parse_str(string encoded_string, [array result])
- Parses GET/POST/COOKIE data and sets global variables */
-PHP_FUNCTION(parse_str)
-{
- zval **arg;
- zval **arrayArg;
- zval *sarg;
- char *res = NULL;
- int argCount;
- int old_rg;
-
- argCount = ARG_COUNT(ht);
- if(argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(arg);
- sarg = *arg;
- if (sarg->value.str.val && *sarg->value.str.val) {
- res = estrndup(sarg->value.str.val, sarg->value.str.len);
- }
-
- old_rg = PG(register_globals);
- if(argCount == 1) {
- PG(register_globals) = 1;
- php_treat_data(PARSE_STRING, res, NULL TSRMLS_CC);
- } else {
- PG(register_globals) = 0;
- /* Clear out the array that was passed in. */
- zval_dtor(*arrayArg);
- array_init(*arrayArg);
-
- php_treat_data(PARSE_STRING, res, *arrayArg TSRMLS_CC);
- }
- PG(register_globals) = old_rg;
-}
-/* }}} */
-
-#define PHP_TAG_BUF_SIZE 1023
-
-/* {{{ php_tag_find
- *
- * Check if tag is in a set of tags
- *
- * states:
- *
- * 0 start tag
- * 1 first non-whitespace char seen
- */
-int php_tag_find(char *tag, int len, char *set) {
- char c, *n, *t;
- int state=0, done=0;
- char *norm = emalloc(len+1);
-
- n = norm;
- t = tag;
- c = tolower(*t);
- /*
- normalize the tag removing leading and trailing whitespace
- and turn any <a whatever...> into just <a> and any </tag>
- into <tag>
- */
- if (!len) {
- return 0;
- }
- while(!done) {
- switch(c) {
- case '<':
- *(n++) = c;
- break;
- case '>':
- done =1;
- break;
- default:
- if(!isspace((int)c)) {
- if(state==0) {
- state=1;
- if(c!='/') *(n++) = c;
- } else {
- *(n++) = c;
- }
- } else {
- if(state==1) done=1;
- }
- break;
- }
- c = tolower(*(++t));
- }
- *(n++) = '>';
- *n = '\0';
- if(strstr(set, norm)) {
- done=1;
- } else {
- done=0;
- }
- efree(norm);
- return done;
-}
-/* }}} */
-
-/* {{{ php_strip_tags
-
- A simple little state-machine to strip out html and php tags
-
- State 0 is the output state, State 1 means we are inside a
- normal html tag and state 2 means we are inside a php tag.
-
- The state variable is passed in to allow a function like fgetss
- to maintain state across calls to the function.
-
- lc holds the last significant character read and br is a bracket
- counter.
-
- When an allow string is passed in we keep track of the string
- in state 1 and when the tag is closed check it against the
- allow string to see if we should allow it.
-*/
-PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len)
-{
- char *tbuf, *buf, *p, *tp, *rp, c, lc;
- int br, i=0;
-
- buf = estrndup(rbuf, len);
- c = *buf;
- lc = '\0';
- p = buf;
- rp = rbuf;
- br = 0;
- if(allow) {
- php_strtolower(allow, allow_len);
- tbuf = emalloc(PHP_TAG_BUF_SIZE+1);
- tp = tbuf;
- } else {
- tbuf = tp = NULL;
- }
-
- while(i<len) {
- switch (c) {
- case '<':
- if (state == 0) {
- lc = '<';
- state = 1;
- if(allow) {
- *(tp++) = '<';
- }
- }
- break;
-
- case '(':
- if (state == 2) {
- if (lc != '\"') {
- lc = '(';
- br++;
- }
- } else if (allow && state == 1) {
- *(tp++) = c;
- } else if (state == 0) {
- *(rp++) = c;
- }
- break;
-
- case ')':
- if (state == 2) {
- if (lc != '\"') {
- lc = ')';
- br--;
- }
- } else if (allow && state == 1) {
- *(tp++) = c;
- } 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;
- tp = tbuf;
- }
- } else {
- *(rp++) = c;
- }
- break;
-
- case '\"':
- if (state == 2) {
- if (lc == '\"') {
- lc = '\0';
- } else if (lc != '\\') {
- lc = '\"';
- }
- } else if (state == 0) {
- *(rp++) = c;
- } else if (allow && state == 1) {
- *(tp++) = c;
- }
- break;
-
- case '?':
- if (state==1 && *(p-1)=='<') {
- br=0;
- state=2;
- break;
- }
- /* fall-through */
-
- default:
- if (state == 0) {
- *(rp++) = c;
- } else if(allow && state == 1) {
- *(tp++) = c;
- if( (tp-tbuf)>=PHP_TAG_BUF_SIZE ) { /* no buffer overflows */
- tp = tbuf;
- }
- }
- break;
- }
- c = *(++p);
- i++;
- }
- *rp = '\0';
- efree(buf);
- if(allow) efree(tbuf);
-}
-/* }}} */
-
-/* {{{ proto string str_repeat(string input, int mult)
- Returns the input string repeat mult times */
-PHP_FUNCTION(str_repeat)
-{
- zval **input_str; /* Input string */
- zval **mult; /* Multiplier */
- char *result; /* Resulting string */
- int result_len; /* Length of the resulting string */
- int i;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &input_str, &mult) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- /* Make sure we're dealing with proper types */
- convert_to_string_ex(input_str);
- convert_to_long_ex(mult);
-
- if ((*mult)->value.lval < 0) {
- php_error(E_WARNING, "Second argument to %s() has to be greater than or equal to 0",
- get_active_function_name(TSRMLS_C));
- return;
- }
-
- /* Don't waste our time if it's empty */
- if ((*input_str)->value.str.len == 0)
- RETURN_STRINGL(empty_string, 0, 1);
-
- /* ... or if the multiplier is zero */
- if ((*mult)->value.lval == 0)
- RETURN_STRINGL(empty_string, 0, 1);
-
- /* Initialize the result string */
- result_len = (*input_str)->value.str.len * (*mult)->value.lval;
- result = (char *)emalloc(result_len + 1);
-
- /* Copy the input string into the result as many times as necessary */
- for (i=0; i<(*mult)->value.lval; i++) {
- memcpy(result + (*input_str)->value.str.len * i,
- (*input_str)->value.str.val,
- (*input_str)->value.str.len);
- }
- result[result_len] = '\0';
-
- RETURN_STRINGL(result, result_len, 0);
-}
-/* }}} */
-
-/* {{{ proto mixed count_chars(string input [, int mode])
- Returns info about what characters are used in input */
-PHP_FUNCTION(count_chars)
-{
- zval **input, **mode;
- int chars[256];
- int ac=ZEND_NUM_ARGS();
- int mymode=0;
- unsigned char *buf;
- int len, inx;
- char retstr[256];
- int retlen=0;
-
- if (ac < 1 || ac > 2 || zend_get_parameters_ex(ac, &input, &mode) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(input);
-
- if (ac == 2) {
- convert_to_long_ex(mode);
- mymode = (*mode)->value.lval;
-
- if (mymode < 0 || mymode > 4) {
- php_error(E_WARNING, "unknown mode");
- RETURN_FALSE;
- }
- }
-
- len = (*input)->value.str.len;
- buf = (unsigned char *) (*input)->value.str.val;
- memset((void*) chars, 0, sizeof(chars));
-
- while (len > 0) {
- chars[*buf]++;
- buf++;
- len--;
- }
-
- if (mymode < 3) {
- array_init(return_value);
- }
-
- for (inx=0; inx < 256; inx++) {
- switch (mymode) {
- case 0:
- add_index_long(return_value, inx, chars[inx]);
- break;
- case 1:
- if (chars[inx] != 0) {
- add_index_long(return_value, inx, chars[inx]);
- }
- break;
- case 2:
- if (chars[inx] == 0) {
- add_index_long(return_value, inx, chars[inx]);
- }
- break;
- case 3:
- if (chars[inx] != 0) {
- retstr[retlen++] = inx;
- }
- break;
- case 4:
- if (chars[inx] == 0) {
- retstr[retlen++] = inx;
- }
- break;
- }
- }
-
- if (mymode >= 3 && mymode <= 4) {
- RETURN_STRINGL(retstr, retlen, 1);
- }
-}
-/* }}} */
-
-/* {{{ php_strnatcmp
- */
-static void php_strnatcmp(INTERNAL_FUNCTION_PARAMETERS, int fold_case)
-{
- zval **s1, **s2;
-
- if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(s1);
- convert_to_string_ex(s2);
-
- RETURN_LONG(strnatcmp_ex((*s1)->value.str.val, (*s1)->value.str.len,
- (*s2)->value.str.val, (*s2)->value.str.len,
- fold_case));
-}
-/* }}} */
-
-/* {{{ proto int strnatcmp(string s1, string s2)
- Returns the result of string comparison using 'natural' algorithm */
-PHP_FUNCTION(strnatcmp)
-{
- php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
-}
-/* }}} */
-
-/* {{{ proto array localeconv( void )
- Returns numeric formatting information based on the current locale */
-PHP_FUNCTION(localeconv)
-{
- zval *grouping, *mon_grouping;
- int len, i;
-
- MAKE_STD_ZVAL(grouping);
- MAKE_STD_ZVAL(mon_grouping);
-
- /* We don't need no stinkin' parameters... */
- if (ZEND_NUM_ARGS() > 0) {
- WRONG_PARAM_COUNT;
- }
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- if (array_init(grouping) == FAILURE || array_init(mon_grouping) == FAILURE) {
- RETURN_FALSE;
- }
-
-#ifdef HAVE_LOCALECONV
- {
- struct lconv currlocdata;
-
- localeconv_r( &currlocdata );
-
- /* Grab the grouping data out of the array */
- len = strlen(currlocdata.grouping);
-
- for (i=0;i<len;i++) {
- add_index_long(grouping, i, currlocdata.grouping[i]);
- }
-
- /* Grab the monetary grouping data out of the array */
- len = strlen(currlocdata.mon_grouping);
-
- for (i=0;i<len;i++) {
- add_index_long(mon_grouping, i, currlocdata.mon_grouping[i]);
- }
-
- add_assoc_string(return_value, "decimal_point", currlocdata.decimal_point, 1);
- add_assoc_string(return_value, "thousands_sep", currlocdata.thousands_sep, 1);
- add_assoc_string(return_value, "int_curr_symbol", currlocdata.int_curr_symbol, 1);
- add_assoc_string(return_value, "currency_symbol", currlocdata.currency_symbol, 1);
- add_assoc_string(return_value, "mon_decimal_point", currlocdata.mon_decimal_point, 1);
- add_assoc_string(return_value, "mon_thousands_sep", currlocdata.mon_thousands_sep, 1);
- add_assoc_string(return_value, "positive_sign", currlocdata.positive_sign, 1);
- add_assoc_string(return_value, "negative_sign", currlocdata.negative_sign, 1);
- add_assoc_long( return_value, "int_frac_digits", currlocdata.int_frac_digits );
- add_assoc_long( return_value, "frac_digits", currlocdata.frac_digits );
- add_assoc_long( return_value, "p_cs_precedes", currlocdata.p_cs_precedes );
- add_assoc_long( return_value, "p_sep_by_space", currlocdata.p_sep_by_space );
- add_assoc_long( return_value, "n_cs_precedes", currlocdata.n_cs_precedes );
- add_assoc_long( return_value, "n_sep_by_space", currlocdata.n_sep_by_space );
- add_assoc_long( return_value, "p_sign_posn", currlocdata.p_sign_posn );
- add_assoc_long( return_value, "n_sign_posn", currlocdata.n_sign_posn );
- }
-#else
- /* Ok, it doesn't look like we have locale info floating around, so I guess it
- wouldn't hurt to just go ahead and return the POSIX locale information? */
-
- add_index_long(grouping, 0, -1);
- add_index_long(mon_grouping, 0, -1);
-
- add_assoc_string(return_value, "decimal_point", "\x2E", 1);
- add_assoc_string(return_value, "thousands_sep", "", 1);
- add_assoc_string(return_value, "int_curr_symbol", "", 1);
- add_assoc_string(return_value, "currency_symbol", "", 1);
- add_assoc_string(return_value, "mon_decimal_point", "\x2E", 1);
- add_assoc_string(return_value, "mon_thousands_sep", "", 1);
- add_assoc_string(return_value, "positive_sign", "", 1);
- add_assoc_string(return_value, "negative_sign", "", 1);
- add_assoc_long( return_value, "int_frac_digits", CHAR_MAX );
- add_assoc_long( return_value, "frac_digits", CHAR_MAX );
- add_assoc_long( return_value, "p_cs_precedes", CHAR_MAX );
- add_assoc_long( return_value, "p_sep_by_space", CHAR_MAX );
- add_assoc_long( return_value, "n_cs_precedes", CHAR_MAX );
- add_assoc_long( return_value, "n_sep_by_space", CHAR_MAX );
- add_assoc_long( return_value, "p_sign_posn", CHAR_MAX );
- add_assoc_long( return_value, "n_sign_posn", CHAR_MAX );
-#endif
-
- zend_hash_update(return_value->value.ht, "grouping", 9, &grouping, sizeof(zval *), NULL);
- zend_hash_update(return_value->value.ht, "mon_grouping", 13, &mon_grouping, sizeof(zval *), NULL);
-}
-/* }}} */
-
-/* {{{ proto int strnatcasecmp(string s1, string s2)
- Returns the result of case-insensitive string comparison using 'natural' algorithm */
-PHP_FUNCTION(strnatcasecmp)
-{
- php_strnatcmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
-}
-/* }}} */
-
-/* {{{ proto int substr_count(string haystack, string needle)
- Returns the number of times a substring occurs in the string */
-PHP_FUNCTION(substr_count)
-{
- zval **haystack, **needle;
- int i, length, count = 0;
- char *p, *endp, cmp;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &haystack, &needle) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- convert_to_string_ex(haystack);
- convert_to_string_ex(needle);
-
- if ((*needle)->value.str.len == 0) {
- php_error(E_WARNING, "Empty substring");
- RETURN_FALSE;
- } else if ((*needle)->value.str.len == 1) {
- /* Special optimized case to avoid calls to php_memnstr(). */
- for (i = 0, p = (*haystack)->value.str.val,
- length = (*haystack)->value.str.len, cmp = (*needle)->value.str.val[0];
- i < length; i++) {
- if (p[i] == cmp) {
- count++;
- }
- }
- } else {
- p = (*haystack)->value.str.val;
- endp = p + (*haystack)->value.str.len;
- while (p <= endp) {
- if( (p = php_memnstr(p, (*needle)->value.str.val, (*needle)->value.str.len, endp)) != NULL ) {
- p += (*needle)->value.str.len;
- count++;
- } else {
- break;
- }
- }
- }
-
- RETURN_LONG(count);
-}
-/* }}} */
-
-/* {{{ proto string str_pad(string input, int pad_length [, string pad_string [, int pad_type]])
- Returns input string padded on the left or right to specified length with pad_string */
-PHP_FUNCTION(str_pad)
-{
- /* Input arguments */
- zval **input, /* Input string */
- **pad_length, /* Length to pad to */
- **pad_string, /* Padding string */
- **pad_type; /* Padding type (left/right/both) */
-
- /* Helper variables */
- int num_pad_chars; /* Number of padding characters (total - input size) */
- char *result = NULL; /* Resulting string */
- int result_len = 0; /* Length of the resulting string */
- char *pad_str_val = " "; /* Pointer to padding string */
- int pad_str_len = 1; /* Length of the padding string */
- int pad_type_val = STR_PAD_RIGHT; /* The padding type value */
- int i, left_pad=0, right_pad=0;
-
-
- if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 4 ||
- zend_get_parameters_ex(ZEND_NUM_ARGS(), &input, &pad_length, &pad_string, &pad_type) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- /* Perform initial conversion to expected data types. */
- convert_to_string_ex(input);
- convert_to_long_ex(pad_length);
-
- num_pad_chars = Z_LVAL_PP(pad_length) - Z_STRLEN_PP(input);
-
- /* If resulting string turns out to be shorter than input string,
- we simply copy the input and return. */
- if (num_pad_chars < 0) {
- *return_value = **input;
- zval_copy_ctor(return_value);
- return;
- }
-
- /* Setup the padding string values if specified. */
- if (ZEND_NUM_ARGS() > 2) {
- convert_to_string_ex(pad_string);
- if (Z_STRLEN_PP(pad_string) == 0) {
- php_error(E_WARNING, "Padding string cannot be empty in %s()",
- get_active_function_name(TSRMLS_C));
- return;
- }
- pad_str_val = Z_STRVAL_PP(pad_string);
- pad_str_len = Z_STRLEN_PP(pad_string);
-
- if (ZEND_NUM_ARGS() > 3) {
- convert_to_long_ex(pad_type);
- pad_type_val = Z_LVAL_PP(pad_type);
- if (pad_type_val < STR_PAD_LEFT || pad_type_val > STR_PAD_BOTH) {
- php_error(E_WARNING, "Padding type has to be STR_PAD_LEFT, STR_PAD_RIGHT, or STR_PAD_BOTH in %s()", get_active_function_name(TSRMLS_C));
- return;
- }
- }
- }
-
- result = (char *)emalloc(Z_STRLEN_PP(input) + num_pad_chars + 1);
-
- /* We need to figure out the left/right padding lengths. */
- switch (pad_type_val) {
- case STR_PAD_RIGHT:
- left_pad = 0;
- right_pad = num_pad_chars;
- break;
-
- case STR_PAD_LEFT:
- left_pad = num_pad_chars;
- right_pad = 0;
- break;
-
- case STR_PAD_BOTH:
- left_pad = num_pad_chars / 2;
- right_pad = num_pad_chars - left_pad;
- break;
- }
-
- /* First we pad on the left. */
- for (i = 0; i < left_pad; i++)
- result[result_len++] = pad_str_val[i % pad_str_len];
-
- /* Then we copy the input string. */
- memcpy(result + result_len, Z_STRVAL_PP(input), Z_STRLEN_PP(input));
- result_len += Z_STRLEN_PP(input);
-
- /* Finally, we pad on the right. */
- for (i = 0; i < right_pad; i++)
- result[result_len++] = pad_str_val[i % pad_str_len];
-
- result[result_len] = '\0';
-
- RETURN_STRINGL(result, result_len, 0);
-}
-/* }}} */
-
-/* {{{ proto mixed sscanf(string str, string format [, string ...])
- Implements an ANSI C compatible sscanf */
-PHP_FUNCTION(sscanf)
-{
- zval **format;
- zval **literal;
- int result;
- zval ***args;
- int argCount;
-
- argCount = ZEND_NUM_ARGS();
- if (argCount < 2) {
- WRONG_PARAM_COUNT;
- }
- args = (zval ***)emalloc(argCount * sizeof(zval **));
- if (!args || (zend_get_parameters_array_ex(argCount, args) == FAILURE)) {
- efree( args );
- WRONG_PARAM_COUNT;
- }
-
- literal = args[0];
- format = args[1];
-
- convert_to_string_ex( format );
- convert_to_string_ex( literal );
-
- result = php_sscanf_internal( (*literal)->value.str.val,
- (*format)->value.str.val,
- argCount, args,
- 2, &return_value TSRMLS_CC);
- efree(args);
-
- if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
- WRONG_PARAM_COUNT;
- }
-
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c
deleted file mode 100644
index c21f5ce0aa..0000000000
--- a/ext/standard/strnatcmp.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/* -*- mode: c; c-file-style: "k&r" -*-
-
- Modified for PHP by Andrei Zmievski <andrei@ispi.net>
-
- strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
- Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include <ctype.h>
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
-
-#include "php.h"
-#include "php_string.h"
-
-#if defined(__GNUC__)
-# define UNUSED __attribute__((__unused__))
-#else
-# define UNUSED
-#endif
-
-static char const *version UNUSED =
- "$Id$";
-/* {{{ compare_right
- */
-static int
-compare_right(char const **a, char const *aend, char const **b, char const *bend)
-{
- int bias = 0;
-
- /* The longest run of digits wins. That aside, the greatest
- value wins, but we can't know that it will until we've scanned
- both numbers to know that they have the same magnitude, so we
- remember it in BIAS. */
- for(;; (*a)++, (*b)++) {
- if ((*a == aend || !isdigit((int)**a)) &&
- (*b == bend || !isdigit((int)**b)))
- return bias;
- else if (*a == aend || !isdigit((int)**a))
- return -1;
- else if (*b == bend || !isdigit((int)**b))
- return +1;
- else if (**a < **b) {
- if (!bias)
- bias = -1;
- } else if (**a > **b) {
- if (!bias)
- bias = +1;
- }
- }
-
- return 0;
-}
-/* }}} */
-
-/* {{{ compare_left
- */
-static int
-compare_left(char const **a, char const *aend, char const **b, char const *bend)
-{
- /* Compare two left-aligned numbers: the first to have a
- different value wins. */
- for(;; (*a)++, (*b)++) {
- if ((*a == aend || !isdigit((int)**a)) &&
- (*b == bend || !isdigit((int)**b)))
- return 0;
- else if (*a == aend || !isdigit((int)**a))
- return -1;
- else if (*b == bend || !isdigit((int)**b))
- return +1;
- else if (**a < **b)
- return -1;
- else if (**a > **b)
- return +1;
- }
-
- return 0;
-}
-/* }}} */
-
-/* {{{ strnatcmp_ex
- */
-PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len, int fold_case)
-{
- char ca, cb;
- char const *ap, *bp;
- char const *aend = a + a_len,
- *bend = b + b_len;
- int fractional, result;
-
- if (a_len == 0 || b_len == 0)
- return a_len - b_len;
-
- ap = a;
- bp = b;
- while (1) {
- ca = *ap; cb = *bp;
-
- /* skip over leading spaces or zeros */
- while (isspace((int)ca))
- ca = *++ap;
-
- while (isspace((int)cb))
- cb = *++bp;
-
- /* process run of digits */
- if (isdigit((int)ca) && isdigit((int)cb)) {
- fractional = (ca == '0' || cb == '0');
-
- if (fractional)
- result = compare_left(&ap, aend, &bp, bend);
- else
- result = compare_right(&ap, aend, &bp, bend);
-
- if (result != 0)
- return result;
- else if (ap == aend && bp == bend)
- /* End of the strings. Let caller sort them out. */
- return 0;
- else {
- /* Keep on comparing from the current point. */
- ca = *ap; cb = *bp;
- }
- }
-
- if (fold_case) {
- ca = toupper(ca);
- cb = toupper(cb);
- }
-
- if (ca < cb)
- return -1;
- else if (ca > cb)
- return +1;
-
- ++ap; ++bp;
- if (ap == aend && bp == bend)
- /* The strings compare the same. Perhaps the caller
- will want to call strcmp to break the tie. */
- return 0;
- else if (ap == aend)
- return -1;
- else if (bp == bend)
- return 1;
- }
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/syslog.c b/ext/standard/syslog.c
deleted file mode 100644
index a166496d81..0000000000
--- a/ext/standard/syslog.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Stig Sæther Bakken <ssb@fast.no> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#ifdef HAVE_SYSLOG_H
-#include "php_ini.h"
-#include "zend_globals.h"
-
-#include <stdlib.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <string.h>
-#include <errno.h>
-
-#include <stdio.h>
-#include "basic_functions.h"
-#include "php_ext_syslog.h"
-
-static void start_syslog(TSRMLS_D);
-
-/* {{{ PHP_MINIT_FUNCTION
- */
-PHP_MINIT_FUNCTION(syslog)
-{
- /* error levels */
- REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
- REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
- REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
- REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
- /* facility: type of program logging the message */
- REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
- REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
- REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
- REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
-#ifdef LOG_NEWS
- /* No LOG_NEWS on HP-UX */
- REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */
-#endif
-#ifdef LOG_UUCP
- /* No LOG_UUCP on HP-UX */
- REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
-#endif
-#ifdef LOG_CRON
- /* apparently some systems don't have this one */
- REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
-#endif
-#ifdef LOG_AUTHPRIV
- /* AIX doesn't have LOG_AUTHPRIV */
- REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
-#endif
-#if !defined(PHP_WIN32)
- REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
-#endif
- /* options */
- REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
-#ifdef LOG_NOWAIT
- REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
-#endif
-#ifdef LOG_PERROR
- /* AIX doesn't have LOG_PERROR */
- REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
-#endif
-
- return SUCCESS;
-}
-/* }}} */
-
-PHP_RINIT_FUNCTION(syslog)
-{
- if (INI_INT("define_syslog_variables")) {
- start_syslog(TSRMLS_C);
- } else {
- BG(syslog_started)=0;
- }
- BG(syslog_device)=NULL;
- return SUCCESS;
-}
-
-
-PHP_RSHUTDOWN_FUNCTION(syslog)
-{
- if (BG(syslog_device)) {
- efree(BG(syslog_device));
- }
- return SUCCESS;
-}
-
-/* {{{ start_syslog
- */
-static void start_syslog(TSRMLS_D)
-{
- /* error levels */
- SET_VAR_LONG("LOG_EMERG", LOG_EMERG); /* system unusable */
- SET_VAR_LONG("LOG_ALERT", LOG_ALERT); /* immediate action required */
- SET_VAR_LONG("LOG_CRIT", LOG_CRIT); /* critical conditions */
- SET_VAR_LONG("LOG_ERR", LOG_ERR);
- SET_VAR_LONG("LOG_WARNING", LOG_WARNING);
- SET_VAR_LONG("LOG_NOTICE", LOG_NOTICE);
- SET_VAR_LONG("LOG_INFO", LOG_INFO);
- SET_VAR_LONG("LOG_DEBUG", LOG_DEBUG);
- /* facility: type of program logging the message */
- SET_VAR_LONG("LOG_KERN", LOG_KERN);
- SET_VAR_LONG("LOG_USER", LOG_USER); /* generic user level */
- SET_VAR_LONG("LOG_MAIL", LOG_MAIL); /* log to email */
- SET_VAR_LONG("LOG_DAEMON", LOG_DAEMON); /* other system daemons */
- SET_VAR_LONG("LOG_AUTH", LOG_AUTH);
- SET_VAR_LONG("LOG_SYSLOG", LOG_SYSLOG);
- SET_VAR_LONG("LOG_LPR", LOG_LPR);
-#ifdef LOG_NEWS
- /* No LOG_NEWS on HP-UX */
- SET_VAR_LONG("LOG_NEWS", LOG_NEWS); /* usenet new */
-#endif
-#ifdef LOG_UUCP
- /* No LOG_UUCP on HP-UX */
- SET_VAR_LONG("LOG_UUCP", LOG_UUCP);
-#endif
-#ifdef LOG_CRON
- /* apparently some systems don't have this one */
- SET_VAR_LONG("LOG_CRON", LOG_CRON);
-#endif
-#ifdef LOG_AUTHPRIV
- /* AIX doesn't have LOG_AUTHPRIV */
- SET_VAR_LONG("LOG_AUTHPRIV", LOG_AUTHPRIV);
-#endif
-#if !defined(PHP_WIN32)
- SET_VAR_LONG("LOG_LOCAL0", LOG_LOCAL0);
- SET_VAR_LONG("LOG_LOCAL1", LOG_LOCAL1);
- SET_VAR_LONG("LOG_LOCAL2", LOG_LOCAL2);
- SET_VAR_LONG("LOG_LOCAL3", LOG_LOCAL3);
- SET_VAR_LONG("LOG_LOCAL4", LOG_LOCAL4);
- SET_VAR_LONG("LOG_LOCAL5", LOG_LOCAL5);
- SET_VAR_LONG("LOG_LOCAL6", LOG_LOCAL6);
- SET_VAR_LONG("LOG_LOCAL7", LOG_LOCAL7);
-#endif
- /* options */
- SET_VAR_LONG("LOG_PID", LOG_PID);
- SET_VAR_LONG("LOG_CONS", LOG_CONS);
- SET_VAR_LONG("LOG_ODELAY", LOG_ODELAY);
- SET_VAR_LONG("LOG_NDELAY", LOG_NDELAY);
-#ifdef LOG_NOWAIT
- /* BeOS doesn't have LOG_NOWAIT */
- SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT);
-#endif
-#ifdef LOG_PERROR
- /* AIX doesn't have LOG_PERROR */
- SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/
-#endif
-
- BG(syslog_started)=1;
-}
-/* }}} */
-
-/* {{{ proto void define_syslog_variables(void)
- Initializes all syslog-related variables */
-PHP_FUNCTION(define_syslog_variables)
-{
- if (!BG(syslog_started)) {
- start_syslog(TSRMLS_C);
- }
-}
-/* }}} */
-
-/* {{{ proto int openlog(string ident, int option, int facility)
- Open connection to system logger */
-/*
- ** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
- ** Syslog($LOG_EMERG, "help me!")
- ** CloseLog();
- */
-PHP_FUNCTION(openlog)
-{
- pval **ident, **option, **facility;
-
- if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &ident, &option, &facility) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(ident);
- convert_to_long_ex(option);
- convert_to_long_ex(facility);
- if (BG(syslog_device)) {
- efree(BG(syslog_device));
- }
- BG(syslog_device) = estrndup((*ident)->value.str.val, (*ident)->value.str.len);
- openlog(BG(syslog_device), (*option)->value.lval, (*facility)->value.lval);
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int closelog(void)
- Close connection to system logger */
-PHP_FUNCTION(closelog)
-{
- closelog();
- if (BG(syslog_device)) {
- efree(BG(syslog_device));
- BG(syslog_device)=NULL;
- }
- RETURN_TRUE;
-}
-/* }}} */
-
-/* {{{ proto int syslog(int priority, string message)
- Generate a system log message */
-PHP_FUNCTION(syslog)
-{
- pval **priority, **message;
-
- if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &priority, &message) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_long_ex(priority);
- convert_to_string_ex(message);
-
- /*
- * CAVEAT: if the message contains patterns such as "%s",
- * this will cause problems.
- */
-
- php_syslog((*priority)->value.lval, "%.500s", (*message)->value.str.val);
- RETURN_TRUE;
-}
-/* }}} */
-
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/tests/assert/assert.phpt b/ext/standard/tests/assert/assert.phpt
deleted file mode 100644
index 7322bac851..0000000000
--- a/ext/standard/tests/assert/assert.phpt
+++ /dev/null
@@ -1,39 +0,0 @@
---TEST--
-assert()
---POST--
---GET--
---FILE--
-<?
-function a($file,$line,$myev)
-{
- echo "assertion failed $line,\"$myev\"\n";
-}
-
-class a
-{
- function assert($file,$line,$myev)
- {
- echo "class assertion failed $line,\"$myev\"\n";
- }
-}
-
-assert_options(ASSERT_ACTIVE,1);
-assert_options(ASSERT_QUIET_EVAL,1);
-assert_options(ASSERT_WARNING,0);
-
-$a = 0;
-
-assert_options(ASSERT_CALLBACK,"a");
-assert('$a != 0');
-
-assert_options(ASSERT_CALLBACK,array("a","assert"));
-assert('$a != 0');
-
-$obj = new a();
-assert_options(ASSERT_CALLBACK,array(&$obj,"assert"));
-assert('$a != 0');
-?>
---EXPECT--
-assertion failed 22,"$a != 0"
-class assertion failed 25,"$a != 0"
-class assertion failed 29,"$a != 0"
diff --git a/ext/standard/tests/file/001.phpt b/ext/standard/tests/file/001.phpt
deleted file mode 100644
index 6c1410c805..0000000000
--- a/ext/standard/tests/file/001.phpt
+++ /dev/null
@@ -1,149 +0,0 @@
---TEST--
-File type functions
---POST--
---GET--
---FILE--
-<?php
-@unlink('test.file');
-@unlink('test.link');
-if (file_exists('test.file')) {
- echo "test.file exists\n";
-} else {
- echo "test.file does not exist\n";
-}
-fclose (fopen('test.file', 'w'));
-chmod ('test.file', 0654);
-if (file_exists('test.file')) {
- echo "test.file exists\n";
-} else {
- echo "test.file does not exist\n";
-}
-sleep (2);
-symlink('test.file','test.link');
-if (file_exists('test.link')) {
- echo "test.link exists\n";
-} else {
- echo "test.link does not exist\n";
-}
-if (is_link('test.file')) {
- echo "test.file is a symlink\n";
-} else {
- echo "test.file is not a symlink\n";
-}
-if (is_link('test.link')) {
- echo "test.link is a symlink\n";
-} else {
- echo "test.link is not a symlink\n";
-}
-if (file_exists('test.file')) {
- echo "test.file exists\n";
-} else {
- echo "test.file does not exist\n";
-}
-$s = stat ('test.file');
-$ls = lstat ('test.file');
-for ($i = 0; $i <= 12; $i++) {
- if ($ls[$i] != $s[$i]) {
- echo "test.file lstat and stat differ at element $i\n";
- }
-}
-$s = stat ('test.link');
-$ls = lstat ('test.link');
-for ($i = 0; $i <= 11; $i++) {
- if ($ls[$i] != $s[$i]) {
- if ($i != 6 && $i != 11) echo "test.link lstat and stat differ at element $i\n";
- }
-}
-echo "test.file is " . filetype('test.file') . "\n";
-echo "test.link is " . filetype('test.link') . "\n";
-printf ("test.file permissions are 0%o\n", 0777 & fileperms('test.file'));
-echo "test.file size is " . filesize('test.file') . "\n";
-if (is_writeable('test.file')) {
- echo "test.file is writeable\n";
-} else {
- echo "test.file is not writeable\n";
-}
-if (is_readable('test.file')) {
- echo "test.file is readable\n";
-} else {
- echo "test.file is not readable\n";
-}
-if (is_executable('test.file')) {
- echo "test.file is executable\n";
-} else {
- echo "test.file is not executable\n";
-}
-chmod ('test.file', 0644);
-clearstatcache();
-if (is_executable('test.file')) {
- echo "test.file is executable\n";
-} else {
- echo "test.file is not executable\n";
-}
-if (is_file('test.file')) {
- echo "test.file is a regular file\n";
-} else {
- echo "test.file is not a regular file\n";
-}
-if (is_file('test.link')) {
- echo "test.link is a regular file\n";
-} else {
- echo "test.link is not a regular file\n";
-}
-if (is_dir('test.link')) {
- echo "test.link is a directory\n";
-} else {
- echo "test.link is not a directory\n";
-}
-if (is_dir('../file')) {
- echo "../file is a directory\n";
-} else {
- echo "../file is not a directory\n";
-}
-if (is_dir('test.file')) {
- echo "test.file is a directory\n";
-} else {
- echo "test.file is not a directory\n";
-}
-unlink('test.file');
-unlink('test.link');
-if (file_exists('test.file')) {
- echo "test.file exists (cached)\n";
-} else {
- echo "test.file does not exist\n";
-}
-clearstatcache();
-if (file_exists('test.file')) {
- echo "test.file exists\n";
-} else {
- echo "test.file does not exist\n";
-}
-?>
---EXPECT--
-test.file does not exist
-test.file exists
-test.link exists
-test.file is not a symlink
-test.link is a symlink
-test.file exists
-test.link lstat and stat differ at element 1
-test.link lstat and stat differ at element 2
-test.link lstat and stat differ at element 7
-test.link lstat and stat differ at element 8
-test.link lstat and stat differ at element 9
-test.link lstat and stat differ at element 10
-test.file is file
-test.link is link
-test.file permissions are 0654
-test.file size is 0
-test.file is writeable
-test.file is readable
-test.file is not executable
-test.file is not executable
-test.file is a regular file
-test.link is a regular file
-test.link is not a directory
-../file is a directory
-test.file is not a directory
-test.file does not exist
-test.file does not exist
diff --git a/ext/standard/tests/general_functions/001.phpt b/ext/standard/tests/general_functions/001.phpt
deleted file mode 100644
index ee6d32f7f8..0000000000
--- a/ext/standard/tests/general_functions/001.phpt
+++ /dev/null
@@ -1,55 +0,0 @@
---TEST--
-sprintf() function
---POST--
---GET--
---FILE--
-<?php
-
-$agent = sprintf("%.5s", "James Bond, 007");
-
-echo("sprintf string truncate test: ");
-if ($agent == "James") {
- echo("passed\n");
-} else {
- echo("failed!\n");
-}
-
-echo("sprintf padding and align test: ");
-$test = sprintf("abc%04d %-20s%c", 20, "fisketur", 33);
-if ($test == "abc0020 fisketur !") {
- echo("passed\n");
-} else {
- echo("failed!\n");
-}
-
-echo("sprintf octal and hex test: ");
-$test = sprintf("%4o %4x %4X %0"."8x", 128, 1024, 49151, 3457925);
-if ($test == " 200 400 BFFF 0034c385") {
- echo("passed\n");
-} else {
- echo("failed!\n");
-}
-
-echo("sprintf octal binary test: ");
-$test = sprintf("%b", 3457925);
-if ($test == "1101001100001110000101") {
- echo("passed\n");
-} else {
- echo("failed!\n");
-}
-
-echo("sprintf float test: ");
-$test = sprintf("%0"."06.2f", 10000/3.0);
-if ($test == "003333.33") {
- echo("passed\n");
-} else {
- echo("failed!\n");
-}
-
-?>
---EXPECT--
-sprintf string truncate test: passed
-sprintf padding and align test: passed
-sprintf octal and hex test: passed
-sprintf octal binary test: passed
-sprintf float test: passed
diff --git a/ext/standard/tests/general_functions/002.phpt b/ext/standard/tests/general_functions/002.phpt
deleted file mode 100644
index d78bdb9afa..0000000000
--- a/ext/standard/tests/general_functions/002.phpt
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-quoted_printable_decode() function test
---POST--
---GET--
---FILE--
-<?php echo quoted_printable_decode("=FAwow-factor=C1=D0=D5=DD=C5=CE=CE=D9=C5=0A=
-=20=D4=CF=D2=C7=CF=D7=D9=C5=
-=20=
-=D0=
-=D2=CF=C5=CB=D4=D9"); ?>
---EXPECT--
-úwow-factorÁÐÕÝÅÎÎÙÅ
- ÔÏÒÇÏ×ÙÅ ÐÒÏÅËÔÙ \ No newline at end of file
diff --git a/ext/standard/tests/general_functions/003.phpt b/ext/standard/tests/general_functions/003.phpt
deleted file mode 100644
index 22cbd4eb4e..0000000000
--- a/ext/standard/tests/general_functions/003.phpt
+++ /dev/null
@@ -1,54 +0,0 @@
---TEST--
-levenshtein() function test
---POST--
---GET--
---FILE--
-<?php
-
-function test_me($title,$expect,$text1,$text2,$cost1=0,$cost2=0,$cost3=0) {
-
- if($cost1==0)
- $result=levenshtein($text1,$text2);
- else
- $result=levenshtein($text1,$text2,$cost1,$cost2,$cost3);
-
- if($result==$expect) return 0;
-
- echo "$title: result is $result instead of $expect ";
- echo "for '$text1'/'$text2' ";
- if($cost1) echo "($cost1:$cost2:$cost3)";
- echo "\n";
-
- return 1;
-}
-
-$n=0;
-
-$n += test_me("equal" , 0, "12345", "12345");
-$n += test_me("1st empty" , 3, "", "xzy");
-$n += test_me("2nd empty" , 3, "xzy", "");
-$n += test_me("both empty" , 0, "", "");
-$n += test_me("1 char" , 1, "1", "2");
-$n += test_me("2 char swap", 2, "12", "21");
-
-$n += test_me("inexpensive delete", 2, "2121", "11", 2, 1, 1);
-$n += test_me("expensive delete" , 10, "2121", "11", 2, 1, 5);
-$n += test_me("inexpensive insert", 2, "11", "2121", 1, 1, 1);
-$n += test_me("expensive insert" , 10, "11", "2121", 5, 1, 1);
-
-$n += test_me("expensive replace" , 3, "111", "121", 2, 3, 2);
-$n += test_me("very expensive replace", 4, "111", "121", 2, 9, 2);
-
-$n += test_me("bug #7368", 2, "13458", "12345");
-$n += test_me("bug #7368", 2, "1345", "1234");
-
-$n += test_me("bug #6562", 1, "debugg", "debug");
-$n += test_me("bug #6562", 1, "ddebug", "debug");
-$n += test_me("bug #6562", 2, "debbbug", "debug");
-$n += test_me("bug #6562", 1, "debugging", "debuging");
-
-echo ($n==0)?"all passed\n":"$n failed\n";
-
-?>
---EXPECT--
-all passed
diff --git a/ext/standard/tests/general_functions/004.data b/ext/standard/tests/general_functions/004.data
deleted file mode 100644
index 5dd0832842..0000000000
--- a/ext/standard/tests/general_functions/004.data
+++ /dev/null
@@ -1,4 +0,0 @@
-name value comment
-true 1 boolean true
-false 0 boolean false
-empty nothing
diff --git a/ext/standard/tests/general_functions/004.phpt b/ext/standard/tests/general_functions/004.phpt
deleted file mode 100644
index 0566502ab5..0000000000
--- a/ext/standard/tests/general_functions/004.phpt
+++ /dev/null
@@ -1,17 +0,0 @@
---TEST--
-fgetcsv() with tab delimited fields (BUG #8258)
---POST--
---GET--
---FILE--
-<?php
-$fp=fopen("004.data","r");
-while($a=fgetcsv($fp,100,"\t")) {
- echo join(",",$a)."\n";
-}
-fclose($fp);
-?>
---EXPECT--
-name,value,comment
-true,1,boolean true
-false,0,boolean false
-empty,,nothing
diff --git a/ext/standard/tests/general_functions/005.phpt b/ext/standard/tests/general_functions/005.phpt
deleted file mode 100644
index 329d46e764..0000000000
--- a/ext/standard/tests/general_functions/005.phpt
+++ /dev/null
@@ -1,26 +0,0 @@
---TEST--
-is_scalar() function test
---POST--
---GET--
---FILE--
-<?php
-class foo {}
-var_dump (is_scalar (TRUE));
-var_dump (is_scalar (1));
-var_dump (is_scalar (1.0));
-var_dump (is_scalar ("Hi!"));
-var_dump (is_scalar (NULL));
-var_dump (is_scalar (array ()));
-var_dump (is_scalar (new foo()));
-var_dump (is_scalar (opendir('.')));
-?>
---EXPECT--
-bool(true)
-bool(true)
-bool(true)
-bool(true)
-bool(false)
-bool(false)
-bool(false)
-bool(false)
-
diff --git a/ext/standard/tests/math/001.phpt b/ext/standard/tests/math/001.phpt
deleted file mode 100644
index a79d32c580..0000000000
--- a/ext/standard/tests/math/001.phpt
+++ /dev/null
@@ -1,45 +0,0 @@
---TEST--
-Simple math tests
---POST--
---GET--
---FILE--
-<?php
-
-define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF);
-define('LONG_MIN', -LONG_MAX - 1);
-printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ),
- is_int(LONG_MIN-1),is_int(LONG_MAX+1));
-
-$tests = <<<TESTS
- 1 === abs(-1)
- 1.5 === abs(-1.5)
- 1 === abs("-1")
- 1.5 === abs("-1.5")
--LONG_MIN+1 === abs(LONG_MIN-1)
--LONG_MIN === abs(LONG_MIN)
--(LONG_MIN+1) === abs(LONG_MIN+1)
--1 === ceil(-1.5)
- 2 === ceil( 1.5)
--2 === floor(-1.5)
- 1 === floor(1.5)
- LONG_MIN === ceil(LONG_MIN - 0.5)
- LONG_MIN+1 === ceil(LONG_MIN + 0.5)
- LONG_MIN-1 === round(LONG_MIN - 0.6)
- LONG_MIN === round(LONG_MIN - 0.4)
- LONG_MIN === round(LONG_MIN + 0.4)
- LONG_MIN+1 === round(LONG_MIN + 0.6)
- LONG_MIN-1 === floor(LONG_MIN - 0.5)
- LONG_MIN === floor(LONG_MIN + 0.5)
- LONG_MAX === ceil(LONG_MAX - 0.5)
- LONG_MAX+1 === ceil(LONG_MAX + 0.5)
- LONG_MAX-1 === round(LONG_MAX - 0.6)
- LONG_MAX === round(LONG_MAX - 0.4)
- LONG_MAX === round(LONG_MAX + 0.4)
- LONG_MAX+1 === round(LONG_MAX + 0.6)
- LONG_MAX-1 === floor(LONG_MAX - 0.5)
- LONG_MAX === floor(LONG_MAX + 0.5)
-TESTS;
-
-include('../../../../tests/quicktester.inc');
---EXPECT--
-OK
diff --git a/ext/standard/tests/math/pow.phpt b/ext/standard/tests/math/pow.phpt
deleted file mode 100644
index 150db4ad38..0000000000
--- a/ext/standard/tests/math/pow.phpt
+++ /dev/null
@@ -1,144 +0,0 @@
---TEST--
-Various pow() tests
---POST--
---GET--
---FILE--
-<?php
-define('LONG_MAX', is_int(5000000000)? 9223372036854775807 : 0x7FFFFFFF);
-define('LONG_MIN', -LONG_MAX - 1);
-printf("%d,%d,%d,%d\n",is_int(LONG_MIN ),is_int(LONG_MAX ),
- is_int(LONG_MIN-1),is_int(LONG_MAX+1));
-
-$tests = <<<TESTS
- 0.25 === pow(-2,-2)
--0.5 === pow(-2,-1)
- 1 === pow(-2, 0)
--2 === pow(-2, 1)
- 4 === pow(-2, 2)
- 1 === pow(-1,-2)
--1 === pow(-1,-1)
- 1 === pow(-1, 0)
--1 === pow(-1, 1)
- 1 === pow(-1, 2)
-FALSE ===@pow( 0,-2)
-FALSE ===@pow( 0,-1)
- 1 === pow( 0, 0)
- 0 === pow( 0, 1)
- 0 === pow( 0, 2)
- 1 === pow( 1,-2)
- 1 === pow( 1,-1)
- 1 === pow( 1, 0)
- 1 === pow( 1, 1)
- 1 === pow( 1, 2)
- 0.25 === pow( 2,-2)
- 0.5 === pow( 2,-1)
- 1 === pow( 2, 0)
- 2 === pow( 2, 1)
- 4 === pow( 2, 2)
-FALSE ===@pow(-2,-2.0)
-FALSE ===@pow(-2,-1.0)
-FALSE ===@pow(-2, 0.0)
-FALSE ===@pow(-2, 1.0)
-FALSE ===@pow(-2, 2.0)
-FALSE ===@pow(-1,-2.0)
-FALSE ===@pow(-1,-1.0)
-FALSE ===@pow(-1, 0.0)
-FALSE ===@pow(-1, 1.0)
-FALSE ===@pow(-1, 2.0)
-FALSE ===@pow( 0,-2.0)
-FALSE ===@pow( 0,-1.0)
-FALSE ===@pow( 0, 0.0)
-FALSE ===@pow( 0, 1.0)
-FALSE ===@pow( 0, 2.0)
- 1.0 === pow( 1,-2.0)
- 1.0 === pow( 1,-1.0)
- 1.0 === pow( 1, 0.0)
- 1.0 === pow( 1, 1.0)
- 1.0 === pow( 1, 2.0)
- 0.25 === pow( 2,-2.0)
- 0.5 === pow( 2,-1.0)
- 1.0 === pow( 2, 0.0)
- 2.0 === pow( 2, 1.0)
- 4.0 === pow( 2, 2.0)
- 2147483648 === pow(2,31)
--2147483648 === pow(-2,31)
- 1000000000 === pow(10,9)
- 100000000 === pow(-10,8)
- 1 === pow(-1,1443279822)
--1 === pow(-1,1443279821)
-sqrt(2) === pow(2,1/2)
-FALSE ===@pow(-2.0,-2.0)
-FALSE ===@pow(-2.0,-1.0)
-FALSE ===@pow(-2.0, 0.0)
-FALSE ===@pow(-2.0, 1.0)
-FALSE ===@pow(-2.0, 2.0)
-FALSE ===@pow(-1.0,-2.0)
-FALSE ===@pow(-1.0,-1.0)
-FALSE ===@pow(-1.0, 0.0)
-FALSE ===@pow(-1.0, 1.0)
-FALSE ===@pow(-1.0, 2.0)
-FALSE ===@pow( 0.0,-2.0)
-FALSE ===@pow( 0.0,-1.0)
-FALSE ===@pow( 0.0, 0.0)
-FALSE ===@pow( 0.0, 1.0)
-FALSE ===@pow( 0.0, 2.0)
- 1.0 === pow( 1.0,-2.0)
- 1.0 === pow( 1.0,-1.0)
- 1.0 === pow( 1.0, 0.0)
- 1.0 === pow( 1.0, 1.0)
- 1.0 === pow( 1.0, 2.0)
- 0.25 === pow( 2.0,-2.0)
- 0.5 === pow( 2.0,-1.0)
- 1.0 === pow( 2.0, 0.0)
- 2.0 === pow( 2.0, 1.0)
- 4.0 === pow( 2.0, 2.0)
- 0.25 === pow(-2.0,-2)
--0.5 === pow(-2.0,-1)
- 1.0 === pow(-2.0, 0)
--2.0 === pow(-2.0, 1)
- 4.0 === pow(-2.0, 2)
- 1.0 === pow(-1.0,-2)
--1.0 === pow(-1.0,-1)
- 1.0 === pow(-1.0, 0)
--1.0 === pow(-1.0, 1)
- 1.0 === pow(-1.0, 2)
-FALSE ===@pow( 0.0,-2)
-FALSE ===@pow( 0.0,-1)
- 1.0 === pow( 0.0, 0)
- 0.0 === pow( 0.0, 1)
- 0.0 === pow( 0.0, 2)
- 1.0 === pow( 1.0,-2)
- 1.0 === pow( 1.0,-1)
- 1.0 === pow( 1.0, 0)
- 1.0 === pow( 1.0, 1)
- 1.0 === pow( 1.0, 2)
- 0.25 === pow( 2.0,-2)
- 0.5 === pow( 2.0,-1)
- 1.0 === pow( 2.0, 0)
- 2.0 === pow( 2.0, 1)
- 4.0 === pow( 2.0, 2)
-LONG_MAX-1 === pow(LONG_MAX-1,1)
-LONG_MIN+1 === pow(LONG_MIN+1,1)
-(LONG_MAX-1)*(LONG_MAX-1) === pow(LONG_MAX-1,2)
-(LONG_MIN+1)*(LONG_MIN+1) === pow(LONG_MIN+1,2)
-(float)(LONG_MAX-1) === pow(LONG_MAX-1,1.0)
-FALSE ===@pow(LONG_MIN+1,1.0)
-(LONG_MAX-1)*(LONG_MAX-1) === pow(LONG_MAX-1,2.0)
-FALSE ===@pow(LONG_MIN+1,2.0)
-LONG_MAX === pow(LONG_MAX,1)
-LONG_MIN === pow(LONG_MIN,1)
-LONG_MAX*LONG_MAX === pow(LONG_MAX,2)
-LONG_MIN*LONG_MIN === pow(LONG_MIN,2)
-(float)LONG_MAX === pow(LONG_MAX,1.0)
-FALSE ===@pow(LONG_MIN,1.0)
-LONG_MAX*LONG_MAX === pow(LONG_MAX,2.0)
-FALSE ===@pow(LONG_MIN,2.0)
-TESTS;
-
- echo "On failure, please mail result to jeroen@php.net\n";
- include('../../../../tests/quicktester.inc');
-
---EXPECT--
-1,1,0,0
-On failure, please mail result to jeroen@php.net
-OK
diff --git a/ext/standard/tests/reg/001.phpt b/ext/standard/tests/reg/001.phpt
deleted file mode 100644
index f63c252518..0000000000
--- a/ext/standard/tests/reg/001.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-RegReplace test 1
---POST--
---GET--
---FILE--
-<?php $a="abc123";
- echo ereg_replace("123","def",$a)?>
---EXPECT--
-abcdef
diff --git a/ext/standard/tests/reg/002.phpt b/ext/standard/tests/reg/002.phpt
deleted file mode 100644
index a9b7aaa00a..0000000000
--- a/ext/standard/tests/reg/002.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-RegReplace test 2
---POST--
---GET--
---FILE--
-<?php $a="abc123";
- echo ereg_replace("123","",$a)?>
---EXPECT--
-abc
diff --git a/ext/standard/tests/reg/003.phpt b/ext/standard/tests/reg/003.phpt
deleted file mode 100644
index edd9c05969..0000000000
--- a/ext/standard/tests/reg/003.phpt
+++ /dev/null
@@ -1,10 +0,0 @@
---TEST--
-ereg_replace single-quote test
---POST--
---GET--
---FILE--
-<?php $a="\\'test";
- echo ereg_replace("\\\\'","'",$a)
-?>
---EXPECT--
-'test
diff --git a/ext/standard/tests/reg/004.phpt b/ext/standard/tests/reg/004.phpt
deleted file mode 100644
index 1f60ff4900..0000000000
--- a/ext/standard/tests/reg/004.phpt
+++ /dev/null
@@ -1,16 +0,0 @@
---TEST--
-simple ereg test
---POST--
---GET--
---FILE--
-<?php $a="This is a nice and simple string";
- if (ereg(".*nice and simple.*",$a)) {
- echo "ok\n";
- }
- if (!ereg(".*doesn't exist.*",$a)) {
- echo "ok\n";
- }
-?>
---EXPECT--
-ok
-ok
diff --git a/ext/standard/tests/reg/005.phpt b/ext/standard/tests/reg/005.phpt
deleted file mode 100644
index 78c0a0912a..0000000000
--- a/ext/standard/tests/reg/005.phpt
+++ /dev/null
@@ -1,20 +0,0 @@
---TEST--
-Test Regular expression register support in ereg
---POST--
---GET--
---FILE--
-<?php $a="This is a nice and simple string";
- echo ereg(".*(is).*(is).*",$a,$registers);
- echo "\n";
- echo $registers[0];
- echo "\n";
- echo $registers[1];
- echo "\n";
- echo $registers[2];
- echo "\n";
-?>
---EXPECT--
-32
-This is a nice and simple string
-is
-is
diff --git a/ext/standard/tests/reg/006.phpt b/ext/standard/tests/reg/006.phpt
deleted file mode 100644
index 50b6dbfd3a..0000000000
--- a/ext/standard/tests/reg/006.phpt
+++ /dev/null
@@ -1,10 +0,0 @@
---TEST--
-Test ereg_replace of start-of-line
---POST--
---GET--
---FILE--
-<?php $a="This is a nice and simple string";
- echo ereg_replace("^This","That",$a);
-?>
---EXPECT--
-That is a nice and simple string
diff --git a/ext/standard/tests/reg/007.phpt b/ext/standard/tests/reg/007.phpt
deleted file mode 100644
index b2646f842f..0000000000
--- a/ext/standard/tests/reg/007.phpt
+++ /dev/null
@@ -1,12 +0,0 @@
---TEST--
-Test empty result buffer in reg_replace
---POST--
---GET--
---FILE--
-<?php
- $a="abcd";
- $b=ereg_replace("abcd","",$a);
- echo "strlen(\$b)=".strlen($b);
-?>
---EXPECT--
-strlen($b)=0
diff --git a/ext/standard/tests/reg/008.phpt b/ext/standard/tests/reg/008.phpt
deleted file mode 100644
index db61d1ca07..0000000000
--- a/ext/standard/tests/reg/008.phpt
+++ /dev/null
@@ -1,10 +0,0 @@
---TEST--
-Test back-references in regular expressions
---POST--
---GET--
---FILE--
-<?php
- echo ereg_replace("([a-z]*)([-=+|]*)([0-9]+)","\\3 \\1 \\2\n","abc+-|=123");
-?>
---EXPECT--
-123 abc +-|=
diff --git a/ext/standard/tests/reg/009.phpt b/ext/standard/tests/reg/009.phpt
deleted file mode 100644
index 4996ef4c97..0000000000
--- a/ext/standard/tests/reg/009.phpt
+++ /dev/null
@@ -1,19 +0,0 @@
---TEST--
-Test split()
---POST--
---GET--
---FILE--
-<?php
- $a=split("[[:space:]]","this is a
-test");
- echo count($a) . "\n";
- for ($i = 0; $i < count($a); $i++) {
- echo $a[$i] . "\n";
- }
-?>
---EXPECT--
-4
-this
-is
-a
-test
diff --git a/ext/standard/tests/reg/010.phpt b/ext/standard/tests/reg/010.phpt
deleted file mode 100644
index 30d28fd02f..0000000000
--- a/ext/standard/tests/reg/010.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-Long back references
---POST--
---GET--
---FILE--
-<?php $a="abc122222222223";
- echo ereg_replace("1(2*)3","\\1def\\1",$a)?>
---EXPECT--
-abc2222222222def2222222222
diff --git a/ext/standard/tests/reg/011.phpt b/ext/standard/tests/reg/011.phpt
deleted file mode 100644
index 4eda774f58..0000000000
--- a/ext/standard/tests/reg/011.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-\0 back reference
---POST--
---GET--
---FILE--
-<?php $a="abc123";
- echo ereg_replace("123","def\\0ghi",$a)?>
---EXPECT--
-abcdef123ghi
diff --git a/ext/standard/tests/reg/012.phpt b/ext/standard/tests/reg/012.phpt
deleted file mode 100644
index d5342c7436..0000000000
--- a/ext/standard/tests/reg/012.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-nonexisting back reference
---POST--
---GET--
---FILE--
-<?php $a="abc123";
- echo ereg_replace("123",'def\1ghi',$a)?>
---EXPECT--
-abcdef\1ghi
diff --git a/ext/standard/tests/reg/013.phpt b/ext/standard/tests/reg/013.phpt
deleted file mode 100644
index ec3329fa7c..0000000000
--- a/ext/standard/tests/reg/013.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-escapes in replace string
---POST--
---GET--
---FILE--
-<?php $a="abc123";
- echo ereg_replace("123","def\\g\\\\hi\\",$a)?>
---EXPECT--
-abcdef\g\\hi\
diff --git a/ext/standard/tests/reg/014.phpt b/ext/standard/tests/reg/014.phpt
deleted file mode 100644
index ec4d19ed0e..0000000000
--- a/ext/standard/tests/reg/014.phpt
+++ /dev/null
@@ -1,9 +0,0 @@
---TEST--
-backreferences not replaced recursively
---POST--
---GET--
---FILE--
-<?php $a="a\\2bxc";
- echo ereg_replace("a(.*)b(.*)c","\\1",$a)?>
---EXPECT--
-\2
diff --git a/ext/standard/tests/reg/015.phpt b/ext/standard/tests/reg/015.phpt
deleted file mode 100644
index 961a60fa76..0000000000
--- a/ext/standard/tests/reg/015.phpt
+++ /dev/null
@@ -1,8 +0,0 @@
---TEST--
-replace empty matches
---POST--
---GET--
---FILE--
-<?php echo ereg_replace("^","z","abc123")?>
---EXPECT--
-zabc123
diff --git a/ext/standard/tests/reg/016.phpt b/ext/standard/tests/reg/016.phpt
deleted file mode 100644
index a24816f182..0000000000
--- a/ext/standard/tests/reg/016.phpt
+++ /dev/null
@@ -1,8 +0,0 @@
---TEST--
-test backslash handling in regular expressions
---POST--
---GET--
---FILE--
-<?php echo ereg_replace('\?',"abc","?123?")?>
---EXPECT--
-abc123abc
diff --git a/ext/standard/tests/serialize/001.phpt b/ext/standard/tests/serialize/001.phpt
deleted file mode 100644
index 78f90ed627..0000000000
--- a/ext/standard/tests/serialize/001.phpt
+++ /dev/null
@@ -1,111 +0,0 @@
---TEST--
-serialize()/unserialize()/var_dump()
---POST--
---GET--
---FILE--
-<?php
-class t
-{
- function t()
- {
- $this->a = "hallo";
- }
-}
-
-class s
-{
- function s()
- {
- $this->a = "hallo";
- $this->b = "php";
- $this->c = "world";
- }
-
- function __sleep()
- {
- echo "__sleep called\n";
- return array("a","c");
- }
-
- function __wakeup()
- {
- echo "__wakeup called\n";
- }
-}
-
-
-echo serialize(NULL)."\n";
-echo serialize((bool) true)."\n";
-echo serialize((bool) false)."\n";
-echo serialize(1)."\n";
-echo serialize(0)."\n";
-echo serialize(-1)."\n";
-echo serialize(1.123456789)."\n";
-echo serialize(1.0)."\n";
-echo serialize(0.0)."\n";
-echo serialize(-1.0)."\n";
-echo serialize(-1.123456789)."\n";
-echo serialize("hallo")."\n";
-echo serialize(array(1,1.1,"hallo",NULL,true,array()))."\n";
-
-$t = new t();
-$data = serialize($t);
-echo "$data\n";
-$t = unserialize($data);
-var_dump($t);
-
-$t = new s();
-$data = serialize($t);
-echo "$data\n";
-$t = unserialize($data);
-var_dump($t);
-
-$a = array("a" => "test");
-$a[ "b" ] = &$a[ "a" ];
-var_dump($a);
-$data = serialize($a);
-echo "$data\n";
-$a = unserialize($data);
-var_dump($a);
-?>
---EXPECT--
-N;
-b:1;
-b:0;
-i:1;
-i:0;
-i:-1;
-d:1.123456789;
-d:1;
-d:0;
-d:-1;
-d:-1.123456789;
-s:5:"hallo";
-a:6:{i:0;i:1;i:1;d:1.1;i:2;s:5:"hallo";i:3;N;i:4;b:1;i:5;a:0:{}}
-O:1:"t":1:{s:1:"a";s:5:"hallo";}
-object(t)(1) {
- ["a"]=>
- string(5) "hallo"
-}
-__sleep called
-O:1:"s":2:{s:1:"a";s:5:"hallo";s:1:"c";s:5:"world";}
-__wakeup called
-object(s)(2) {
- ["a"]=>
- string(5) "hallo"
- ["c"]=>
- string(5) "world"
-}
-array(2) {
- ["a"]=>
- &string(4) "test"
- ["b"]=>
- &string(4) "test"
-}
-a:2:{s:1:"a";s:4:"test";s:1:"b";R:2;}
-array(2) {
- ["a"]=>
- &string(4) "test"
- ["b"]=>
- &string(4) "test"
-}
diff --git a/ext/standard/tests/strings/trim.phpt b/ext/standard/tests/strings/trim.phpt
deleted file mode 100644
index e46512d271..0000000000
--- a/ext/standard/tests/strings/trim.phpt
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-trim() function
---POST--
---GET--
---FILE--
-<?php
-
-$tests = <<<TESTS
-'ABC' === trim('ABC')
-'ABC' === ltrim('ABC')
-'ABC' === rtrim('ABC')
-'ABC' === trim(" \\0\\t\\nABC \\0\\t\\n")
-"ABC \\0\\t\\n" === ltrim(" \\0\\t\\nABC \\0\\t\\n")
-" \\0\\t\\nABC" === rtrim(" \\0\\t\\nABC \\0\\t\\n")
-" \\0\\t\\nABC \\0\\t\\n" === trim(" \\0\\t\\nABC \\0\\t\\n",'')
-" \\0\\t\\nABC \\0\\t\\n" === ltrim(" \\0\\t\\nABC \\0\\t\\n",'')
-" \\0\\t\\nABC \\0\\t\\n" === rtrim(" \\0\\t\\nABC \\0\\t\\n",'')
-"ABC\\x50\\xC1" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC0")
-"ABC\\x50" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC1")
-"ABC" === trim("ABC\\x50\\xC1\\x60\\x90","\\x50..\\xC1")
-"ABC\\x50\\xC1" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC0")
-"ABC\\x50" === trim("ABC\\x50\\xC1\\x60\\x90","\\x51..\\xC1")
-"ABC" === trim("ABC\\x50\\xC1\\x60\\x90","\\x50..\\xC1")
-TESTS;
-
-include('../../../../tests/quicktester.inc');
-
---EXPECT--
-OK
diff --git a/ext/standard/tests/time/001.phpt b/ext/standard/tests/time/001.phpt
deleted file mode 100644
index 004a498bac..0000000000
--- a/ext/standard/tests/time/001.phpt
+++ /dev/null
@@ -1,19 +0,0 @@
---TEST--
-microtime() function
---POST--
---GET--
---FILE--
-<?php
-$passed = 0;
-$failed = 0;
-for ($i=1;$i<=100000;$i++) {
- list($micro,$time)=explode(" ",microtime());
- $add=$micro+$time;
- $add<$last ? $failed++: $passed++;
- $last=$add; }
-echo "Passed: ".$passed."\n";
-echo "Failed: ".$failed."\n";
-?>
---EXPECT--
-Passed: 100000
-Failed: 0 \ No newline at end of file
diff --git a/ext/standard/tests/time/002.phpt b/ext/standard/tests/time/002.phpt
deleted file mode 100644
index 766af4d773..0000000000
--- a/ext/standard/tests/time/002.phpt
+++ /dev/null
@@ -1,40 +0,0 @@
---TEST--
-strtotime() function
---POST--
---GET--
---FILE--
-<?php
- echo "1999-10-13\n";
- echo strtotime ("1999-10-13")."\n";
- echo strtotime ("Oct 13 1999")."\n\n";
-
- echo "2000-01-19\n";
- echo strtotime ("2000-01-19")."\n";
- echo strtotime ("Jan 19 2000")."\n\n";
-
- echo "2001-12-21\n";
- echo strtotime ("2001-12-21")."\n";
- echo strtotime ("Dec 21 2001")."\n\n";
-
- echo "2001-12-21 12:16\n";
- echo strtotime ("2001-12-21 12:16")."\n";
- echo strtotime ("Dec 21 2001 12:16")."\n";
- echo strtotime ("Dec 21 12:16")."\n";
-?>
---EXPECT--
-1999-10-13
-939765600
-939765600
-
-2000-01-19
-948236400
-948236400
-
-2001-12-21
-1008889200
-1008889200
-
-2001-12-21 12:16
-1008933360
-1008933360
--1
diff --git a/ext/standard/type.c b/ext/standard/type.c
deleted file mode 100644
index b782df1c85..0000000000
--- a/ext/standard/type.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@php.net> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include "php.h"
-#include "type.h"
-
-/* {{{ php_check_type
- * Determines if 'str' is an integer (long), real number or a string
- *
- * Note that leading zeroes automatically force a STRING type
- */
-int php_check_type(char *str)
-{
- char *s;
- int type = IS_LONG;
-
- s = str;
- if (*s == '0' && *(s + 1) && *(s + 1) != '.')
- return (IS_STRING);
- if (*s == '+' || *s == '-' || (*s >= '0' && *s <= '9') || *s == '.') {
- if (*s == '.')
- type = IS_DOUBLE;
- s++;
- while (*s) {
- if (*s >= '0' && *s <= '9') {
- s++;
- continue;
- } else if (*s == '.' && type == IS_LONG) {
- type = IS_DOUBLE;
- s++;
- continue;
- } else
- return (IS_STRING);
- }
- } else
- return (IS_STRING);
-
- return (type);
-} /* php_check_type */
-/* }}} */
-
-/* {{{ php_check_ident_type
- * 0 - simple variable
- * 1 - non-index array
- * 2 - index array
- */
-int php_check_ident_type(char *str)
-{
- char *s;
-
- if (!(s = (char *) strchr(str, '[')))
- return (GPC_REGULAR);
- s++;
- while (*s == ' ' || *s == '\t' || *s == '\n') {
- s++;
- }
- if (*s == ']') {
- return (GPC_NON_INDEXED_ARRAY);
- }
- return (GPC_INDEXED_ARRAY);
-}
-/* }}} */
-
-/* {{{ php_get_ident_index
- */
-char *php_get_ident_index(char *str)
-{
- char *temp;
- char *s, *t;
- char o;
-
- temp = emalloc(strlen(str));
- temp[0] = '\0';
- s = (char *) strchr(str, '[');
- if (s) {
- t = (char *) strrchr(str, ']');
- if (t) {
- o = *t;
- *t = '\0';
- strcpy(temp, s + 1);
- *t = o;
- }
- }
- return (temp);
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/type.h b/ext/standard/type.h
deleted file mode 100644
index 20a351b041..0000000000
--- a/ext/standard/type.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef TYPE_H
-#define TYPE_H
-
-extern int php_check_type(char *str);
-extern int php_check_ident_type(char *str);
-extern char *php_get_ident_index(char *str);
-
-#define GPC_REGULAR 0x1
-#define GPC_INDEXED_ARRAY 0x2
-#define GPC_NON_INDEXED_ARRAY 0x4
-#define GPC_ARRAY (GPC_INDEXED_ARRAY | GPC_NON_INDEXED_ARRAY)
-
-#endif
diff --git a/ext/standard/uniqid.c b/ext/standard/uniqid.c
deleted file mode 100644
index 741510264e..0000000000
--- a/ext/standard/uniqid.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Stig Sæther Bakken <ssb@guardian.no> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#include "php.h"
-
-#include <stdlib.h>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <string.h>
-#include <errno.h>
-
-#include <stdio.h>
-#ifdef PHP_WIN32
-#include "win32/time.h"
-#else
-#include <sys/time.h>
-#endif
-
-#include "php_lcg.h"
-#include "uniqid.h"
-
-#define MORE_ENTROPY (argc == 2 && (*flags)->value.lval)
-
-/* {{{ proto string uniqid(string prefix, [bool more_entropy])
- Generate a unique id */
-PHP_FUNCTION(uniqid)
-{
-#ifdef HAVE_GETTIMEOFDAY
- pval **prefix, **flags;
- char uniqid[138];
- int sec, usec, argc;
- struct timeval tv;
-
- argc = ZEND_NUM_ARGS();
- if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &prefix, &flags)) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(prefix);
- if (argc == 2) {
- convert_to_boolean_ex(flags);
- }
-
- /* Do some bounds checking since we are using a char array. */
- if ((*prefix)->value.str.len > 114) {
- php_error(E_WARNING, "The prefix to uniqid should not be more than 114 characters.");
- return;
- }
-#if HAVE_USLEEP && !defined(PHP_WIN32)
- if (!MORE_ENTROPY) {
- usleep(1);
- }
-#endif
- gettimeofday((struct timeval *) &tv, (struct timezone *) NULL);
- sec = (int) tv.tv_sec;
- usec = (int) (tv.tv_usec % 1000000);
-
- /* The max value usec can have is 0xF423F, so we use only five hex
- * digits for usecs.
- */
- if (MORE_ENTROPY) {
- sprintf(uniqid, "%s%08x%05x%.8f", (*prefix)->value.str.val, sec, usec, php_combined_lcg(TSRMLS_C) * 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:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/uniqid.h b/ext/standard/uniqid.h
deleted file mode 100644
index 9cf6345622..0000000000
--- a/ext/standard/uniqid.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Stig Sæther Bakken <ssb@guardian.no> |
- +----------------------------------------------------------------------+
- */
-
-/* $Id$ */
-
-#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 b2484ea53f..0000000000
--- a/ext/standard/url.c
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Jim Winstead (jimw@php.net) |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/types.h>
-
-#include "php.h"
-
-#include "url.h"
-#ifdef _OSD_POSIX
-#ifndef APACHE
-#error On this EBCDIC platform, PHP is only supported as an Apache module.
-#else /*APACHE*/
-#ifndef CHARSET_EBCDIC
-#define CHARSET_EBCDIC /* this machine uses EBCDIC, not ASCII! */
-#endif
-#include "ebcdic.h"
-#endif /*APACHE*/
-#endif /*_OSD_POSIX*/
-
-/* {{{ free_url
- */
-PHPAPI void php_url_free(php_url *theurl)
-{
- if (theurl->scheme)
- efree(theurl->scheme);
- if (theurl->user)
- efree(theurl->user);
- if (theurl->pass)
- efree(theurl->pass);
- if (theurl->host)
- efree(theurl->host);
- if (theurl->path)
- efree(theurl->path);
- if (theurl->query)
- efree(theurl->query);
- if (theurl->fragment)
- efree(theurl->fragment);
- efree(theurl);
-}
-/* }}} */
-
-/* {{{ url_parse
- */
-PHPAPI php_url *php_url_parse(char *str)
-{
- regex_t re;
- regmatch_t subs[11];
- int err;
- int length = strlen(str);
- char *result;
-
- php_url *ret = (php_url *) emalloc(sizeof(php_url));
- if (!ret) {
- /*php_error(E_WARNING, "Unable to allocate memory\n");*/
- return NULL;
- }
- memset(ret, 0, sizeof(php_url));
-
- /* from Appendix B of draft-fielding-url-syntax-09,
- http://www.ics.uci.edu/~fielding/url/url.txt */
- err = regcomp(&re, "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?", REG_EXTENDED);
- if (err) {
- /*php_error(E_WARNING, "Unable to compile regex: %d\n", err);*/
- efree(ret);
- return NULL;
- }
- err = regexec(&re, str, 10, subs, 0);
- if (err) {
- /*php_error(E_WARNING, "Error with regex\n");*/
- efree(ret);
- regfree(&re);
- return NULL;
- }
- /* no processing necessary on the scheme */
- if (subs[2].rm_so != -1 && subs[2].rm_so <= length) {
- ret->scheme = estrndup(str + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
- }
-
- /* the path to the resource */
- if (subs[5].rm_so != -1 && subs[5].rm_so <= length) {
- ret->path = estrndup(str + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so);
- }
-
- /* the query part */
- if (subs[7].rm_so != -1 && subs[7].rm_so <= length) {
- ret->query = estrndup(str + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
- }
-
- /* the fragment */
- if (subs[9].rm_so != -1 && subs[9].rm_so <= length) {
- ret->fragment = estrndup(str + subs[9].rm_so, subs[9].rm_eo - subs[9].rm_so);
- }
-
- /* extract the username, pass, and port from the hostname */
- if (subs[4].rm_so != -1 && subs[4].rm_so <= length) {
-
- int cerr;
- /* extract username:pass@host:port from regex results */
- result = estrndup(str + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
- length = strlen(result);
-
- regfree(&re); /* free the old regex */
-
- if ((cerr=regcomp(&re, "^(([^@:]+)(:([^@:]+))?@)?((\\[([^]]+)\\])|([^:@]+))(:([^:@]+))?", REG_EXTENDED))
- || (err=regexec(&re, result, 11, subs, 0))) {
- STR_FREE(ret->scheme);
- STR_FREE(ret->path);
- STR_FREE(ret->query);
- STR_FREE(ret->fragment);
- efree(ret);
- efree(result);
- /*php_error(E_WARNING, "Unable to compile regex: %d\n", err);*/
- if (!cerr) regfree(&re);
- return NULL;
- }
- /* now deal with all of the results */
- if (subs[2].rm_so != -1 && subs[2].rm_so < length) {
- ret->user = estrndup(result + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
- }
- if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
- ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
- }
- if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
- ret->host = estrndup(result + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
- } else if (subs[8].rm_so != -1 && subs[8].rm_so < length) {
- ret->host = estrndup(result + subs[8].rm_so, subs[8].rm_eo - subs[8].rm_so);
- }
- if (subs[10].rm_so != -1 && subs[10].rm_so < length) {
- ret->port = (unsigned short) strtol(result + subs[10].rm_so, NULL, 10);
- }
- efree(result);
- }
- else if (ret->scheme && !strcmp(ret->scheme, "http")) {
- STR_FREE(ret->scheme);
- STR_FREE(ret->path);
- STR_FREE(ret->query);
- STR_FREE(ret->fragment);
- efree(ret);
- regfree(&re);
- return NULL;
- }
- regfree(&re);
- return ret;
-}
-/* }}} */
-
-/* {{{ proto array parse_url(string url)
- Parse a URL and return its components */
-PHP_FUNCTION(parse_url)
-{
- pval **str;
- php_url *resource;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(str);
-
- resource = php_url_parse((*str)->value.str.val);
-
- if (resource == NULL) {
- php_error(E_WARNING, "unable to parse url (%s)", (*str)->value.str.val);
- RETURN_FALSE;
- }
- /* allocate an array for return */
- if (array_init(return_value) == FAILURE) {
- php_url_free(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);
- php_url_free(resource);
-}
-/* }}} */
-
-/* {{{ php_htoi
- */
-static int php_htoi(char *s)
-{
- int value;
- int c;
-
- c = s[0];
- if (isupper(c))
- c = tolower(c);
- value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
-
- c = s[1];
- if (isupper(c))
- c = tolower(c);
- value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
-
- return (value);
-}
-/* }}} */
-
-/* rfc1738:
-
- ...The characters ";",
- "/", "?", ":", "@", "=" and "&" are the characters which may be
- reserved for special meaning within a scheme...
-
- ...Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
- reserved characters used for their reserved purposes may be used
- unencoded within a URL...
-
- For added safety, we only leave -_. unencoded.
- */
-
-static unsigned char hexchars[] = "0123456789ABCDEF";
-
-/* {{{ php_url_encode
- */
-PHPAPI char *php_url_encode(char *s, int len, int *new_length)
-{
- register int x, y;
- unsigned char *str;
-
- str = (unsigned char *) emalloc(3 * 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) {
- /* Allow only alphanumeric chars and '_', '-', '.'; escape the rest */
- str[y++] = '%';
- str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
- str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
- }
-#endif /*CHARSET_EBCDIC*/
- }
- str[y] = '\0';
- if (new_length) {
- *new_length = y;
- }
- return ((char *) str);
-}
-/* }}} */
-
-/* {{{ proto string urlencode(string str)
- URL-encodes string */
-PHP_FUNCTION(urlencode)
-{
- pval **arg;
- char *str;
- int str_len;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (!(*arg)->value.str.len) {
- ZVAL_FALSE(return_value);
- return;
- }
- str = php_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &str_len);
- RETVAL_STRINGL(str, str_len, 0);
-}
-/* }}} */
-
-/* {{{ proto string urldecode(string str)
- Decodes URL-encoded string */
-PHP_FUNCTION(urldecode)
-{
- pval **arg;
- int len;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (!(*arg)->value.str.len) {
- ZVAL_FALSE(return_value);
- return;
- }
-
- *return_value = **arg;
- zval_copy_ctor(return_value);
-
- len = php_url_decode(return_value->value.str.val, return_value->value.str.len);
- return_value->value.str.len = len;
-}
-/* }}} */
-
-/* {{{ php_url_decode
- */
-PHPAPI int php_url_decode(char *str, int len)
-{
- char *dest = str;
- char *data = str;
-
- while (len--) {
- if (*data == '+')
- *dest = ' ';
- else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) {
-#ifndef CHARSET_EBCDIC
- *dest = (char) php_htoi(data + 1);
-#else
- *dest = os_toebcdic[(char) php_htoi(data + 1)];
-#endif
- data += 2;
- len -= 2;
- } else
- *dest = *data;
- data++;
- dest++;
- }
- *dest = '\0';
- return dest - str;
-}
-/* }}} */
-
-/* {{{ php_raw_url_encode
- */
-PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length)
-{
- register int x, y;
- unsigned char *str;
-
- str = (unsigned char *) emalloc(3 * len + 1);
- for (x = 0, y = 0; len--; x++, y++) {
- str[y] = (unsigned char) s[x];
-#ifndef CHARSET_EBCDIC
- if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
- (str[y] < 'A' && str[y] > '9') ||
- (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
- (str[y] > 'z')) {
- str[y++] = '%';
- str[y++] = hexchars[(unsigned char) s[x] >> 4];
- str[y] = hexchars[(unsigned char) s[x] & 15];
-#else /*CHARSET_EBCDIC*/
- if (!isalnum(str[y]) && strchr("_-.", str[y]) != NULL) {
- str[y++] = '%';
- str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
- str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 15];
-#endif /*CHARSET_EBCDIC*/
- }
- }
- str[y] = '\0';
- if (new_length) {
- *new_length = y;
- }
- return ((char *) str);
-}
-/* }}} */
-
-/* {{{ proto string rawurlencode(string str)
- URL-encodes string */
-PHP_FUNCTION(rawurlencode)
-{
- pval **arg;
- char *str;
- int new_len;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (!(*arg)->value.str.len) {
- RETURN_FALSE;
- }
- str = php_raw_url_encode((*arg)->value.str.val, (*arg)->value.str.len, &new_len);
- RETVAL_STRINGL(str, new_len, 0);
-}
-/* }}} */
-
-/* {{{ proto string rawurldecode(string str)
- Decodes URL-encodes string */
-PHP_FUNCTION(rawurldecode)
-{
- pval **arg;
- int len;
- char *str;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string_ex(arg);
-
- if (!(*arg)->value.str.len) {
- RETURN_FALSE;
- }
- str = estrndup(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg));
- len = php_raw_url_decode(str, Z_STRLEN_PP(arg));
-
- RETVAL_STRINGL(str, len, 0);
-}
-/* }}} */
-
-/* {{{ php_raw_url_decode
- */
-PHPAPI int php_raw_url_decode(char *str, int len)
-{
- char *dest = str;
- char *data = str;
-
- while (len--) {
- if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) {
-#ifndef CHARSET_EBCDIC
- *dest = (char) php_htoi(data + 1);
-#else
- *dest = os_toebcdic[(char) php_htoi(data + 1)];
-#endif
- data += 2;
- len -= 2;
- } else
- *dest = *data;
- data++;
- dest++;
- }
- *dest = '\0';
- return dest - str;
-}
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/url.h b/ext/standard/url.h
deleted file mode 100644
index ab63f28a28..0000000000
--- a/ext/standard/url.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jim Winstead (jimw@php.net) |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#ifndef URL_H
-#define URL_H
-
-typedef struct php_url {
- char *scheme;
- char *user;
- char *pass;
- char *host;
- unsigned short port;
- char *path;
- char *query;
- char *fragment;
-} php_url;
-
-PHPAPI void php_url_free(php_url *theurl);
-PHPAPI php_url *php_url_parse(char *str);
-PHPAPI int php_url_decode(char *str, int len); /* return value: length of decoded string */
-PHPAPI int php_raw_url_decode(char *str, int len); /* return value: length of decoded string */
-PHPAPI char *php_url_encode(char *s, int len, int *new_length);
-PHPAPI char *php_raw_url_encode(char *s, int len, int *new_length);
-
-PHP_FUNCTION(parse_url);
-PHP_FUNCTION(urlencode);
-PHP_FUNCTION(urldecode);
-PHP_FUNCTION(rawurlencode);
-PHP_FUNCTION(rawurldecode);
-
-#endif /* URL_H */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
diff --git a/ext/standard/url_scanner.c b/ext/standard/url_scanner.c
deleted file mode 100644
index 07b46f7fa2..0000000000
--- a/ext/standard/url_scanner.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Hartmut Holzgraefe <hartmut@six.de> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#include "php.h"
-
-#ifdef TRANS_SID
-
-#include "php_globals.h"
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "basic_functions.h"
-#include "url_scanner.h"
-
-#ifndef BUFSIZE
-#define BUFSIZE 256
-#endif
-
-PHP_RINIT_FUNCTION(url_scanner)
-{
- url_adapt(NULL,0,NULL,NULL);
- return SUCCESS;
-}
-
-
-PHP_RSHUTDOWN_FUNCTION(url_scanner)
-{
- url_adapt(NULL,0,NULL,NULL);
- return SUCCESS;
-}
-
-/* {{{ url_attr_addon
- */
-static char *url_attr_addon(const char *tag,const char *attr,const char *val,const char *buf)
-{
- int flag = 0;
- TSRMLS_FETCH();
-
- if(!strcasecmp(tag,"a") && !strcasecmp(attr,"href")) {
- flag = 1;
- } else if(!strcasecmp(tag,"area" ) && !strcasecmp(attr,"href" )) {
- flag = 1;
- } else if(!strcasecmp(tag,"form" ) && !strcasecmp(attr,"action" )) {
- flag = 1;
- } else if(!strcasecmp(tag,"frame") && !strcasecmp(attr,"source" )) {
- flag = 1;
- } else if(!strcasecmp(tag,"img" ) && !strcasecmp(attr,"action" )) {
- flag = 1;
- }
- if(flag) {
- if(!strstr(val,buf)&&!strchr(val,':'))
- {
- char *result = (char *)emalloc(strlen(buf)+strlen(PG(arg_separator).output)+1);
- int n;
-
- if(strchr(val,'?')) {
- strcpy(result,PG(arg_separator).output);
- n=strlen(PG(arg_separator).output);
- } else {
- *result='?';
- n=1;
- }
- strcpy(result+n,buf);
- return result;
- }
- }
- return NULL;
-}
-/* }}} */
-
-#define US BG(url_adapt_state)
-
-/* {{{ url_adapt_ext
- */
-char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *val, size_t *newlen)
-{
- char buf[1024];
-
- snprintf(buf, sizeof(buf)-1, "%s=%s", name, val);
-
- return url_adapt(src, srclen, buf, newlen);
-}
-/* }}} */
-
-/* {{{ url_adapt
- */
-char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen)
-{
- char *out,*outp;
- int maxl,n;
- TSRMLS_FETCH();
-
- if(src==NULL) {
- US.state=STATE_NORMAL;
- if(US.tag) { efree(US.tag); US.tag =NULL; }
- if(US.attr) { efree(US.attr); US.attr=NULL; }
- if(US.val) { efree(US.val); US.val =NULL; }
- return NULL;
- }
-
- if(srclen==0)
- srclen=strlen(src);
-
- out=malloc(srclen+1);
- maxl=srclen;
- n=srclen;
-
- *newlen=0;
- outp=out;
-
- while(n--) {
- switch(US.state) {
- case STATE_NORMAL:
- if(*src=='<')
- US.state=STATE_TAG_START;
- break;
-
- case STATE_TAG_START:
- if(! isalnum(*src))
- US.state=STATE_NORMAL;
- US.state=STATE_TAG;
- US.ml=BUFSIZE;
- US.p=US.tag=erealloc(US.tag,US.ml);
- *(US.p)++=*src;
- US.l=1;
- break;
-
- case STATE_TAG:
- if(isalnum(*src)) {
- *(US.p)++ = *src;
- US.l++;
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.tag=erealloc(US.tag,US.ml);
- US.p = US.tag+US.l;
- }
- } else if (isspace(*src)) {
- US.state = STATE_IN_TAG;
- *US.p='\0';
- US.tag=erealloc(US.tag,US.l);
- } else {
- US.state = STATE_NORMAL;
- efree(US.tag);
- US.tag=NULL;
- }
- break;
-
- case STATE_IN_TAG:
- if(isalnum(*src)) {
- US.state=STATE_TAG_ATTR;
- US.ml=BUFSIZE;
- US.p=US.attr=erealloc(US.attr,US.ml);
- *(US.p)++=*src;
- US.l=1;
- } else if (! isspace(*src)) {
- US.state = STATE_NORMAL;
- efree(US.tag);
- US.tag=NULL;
- }
- break;
-
- case STATE_TAG_ATTR:
- if(isalnum(*src)) {
- *US.p++=*src;
- ++US.l;
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.attr=erealloc(US.attr,US.ml);
- US.p = US.attr+US.l;
- }
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.attr=erealloc(US.attr,US.ml);
- US.p = US.attr+US.l;
- }
- } else if(isspace(*src)||(*src=='=')){
- US.state=STATE_TAG_IS;
- *US.p=0;
- US.attr=erealloc(US.attr,US.l);
- } else if(*src=='>') {
- US.state=STATE_NORMAL;
- } else {
- efree(US.attr);
- US.attr=NULL;
- US.state=STATE_IN_TAG;
- }
- break;
-
- case STATE_TAG_IS:
- case STATE_TAG_IS2:
- if(*src=='>'){
- US.state=STATE_NORMAL;
- if(! (US.attr_done)) {
- char *p;
- p=url_attr_addon(US.tag,US.attr,"",data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- } else if(*src=='#') {
- if(! (US.attr_done)) {
- char *p;
- US.attr_done=1;
- p=url_attr_addon(US.tag,US.attr,"#",data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- } else if(!isspace(*src)&&(*src!='=')) {
- US.ml=BUFSIZE;
- US.p=US.val=erealloc(US.val,US.ml);
- US.l=0;
- US.attr_done=0;
- if((*src=='"')||(*src=='\'')) {
- US.state=STATE_TAG_QVAL2;
- US.delim=*src;
- } else {
- US.state=STATE_TAG_VAL;
- *US.p++=*src;
- US.l++;
- }
- }
- break;
-
-
- case STATE_TAG_QVAL2:
- if(*src=='#') {
- if(! (US.attr_done)) {
- char *p;
- US.attr_done=1;
- *US.p='\0';
- p=url_attr_addon(US.tag,US.attr,US.val,data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- } else if(*src==US.delim) {
- US.state=STATE_IN_TAG;
- *US.p='\0';
- if(! (US.attr_done)) {
- char *p;
- p=url_attr_addon(US.tag,US.attr,US.val,data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- break;
- } else if(*src=='\\') {
- US.state=STATE_TAG_QVAL2b;
- } else if (*src=='>') {
- US.state=STATE_NORMAL;
- }
-
- *US.p++=*src;
- ++US.l;
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.val=erealloc(US.val,US.ml);
- US.p = US.val+US.l;
- }
-
- break;
-
- case STATE_TAG_QVAL2b:
- US.state=STATE_TAG_QVAL2;
- *US.p++=*src;
- ++US.l;
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.val=erealloc(US.val,US.ml);
- US.p = US.val+US.l;
- }
- break;
-
- case STATE_TAG_VAL:
- case STATE_TAG_VAL2:
- if(*src=='#') {
- if(! (US.attr_done)) {
- char *p;
- US.attr_done=1;
- *US.p='\0';
- p=url_attr_addon(US.tag,US.attr,US.val,data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- } else if(isspace(*src)||(*src=='>')) {
- US.state=(*src=='>')?STATE_NORMAL:STATE_IN_TAG;
- *US.p='\0';
- if(! (US.attr_done)) {
- char *p;
- p=url_attr_addon(US.tag,US.attr,US.val,data);
- if(p) {
- int l= strlen(p);
- maxl+=l;
- out=realloc(out,maxl);
- outp=out+*newlen;
- strcpy(outp,p);
- outp+=l;
- *newlen+=l;
- efree(p);
- }
- }
- } else {
- *US.p++=*src;
- US.l++;
- if(US.l==US.ml) {
- US.ml+=BUFSIZE;
- US.val=erealloc(US.val,US.ml);
- US.p = US.val+US.l;
- }
- }
- break;
- }
-
- *outp++=*src++;
- *newlen+=1;
- }
- *outp='\0';
- return out;
-}
-/* }}} */
-#endif
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */
diff --git a/ext/standard/url_scanner.h b/ext/standard/url_scanner.h
deleted file mode 100644
index ec615fdcef..0000000000
--- a/ext/standard/url_scanner.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Author: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
- */
-/* $Id$ */
-
-#ifndef URI_SCANNER_H
-#define URI_SCANNER_H
-
-PHP_RINIT_FUNCTION(url_scanner);
-PHP_RSHUTDOWN_FUNCTION(url_scanner);
-
-char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen);
-
-enum url_state {
- STATE_NORMAL,
- STATE_TAG_START,
- STATE_TAG,
- STATE_IN_TAG,
- STATE_TAG_ATTR,
- STATE_TAG_IS,
- STATE_TAG_IS2,
- STATE_TAG_VAL,
- STATE_TAG_VAL2,
- STATE_TAG_QVAL1,
- STATE_TAG_QVAL2,
- STATE_TAG_QVAL2b
-};
-
-typedef struct url_adapt_struct {
- enum url_state state;
- char *tag;
- char *attr;
- char *val;
- char delim;
- char *p;
- int l, ml;
- int attr_done;
-} url_adapt_state_t;
-
-#endif
diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c
deleted file mode 100644
index 35dff9f381..0000000000
--- a/ext/standard/url_scanner_ex.c
+++ /dev/null
@@ -1,903 +0,0 @@
-/* Generated by re2c 0.5 on Sun Aug 5 18:41:23 2001 */
-#line 1 "url_scanner_ex.re"
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-
-#ifdef TRANS_SID
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "php_ini.h"
-#include "php_globals.h"
-#define STATE_TAG SOME_OTHER_STATE_TAG
-#include "basic_functions.h"
-#undef STATE_TAG
-
-#define url_adapt_ext url_adapt_ext_ex
-#define url_scanner url_scanner_ex
-
-#include "php_smart_str.h"
-
-static PHP_INI_MH(OnUpdateTags)
-{
- url_adapt_state_ex_t *ctx;
- char *key;
- char *lasts;
- char *tmp;
-
- ctx = &BG(url_adapt_state_ex);
-
- tmp = estrndup(new_value, new_value_length);
-
- if (ctx->tags)
- zend_hash_destroy(ctx->tags);
- else
- ctx->tags = malloc(sizeof(HashTable));
-
- zend_hash_init(ctx->tags, 0, NULL, NULL, 1);
-
- for (key = php_strtok_r(tmp, ",", &lasts);
- key;
- key = php_strtok_r(NULL, ",", &lasts)) {
- char *val;
-
- val = strchr(key, '=');
- if (val) {
- char *q;
- int keylen;
-
- *val++ = '\0';
- for (q = key; *q; q++)
- *q = tolower(*q);
- keylen = q - key;
- /* key is stored withOUT NUL
- val is stored WITH NUL */
- zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL);
- }
- }
-
- efree(tmp);
-
- return SUCCESS;
-}
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=fakeentry", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
-PHP_INI_END()
-
-#line 93
-
-
-#define YYFILL(n) goto done
-#define YYCTYPE unsigned char
-#define YYCURSOR p
-#define YYLIMIT q
-#define YYMARKER r
-
-static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
-{
- register const char *p, *q, *r;
- const char *bash = NULL;
- const char *sep = "?";
-
- q = (p = url->c) + url->len;
-
-scan:
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 0, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 0, 128, 128, 128, 128, 0,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- };
- goto yy0;
-yy1: ++YYCURSOR;
-yy0:
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
- if(yybm[0+yych] & 128) goto yy8;
- if(yych <= '9') goto yy6;
- if(yych >= ';') goto yy4;
-yy2: yych = *++YYCURSOR;
-yy3:
-#line 111
- { smart_str_append(dest, url); return; }
-yy4: yych = *++YYCURSOR;
-yy5:
-#line 112
- { sep = separator; goto done; }
-yy6: yych = *++YYCURSOR;
-yy7:
-#line 113
- { bash = p; goto done; }
-yy8: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy9: if(yybm[0+yych] & 128) goto yy8;
-yy10:
-#line 114
- { goto scan; }
-}
-#line 115
-
-done:
-
- /* Don't modify URLs of the format "#mark" */
- if (bash && bash - url->c == 0) {
- smart_str_append(dest, url);
- return;
- }
-
- if (bash)
- smart_str_appendl(dest, url->c, bash - url->c);
- else
- smart_str_append(dest, url);
-
- smart_str_appends(dest, sep);
- smart_str_append(dest, name);
- smart_str_appendc(dest, '=');
- smart_str_append(dest, val);
-
- if (bash)
- smart_str_appendl(dest, bash, q - bash);
-}
-
-#undef YYFILL
-#undef YYCTYPE
-#undef YYCURSOR
-#undef YYLIMIT
-#undef YYMARKER
-
-static inline void tag_arg(url_adapt_state_ex_t *ctx, char quote TSRMLS_DC)
-{
- char f = 0;
-
- if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
- f = 1;
-
- smart_str_appendc(&ctx->result, quote);
- if (f) {
- append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator).output);
- } else {
- smart_str_append(&ctx->result, &ctx->val);
- }
- smart_str_appendc(&ctx->result, quote);
-}
-
-enum {
- STATE_PLAIN = 0,
- STATE_TAG,
- STATE_NEXT_ARG,
- STATE_ARG,
- STATE_BEFORE_VAL,
- STATE_VAL
-};
-
-#define YYFILL(n) goto stop
-#define YYCTYPE unsigned char
-#define YYCURSOR xp
-#define YYLIMIT end
-#define YYMARKER q
-#define STATE ctx->state
-
-#define STD_PARA url_adapt_state_ex_t *ctx, char *start, char *YYCURSOR TSRMLS_DC
-#define STD_ARGS ctx, start, xp TSRMLS_CC
-
-static inline void passthru(STD_PARA)
-{
- smart_str_appendl(&ctx->result, start, YYCURSOR - start);
-}
-
-static inline void handle_form(STD_PARA)
-{
- if (ctx->tag.len == 4 && strncasecmp(ctx->tag.c, "form", 4) == 0) {
- smart_str_appends(&ctx->result, "<input type=\"hidden\" name=\"");
- smart_str_append(&ctx->result, &ctx->q_name);
- smart_str_appends(&ctx->result, "\" value=\"");
- smart_str_append(&ctx->result, &ctx->q_value);
- smart_str_appends(&ctx->result, "\" />");
- }
-}
-
-/*
- * HANDLE_TAG copies the HTML Tag and checks whether we
- * have that tag in our table. If we might modify it,
- * we continue to scan the tag, otherwise we simply copy the complete
- * HTML stuff to the result buffer.
- */
-
-static inline void handle_tag(STD_PARA)
-{
- int ok = 0;
- int i;
-
- ctx->tag.len = 0;
- smart_str_appendl(&ctx->tag, start, YYCURSOR - start);
- for (i = 0; i < ctx->tag.len; i++)
- ctx->tag.c[i] = tolower(ctx->tag.c[i]);
- if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS)
- ok = 1;
- STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN;
-}
-
-static inline void handle_arg(STD_PARA)
-{
- ctx->arg.len = 0;
- smart_str_appendl(&ctx->arg, start, YYCURSOR - start);
-}
-
-static inline void handle_val(STD_PARA, char quotes, char type)
-{
- smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2);
- tag_arg(ctx, type TSRMLS_CC);
-}
-
-#ifdef SCANNER_DEBUG
-#define scdebug(x) printf x
-#else
-#define scdebug(x)
-#endif
-
-static inline void mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size_t newlen TSRMLS_DC)
-{
- char *end, *q;
- char *xp;
- char *start;
- int rest;
-
- smart_str_appendl(&ctx->buf, newdata, newlen);
-
- YYCURSOR = ctx->buf.c;
- YYLIMIT = ctx->buf.c + ctx->buf.len;
-
- switch (STATE) {
- case STATE_PLAIN: goto state_plain;
- case STATE_TAG: goto state_tag;
- case STATE_NEXT_ARG: goto state_next_arg;
- case STATE_ARG: goto state_arg;
- case STATE_BEFORE_VAL: goto state_before_val;
- case STATE_VAL: goto state_val;
- }
-
-
-state_plain_begin:
- STATE = STATE_PLAIN;
-
-state_plain:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 0, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- };
- goto yy11;
-yy12: ++YYCURSOR;
-yy11:
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
- if(yybm[0+yych] & 128) goto yy15;
-yy13: yych = *++YYCURSOR;
-yy14:
-#line 262
- { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; }
-yy15: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy16: if(yybm[0+yych] & 128) goto yy15;
-yy17:
-#line 263
- { passthru(STD_ARGS); goto state_plain; }
-}
-#line 264
-
-
-state_tag:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 0, 0, 0, 0, 0,
- 0, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- };
- goto yy18;
-yy19: ++YYCURSOR;
-yy18:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yych <= '@') goto yy22;
- if(yych <= 'Z') goto yy20;
- if(yych <= '`') goto yy22;
- if(yych >= '{') goto yy22;
-yy20: yych = *++YYCURSOR;
- goto yy25;
-yy21:
-#line 269
- { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; }
-yy22: yych = *++YYCURSOR;
-yy23:
-#line 270
- { passthru(STD_ARGS); goto state_plain_begin; }
-yy24: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy25: if(yybm[0+yych] & 128) goto yy24;
- goto yy21;
-}
-#line 271
-
-
-state_next_arg_begin:
- STATE = STATE_NEXT_ARG;
-
-state_next_arg:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 128, 128, 128, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 128, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- };
- goto yy26;
-yy27: ++YYCURSOR;
-yy26:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yych <= '='){
- if(yych <= '\v'){
- if(yych <= '\b') goto yy34;
- goto yy30;
- } else {
- if(yych == ' ') goto yy30;
- goto yy34;
- }
- } else {
- if(yych <= 'Z'){
- if(yych <= '>') goto yy28;
- if(yych <= '@') goto yy34;
- goto yy32;
- } else {
- if(yych <= '`') goto yy34;
- if(yych <= 'z') goto yy32;
- goto yy34;
- }
- }
-yy28: yych = *++YYCURSOR;
-yy29:
-#line 279
- { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }
-yy30: yych = *++YYCURSOR;
- goto yy37;
-yy31:
-#line 280
- { passthru(STD_ARGS); goto state_next_arg; }
-yy32: yych = *++YYCURSOR;
-yy33:
-#line 281
- { --YYCURSOR; STATE = STATE_ARG; goto state_arg; }
-yy34: yych = *++YYCURSOR;
-yy35:
-#line 282
- { passthru(STD_ARGS); goto state_plain_begin; }
-yy36: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy37: if(yybm[0+yych] & 128) goto yy36;
- goto yy31;
-}
-#line 283
-
-
-state_arg:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 0, 0, 0, 0, 0,
- 0, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 128, 128, 128, 128, 128,
- 128, 128, 128, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- };
- goto yy38;
-yy39: ++YYCURSOR;
-yy38:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yych <= '@') goto yy42;
- if(yych <= 'Z') goto yy40;
- if(yych <= '`') goto yy42;
- if(yych >= '{') goto yy42;
-yy40: yych = *++YYCURSOR;
- goto yy45;
-yy41:
-#line 288
- { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }
-yy42: yych = *++YYCURSOR;
-yy43:
-#line 289
- { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }
-yy44: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy45: if(yybm[0+yych] & 128) goto yy44;
- goto yy41;
-}
-#line 290
-
-
-state_before_val:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 128, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0,
- };
- goto yy46;
-yy47: ++YYCURSOR;
-yy46:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yych == ' ') goto yy48;
- if(yych == '=') goto yy50;
- goto yy52;
-yy48: yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if(yych == ' ') goto yy55;
- if(yych == '=') goto yy53;
-yy49:
-#line 296
- { --YYCURSOR; goto state_next_arg_begin; }
-yy50: yych = *++YYCURSOR;
- goto yy54;
-yy51:
-#line 295
- { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }
-yy52: yych = *++YYCURSOR;
- goto yy49;
-yy53: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy54: if(yybm[0+yych] & 128) goto yy53;
- goto yy51;
-yy55: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy56: if(yych == ' ') goto yy55;
- if(yych == '=') goto yy53;
-yy57: YYCURSOR = YYMARKER;
- switch(yyaccept){
- case 0: goto yy49;
- }
-}
-#line 297
-
-
-
-state_val:
- start = YYCURSOR;
-{
- YYCTYPE yych;
- unsigned int yyaccept;
- static unsigned char yybm[] = {
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 192, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 192, 224, 64, 224, 224, 224, 224, 128,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 0, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- 224, 224, 224, 224, 224, 224, 224, 224,
- };
- goto yy58;
-yy59: ++YYCURSOR;
-yy58:
- if((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
- yych = *YYCURSOR;
- if(yych <= '!'){
- if(yych <= '\n'){
- if(yych <= '\t') goto yy63;
- goto yy65;
- } else {
- if(yych == ' ') goto yy65;
- goto yy63;
- }
- } else {
- if(yych <= '\''){
- if(yych <= '"') goto yy60;
- if(yych <= '&') goto yy63;
- goto yy62;
- } else {
- if(yych == '>') goto yy65;
- goto yy63;
- }
- }
-yy60: yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if(yych != '>') goto yy74;
-yy61:
-#line 306
- { passthru(STD_ARGS); goto state_next_arg_begin; }
-yy62: yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if(yych == '>') goto yy61;
- goto yy69;
-yy63: yych = *++YYCURSOR;
- goto yy67;
-yy64:
-#line 305
- { handle_val(STD_ARGS, 0, '"'); goto state_next_arg_begin; }
-yy65: yych = *++YYCURSOR;
- goto yy61;
-yy66: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy67: if(yybm[0+yych] & 32) goto yy66;
- goto yy64;
-yy68: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy69: if(yybm[0+yych] & 64) goto yy68;
- if(yych <= '=') goto yy71;
-yy70: YYCURSOR = YYMARKER;
- switch(yyaccept){
- case 0: goto yy61;
- }
-yy71: yych = *++YYCURSOR;
-yy72:
-#line 304
- { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }
-yy73: ++YYCURSOR;
- if(YYLIMIT == YYCURSOR) YYFILL(1);
- yych = *YYCURSOR;
-yy74: if(yybm[0+yych] & 128) goto yy73;
- if(yych >= '>') goto yy70;
-yy75: yych = *++YYCURSOR;
-yy76:
-#line 303
- { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }
-}
-#line 307
-
-
-stop:
- rest = YYLIMIT - start;
- scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
- /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
- if (rest < 0) rest = 0;
-
- if (rest) memmove(ctx->buf.c, start, rest);
- ctx->buf.len = rest;
-}
-
-char *url_adapt_flush(size_t *newlen TSRMLS_DC)
-{
- char *ret = NULL;
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- if (ctx->buf.len) {
- ret = ctx->buf.c;
- *newlen = ctx->buf.len;
- ctx->buf.c = 0;
- ctx->buf.len = 0;
- }
-
- return ret;
-}
-
-char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
-{
- smart_str surl = {0};
- smart_str buf = {0};
- smart_str sname = {0};
- smart_str sval = {0};
-
- smart_str_setl(&surl, url, urllen);
- smart_str_sets(&sname, name);
- smart_str_sets(&sval, value);
-
- append_modified_url(&surl, &buf, &sname, &sval, PG(arg_separator).output);
-
- smart_str_0(&buf);
- if (newlen) *newlen = buf.len;
-
- return buf.c;
-}
-
-char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
-{
- char *ret;
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- smart_str_sets(&ctx->q_name, name);
- smart_str_sets(&ctx->q_value, value);
- mainloop(ctx, src, srclen TSRMLS_CC);
-
- *newlen = ctx->result.len;
- if (!ctx->result.c)
- smart_str_appendl(&ctx->result, "", 0);
- smart_str_0(&ctx->result);
- ctx->result.len = 0;
- return ctx->result.c;
-}
-
-PHP_RINIT_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags));
-
- return SUCCESS;
-}
-
-PHP_RSHUTDOWN_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- smart_str_free(&ctx->result);
- smart_str_free(&ctx->buf);
- smart_str_free(&ctx->tag);
- smart_str_free(&ctx->arg);
-
- return SUCCESS;
-}
-
-PHP_MINIT_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- ctx->tags = NULL;
-
- REGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(url_scanner)
-{
- UNREGISTER_INI_ENTRIES();
- zend_hash_destroy(BG(url_adapt_state_ex).tags);
- free(BG(url_adapt_state_ex).tags);
- return SUCCESS;
-}
-
-#endif
diff --git a/ext/standard/url_scanner_ex.h b/ext/standard/url_scanner_ex.h
deleted file mode 100644
index d5595570ae..0000000000
--- a/ext/standard/url_scanner_ex.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef URL_SCANNER_EX_H
-#define URL_SCANNER_EX_H
-
-PHP_MINIT_FUNCTION(url_scanner_ex);
-PHP_MSHUTDOWN_FUNCTION(url_scanner_ex);
-PHP_RSHUTDOWN_FUNCTION(url_scanner_ex);
-PHP_RINIT_FUNCTION(url_scanner_ex);
-
-char *url_adapt_ext_ex(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen TSRMLS_DC);
-
-char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC);
-
-char *url_adapt_flush(size_t * TSRMLS_DC);
-
-#include "php_smart_str_public.h"
-
-typedef struct {
- /* Used by the mainloop of the scanner */
- smart_str tag; /* read only */
- smart_str arg; /* read only */
- smart_str val; /* read only */
- smart_str buf;
-
- /* The result buffer */
- smart_str result;
-
- /* The data which is appended to each relative URL */
- smart_str q_name;
- smart_str q_value;
-
- char *lookup_data;
- int state;
-
- /* Everything above is zeroed in RINIT */
- HashTable *tags;
-} url_adapt_state_ex_t;
-
-#endif
diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re
deleted file mode 100644
index 2bcc2a286b..0000000000
--- a/ext/standard/url_scanner_ex.re
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-#include "php.h"
-
-#ifdef TRANS_SID
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "php_ini.h"
-#include "php_globals.h"
-#define STATE_TAG SOME_OTHER_STATE_TAG
-#include "basic_functions.h"
-#undef STATE_TAG
-
-#define url_adapt_ext url_adapt_ext_ex
-#define url_scanner url_scanner_ex
-
-#include "php_smart_str.h"
-
-static PHP_INI_MH(OnUpdateTags)
-{
- url_adapt_state_ex_t *ctx;
- char *key;
- char *lasts;
- char *tmp;
-
- ctx = &BG(url_adapt_state_ex);
-
- tmp = estrndup(new_value, new_value_length);
-
- if (ctx->tags)
- zend_hash_destroy(ctx->tags);
- else
- ctx->tags = malloc(sizeof(HashTable));
-
- zend_hash_init(ctx->tags, 0, NULL, NULL, 1);
-
- for (key = php_strtok_r(tmp, ",", &lasts);
- key;
- key = php_strtok_r(NULL, ",", &lasts)) {
- char *val;
-
- val = strchr(key, '=');
- if (val) {
- char *q;
- int keylen;
-
- *val++ = '\0';
- for (q = key; *q; q++)
- *q = tolower(*q);
- keylen = q - key;
- /* key is stored withOUT NUL
- val is stored WITH NUL */
- zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL);
- }
- }
-
- efree(tmp);
-
- return SUCCESS;
-}
-
-PHP_INI_BEGIN()
- STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=fakeentry", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
-PHP_INI_END()
-
-/*!re2c
-any = [\000-\377];
-N = (any\[<]);
-alpha = [a-zA-Z];
-*/
-
-#define YYFILL(n) goto done
-#define YYCTYPE unsigned char
-#define YYCURSOR p
-#define YYLIMIT q
-#define YYMARKER r
-
-static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
-{
- register const char *p, *q, *r;
- const char *bash = NULL;
- const char *sep = "?";
-
- q = (p = url->c) + url->len;
-
-scan:
-/*!re2c
- ":" { smart_str_append(dest, url); return; }
- "?" { sep = separator; goto done; }
- "#" { bash = p; goto done; }
- (any\[:?#])+ { goto scan; }
-*/
-done:
-
- /* Don't modify URLs of the format "#mark" */
- if (bash && bash - url->c == 0) {
- smart_str_append(dest, url);
- return;
- }
-
- if (bash)
- smart_str_appendl(dest, url->c, bash - url->c);
- else
- smart_str_append(dest, url);
-
- smart_str_appends(dest, sep);
- smart_str_append(dest, name);
- smart_str_appendc(dest, '=');
- smart_str_append(dest, val);
-
- if (bash)
- smart_str_appendl(dest, bash, q - bash);
-}
-
-#undef YYFILL
-#undef YYCTYPE
-#undef YYCURSOR
-#undef YYLIMIT
-#undef YYMARKER
-
-static inline void tag_arg(url_adapt_state_ex_t *ctx, char quote TSRMLS_DC)
-{
- char f = 0;
-
- if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
- f = 1;
-
- smart_str_appendc(&ctx->result, quote);
- if (f) {
- append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator).output);
- } else {
- smart_str_append(&ctx->result, &ctx->val);
- }
- smart_str_appendc(&ctx->result, quote);
-}
-
-enum {
- STATE_PLAIN = 0,
- STATE_TAG,
- STATE_NEXT_ARG,
- STATE_ARG,
- STATE_BEFORE_VAL,
- STATE_VAL
-};
-
-#define YYFILL(n) goto stop
-#define YYCTYPE unsigned char
-#define YYCURSOR xp
-#define YYLIMIT end
-#define YYMARKER q
-#define STATE ctx->state
-
-#define STD_PARA url_adapt_state_ex_t *ctx, char *start, char *YYCURSOR TSRMLS_DC
-#define STD_ARGS ctx, start, xp TSRMLS_CC
-
-static inline void passthru(STD_PARA)
-{
- smart_str_appendl(&ctx->result, start, YYCURSOR - start);
-}
-
-static inline void handle_form(STD_PARA)
-{
- if (ctx->tag.len == 4 && strncasecmp(ctx->tag.c, "form", 4) == 0) {
- smart_str_appends(&ctx->result, "<input type=\"hidden\" name=\"");
- smart_str_append(&ctx->result, &ctx->q_name);
- smart_str_appends(&ctx->result, "\" value=\"");
- smart_str_append(&ctx->result, &ctx->q_value);
- smart_str_appends(&ctx->result, "\" />");
- }
-}
-
-/*
- * HANDLE_TAG copies the HTML Tag and checks whether we
- * have that tag in our table. If we might modify it,
- * we continue to scan the tag, otherwise we simply copy the complete
- * HTML stuff to the result buffer.
- */
-
-static inline void handle_tag(STD_PARA)
-{
- int ok = 0;
- int i;
-
- ctx->tag.len = 0;
- smart_str_appendl(&ctx->tag, start, YYCURSOR - start);
- for (i = 0; i < ctx->tag.len; i++)
- ctx->tag.c[i] = tolower(ctx->tag.c[i]);
- if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS)
- ok = 1;
- STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN;
-}
-
-static inline void handle_arg(STD_PARA)
-{
- ctx->arg.len = 0;
- smart_str_appendl(&ctx->arg, start, YYCURSOR - start);
-}
-
-static inline void handle_val(STD_PARA, char quotes, char type)
-{
- smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2);
- tag_arg(ctx, type TSRMLS_CC);
-}
-
-#ifdef SCANNER_DEBUG
-#define scdebug(x) printf x
-#else
-#define scdebug(x)
-#endif
-
-static inline void mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size_t newlen TSRMLS_DC)
-{
- char *end, *q;
- char *xp;
- char *start;
- int rest;
-
- smart_str_appendl(&ctx->buf, newdata, newlen);
-
- YYCURSOR = ctx->buf.c;
- YYLIMIT = ctx->buf.c + ctx->buf.len;
-
- switch (STATE) {
- case STATE_PLAIN: goto state_plain;
- case STATE_TAG: goto state_tag;
- case STATE_NEXT_ARG: goto state_next_arg;
- case STATE_ARG: goto state_arg;
- case STATE_BEFORE_VAL: goto state_before_val;
- case STATE_VAL: goto state_val;
- }
-
-
-state_plain_begin:
- STATE = STATE_PLAIN;
-
-state_plain:
- start = YYCURSOR;
-/*!re2c
- "<" { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; }
- N+ { passthru(STD_ARGS); goto state_plain; }
-*/
-
-state_tag:
- start = YYCURSOR;
-/*!re2c
- alpha+ { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; }
- any { passthru(STD_ARGS); goto state_plain_begin; }
-*/
-
-state_next_arg_begin:
- STATE = STATE_NEXT_ARG;
-
-state_next_arg:
- start = YYCURSOR;
-/*!re2c
- ">" { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }
- [ \v\t\n]+ { passthru(STD_ARGS); goto state_next_arg; }
- alpha { --YYCURSOR; STATE = STATE_ARG; goto state_arg; }
- any { passthru(STD_ARGS); goto state_plain_begin; }
-*/
-
-state_arg:
- start = YYCURSOR;
-/*!re2c
- alpha+ { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }
- any { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }
-*/
-
-state_before_val:
- start = YYCURSOR;
-/*!re2c
- [ ]* "=" [ ]* { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }
- any { --YYCURSOR; goto state_next_arg_begin; }
-*/
-
-
-state_val:
- start = YYCURSOR;
-/*!re2c
- ["] (any\[">])* ["] { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }
- ['] (any\['>])* ['] { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }
- (any\[ \n>"'])+ { handle_val(STD_ARGS, 0, '"'); goto state_next_arg_begin; }
- any { passthru(STD_ARGS); goto state_next_arg_begin; }
-*/
-
-stop:
- rest = YYLIMIT - start;
- scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
- /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */
- if (rest < 0) rest = 0;
-
- if (rest) memmove(ctx->buf.c, start, rest);
- ctx->buf.len = rest;
-}
-
-char *url_adapt_flush(size_t *newlen TSRMLS_DC)
-{
- char *ret = NULL;
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- if (ctx->buf.len) {
- ret = ctx->buf.c;
- *newlen = ctx->buf.len;
- ctx->buf.c = 0;
- ctx->buf.len = 0;
- }
-
- return ret;
-}
-
-char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
-{
- smart_str surl = {0};
- smart_str buf = {0};
- smart_str sname = {0};
- smart_str sval = {0};
-
- smart_str_setl(&surl, url, urllen);
- smart_str_sets(&sname, name);
- smart_str_sets(&sval, value);
-
- append_modified_url(&surl, &buf, &sname, &sval, PG(arg_separator).output);
-
- smart_str_0(&buf);
- if (newlen) *newlen = buf.len;
-
- return buf.c;
-}
-
-char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
-{
- char *ret;
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- smart_str_sets(&ctx->q_name, name);
- smart_str_sets(&ctx->q_value, value);
- mainloop(ctx, src, srclen TSRMLS_CC);
-
- *newlen = ctx->result.len;
- if (!ctx->result.c)
- smart_str_appendl(&ctx->result, "", 0);
- smart_str_0(&ctx->result);
- ctx->result.len = 0;
- return ctx->result.c;
-}
-
-PHP_RINIT_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags));
-
- return SUCCESS;
-}
-
-PHP_RSHUTDOWN_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- smart_str_free(&ctx->result);
- smart_str_free(&ctx->buf);
- smart_str_free(&ctx->tag);
- smart_str_free(&ctx->arg);
-
- return SUCCESS;
-}
-
-PHP_MINIT_FUNCTION(url_scanner)
-{
- url_adapt_state_ex_t *ctx;
-
- ctx = &BG(url_adapt_state_ex);
-
- ctx->tags = NULL;
-
- REGISTER_INI_ENTRIES();
- return SUCCESS;
-}
-
-PHP_MSHUTDOWN_FUNCTION(url_scanner)
-{
- UNREGISTER_INI_ENTRIES();
- zend_hash_destroy(BG(url_adapt_state_ex).tags);
- free(BG(url_adapt_state_ex).tags);
- return SUCCESS;
-}
-
-#endif
diff --git a/ext/standard/var.c b/ext/standard/var.c
deleted file mode 100644
index e384eb2461..0000000000
--- a/ext/standard/var.c
+++ /dev/null
@@ -1,677 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Jani Lehtimäki <jkl@njet.net> |
- | Thies C. Arntzen <thies@thieso.net> |
- | Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id: var.c
- 1.111 2001/08/06 13:36:08 thies Exp $ */
-
-
-/* {{{ includes
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "php.h"
-#include "php_string.h"
-#include "php_var.h"
-#include "php_smart_str.h"
-#include "basic_functions.h"
-#include "php_incomplete_class.h"
-
-#define COMMON ((*struc)->is_ref?"&":"")
-
-/* }}} */
-/* {{{ php_var_dump */
-
-static int php_array_element_dump(zval **zv, int num_args, va_list args, zend_hash_key *hash_key)
-{
- int level;
- TSRMLS_FETCH();
-
- level = va_arg(args, int);
-
- if (hash_key->nKeyLength==0) { /* numeric key */
- php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
- } else { /* string key */
- php_printf("%*c[\"%s\"]=>\n", level + 1, ' ', hash_key->arKey);
- }
- php_var_dump(zv, level + 2 TSRMLS_CC);
- return 0;
-}
-
-void php_var_dump(zval **struc, int level TSRMLS_DC)
-{
- HashTable *myht;
-
- if (level>1) {
- php_printf("%*c", level-1, ' ');
- }
-
- switch ((*struc)->type) {
- case IS_BOOL:
- php_printf("%sbool(%s)\n", COMMON, Z_LVAL_PP(struc)?"true":"false");
- break;
- case IS_NULL:
- php_printf("%sNULL\n", COMMON);
- break;
- case IS_LONG:
- php_printf("%sint(%ld)\n", COMMON, Z_LVAL_PP(struc));
- break;
- case IS_DOUBLE: {
-
- php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc));
- }
- break;
- case IS_STRING:
- php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
- PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
- PUTS("\"\n");
- break;
- case IS_ARRAY:
- myht = HASH_OF(*struc);
- php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht));
- goto head_done;
- case IS_OBJECT:
- myht = Z_OBJPROP_PP(struc);
- php_printf("%sobject(%s)(%d) {\n", COMMON, Z_OBJCE_PP(struc)->name, zend_hash_num_elements(myht));
-head_done:
- zend_hash_apply_with_arguments(myht, (apply_func_args_t) php_array_element_dump, 1, level);
- if (level>1) {
- php_printf("%*c", level-1, ' ');
- }
- PUTS("}\n");
- break;
- case IS_RESOURCE: {
- char *type_name;
-
- type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
- php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown");
- break;
- }
- default:
- php_printf("%sUNKNOWN:0\n", COMMON);
- break;
- }
-}
-
-/* }}} */
-
-
-/* {{{ proto void var_dump(mixed var)
- Dumps a string representation of variable to output */
-PHP_FUNCTION(var_dump)
-{
- zval ***args;
- int argc;
- int i;
-
- argc = ZEND_NUM_ARGS();
-
- args = (zval ***)emalloc(argc * sizeof(zval **));
- if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) {
- efree(args);
- WRONG_PARAM_COUNT;
- }
-
- for (i=0; i<argc; i++)
- php_var_dump(args[i], 1 TSRMLS_CC);
-
- efree(args);
-}
-/* }}} */
-
-
-/* {{{ php_var_serialize */
-
-static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC);
-
-static inline int php_add_var_hash(HashTable *var_hash, zval *var, void *var_old)
-{
- ulong var_no;
- char id[32], *p;
-
- p = smart_str_print_long(id, (long) var);
- *p = '\0';
-
- if (var_old && zend_hash_find(var_hash, id, p - id, var_old) == SUCCESS) {
- if (!var->is_ref) {
- /* we still need to bump up the counter, since non-refs will
- be counted separately by unserializer */
- var_no = -1;
- zend_hash_next_index_insert(var_hash, &var_no, sizeof(var_no), NULL);
- }
- return FAILURE;
- }
-
- /* +1 because otherwise hash will think we are trying to store NULL pointer */
- var_no = zend_hash_num_elements(var_hash) + 1;
- zend_hash_add(var_hash, id, p - id, &var_no, sizeof(var_no), NULL);
- return SUCCESS;
-}
-
-static inline void php_var_serialize_long(smart_str *buf, long val)
-{
- smart_str_appendl(buf, "i:", 2);
- smart_str_append_long(buf, val);
- smart_str_appendc(buf, ';');
-}
-
-static inline void php_var_serialize_string(smart_str *buf, char *str, int len)
-{
- smart_str_appendl(buf, "s:", 2);
- smart_str_append_long(buf, len);
- smart_str_appendl(buf, ":\"", 2);
- smart_str_appendl(buf, str, len);
- smart_str_appendl(buf, "\";", 2);
-}
-
-static inline void php_var_serialize_class_name(smart_str *buf, zval **struc TSRMLS_DC)
-{
- PHP_CLASS_ATTRIBUTES;
-
- PHP_SET_CLASS_ATTRIBUTES(*struc);
- smart_str_appendl(buf, "O:", 2);
- smart_str_append_long(buf, name_len);
- smart_str_appendl(buf, ":\"", 2);
- smart_str_appendl(buf, class_name, name_len);
- smart_str_appendl(buf, "\":", 2);
- PHP_CLEANUP_CLASS_ATTRIBUTES();
-}
-
-static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_ptr, HashTable *var_hash TSRMLS_DC)
-{
- int count = zend_hash_num_elements(HASH_OF(retval_ptr));
-
- php_var_serialize_class_name(buf, struc TSRMLS_CC);
-
- smart_str_append_long(buf, count);
- smart_str_appendl(buf, ":{", 2);
-
- if (count > 0) {
- char *key;
- zval **d, **name;
- ulong index;
- HashPosition pos;
- int i;
-
- zend_hash_internal_pointer_reset_ex(HASH_OF(retval_ptr), &pos);
-
- for (;; zend_hash_move_forward_ex(HASH_OF(retval_ptr), &pos)) {
- i = zend_hash_get_current_key_ex(HASH_OF(retval_ptr), &key, NULL,
- &index, 0, &pos);
-
- if (i == HASH_KEY_NON_EXISTANT)
- break;
-
- zend_hash_get_current_data_ex(HASH_OF(retval_ptr),
- (void **) &name, &pos);
-
- if (Z_TYPE_PP(name) != IS_STRING) {
- php_error(E_NOTICE, "__sleep should return an array only "
- "containing the names of instance-variables to "
- "serialize.");
- continue;
- }
-
- if (zend_hash_find(Z_OBJPROP_PP(struc), Z_STRVAL_PP(name),
- Z_STRLEN_PP(name) + 1, (void *) &d) == SUCCESS) {
- php_var_serialize_string(buf, Z_STRVAL_PP(name),
- Z_STRLEN_PP(name));
- php_var_serialize_intern(buf, d, var_hash TSRMLS_CC);
- }
- }
- }
- smart_str_appendc(buf, '}');
-}
-
-
-static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC)
-{
- int i;
- ulong *var_already;
- HashTable *myht;
-
- if(var_hash
- && php_add_var_hash(var_hash, *struc, (void *) &var_already) == FAILURE
- && (*struc)->is_ref) {
- smart_str_appendl(buf, "R:", 2);
- smart_str_append_long(buf, *var_already);
- smart_str_appendc(buf, ';');
- return;
- }
-
- switch (Z_TYPE_PP(struc)) {
- case IS_BOOL:
- smart_str_appendl(buf, "b:", 2);
- smart_str_append_long(buf, Z_LVAL_PP(struc));
- smart_str_appendc(buf, ';');
- return;
-
- case IS_NULL:
- smart_str_appendl(buf, "N;", 2);
- return;
-
- case IS_LONG:
- php_var_serialize_long(buf, Z_LVAL_PP(struc));
- return;
-
- case IS_DOUBLE: {
- char s[256];
- ulong slen;
-
- slen = sprintf(s, "d:%.*G;", (int) EG(precision), Z_DVAL_PP(struc));
- smart_str_appendl(buf, s, slen);
- return;
- }
-
- case IS_STRING:
- php_var_serialize_string(buf, Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
- return;
-
- case IS_OBJECT: {
- zval *retval_ptr = NULL;
- zval fname;
- int res;
-
- INIT_PZVAL(&fname);
- ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0);
- res = call_user_function_ex(CG(function_table), struc, &fname,
- &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
-
- if (res == SUCCESS) {
- if (retval_ptr) {
- if (HASH_OF(retval_ptr))
- php_var_serialize_class(buf, struc, retval_ptr,
- var_hash TSRMLS_CC);
- zval_ptr_dtor(&retval_ptr);
- }
- return;
- }
- if (retval_ptr)
- zval_ptr_dtor(&retval_ptr);
- /* fall-through */
- }
- case IS_ARRAY:
- myht = HASH_OF(*struc);
- i = zend_hash_num_elements(myht);
- if (Z_TYPE_PP(struc) == IS_ARRAY) {
- smart_str_appendl(buf, "a:", 2);
- } else {
- php_var_serialize_class_name(buf, struc TSRMLS_CC);
- }
- smart_str_append_long(buf, i);
- smart_str_appendl(buf, ":{", 2);
- if (i > 0) {
- char *key;
- zval **data;
- ulong index;
- ulong key_len;
- HashPosition pos;
-
- zend_hash_internal_pointer_reset_ex(myht, &pos);
- for (;; zend_hash_move_forward_ex(myht, &pos)) {
- i = zend_hash_get_current_key_ex(myht, &key, &key_len,
- &index, 0, &pos);
- if (i == HASH_KEY_NON_EXISTANT)
- break;
-
- if (zend_hash_get_current_data_ex(myht,
- (void **) &data, &pos) != SUCCESS
- || !data
- || data == struc)
- continue;
-
- switch (i) {
- case HASH_KEY_IS_LONG:
- php_var_serialize_long(buf, index);
- break;
- case HASH_KEY_IS_STRING:
- php_var_serialize_string(buf, key, key_len - 1);
- break;
- }
- php_var_serialize_intern(buf, data, var_hash TSRMLS_CC);
- }
- }
- smart_str_appendc(buf, '}');
- return;
- default:
- smart_str_appendl(buf, "i:0;", 4);
- return;
- }
-}
-
-PHPAPI void php_var_serialize(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC)
-{
- php_var_serialize_intern(buf, struc, var_hash TSRMLS_CC);
- smart_str_0(buf);
-}
-
-/* }}} */
-/* {{{ php_var_unserialize */
-
-PHPAPI int php_var_unserialize(zval **rval, const char **p, const char *max, HashTable *var_hash TSRMLS_DC)
-{
- const char *q;
- char *str;
- int i;
- char cur;
- ulong id;
- HashTable *myht;
- zval **rval_ref;
-
- if (var_hash && **p != 'R') { /* references aren't counted by serializer! */
- zend_hash_next_index_insert(var_hash, rval, sizeof(*rval), NULL);
- }
-
- switch (cur = **p) {
- case 'R':
- if (*((*p) + 1) != ':') {
- return 0;
- }
- q = *p;
- while (**p && **p != ';') {
- (*p)++;
- }
- if (**p != ';') {
- return 0;
- }
- (*p)++;
- id = atol(q + 2)-1; /* count starts with 1 */
- if (!var_hash) {
- return 0;
- }
- if (zend_hash_index_find(var_hash, id, (void *)&rval_ref) != SUCCESS) {
- return 0;
- }
- zval_ptr_dtor(rval);
- *rval = *rval_ref;
- (*rval)->refcount++;
- (*rval)->is_ref = 1;
- return 1;
-
- case 'N':
- if (*((*p) + 1) != ';') {
- return 0;
- }
- (*p)++;
- INIT_PZVAL(*rval);
- ZVAL_NULL(*rval);
- (*p)++;
- return 1;
-
- case 'b': /* bool */
- case 'i':
- if (*((*p) + 1) != ':') {
- return 0;
- }
- q = *p;
- while (**p && **p != ';') {
- (*p)++;
- }
- if (**p != ';') {
- return 0;
- }
- (*p)++;
- INIT_PZVAL(*rval);
- if (cur == 'b') {
- ZVAL_BOOL(*rval, atol(q + 2));
- } else {
- ZVAL_LONG(*rval, atol(q + 2));
- }
- return 1;
-
- case 'd':
- if (*((*p) + 1) != ':') {
- return 0;
- }
- q = *p;
- while (**p && **p != ';') {
- (*p)++;
- }
- if (**p != ';') {
- return 0;
- }
- (*p)++;
- INIT_PZVAL(*rval);
- ZVAL_DOUBLE(*rval, 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;
- INIT_PZVAL(*rval);
- ZVAL_STRINGL(*rval, str, i, 0);
- return 1;
-
- case 'a':
- case 'o':
- case 'O': {
- zend_bool incomplete_class = 0;
- char *class_name = NULL;
- size_t name_len = 0;
- int pi;
-
- INIT_PZVAL(*rval);
-
- if (cur == 'a') {
- (*rval)->type = IS_ARRAY;
- ALLOC_HASHTABLE((*rval)->value.ht);
- myht = (*rval)->value.ht;
- } else {
- zend_class_entry *ce;
-
- if (cur == 'O') { /* php4 serialized - we get the class-name */
- if (*((*p) + 1) != ':') {
- return 0;
- }
- (*p) += 2;
- q = *p;
- while (**p && **p != ':') {
- (*p)++;
- }
- if (**p != ':') {
- return 0;
- }
- name_len = 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);
- for(pi=0;pi<i;pi++) {
- class_name[pi] = tolower((*p)[pi]);
- }
- class_name[i] = 0;
- (*p) += i;
-
- if (zend_hash_find(EG(class_table), class_name, i+1, (void **) &ce)==FAILURE) {
- incomplete_class = 1;
- ce = PHP_IC_ENTRY;
- }
- } else { /* old php 3.0 data 'o' */
- ce = &zend_standard_class_def;
- }
-
- /* OBJECTS_FIXME */
- object_init_ex(*rval, ce);
- myht = Z_OBJPROP_PP(rval);
-
- if (incomplete_class)
- php_store_class_name(*rval, class_name, name_len);
-
- if (class_name)
- efree(class_name);
- }
-
- (*p) += 2;
- i = atoi(*p);
-
- if (cur == 'a') { /* object_init_ex will init the HashTable for objects! */
- zend_hash_init(myht, i + 1, NULL, ZVAL_PTR_DTOR, 0);
- }
-
- while (**p && **p != ':') {
- (*p)++;
- }
- if (**p != ':' || *((*p) + 1) != '{') {
- return 0;
- }
- for ((*p) += 2; **p && **p != '}' && i > 0; i--) {
- zval *key;
- zval *data;
-
- ALLOC_INIT_ZVAL(key);
- ALLOC_INIT_ZVAL(data);
-
- if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) {
- zval_dtor(key);
- FREE_ZVAL(key);
- FREE_ZVAL(data);
- return 0;
- }
- if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) {
- zval_dtor(key);
- FREE_ZVAL(key);
- zval_dtor(data);
- FREE_ZVAL(data);
- return 0;
- }
- switch (key->type) {
- case IS_LONG:
- zend_hash_index_update(myht, Z_LVAL_P(key), &data, sizeof(data), NULL);
- break;
- case IS_STRING:
- zend_hash_update(myht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
- break;
- }
- zval_dtor(key);
- FREE_ZVAL(key);
- }
-
- if ((*rval)->type == IS_OBJECT) {
- zval *retval_ptr = NULL;
- zval fname;
-
- INIT_PZVAL(&fname);
- ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
- call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
-
- if (retval_ptr)
- zval_ptr_dtor(&retval_ptr);
- }
-
- return *((*p)++) == '}';
- }
- }
-
- return 0;
-}
-
-/* }}} */
-/* {{{ proto string serialize(mixed variable)
- Returns a string representation of variable (which can later be unserialized) */
-PHP_FUNCTION(serialize)
-{
- zval **struc;
- php_serialize_data_t var_hash;
- smart_str buf = {0};
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &struc) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- return_value->type = IS_STRING;
- return_value->value.str.val = NULL;
- return_value->value.str.len = 0;
-
- PHP_VAR_SERIALIZE_INIT(var_hash);
- php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
- PHP_VAR_SERIALIZE_DESTROY(var_hash);
- RETVAL_STRINGL(buf.c, buf.len, 0);
-}
-
-/* }}} */
-/* {{{ proto mixed unserialize(string variable_representation)
- Takes a string representation of variable and recreates it */
-
-
-PHP_FUNCTION(unserialize)
-{
- zval **buf;
- php_serialize_data_t var_hash;
-
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &buf) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
-
- if ((*buf)->type == IS_STRING) {
- const char *p = (*buf)->value.str.val;
-
- if (Z_STRLEN_PP(buf) == 0) {
- RETURN_FALSE;
- }
-
- PHP_VAR_UNSERIALIZE_INIT(var_hash);
- if (!php_var_unserialize(&return_value, &p, p + Z_STRLEN_PP(buf), &var_hash TSRMLS_CC)) {
- PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
- zval_dtor(return_value);
- php_error(E_NOTICE, "unserialize() failed at offset %d of %d bytes", p - Z_STRVAL_PP(buf), Z_STRLEN_PP(buf));
- RETURN_FALSE;
- }
- PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
- } else {
- php_error(E_NOTICE, "argument passed to unserialize() is not an string");
- RETURN_FALSE;
- }
-}
-
-/* }}} */
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- * vim600: sw=4 ts=4 tw=78 fdm=marker
- * vim<600: sw=4 ts=4 tw=78
- */