First commit of re-structuring phase one. We have started using automake in

sub-directories and started to move extension code into ext/<name>.  For now,
I have moved the "standard" extension (which is quite a mix of everything
right now) and the GD extension into their own subdirs in ext/.
The configure script now also runs configure in the libzend directory
automatically and makes sure php4 and libzend use the same config.cache file.
To avoid running configure in libzend, use the --no-recursion option.
"make" in php4 also builds libzend now.
The Apache module doesn't compile right now, but a fix for that is
coming up.
This commit is contained in:
Stig Bakken 1999-04-17 00:37:12 +00:00
parent 2127ede122
commit 257de2bade
92 changed files with 21455 additions and 1852 deletions

View file

@ -1,7 +1,7 @@
# +----------------------------------------------------------------------+
# | PHP HTML Embedded Scripting Language Version 3.0 |
# | PHP HTML Embedded Scripting Language Version 4.0 |
# +----------------------------------------------------------------------+
# | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
# | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
# +----------------------------------------------------------------------+
# | This program is free software; you can redistribute it and/or modify |
# | it under the terms of one of the following licenses: |
@ -32,13 +32,15 @@ exec_prefix = @exec_prefix@
srcdir = @srcdir@
VPATH = @srcdir@
bindir = @bindir@
ZEND_DIR = $(srcdir)/libzend
SUBDIRS=libzend ext
CC = @CC@
AR = ar rc
BINNAME = @BINNAME@
INSTALL_IT = @INSTALL_IT@
INCLUDE = -I$(srcdir) -I. -I$(ZEND_DIR) @GDBM_INCLUDE@ @ORACLE_INCLUDE@ @APACHE_INCLUDE@ @FHTTPD_INCLUDE@ @ADA_INCLUDE@ @IODBC_INCLUDE@ @SYBASE_INCLUDE@ @SYBASE_CT_INCLUDE@ @MYSQL_INCLUDE@ @MSQL_INCLUDE@ @SOLID_INCLUDE@ @EMPRESS_INCLUDE@ @OPENLINK_INCLUDE@ @PGSQL_INCLUDE@ @LDAP_INCLUDE@ @VELOCIS_INCLUDE@ @CODBC_INCLUDE@ @GD_INCLUDE@ @IMAP_INCLUDE@ @ZLIB_INCLUDE@ @PDFLIB_INCLUDE@ @FDFLIB_INCLUDE@ @IFX_INCLUDE@ @SNMP_INCLUDE@ @IBASE_INCLUDE@
INCLUDE = -I$(srcdir) -I. -I$(ZEND_DIR)
PROF_CFLAGS =
CFLAGS_SHLIB = @CFLAGS_SHLIB@
LDFLAGS_SHLIB = @LDFLAGS_SHLIB@
@ -64,60 +66,55 @@ OBJS = main.o internal_functions.o snprintf.o php3_sprintf.o \
php_ini.o
FUNCTIONS_SOURCE = functions/adabasd.c functions/apache.c functions/fhttpd.c \
functions/basic_functions.c \
functions/crypt.c functions/datetime.c functions/db.c \
functions/dbase.c functions/dir.c \
functions/dl.c functions/dns.c functions/exec.c functions/file.c \
functions/filepro.c functions/filestat.c \
functions/formatted_print.c functions/fsock.c functions/gd.c \
functions/head.c functions/html.c functions/image.c functions/imap.c\
functions/link.c functions/mail.c functions/math.c functions/iptc.c \
functions/md5.c functions/microtime.c functions/mime.c \
functions/crypt.c functions/db.c functions/dbase.c \
functions/dl.c functions/filepro.c \
functions/head.c functions/imap.c functions/mime.c \
functions/msql.c functions/mysql.c \
functions/oracle.c functions/oci8.c functions/pack.c \
functions/pageinfo.c functions/pgsql.c \
functions/post.c functions/rand.c functions/reg.c \
functions/solid.c functions/soundex.c \
functions/string.c functions/syslog.c functions/type.c \
functions/uniqid.c functions/sybase.c \
functions/sybase-ct.c functions/url.c functions/base64.c \
functions/info.c @BCMATH_SRC@ functions/xml.c \
functions/unified_odbc.c functions/ldap.c functions/browscap.c \
functions/velocis.c functions/gdttf.c functions/gdcache.c \
functions/oracle.c functions/oci8.c functions/pgsql.c \
functions/post.c functions/solid.c functions/sybase.c \
functions/sybase-ct.c @BCMATH_SRC@ functions/xml.c \
functions/unified_odbc.c functions/ldap.c functions/velocis.c \
functions/zlib.c functions/COM.c functions/ifx.c \
functions/pdf.c functions/hw.c functions/hg_comm.c functions/dlist.c \
functions/fdf.c \
functions/snmp.c functions/var.c functions/interbase.c \
functions/quot_print.c functions/cyr_convert.c \
functions/fdf.c functions/snmp.c functions/interbase.c \
functions/sysvsem.c functions/sysvshm.c functions/dav.c
FUNCTIONS = $(FUNCTIONS_SOURCE:.c=.o)
LIBS = $(PHPLIBS) @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @FHTTPD_LIB@ @DBASE_LIB@ @REGEX_LIB@ @DBM_LIB@ @ORACLE_LFLAGS@ @ORACLE_LIBS@ @IODBC_LFLAGS@ @IODBC_LIBS@ @SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @MYSQL_LFLAGS@ @MYSQL_LIBS@ @MSQL_LFLAGS@ @MSQL_LIBS@ @ADA_LFLAGS@ @ADA_LIBS@ @SOLID_LIBS@ @EMPRESS_LIBS@ @OPENLINK_LFLAGS@ @OPENLINK_LIBS@ @PGSQL_LFLAGS@ @PGSQL_LIBS@ @LDAP_LFLAGS@ @LDAP_LIBS@ @VELOCIS_LIBS@ @CODBC_LFLAGS@ @CODBC_LIBS@ @IMAP_LIBS@ @GD_LIBS@ @ZLIB_LIBS@ @PDFLIB_LIBS@ @FDFLIB_LIBS@ @IFX_LFLAGS@ @IFX_LIBS@ @SNMP_LFLAGS@ @SNMP_LIBS@ @IBASE_LFLAGS@ @IBASE_LIBS@ @XML_LIBS@ @LIBS@
PHPLIBS = -L@top_srcdir@/libzend -lzend -L@top_srcdir@/ext -lphpext
LIBS = $(PHPLIBS) @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @FHTTPD_LIB@ @DBASE_LIB@ @REGEX_LIB@ @DBM_LIB@ @ORACLE_LFLAGS@ @ORACLE_LIBS@ @IODBC_LFLAGS@ @IODBC_LIBS@ @SYBASE_LFLAGS@ @SYBASE_LIBS@ @SYBASE_CT_LFLAGS@ @SYBASE_CT_LIBS@ @MYSQL_LFLAGS@ @MYSQL_LIBS@ @MSQL_LFLAGS@ @MSQL_LIBS@ @ADA_LFLAGS@ @ADA_LIBS@ @SOLID_LIBS@ @EMPRESS_LIBS@ @OPENLINK_LFLAGS@ @OPENLINK_LIBS@ @PGSQL_LFLAGS@ @PGSQL_LIBS@ @LDAP_LFLAGS@ @LDAP_LIBS@ @VELOCIS_LIBS@ @CODBC_LFLAGS@ @CODBC_LIBS@ @IMAP_LIBS@ @ZLIB_LIBS@ @PDFLIB_LIBS@ @FDFLIB_LIBS@ @IFX_LFLAGS@ @IFX_LIBS@ @SNMP_LFLAGS@ @SNMP_LIBS@ @IBASE_LFLAGS@ @IBASE_LIBS@ @XML_LIBS@ @LIBS@
all: $(BINNAME)
php: $(OBJS) $(FUNCTIONS) @REGEX_LIB@ @FHTTPD_LIB@ @DBASE_LIB@ $(ZEND_DIR)/libzend.a
all-recursive clean-recursive distclean-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
for subdir in $(SUBDIRS); do \
target=`echo $@ | sed s/-recursive//`; \
echo "Making $$target in $$subdir"; \
(cd $$subdir && $(MAKE) $$target) || fail=yes; \
done && test -z "$$fail"
# CGI binary or fhttpd module
php: all-recursive $(OBJS) $(FUNCTIONS) @REGEX_LIB@ @FHTTPD_LIB@ @DBASE_LIB@
$(CC) $(CFLAGS) -o $(BINNAME) $(LDFLAGS) $(OBJS) $(FUNCTIONS) $(LIBS)
libphp3.a: $(OBJS) $(FUNCTIONS) @DBASE_LIB@
# Apache 1.2 module
libphp3.a: all-recursive $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(AR) $(BINNAME) $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(RANLIB) $(BINNAME)
libmodphp3.a: $(OBJS) $(FUNCTIONS) @DBASE_LIB@
# Apache 1.3 static module
libmodphp3.a: all-recursive $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(AR) $(BINNAME) $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(RANLIB) $(BINNAME)
libmodphp3-so.a: $(OBJS) $(FUNCTIONS) @DBASE_LIB@
# Apache 1.3 shared module
libmodphp3-so.a: all-recursive $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(AR) libmodphp3-so.a $(OBJS) $(FUNCTIONS) @DBASE_LIB@
$(RANLIB) libmodphp3-so.a
libphp3.so: mod_php3.c libmodphp3-so.a
$(APXS) -c -o libphp3.so $(APXS_LDFLAGS) mod_php3.c libmodphp3-so.a
docs:
cd doc; $(MAKE)
regex/libregex.a:
(cd regex; $(MAKE) lib)
@ -136,14 +133,14 @@ configuration-scanner.o:
configuration-scanner.c: $(srcdir)/configuration-scanner.l
flex -Pcfg -oconfiguration-scanner.c -i $(srcdir)/configuration-scanner.l
clean:
clean: clean-recursive
-rm -f libphp3.a libmodphp3.a php *.o
-rm -f $(FUNCTIONS) functions/ifx.c
-rm -f test/php.desc test/php.in test/php.out test/php.test
-rm -f test/a.tmp test/b.tmp test/test.dbm*
(cd dbase; $(MAKE) clean)
distclean: clean
distclean: clean distclean-recursive
-rm -f *-parser.[ch] *-scanner.c *.output
-rm -f config.status config.cache config.log
-rm -f Makefile Makefile.depend config.h build-defs.h
@ -210,680 +207,6 @@ depend: parser-scanner
$(CC) $(CFLAGS) -MM $(SOURCE) | perl -pe 's|regex/regex.h||;' > Makefile.depend
$(CC) $(CFLAGS) -MM $(FUNCTIONS_SOURCE) | perl -pe 's|^(.+\.o)|functions/$$1|; s|regex/regex.h||;' >> Makefile.depend
main.o: main.c php.h php_version.h libzend/zend.h libzend/config.h \
libzend/config.unix.h libzend/zend_errors.h libzend/zend_alloc.h \
libzend/zend_hash.h libzend/zend_llist.h libzend/zend_API.h \
libzend/modules.h libzend/zend_list.h config.h request_info.h \
php3_compat.h libzend/zend_stack.h safe_mode.h \
fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h build-defs.h \
php_ini.h php_globals.h main.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_execute.h control_structures.h \
functions/basic_functions.h libzend/zend_highlight.h functions/info.h \
functions/head.h functions/post.h functions/type.h snprintf.h \
libzend/zend_indent.h logos.h
internal_functions.o: internal_functions.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h internal_functions_registry.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_execute.h functions/php3_ifx.h \
functions/php3_ldap.h functions/php3_mysql.h functions/php3_bcmath.h \
functions/php3_msql.h functions/basic_functions.h \
libzend/zend_highlight.h functions/phpmath.h functions/php3_string.h \
functions/php3_oci8.h functions/oracle.h functions/base64.h \
functions/php3_dir.h functions/dns.h functions/php3_pgsql.h \
functions/php3_velocis.h functions/php3_sybase.h \
functions/php3_sybase-ct.h functions/reg.h functions/php3_mail.h \
functions/imap.h functions/md5.h functions/global.h \
functions/php3_gd.h functions/html.h functions/dl.h functions/head.h \
functions/post.h functions/exec.h functions/php3_solid.h \
functions/adabasd.h functions/file.h functions/dbase.h functions/hw.h \
functions/filepro.h functions/db.h functions/php3_syslog.h \
functions/php3_filestat.h functions/php3_browscap.h functions/pack.h \
functions/php3_unified_odbc.h dl/snmp/php3_snmp.h \
functions/php3_zlib.h functions/php3_COM.h functions/php3_interbase.h \
functions/php3_xml.h functions/php3_pdf.h functions/php3_fdf.h \
functions/php3_sysvsem.h functions/php3_sysvshm.h \
functions/php3_dav.h
snprintf.o: snprintf.c config.h
php3_sprintf.o: php3_sprintf.c config.h
configuration-parser.o: configuration-parser.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h php_globals.h php_ini.h functions/dl.h \
functions/file.h functions/php3_browscap.h libzend/zend_extensions.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_execute.h
configuration-scanner.o: configuration-scanner.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h configuration-parser.h
request_info.o: request_info.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h
safe_mode.o: safe_mode.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/pageinfo.h
fopen-wrappers.o: fopen-wrappers.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_globals.h \
php3_realpath.h functions/head.h functions/url.h functions/base64.h \
functions/fsock.h functions/php3_string.h libzend/zend_compile.h \
libzend/zend-parser.h libzend/zend_globals.h libzend/zend_ptr_stack.h \
libzend/zend_execute.h
php3_realpath.o: php3_realpath.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h
alloca.o: alloca.c
output.o: output.c php.h php_version.h libzend/zend.h libzend/config.h \
libzend/config.unix.h libzend/zend_errors.h libzend/zend_alloc.h \
libzend/zend_hash.h libzend/zend_llist.h libzend/zend_API.h \
libzend/modules.h libzend/zend_list.h config.h request_info.h \
php3_compat.h libzend/zend_stack.h safe_mode.h \
fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h
php_ini.o: php_ini.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_ini.h \
php_globals.h
functions/adabasd.o: functions/adabasd.c config.h build-defs.h php.h \
php_version.h libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/php3_string.h functions/head.h \
functions/adabasd.h
functions/apache.o: functions/apache.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
php_globals.h php_ini.h mod_php3.h
functions/fhttpd.o: functions/fhttpd.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h
functions/basic_functions.o: functions/basic_functions.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h php_ini.h internal_functions_registry.h \
functions/basic_functions.h libzend/zend_highlight.h \
functions/phpmath.h functions/php3_string.h functions/dns.h \
functions/md5.h functions/global.h functions/html.h functions/post.h \
functions/exec.h functions/info.h functions/url.h \
functions/datetime.h functions/fsock.h functions/image.h \
functions/php3_link.h functions/php3_filestat.h functions/microtime.h \
functions/pageinfo.h functions/uniqid.h functions/base64.h \
functions/php3_mail.h functions/php3_var.h functions/php3_iptc.h \
functions/quot_print.h functions/cyr_convert.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_execute.h php_globals.h
functions/crypt.o: functions/crypt.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_string.h
functions/datetime.o: functions/datetime.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/datetime.h snprintf.h php_globals.h
functions/db.o: functions/db.c
functions/dbase.o: functions/dbase.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_globals.h
functions/dir.o: functions/dir.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_dir.h
functions/dl.o: functions/dl.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/dl.h \
php_globals.h
functions/dns.o: functions/dns.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/dns.h
functions/exec.o: functions/exec.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_string.h functions/head.h functions/exec.h \
php_globals.h
functions/file.o: functions/file.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_string.h functions/file.h snprintf.h functions/fsock.h \
php_globals.h
functions/filepro.o: functions/filepro.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_globals.h \
functions/filepro.h
functions/filestat.o: functions/filestat.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_globals.h \
functions/php3_filestat.h
functions/formatted_print.o: functions/formatted_print.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/head.h functions/php3_string.h \
libzend/zend_execute.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_globals.h libzend/zend_ptr_stack.h
functions/fsock.o: functions/fsock.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/base64.h \
functions/file.h functions/post.h functions/url.h functions/fsock.h \
build-defs.h
functions/gd.o: functions/gd.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_gd.h
functions/head.o: functions/head.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/reg.h \
functions/php3_string.h functions/pageinfo.h main.h \
libzend/zend_globals.h libzend/zend_ptr_stack.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_execute.h \
functions/datetime.h functions/head.h functions/post.h php_globals.h \
functions/url.h
functions/html.o: functions/html.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/reg.h \
functions/html.h
functions/image.o: functions/image.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/image.h
functions/imap.o: functions/imap.c config.h php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h
functions/link.o: functions/link.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_filestat.h php_globals.h functions/php3_link.h
functions/mail.o: functions/mail.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h build-defs.h \
functions/php3_mail.h php_ini.h
functions/math.o: functions/math.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/phpmath.h \
snprintf.h
functions/iptc.o: functions/iptc.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_iptc.h
functions/md5.o: functions/md5.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/md5.h \
functions/global.h
functions/microtime.o: functions/microtime.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/microtime.h snprintf.h
functions/mime.o: functions/mime.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/type.h \
functions/post.h functions/mime.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_execute.h php_globals.h
functions/msql.o: functions/msql.c config.h php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_msql.h functions/reg.h functions/php3_string.h \
php_globals.h
functions/mysql.o: functions/mysql.c config.h build-defs.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h php_globals.h functions/php3_string.h \
functions/php3_mysql.h php_ini.h
functions/oracle.o: functions/oracle.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/oracle.h
functions/oci8.o: functions/oci8.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_oci8.h
functions/pack.o: functions/pack.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_string.h functions/pack.h snprintf.h functions/fsock.h
functions/pageinfo.o: functions/pageinfo.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/pageinfo.h
functions/pgsql.o: functions/pgsql.c config.h php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_pgsql.h functions/php3_string.h php_globals.h
functions/post.o: functions/post.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/mime.h \
functions/type.h functions/php3_string.h functions/post.h \
functions/url.h php_globals.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_execute.h
functions/rand.o: functions/rand.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/phpmath.h
functions/reg.o: functions/reg.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_string.h functions/reg.h
functions/solid.o: functions/solid.c config.h build-defs.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/php3_solid.h
functions/soundex.o: functions/soundex.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_string.h
functions/string.o: functions/string.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/reg.h \
functions/post.h functions/php3_string.h libzend/zend_execute.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h php_globals.h
functions/syslog.o: functions/syslog.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_ini.h \
libzend/zend_globals.h libzend/zend_ptr_stack.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_execute.h \
functions/php3_syslog.h
functions/type.o: functions/type.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/type.h
functions/uniqid.o: functions/uniqid.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/uniqid.h
functions/sybase.o: functions/sybase.c config.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/php3_sybase.h \
functions/php3_string.h php_globals.h
functions/sybase-ct.o: functions/sybase-ct.c config.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/php3_sybase-ct.h \
functions/php3_string.h php_globals.h
functions/url.o: functions/url.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/url.h
functions/base64.o: functions/base64.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/base64.h
functions/info.o: functions/info.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h php_ini.h \
php_globals.h functions/head.h functions/info.h build-defs.h \
libzend/zend_globals.h libzend/zend_ptr_stack.h \
libzend/zend_compile.h libzend/zend-parser.h libzend/zend_execute.h
functions/bcmath.o: functions/bcmath.c config.h build-defs.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/number.h functions/php3_bcmath.h
functions/number.o: functions/number.c functions/number.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h
functions/xml.o: functions/xml.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_xml.h
functions/unified_odbc.o: functions/unified_odbc.c config.h build-defs.h php.h \
php_version.h libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h dl/phpdl.h functions/php3_string.h \
functions/php3_unified_odbc.h functions/head.h snprintf.h
functions/ldap.o: functions/ldap.c config.h php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h
functions/browscap.o: functions/browscap.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_browscap.h php_ini.h libzend/zend_globals.h \
libzend/zend_ptr_stack.h libzend/zend_compile.h libzend/zend-parser.h \
libzend/zend_execute.h
functions/velocis.o: functions/velocis.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_velocis.h
functions/gdttf.o: functions/gdttf.c config.h
functions/gdcache.o: functions/gdcache.c config.h
functions/zlib.o: functions/zlib.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_string.h functions/php3_zlib.h snprintf.h
functions/COM.o: functions/COM.c
functions/pdf.o: functions/pdf.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_pdf.h
functions/hw.o: functions/hw.c config.h php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h
functions/hg_comm.o: functions/hg_comm.c config.h
functions/dlist.o: functions/dlist.c config.h
functions/fdf.o: functions/fdf.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/head.h \
functions/php3_fdf.h
functions/snmp.o: functions/snmp.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_snmp.h
functions/var.o: functions/var.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h functions/reg.h \
functions/post.h functions/php3_string.h functions/php3_var.h
functions/interbase.o: functions/interbase.c config.h php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h \
libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/php3_interbase.h
functions/quot_print.o: functions/quot_print.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/quot_print.h
functions/cyr_convert.o: functions/cyr_convert.c php.h php_version.h \
libzend/zend.h libzend/config.h libzend/config.unix.h \
libzend/zend_errors.h libzend/zend_alloc.h libzend/zend_hash.h \
libzend/zend_llist.h libzend/zend_API.h libzend/modules.h \
libzend/zend_list.h config.h request_info.h php3_compat.h \
libzend/zend_stack.h safe_mode.h fopen-wrappers.h \
output.h libzend/zend_operators.h libzend/zend_variables.h \
libzend/zend_constants.h functions/cyr_convert.h
functions/sysvsem.o: functions/sysvsem.c config.h
functions/sysvshm.o: functions/sysvshm.c config.h
functions/dav.o: functions/dav.c php.h php_version.h libzend/zend.h \
libzend/config.h libzend/config.unix.h libzend/zend_errors.h \
libzend/zend_alloc.h libzend/zend_hash.h libzend/zend_llist.h \
libzend/zend_API.h libzend/modules.h libzend/zend_list.h config.h \
request_info.h php3_compat.h libzend/zend_stack.h \
safe_mode.h fopen-wrappers.h output.h libzend/zend_operators.h \
libzend/zend_variables.h libzend/zend_constants.h \
functions/php3_dav.h
# Local Variables:
# tab-width: 4
# End:

433
acinclude.m4 Normal file
View file

@ -0,0 +1,433 @@
dnl $Id$
dnl
dnl This file contains local autoconf functions.
AC_DEFUN(AC_ORACLE_VERSION,[
AC_MSG_CHECKING([Oracle version])
if test -f "$ORACLEINST_TOP/orainst/unix.rgs"
then
ORACLE_VERSION=`grep '"ocommon"' $ORACLEINST_TOP/orainst/unix.rgs | sed 's/[ ][ ]*/:/g' | cut -d: -f 6 | cut -c 2-4`
test -z "$ORACLE_VERSION" && ORACLE_VERSION=7.3
else
ORACLE_VERSION=8.0
fi
AC_MSG_RESULT($ORACLE_VERSION)
])
dnl
dnl Test mSQL version by checking if msql.h has "IDX_TYPE" defined.
dnl
AC_DEFUN(AC_MSQL_VERSION,[
AC_MSG_CHECKING([mSQL version])
ac_php_oldcflags=$CFLAGS
CFLAGS="$MSQL_INCLUDE $CFLAGS";
AC_TRY_COMPILE([#include <sys/types.h>
#include "msql.h"],[int i = IDX_TYPE],[
AC_DEFINE(MSQL1,0)
MSQL_VERSION="2.0 or newer"
],[
AC_DEFINE(MSQL1,1)
MSQL_VERSION="1.0"
])
CFLAGS=$ac_php_oldcflags
AC_MSG_RESULT($MSQL_VERSION)
])
dnl
dnl Figure out which library file to link with for the Solid support.
dnl
AC_DEFUN(AC_FIND_SOLID_LIBS,[
AC_MSG_CHECKING([Solid library file])
ac_solid_uname_s=`uname -s 2>/dev/null`
case $ac_solid_uname_s in
AIX) ac_solid_os=a3x;;
HP-UX) ac_solid_os=h9x;;
IRIX) ac_solid_os=irx;;
Linux) ac_solid_os=lux;;
SunOS) ac_solid_os=ssx;; # should we deal with SunOS 4?
FreeBSD) ac_solid_os=fbx;;
# "uname -s" on SCO makes no sense.
esac
SOLID_LIBS=`echo $1/scl${ac_solid_os}*.so | cut -d' ' -f1`
if test ! -f $SOLID_LIBS; then
SOLID_LIBS=`echo $1/scl${ac_solid_os}*.a | cut -d' ' -f1`
fi
if test ! -f $SOLID_LIBS; then
SOLID_LIBS=`echo $1/scl2x${ac_solid_os}*.a | cut -d' ' -f1`
fi
if test ! -f $SOLID_LIBS; then
SOLID_LIBS=`echo $1/scl2x${ac_solid_os}*.a | cut -d' ' -f1`
fi
if test ! -f $SOLID_LIBS; then
SOLID_LIBS=`echo $1/bcl${ac_solid_os}*.so | cut -d' ' -f1`
fi
if test ! -f $SOLID_LIBS; then
SOLID_LIBS=`echo $1/bcl${ac_solid_os}*.a | cut -d' ' -f1`
fi
AC_MSG_RESULT(`echo $SOLID_LIBS | sed -e 's!.*/!!'`)
])
dnl
dnl Figure out which library file to link with for the Empress support.
dnl
AC_DEFUN(AC_FIND_EMPRESS_LIBS,[
AC_MSG_CHECKING([Empress library file])
EMPRESS_LIBS=`echo $1/empodbc.so | cut -d' ' -f1`
if test ! -f $EMPRESS_LIBS; then
EMPRESS_LIBS=`echo $1/empodbc.a | cut -d' ' -f1`
fi
AC_MSG_RESULT(`echo $EMPRESS_LIBS | sed -e 's!.*/!!'`)
])
dnl
dnl See if we have broken header files like SunOS has.
dnl
AC_DEFUN(AC_MISSING_FCLOSE_DECL,[
AC_MSG_CHECKING([for fclose declaration])
AC_TRY_COMPILE([#include <stdio.h>],[int (*func)() = fclose],[
AC_DEFINE(MISSING_FCLOSE_DECL,0)
AC_MSG_RESULT(ok)
],[
AC_DEFINE(MISSING_FCLOSE_DECL,1)
AC_MSG_RESULT(missing)
])
])
# Checks for libraries.
# Prefer gdbm, Berkeley DB and ndbm/dbm, in that order
AC_DEFUN(AC_PREFERRED_DB_LIB,[
AC_CHECK_LIB(gdbm, gdbm_open,[AC_DEFINE(GDBM) DBM_TYPE=gdbm; DBM_LIB=-lgdbm],
[AC_CHECK_LIB(db, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldb],
[AC_CHECK_LIB(c, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=],
[AC_CHECK_LIB(dbm, dbm_open,[AC_DEFINE(NDBM) DBM_TYPE=ndbm; DBM_LIB=-ldbm],
[DBM_TYPE=""])])])])
AC_MSG_CHECKING([preferred dbm library])
if test "a$DBM_TYPE" = a; then
AC_MSG_RESULT(none found)
AC_MSG_WARN(No dbm library found - using built-in flatfile support)
else
AC_MSG_RESULT($DBM_TYPE chosen)
fi
AC_SUBST(DBM_LIB)
AC_SUBST(DBM_TYPE)
])
dnl
dnl Check for broken sprintf()
dnl
AC_DEFUN(AC_BROKEN_SPRINTF,[
AC_MSG_CHECKING([for broken sprintf])
AC_TRY_RUN([main() { char buf[20]; exit (sprintf(buf,"testing 123")!=11); }],[
AC_DEFINE(BROKEN_SPRINTF,0)
AC_MSG_RESULT(ok)
],[
AC_DEFINE(BROKEN_SPRINTF,1)
AC_MSG_RESULT(broken)
],[
AC_DEFINE(BROKEN_SPRINTF,0)
AC_MSG_RESULT(cannot check, guessing ok)
])
])
dnl
dnl Check for crypt() capabilities
dnl
AC_DEFUN(AC_CRYPT_CAP,[
AC_MSG_CHECKING([for standard DES crypt])
AC_TRY_RUN([
main() {
#if HAVE_CRYPT
exit (strcmp((char *)crypt("rasmuslerdorf","rl"),"rl.3StKT.4T8M"));
#else
exit(0);
#endif
}],[
AC_DEFINE(PHP3_STD_DES_CRYPT,1)
AC_MSG_RESULT(yes)
],[
AC_DEFINE(PHP3_STD_DES_CRYPT,0)
AC_MSG_RESULT(no)
],[
AC_DEFINE(PHP3_STD_DES_CRYPT,1)
AC_MSG_RESULT(cannot check, guessing yes)
])
AC_MSG_CHECKING([for extended DES crypt])
AC_TRY_RUN([
main() {
#if HAVE_CRYPT
exit (strcmp((char *)crypt("rasmuslerdorf","_J9..rasm"),"_J9..rasmBYk8r9AiWNc"));
#else
exit(0);
#endif
}],[
AC_DEFINE(PHP3_EXT_DES_CRYPT,1)
AC_MSG_RESULT(yes)
],[
AC_DEFINE(PHP3_EXT_DES_CRYPT,0)
AC_MSG_RESULT(no)
],[
AC_DEFINE(PHP3_EXT_DES_CRYPT,0)
AC_MSG_RESULT(cannot check, guessing no)
])
AC_MSG_CHECKING([for MD5 crypt])
AC_TRY_RUN([
main() {
#if HAVE_CRYPT
char salt[15], answer[40];
salt[0]='$'; salt[1]='1'; salt[2]='$';
salt[3]='r'; salt[4]='a'; salt[5]='s';
salt[6]='m'; salt[7]='u'; salt[8]='s';
salt[9]='l'; salt[10]='e'; salt[11]='$';
salt[12]='\0';
strcpy(answer,salt);
strcat(answer,"rISCgZzpwk3UhDidwXvin0");
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
#else
exit(0);
#endif
}],[
AC_DEFINE(PHP3_MD5_CRYPT,1)
AC_MSG_RESULT(yes)
],[
AC_DEFINE(PHP3_MD5_CRYPT,0)
AC_MSG_RESULT(no)
],[
AC_DEFINE(PHP3_MD5_CRYPT,0)
AC_MSG_RESULT(cannot check, guessing no)
])
AC_MSG_CHECKING([for Blowfish crypt])
AC_TRY_RUN([
main() {
#if HAVE_CRYPT
char salt[25], answer[70];
salt[0]='$'; salt[1]='2'; salt[2]='a'; salt[3]='$'; salt[4]='0'; salt[5]='7'; salt[6]='$'; salt[7]='\0';
strcat(salt,"rasmuslerd");
strcpy(answer,salt);
strcpy(&answer[16],"O............gl95GkTKn53Of.H4YchXl5PwvvW.5ri");
exit (strcmp((char *)crypt("rasmuslerdorf",salt),answer));
#else
exit(0);
#endif
}],[
AC_DEFINE(PHP3_BLOWFISH_CRYPT,1)
AC_MSG_RESULT(yes)
],[
AC_DEFINE(PHP3_BLOWFISH_CRYPT,0)
AC_MSG_RESULT(no)
],[
AC_DEFINE(PHP3_BLOWFISH_CRYPT,0)
AC_MSG_RESULT(cannot check, guessing no)
])
])
## libtool.m4 - Configure libtool for the target system. -*-Shell-script-*-
## Copyright (C) 1996, 1997 Free Software Foundation, Inc.
## Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## As a special exception to the GNU General Public License, if you
## distribute this file as part of a program that contains a
## configuration script generated by Autoconf, you may include it under
## the same distribution terms that you use for the rest of that program.
# serial 9 AM_PROG_LIBTOOL
AC_DEFUN(AM_PROG_LIBTOOL,
[AC_REQUIRE([AC_CANONICAL_HOST])
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_PROG_RANLIB])
AC_REQUIRE([AM_PROG_LD])
AC_REQUIRE([AC_PROG_LN_S])
# Always use our own libtool.
LIBTOOL='$(top_builddir)/libtool'
AC_SUBST(LIBTOOL)
dnl Allow the --disable-shared flag to stop us from building shared libs.
AC_ARG_ENABLE(shared,
[ --enable-shared build shared libraries [default=yes]],
test "$enableval" = no && libtool_shared=" --disable-shared",
libtool_shared=)
dnl Allow the --disable-static flag to stop us from building static libs.
AC_ARG_ENABLE(static,
[ --enable-static build static libraries [default=yes]],
test "$enableval" = no && libtool_static=" --disable-static",
libtool_static=)
libtool_flags="$libtool_shared$libtool_static"
test "$silent" = yes && libtool_flags="$libtool_flags --silent"
test "$ac_cv_prog_gcc" = yes && libtool_flags="$libtool_flags --with-gcc"
test "$ac_cv_prog_gnu_ld" = yes && libtool_flags="$libtool_flags --with-gnu-ld"
# Some flags need to be propagated to the compiler or linker for good
# libtool support.
[case "$host" in
*-*-irix6*)
for f in '-32' '-64' '-cckr' '-n32' '-mips1' '-mips2' '-mips3' '-mips4'; do
if echo " $CC $CFLAGS " | egrep -e "[ ]$f[ ]" > /dev/null; then
LD="${LD-ld} $f"
fi
done
;;
*-*-sco3.2v5*)
# On SCO OpenServer 5, we need -belf to get full-featured binaries.
CFLAGS="$CFLAGS -belf"
;;
esac]
# Actually configure libtool. ac_aux_dir is where install-sh is found.
CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" \
LD="$LD" RANLIB="$RANLIB" LN_S="$LN_S" \
${CONFIG_SHELL-/bin/sh} $ac_aux_dir/ltconfig \
$libtool_flags --no-verify $ac_aux_dir/ltmain.sh $host \
|| AC_MSG_ERROR([libtool configure failed])
])
# AM_PROG_LD - find the path to the GNU or non-GNU linker
AC_DEFUN(AM_PROG_LD,
[AC_ARG_WITH(gnu-ld,
[ --with-gnu-ld assume the C compiler uses GNU ld [default=no]],
test "$withval" = no || with_gnu_ld=yes, with_gnu_ld=no)
if test "$with_gnu_ld" = yes; then
AC_MSG_CHECKING([for GNU ld])
else
AC_MSG_CHECKING([for non-GNU ld])
fi
AC_CACHE_VAL(ac_cv_path_LD,
[case "$LD" in
/*)
ac_cv_path_LD="$LD" # Let the user override the test with a path.
;;
*)
IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:"
for ac_dir in $PATH; do
test -z "$ac_dir" && ac_dir=.
if test -f "$ac_dir/ld"; then
ac_cv_path_LD="$ac_dir/ld"
# Check to see if the program is GNU ld. I'd rather use --version,
# but apparently some GNU ld's only accept -v.
# Break only if it was the GNU/non-GNU ld that we prefer.
if "$ac_cv_path_LD" -v 2>&1 < /dev/null | egrep '(GNU ld|with BFD)' > /dev/null; then
test "$with_gnu_ld" = yes && break
else
test "$with_gnu_ld" != yes && break
fi
fi
done
IFS="$ac_save_ifs"
;;
esac])
LD="$ac_cv_path_LD"
if test -n "$LD"; then
AC_MSG_RESULT($LD)
else
AC_MSG_RESULT(no)
fi
test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
AC_SUBST(LD)
AM_PROG_LD_GNU
])
AC_DEFUN(AM_PROG_LD_GNU,
[AC_CACHE_CHECK([whether we are using GNU ld], ac_cv_prog_gnu_ld,
[# I'd rather use --version here, but apparently some GNU ld's only accept -v.
if $LD -v 2>&1 </dev/null | egrep '(GNU ld|with BFD)' > /dev/null; then
ac_cv_prog_gnu_ld=yes
else
ac_cv_prog_gnu_ld=no
fi])
])
# the following 'borrwed' from automake until we switch over
# Add --enable-maintainer-mode option to configure.
# From Jim Meyering
# serial 1
AC_DEFUN(AM_MAINTAINER_MODE,
[AC_MSG_CHECKING([whether to enable maintainer-specific portions of Makefiles])
dnl maintainer-mode is disabled by default
AC_ARG_ENABLE(maintainer-mode,
[ --enable-maintainer-mode enable make rules and dependencies not useful
(and sometimes confusing) to the casual installer],
USE_MAINTAINER_MODE=$enableval,
USE_MAINTAINER_MODE=no)
AC_MSG_RESULT($USE_MAINTAINER_MODE)
if test $USE_MAINTAINER_MODE = yes; then
MAINT=
else
MAINT='#M#'
fi
AC_SUBST(MAINT)dnl
]
)
# another one stolen from automake temporarily
#
# Check to make sure that the build environment is sane.
#
AC_DEFUN(AM_SANITY_CHECK,
[AC_MSG_CHECKING([whether build environment is sane])
# Just in case
sleep 1
echo timestamp > conftestfile
# Do `set' in a subshell so we don't clobber the current shell's
# arguments. Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
if test "$@" = "X"; then
# -L didn't work.
set X `ls -t $srcdir/configure conftestfile`
fi
test "[$]2" = conftestfile
)
then
# Ok.
:
else
AC_MSG_ERROR([newly created file is older than distributed files!
Check your system clock])
fi
rm -f conftest*
AC_MSG_RESULT(yes)])
dnl
dnl Stuff to do when setting up a new extension.
dnl XXX have to change the hardcoding of ".a" when we want to be able
dnl to make dynamic libraries as well.
dnl
AC_DEFUN(PHP_EXTENSION,[
EXT_SUBDIRS="$EXT_SUBDIRS $1"
_extlib="libphpext_$1.a"
EXT_LIBS="$EXT_LIBS $1/$_extlib"
EXTINFO_DEPS="$EXTINFO_DEPS ../ext/$1/extinfo.c.stub"
])
AC_SUBST(EXT_SUBDIRS)
AC_SUBST(EXT_LIBS)
AC_SUBST(EXTINFO_DEPS)

132
aclocal.m4 vendored
View file

@ -1,3 +1,15 @@
dnl aclocal.m4 generated automatically by aclocal 1.3
dnl Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
dnl This Makefile.in is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
dnl PARTICULAR PURPOSE.
dnl $Id$
dnl
dnl This file contains local autoconf functions.
@ -227,28 +239,6 @@ main() {
])
])
## libtool.m4 - Configure libtool for the target system. -*-Shell-script-*-
## Copyright (C) 1996, 1997 Free Software Foundation, Inc.
## Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## As a special exception to the GNU General Public License, if you
## distribute this file as part of a program that contains a
## configuration script generated by Autoconf, you may include it under
## the same distribution terms that you use for the rest of that program.
# serial 9 AM_PROG_LIBTOOL
AC_DEFUN(AM_PROG_LIBTOOL,
@ -415,3 +405,101 @@ Check your system clock])
fi
rm -f conftest*
AC_MSG_RESULT(yes)])
dnl
dnl Stuff to do when setting up a new extension.
dnl XXX have to change the hardcoding of ".a" when we want to be able
dnl to make dynamic libraries as well.
dnl
AC_DEFUN(PHP_EXTENSION,[
EXT_SUBDIRS="$EXT_SUBDIRS $1"
_extlib="libphpext_$1.a"
EXT_LIBS="$EXT_LIBS $1/$_extlib"
EXTINFO_DEPS="$EXTINFO_DEPS ../ext/$1/extinfo.c.stub"
])
AC_SUBST(EXT_SUBDIRS)
AC_SUBST(EXT_LIBS)
AC_SUBST(EXTINFO_DEPS)
# Do all the work for Automake. This macro actually does too much --
# some checks are only needed if your package does certain things.
# But this isn't really a big deal.
# serial 1
dnl Usage:
dnl AM_INIT_AUTOMAKE(package,version, [no-define])
AC_DEFUN(AM_INIT_AUTOMAKE,
[AC_REQUIRE([AM_PROG_INSTALL])
PACKAGE=[$1]
AC_SUBST(PACKAGE)
VERSION=[$2]
AC_SUBST(VERSION)
dnl test to see if srcdir already configured
if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
fi
ifelse([$3],,
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION"))
AC_REQUIRE([AM_SANITY_CHECK])
AC_REQUIRE([AC_ARG_PROGRAM])
dnl FIXME This is truly gross.
missing_dir=`cd $ac_aux_dir && pwd`
AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
AC_REQUIRE([AC_PROG_MAKE_SET])])
# serial 1
AC_DEFUN(AM_PROG_INSTALL,
[AC_REQUIRE([AC_PROG_INSTALL])
test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}'
AC_SUBST(INSTALL_SCRIPT)dnl
])
dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
dnl The program must properly implement --version.
AC_DEFUN(AM_MISSING_PROG,
[AC_MSG_CHECKING(for working $2)
# Run test in a subshell; some versions of sh will print an error if
# an executable is not found, even if stderr is redirected.
# Redirect stdin to placate older versions of autoconf. Sigh.
if ($2 --version) < /dev/null > /dev/null 2>&1; then
$1=$2
AC_MSG_RESULT(found)
else
$1="$3/missing $2"
AC_MSG_RESULT(missing)
fi
AC_SUBST($1)])
# Like AC_CONFIG_HEADER, but automatically create stamp file.
AC_DEFUN(AM_CONFIG_HEADER,
[AC_PREREQ([2.12])
AC_CONFIG_HEADER([$1])
dnl When config.status generates a header, we must update the stamp-h file.
dnl This file resides in the same directory as the config header
dnl that is generated. We must strip everything past the first ":",
dnl and everything past the last "/".
AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
<<am_indx=1
for am_file in <<$1>>; do
case " <<$>>CONFIG_HEADERS " in
*" <<$>>am_file "*<<)>>
echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
;;
esac
am_indx=`expr "<<$>>am_indx" + 1`
done<<>>dnl>>)
changequote([,]))])

File diff suppressed because it is too large Load diff

1993
configure.in.in Normal file

File diff suppressed because it is too large Load diff

8
ext/Makefile.am Normal file
View file

@ -0,0 +1,8 @@
## Process this file with automake to produce Makefile.in
SUBDIRS = @EXT_SUBDIRS@
noinst_LIBRARIES=libphpext.a
libphpext.a: @EXT_LIBS@
$(top_srcdir)/scripts/mkextlib $@ $(SUBDIRS)

569
ext/ereg/ereg.c Normal file
View file

@ -0,0 +1,569 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Jim Winstead <jimw@php.net> |
| Jaakko Hyvätti <jaakko@hyvatti.iki.fi> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <stdio.h>
#include "php.h"
#include "php3_string.h"
#include "reg.h"
unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
function_entry reg_functions[] = {
{"ereg", php3_ereg, third_argument_force_ref },
{"ereg_replace", php3_eregreplace, NULL },
{"eregi", php3_eregi, third_argument_force_ref },
{"eregi_replace", php3_eregireplace, NULL },
{"split", php3_split, NULL},
{"join", php3_implode, NULL},
{"sql_regcase", php3_sql_regcase, NULL},
{NULL, NULL, NULL}
};
php3_module_entry regexp_module_entry = {
"Regular Expressions", reg_functions, NULL, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
/* This is the maximum number of (..) constructs we'll generate from a
call to ereg() or eregi() with the optional third argument. */
#define NS 10
/*
* _php3_reg_eprint - convert error number to name
*/
static void _php3_reg_eprint(int err, regex_t *re) {
char *buf = NULL, *message = NULL;
size_t len;
size_t buf_len;
#ifdef REG_ITOA
/* get the length of the message */
buf_len = regerror(REG_ITOA | err, re, NULL, 0);
if (buf_len) {
buf = (char *)emalloc(buf_len * sizeof(char));
if (!buf) return; /* fail silently */
/* finally, get the error message */
regerror(REG_ITOA | err, re, buf, buf_len);
}
#else
buf_len = 0;
#endif
len = regerror(err, re, NULL, 0);
if (len) {
message = (char *)emalloc((buf_len + len + 2) * sizeof(char));
if (!message) {
return; /* fail silently */
}
if (buf_len) {
snprintf(message, buf_len, "%s: ", buf);
buf_len += 1; /* so pointer math below works */
}
/* drop the message into place */
regerror(err, re, message + buf_len, len);
php3_error(E_WARNING, "%s", message);
}
STR_FREE(buf);
STR_FREE(message);
}
static void _php3_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval *regex, /* Regular expression */
*findin, /* String to apply expression to */
*array = NULL; /* Optional register array */
regex_t re;
regmatch_t subs[NS];
int err, i, match_len, string_len;
int copts = 0;
off_t start, end;
char *buf = NULL;
char *string = NULL;
TLS_VARS;
if (icase)
copts |= REG_ICASE;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 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 (getParameters(ht, 3, &regex, &findin, &array) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!ParameterPassedByReference(ht, 3)) {
php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
RETURN_FALSE;
}
break;
default:
WRONG_PARAM_COUNT;
}
/* compile the regular expression from the supplied regex */
if (regex->type == IS_STRING) {
err = regcomp(&re, regex->value.str.val, REG_EXTENDED | copts);
} else {
/* we convert numbers to integers and treat them as a string */
if (regex->type == IS_DOUBLE)
convert_to_long(regex); /* get rid of decimal places */
convert_to_string(regex);
/* don't bother doing an extended regex with just a number */
err = regcomp(&re, regex->value.str.val, copts);
}
if (err) {
_php3_reg_eprint(err, &re);
RETURN_FALSE;
}
/* make a copy of the string we're looking in */
convert_to_string(findin);
string = estrndup(findin->value.str.val, findin->value.str.len);
/* actually execute the regular expression */
err = regexec(&re, string, (size_t) NS, subs, 0);
if (err && err != REG_NOMATCH) {
_php3_reg_eprint(err, &re);
regfree(&re);
RETURN_FALSE;
}
match_len = 1;
if (array && err != REG_NOMATCH) {
match_len = (int) (subs[0].rm_eo - subs[0].rm_so);
string_len = strlen(string) + 1;
buf = emalloc(string_len);
if (!buf) {
php3_error(E_WARNING, "Unable to allocate memory in _php3_ereg");
RETURN_FALSE;
}
pval_destructor(array _INLINE_TLS); /* 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);
}
}
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 */
void php3_ereg(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto int eregi(string pattern, string string [, array registers])
Case-insensitive regular expression match */
void php3_eregi(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* this is the meat and potatoes of regex replacement! */
char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended)
{
regex_t re;
regmatch_t subs[NS];
char *buf, /* buf is where we build the replaced string */
*nbuf, /* nbuf is used when we grow the buffer */
*walkbuf; /* used to walk buf when replacing backrefs */
const char *walk; /* used to walk replacement string for backrefs */
int buf_len;
int pos, tmp, string_len, new_l;
int err, copts = 0;
string_len = strlen(string);
if (!string_len)
return (char *)string;
if (icase)
copts = REG_ICASE;
if (extended)
copts |= REG_EXTENDED;
err = regcomp(&re, pattern, copts);
if (err) {
_php3_reg_eprint(err, &re);
return ((char *) -1);
}
/* start with a buffer that is twice the size of the stringo
we're doing replacements in */
buf_len = 2 * string_len + 1;
buf = emalloc(buf_len * sizeof(char));
if (!buf) {
php3_error(E_WARNING, "Unable to allocate memory in _php3_regreplace");
regfree(&re);
return ((char *) -1);
}
err = pos = 0;
buf[0] = '\0';
while (!err) {
err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0));
if (err && err != REG_NOMATCH) {
_php3_reg_eprint(err, &re);
regfree(&re);
return ((char *) -1);
}
if (!err) {
/* backref replacement is done in two passes:
1) find out how long the string will be, and allocate buf
2) copy the part before match, replacement and backrefs to buf
Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi>
*/
new_l = strlen(buf) + subs[0].rm_so; /* part before the match */
walk = replace;
while (*walk)
if ('\\' == *walk
&& '0' <= walk[1] && '9' >= walk[1]
&& subs[walk[1] - '0'].rm_so > -1
&& subs[walk[1] - '0'].rm_eo > -1) {
new_l += subs[walk[1] - '0'].rm_eo
- subs[walk[1] - '0'].rm_so;
walk += 2;
} else {
new_l++;
walk++;
}
if (new_l + 1 > buf_len) {
buf_len = 1 + buf_len + 2 * new_l;
nbuf = emalloc(buf_len);
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
tmp = strlen(buf);
/* copy the part of the string before the match */
strncat(buf, &string[pos], subs[0].rm_so);
/* copy replacement and backrefs */
walkbuf = &buf[tmp + subs[0].rm_so];
walk = replace;
while (*walk)
if ('\\' == *walk
&& '0' <= walk[1] && '9' >= walk[1]
&& subs[walk[1] - '0'].rm_so > -1
&& subs[walk[1] - '0'].rm_eo > -1) {
tmp = subs[walk[1] - '0'].rm_eo
- subs[walk[1] - '0'].rm_so;
memcpy (walkbuf,
&string[pos + subs[walk[1] - '0'].rm_so],
tmp);
walkbuf += tmp;
walk += 2;
} else
*walkbuf++ = *walk++;
*walkbuf = '\0';
/* and get ready to keep looking for replacements */
if (subs[0].rm_so == subs[0].rm_eo) {
if (subs[0].rm_so + pos >= string_len)
break;
new_l = strlen (buf) + 1;
if (new_l + 1 > buf_len) {
buf_len = 1 + buf_len + 2 * new_l;
nbuf = emalloc(buf_len * sizeof(char));
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
pos += subs[0].rm_eo + 1;
buf [new_l-1] = string [pos-1];
buf [new_l] = '\0';
} else {
pos += subs[0].rm_eo;
}
} else { /* REG_NOMATCH */
new_l = strlen(buf) + strlen(&string[pos]);
if (new_l + 1 > buf_len) {
buf_len = new_l + 1; /* now we know exactly how long it is */
nbuf = emalloc(buf_len * sizeof(char));
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
/* stick that last bit of string on our output */
strcat(buf, &string[pos]);
}
}
/* don't want to leak memory .. */
regfree(&re);
/* whew. */
return (buf);
}
static void _php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval *arg_pattern,
*arg_replace,
*arg_string;
char *pattern;
char *string;
char *replace;
char *ret;
TLS_VARS;
if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (arg_pattern->type == IS_STRING) {
if (arg_pattern->value.str.val && arg_pattern->value.str.len)
pattern = estrndup(arg_pattern->value.str.val,arg_pattern->value.str.len);
else
pattern = empty_string;
} else {
convert_to_long(arg_pattern);
pattern = emalloc(2);
pattern[0] = (char) arg_pattern->value.lval;
pattern[1] = '\0';
}
if (arg_replace->type == IS_STRING) {
if (arg_replace->value.str.val && arg_replace->value.str.len)
replace = estrndup(arg_replace->value.str.val, arg_replace->value.str.len);
else
replace = empty_string;
} else {
convert_to_long(arg_replace);
replace = emalloc(2);
replace[0] = (char) arg_replace->value.lval;
replace[1] = '\0';
}
convert_to_string(arg_string);
if (arg_string->value.str.val && arg_string->value.str.len)
string = estrndup(arg_string->value.str.val, arg_string->value.str.len);
else
string = empty_string;
/* do the actual work */
ret = _php3_regreplace(pattern, replace, string, icase, 1);
if (ret == (char *) -1) {
RETVAL_FALSE;
} else {
RETVAL_STRING(ret,1);
STR_FREE(ret);
}
STR_FREE(string);
STR_FREE(replace);
STR_FREE(pattern);
}
/* {{{ proto string ereg_replace(string pattern, string string [, array registers])
Replace regular expression */
void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto string eregi_replace(string pattern, string string [, array registers])
Case insensitive replace regular expression */
void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
= split(":", $passwd_file, 5); */
/* {{{ proto array split(string pattern, string string [, int limit])
split string into array by regular expression */
void php3_split(INTERNAL_FUNCTION_PARAMETERS)
{
pval *spliton, *str, *arg_count = NULL;
regex_t re;
regmatch_t subs[1];
char *strp, *endp;
int err, size, count;
TLS_VARS;
switch (ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &spliton, &str) == FAILURE)
WRONG_PARAM_COUNT;
count = -1;
break;
case 3:
if (getParameters(ht, 3, &spliton, &str, &arg_count) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long(arg_count);
count = arg_count->value.lval;
break;
default:
WRONG_PARAM_COUNT;
}
convert_to_string(spliton);
convert_to_string(str);
strp = str->value.str.val;
endp = str->value.str.val + strlen(str->value.str.val);
err = regcomp(&re, spliton->value.str.val, REG_EXTENDED);
if (err) {
php3_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);
php3_error(E_WARNING, "bad regular expression for split()");
_php3_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) {
php3_error(E_WARNING, "unexpected regex error (%d)", err);
regfree(&re);
_php3_hash_destroy(return_value->value.ht);
efree(return_value->value.ht);
RETURN_FALSE;
}
/* otherwise we just have one last element to add to the array */
size = endp - strp;
add_next_index_stringl(return_value, strp, size, 1);
regfree(&re);
return;
}
/* }}} */
/* {{{ proto string sql_regcase(string string)
Make regular expression for case insensitive match */
PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS)
{
pval *string;
char *tmp;
register int i;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(string);
tmp = (char *) emalloc(string->value.str.len*4+1);
for (i=0; i<string->value.str.len; i++) {
tmp[i*4] = '[';
tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]);
tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]);
tmp[i*4+3]=']';
}
tmp[string->value.str.len*4]=0;
return_value->value.str.val = tmp;
return_value->value.str.len = string->value.str.len*4;
return_value->type = IS_STRING;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

48
ext/ereg/php_ereg.h Normal file
View file

@ -0,0 +1,48 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _REG_H
#define _REG_H
extern php3_module_entry regexp_module_entry;
#define regexp_module_ptr &regexp_module_entry
extern char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended);
extern void php3_ereg(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregi(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_split(INTERNAL_FUNCTION_PARAMETERS);
extern PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _REG_H */

4
ext/gd/Makefile.am Normal file
View file

@ -0,0 +1,4 @@
## Process this file with automake to produce Makefile.in
INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend
noinst_LIBRARIES=libphpext_gd.a
libphpext_gd_a_SOURCES=gd.c gdcache.c gdttf.c

54
ext/gd/config.m4 Normal file
View file

@ -0,0 +1,54 @@
AC_MSG_CHECKING(whether to include GD support)
AC_ARG_WITH(gd,
[ --without-gd Disable GD support.
--with-gd[=DIR] Include GD support (DIR is GD's install dir).],
[
case "$withval" in
no)
AC_MSG_RESULT(no) ;;
yes)
GD_LIBS="-lgd"
AC_DEFINE(HAVE_LIBGD)
AC_MSG_RESULT(yes)
AC_CHECK_LIB(gd, gdImageString16, [ AC_DEFINE(HAVE_LIBGD13) ])
ac_cv_lib_gd_gdImageLine=yes
;;
*)
dnl A whole whack of possible places where this might be
test -f $withval/include/gd1.3/gd.h && GD_INCLUDE="-I$withval/include/gd1.3"
test -f $withval/include/gd/gd.h && GD_INCLUDE="-I$withval/include/gd"
test -f $withval/include/gd.h && GD_INCLUDE="-I$withval/include"
test -f $withval/gd1.3/gd.h && GD_INCLUDE="-I$withval/gd1.3"
test -f $withval/gd/gd.h && GD_INCLUDE="-I$withval/gd"
test -f $withval/gd.h && GD_INCLUDE="-I$withval"
test -f $withval/lib/libgd.a && GD_LIB="$withval/lib"
test -f $withval/lib/gd/libgd.a && GD_LIB="$withval/lib/gd"
test -f $withval/lib/gd1.3/libgd.a && GD_LIB="$withval/lib/gd1.3"
test -f $withval/libgd.a && GD_LIB="$withval"
test -f $withval/gd/libgd.a && GD_LIB="$withval/gd"
test -f $withval/gd1.3/libgd.a && GD_LIB="$withval/gd1.3"
if test -n "$GD_INCLUDE" && test -n "$GD_LIB" ; then
GD_LIBS="-L$GD_LIB -lgd"
AC_DEFINE(HAVE_LIBGD)
AC_MSG_RESULT(yes)
AC_CHECK_LIB(gd, gdImageString16, [ AC_DEFINE(HAVE_LIBGD13) ])
ac_cv_lib_gd_gdImageLine=yes
else
AC_MSG_RESULT(no)
fi ;;
esac
],[
AC_CHECK_LIB(gd, gdImageLine)
AC_CHECK_LIB(gd, gdImageString16, [ AC_DEFINE(HAVE_LIBGD13) ])
])
if test "$ac_cv_lib_gd_gdImageLine" = "yes"; then
if test -f /usr/pkg/include/gd/gd.h -a -z "$GD_INCLUDE" ; then
GD_INCLUDE="-I/usr/pkg/include/gd"
fi
AC_CHECK_LIB(ttf, TT_Open_Face)
PHP_EXTENSION(gd)
LIBS="$LIBS $GD_LIBS"
INCLUDE="$INCLUDE $GD_INCLUDE"
fi

View file

@ -39,7 +39,7 @@
# include "tls.h"
#endif
#include "php.h"
#include "head.h"
#include "functions/head.h"
#include <math.h>
#include "php3_gd.h"

102
ext/gd/php3_gd.h Normal file
View file

@ -0,0 +1,102 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Stig Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHP3_GD_H
#define _PHP3_GD_H
#if COMPILE_DL
#undef HAVE_LIBGD
#define HAVE_LIBGD 1
#endif
#if HAVE_LIBGD
#include <gd.h>
extern php3_module_entry gd_module_entry;
#define gd_module_ptr &gd_module_entry
/* gd.c functions */
extern void php3_info_gd(void);
extern int php3_minit_gd(INIT_FUNC_ARGS);
extern int php3_mend_gd(void);
extern int gdImageColorResolve(gdImagePtr, int, int, int);
extern void php3_imagearc(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagechar(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecharup(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorallocate(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorat(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorclosest(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolordeallocate(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorresolve(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorexact(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorset(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorstotal(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolorsforindex(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecolortransparent(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecopy(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecopyresized(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecreate(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagecreatefromgif (INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagedestroy(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefill(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefilledpolygon(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefilledrectangle(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefilltoborder(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefontwidth(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagefontheight(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagegif (INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imageinterlace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imageline(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imageloadfont(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagepolygon(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagerectangle(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagesetpixel(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagestring(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagestringup(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagesxfn(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagesyfn(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_free_gd_font(gdFontPtr);
extern void _php3_gdimagecharup(gdImagePtr, gdFontPtr, int, int, int, int);
extern void php3_imagedashedline(INTERNAL_FUNCTION_PARAMETERS);
#ifdef HAVE_LIBTTF
extern void php3_imagettfbbox(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_imagettftext(INTERNAL_FUNCTION_PARAMETERS);
#endif
#else
#define gd_module_ptr NULL
#endif
#endif /* _PHP3_GD_H */

6
ext/gd/setup.stub Normal file
View file

@ -0,0 +1,6 @@
define_option with-gd 'GD support?' yesnodir \
"yes /usr GD install" \
' Whether to include GD support. If PHP can find the GD libraries\n
on your system, it will be included automatically. You should enter\n
something here if you do not want to include GD support or if you\n
have installed GD in some unusual directory.'

11
ext/standard/Makefile.am Normal file
View file

@ -0,0 +1,11 @@
## Process this file with automake to produce Makefile.in
INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend -I@top_srcdir@/functions
noinst_LIBRARIES=libphpext_standard.a
libphpext_standard_a_SOURCES=\
base64.c basic_functions.c browscap.c datetime.c dir.c \
dns.c exec.c file.c filestat.c formatted_print.c fsock.c \
html.c image.c info.c link.c mail.c math.c md5.c microtime.c \
pack.c pageinfo.c rand.c reg.c soundex.c string.c \
syslog.c type.c uniqid.c url.c iptc.c var.c quot_print.c \
cyr_convert.c

197
ext/standard/base64.c Normal file
View file

@ -0,0 +1,197 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <string.h>
#include "php.h"
#include "base64.h"
static char base64_table[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
};
static char base64_pad = '=';
unsigned char *_php3_base64_encode(const unsigned char *string, int length, int *ret_length) {
const unsigned char *current = string;
int i = 0;
unsigned char *result = (unsigned char *)emalloc(((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
while (length > 2) { /* keep going until we have less than 24 bits */
result[i++] = base64_table[current[0] >> 2];
result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
result[i++] = base64_table[((current[1] & 0x0f) << 2) + (current[2] >> 6)];
result[i++] = base64_table[current[2] & 0x3f];
current += 3;
length -= 3; /* we just handle 3 octets of data */
}
/* now deal with the tail end of things */
if (length != 0) {
result[i++] = base64_table[current[0] >> 2];
if (length > 1) {
result[i++] = base64_table[((current[0] & 0x03) << 4) + (current[1] >> 4)];
result[i++] = base64_table[(current[1] & 0x0f) << 2];
result[i++] = base64_pad;
}
else {
result[i++] = base64_table[(current[0] & 0x03) << 4];
result[i++] = base64_pad;
result[i++] = base64_pad;
}
}
if(ret_length) {
*ret_length = i;
}
result[i] = '\0';
return result;
}
/* as above, but backwards. :) */
unsigned char *_php3_base64_decode(const unsigned char *string, int length, int *ret_length) {
const unsigned char *current = string;
int ch, i = 0, j = 0, k;
unsigned char *result = (unsigned char *)emalloc((length / 4 * 3 + 1) * sizeof(char));
if (result == NULL) {
return NULL;
}
/* run through the whole string, converting as we go */
while ((ch = *current++) != '\0') {
if (ch == base64_pad) break;
ch = (int)strchr(base64_table, ch);
if (ch == 0) {
efree(result);
return NULL;
}
ch -= (int)base64_table;
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 */
void php3_base64_encode(INTERNAL_FUNCTION_PARAMETERS) {
pval *string;
unsigned char *result;
int ret_length;
TLS_VARS;
if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&string) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(string);
result = _php3_base64_encode(string->value.str.val, string->value.str.len, &ret_length);
if (result != NULL) {
return_value->value.str.val = result;
return_value->value.str.len = ret_length;
return_value->type = IS_STRING;
} else {
RETURN_FALSE;
}
}
/* }}} */
/* {{{ proto string base64_decode(string str)
Decodes string using MIME base64 algorithm */
void php3_base64_decode(INTERNAL_FUNCTION_PARAMETERS) {
pval *string;
unsigned char *result;
int ret_length;
TLS_VARS;
if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&string) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(string);
result = _php3_base64_decode(string->value.str.val, string->value.str.len, &ret_length);
if (result != NULL) {
return_value->value.str.val = result;
return_value->value.str.len = ret_length;
return_value->type = IS_STRING;
} else {
RETURN_FALSE;
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

47
ext/standard/base64.h Normal file
View file

@ -0,0 +1,47 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _BASE64_h
#define _BASE64_h
extern void php3_base64_decode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_base64_encode(INTERNAL_FUNCTION_PARAMETERS);
extern unsigned char *_php3_base64_encode(const unsigned char *, int, int *);
extern unsigned char *_php3_base64_decode(const unsigned char *, int, int *);
#endif /* _BASE64_h */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,130 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _BASIC_FUNCTIONS_H
#define _BASIC_FUNCTIONS_H
#include "zend_highlight.h"
extern php3_module_entry basic_functions_module;
#define basic_functions_module_ptr &basic_functions_module
extern int php3_minit_basic(INIT_FUNC_ARGS);
extern int php3_mshutdown_basic(SHUTDOWN_FUNC_ARGS);
extern int php3_rinit_basic(INIT_FUNC_ARGS);
extern int php3_rshutdown_basic(SHUTDOWN_FUNC_ARGS);
extern void int_value(INTERNAL_FUNCTION_PARAMETERS);
extern void double_value(INTERNAL_FUNCTION_PARAMETERS);
extern void string_value(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_toggle_short_open_tag(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_sleep(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_usleep(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_key_sort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_asort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_arsort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_sort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rsort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_user_sort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_auser_sort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_user_key_sort(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_array_walk(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_count(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_flush(INTERNAL_FUNCTION_PARAMETERS);
extern void array_end(INTERNAL_FUNCTION_PARAMETERS);
extern void array_prev(INTERNAL_FUNCTION_PARAMETERS);
extern void array_next(INTERNAL_FUNCTION_PARAMETERS);
extern void array_each(INTERNAL_FUNCTION_PARAMETERS);
extern void array_reset(INTERNAL_FUNCTION_PARAMETERS);
extern void array_current(INTERNAL_FUNCTION_PARAMETERS);
extern void array_current_key(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_gettype(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_settype(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_min(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_max(INTERNAL_FUNCTION_PARAMETERS);
/* system functions */
extern void php3_getenv(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_putenv(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_error_reporting(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_get_current_user(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_time_limit(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_get_cfg_var(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_magic_quotes_runtime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_get_magic_quotes_runtime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_get_magic_quotes_gpc(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_is_type(INTERNAL_FUNCTION_PARAMETERS, int type);
extern void php3_is_long(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_is_double(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_is_string(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_is_array(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_is_object(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_leak(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_error_log(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_call_user_func(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_call_user_method(INTERNAL_FUNCTION_PARAMETERS);
PHP_FUNCTION(register_shutdown_function);
PHP_FUNCTION(highlight_file);
PHP_FUNCTION(highlight_string);
void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini);
PHP_FUNCTION(ob_start);
PHP_FUNCTION(ob_end_flush);
PHP_FUNCTION(ob_end_clean);
PHP_FUNCTION(ob_get_contents);
PHP_FUNCTION(ini_get);
PHP_FUNCTION(ini_alter);
PHP_FUNCTION(ini_restore);
PHP_FUNCTION(print_r);
PHP_FUNCTION(define);
PHP_FUNCTION(defined);
#if HAVE_PUTENV
typedef struct {
char *putenv_string;
char *previous_value;
char *key;
int key_len;
} putenv_entry;
#endif
#endif /* _BASIC_FUNCTIONS_H */

137
ext/standard/browscap.c Normal file
View file

@ -0,0 +1,137 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "php3_browscap.h"
#include "php_ini.h"
#include "zend_globals.h"
#ifndef THREAD_SAFE
HashTable browser_hash;
static char *lookup_browser_name;
static pval *found_browser_entry;
#endif
function_entry browscap_functions[] = {
{"get_browser", php3_get_browser, NULL},
{NULL, NULL, NULL}
};
php3_module_entry browscap_module_entry = {
"browscap", browscap_functions, php3_minit_browscap, php3_mshutdown_browscap, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
static int browser_reg_compare(pval *browser)
{
pval *browser_name;
regex_t r;
TLS_VARS;
if (GLOBAL(found_browser_entry)) { /* already found */
return 0;
}
_php3_hash_find(browser->value.ht,"browser_name_pattern",sizeof("browser_name_pattern"),(void **) &browser_name);
if (!strchr(browser_name->value.str.val,'*')) {
return 0;
}
if (regcomp(&r,browser_name->value.str.val,REG_NOSUB)!=0) {
return 0;
}
if (regexec(&r,GLOBAL(lookup_browser_name),0,NULL,0)==0) {
GLOBAL(found_browser_entry) = browser;
}
regfree(&r);
return 0;
}
void php3_get_browser(INTERNAL_FUNCTION_PARAMETERS)
{
pval *agent_name,*agent,tmp;
ELS_FETCH();
if (!INI_STR("browscap")) {
RETURN_FALSE;
}
switch(ARG_COUNT(ht)) {
case 0:
if (_php3_hash_find(&EG(symbol_table), "HTTP_USER_AGENT", sizeof("HTTP_USER_AGENT"), (void **) &agent_name)==FAILURE) {
agent_name = &tmp;
var_reset(agent_name);
}
break;
case 1:
if (getParameters(ht, 1, &agent_name)==FAILURE) {
RETURN_FALSE;
}
break;
default:
WRONG_PARAM_COUNT;
break;
}
convert_to_string(agent_name);
if (_php3_hash_find(&GLOBAL(browser_hash), agent_name->value.str.val, agent_name->value.str.len+1, (void **) &agent)==FAILURE) {
GLOBAL(lookup_browser_name) = agent_name->value.str.val;
GLOBAL(found_browser_entry) = NULL;
_php3_hash_apply(&GLOBAL(browser_hash),(int (*)(void *)) browser_reg_compare);
if (GLOBAL(found_browser_entry)) {
agent = GLOBAL(found_browser_entry);
} else if (_php3_hash_find(&GLOBAL(browser_hash), "Default Browser", sizeof("Default Browser"), (void **) &agent)==FAILURE) {
RETURN_FALSE;
}
}
*return_value = *agent;
return_value->type = IS_OBJECT;
pval_copy_constructor(return_value);
return_value->value.ht->pDestructor = PVAL_DESTRUCTOR;
while (_php3_hash_find(agent->value.ht, "parent", sizeof("parent"), (void **) &agent_name)==SUCCESS) {
if (_php3_hash_find(&GLOBAL(browser_hash), agent_name->value.str.val, agent_name->value.str.len+1, (void **) &agent)==FAILURE) {
break;
}
_php3_hash_merge(return_value->value.ht,agent->value.ht,(void (*)(void *pData)) pval_copy_constructor, (void *) &tmp, sizeof(pval));
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

3
ext/standard/config.m4 Normal file
View file

@ -0,0 +1,3 @@
dnl $Id$ -*- sh -*-
PHP_EXTENSION(standard)

301
ext/standard/cyr_convert.c Normal file
View file

@ -0,0 +1,301 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Kirill Maximov (kir@rus.net |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include "php.h"
#include "cyr_convert.h"
#include <stdio.h>
/*****************************************************************************
* This is codetables for different Cyrillic charsets (relative to koi8-r).
* Each table contains data for 128-255 symbols from ASCII table.
* First 256 symbols are for conversion from koi8-r to corresponding charset,
* second 256 symbols are for reverse conversion, from charset to koi8-r.
*
* Here we have the following tables:
* _cyr_win1251 - for windows-1251 charset
* _cyr_iso88595 - for iso8859-5 charset
* _cyr_cp866 - for x-cp866 charset
* _cyr_mac - for x-mac-cyrillic charset
*
*****************************************************************************/
typedef unsigned char _cyr_charset_table[512];
const static _cyr_charset_table _cyr_win1251 = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,46,
46,46,46,46,46,46,46,46,179,46,32,46,46,46,46,32,
46,46,46,46,46,46,46,46,163,46,32,46,46,46,46,32,
225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,184,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,168,32,32,32,32,32,32,32,32,32,32,32,32,
254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
207,223,208,209,210,211,198,194,220,219,199,216,221,217,215,218,
},
_cyr_cp866 = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
35,35,35,124,124,124,124,43,43,124,124,43,43,43,43,43,
43,45,45,124,45,43,124,124,43,43,45,45,124,45,43,45,
45,45,45,43,43,43,43,43,43,43,43,35,35,124,124,35,
210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
179,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,241,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,240,32,32,32,32,32,32,32,32,32,32,32,32,
238,160,161,230,164,165,228,163,229,168,169,170,171,172,173,174,
175,239,224,225,226,227,166,162,236,235,167,232,237,233,231,234,
158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154,
},
_cyr_iso88595 = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,179,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
32,163,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,241,32,32,32,32,32,32,32,32,32,32,32,32,
32,32,32,161,32,32,32,32,32,32,32,32,32,32,32,32,
238,208,209,230,212,213,228,211,229,216,217,218,219,220,221,222,
223,239,224,225,226,227,214,210,236,235,215,232,237,233,231,234,
206,176,177,198,180,181,196,179,197,184,185,186,187,188,189,190,
191,207,192,193,194,195,182,178,204,203,183,200,205,201,199,202,
},
_cyr_mac = {
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
144,145,146,147,148,149,150,151,152,153,154,155,156,179,163,209,
193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,255,
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
160,161,162,222,164,165,166,167,168,169,170,171,172,173,174,175,
176,177,178,221,180,181,182,183,184,185,186,187,188,189,190,191,
254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
239,223,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
158,128,129,150,132,133,148,131,149,136,137,138,139,140,141,142,
143,159,144,145,146,147,134,130,156,155,135,152,157,153,151,154,
};
/*****************************************************************************
* This is the function that performs real in-place conversion of the string
* between charsets.
* Parameters:
* str - string to be converted
* from,to - one-symbol label of source and destination charset
* The following symbols are used as labels:
* k - koi8-r
* w - windows-1251
* i - iso8859-5
* a - x-cp866
* d - x-cp866
* m - x-mac-cyrillic
*****************************************************************************/
static char * _php3_convert_cyr_string(unsigned char *str, char from, char to)
{
const unsigned char *from_table, *to_table;
unsigned char tmp;
int i;
from_table = NULL;
to_table = NULL;
switch (toupper(from))
{
case 'W':
from_table = _cyr_win1251;
break;
case 'A':
case 'D':
from_table = _cyr_cp866;
break;
case 'I':
from_table = _cyr_iso88595;
break;
case 'M':
from_table = _cyr_mac;
break;
case 'K':
break;
default:
php3_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:
php3_error(E_WARNING, "Unknown destination charset: %c", to);
break;
}
if (!str)
return (char *)str;
for( i = 0; str[i]; i++)
{
tmp = (from_table == NULL)? str[i] : from_table[ str[i] ];
str[i] = (to_table == NULL) ? tmp : to_table[tmp + 256];
}
return (char *)str;
}
/* {{{ proto string convert_cyr_string(string str, string from, string to)
Convert from one Cyrillic character set to another */
void php3_convert_cyr_string(INTERNAL_FUNCTION_PARAMETERS)
{
pval *str_arg, *fr_cs, *to_cs;
unsigned char *str;
if (ARG_COUNT(ht) != 3 || getParameters(ht,3,&str_arg, &fr_cs, &to_cs)==FAILURE)
{
WRONG_PARAM_COUNT;
}
convert_to_string(str_arg);
convert_to_string(fr_cs);
convert_to_string(to_cs);
str = (unsigned char*) str_arg->value.str.val;
_php3_convert_cyr_string(str, fr_cs->value.str.val[0], to_cs->value.str.val[0]);
RETVAL_STRING((char *)str, 1)
}
/* }}} */

View file

@ -0,0 +1,40 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Kirill Maximov (kir@rus.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _CYR_CONVERT_H
#define _CYR_CONVERT_H
extern void php3_convert_cyr_string(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _CYR_CONVERT_H */

510
ext/standard/datetime.c Normal file
View file

@ -0,0 +1,510 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
| Rasmus Lerdorf <rasmus@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "zend_operators.h"
#include "datetime.h"
#include "snprintf.h"
#include "php_globals.h"
#include <time.h>
#include <stdio.h>
char *mon_full_names[] =
{
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
char *mon_short_names[] =
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
char *day_full_names[] =
{
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
char *day_short_names[] =
{
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
#ifndef HAVE_TM_ZONE
#ifndef _TIMEZONE
extern time_t timezone;
#endif
#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}
};
void php3_time(INTERNAL_FUNCTION_PARAMETERS)
{
return_value->value.lval = (long) time(NULL);
return_value->type = IS_LONG;
}
void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm)
{
pval *arguments[6];
struct tm ta, *tn;
time_t t;
int i, gmadjust=0,arg_count = ARG_COUNT(ht);
if (arg_count > 6 || getParametersArray(ht, arg_count, arguments) == FAILURE) {
WRONG_PARAM_COUNT;
}
/* convert supplied arguments to longs */
for (i = 0; i < arg_count; i++) {
convert_to_long(arguments[i]);
}
t=time(NULL);
if (gm) {
tn = gmtime(&t);
#if HAVE_TZSET
tzset();
#if HAVE_TM_ZONE
gmadjust=(tn->tm_gmtoff)/3600;
#else
gmadjust=timezone/3600;
#endif
#endif
} else {
tn = localtime(&t);
}
memcpy(&ta,tn,sizeof(struct tm));
ta.tm_isdst = -1;
switch(arg_count) {
case 6:
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 - gmadjust;
case 0:
break;
}
return_value->value.lval = mktime(&ta);
return_value->type = IS_LONG;
}
void php3_mktime(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
void php3_gmmktime(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
static void
_php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
{
pval *format, *timestamp;
time_t the_time;
struct tm *ta;
int i, size = 0, length, h;
char tmp_buff[16];
TLS_VARS;
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &format) == FAILURE) {
WRONG_PARAM_COUNT;
}
the_time = time(NULL);
break;
case 2:
if (getParameters(ht, 2, &format, &timestamp) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(timestamp);
the_time = timestamp->value.lval;
break;
default:
WRONG_PARAM_COUNT;
}
convert_to_string(format);
if (gm) {
ta = gmtime(&the_time);
} else {
ta = localtime(&the_time);
}
if (!ta) { /* that really shouldn't happen... */
php3_error(E_WARNING, "unexpected error in date()");
RETURN_FALSE;
}
for (i = 0; i < format->value.str.len; i++) {
switch (format->value.str.val[i]) {
case 'U': /* seconds since the epoch */
size += 10;
break;
case 'F': /* month, textual, full */
case 'l': /* day (of the week), textual */
size += 9;
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 */
size += 3;
break;
case 'y': /* year, numeric, 2 digits */
case 'm': /* month, numeric */
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 '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) */
size += 2;
break;
case '\\':
if(i < format->value.str.len-1) {
i++;
}
case 'w': /* day of the week, numeric */
default:
size++;
break;
}
}
return_value->value.str.val = (char *) emalloc(size + 1);
return_value->value.str.val[0] = '\0';
for (i = 0; i < format->value.str.len; i++) {
switch (format->value.str.val[i]) {
case '\\':
if(i < format->value.str.len-1) {
char ch[2];
ch[0]=format->value.str.val[i+1];
ch[1]='\0';
strcat(return_value->value.str.val, ch);
i++;
}
break;
case 'U': /* seconds since the epoch */
sprintf(tmp_buff, "%ld", (long)the_time); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
case 'F': /* month, textual, full */
strcat(return_value->value.str.val, mon_full_names[ta->tm_mon]);
break;
case 'l': /* day (of the week), textual, full */
strcat(return_value->value.str.val, day_full_names[ta->tm_wday]);
break;
case 'Y': /* year, numeric, 4 digits */
sprintf(tmp_buff, "%d", ta->tm_year + 1900); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
case 'M': /* month, textual, 3 letters */
strcat(return_value->value.str.val, mon_short_names[ta->tm_mon]);
break;
case 'D': /* day (of the week), textual, 3 letters */
strcat(return_value->value.str.val, day_short_names[ta->tm_wday]);
break;
case 'z': /* day (of the year) */
sprintf(tmp_buff, "%d", ta->tm_yday); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
case 'y': /* year, numeric, 2 digits */
sprintf(tmp_buff, "%02d", ((ta->tm_year)%100)); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
case 'm': /* month, numeric */
sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
case '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 '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 'w': /* day of the week, numeric EXTENSION */
sprintf(tmp_buff, "%01d", ta->tm_wday); /* 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;
}
void php3_date(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
void php3_gmdate(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
void php3_getdate(INTERNAL_FUNCTION_PARAMETERS)
{
pval *timestamp_arg;
struct tm *ta;
time_t timestamp;
if (ARG_COUNT(ht) == 0) {
timestamp = time(NULL);
} else if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &timestamp_arg) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_long(timestamp_arg);
timestamp = timestamp_arg->value.lval;
}
ta = localtime(&timestamp);
if (!ta) {
php3_error(E_WARNING, "Cannot perform date calculation");
return;
}
if (array_init(return_value) == FAILURE) {
php3_error(E_ERROR, "Unable to initialize array");
return;
}
add_assoc_long(return_value, "seconds", ta->tm_sec);
add_assoc_long(return_value, "minutes", ta->tm_min);
add_assoc_long(return_value, "hours", ta->tm_hour);
add_assoc_long(return_value, "mday", ta->tm_mday);
add_assoc_long(return_value, "wday", ta->tm_wday);
add_assoc_long(return_value, "mon", ta->tm_mon + 1);
add_assoc_long(return_value, "year", ta->tm_year + 1900);
add_assoc_long(return_value, "yday", ta->tm_yday);
add_assoc_string(return_value, "weekday", day_full_names[ta->tm_wday], 1);
add_assoc_string(return_value, "month", mon_full_names[ta->tm_mon], 1);
add_index_long(return_value, 0, timestamp);
}
/* Return date string in standard format for http headers */
char *php3_std_date(time_t t)
{
struct tm *tm1;
char *str;
PLS_FETCH();
tm1 = gmtime(&t);
str = emalloc(81);
if (PG(y2k_compliance)) {
snprintf(str, 80, "%s, %02d-%s-%04d %02d:%02d:%02d GMT",
day_full_names[tm1->tm_wday],
tm1->tm_mday,
mon_short_names[tm1->tm_mon],
tm1->tm_year+1900,
tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
} else {
snprintf(str, 80, "%s, %02d-%s-%02d %02d:%02d:%02d GMT",
day_full_names[tm1->tm_wday],
tm1->tm_mday,
mon_short_names[tm1->tm_mon],
((tm1->tm_year)%100),
tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
}
str[79]=0;
return (str);
}
/*
* CheckDate(month, day, year);
* returns True(1) if it is valid date
*
*/
#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
void php3_checkdate(INTERNAL_FUNCTION_PARAMETERS)
{
pval *month, *day, *year;
int m, d, y;
TLS_VARS;
if (ARG_COUNT(ht) != 3 ||
getParameters(ht, 3, &month, &day, &year) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(day);
convert_to_long(month);
convert_to_long(year);
y = year->value.lval;
m = month->value.lval;
d = day->value.lval;
if (y < 100)
y += 1900;
if (y < 0 || y > 32767) {
RETURN_FALSE;
}
if (m < 1 || m > 12) {
RETURN_FALSE;
}
if (d < 1 || d > phpday_tab[isleap(y)][m - 1]) {
RETURN_FALSE;
}
RETURN_TRUE; /* True : This month,day,year arguments are valid */
}
#if HAVE_STRFTIME
void php3_strftime(INTERNAL_FUNCTION_PARAMETERS)
{
pval *format_arg, *timestamp_arg;
char *format,*buf;
time_t timestamp;
struct tm *ta;
size_t buf_len=64, real_len;
switch (ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &format_arg)==FAILURE) {
RETURN_FALSE;
}
time(&timestamp);
break;
case 2:
if (getParameters(ht, 2, &format_arg, &timestamp_arg)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(timestamp_arg);
timestamp = timestamp_arg->value.lval;
break;
default:
WRONG_PARAM_COUNT;
break;
}
convert_to_string(format_arg);
if (format_arg->value.str.len==0) {
RETURN_FALSE;
}
format = format_arg->value.str.val;
ta = localtime(&timestamp);
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);
}
return_value->value.str.val = (char *) erealloc(buf,real_len+1);
return_value->value.str.len = real_len;
return_value->type = IS_STRING;
}
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

51
ext/standard/datetime.h Normal file
View file

@ -0,0 +1,51 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@zend.com> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _DATETIME_H
#define _DATETIME_H
extern void php3_time(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_mktime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_gmmktime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_date(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_gmdate(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getdate(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_checkdate(INTERNAL_FUNCTION_PARAMETERS);
#if HAVE_STRFTIME
extern void php3_strftime(INTERNAL_FUNCTION_PARAMETERS);
#endif
extern char *php3_std_date(time_t t);
void _php3_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm);
#endif /* _DATETIME_H */

287
ext/standard/dir.c Normal file
View file

@ -0,0 +1,287 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "fopen-wrappers.h"
#include "php3_dir.h"
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <errno.h>
#if MSVC5
#if !(APACHE)
#define NEEDRDH 1
#endif
#include "win32/readdir.h"
#endif
#ifndef THREAD_SAFE
static int dirp_id = 0;
static int le_dirp;
#endif
function_entry php3_dir_functions[] = {
{"opendir", php3_opendir, NULL},
{"closedir", php3_closedir, NULL},
{"chdir", php3_chdir, NULL},
{"rewinddir", php3_rewinddir, NULL},
{"readdir", php3_readdir, NULL},
{"dir", php3_getdir, NULL},
{NULL, NULL, NULL}
};
php3_module_entry php3_dir_module_entry = {
"PHP_dir", php3_dir_functions, php3_minit_dir, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
int php3_minit_dir(INIT_FUNC_ARGS)
{
TLS_VARS;
GLOBAL(le_dirp) = register_list_destructors(closedir,NULL);
return SUCCESS;
}
/* {{{ proto int opendir(string path)
Open a directory and return a dir_handle */
void php3_opendir(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
DIR *dirp;
int ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
/* Check open_basedir */
if (_php3_check_open_basedir(arg->value.str.val)) RETURN_FALSE;
dirp = opendir(arg->value.str.val);
if (!dirp) {
php3_error(E_WARNING, "OpenDir: %s (errno %d)", strerror(errno),errno);
RETURN_FALSE;
}
ret = php3_list_insert(dirp, GLOBAL(le_dirp));
GLOBAL(dirp_id) = ret;
RETURN_LONG(ret);
}
/* }}} */
/* {{{ proto void closedir([int dir_handle])
Close directory connection identified by the dir_handle */
void php3_closedir(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp;
int id_to_find;
DIR *dirp;
int dirp_type;
TLS_VARS;
if (ARG_COUNT(ht) == 0) {
if (getThis(&id) == SUCCESS) {
if (_php3_hash_find(id->value.ht, "handle", sizeof("handle"), (void **)&tmp) == FAILURE) {
php3_error(E_WARNING, "unable to find my handle property");
RETURN_FALSE;
}
id_to_find = tmp->value.lval;
} else {
id_to_find = GLOBAL(dirp_id);
}
} else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_long(id);
id_to_find = id->value.lval;
}
dirp = (DIR *)php3_list_find(id_to_find, &dirp_type);
if (!dirp || dirp_type != GLOBAL(le_dirp)) {
php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find);
RETURN_FALSE;
}
php3_list_delete(id_to_find);
}
/* }}} */
/* {{{ proto int chdir(string directory)
Change the current directory */
void php3_chdir(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
int ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
ret = chdir(arg->value.str.val);
if (ret < 0) {
php3_error(E_WARNING, "ChDir: %s (errno %d)", strerror(errno), errno);
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto void rewinddir([int dir_handle])
Rewind dir_handle back to the start */
void php3_rewinddir(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp;
int id_to_find;
DIR *dirp;
int dirp_type;
TLS_VARS;
if (ARG_COUNT(ht) == 0) {
if (getThis(&id) == SUCCESS) {
if (_php3_hash_find(id->value.ht, "handle", sizeof("handle"), (void **)&tmp) == FAILURE) {
php3_error(E_WARNING, "unable to find my handle property");
RETURN_FALSE;
}
id_to_find = tmp->value.lval;
} else {
id_to_find = GLOBAL(dirp_id);
}
} else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_long(id);
id_to_find = id->value.lval;
}
dirp = (DIR *)php3_list_find(id_to_find, &dirp_type);
if (!dirp || dirp_type != GLOBAL(le_dirp)) {
php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find);
RETURN_FALSE;
}
rewinddir(dirp);
}
/* }}} */
/* {{{ proto string readdir([int dir_handle])
Read directory entry from dir_handle */
void php3_readdir(INTERNAL_FUNCTION_PARAMETERS)
{
pval *id, *tmp;
int id_to_find;
DIR *dirp;
int dirp_type;
struct dirent *direntp;
TLS_VARS;
if (ARG_COUNT(ht) == 0) {
if (getThis(&id) == SUCCESS) {
if (_php3_hash_find(id->value.ht, "handle", sizeof("handle"), (void **)&tmp) == FAILURE) {
php3_error(E_WARNING, "unable to find my handle property");
RETURN_FALSE;
}
id_to_find = tmp->value.lval;
} else {
id_to_find = GLOBAL(dirp_id);
}
} else if ((ARG_COUNT(ht) != 1) || getParameters(ht, 1, &id) == FAILURE) {
WRONG_PARAM_COUNT;
} else {
convert_to_long(id);
id_to_find = id->value.lval;
}
dirp = (DIR *)php3_list_find(id_to_find, &dirp_type);
if (!dirp || dirp_type != GLOBAL(le_dirp)) {
php3_error(E_WARNING, "unable to find identifier (%d)", id_to_find);
RETURN_FALSE;
}
direntp = readdir(dirp);
if (direntp) {
RETURN_STRINGL(direntp->d_name, strlen(direntp->d_name), 1);
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto class dir(string directory)
Directory class with properties, handle and class and methods read, rewind and close */
void php3_getdir(INTERNAL_FUNCTION_PARAMETERS) {
pval *arg;
DIR *dirp;
int ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
/* Check open_basedir */
if (_php3_check_open_basedir(arg->value.str.val)) RETURN_FALSE;
dirp = opendir(arg->value.str.val);
if (!dirp) {
php3_error(E_WARNING, "OpenDir: %s (errno %d)", strerror(errno), errno);
RETURN_FALSE;
}
ret = php3_list_insert(dirp, GLOBAL(le_dirp));
GLOBAL(dirp_id) = ret;
/* construct an object with some methods */
object_init(return_value);
add_property_long(return_value, "handle", ret);
add_property_stringl(return_value, "path", arg->value.str.val, arg->value.str.len, 1);
add_method(return_value, "read", php3_readdir);
add_method(return_value, "rewind", php3_rewinddir);
add_method(return_value, "close", php3_closedir);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

343
ext/standard/dns.c Normal file
View file

@ -0,0 +1,343 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if WIN32|WINNT
#if HAVE_BINDLIB
#ifndef WINNT
#define WINNT 1
#endif
/* located in www.php.net/extra/bindlib.zip */
#include "arpa/inet.h"
#include "netdb.h"
#include "arpa/nameser.h"
#include "resolv.h"
#endif
#include <winsock.h>
#else
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef _OSD_POSIX
#undef STATUS
#undef T_UNSPEC
#endif
#include <arpa/nameser.h>
#include <resolv.h>
#endif
#include "dns.h"
char *_php3_gethostbyaddr(char *ip);
char *_php3_gethostbyname(char *name);
/* {{{ proto string gethostbyaddr(string ip_address)
Get the Internet host name corresponding to a given IP address */
void php3_gethostbyaddr(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
return_value->value.str.val = _php3_gethostbyaddr(arg->value.str.val);
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->type = IS_STRING;
}
/* }}} */
char *_php3_gethostbyaddr(char *ip)
{
unsigned long addr;
struct hostent *hp;
if ((int) (addr = inet_addr(ip)) == -1) {
#if DEBUG
php3_error(E_WARNING, "address not in a.b.c.d form");
#endif
return estrdup(ip);
}
hp = gethostbyaddr((char *) &addr, sizeof(addr), AF_INET);
if (!hp) {
#if DEBUG
php3_error(E_WARNING, "Unable to resolve %s\n", ip);
#endif
return estrdup(ip);
}
return estrdup(hp->h_name);
}
/* {{{ proto string gethostbyname(string hostname)
Get the IP address corresponding to a given Internet host name */
void php3_gethostbyname(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
return_value->value.str.val = _php3_gethostbyname(arg->value.str.val);
return_value->value.str.len = strlen(return_value->value.str.val);
return_value->type = IS_STRING;
}
/* }}} */
/* {{{ proto array gethostbynamel(string hostname)
Return a list of IP addresses that a given hostname resolves to. */
void php3_gethostbynamel(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
struct hostent *hp;
struct in_addr in;
int i;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
hp = gethostbyname(arg->value.str.val);
if (hp == NULL || hp->h_addr_list == NULL) {
#if DEBUG
php3_error(E_WARNING, "Unable to resolve %s\n", arg->value.str.val);
#endif
return;
}
for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) {
memcpy(&in.s_addr, hp->h_addr_list[i], sizeof(in.s_addr));
add_next_index_string(return_value, inet_ntoa(in), 1);
}
return;
}
/* }}} */
char *_php3_gethostbyname(char *name)
{
struct hostent *hp;
struct in_addr in;
hp = gethostbyname(name);
if (!hp || !hp->h_addr_list) {
#if DEBUG
php3_error(E_WARNING, "Unable to resolve %s\n", name);
#endif
return estrdup(name);
}
memcpy(&in.s_addr, *(hp->h_addr_list), sizeof(in.s_addr));
return estrdup(inet_ntoa(in));
}
#if !(WIN32|WINNT)||HAVE_BINDLIB
/* {{{ proto int checkdnsrr(string host [, string type])
Check DNS records corresponding to a given Internet host name or IP address */
void php3_checkdnsrr(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1,*arg2;
int type,i;
#ifndef MAXPACKET
#define MAXPACKET 8192 /* max packet size used internally by BIND */
#endif
u_char ans[MAXPACKET];
TLS_VARS;
switch (ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
type = T_MX;
convert_to_string(arg1);
break;
case 2:
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg1);
convert_to_string(arg2);
if ( !strcasecmp("A",arg2->value.str.val) ) type = T_A;
else if ( !strcasecmp("NS",arg2->value.str.val) ) type = T_NS;
else if ( !strcasecmp("MX",arg2->value.str.val) ) type = T_MX;
else if ( !strcasecmp("PTR",arg2->value.str.val) ) type = T_PTR;
else if ( !strcasecmp("ANY",arg2->value.str.val) ) type = T_ANY;
else if ( !strcasecmp("SOA",arg2->value.str.val) ) type = T_SOA;
else if ( !strcasecmp("CNAME",arg2->value.str.val) ) type = T_CNAME;
else {
php3_error(E_WARNING,"Type '%s' not supported",arg2->value.str.val);
RETURN_FALSE;
}
break;
default:
WRONG_PARAM_COUNT;
}
i = res_search(arg1->value.str.val,C_IN,type,ans,sizeof(ans));
if ( i < 0 ) {
RETURN_FALSE;
}
RETURN_TRUE;
}
/* }}} */
#ifndef HFIXEDSZ
#define HFIXEDSZ 12 /* fixed data in header <arpa/nameser.h> */
#endif /* HFIXEDSZ */
#ifndef QFIXEDSZ
#define QFIXEDSZ 4 /* fixed data in query <arpa/nameser.h> */
#endif /* QFIXEDSZ */
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif /* MAXHOSTNAMELEN */
/* {{{ proto int getmxrr(string hostname, array mxhosts [, array weight])
Get MX records corresponding to a given Internet host name */
void php3_getmxrr(INTERNAL_FUNCTION_PARAMETERS)
{
pval *host, *mx_list, *weight_list;
pval tmp1,tmp2;
int need_weight = 0;
int count,qdc;
u_short type,weight;
u_char ans[MAXPACKET];
char buf[MAXHOSTNAMELEN];
HEADER *hp;
u_char *cp,*end;
int i;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &host, &mx_list) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!ParameterPassedByReference(ht, 2)) {
php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
RETURN_FALSE;
}
break;
case 3:
if (getParameters(ht, 3, &host, &mx_list, &weight_list) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!ParameterPassedByReference(ht, 2) || !ParameterPassedByReference(ht, 3)) {
php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
RETURN_FALSE;
}
need_weight = 1;
pval_destructor(weight_list _INLINE_TLS); /* 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 _INLINE_TLS); /* start with clean array */
if ( array_init(mx_list) == FAILURE ) {
RETURN_FALSE;
}
/* Go! */
i = res_search(host->value.str.val,C_IN,T_MX,(u_char *)&ans,sizeof(ans));
if ( i < 0 ) {
RETURN_FALSE;
}
if ( i > sizeof(ans) ) i = sizeof(ans);
hp = (HEADER *)&ans;
cp = (u_char *)&ans + HFIXEDSZ;
end = (u_char *)&ans +i;
for ( qdc = ntohs((unsigned short)hp->qdcount); qdc--; cp += i + QFIXEDSZ) {
if ( (i = dn_skipname(cp,end)) < 0 ) {
RETURN_FALSE;
}
}
count = ntohs((unsigned short)hp->ancount);
while ( --count >= 0 && cp < end ) {
if ( (i = dn_skipname(cp,end)) < 0 ) {
RETURN_FALSE;
}
cp += i;
GETSHORT(type,cp);
cp += INT16SZ + INT32SZ;
GETSHORT(i,cp);
if ( type != T_MX ) {
cp += i;
continue;
}
GETSHORT(weight,cp);
if ( (i = dn_expand(ans,end,cp,buf,sizeof(buf)-1)) < 0 ) {
RETURN_FALSE;
}
cp += i;
tmp1.value.str.len = strlen(buf);
tmp1.value.str.val = estrndup(buf,tmp1.value.str.len);
tmp1.type = IS_STRING;
_php3_hash_next_index_insert(mx_list->value.ht, (void *)&tmp1, sizeof(pval), NULL);
if ( need_weight ) {
tmp2.value.lval = (long)weight;
tmp2.type = IS_LONG;
_php3_hash_next_index_insert(weight_list->value.ht, (void *)&tmp2, sizeof(pval), NULL);
}
}
RETURN_TRUE;
}
/* }}} */
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

53
ext/standard/dns.h Normal file
View file

@ -0,0 +1,53 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _DNS_H
#define _DNS_H
extern void php3_gethostbyaddr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_gethostbyname(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_gethostbynamel(INTERNAL_FUNCTION_PARAMETERS);
#if !(WIN32|WINNT)||(HAVE_BINDLIB)
extern void php3_checkdnsrr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getmxrr(INTERNAL_FUNCTION_PARAMETERS);
#endif
#ifndef INT16SZ
#define INT16SZ 2
#endif
#ifndef INT32SZ
#define INT32SZ 4
#endif
#endif /* _DNS_H */

388
ext/standard/exec.c Normal file
View file

@ -0,0 +1,388 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Rasmus Lerdorf |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <stdio.h>
#include "php.h"
#include <ctype.h>
#include "php3_string.h"
#include "safe_mode.h"
#include "head.h"
#include "exec.h"
#include "php_globals.h"
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
/*
* If type==0, only last line of output is returned (exec)
* If type==1, all lines will be printed and last lined returned (system)
* If type==2, all lines will be saved to given array (exec with &$array)
* If type==3, output will be printed binary, no lines will be saved or returned (passthru)
*
*/
static int _Exec(int type, char *cmd, pval *array, pval *return_value)
{
FILE *fp;
char buf[EXEC_INPUT_BUF], *tmp=NULL;
int t, l, ret, output=1;
int overflow_limit, lcmd, ldir;
char *b, *c, *d=NULL;
PLS_FETCH();
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, "..")) {
php3_error(E_WARNING, "No '..' components allowed in path");
return -1;
}
d = emalloc(l);
strcpy(d, PG(safe_mode_exec_dir));
overflow_limit -= ldir;
b = strrchr(cmd, '/');
if (b) {
strcat(d, b);
overflow_limit -= strlen(b);
} else {
strcat(d, "/");
strcat(d, cmd);
overflow_limit-=(strlen(cmd)+1);
}
if (c) {
*c = ' ';
strncat(d, c, overflow_limit);
}
tmp = _php3_escapeshellcmd(d);
efree(d);
d = tmp;
#if WIN32|WINNT
fp = popen(d, "rb");
#else
fp = popen(d, "r");
#endif
if (!fp) {
php3_error(E_WARNING, "Unable to fork [%s]", d);
efree(d);
return -1;
}
} else { /* not safe_mode */
#if WIN32|WINNT
fp = popen(cmd, "rb");
#else
fp = popen(cmd, "r");
#endif
if (!fp) {
php3_error(E_WARNING, "Unable to fork [%s]", cmd);
return -1;
}
}
buf[0] = '\0';
if (type==2) {
if (array->type != IS_ARRAY) {
pval_destructor(array _INLINE_TLS);
array_init(array);
}
}
if (type != 3) {
while (fgets(buf, EXEC_INPUT_BUF - 1, fp)) {
if (type == 1) {
if (output) PUTS(buf);
#if APACHE
# if MODULE_MAGIC_NUMBER > 19970110
if (output) rflush(GLOBAL(php3_rqst));
# else
if (output) bflush(GLOBAL(php3_rqst)->connection->client);
# endif
#endif
#if CGI_BINARY
fflush(stdout);
#endif
#if FHTTPD
/* fhttpd doesn't flush */
#endif
#if USE_SAPI
GLOBAL(sapi_rqst)->flush(GLOBAL(sapi_rqst)->scid);
#endif
}
else if (type == 2) {
pval tmp;
/* strip trailing whitespaces */
l = strlen(buf);
t = l;
while (l && isspace((int)buf[--l]));
if (l < t) buf[l + 1] = '\0';
tmp.value.str.len = strlen(buf);
tmp.value.str.val = estrndup(buf,tmp.value.str.len);
tmp.type = IS_STRING;
_php3_hash_next_index_insert(array->value.ht,(void *) &tmp, sizeof(pval), NULL);
}
}
/* strip trailing spaces */
l = strlen(buf);
t = l;
while (l && isspace((int)buf[--l]));
if (l < t) buf[l + 1] = '\0';
} else {
int b, i;
while ((b = fread(buf, 1, sizeof(buf), fp)) > 0) {
for (i = 0; i < b; i++)
if (output) PUTC(buf[i]);
}
}
/* Return last line from the shell command */
if (PG(magic_quotes_runtime) && type!=3) {
int len;
tmp = _php3_addslashes(buf, 0, &len, 0);
RETVAL_STRINGL(tmp,len,0);
} else {
RETVAL_STRING(buf,1);
}
ret = pclose(fp);
#if HAVE_SYS_WAIT_H
if (WIFEXITED(ret)) {
ret = WEXITSTATUS(ret);
}
#endif
if (d) efree(d);
return ret;
}
/* {{{ proto int exec(string command [, array output [, int return_value]])
Execute an external program */
void php3_exec(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1, *arg2, *arg3;
int arg_count = ARG_COUNT(ht);
int ret;
if (arg_count > 3 || getParameters(ht, arg_count, &arg1, &arg2, &arg3) == FAILURE) {
WRONG_PARAM_COUNT;
}
switch (arg_count) {
case 1:
ret = _Exec(0, arg1->value.str.val, NULL, return_value);
break;
case 2:
if (!ParameterPassedByReference(ht,2)) {
php3_error(E_WARNING,"Array argument to exec() not passed by reference");
}
ret = _Exec(2, arg1->value.str.val, arg2, return_value);
break;
case 3:
if (!ParameterPassedByReference(ht,2)) {
php3_error(E_WARNING,"Array argument to exec() not passed by reference");
}
if (!ParameterPassedByReference(ht,3)) {
php3_error(E_WARNING,"return_status argument to exec() not passed by reference");
}
ret = _Exec(2, arg1->value.str.val, arg2, return_value);
arg3->type = IS_LONG;
arg3->value.lval=ret;
break;
}
}
/* }}} */
/* {{{ proto int system(string command [, int return_value])
Execute an external program and display output */
void php3_system(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1, *arg2;
int arg_count = ARG_COUNT(ht);
int ret;
if (arg_count > 2 || getParameters(ht, arg_count, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
switch (arg_count) {
case 1:
ret = _Exec(1, arg1->value.str.val, NULL, return_value);
break;
case 2:
if (!ParameterPassedByReference(ht,2)) {
php3_error(E_WARNING,"return_status argument to system() not passed by reference");
}
ret = _Exec(1, arg1->value.str.val, NULL, return_value);
arg2->type = IS_LONG;
arg2->value.lval=ret;
break;
}
}
/* }}} */
/* {{{ proto int passthru(string command [, int return_value])
Execute an external program and display raw output */
void php3_passthru(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1, *arg2;
int arg_count = ARG_COUNT(ht);
int ret;
if (arg_count > 2 || getParameters(ht, arg_count, &arg1, &arg2) == FAILURE) {
WRONG_PARAM_COUNT;
}
switch (arg_count) {
case 1:
ret = _Exec(3, arg1->value.str.val, NULL, return_value);
break;
case 2:
if (!ParameterPassedByReference(ht,2)) {
php3_error(E_WARNING,"return_status argument to system() not passed by reference");
}
ret = _Exec(3, arg1->value.str.val, NULL, return_value);
arg2->type = IS_LONG;
arg2->value.lval=ret;
break;
}
}
/* }}} */
static int php3_ind(char *s, char c)
{
register int x;
for (x = 0; s[x]; x++)
if (s[x] == c)
return x;
return -1;
}
/* Escape all chars that could possibly be used to
break out of a shell command
This function emalloc's a string and returns the pointer.
Remember to efree it when done with it.
*NOT* safe for binary strings
*/
char * _php3_escapeshellcmd(char *str) {
register int x, y, l;
char *cmd;
l = strlen(str);
cmd = emalloc(2 * l + 1);
strcpy(cmd, str);
for (x = 0; cmd[x]; x++) {
if (php3_ind("&;`'\"|*?~<>^()[]{}$\\\x0A\xFF", cmd[x]) != -1) {
for (y = l + 1; y > x; y--)
cmd[y] = cmd[y - 1];
l++; /* length has been increased */
cmd[x] = '\\';
x++; /* skip the character */
}
}
return cmd;
}
/* {{{ proto escapeshellcmd(string command)
escape shell metacharacters */
void php3_escapeshellcmd(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1;
char *cmd;
TLS_VARS;
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
cmd = _php3_escapeshellcmd(arg1->value.str.val);
RETVAL_STRING(cmd,1);
efree(cmd);
}
/* }}} */
PHP_FUNCTION(shell_exec)
{
FILE *in;
int readbytes,total_readbytes=0,allocated_space;
pval *cmd;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &cmd)==FAILURE) {
WRONG_PARAM_COUNT;
}
if (PG(safe_mode)) {
php3_error(E_WARNING,"Cannot execute using backquotes in safe mode");
RETURN_FALSE;
}
convert_to_string(cmd);
#if WIN32|WINNT
if ((in=popen(cmd->value.str.val,"rt"))==NULL) {
#else
if ((in=popen(cmd->value.str.val,"r"))==NULL) {
#endif
php3_error(E_WARNING,"Unable to execute '%s'",cmd->value.str.val);
}
allocated_space = EXEC_INPUT_BUF;
return_value->value.str.val = (char *) emalloc(allocated_space);
while (1) {
readbytes = fread(return_value->value.str.val+total_readbytes,1,EXEC_INPUT_BUF,in);
if (readbytes<=0) {
break;
}
total_readbytes += readbytes;
allocated_space = total_readbytes+EXEC_INPUT_BUF;
return_value->value.str.val = (char *) erealloc(return_value->value.str.val,allocated_space);
}
fclose(in);
return_value->value.str.val = erealloc(return_value->value.str.val,total_readbytes+1);
return_value->value.str.val[total_readbytes]=0;
return_value->value.str.len = total_readbytes;
return_value->type = IS_STRING;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

43
ext/standard/exec.h Normal file
View file

@ -0,0 +1,43 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _EXEC_H
#define _EXEC_H
extern void php3_system(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_exec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_escapeshellcmd(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_passthru(INTERNAL_FUNCTION_PARAMETERS);
PHP_FUNCTION(shell_exec);
char *_php3_escapeshellcmd(char *);
#endif /* _EXEC_H */

1435
ext/standard/file.c Normal file

File diff suppressed because it is too large Load diff

65
ext/standard/file.h Normal file
View file

@ -0,0 +1,65 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _FILE_H
#define _FILE_H
extern php3_module_entry php3_file_module_entry;
#define php3_file_module_ptr &php3_file_module_entry
extern int php3_minit_file(INIT_FUNC_ARGS);
extern void php3_tempnam(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fopen(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fclose(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_popen(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pclose(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_feof(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fread(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fgetc(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fgets(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fgetss(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fwrite(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rewind(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ftell(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fseek(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_mkdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rmdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fpassthru(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_readfile(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileumask(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rename(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_file_copy(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_file(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_socket_blocking(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_set_socket_timeout(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_get_meta_tags(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _FILE_H */

509
ext/standard/filestat.c Normal file
View file

@ -0,0 +1,509 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#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_PWD_H
# if MSVC5
# include "win32/pwd.h"
# else
# include <pwd.h>
# endif
#endif
#if HAVE_GRP_H
# if MSVC5
# include "win32/grp.h"
# else
# include <grp.h>
# endif
#endif
#if HAVE_UTIME
# if MSVC5
# include <sys/utime.h>
# else
# include <utime.h>
# endif
#endif
#include "php3_filestat.h"
#ifndef THREAD_SAFE
static char *CurrentStatFile=NULL;
# if MSVC5
static unsigned int CurrentStatLength=0;
# else
static int CurrentStatLength=0;
# endif
static struct stat sb;
#if HAVE_SYMLINK
static struct stat lsb;
#endif
#endif
#ifndef S_ISDIR
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
#endif
#ifndef S_ISLNK
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
#endif
int php3_init_filestat(INIT_FUNC_ARGS)
{
TLS_VARS;
GLOBAL(CurrentStatFile)=NULL;
GLOBAL(CurrentStatLength)=0;
return SUCCESS;
}
int php3_shutdown_filestat(SHUTDOWN_FUNC_ARGS)
{
TLS_VARS;
if (GLOBAL(CurrentStatFile))
efree (GLOBAL(CurrentStatFile));
return SUCCESS;
}
void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS)
{
#ifndef WINDOWS
pval *filename, *group;
gid_t gid;
struct group *gr=NULL;
#endif
int ret;
TLS_VARS;
ret = 0;
#ifndef WINDOWS
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&group)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
if (group->type == IS_STRING) {
gr = getgrnam(group->value.str.val);
if (!gr) {
php3_error(E_WARNING, "unable to find gid for %s",
group->value.str.val);
RETURN_FALSE;
}
gid = gr->gr_gid;
} else {
convert_to_long(group);
gid = group->value.lval;
}
/* #if PHP_SAFE_MODE */
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
RETURN_FALSE;
}
/* #endif */
/* Check the basedir */
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
ret = chown(filename->value.str.val, -1, gid);
if (ret == -1) {
php3_error(E_WARNING, "chgrp failed: %s", strerror(errno));
RETURN_FALSE;
}
#endif
RETURN_TRUE;
}
void php3_chown(INTERNAL_FUNCTION_PARAMETERS)
{
#ifndef WINDOWS
pval *filename, *user;
int ret;
uid_t uid;
struct passwd *pw = NULL;
TLS_VARS;
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&user)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
if (user->type == IS_STRING) {
pw = getpwnam(user->value.str.val);
if (!pw) {
php3_error(E_WARNING, "unable to find uid for %s",
user->value.str.val);
RETURN_FALSE;
}
uid = pw->pw_uid;
} else {
convert_to_long(user);
uid = user->value.lval;
}
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
RETURN_FALSE;
}
/* Check the basedir */
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
ret = chown(filename->value.str.val, uid, -1);
if (ret == -1) {
php3_error(E_WARNING, "chown failed: %s", strerror(errno));
RETURN_FALSE;
}
#else
TLS_VARS;
#endif
RETURN_TRUE;
}
void php3_chmod(INTERNAL_FUNCTION_PARAMETERS) {
pval *filename, *mode;
int ret;
TLS_VARS;
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&mode)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
convert_to_long(mode);
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
RETURN_FALSE;
}
/* Check the basedir */
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
ret = chmod(filename->value.str.val, mode->value.lval);
if (ret == -1) {
php3_error(E_WARNING, "chmod failed: %s", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
}
void php3_touch(INTERNAL_FUNCTION_PARAMETERS) {
#if HAVE_UTIME
pval *filename, *filetime;
int ret;
struct stat sb;
FILE *file;
struct utimbuf *newtime = NULL;
int ac = ARG_COUNT(ht);
TLS_VARS;
if (ac == 1 && getParameters(ht,1,&filename) != FAILURE) {
#ifndef HAVE_UTIME_NULL
newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
if (!newtime) {
php3_error(E_WARNING, "unable to emalloc memory for changing time");
return;
}
newtime->actime = time(NULL);
newtime->modtime = newtime->actime;
#endif
} else if (ac == 2 && getParameters(ht,2,&filename,&filetime) != FAILURE) {
newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
if (!newtime) {
php3_error(E_WARNING, "unable to emalloc memory for changing time");
return;
}
convert_to_long(filetime);
newtime->actime = filetime->value.lval;
newtime->modtime = filetime->value.lval;
} else {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
if (newtime) efree(newtime);
RETURN_FALSE;
}
/* Check the basedir */
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
/* create the file if it doesn't exist already */
ret = stat(filename->value.str.val, &sb);
if (ret == -1) {
file = fopen(filename->value.str.val, "w");
if (file == NULL) {
php3_error(E_WARNING, "unable to create file %s because %s", filename->value.str.val, strerror(errno));
if (newtime) efree(newtime);
RETURN_FALSE;
}
fclose(file);
}
ret = utime(filename->value.str.val, newtime);
if (newtime) efree(newtime);
if (ret == -1) {
php3_error(E_WARNING, "utime failed: %s", strerror(errno));
RETURN_FALSE;
} else {
RETURN_TRUE;
}
#endif
}
void php3_clearstatcache(INTERNAL_FUNCTION_PARAMETERS) {
TLS_VARS;
if (GLOBAL(CurrentStatFile)) {
efree(GLOBAL(CurrentStatFile));
GLOBAL(CurrentStatFile) = NULL;
}
}
static void _php3_stat(const char *filename, int type, pval *return_value)
{
struct stat *stat_sb = &GLOBAL(sb);
TLS_VARS;
if (!GLOBAL(CurrentStatFile) || strcmp(filename,GLOBAL(CurrentStatFile))) {
if (!GLOBAL(CurrentStatFile)
|| strlen(filename) > GLOBAL(CurrentStatLength)) {
if (GLOBAL(CurrentStatFile)) efree(GLOBAL(CurrentStatFile));
GLOBAL(CurrentStatLength) = strlen(filename);
GLOBAL(CurrentStatFile) = estrndup(filename,GLOBAL(CurrentStatLength));
} else {
strcpy(GLOBAL(CurrentStatFile),filename);
}
#if HAVE_SYMLINK
GLOBAL(lsb).st_mode = 0; /* mark lstat buf invalid */
#endif
if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */
php3_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",GLOBAL(CurrentStatFile),errno,strerror(errno));
}
efree(GLOBAL(CurrentStatFile));
GLOBAL(CurrentStatFile)=NULL;
RETURN_FALSE;
}
}
#if HAVE_SYMLINK
if (8 == type /* filetype */
|| 14 == type /* is link */
|| 16 == type) { /* lstat */
/* do lstat if the buffer is empty */
if (!GLOBAL(lsb).st_mode) {
if (lstat(GLOBAL(CurrentStatFile),&GLOBAL(lsb)) == -1) {
php3_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",GLOBAL(CurrentStatFile),errno,strerror(errno));
RETURN_FALSE;
}
}
}
#endif
switch(type) {
case 0: /* fileperms */
RETURN_LONG((long)GLOBAL(sb).st_mode);
case 1: /* fileinode */
RETURN_LONG((long)GLOBAL(sb).st_ino);
case 2: /* filesize */
RETURN_LONG((long)GLOBAL(sb).st_size);
case 3: /* fileowner */
RETURN_LONG((long)GLOBAL(sb).st_uid);
case 4: /* filegroup */
RETURN_LONG((long)GLOBAL(sb).st_gid);
case 5: /* fileatime */
RETURN_LONG((long)GLOBAL(sb).st_atime);
case 6: /* filemtime */
RETURN_LONG((long)GLOBAL(sb).st_mtime);
case 7: /* filectime */
RETURN_LONG((long)GLOBAL(sb).st_ctime);
case 8: /* filetype */
#if HAVE_SYMLINK
if (S_ISLNK(GLOBAL(lsb).st_mode)) {
RETURN_STRING("link",1);
}
#endif
switch(GLOBAL(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);
}
php3_error(E_WARNING,"Unknown file type (%d)",GLOBAL(sb).st_mode&S_IFMT);
RETURN_STRING("unknown",1);
case 9: /*is writable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IWRITE)!=0);
case 10: /*is readable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IREAD)!=0);
case 11: /*is executable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IEXEC)!=0 && !S_ISDIR(GLOBAL(sb).st_mode));
case 12: /*is file*/
RETURN_LONG(S_ISREG(GLOBAL(sb).st_mode));
case 13: /*is dir*/
RETURN_LONG(S_ISDIR(GLOBAL(sb).st_mode));
case 14: /*is link*/
#if HAVE_SYMLINK
RETURN_LONG(S_ISLNK(GLOBAL(lsb).st_mode));
#else
RETURN_FALSE;
#endif
case 15: /*file exists*/
RETURN_TRUE; /* the false case was done earlier */
case 16: /* lstat */
#if HAVE_SYMLINK
stat_sb = &GLOBAL(lsb);
#endif
/* FALLTHROUGH */
case 17: /* stat */
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
add_next_index_long(return_value, stat_sb->st_dev);
add_next_index_long(return_value, stat_sb->st_ino);
add_next_index_long(return_value, stat_sb->st_mode);
add_next_index_long(return_value, stat_sb->st_nlink);
add_next_index_long(return_value, stat_sb->st_uid);
add_next_index_long(return_value, stat_sb->st_gid);
#ifdef HAVE_ST_BLKSIZE
add_next_index_long(return_value, stat_sb->st_rdev);
#else
add_next_index_long(return_value, -1);
#endif
add_next_index_long(return_value, stat_sb->st_size);
add_next_index_long(return_value, stat_sb->st_atime);
add_next_index_long(return_value, stat_sb->st_mtime);
add_next_index_long(return_value, stat_sb->st_ctime);
#if HAVE_ST_BLKSIZE
add_next_index_long(return_value, stat_sb->st_blksize);
#else
add_next_index_long(return_value, -1);
#endif
#if HAVE_ST_BLOCKS
add_next_index_long(return_value, stat_sb->st_blocks);
#else
add_next_index_long(return_value, -1);
#endif
return;
}
php3_error(E_WARNING, "didn't understand stat call");
RETURN_FALSE;
}
/* another quickie macro to make defining similar functions easier */
#define FileFunction(name, funcnum) \
void name(INTERNAL_FUNCTION_PARAMETERS) { \
pval *filename; \
if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&filename) == FAILURE) { \
WRONG_PARAM_COUNT; \
} \
convert_to_string(filename); \
_php3_stat(filename->value.str.val, funcnum, return_value); \
}
FileFunction(php3_fileperms,0)
FileFunction(php3_fileinode,1)
FileFunction(php3_filesize, 2)
FileFunction(php3_fileowner,3)
FileFunction(php3_filegroup,4)
FileFunction(php3_fileatime,5)
FileFunction(php3_filemtime,6)
FileFunction(php3_filectime,7)
FileFunction(php3_filetype, 8)
FileFunction(php3_iswritable, 9)
FileFunction(php3_isreadable,10)
FileFunction(php3_isexec,11)
FileFunction(php3_isfile,12)
FileFunction(php3_isdir,13)
FileFunction(php3_islink,14)
FileFunction(php3_fileexists,15)
FileFunction(php3_lstat,16)
FileFunction(php3_stat,17)
function_entry php3_filestat_functions[] = {
{"fileatime", php3_fileatime, NULL},
{"filectime", php3_filectime, NULL},
{"filegroup", php3_filegroup, NULL},
{"fileinode", php3_fileinode, NULL},
{"filemtime", php3_filemtime, NULL},
{"fileowner", php3_fileowner, NULL},
{"fileperms", php3_fileperms, NULL},
{"filesize", php3_filesize, NULL},
{"filetype", php3_filetype, NULL},
{"file_exists", php3_fileexists, NULL},
{"is_writeable",php3_iswritable, NULL},
{"is_readable", php3_isreadable, NULL},
{"is_executable",php3_isexec, NULL},
{"is_file", php3_isfile, NULL},
{"is_dir", php3_isdir, NULL},
{"is_link", php3_islink, NULL},
{"stat", php3_stat, NULL},
{"lstat", php3_lstat, NULL},
{"chown", php3_chown, NULL},
{"chgrp", php3_chgrp, NULL},
{"chmod", php3_chmod, NULL},
{"touch", php3_touch, NULL},
{NULL, NULL, NULL}
};
php3_module_entry php3_filestat_module_entry = {
"PHP_filestat", php3_filestat_functions, NULL, NULL, php3_init_filestat, php3_shutdown_filestat, NULL, STANDARD_MODULE_PROPERTIES
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

View file

@ -0,0 +1,602 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <math.h> /* modf() */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "head.h"
#include "php3_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) php3_printf arg
#else
# define PRINTF_DEBUG(arg)
#endif
static char hexchars[] = "0123456789abcdef";
static char HEXCHARS[] = "0123456789ABCDEF";
/*
* cvt.c - IEEE floating point formatting routines for FreeBSD
* from GNU libc-4.6.27
*/
/*
* _php3_cvt converts to decimal
* the number of digits is specified by ndigit
* decpt is set to the position of the decimal point
* sign is set to 0 for positive, 1 for negative
*/
static char *
_php3_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag)
{
register int r2;
double fi, fj;
register char *p, *p1;
/*THREADX*/
#ifndef THREAD_SAFE
static char cvt_buf[NDIG];
#endif
TLS_VARS;
if (ndigits >= NDIG - 1)
ndigits = NDIG - 2;
r2 = 0;
*sign = 0;
p = &STATIC(cvt_buf)[0];
if (arg < 0) {
*sign = 1;
arg = -arg;
}
arg = modf(arg, &fi);
p1 = &STATIC(cvt_buf)[NDIG];
/*
* Do integer part
*/
if (fi != 0) {
p1 = &STATIC(cvt_buf)[NDIG];
while (fi != 0) {
fj = modf(fi / 10, &fi);
*--p1 = (int) ((fj + .03) * 10) + '0';
r2++;
}
while (p1 < &STATIC(cvt_buf)[NDIG])
*p++ = *p1++;
} else if (arg > 0) {
while ((fj = arg * 10) < 1) {
arg = fj;
r2--;
}
}
p1 = &STATIC(cvt_buf)[ndigits];
if (eflag == 0)
p1 += r2;
*decpt = r2;
if (p1 < &STATIC(cvt_buf)[0]) {
STATIC(cvt_buf)[0] = '\0';
return (STATIC(cvt_buf));
}
while (p <= p1 && p < &STATIC(cvt_buf)[NDIG]) {
arg *= 10;
arg = modf(arg, &fj);
*p++ = (int) fj + '0';
}
if (p1 >= &STATIC(cvt_buf)[NDIG]) {
STATIC(cvt_buf)[NDIG - 1] = '\0';
return (STATIC(cvt_buf));
}
p = p1;
*p1 += 5;
while (*p1 > '9') {
*p1 = '0';
if (p1 > STATIC(cvt_buf))
++ * --p1;
else {
*p1 = '1';
(*decpt)++;
if (eflag == 0) {
if (p > STATIC(cvt_buf))
*p = '0';
p++;
}
}
}
*p = '\0';
return (STATIC(cvt_buf));
}
inline static void
_php3_sprintf_appendchar(char **buffer, int *pos, int *size, char add)
{
if ((*pos + 1) >= *size) {
*size <<= 1;
PRINTF_DEBUG(("%s: ereallocing buffer to %d bytes\n", get_active_function_name(), *size));
*buffer = erealloc(*buffer, *size);
}
PRINTF_DEBUG(("sprintf: appending '%c', pos=\n", add, *pos));
(*buffer)[(*pos)++] = add;
}
inline static void
_php3_sprintf_appendstring(char **buffer, int *pos, int *size, char *add,
int min_width, int max_width, char padding,
int alignment, int len)
{
register int npad = min_width - MIN(len,(max_width?max_width:len));
if (npad<0) {
npad=0;
}
PRINTF_DEBUG(("sprintf: appendstring(%x, %d, %d, \"%s\", %d, '%c', %d)\n",
*buffer, *pos, *size, add, min_width, padding, alignment));
if (max_width == 0) {
max_width = MAX(min_width,len);
}
if ((*pos + max_width) >= *size) {
while ((*pos + max_width) >= *size) {
*size <<= 1;
}
PRINTF_DEBUG(("sprintf ereallocing buffer to %d bytes\n", *size));
*buffer = erealloc(*buffer, *size);
}
if (alignment == ALIGN_RIGHT) {
while (npad-- > 0) {
(*buffer)[(*pos)++] = padding;
}
}
PRINTF_DEBUG(("sprintf: appending \"%s\"\n", add));
strncpy(&(*buffer)[*pos], add, max_width);
*pos += MIN(max_width,len);
if (alignment == ALIGN_LEFT) {
while (npad--) {
(*buffer)[(*pos)++] = padding;
}
}
}
inline static void
_php3_sprintf_appendint(char **buffer, int *pos, int *size, int number,
int width, char padding, int alignment)
{
char numbuf[NUM_BUF_SIZE];
register unsigned int magn, nmagn, i = NUM_BUF_SIZE - 1, neg = 0;
PRINTF_DEBUG(("sprintf: appendint(%x, %x, %x, %d, %d, '%c', %d)\n",
*buffer, pos, size, number, width, padding, alignment));
if (number < 0) {
neg = 1;
magn = ((unsigned int) -(number + 1)) + 1;
} else {
magn = (unsigned int) number;
}
numbuf[i] = '\0';
do {
nmagn = magn / 10;
numbuf[--i] = (magn - (nmagn * 10)) + '0';
magn = nmagn;
}
while (magn > 0 && i > 0);
if (neg) {
numbuf[--i] = '-';
}
PRINTF_DEBUG(("sprintf: appending %d as \"%s\", i=%d\n",
number, &numbuf[i], i));
_php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
padding, alignment, (NUM_BUF_SIZE - 1) - i);
}
inline static void
_php3_sprintf_appenddouble(char **buffer, int *pos,
int *size, double number,
int width, char padding,
int alignment, int precision,
int adjust, char fmt)
{
char numbuf[NUM_BUF_SIZE];
char *cvt;
register int i = 0, j = 0;
int sign, decpt;
PRINTF_DEBUG(("sprintf: appenddouble(%x, %x, %x, %f, %d, '%c', %d, %c)\n",
*buffer, pos, size, number, width, padding, alignment, fmt));
if ((adjust & ADJ_PRECISION) == 0) {
precision = FLOAT_PRECISION;
} else if (precision > MAX_FLOAT_PRECISION) {
precision = MAX_FLOAT_PRECISION;
}
cvt = _php3_cvt(number, precision, &decpt, &sign, (fmt == 'e'));
if (sign) {
numbuf[i++] = '-';
}
if (fmt == 'f') {
if (decpt <= 0) {
numbuf[i++] = '0';
if (precision > 0) {
int k = precision;
numbuf[i++] = '.';
while ((decpt++ < 0) && k--) {
numbuf[i++] = '0';
}
}
} else {
while (decpt-- > 0)
numbuf[i++] = cvt[j++];
if (precision > 0)
numbuf[i++] = '.';
}
} else {
numbuf[i++] = cvt[j++];
if (precision > 0)
numbuf[i++] = '.';
}
while (cvt[j]) {
numbuf[i++] = cvt[j++];
}
numbuf[i] = '\0';
if (precision > 0) {
width += (precision + 1);
}
_php3_sprintf_appendstring(buffer, pos, size, numbuf, width, 0, padding,
alignment, i);
}
inline static void
_php3_sprintf_append2n(char **buffer, int *pos, int *size, int number,
int width, char padding, int alignment, int n,
char *chartable)
{
char numbuf[NUM_BUF_SIZE];
register unsigned int num, i = NUM_BUF_SIZE - 1, neg = 0;
register int andbits = (1 << n) - 1;
PRINTF_DEBUG(("sprintf: append2n(%x, %x, %x, %d, %d, '%c', %d, %d, %x)\n",
*buffer, pos, size, number, width, padding, alignment, n,
chartable));
PRINTF_DEBUG(("sprintf: append2n 2^%d andbits=%x\n", n, andbits));
if (number < 0) {
neg = 1;
num = ((unsigned int) -(number + 1)) + 1;
} else {
num = (unsigned int) number;
}
numbuf[i] = '\0';
do {
numbuf[--i] = chartable[(num & andbits)];
num >>= n;
}
while (num > 0);
if (neg) {
numbuf[--i] = '-';
}
_php3_sprintf_appendstring(buffer, pos, size, &numbuf[i], width, 0,
padding, alignment, (NUM_BUF_SIZE - 1) - i);
}
inline static int
_php3_sprintf_getnumber(char *buffer, int *pos)
{
char *endptr;
register int num = strtol(&buffer[*pos], &endptr, 10);
register int i = 0;
if (endptr != NULL) {
i = (endptr - &buffer[*pos]);
}
PRINTF_DEBUG(("sprintf_getnumber: number was %d bytes long\n", i));
*pos += i;
return num;
}
/*
* New sprintf implementation for PHP.
*
* Modifiers:
*
* " " pad integers with spaces
* "-" left adjusted field
* n field size
* "."n precision (floats only)
*
* Type specifiers:
*
* "%" literal "%", modifiers are ignored.
* "b" integer argument is printed as binary
* "c" integer argument is printed as a single character
* "d" argument is an integer
* "f" the argument is a float
* "o" integer argument is printed as octal
* "s" argument is a string
* "x" integer argument is printed as lowercase hexadecimal
* "X" integer argument is printed as uppercase hexadecimal
*
*/
static char *
php3_formatted_print(int ht, int *len)
{
pval **args;
int argc, size = 240, inpos = 0, outpos = 0;
int alignment, width, precision, currarg, adjusting;
char *format, *result, padding;
argc = ARG_COUNT(ht);
if (argc < 1) {
WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
}
args = emalloc(argc * sizeof(pval *));
if (getParametersArray(ht, argc, args) == FAILURE) {
efree(args);
WRONG_PARAM_COUNT_WITH_RETVAL(NULL);
}
convert_to_string(args[0]);
format = args[0]->value.str.val;
result = emalloc(size);
currarg = 1;
while (format[inpos]) {
PRINTF_DEBUG(("sprintf: format[%d]='%c'\n", inpos, format[inpos]));
PRINTF_DEBUG(("sprintf: outpos=%d\n", outpos));
if (format[inpos] != '%') {
_php3_sprintf_appendchar(&result, &outpos, &size, format[inpos++]);
} else if (format[inpos + 1] == '%') {
_php3_sprintf_appendchar(&result, &outpos, &size, '%');
inpos += 2;
} else {
if (currarg >= argc && format[inpos + 1] != '%') {
efree(result);
efree(args);
php3_error(E_WARNING, "%s(): too few arguments",get_active_function_name());
return NULL;
}
/* starting a new format specifier, reset variables */
alignment = ALIGN_RIGHT;
adjusting = 0;
padding = ' ';
inpos++; /* skip the '%' */
PRINTF_DEBUG(("sprintf: first looking at '%c', inpos=%d\n",
format[inpos], inpos));
if (isascii((int)format[inpos]) && !isalpha((int)format[inpos])) {
/* first look for modifiers */
PRINTF_DEBUG(("sprintf: looking for modifiers\n"
"sprintf: now looking at '%c', inpos=%d\n",
format[inpos], inpos));
for (;; inpos++) {
if (format[inpos] == ' ' || format[inpos] == '0') {
padding = format[inpos];
} else if (format[inpos] == '-') {
alignment = ALIGN_LEFT;
/* space padding, the default */
} else if (format[inpos] == '\'') {
padding = format[++inpos];
} else {
PRINTF_DEBUG(("sprintf: end of modifiers\n"));
break;
}
}
PRINTF_DEBUG(("sprintf: padding='%c'\n", padding));
PRINTF_DEBUG(("sprintf: alignment=%s\n",
(alignment == ALIGN_LEFT) ? "left" : "right"));
/* after modifiers comes width */
if (isdigit((int)format[inpos])) {
PRINTF_DEBUG(("sprintf: getting width\n"));
width = _php3_sprintf_getnumber(format, &inpos);
adjusting |= ADJ_WIDTH;
} else {
width = 0;
}
PRINTF_DEBUG(("sprintf: width=%d\n", width));
/* after width comes precision */
if (format[inpos] == '.') {
inpos++;
PRINTF_DEBUG(("sprintf: getting precision\n"));
if (isdigit((int)format[inpos])) {
precision = _php3_sprintf_getnumber(format, &inpos);
adjusting |= ADJ_PRECISION;
} else {
precision = 0;
}
} else {
precision = 0;
}
PRINTF_DEBUG(("sprintf: precision=%d\n", precision));
} else {
width = precision = 0;
}
if (format[inpos] == 'l') {
inpos++;
}
PRINTF_DEBUG(("sprintf: format character='%c'\n", format[inpos]));
/* now we expect to find a type specifier */
switch (format[inpos]) {
case 's':
convert_to_string(args[currarg]);
_php3_sprintf_appendstring(&result, &outpos, &size,
args[currarg]->value.str.val,
width, precision, padding,
alignment,
args[currarg]->value.str.len);
break;
case 'd':
convert_to_long(args[currarg]);
_php3_sprintf_appendint(&result, &outpos, &size,
args[currarg]->value.lval,
width, padding, alignment);
break;
case 'e':
case 'f':
/* XXX not done */
convert_to_double(args[currarg]);
_php3_sprintf_appenddouble(&result, &outpos, &size,
args[currarg]->value.dval,
width, padding, alignment,
precision, adjusting,
format[inpos]);
break;
case 'c':
convert_to_long(args[currarg]);
_php3_sprintf_appendchar(&result, &outpos, &size,
(char) args[currarg]->value.lval);
break;
case 'o':
convert_to_long(args[currarg]);
_php3_sprintf_append2n(&result, &outpos, &size,
args[currarg]->value.lval,
width, padding, alignment, 3,
hexchars);
break;
case 'x':
convert_to_long(args[currarg]);
_php3_sprintf_append2n(&result, &outpos, &size,
args[currarg]->value.lval,
width, padding, alignment, 4,
hexchars);
break;
case 'X':
convert_to_long(args[currarg]);
_php3_sprintf_append2n(&result, &outpos, &size,
args[currarg]->value.lval,
width, padding, alignment, 4,
HEXCHARS);
break;
case 'b':
convert_to_long(args[currarg]);
_php3_sprintf_append2n(&result, &outpos, &size,
args[currarg]->value.lval,
width, padding, alignment, 1,
hexchars);
break;
case '%':
_php3_sprintf_appendchar(&result, &outpos, &size, '%');
break;
default:
break;
}
currarg++;
inpos++;
}
}
efree(args);
/* possibly, we have to make sure we have room for the terminating null? */
result[outpos]=0;
*len = outpos;
return result;
}
PHP_FUNCTION(user_sprintf)
{
char *result;
int len;
TLS_VARS;
if ((result=php3_formatted_print(ht,&len))==NULL) {
RETURN_FALSE;
}
RETVAL_STRINGL(result,len,1);
efree(result);
}
PHP_FUNCTION(user_printf)
{
char *result;
int len;
TLS_VARS;
if ((result=php3_formatted_print(ht,&len))==NULL) {
RETURN_FALSE;
}
PHPWRITE(result,len);
efree(result);
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

477
ext/standard/fsock.c Normal file
View file

@ -0,0 +1,477 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Paul Panotzki - Bunyip Information Systems |
| Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef WIN32
#include <winsock.h>
#else
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif
#ifdef WIN32
#undef AF_UNIX
#endif
#if defined(AF_UNIX)
#include <sys/un.h>
#endif
#include <string.h>
#include <errno.h>
#include "base64.h"
#include "file.h"
#include "post.h"
#include "url.h"
#include "fsock.h"
#ifndef THREAD_SAFE
extern int le_fp;
#endif
#define FREE_SOCK if(socketd >= 0) close(socketd); efree(sock); if (key) efree(key)
#if WIN32|WINNT
#define EWOULDBLOCK WSAEWOULDBLOCK
#else
#include "build-defs.h"
#endif
static unsigned char third_and_fourth_args_force_ref[] = { 4, BYREF_NONE, BYREF_NONE, BYREF_FORCE, BYREF_FORCE };
function_entry fsock_functions[] = {
PHP_FE(fsockopen, third_and_fourth_args_force_ref)
PHP_FE(pfsockopen, third_and_fourth_args_force_ref)
{NULL, NULL, NULL}
};
struct php3i_sockbuf {
int socket;
char *readbuf;
size_t readbuflen;
size_t readpos;
size_t writepos;
struct php3i_sockbuf *next;
};
static struct php3i_sockbuf *phpsockbuf;
static int php3_minit_fsock(INIT_FUNC_ARGS);
static int php3_mshutdown_fsock(void);
static int php3_rshutdown_fsock(void);
php3_module_entry fsock_module_entry = {
"Socket functions", fsock_functions, php3_minit_fsock, php3_mshutdown_fsock, NULL, php3_rshutdown_fsock, NULL, STANDARD_MODULE_PROPERTIES
};
#ifndef THREAD_SAFE
static HashTable ht_keys;
static HashTable ht_socks;
#endif
/* {{{ lookup_hostname */
/*
* Converts a host name to an IP address.
*/
int lookup_hostname(const char *addr, struct in_addr *in)
{
struct hostent *host_info;
if(!inet_aton(addr, in)) {
host_info = gethostbyname(addr);
if (host_info == 0) {
/* Error: unknown host */
return -1;
}
*in = *((struct in_addr *) host_info->h_addr);
}
return 0;
}
/* }}} */
/* {{{ _php3_is_persistent_sock */
int _php3_is_persistent_sock(int sock)
{
char *key;
if (_php3_hash_find(&ht_socks, (char *) &sock, sizeof(sock),
(void **) &key) == SUCCESS) {
return 1;
}
return 0;
}
/* }}} */
/* {{{ _php3_fsockopen() */
/*
This function takes an optional third argument which should be
passed by reference. The error code from the connect call is written
to this variable.
*/
static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
pval *args[4];
int *sock=emalloc(sizeof(int));
int *sockp;
int id, arg_count=ARG_COUNT(ht);
int socketd = -1;
unsigned short portno;
char *key = NULL;
TLS_VARS;
if (arg_count > 4 || arg_count < 2 || getParametersArray(ht,arg_count,args)==FAILURE) {
FREE_SOCK;
WRONG_PARAM_COUNT;
}
switch(arg_count) {
case 4:
if(!ParameterPassedByReference(ht,4)) {
php3_error(E_WARNING,"error string argument to fsockopen not passed by reference");
}
pval_copy_constructor(args[3]);
args[3]->value.str.val = empty_string;
args[3]->value.str.len = 0;
args[3]->type = IS_STRING;
/* fall-through */
case 3:
if(!ParameterPassedByReference(ht,3)) {
php3_error(E_WARNING,"error argument to fsockopen not passed by reference");
}
args[2]->type = IS_LONG;
args[2]->value.lval = 0;
break;
}
convert_to_string(args[0]);
convert_to_long(args[1]);
portno = (unsigned short) args[1]->value.lval;
key = emalloc(args[0]->value.str.len + 10);
sprintf(key, "%s:%d", args[0]->value.str.val, portno);
if (persistent && _php3_hash_find(&ht_keys, key, strlen(key) + 1,
(void *) &sockp) == SUCCESS) {
efree(key);
*sock = *sockp;
RETURN_LONG(php3_list_insert(sock, GLOBAL(wsa_fp)));
}
if (portno) {
struct sockaddr_in server;
memset(&server, 0, sizeof(server));
socketd = socket(AF_INET, SOCK_STREAM, 0);
if (socketd == SOCK_ERR) {
FREE_SOCK;
RETURN_FALSE;
}
server.sin_family = AF_INET;
if (lookup_hostname(args[0]->value.str.val, &server.sin_addr)) {
FREE_SOCK;
RETURN_FALSE;
}
server.sin_port = htons(portno);
if (connect(socketd, (struct sockaddr *)&server, sizeof(server)) == SOCK_CONN_ERR) {
FREE_SOCK;
if(arg_count>2) args[2]->value.lval = errno;
if(arg_count>3) {
args[3]->value.str.val = estrdup(strerror(errno));
args[3]->value.str.len = strlen(args[3]->value.str.val);
}
RETURN_FALSE;
}
#if defined(AF_UNIX)
} else {
/* Unix domain socket. s->strval is socket name. */
struct sockaddr_un unix_addr;
socketd = socket(AF_UNIX,SOCK_STREAM,0);
if (socketd == SOCK_ERR) {
FREE_SOCK;
RETURN_FALSE;
}
memset(&unix_addr,(char)0,sizeof(unix_addr));
unix_addr.sun_family = AF_UNIX;
strcpy(unix_addr.sun_path, args[0]->value.str.val);
if (connect(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr)) == SOCK_CONN_ERR) {
FREE_SOCK;
if(arg_count>2) args[2]->value.lval = errno;
if(arg_count>3) {
args[3]->value.str.val = estrdup(strerror(errno));
args[3]->value.str.len = strlen(args[3]->value.str.val);
}
RETURN_FALSE;
}
#endif /* AF_UNIX */
}
#if 0
if ((fp = fdopen (socketd, "r+")) == NULL){
RETURN_LONG(-6); /* FIXME */
}
#ifdef HAVE_SETVBUF
if ((setvbuf(fp, NULL, _IONBF, 0)) != 0){
RETURN_LONG(-7); /* FIXME */
}
#endif
#endif
*sock=socketd;
if (persistent) {
_php3_hash_update(&ht_keys, key, strlen(key) + 1,
sock, sizeof(*sock), NULL);
_php3_hash_update(&ht_socks, (char *) sock, sizeof(*sock),
key, strlen(key) + 1, NULL);
}
if(key) efree(key);
id = php3_list_insert(sock,GLOBAL(wsa_fp));
RETURN_LONG(id);
}
/* }}} */
/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr]])
Open Internet or Unix domain socket connection */
PHP_FUNCTION(fsockopen)
{
_php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr]])
Open persistent Internet or Unix domain socket connection */
PHP_FUNCTION(pfsockopen)
{
_php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* Known issues with the socket buffering code:
* - does not work reliably with persistent sockets yet
* (buffered data is not persistent)
* - php3_fopen_url_wrapper() is still doing single-byte lookahead/read
*/
/* {{{ _php3_sock_fgets() */
int _php3_sock_fgets(char *buf, int maxlen, int socket)
{
struct php3i_sockbuf *sockbuf = NULL, *tmpsockbuf;
int bytesread, toread, len, buflen, count = 0;
char *nl;
tmpsockbuf = phpsockbuf;
while (tmpsockbuf) {
if (tmpsockbuf->socket == socket) {
sockbuf = tmpsockbuf;
break;
}
tmpsockbuf = tmpsockbuf->next;
}
if (sockbuf) {
toread = sockbuf->writepos - sockbuf->readpos;
if (toread > maxlen) {
toread = maxlen;
}
if ((nl = memchr(sockbuf->readbuf + sockbuf->readpos, '\n', toread)) != NULL) {
toread = (nl - (sockbuf->readbuf + sockbuf->readpos)) + 1;
}
memcpy(buf, sockbuf->readbuf + sockbuf->readpos, toread);
sockbuf->readpos += toread;
count += toread;
buf += toread;
if (sockbuf->readpos >= sockbuf->writepos) {
sockbuf->readpos = sockbuf->writepos = 0;
}
if (nl != NULL) {
/* if a newline was found, skip the recv() loop */
goto sock_fgets_exit;
}
}
nl = NULL;
buflen = 0;
while (count < maxlen && nl == NULL) {
toread = maxlen - count;
bytesread = recv(socket, buf, toread, 0);
if (bytesread <= 0) {
break;
}
if ((nl = memchr(buf, '\n', bytesread)) != NULL) {
len = (nl - buf) + 1;
count += len;
buf += len;
if (len < bytesread) {
buflen = bytesread - len;
break;
}
} else {
count += bytesread;
buf += bytesread;
}
}
if (buflen > 0) { /* there was data after the "\n" ... */
if (sockbuf == NULL) {
sockbuf = emalloc(sizeof(struct php3i_sockbuf));
sockbuf->socket = socket;
sockbuf->readbuf = emalloc(maxlen);
sockbuf->readbuflen = maxlen;
sockbuf->readpos = sockbuf->writepos = 0;
sockbuf->next = phpsockbuf;
phpsockbuf = sockbuf;
} else {
int needlen = sockbuf->writepos + buflen;
if (needlen > sockbuf->readbuflen) {
sockbuf->readbuflen += maxlen;
sockbuf->readbuf = erealloc(sockbuf->readbuf, sockbuf->readbuflen);
}
}
memcpy(sockbuf->readbuf + sockbuf->writepos, buf, buflen);
sockbuf->writepos += buflen;
}
sock_fgets_exit:
*buf = '\0';
return count;
}
/* }}} */
/* {{{ _php3_sock_fread() */
int _php3_sock_fread(char *buf, int maxlen, int socket)
{
struct php3i_sockbuf *sockbuf = phpsockbuf;
int bytesread, toread, count = 0;
while (sockbuf) {
if (sockbuf->socket == socket) {
toread = sockbuf->writepos - sockbuf->readpos;
if (toread > maxlen) {
toread = maxlen;
}
memcpy(buf, sockbuf->readbuf + sockbuf->readpos, toread);
sockbuf->readpos += toread;
count += toread;
buf += toread;
break;
}
sockbuf = sockbuf->next;
}
while (count < maxlen) {
toread = maxlen - count;
bytesread = recv(socket, buf, toread, 0);
if (bytesread <= 0) {
break;
}
count += bytesread;
buf += bytesread;
}
*buf = '\0';
return count;
}
/* }}} */
/* {{{ module start/shutdown functions */
/* {{{ _php3_sock_destroy */
#ifndef THREAD_SAFE
static void _php3_sock_destroy(void *data)
{
int *sock = (int *) data;
close(*sock);
}
#endif
/* }}} */
/* {{{ php3_minit_fsock */
static int php3_minit_fsock(INIT_FUNC_ARGS)
{
#ifndef THREAD_SAFE
_php3_hash_init(&ht_keys, 0, NULL, NULL, 1);
_php3_hash_init(&ht_socks, 0, NULL, _php3_sock_destroy, 1);
#endif
return SUCCESS;
}
/* }}} */
/* {{{ php3_mshutdown_fsock */
static int php3_mshutdown_fsock(void)
{
#ifndef THREAD_SAFE
_php3_hash_destroy(&ht_socks);
_php3_hash_destroy(&ht_keys);
#endif
return SUCCESS;
}
/* }}} */
/* {{{ php3_rshutdown_fsock() */
static int php3_rshutdown_fsock(void)
{
struct php3i_sockbuf *sockbuf = phpsockbuf, *this;
while (sockbuf) {
this = sockbuf;
sockbuf = this->next;
efree(this->readbuf);
efree(this);
}
phpsockbuf = NULL;
return SUCCESS;
}
/* }}} */
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

47
ext/standard/fsock.h Normal file
View file

@ -0,0 +1,47 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Paul Panotzki - Bunyip Information Systems |
| Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _FSOCK_H
#define _FSOCK_H
#include <netinet/in.h>
extern php3_module_entry fsock_module_entry;
#define fsock_module_ptr &fsock_module_entry
extern PHP_FUNCTION(fsockopen);
extern PHP_FUNCTION(pfsockopen);
extern int lookup_hostname(const char *addr, struct in_addr *in);
extern int _php3_sock_fgets(char *buf, int maxlen, int socket);
extern int _php3_sock_fread(char *buf, int maxlen, int socket);
extern int _php3_is_persistent_sock(int);
#endif /* _FSOCK_H */

58
ext/standard/global.h Normal file
View file

@ -0,0 +1,58 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* GLOBAL.H - RSAREF types and constants
*/
/* PROTOTYPES should be set to one if and only if the compiler supports
function argument prototyping.
The following makes PROTOTYPES default to 0 if it has not already
been defined with C compiler flags.
*/
#ifndef PROTOTYPES
#define PROTOTYPES 1 /* php3 has prototypes everywhere */
#endif
/* _POINTER defines a generic pointer type */
typedef unsigned char *_POINTER;
/* UINT2 defines a two byte word */
typedef unsigned short int UINT2;
/* UINT4 defines a four byte word */
typedef unsigned long int UINT4;
/* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
returns an empty list.
*/
#if PROTOTYPES
#define PROTO_LIST(list) list
#else
#define PROTO_LIST(list) ()
#endif

134
ext/standard/html.c Normal file
View file

@ -0,0 +1,134 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Jaakko Hyvätti <jaakko.hyvatti@iki.fi> |
+----------------------------------------------------------------------+
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "reg.h"
#include "html.h"
/* This must be fixed to handle the input string according to LC_CTYPE.
Defaults to ISO-8859-1 for now. */
static char EntTable[][7] =
{
"nbsp","iexcl","cent","pound","curren","yen","brvbar",
"sect","uml","copy","ordf","laquo","not","shy","reg",
"macr","deg","plusmn","sup2","sup3","acute","micro",
"para","middot","cedil","sup1","ordm","raquo","frac14",
"frac12","frac34","iquest","Agrave","Aacute","Acirc",
"Atilde","Auml","Aring","AElig","Ccedil","Egrave",
"Eacute","Ecirc","Euml","Igrave","Iacute","Icirc",
"Iuml","ETH","Ntilde","Ograve","Oacute","Ocirc","Otilde",
"Ouml","times","Oslash","Ugrave","Uacute","Ucirc","Uuml",
"Yacute","THORN","szlig","agrave","aacute","acirc",
"atilde","auml","aring","aelig","ccedil","egrave",
"eacute","ecirc","euml","igrave","iacute","icirc",
"iuml","eth","ntilde","ograve","oacute","ocirc","otilde",
"ouml","divide","oslash","ugrave","uacute","ucirc",
"uuml","yacute","thorn","yuml"
};
static void _php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS, int all)
{
pval *arg;
int i, len, maxlen;
unsigned char *old;
char *new;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
maxlen = 2 * arg->value.str.len;
if (maxlen < 128)
maxlen = 128;
new = emalloc (maxlen);
len = 0;
old = (unsigned char *)arg->value.str.val;
i = arg->value.str.len;
while (i--) {
if (len + 9 > maxlen)
new = erealloc (new, maxlen += 128);
if (38 == *old) {
memcpy (new + len, "&amp;", 5);
len += 5;
} else if (34 == *old) {
memcpy (new + len, "&quot;", 6);
len += 6;
} else if (60 == *old) {
memcpy (new + len, "&lt;", 4);
len += 4;
} else if (62 == *old) {
memcpy (new + len, "&gt;", 4);
len += 4;
} else if (all && 160 <= *old) {
new [len++] = '&';
strcpy (new + len, EntTable [*old - 160]);
len += strlen (EntTable [*old - 160]);
new [len++] = ';';
} else {
new [len++] = *old;
}
old++;
}
new [len] = '\0';
RETVAL_STRINGL(new,len,1);
efree(new);
}
/* {{{ proto string htmlspecialchars(string string)
Convert special characters to HTML entities */
void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,0);
}
/* }}} */
/* {{{ proto string htmlentities(string string)
Convert all applicable characters to HTML entities */
void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_htmlentities(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

38
ext/standard/html.h Normal file
View file

@ -0,0 +1,38 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _HTML_H
#define _HTML_H
extern void php3_htmlspecialchars(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_htmlentities(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _HTML_H */

386
ext/standard/image.c Normal file
View file

@ -0,0 +1,386 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf |
+----------------------------------------------------------------------+
*/
/* $Id$ */
/*
* Based on Daniel Schmitt's imageinfo.c which carried the following
* Copyright notice.
*/
/*
* imageinfo.c
*
* Simple routines to extract image width/height data from GIF/JPEG files.
*
* Copyright (c) 1997 Daniel Schmitt, opal online publishing, Bonn, Germany.
*
* Includes code snippets from rdjpgcom.c,
* Copyright (c) 1994-1995 Thomas G. Lane
* from release 6a of the Independent JPEG Group's software.
*
* Legal status: see GNU General Public License version 2 or later.
*
*/
#include "php.h"
#include <stdio.h>
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include "fopen-wrappers.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "image.h"
/* file type markers */
const char php3_sig_gif[3] =
{'G', 'I', 'F'};
const char php3_sig_jpg[3] =
{(char) 0xff, (char) 0xd8, (char) 0xff};
const char php3_sig_png[8] =
{(char) 0x89, (char) 0x50, (char) 0x4e,
(char) 0x47, (char) 0x0d, (char) 0x0a,
(char) 0x1a, (char) 0x0a};
/* return info as a struct, to make expansion easier */
struct gfxinfo {
unsigned int width;
unsigned int height;
};
/* routine to handle GIF files. If only everything were that easy... ;} */
static struct gfxinfo *php3_handle_gif (FILE *fp)
{
struct gfxinfo *result = NULL;
unsigned char a[2];
result = (struct gfxinfo *) emalloc(sizeof(struct gfxinfo));
fseek(fp, 6L, SEEK_SET);
fread(a,sizeof(a),1,fp);
result->width = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
fread(a,sizeof(a),1,fp);
result->height = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
return result;
}
static unsigned long php3_read4(FILE *fp)
{
unsigned char a[ 4 ];
/* just return 0 if we hit the end-of-file */
if (fread(a,sizeof(a),1,fp) != 1) return 0;
return (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]);
}
/* routine to handle PNG files. - even easier */
static struct gfxinfo *php3_handle_png(FILE *fp)
{
struct gfxinfo *result = NULL;
unsigned long in_width, in_height;
result = (struct gfxinfo *) emalloc(sizeof(struct gfxinfo));
fseek(fp, 16L, SEEK_SET);
in_width = php3_read4(fp);
in_height = php3_read4(fp);
result->width = (unsigned int) in_width;
result->height = (unsigned int) in_height;
return result;
}
/* routines to handle JPEG data */
/* some defines for the different JPEG block types */
#define M_SOF0 0xC0 /* Start Of Frame N */
#define M_SOF1 0xC1 /* N indicates which compression process */
#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
#define M_SOF3 0xC3
#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
#define M_SOF6 0xC6
#define M_SOF7 0xC7
#define M_SOF9 0xC9
#define M_SOF10 0xCA
#define M_SOF11 0xCB
#define M_SOF13 0xCD
#define M_SOF14 0xCE
#define M_SOF15 0xCF
#define M_SOI 0xD8
#define M_EOI 0xD9 /* End Of Image (end of datastream) */
#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
#define M_APP0 0xe0
#define M_APP1 0xe1
#define M_APP2 0xe2
#define M_APP3 0xe3
#define M_APP4 0xe4
#define M_APP5 0xe5
#define M_APP6 0xe6
#define M_APP7 0xe7
#define M_APP8 0xe8
#define M_APP9 0xe9
#define M_APP10 0xea
#define M_APP11 0xeb
#define M_APP12 0xec
#define M_APP13 0xed
#define M_APP14 0xee
#define M_APP15 0xef
static unsigned short php3_read2(FILE *fp)
{
unsigned char a[ 2 ];
/* just return 0 if we hit the end-of-file */
if (fread(a,sizeof(a),1,fp) != 1) return 0;
return (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]);
}
static unsigned int php3_next_marker(FILE *fp)
/* get next marker byte from file */
{
int c;
/* skip unimportant stuff */
c = getc(fp);
while (c != 0xff) {
if ((c = getc(fp)) == EOF)
return M_EOI; /* we hit EOF */
}
/* get marker byte, swallowing possible padding */
do {
if ((c = getc(fp)) == EOF)
return M_EOI; /* we hit EOF */
} while (c == 0xff);
return (unsigned int) c;
}
static void php3_skip_variable(FILE *fp)
/* skip over a variable-length block; assumes proper length marker */
{
unsigned short length;
length = php3_read2(fp);
length -= 2; /* length includes itself */
fseek(fp, (long) length, SEEK_CUR); /* skip the header */
}
static void php3_read_APP(FILE *fp,unsigned int marker,pval *info)
{
unsigned short length;
unsigned char *buffer;
unsigned char markername[ 16 ];
length = php3_read2(fp);
length -= 2; /* length includes itself */
buffer = emalloc(length);
if (fread(buffer,length,1,fp) != 1) {
return;
}
sprintf(markername,"APP%d",marker - M_APP0);
add_assoc_stringl(info,markername,buffer,length,1);
efree(buffer);
}
static struct gfxinfo *php3_handle_jpeg(FILE *fp,pval *info)
/* main loop to parse JPEG structure */
{
struct gfxinfo *result = NULL;
unsigned int marker;
unsigned short in_width, in_height;
fseek(fp, 0L, SEEK_SET); /* position file pointer on SOF */
if (getc(fp) != 0xFF) /* JPEG header... */
return NULL;
if (getc(fp) != M_SOI) /* JPEG header... */
return NULL;
for (;;) {
marker = php3_next_marker(fp);
switch (marker) {
case M_SOF0:
case M_SOF1:
case M_SOF2:
case M_SOF3:
case M_SOF5:
case M_SOF6:
case M_SOF7:
case M_SOF9:
case M_SOF10:
case M_SOF11:
case M_SOF13:
case M_SOF14:
case M_SOF15:
if (result == NULL) {
/* handle SOFn block */
fseek(fp, 3L, SEEK_CUR); /* skip length and precision bytes */
in_height = php3_read2(fp);
in_width = php3_read2(fp);
/* fill a gfxinfo struct to return the data */
result = (struct gfxinfo *) emalloc(sizeof(struct gfxinfo));
result->width = (unsigned int) in_width;
result->height = (unsigned int) in_height;
if (! info) /* if we don't want an extanded info -> return */
return result;
} else {
php3_skip_variable(fp);
}
break;
case M_APP0:
case M_APP1:
case M_APP2:
case M_APP3:
case M_APP4:
case M_APP5:
case M_APP6:
case M_APP7:
case M_APP8:
case M_APP9:
case M_APP10:
case M_APP11:
case M_APP12:
case M_APP13:
case M_APP14:
case M_APP15:
if (info) {
php3_read_APP(fp,marker,info); /* read all the app markes... */
} else {
php3_skip_variable(fp);
}
break;
case M_SOS:
case M_EOI:
return result; /* we're about to hit image data, or are at EOF. stop processing. */
break;
default:
php3_skip_variable(fp); /* anything else isn't interesting */
break;
}
}
return NULL;
}
/* main function */
void php3_getimagesize(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1,*info = 0;
FILE *fp;
int itype = 0;
char filetype[3];
char pngtype[8];
char temp[64];
struct gfxinfo *result = NULL;
switch(ARG_COUNT(ht)){
case 1:
if (getParameters(ht, 1, &arg1) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg1);
break;
case 2:
if (getParameters(ht, 2, &arg1, &info) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!ParameterPassedByReference(ht, 2)) {
php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
RETURN_FALSE;
}
pval_destructor(info _INLINE_TLS);
if (array_init(info) == FAILURE) {
return;
}
convert_to_string(arg1);
break;
default:
WRONG_PARAM_COUNT;
break;
}
/* Check open_basedir */
if (_php3_check_open_basedir(arg1->value.str.val)) return;
if ((fp = fopen(arg1->value.str.val,"rb")) == 0) {
php3_error(E_WARNING, "Unable to open %s", arg1->value.str.val);
return;
}
fread(filetype,sizeof(filetype),1,fp);
if (!memcmp(filetype, php3_sig_gif, 3)) {
result = php3_handle_gif (fp);
itype = 1;
} else if (!memcmp(filetype, php3_sig_jpg, 3)) {
result = php3_handle_jpeg(fp,info);
itype = 2;
} else if (!memcmp(filetype, php3_sig_png, 3)) {
fseek(fp, 0L, SEEK_SET);
fread(pngtype, sizeof(pngtype), 1, fp);
if (!memcmp(pngtype, php3_sig_png, 8)) {
result = php3_handle_png(fp);
itype = 3;
} else {
php3_error(E_WARNING, "PNG file corrupted by ASCII conversion");
}
}
fclose(fp);
if (result) {
if (array_init(return_value) == FAILURE) {
php3_error(E_ERROR, "Unable to initialize array");
if (result) efree(result);
return;
}
add_index_long(return_value, 0, result->width);
add_index_long(return_value, 1, result->height);
add_index_long(return_value, 2, itype);
sprintf(temp, "width=\"%d\" height=\"%d\"", result->width, result->height); /* safe */
add_index_string(return_value, 3, temp, 1);
efree(result);
}
}

36
ext/standard/image.h Normal file
View file

@ -0,0 +1,36 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _IMAGE_H
#define _IMAGE_H
extern void php3_getimagesize(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _IMAGE_H */

438
ext/standard/info.c Normal file
View file

@ -0,0 +1,438 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "php_globals.h"
#include "head.h"
#include "info.h"
#ifndef MSVC5
#include "build-defs.h"
#endif
#include "zend_globals.h" /* needs ELS */
#define PHP3_CONF_STR(directive,value1,value2) \
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">"); \
PUTS(directive); \
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">&nbsp;"); \
if (value1) PUTS(value1); \
else PUTS("<i>none</i>"); \
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">&nbsp;"); \
if (value2) PUTS(value2); \
else PUTS("<i>none</i>"); \
PUTS("</td></tr>\n");
#define PHP3_CONF_LONG(directive,value1,value2) \
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">%s</td><td bgcolor=\"" CONTENTS_COLOR "\">%ld</td><td bgcolor=\"" CONTENTS_COLOR "\">%ld</td></tr>\n",directive,value1,value2);
extern char **environ;
#define SECTION(name) PUTS("<hr><h2>" name "</h2>\n")
#define ENTRY_NAME_COLOR "#999999"
#define CONTENTS_COLOR "#DDDDDD"
#define HEADER_COLOR "#00DDDD"
static int _display_module_info(php3_module_entry *module)
{
PUTS("<tr><th align=left bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS(module->name);
PUTS("</th><td bgcolor=\"" CONTENTS_COLOR "\">");
if (module->info_func) {
module->info_func();
} else {
PUTS("No additional information.");
}
PUTS("</td></tr>\n");
return 0;
}
void _php3_info(void)
{
char **env,*tmp1,*tmp2;
char *php3_uname;
#if WIN32|WINNT
char php3_windows_uname[256];
DWORD dwBuild=0;
DWORD dwVersion = GetVersion();
DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion)));
#endif
ELS_FETCH();
PLS_FETCH();
#if WIN32|WINNT
// Get build numbers for Windows NT or Win95
if (dwVersion < 0x80000000){
dwBuild = (DWORD)(HIWORD(dwVersion));
snprintf(php3_windows_uname,255,"%s %d.%d build %d","Windows NT",dwWindowsMajorVersion,dwWindowsMinorVersion,dwBuild);
} else {
snprintf(php3_windows_uname,255,"%s %d.%d","Windows 95/98",dwWindowsMajorVersion,dwWindowsMinorVersion);
}
php3_uname = php3_windows_uname;
#else
php3_uname=PHP_UNAME;
#endif
PUTS("<img src=\"?=PHPE9568F34-D428-11d2-A769-00AA001ACF42\" border=\"0\" width=\"100\" height=\"56\" align=\"right\">\n");
php3_printf("<center><h1>PHP Version %s</h1></center>\n", PHP_VERSION);
PUTS("<p>by <a href=\"mailto:rasmus@lerdorf.on.ca\">Rasmus Lerdorf</a>,\n");
PUTS("<a href=\"mailto:andi@zend.com\">Andi Gutmans</a>,\n");
PUTS("<a href=\"mailto:zeev@zend.com\">Zeev Suraski</a>,\n");
PUTS("<a href=\"mailto:ssb@guardian.no\">Stig Bakken</a>,\n");
PUTS("<a href=\"mailto:shane@caraveo.com\">Shane Caraveo</a>,\n");
PUTS("<a href=\"mailto:jimw@php.net\">Jim Winstead</a>, and countless others.</P>\n");
PUTS("<P><a href=\"http://www.zend.com/\">Zend</a>:</a> ");
PUTS("<a href=\"mailto:andi@zend.com\">Andi Gutmans</a> and \n");
PUTS("<a href=\"mailto:zeev@zend.com\">Zeev Suraski</a></p>\n");
PUTS("<hr>");
php3_printf("<center>System: %s<br>Build Date: %s</center>\n", php3_uname, __DATE__);
PUTS("<center>\n");
SECTION("Extensions");
PUTS("<table border=5 width=\"600\">\n");
PUTS("<tr><th bgcolor=\"" HEADER_COLOR "\">Extensions</th><th bgcolor=\"" HEADER_COLOR "\">Additional Information</th></tr>\n");
#ifndef MSVC5
PUTS("<tr><th align=left bgcolor=\"" ENTRY_NAME_COLOR "\">PHP core</th>\n");
PUTS("<td bgcolor=\"" CONTENTS_COLOR "\"><tt>CFLAGS=" PHP_CFLAGS "<br>\n");
PUTS("HSREGEX=" PHP_HSREGEX "</td></tr>\n");
#endif
_php3_hash_apply(&GLOBAL(module_registry),(int (*)(void *))_display_module_info);
PUTS("</table>\n");
SECTION("Configuration");
PUTS("php3.ini file path is set to: ");
PUTS(CONFIGURATION_FILE_PATH);
PUTS("<br>\n");
PUTS("<table border=5 width=\"600\">\n");
PUTS("<tr><th bgcolor=\"" HEADER_COLOR "\">Directive</th><th bgcolor=\"" HEADER_COLOR "\">Master Value</th><th bgcolor=\"" HEADER_COLOR "\">Local Value</th></tr>\n");
PHP3_CONF_STR("arg_separator", INI_ORIG_STR("arg_separator"), PG(arg_separator));
PHP3_CONF_LONG("asp_tags", INI_ORIG_INT("asp_tags"), PG(asp_tags));
PHP3_CONF_STR("auto_prepend_file", INI_ORIG_STR("auto_prepend_file"), PG(auto_prepend_file));
PHP3_CONF_STR("auto_append_file", INI_ORIG_STR("auto_append_file"), PG(auto_append_file));
PHP3_CONF_STR("browscap", INI_ORIG_STR("browscap"), INI_STR("browscap"));
PHP3_CONF_LONG("define_syslog_variables", INI_ORIG_STR("define_syslog_variables"), INI_STR("define_syslog_variables"));
PHP3_CONF_LONG("display_errors", INI_ORIG_INT("display_errors"), PG(display_errors));
PHP3_CONF_STR("doc_root", INI_ORIG_STR("doc_root"), PG(doc_root));
PHP3_CONF_LONG("enable_dl", INI_ORIG_INT("enable_dl"), PG(enable_dl));
PHP3_CONF_STR("error_log", INI_ORIG_STR("error_log"), PG(error_log));
PHP3_CONF_STR("error_prepend_string", INI_ORIG_STR("error_prepend_string"), INI_STR("error_prepend_string"));
PHP3_CONF_STR("error_append_string", INI_ORIG_STR("error_append_string"), INI_STR("error_append_string"));
PHP3_CONF_LONG("error_reporting", INI_ORIG_INT("error_reporting"), EG(error_reporting));
PHP3_CONF_STR("extension_dir", INI_ORIG_STR("extension_dir"), PG(extension_dir));
PHP3_CONF_STR("gpc_order", INI_ORIG_STR("gpc_order"), PG(gpc_order));
PHP3_CONF_STR("include_path", INI_ORIG_STR("include_path"), PG(include_path));
PHP3_CONF_LONG("log_errors", INI_ORIG_INT("log_errors"), PG(log_errors));
PHP3_CONF_LONG("max_execution_time", INI_ORIG_INT("max_execution_time"), PG(max_execution_time));
PHP3_CONF_LONG("magic_quotes_gpc", INI_ORIG_INT("magic_quotes_gpc"), PG(magic_quotes_gpc));
PHP3_CONF_LONG("magic_quotes_runtime", INI_ORIG_INT("magic_quotes_runtime"), PG(magic_quotes_runtime));
PHP3_CONF_LONG("magic_quotes_sybase", INI_ORIG_INT("magic_quotes_sybase"), PG(magic_quotes_sybase));
PHP3_CONF_LONG("memory limit", INI_ORIG_INT("memory_limit"), PG(memory_limit));
PHP3_CONF_STR("open_basedir", INI_ORIG_STR("open_basedir"), PG(open_basedir));
PHP3_CONF_LONG("precision", INI_ORIG_INT("precision"), EG(precision));
PHP3_CONF_LONG("safe_mode", INI_ORIG_INT("safe_mode"), PG(safe_mode));
PHP3_CONF_STR("safe_mode_exec_dir", INI_ORIG_STR("safe_mode_exec_dir"), PG(safe_mode_exec_dir));
PHP3_CONF_STR("sendmail_from", INI_ORIG_STR("sendmail_from"), INI_STR("sendmail_from"));
PHP3_CONF_STR("sendmail_path", INI_ORIG_STR("sendmail_path"), INI_STR("sendmail_path"));
PHP3_CONF_LONG("short_open_tag", INI_ORIG_INT("short_open_tag"), PG(short_tags));
PHP3_CONF_STR("SMTP", INI_ORIG_STR("SMTP"), INI_STR("SMTP"));
PHP3_CONF_LONG("sql_safe_mode", INI_ORIG_INT("sql.safe_mode"), PG(sql_safe_mode));
PHP3_CONF_LONG("track_errors", INI_ORIG_INT("track_errors"), PG(track_errors));
PHP3_CONF_LONG("track_vars", INI_ORIG_INT("track_vars"), PG(track_vars));
PHP3_CONF_LONG("upload_max_filesize", INI_ORIG_INT("upload_max_filesize"), PG(upload_max_filesize));
PHP3_CONF_STR("upload_tmp_dir", INI_ORIG_STR("upload_tmp_dir"), PG(upload_tmp_dir));
PHP3_CONF_STR("user_dir", INI_ORIG_STR("user_dir"), PG(user_dir));
PHP3_CONF_LONG("y2k_compliance", INI_ORIG_INT("y2k_compliance"), PG(y2k_compliance));
/* apache only directives */
PHP3_CONF_LONG("engine", INI_ORIG_INT("engine"), INI_INT("engine")); /* apache only */
PHP3_CONF_LONG("xbithack", INI_ORIG_INT("xbithack"), INI_INT("xbithack")); /* apache only */
PHP3_CONF_LONG("last_modified", INI_ORIG_INT("last_modified"), INI_INT("last_modified")); /* apache only */
/* end of apache only directives */
/* And now for the highlight colours */
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_comment</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.comment"), INI_ORIG_STR("highlight.comment"), INI_STR("highlight.comment"), INI_STR("highlight.comment"));
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_default</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.default"), INI_ORIG_STR("highlight.default"), INI_STR("highlight.default"), INI_STR("highlight.default"));
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_html</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.html"), INI_ORIG_STR("highlight.html"), INI_STR("highlight.html"), INI_STR("highlight.html"));
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_string</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.string"), INI_ORIG_STR("highlight.string"), INI_STR("highlight.string"), INI_STR("highlight.string"));
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_bg</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.bg"), INI_ORIG_STR("highlight.bg"), INI_STR("highlight.bg"), INI_STR("highlight.bg"));
php3_printf("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">highlight_keyword</td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td><td bgcolor=\"" CONTENTS_COLOR "\"><font color=%s>&nbsp;%s</font></td></tr>\n",INI_ORIG_STR("highlight.keyword"), INI_ORIG_STR("highlight.keyword"), INI_STR("highlight.keyword"), INI_STR("highlight.keyword"));
PUTS("</table>");
#if USE_SAPI /* call a server module specific info function */
GLOBAL(sapi_rqst)->info(GLOBAL(sapi_rqst));
#endif
SECTION("Environment");
PUTS("<table border=5 width=\"600\">\n");
PUTS("<tr><th bgcolor=\"" HEADER_COLOR "\">Variable</th><th bgcolor=\"" HEADER_COLOR "\">Value</th></tr>\n");
for (env=environ; env!=NULL && *env !=NULL; env++) {
tmp1 = estrdup(*env);
if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
efree(tmp1);
continue;
}
*tmp2 = 0;
tmp2++;
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS(tmp1);
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
if (tmp2 && *tmp2) {
PUTS(tmp2);
} else {
PUTS("&nbsp;");
}
PUTS("</td></tr>\n");
efree(tmp1);
}
PUTS("</table>\n");
{
pval **data, **tmp;
char *string_key;
ulong num_key;
SECTION("PHP Variables");
PUTS("<table border=5 width=\"600\">\n");
PUTS("<tr><th bgcolor=\"" HEADER_COLOR "\">Variable</th><th bgcolor=\"" HEADER_COLOR "\">Value</th></tr>\n");
if (_php3_hash_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF"), (void **) &data) != FAILURE) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS("PHP_SELF");
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*data)->value.str.val);
PUTS("</td></tr>\n");
}
if (_php3_hash_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE"), (void **) &data) != FAILURE) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS("PHP_AUTH_TYPE");
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*data)->value.str.val);
PUTS("</td></tr>\n");
}
if (_php3_hash_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &data) != FAILURE) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS("PHP_AUTH_USER");
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*data)->value.str.val);
PUTS("</td></tr>\n");
}
if (_php3_hash_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &data) != FAILURE) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS("PHP_AUTH_PW");
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*data)->value.str.val);
PUTS("</td></tr>\n");
}
if (_php3_hash_find(&EG(symbol_table), "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"), (void **) &data) != FAILURE) {
_php3_hash_internal_pointer_reset((*data)->value.ht);
while (_php3_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) {
convert_to_string(*tmp);
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">HTTP_GET_VARS[\"");
switch (_php3_hash_get_current_key((*data)->value.ht, &string_key, &num_key)) {
case HASH_KEY_IS_STRING:
PUTS(string_key);
break;
case HASH_KEY_IS_LONG:
php3_printf("%ld",num_key);
break;
}
PUTS("\"]</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*tmp)->value.str.val); /* This could be "Array" - too ugly to expand that for now */
PUTS("</td></tr>\n");
_php3_hash_move_forward((*data)->value.ht);
}
}
if (_php3_hash_find(&EG(symbol_table), "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"), (void **) &data) != FAILURE) {
_php3_hash_internal_pointer_reset((*data)->value.ht);
while (_php3_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) {
convert_to_string(*tmp);
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">HTTP_POST_VARS[\"");
switch (_php3_hash_get_current_key((*data)->value.ht, &string_key, &num_key)) {
case HASH_KEY_IS_STRING:
PUTS(string_key);
break;
case HASH_KEY_IS_LONG:
php3_printf("%ld",num_key);
break;
}
PUTS("\"]</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*tmp)->value.str.val);
PUTS("</td></tr>\n");
_php3_hash_move_forward((*data)->value.ht);
}
}
if (_php3_hash_find(&EG(symbol_table), "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"), (void **) &data) != FAILURE) {
_php3_hash_internal_pointer_reset((*data)->value.ht);
while (_php3_hash_get_current_data((*data)->value.ht, (void **) &tmp) == SUCCESS) {
convert_to_string(*tmp);
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">HTTP_COOKIE_VARS[\"");
switch (_php3_hash_get_current_key((*data)->value.ht, &string_key, &num_key)) {
case HASH_KEY_IS_STRING:
PUTS(string_key);
break;
case HASH_KEY_IS_LONG:
php3_printf("%ld",num_key);
break;
}
PUTS("\"]</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS((*tmp)->value.str.val);
PUTS("</td></tr>\n");
_php3_hash_move_forward((*data)->value.ht);
}
}
PUTS("</table>\n");
}
#if APACHE
{
register int i;
array_header *arr = table_elts(GLOBAL(php3_rqst)->subprocess_env);
table_entry *elts = (table_entry *)arr->elts;
SECTION("Apache Environment");
PUTS("<table border=5 width=\"600\">\n");
PUTS("<tr><th bgcolor=\"" HEADER_COLOR "\">Variable</th><th bgcolor=\"" HEADER_COLOR "\">Value</th></tr>\n");
for (i=0; i < arr->nelts; i++) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS(elts[i].key);
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS(elts[i].val);
PUTS("&nbsp;</td></tr>\n");
}
PUTS("</table>\n");
}
#endif
#if APACHE
{
array_header *env_arr;
table_entry *env;
int i;
SECTION("HTTP Headers Information");
PUTS("<table border=5 width=\"600\">\n");
PUTS(" <tr><th colspan=2 bgcolor=\"" HEADER_COLOR "\">HTTP Request Headers</th></tr>\n");
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">HTTP Request</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS(GLOBAL(php3_rqst)->the_request);
PUTS("&nbsp;</td></tr>\n");
env_arr = table_elts(GLOBAL(php3_rqst)->headers_in);
env = (table_entry *)env_arr->elts;
for (i = 0; i < env_arr->nelts; ++i) {
if (env[i].key) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS(env[i].key);
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS(env[i].val);
PUTS("&nbsp;</td></tr>\n");
}
}
PUTS(" <tr><th colspan=2 bgcolor=\"" HEADER_COLOR "\">HTTP Response Headers</th></tr>\n");
env_arr = table_elts(GLOBAL(php3_rqst)->headers_out);
env = (table_entry *)env_arr->elts;
for(i = 0; i < env_arr->nelts; ++i) {
if (env[i].key) {
PUTS("<tr><td bgcolor=\"" ENTRY_NAME_COLOR "\">");
PUTS(env[i].key);
PUTS("</td><td bgcolor=\"" CONTENTS_COLOR "\">");
PUTS(env[i].val);
PUTS("&nbsp;</td></tr>\n");
}
}
PUTS("</table>\n\n");
}
#endif
PUTS("</center>");
PUTS("<hr>\n");
PUTS("<table width=\"100%%\"><tr>\n");
php3_printf("<td><h2>Zend</h2>This program makes use of the Zend scripting language engine:<br><pre>%s</pre></td>", get_zend_version());
PUTS("<td width=\"100\"><a href=\"http://www.zend.com/\"><img src=\"?=PHPE9568F35-D428-11d2-A769-00AA001ACF42\" border=\"0\" width=\"100\" height=\"89\"></a></td>\n");
PUTS("</tr></table>\n");
SECTION("PHP License");
PUTS("<PRE>This program is free software; you can redistribute it and/or modify\n");
PUTS("it under the terms of:\n");
PUTS("\n");
PUTS("A) the GNU General Public License as published by the Free Software\n");
PUTS(" Foundation; either version 2 of the License, or (at your option)\n");
PUTS(" any later version.\n");
PUTS("\n");
PUTS("B) the PHP License as published by the PHP Development Team and\n");
PUTS(" included in the distribution in the file: LICENSE\n");
PUTS("\n");
PUTS("This program is distributed in the hope that it will be useful,\n");
PUTS("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
PUTS("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n");
PUTS("GNU General Public License for more details.\n");
PUTS("\n");
PUTS("You should have received a copy of both licenses referred to here.\n");
PUTS("If you did not, or have any questions about PHP licensing, please\n");
PUTS("contact core@php.net.</PRE>\n");
}
/* {{{ proto void phpinfo(void)
Output a page of useful information about PHP and the current request */
void php3_info(INTERNAL_FUNCTION_PARAMETERS)
{
TLS_VARS;
_php3_info();
RETURN_TRUE;
}
/* }}} */
/* {{{ proto string phpversion(void)
Return the current PHP version */
void php3_version(INTERNAL_FUNCTION_PARAMETERS)
{
TLS_VARS;
RETURN_STRING(PHP_VERSION,1);
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

40
ext/standard/info.h Normal file
View file

@ -0,0 +1,40 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _INFO_H
#define _INFO_H
extern void php3_version(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_info(INTERNAL_FUNCTION_PARAMETERS);
extern void _php3_info(void);
#endif /* _INFO_H */

132
ext/standard/iptc.c Normal file
View file

@ -0,0 +1,132 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Thies C. Arntzen (thies@digicol.de) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
/*
* Functions to parse & compse IPTC data.
* PhotoShop >= 3.0 can read and write textual data to JPEG files.
* ... more to come .....
*/
/*
* TODO:
* - add IPTC translation table
* - implement a call to embed iptc into a JPEG file
*/
#include "php.h"
#include "php3_iptc.h"
void php3_iptcparse(INTERNAL_FUNCTION_PARAMETERS)
{
unsigned int length, inx, len, inheader, tagsfound;
unsigned char *buffer;
unsigned char recnum, dataset;
unsigned char key[ 16 ];
pval values, *str, *element;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &str) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(str);
inx = 0;
length = str->value.str.len;
buffer = str->value.str.val;
inheader = 0; /* have we already found the IPTC-Header??? */
tagsfound = 0; /* number of tags already found */
while (inx < length) {
if (buffer[ inx++ ] != 0x1c) { /* skip all junk */
if (inheader) {
break; /* we ran against some data which does not conform to IPTC - stop parsing! */
} else {
continue;
}
} else {
inheader = 1;
}
if ((inx + 4) >= length)
break;
dataset = buffer[ inx++ ];
recnum = buffer[ inx++ ];
if (buffer[ inx ] & (unsigned char) 0x80) {
len = (((long) buffer[ inx + 2 ]) << 24) + (((long) buffer[ inx + 3 ]) << 16) +
(((long) buffer[ inx + 4 ]) << 8) + (((long) buffer[ inx + 5 ]));
inx += 6;
} else {
len = (((unsigned short) buffer[ inx ])<<8) | (unsigned short)buffer[ inx+1 ];
inx += 2;
}
sprintf(key,"%d#%03d",(unsigned int) dataset,(unsigned int) recnum);
if ((inx + len) > length)
break;
if (tagsfound == 0) { /* found the 1st tag - initialize the return array */
if (array_init(return_value) == FAILURE) {
php3_error(E_ERROR, "Unable to initialize array");
RETURN_FALSE;
}
}
if (_php3_hash_find(return_value->value.ht,key,strlen(key) + 1,(void **) &element) == FAILURE) {
if (array_init(&values) == FAILURE) {
php3_error(E_ERROR, "Unable to initialize array");
RETURN_FALSE;
}
_php3_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:
*/

214
ext/standard/link.c Normal file
View file

@ -0,0 +1,214 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "php3_filestat.h"
#include "php_globals.h"
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <string.h>
#if HAVE_PWD_H
#if MSVC5
#include "win32/pwd.h"
#else
#include <pwd.h>
#endif
#endif
#if HAVE_GRP_H
#if MSVC5
#include "win32/grp.h"
#else
#include <grp.h>
#endif
#endif
#include <errno.h>
#include <ctype.h>
#include "safe_mode.h"
#include "php3_link.h"
/* {{{ proto string readlink(string filename)
Return the target of a symbolic link */
void php3_readlink(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_SYMLINK
pval *filename;
char buff[256];
int ret;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &filename) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
ret = readlink(filename->value.str.val, buff, 255);
if (ret == -1) {
php3_error(E_WARNING, "readlink failed (%s)", strerror(errno));
RETURN_FALSE;
}
/* Append NULL to the end of the string */
buff[ret] = '\0';
RETURN_STRING(buff,1);
#endif
}
/* }}} */
/* {{{ proto int linkinfo(string filename)
Returns the st_dev field of the UNIX C stat structure describing the link */
void php3_linkinfo(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_SYMLINK
pval *filename;
struct stat sb;
int ret;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &filename) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
ret = lstat(filename->value.str.val, &sb);
if (ret == -1) {
php3_error(E_WARNING, "LinkInfo failed (%s)", strerror(errno));
RETURN_LONG(-1L);
}
RETURN_LONG((long) sb.st_dev);
#endif
}
/* }}} */
/* {{{ proto int symlink(string target, string link)
Create a symbolic link */
void php3_symlink(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_SYMLINK
pval *topath, *frompath;
int ret;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &topath, &frompath) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(topath);
convert_to_string(frompath);
if (PG(safe_mode) && !_php3_checkuid(topath->value.str.val, 2)) {
RETURN_FALSE;
}
ret = symlink(topath->value.str.val, frompath->value.str.val);
if (ret == -1) {
php3_error(E_WARNING, "SymLink failed (%s)", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
#endif
}
/* }}} */
/* {{{ proto int link(string target, string link)
Create a hard link */
void php3_link(INTERNAL_FUNCTION_PARAMETERS)
{
#if HAVE_LINK
pval *topath, *frompath;
int ret;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &topath, &frompath) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(topath);
convert_to_string(frompath);
if (PG(safe_mode) && !_php3_checkuid(topath->value.str.val, 2)) {
RETURN_FALSE;
}
ret = link(topath->value.str.val, frompath->value.str.val);
if (ret == -1) {
php3_error(E_WARNING, "Link failed (%s)", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
#endif
}
/* }}} */
/* {{{ proto int unlink(string filename)
Delete a file */
void php3_unlink(INTERNAL_FUNCTION_PARAMETERS)
{
pval *filename;
int ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &filename) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(filename);
if (PG(safe_mode) && !_php3_checkuid(filename->value.str.val, 2)) {
RETURN_FALSE;
}
ret = unlink(filename->value.str.val);
if (ret == -1) {
php3_error(E_WARNING, "Unlink failed (%s)", strerror(errno));
RETURN_FALSE;
}
/* Clear stat cache */
php3_clearstatcache(INTERNAL_FUNCTION_PARAM_PASSTHRU);
RETURN_TRUE;
}
/* }}} */
function_entry link_functions[] = {
{"readlink", php3_readlink, NULL},
{"linkinfo", php3_linkinfo, NULL},
{"symlink", php3_symlink, NULL},
{"link", php3_link, NULL},
{"unlink", php3_unlink, NULL},
{NULL, NULL, NULL}
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

188
ext/standard/mail.c Normal file
View file

@ -0,0 +1,188 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#ifndef MSVC5
#include "build-defs.h"
#endif
#include "php3_mail.h"
#include "php_ini.h"
#if APACHE
# ifndef DEBUG
# undef palloc
# endif
#endif
#if HAVE_SENDMAIL
#if MSVC5
#include "win32/sendmail.h"
#endif
function_entry mail_functions[] = {
{"mail", php3_mail, NULL},
{NULL, NULL, NULL}
};
php3_module_entry mail_module_entry = {
"Sendmail", mail_functions, NULL, NULL, NULL, NULL, php3_info_mail, STANDARD_MODULE_PROPERTIES
};
#if COMPILE_DL
DLEXPORT php3_module_entry *get_module(void) { return &odbc_module_entry; }
#endif
/* {{{ proto int mail(string to, string subject, string message [, string additional_headers])
Send an email message */
void php3_mail(INTERNAL_FUNCTION_PARAMETERS)
{
pval *argv[4];
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL;
int argc;
TLS_VARS;
argc = ARG_COUNT(ht);
if (argc < 3 || argc > 4 || getParametersArray(ht, argc, argv) == FAILURE) {
WRONG_PARAM_COUNT;
}
/* To: */
convert_to_string(argv[0]);
if (argv[0]->value.str.val) {
to = argv[0]->value.str.val;
} else {
php3_error(E_WARNING, "No to field in mail command");
RETURN_FALSE;
}
/* Subject: */
convert_to_string(argv[1]);
if (argv[1]->value.str.val) {
subject = argv[1]->value.str.val;
} else {
php3_error(E_WARNING, "No subject field in mail command");
RETURN_FALSE;
}
/* message body */
convert_to_string(argv[2]);
if (argv[2]->value.str.val) {
message = argv[2]->value.str.val;
} else {
/* this is not really an error, so it is allowed. */
php3_error(E_WARNING, "No message string in mail command");
message = NULL;
}
if (argc == 4) { /* other headers */
convert_to_string(argv[3]);
headers = argv[3]->value.str.val;
}
if (_php3_mail(to, subject, message, headers)){
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}
/* }}} */
int _php3_mail(char *to, char *subject, char *message, char *headers)
{
#if MSVC5
int tsm_err;
#else
FILE *sendmail;
int ret;
char *sendmail_path = INI_STR("sendmail_path");
#endif
#if MSVC5
if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
php3_error(E_WARNING, GetSMErrorText(tsm_err));
return 0;
}
#else
if (!sendmail_path) {
return 0;
}
sendmail = popen(sendmail_path, "w");
if (sendmail) {
fprintf(sendmail, "To: %s\n", to);
fprintf(sendmail, "Subject: %s\n", subject);
if (headers != NULL) {
fprintf(sendmail, "%s\n", headers);
}
fprintf(sendmail, "\n%s\n", message);
ret = pclose(sendmail);
if (ret == -1) {
return 0;
} else {
return 1;
}
} else {
php3_error(E_WARNING, "Could not execute mail delivery program");
return 0;
}
#endif
return 1;
}
void php3_info_mail(void)
{
#if MSVC5
PUTS("Internal Sendmail support for Windows 4");
#else
php3_printf("Path to sendmail: <tt>%s</tt>", INI_STR("sendmail_path"));
#endif
}
#else
void php3_mail(INTERNAL_FUNCTION_PARAMETERS) {}
void php3_info_mail() {}
#endif
/*
* Local variables:
* tab-width: 4
* End:
*/

708
ext/standard/math.c Normal file
View file

@ -0,0 +1,708 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jim Winstead (jimw@php.net) |
| Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "phpmath.h"
#include "snprintf.h"
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
char *_php3_number_format(double, int, char ,char);
/* {{{ proto int abs(int number)
Return the absolute value of the number */
void php3_abs(INTERNAL_FUNCTION_PARAMETERS) {
pval *value;
TLS_VARS;
if (ARG_COUNT(ht)!=1||getParameters(ht,1,&value)==FAILURE) {
WRONG_PARAM_COUNT;
}
if (value->type == IS_STRING) {
convert_scalar_to_number(value);
}
if (value->type == IS_DOUBLE) {
RETURN_DOUBLE(fabs(value->value.dval));
}
else if (value->type == IS_LONG) {
RETURN_LONG(labs(value->value.lval));
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto int ceil(double number)
Returns the next highest integer value of the number */
void php3_ceil(INTERNAL_FUNCTION_PARAMETERS) {
pval *value;
TLS_VARS;
if (ARG_COUNT(ht)!=1||getParameters(ht,1,&value)==FAILURE) {
WRONG_PARAM_COUNT;
}
if (value->type == IS_STRING) {
convert_scalar_to_number(value);
}
if (value->type == IS_DOUBLE) {
RETURN_LONG((long)ceil(value->value.dval));
}
else if (value->type == IS_LONG) {
RETURN_LONG(value->value.lval);
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto int floor(double number)
Returns the next lowest integer value from the number */
void php3_floor(INTERNAL_FUNCTION_PARAMETERS) {
pval *value;
TLS_VARS;
if (ARG_COUNT(ht)!=1||getParameters(ht,1,&value)==FAILURE) {
WRONG_PARAM_COUNT;
}
if (value->type == IS_STRING) {
convert_scalar_to_number(value);
}
if (value->type == IS_DOUBLE) {
RETURN_LONG((long)floor(value->value.dval));
}
else if (value->type == IS_LONG) {
RETURN_LONG(value->value.lval);
}
RETURN_FALSE;
}
/* }}} */
#ifndef HAVE_RINT
/* emulate rint */
inline double rint(double n)
{
double i, f;
f = modf(n, &i);
if (f > .5)
i++;
else if (f < -.5)
i--;
return i;
}
#endif
/* {{{ proto int round(double number)
Returns the rounded value of the number */
void php3_round(INTERNAL_FUNCTION_PARAMETERS)
{
pval *value;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &value) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (value->type == IS_STRING) {
convert_scalar_to_number(value);
}
if (value->type == IS_DOUBLE) {
RETURN_DOUBLE(rint(value->value.dval));
}
if (value->type == IS_LONG) {
RETURN_DOUBLE((double)value->value.lval);
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto double sin(double number)
Returns the sine of the number in radians */
void php3_sin(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = sin(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double cos(double number)
Returns the cosine of the number in radians */
void php3_cos(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = cos(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double tan(double number)
Returns the tangent of the number in radians */
void php3_tan(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = tan(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double asin(double number)
Returns the arc sine of the number in radians */
void php3_asin(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = asin(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double acos(double number)
Return the arc cosine of the number in radians */
void php3_acos(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = acos(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double atan(double number)
Returns the arc tangent of the number in radians */
void php3_atan(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = atan(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double atan2(double y, double x)
Returns the arc tangent of y/x, with the resulting quadrant determined by the signs of y and x */
void php3_atan2(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num1, *num2;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &num1, &num2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num1);
convert_to_double(num2);
return_value->value.dval = atan2(num1->value.dval,num2->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double pi(void)
Returns an approximation of pi */
void php3_pi(INTERNAL_FUNCTION_PARAMETERS)
{
return_value->value.dval = M_PI;
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double pow(double base, double exponent)
Returns base raised to the power of expopent */
void php3_pow(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num1, *num2;
TLS_VARS;
if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&num1,&num2) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num1);
convert_to_double(num2);
RETURN_DOUBLE(pow(num1->value.dval, num2->value.dval));
}
/* }}} */
/* {{{ proto double exp(double number)
Returns e raised to the power of the number */
void php3_exp(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = exp(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double log(double number)
Returns the natural logarithm of the number */
void php3_log(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = log(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double log10(double number)
Returns the base-10 logarithm of the number */
void php3_log10(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = log10(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double sqrt(double number)
Returns the square root of the number */
void php3_sqrt(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &num) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(num);
return_value->value.dval = sqrt(num->value.dval);
return_value->type = IS_DOUBLE;
}
/* }}} */
/* {{{ proto double deg2rad(double number)
Converts the number in degrees to the radian equivalent */
void php3_deg2rad(INTERNAL_FUNCTION_PARAMETERS)
{
pval *deg;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &deg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(deg);
RETVAL_DOUBLE((deg->value.dval / 180.0) * M_PI);
}
/* }}} */
/* {{{ proto double rad2deg(double number)
Converts the radian number to the equivalent number in degrees */
void php3_rad2deg(INTERNAL_FUNCTION_PARAMETERS)
{
pval *rad;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &rad) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_double(rad);
RETVAL_DOUBLE((rad->value.dval / M_PI) * 180);
}
/* }}} */
/*
* Convert a string representation of a base(2-36) number to a long.
*/
static long
_php3_basetolong(pval *arg, int base) {
long mult = 1, num = 0, digit;
int i;
char c, *s;
if (arg->type != IS_STRING || base < 2 || base > 36) {
return 0;
}
s = arg->value.str.val;
for (i = arg->value.str.len - 1; i >= 0; i--, mult *= base) {
c = toupper(s[i]);
if (c >= '0' && c <= '9') {
digit = (c - '0');
} else if (c >= 'A' && c <= 'Z') {
digit = (c - 'A' + 10);
} else {
continue;
}
if (digit >= base) {
continue;
}
num += mult * digit;
}
return num;
}
/*
* Convert a long to a string containing a base(2-36) representation of
* the number.
*/
static char *
_php3_longtobase(pval *arg, int base)
{
static char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char *result, *ptr, *ret;
int len, digit;
long value;
if (arg->type != IS_LONG || base < 2 || base > 36) {
return empty_string;
}
value = arg->value.lval;
/* allocates space for the longest possible result with the lowest base */
len = (sizeof(arg->value.lval) * 8) + 1;
result = emalloc((sizeof(arg->value.lval) * 8) + 1);
ptr = result + len - 1;
*ptr-- = '\0';
do {
digit = value % base;
*ptr = digits[digit];
value /= base;
}
while (ptr-- > result && value);
ptr++;
ret = estrdup(ptr);
efree(result);
return ret;
}
/* {{{ proto int bindec(string binary_number)
Returns the decimal equivalent of the binary number */
void php3_bindec(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
long ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
ret = _php3_basetolong(arg, 2);
RETVAL_LONG(ret);
}
/* }}} */
/* {{{ proto int hexdec(string hexadimal_number)
Returns the decimal equivalent of the hexadecimal number */
void php3_hexdec(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
long ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
ret = _php3_basetolong(arg, 16);
RETVAL_LONG(ret);
}
/* }}} */
/* {{{ proto int octdec(string octal_number)
Returns the decimal equivalent of an octal string */
void php3_octdec(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
long ret;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
ret = _php3_basetolong(arg, 8);
RETVAL_LONG(ret);
}
/* }}} */
/* {{{ proto string decbin(int decimal_number)
Returns a string containing a binary representation of the number */
void php3_decbin(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char *result;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg);
result = _php3_longtobase(arg, 2);
return_value->type = IS_STRING;
return_value->value.str.len = strlen(result);
return_value->value.str.val = result;
}
/* }}} */
/* {{{ proto string decoct(int decimal_number)
Returns a string containing an octal representation of the given number */
void php3_decoct(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char *result;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg);
result = _php3_longtobase(arg, 8);
return_value->type = IS_STRING;
return_value->value.str.len = strlen(result);
return_value->value.str.val = result;
}
/* }}} */
/* {{{ proto string dechex(int decimal_number)
Returns a string containing a hexadecimal representation of the given number */
void php3_dechex(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char *result;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg);
result = _php3_longtobase(arg, 16);
return_value->type = IS_STRING;
return_value->value.str.len = strlen(result);
return_value->value.str.val = result;
}
/* }}} */
/* {{{ proto string base_convert(string number, int frombase, int tobase)
Converts a number in a string from any base <= 36 to any base <= 36.
*/
void php3_base_convert(INTERNAL_FUNCTION_PARAMETERS)
{
pval *number, *frombase, *tobase, temp;
char *result;
if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &number, &frombase, &tobase)
== FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(number);
convert_to_long(frombase);
convert_to_long(tobase);
if (frombase->value.lval < 2 || frombase->value.lval > 36) {
php3_error(E_WARNING, "base_convert: invalid `from base' (%d)",
frombase->value.lval);
RETURN_FALSE;
}
if (tobase->value.lval < 2 || tobase->value.lval > 36) {
php3_error(E_WARNING, "base_convert: invalid `to base' (%d)",
tobase->value.lval);
RETURN_FALSE;
}
temp.type = IS_LONG;
temp.value.lval = _php3_basetolong(number, frombase->value.lval);
result = _php3_longtobase(&temp, tobase->value.lval);
RETVAL_STRING(result, 0);
} /* }}} */
char *_php3_number_format(double d,int dec,char dec_point,char thousand_sep)
{
char *tmpbuf,*resbuf;
char *s,*t; /* source, target */
int tmplen,reslen=0;
int count=0;
int is_negative=0;
if (d<0) {
is_negative=1;
d = -d;
}
dec = MAX(0,dec);
tmpbuf = (char *) emalloc(32+dec);
tmplen=_php3_sprintf(tmpbuf,"%.*f",dec,d);
for (t=tmpbuf; *t; t++) {
if (*t=='.') {
*t = dec_point;
}
}
if (dec) {
reslen = dec+1 + (tmplen-dec-1) + (tmplen-1-dec-1)/3;
} else {
reslen = tmplen+(tmplen-1)/3;
}
if (is_negative) {
reslen++;
}
resbuf = (char *) emalloc(reslen+1);
s = tmpbuf+tmplen-1;
t = resbuf+reslen;
*t-- = 0;
if (dec) {
while (*s!=dec_point) {
*t-- = *s--;
}
*t-- = *s--; /* copy that dot */
}
while(s>=tmpbuf) {
*t-- = *s--;
if ((++count%3)==0 && s>=tmpbuf) {
*t-- = thousand_sep;
}
}
if (is_negative) {
*t-- = '-';
}
efree(tmpbuf);
return resbuf;
}
/* {{{ proto string number_format(double number, [,int num_decimal_places [, string dec_seperator, string thousands_seperator)]])
Formats a number with grouped thousands */
void php3_number_format(INTERNAL_FUNCTION_PARAMETERS)
{
pval *num,*dec,*t_s,*d_p;
char thousand_sep=',', dec_point='.';
switch(ARG_COUNT(ht)) {
case 1:
if (getParameters(ht, 1, &num)==FAILURE) {
RETURN_FALSE;
}
convert_to_double(num);
RETURN_STRING(_php3_number_format(num->value.dval,0,dec_point,thousand_sep),0);
break;
case 2:
if (getParameters(ht, 2, &num, &dec)==FAILURE) {
RETURN_FALSE;
}
convert_to_double(num);
convert_to_long(dec);
RETURN_STRING(_php3_number_format(num->value.dval,dec->value.lval,dec_point,thousand_sep),0);
break;
case 4:
if (getParameters(ht, 4, &num, &dec, &d_p, &t_s)==FAILURE) {
RETURN_FALSE;
}
convert_to_double(num);
convert_to_long(dec);
convert_to_string(d_p);
convert_to_string(t_s);
if (d_p->value.str.len==1) {
dec_point=d_p->value.str.val[0];
}
if (t_s->value.str.len==1) {
thousand_sep=t_s->value.str.val[0];
}
RETURN_STRING(_php3_number_format(num->value.dval,dec->value.lval,dec_point,thousand_sep),0);
break;
default:
WRONG_PARAM_COUNT;
break;
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

407
ext/standard/md5.c Normal file
View file

@ -0,0 +1,407 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Lachlan Roche |
+----------------------------------------------------------------------+
*/
/*
* md5.c - Copyright 1997 Lachlan Roche
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <stdio.h>
#include "php.h"
#include "md5.h"
/* {{{ proto string md5(string str)
Calculate the md5 hash of a string */
void php3_md5(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char md5str[33];
PHP3_MD5_CTX context;
unsigned char digest[16];
int i;
char *r;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
md5str[0] = '\0';
PHP3_MD5Init(&context);
PHP3_MD5Update(&context, arg->value.str.val, arg->value.str.len);
PHP3_MD5Final(digest, &context);
for (i = 0, r = md5str; i < 16; i++, r += 2) {
sprintf(r, "%02x", digest[i]);
}
*r = '\0';
RETVAL_STRING(md5str,1);
}
/* }}} */
/*
* The remaining code is the reference MD5 code (md5c.c) from rfc1321
*/
/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
/* Constants for MD5Transform routine.
*/
#define S11 7
#define S12 12
#define S13 17
#define S14 22
#define S21 5
#define S22 9
#define S23 14
#define S24 20
#define S31 4
#define S32 11
#define S33 16
#define S34 23
#define S41 6
#define S42 10
#define S43 15
#define S44 21
static void MD5Transform PROTO_LIST((UINT4[4], const unsigned char[64]));
static void Encode PROTO_LIST
((unsigned char *, UINT4 *, unsigned int));
static void Decode PROTO_LIST
((UINT4 *, const unsigned char *, unsigned int));
static void MD5_memcpy PROTO_LIST((_POINTER, _POINTER, unsigned int));
static void MD5_memset PROTO_LIST((_POINTER, int, unsigned int));
static unsigned char PADDING[64] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
/* F, G, H and I are basic MD5 functions.
*/
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
#define H(x, y, z) ((x) ^ (y) ^ (z))
#define I(x, y, z) ((y) ^ ((x) | (~z)))
/* ROTATE_LEFT rotates x left n bits.
*/
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
Rotation is separate from addition to prevent recomputation.
*/
#define FF(a, b, c, d, x, s, ac) { \
(a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define GG(a, b, c, d, x, s, ac) { \
(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define HH(a, b, c, d, x, s, ac) { \
(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
#define II(a, b, c, d, x, s, ac) { \
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
(a) = ROTATE_LEFT ((a), (s)); \
(a) += (b); \
}
/* MD5 initialization. Begins an MD5 operation, writing a new context.
*/
void PHP3_MD5Init(PHP3_MD5_CTX * context)
{
context->count[0] = context->count[1] = 0;
/* Load magic initialization constants.
*/
context->state[0] = 0x67452301;
context->state[1] = 0xefcdab89;
context->state[2] = 0x98badcfe;
context->state[3] = 0x10325476;
}
/* MD5 block update operation. Continues an MD5 message-digest
operation, processing another message block, and updating the
context.
*/
void PHP3_MD5Update(PHP3_MD5_CTX * context, const unsigned char *input,
unsigned int inputLen)
{
unsigned int i, index, partLen;
/* Compute number of bytes mod 64 */
index = (unsigned int) ((context->count[0] >> 3) & 0x3F);
/* Update number of bits */
if ((context->count[0] += ((UINT4) inputLen << 3))
< ((UINT4) inputLen << 3))
context->count[1]++;
context->count[1] += ((UINT4) inputLen >> 29);
partLen = 64 - index;
/* Transform as many times as possible.
*/
if (inputLen >= partLen) {
MD5_memcpy
((_POINTER) & context->buffer[index], (_POINTER) input, partLen);
MD5Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
MD5Transform(context->state, &input[i]);
index = 0;
} else
i = 0;
/* Buffer remaining input */
MD5_memcpy
((_POINTER) & context->buffer[index], (_POINTER) & input[i],
inputLen - i);
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
the message digest and zeroizing the context.
*/
void PHP3_MD5Final(unsigned char digest[16], PHP3_MD5_CTX * context)
{
unsigned char bits[8];
unsigned int index, padLen;
/* Save number of bits */
Encode(bits, context->count, 8);
/* Pad out to 56 mod 64.
*/
index = (unsigned int) ((context->count[0] >> 3) & 0x3f);
padLen = (index < 56) ? (56 - index) : (120 - index);
PHP3_MD5Update(context, PADDING, padLen);
/* Append length (before padding) */
PHP3_MD5Update(context, bits, 8);
/* Store state in digest */
Encode(digest, context->state, 16);
/* Zeroize sensitive information.
*/
MD5_memset((_POINTER) context, 0, sizeof(*context));
}
/* MD5 basic transformation. Transforms state based on block.
*/
static void MD5Transform(state, block)
UINT4 state[4];
const unsigned char block[64];
{
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
Decode(x, block, 64);
/* Round 1 */
FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
/* Round 2 */
GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
/* Round 3 */
HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
/* Round 4 */
II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
state[0] += a;
state[1] += b;
state[2] += c;
state[3] += d;
/* Zeroize sensitive information. */
MD5_memset((_POINTER) x, 0, sizeof(x));
}
/* Encodes input (UINT4) into output (unsigned char). Assumes len is
a multiple of 4.
*/
static void Encode(output, input, len)
unsigned char *output;
UINT4 *input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char) (input[i] & 0xff);
output[j + 1] = (unsigned char) ((input[i] >> 8) & 0xff);
output[j + 2] = (unsigned char) ((input[i] >> 16) & 0xff);
output[j + 3] = (unsigned char) ((input[i] >> 24) & 0xff);
}
}
/* Decodes input (unsigned char) into output (UINT4). Assumes len is
a multiple of 4.
*/
static void Decode(output, input, len)
UINT4 *output;
const unsigned char *input;
unsigned int len;
{
unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4) input[j]) | (((UINT4) input[j + 1]) << 8) |
(((UINT4) input[j + 2]) << 16) | (((UINT4) input[j + 3]) << 24);
}
/* Note: Replace "for loop" with standard memcpy if possible.
*/
static void MD5_memcpy(output, input, len)
_POINTER output;
_POINTER input;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
output[i] = input[i];
}
/* Note: Replace "for loop" with standard memset if possible.
*/
static void MD5_memset(output, value, len)
_POINTER output;
int value;
unsigned int len;
{
unsigned int i;
for (i = 0; i < len; i++)
((char *) output)[i] = (char) value;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

71
ext/standard/md5.h Normal file
View file

@ -0,0 +1,71 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
#ifndef _md5_h
#define _md5_h
/* MD5.H - header file for MD5C.C
*/
/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
rights reserved.
License to copy and use this software is granted provided that it
is identified as the "RSA Data Security, Inc. MD5 Message-Digest
Algorithm" in all material mentioning or referencing this software
or this function.
License is also granted to make and use derivative works provided
that such works are identified as "derived from the RSA Data
Security, Inc. MD5 Message-Digest Algorithm" in all material
mentioning or referencing the derived work.
RSA Data Security, Inc. makes no representations concerning either
the merchantability of this software or the suitability of this
software for any particular purpose. It is provided "as is"
without express or implied warranty of any kind.
These notices must be retained in any copies of any part of this
documentation and/or software.
*/
#include "global.h"
/* MD5 context. */
typedef struct {
UINT4 state[4]; /* state (ABCD) */
UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
unsigned char buffer[64]; /* input buffer */
} PHP3_MD5_CTX;
void PHP3_MD5Init PROTO_LIST((PHP3_MD5_CTX *));
void PHP3_MD5Update PROTO_LIST((PHP3_MD5_CTX *, const unsigned char *, unsigned int));
void PHP3_MD5Final PROTO_LIST((unsigned char[16], PHP3_MD5_CTX *));
extern void php3_md5(INTERNAL_FUNCTION_PARAMETERS);
#endif

88
ext/standard/microtime.c Normal file
View file

@ -0,0 +1,88 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Paul Panotzki - Bunyip Information Systems |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "microtime.h"
#include "snprintf.h"
#include <stdio.h>
#if HAVE_GETTIMEOFDAY
#if MSVC5
#include "win32/time.h"
#else
#include <sys/time.h>
#endif
#endif
#define NUL '\0'
#define MICRO_IN_SEC 1000000.00
/* {{{ proto string microtime(void)
Returns a string containing the current time in seconds and microseconds */
#ifdef __cplusplus
void php3_microtime(HashTable *)
#else
void php3_microtime(INTERNAL_FUNCTION_PARAMETERS)
#endif
{
#if HAVE_GETTIMEOFDAY
struct timeval tp;
long sec = 0L;
double msec = 0.0;
char ret[100];
TLS_VARS;
if (gettimeofday((struct timeval *) &tp, (NUL)) == 0) {
msec = (double) (tp.tv_usec / MICRO_IN_SEC);
sec = tp.tv_sec;
}
snprintf(ret, 100, "%.8f %ld", msec, sec);
RETVAL_STRING(ret,1);
#endif
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

37
ext/standard/microtime.h Normal file
View file

@ -0,0 +1,37 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Paul Panotzki - Bunyip Information Systems |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _MICROTIME_H
#define _MICROTIME_H
extern void php3_microtime(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _MICROTIME_H */

890
ext/standard/pack.c Normal file
View file

@ -0,0 +1,890 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Chris Schneider <cschneid@relog.ch> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#if MSVC5
#include <windows.h>
#include <winsock.h>
#define O_RDONLY _O_RDONLY
#include "win32/param.h"
#else
#include <sys/param.h>
#endif
#include "head.h"
#include "safe_mode.h"
#include "php3_string.h"
#include "pack.h"
#if HAVE_PWD_H
#if MSVC5
#include "win32/pwd.h"
#else
#include <pwd.h>
#endif
#endif
#include "snprintf.h"
#include "fsock.h"
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
function_entry pack_functions[] = {
{"pack", php3_pack, NULL},
{"unpack", php3_unpack, NULL},
{NULL, NULL, NULL}
};
php3_module_entry pack_module_entry = {
"PHP_pack", pack_functions, php3_minit_pack, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
/* Whether machine is little endian */
char machine_little_endian;
/* Mapping of byte from char (8bit) to long for machine endian */
static int byte_map[1];
/* Mappings of bytes from int (machine dependant) to int for machine endian */
static int int_map[sizeof(int)];
/* Mappings of bytes from shorts (16bit) for all endian environments */
static int machine_endian_short_map[2];
static int big_endian_short_map[2];
static int little_endian_short_map[2];
/* Mappings of bytes from longs (32bit) for all endian environments */
static int machine_endian_long_map[4];
static int big_endian_long_map[4];
static int little_endian_long_map[4];
static void _php3_pack(pval *val, int size, int *map, char *output)
{
int i;
char *v;
convert_to_long(val);
v = (char *)&val->value.lval;
for (i = 0; i < size; i++) {
*(output++) = v[map[i]];
}
}
/* pack() idea stolen from Perl (implemented formats behave the same as there)
* Implemented formats are A,a,h,H,c,C,s,S,i,I,l,L,n,N,f,d,x,X,@.
*/
/* {{{ proto string pack(string format, mixed arg1, mixed arg2, ...)
Takes 1 or more arguments and packs them into a binary string according to the format argument */
PHP_FUNCTION(pack)
{
pval **argv;
int argc, i;
int currentarg;
char *format;
int formatlen;
char *formatcodes;
int *formatargs;
int formatcount = 0;
int outputpos = 0, outputsize = 0;
char *output;
TLS_VARS;
argc = ARG_COUNT(ht);
if (argc < 1) {
WRONG_PARAM_COUNT;
}
argv = emalloc(argc * sizeof(pval *));
if (getParametersArray(ht, argc, argv) == FAILURE) {
efree(argv);
WRONG_PARAM_COUNT;
}
convert_to_string(argv[0]);
format = argv[0]->value.str.val;
formatlen = argv[0]->value.str.len;
/* We have a maximum of <formatlen> format codes to deal with */
formatcodes = emalloc(formatlen * sizeof(*formatcodes));
formatargs = emalloc(formatlen * sizeof(*formatargs));
currentarg = 1;
/* Preprocess format into formatcodes and formatargs */
for (i = 0; i < formatlen; formatcount++) {
char code = format[i++];
int arg = 1;
/* Handle format arguments if any */
if (i < formatlen) {
char c = format[i];
if (c == '*') {
arg = -1;
i++;
}
else if ((c >= '0') && (c <= '9')) {
arg = atoi(&format[i]);
while (format[i] >= '0' && format[i] <= '9' && i < formatlen) {
i++;
}
}
}
/* Handle special arg '*' for all codes and check argv overflows */
switch ((int)code) {
/* Never uses any args */
case 'x': case 'X': case '@': {
if (arg < 0) {
php3_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);
php3_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);
php3_error(E_ERROR, "pack type %c: too few arguments", code);
RETURN_FALSE;
}
break;
}
default: {
php3_error(E_ERROR, "pack type %c: unknown format code", code);
RETURN_FALSE;
}
}
formatcodes[formatcount] = code;
formatargs[formatcount] = arg;
}
if (currentarg < argc) {
php3_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) {
php3_error(E_WARNING, "pack type %c: outside of string", code);
outputpos = 0;
}
break;
}
case '@': {
outputpos = arg;
break;
}
}
if (outputsize < outputpos) {
outputsize = outputpos;
}
}
output = emalloc(outputsize + 1);
outputpos = 0;
currentarg = 1;
/* Do actual packing */
for (i = 0; i < formatcount; i++) {
int code = (int)formatcodes[i];
int arg = formatargs[i];
pval *val;
switch ((int)code) {
case 'a': case 'A': {
memset(&output[outputpos], (code == 'a') ? '\0' : ' ', arg);
val = argv[currentarg++];
convert_to_string(val);
memcpy(&output[outputpos], val->value.str.val,
(val->value.str.len < arg) ? val->value.str.len : arg);
outputpos += arg;
break;
}
case 'h': case 'H': {
int nibbleshift = (code == 'h') ? 0 : 4;
int first = 1;
char *v;
val = argv[currentarg++];
convert_to_string(val);
v = val->value.str.val;
outputpos--;
while (arg-- > 0) {
char n = *(v++);
if ((n >= '0') && (n <= '9')) {
n -= '0';
} else if ((n >= 'A') && (n <= 'F')) {
n -= ('A' - 10);
} else if ((n >= 'a') && (n <= 'f')) {
n -= ('a' - 10);
} else {
php3_error(E_WARNING, "pack type %c: illegal hex digit %c", code, n);
n = 0;
}
if (first--) {
output[++outputpos] = 0;
} else {
first = 1;
}
output[outputpos] |= (n << nibbleshift);
nibbleshift = (nibbleshift + 4) & 7;
}
outputpos++;
break;
}
case 'c': case 'C': {
while (arg-- > 0) {
_php3_pack(argv[currentarg++], 1, byte_map, &output[outputpos]);
outputpos++;
}
break;
}
case 's': case 'S': case 'n': case 'v': {
int *map = machine_endian_short_map;
if (code == 'n') {
map = big_endian_short_map;
} else if (code == 'v') {
map = little_endian_short_map;
}
while (arg-- > 0) {
_php3_pack(argv[currentarg++], 2, map, &output[outputpos]);
outputpos += 2;
}
break;
}
case 'i': case 'I': {
while (arg-- > 0) {
_php3_pack(argv[currentarg++], sizeof(int), int_map, &output[outputpos]);
outputpos += sizeof(int);
}
break;
}
case 'l': case 'L': case 'N': case 'V': {
int *map = machine_endian_long_map;
if (code == 'N') {
map = big_endian_long_map;
} else if (code == 'V') {
map = little_endian_long_map;
}
while (arg-- > 0) {
_php3_pack(argv[currentarg++], 4, map, &output[outputpos]);
outputpos += 4;
}
break;
}
case 'f': {
float v;
while (arg-- > 0) {
val = argv[currentarg++];
convert_to_double(val);
v = (float)val->value.dval;
memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v);
}
break;
}
case 'd': {
double v;
while (arg-- > 0) {
val = argv[currentarg++];
convert_to_double(val);
v = (double)val->value.dval;
memcpy(&output[outputpos], &v, sizeof(v));
outputpos += sizeof(v);
}
break;
}
case 'x': {
memset(&output[outputpos], '\0', arg);
outputpos += arg;
break;
}
case 'X': {
outputpos -= arg;
if (outputpos < 0) {
outputpos = 0;
}
break;
}
case '@': {
if (arg > outputpos) {
memset(&output[outputpos], '\0', arg - outputpos);
}
outputpos = arg;
break;
}
}
}
efree(argv);
efree(formatcodes);
efree(formatargs);
output[outputpos] = '\0';
RETVAL_STRINGL(output, outputpos, 1);
efree(output);
}
/* }}} */
static long _php3_unpack(char *data, int size, int issigned, int *map)
{
long result;
char *cresult = (char *)&result;
int i;
result = issigned ? -1 : 0;
for (i = 0; i < size; i++) {
cresult[map[i]] = *(data++);
}
return result;
}
/* unpack() is based on Perl's unpack(), but is modified a bit from there.
* Rather than depending on error-prone ordered lists or syntactically
* unpleasant pass-by-reference, we return an object with named paramters
* (like *_fetch_object()). Syntax is "f[repeat]name/...", where "f" is the
* formatter char (like pack()), "[repeatt]" is the optional repeater argument,
* and "name" is the name of the variable to use.
* Example: "c2chars/nints" will return an object with fields
* chars1, chars2, and ints.
* Numeric pack types will return numbers, a and A will return strings,
* f and d will return doubles.
* Implemented formats are A,a,h,H,c,C,s,S,i,I,l,L,n,N,f,d,x,X,@.
*/
/* {{{ proto array unpack(string format, string input)
Unpack binary string into named array elements according to format argument */
PHP_FUNCTION(unpack)
{
pval *formatarg;
pval *inputarg;
char *format;
char *input;
int formatlen;
int inputpos, inputlen;
int i;
TLS_VARS;
if ((ARG_COUNT(ht) != 2) || getParameters(ht, 2, &formatarg, &inputarg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(formatarg);
convert_to_string(inputarg);
format = formatarg->value.str.val;
formatlen = formatarg->value.str.len;
input = inputarg->value.str.val;
inputlen = inputarg->value.str.len;
inputpos = 0;
if (array_init(return_value) == FAILURE)
return;
while (formatlen-- > 0) {
char type = *(format++);
char c;
int arg = 1;
char *name;
int namelen;
int size=0;
/* Handle format arguments if any */
if (formatlen > 0) {
c = *format;
if ((c >= '0') && (c <= '9')) {
arg = atoi(format);
while ((formatlen > 0) && (*format >= '0') && (*format <= '9')) {
format++;
formatlen--;
}
} else if (c == '*') {
arg = -1;
format++;
formatlen--;
}
}
/* Get of new value in array */
name = format;
while ((formatlen > 0) && (*format != '/')) {
formatlen--;
format++;
}
namelen = format - name;
if (namelen > 200)
namelen = 200;
switch ((int)type) {
/* Never use any input */
case 'X': {
size = -1;
break;
}
case '@': {
size = 0;
break;
}
case 'a': case 'A': case 'h': case 'H': {
size = arg;
arg = 1;
break;
}
/* Use 1 byte of input */
case 'c': case 'C': case 'x': {
size = 1;
break;
}
/* Use 2 bytes of input */
case 's': case 'S': case 'n': case 'v': {
size = 2;
break;
}
/* Use sizeof(int) bytes of input */
case 'i': case 'I': {
size = sizeof(int);
break;
}
/* Use 4 bytes of input */
case 'l': case 'L': case 'N': case 'V': {
size = 4;
break;
}
/* Use sizeof(float) bytes of input */
case 'f': {
size = sizeof(float);
break;
}
/* Use sizeof(double) bytes of input */
case 'd': {
size = sizeof(double);
break;
}
}
/* Do actual unpacking */
for (i = 0; (i != arg); i++ ) {
/* Space for name + number, safe as namelen is ensured <= 200 */
char n[256];
if (arg != 1) {
/* Need to add element number to name */
sprintf(n, "%.*s%d", namelen, name, i + 1);
} else {
/* Truncate name to next format code or end of string */
sprintf(n, "%.*s", namelen, name);
}
if ((inputpos + size) <= inputlen) {
switch ((int)type) {
case 'a': case 'A': {
char pad = (type == 'a') ? '\0' : ' ';
int len = inputlen - inputpos; /* Remaining string */
/* If size was given take minimum of len and size */
if ((size >= 0) && (len > size)) {
len = size;
}
size = len;
/* Remove padding chars from unpacked data */
while (--len >= 0) {
if (input[inputpos + len] != pad)
break;
}
add_assoc_stringl(return_value, n, &input[inputpos], len + 1, 1);
break;
}
case 'h': case 'H': {
int len = (inputlen - inputpos) * 2; /* Remaining */
int nibbleshift = (type == 'h') ? 0 : 4;
int first = 1;
char *buf;
int ipos, opos;
/* If size was given take minimum of len and size */
if ((size >= 0) && (len > size)) {
len = size;
}
size = (len + 1) / 2;
buf = emalloc(len + 1);
for (ipos = opos = 0; opos < len; opos++) {
char c = (input[inputpos + ipos] >> nibbleshift) & 0xf;
if (c < 10) {
c += '0';
} else {
c += 'a' - 10;
}
buf[opos] = c;
nibbleshift = (nibbleshift + 4) & 7;
if (first-- == 0) {
ipos++;
first = 1;
}
}
buf[len] = '\0';
add_assoc_stringl(return_value, n, buf, len, 1);
efree(buf);
break;
}
case 'c': case 'C': {
int issigned = (type == 'c') ? (input[inputpos] & 0x80) : 0;
long v = _php3_unpack(&input[inputpos], 1, issigned, byte_map);
add_assoc_long(return_value, n, v);
break;
}
case 's': case 'S': case 'n': case 'v': {
long v;
int issigned = 0;
int *map = machine_endian_short_map;
if (type == 's') {
issigned = input[inputpos + (machine_little_endian ? 1 : 0)] & 0x80;
} else if (type == 'n') {
map = big_endian_short_map;
} else if (type == 'v') {
map = little_endian_short_map;
}
v = _php3_unpack(&input[inputpos], 2, issigned, map);
add_assoc_long(return_value, n, v);
break;
}
case 'i': case 'I': {
long v;
int issigned = 0;
if (type == 'i') {
issigned = input[inputpos + (machine_little_endian ? (sizeof(int) - 1) : 0)] & 0x80;
}
v = _php3_unpack(&input[inputpos], sizeof(int), issigned, int_map);
add_assoc_long(return_value, n, v);
break;
}
case 'l': case 'L': case 'N': case 'V': {
int issigned = 0;
int *map = machine_endian_long_map;
long v;
if (type == 'l') {
issigned = input[inputpos + (machine_little_endian ? 3 : 0)] & 0x80;
} else if (type == 'N') {
map = big_endian_long_map;
} else if (type == 'V') {
map = little_endian_long_map;
}
v = _php3_unpack(&input[inputpos], 4, issigned, map);
add_assoc_long(return_value, n, v);
break;
}
case 'f': {
float v;
memcpy(&v, &input[inputpos], sizeof(float));
add_assoc_double(return_value, n, (double)v);
break;
}
case 'd': {
double v;
memcpy(&v, &input[inputpos], sizeof(float));
add_assoc_double(return_value, n, v);
break;
}
case 'x': {
/* Do nothing with input, just skip it */
break;
}
case 'X': {
if (inputpos < size) {
inputpos = -size;
i = arg - 1; /* Break out of for loop */
if (arg >= 0) {
php3_error(E_WARNING, "pack type %c: outside of string", type);
}
}
break;
}
case '@': {
if (arg <= inputlen) {
inputpos = arg;
} else {
php3_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 {
php3_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++;
}
}
/* }}} */
int php3_minit_pack(INIT_FUNC_ARGS)
{
int machine_endian_check = 1;
int i;
TLS_VARS;
machine_little_endian = ((char *)&machine_endian_check)[0];
if (machine_little_endian) {
/* Where to get lo to hi bytes from */
byte_map[0] = 0;
for (i = 0; i < sizeof(int); i++) {
int_map[i] = i;
}
machine_endian_short_map[0] = 0;
machine_endian_short_map[1] = 1;
big_endian_short_map[0] = 1;
big_endian_short_map[1] = 0;
little_endian_short_map[0] = 0;
little_endian_short_map[1] = 1;
machine_endian_long_map[0] = 0;
machine_endian_long_map[1] = 1;
machine_endian_long_map[2] = 2;
machine_endian_long_map[3] = 3;
big_endian_long_map[0] = 3;
big_endian_long_map[1] = 2;
big_endian_long_map[2] = 1;
big_endian_long_map[3] = 0;
little_endian_long_map[0] = 0;
little_endian_long_map[1] = 1;
little_endian_long_map[2] = 2;
little_endian_long_map[3] = 3;
}
else {
pval val;
int size = sizeof(val.value.lval);
val.value.lval=0; /*silence a warning*/
/* Where to get hi to lo bytes from */
byte_map[0] = size - 1;
for (i = 0; i < sizeof(int); i++) {
int_map[i] = size - (sizeof(int) - i);
}
machine_endian_short_map[0] = size - 2;
machine_endian_short_map[1] = size - 1;
big_endian_short_map[0] = size - 2;
big_endian_short_map[1] = size - 1;
little_endian_short_map[0] = size - 1;
little_endian_short_map[1] = size - 2;
machine_endian_long_map[0] = size - 4;
machine_endian_long_map[1] = size - 3;
machine_endian_long_map[2] = size - 2;
machine_endian_long_map[3] = size - 1;
big_endian_long_map[0] = size - 4;
big_endian_long_map[1] = size - 3;
big_endian_long_map[2] = size - 2;
big_endian_long_map[3] = size - 1;
little_endian_long_map[0] = size - 1;
little_endian_long_map[1] = size - 2;
little_endian_long_map[2] = size - 3;
little_endian_long_map[3] = size - 4;
}
return SUCCESS;
}
/*
* Local variables:
* tab-width: 4
* End:
*/

42
ext/standard/pack.h Normal file
View file

@ -0,0 +1,42 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PACK_H
#define _PACK_H
extern php3_module_entry pack_module_entry;
#define pack_module_ptr &pack_module_entry
extern int php3_minit_pack(INIT_FUNC_ARGS);
extern void php3_pack(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_unpack(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PACK_H */

159
ext/standard/pageinfo.c Normal file
View file

@ -0,0 +1,159 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "pageinfo.h"
#include <stdio.h>
#include <stdlib.h>
#if HAVE_PWD_H
#if MSVC5
#include "win32/pwd.h"
#else
#include <pwd.h>
#endif
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/stat.h>
#if MSVC5
#include <process.h>
#endif
#ifndef THREAD_SAFE
static long page_uid = -1;
static long page_inode = -1;
static long page_mtime = -1;
#endif
static void _php3_statpage(void)
{
#if !APACHE
char *path;
struct stat sb;
#endif
TLS_VARS;
#if APACHE
/* Apache has already gone through the trouble of doing
the stat(), so the only real overhead is copying three
values. We can afford it, and it means we don't have to
worry about resetting the static variables after every
hit. */
GLOBAL(page_uid) = GLOBAL(php3_rqst)->finfo.st_uid;
GLOBAL(page_inode) = GLOBAL(php3_rqst)->finfo.st_ino;
GLOBAL(page_mtime) = GLOBAL(php3_rqst)->finfo.st_mtime;
#else
if (GLOBAL(page_uid) == -1) {
path = GLOBAL(request_info).filename;
if (path != NULL) {
if (stat(path, &sb) == -1) {
php3_error(E_WARNING, "Unable to find file: '%s'", path);
return;
}
GLOBAL(page_uid) = sb.st_uid;
GLOBAL(page_inode) = sb.st_ino;
GLOBAL(page_mtime) = sb.st_mtime;
}
}
#endif
}
long _php3_getuid(void)
{
TLS_VARS;
_php3_statpage();
return (GLOBAL(page_uid));
}
/* {{{ proto int getmyuid(void)
Get PHP script owner's UID */
void php3_getmyuid(INTERNAL_FUNCTION_PARAMETERS)
{
long uid;
TLS_VARS;
uid = _php3_getuid();
if (uid < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(uid);
}
}
/* }}} */
/* {{{ proto int getmypid(void)
Get current process ID */
void php3_getmypid(INTERNAL_FUNCTION_PARAMETERS)
{
int pid;
TLS_VARS;
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 */
void php3_getmyinode(INTERNAL_FUNCTION_PARAMETERS)
{
TLS_VARS;
_php3_statpage();
if (GLOBAL(page_inode) < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(GLOBAL(page_inode));
}
}
/* }}} */
/* {{{ proto int getlastmod(void)
Get time of last page modification */
void php3_getlastmod(INTERNAL_FUNCTION_PARAMETERS)
{
TLS_VARS;
_php3_statpage();
if (GLOBAL(page_mtime) < 0) {
RETURN_FALSE;
} else {
RETURN_LONG(GLOBAL(page_mtime));
}
}
/* }}} */

11
ext/standard/pageinfo.h Normal file
View file

@ -0,0 +1,11 @@
#ifndef _PROCESS_H
#define _PROCESS_H
extern void php3_getmyuid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getmypid(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getmyinode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getlastmod(INTERNAL_FUNCTION_PARAMETERS);
extern long _php3_getuid(void);
#endif

View file

@ -0,0 +1,43 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Zeev Suraski <zeev@zend.com> |
+----------------------------------------------------------------------+
*/
#ifndef _PHP3_BROWSCAP_H
#define _PHP3_BROWSCAP_H
extern php3_module_entry browscap_module_entry;
#define browscap_module_ptr &browscap_module_entry
extern int php3_minit_browscap(INIT_FUNC_ARGS);
extern int php3_mshutdown_browscap(SHUTDOWN_FUNC_ARGS);
extern void php3_get_browser(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHP3_BROWSCAP_H */

48
ext/standard/php3_dir.h Normal file
View file

@ -0,0 +1,48 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHP3_DIR_H
#define _PHP3_DIR_H
extern php3_module_entry php3_dir_module_entry;
#define php3_dir_module_ptr &php3_dir_module_entry
/* directory functions */
extern int php3_minit_dir(INIT_FUNC_ARGS);
extern void php3_opendir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_closedir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rewinddir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_readdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getdir(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHP3_DIR_H */

View file

@ -0,0 +1,64 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Jim Winstead <jimw@php.net> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _FILESTAT_H
#define _FILESTAT_H
extern int php3_init_filestat(INIT_FUNC_ARGS);
extern int php3_shutdown_filestat(SHUTDOWN_FUNC_ARGS);
extern void php3_clearstatcache(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileatime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_filectime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_filegroup(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileinode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_filemtime(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileowner(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileperms(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_filesize(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_filetype(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_iswritable(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_isreadable(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_isexec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_isfile(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_isdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_islink(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileexists(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_stat(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_lstat(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chown(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chmod(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_touch(INTERNAL_FUNCTION_PARAMETERS);
extern php3_module_entry php3_filestat_module_entry;
#define php3_filestat_module_ptr &php3_filestat_module_entry
#endif /* _FILESTAT_H */

38
ext/standard/php3_iptc.h Normal file
View file

@ -0,0 +1,38 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Thies C. Arntzen <thies@digicol.de> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHPIPTC_H
#define _PHPIPTC_H
extern void php3_iptcparse(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHPIPTC_H */

41
ext/standard/php3_link.h Normal file
View file

@ -0,0 +1,41 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHP3_LINK_H
#define _PHP3_LINK_H
extern void php3_link(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_unlink(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_readlink(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_linkinfo(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_symlink(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHP3_LINK_H */

46
ext/standard/php3_mail.h Normal file
View file

@ -0,0 +1,46 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _MAIL_H
#define _MAIL_H
#if HAVE_SENDMAIL
extern php3_module_entry mail_module_entry;
#define mail_module_ptr &mail_module_entry
extern void php3_mail(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_info_mail(void);
extern int _php3_mail(char *to, char *subject, char *message, char *headers);
#else
#define mail_module_ptr NULL
#endif
#endif /* _MAIL_H */

View file

@ -0,0 +1,71 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "basic_functions.h"
#include "phpmath.h"
#include "php3_string.h"
#include "base64.h"
#include "php3_dir.h"
#include "dns.h"
#include "reg.h"
#include "php3_mail.h"
#include "md5.h"
#include "html.h"
#include "exec.h"
#include "file.h"
#include "php3_syslog.h"
#include "php3_filestat.h"
#include "php3_browscap.h"
#include "pack.h"
#include "datetime.h"
#include "microtime.h"
#include "url.h"
#include "pageinfo.h"
#include "cyr_convert.h"
#include "php3_link.h"
#include "fsock.h"
#include "image.h"
#include "php3_iptc.h"
#include "info.h"
#include "uniqid.h"
#include "php3_var.h"
#include "quot_print.h"
#include "type.h"
#define standard_module_ptr basic_functions_module_ptr
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

View file

@ -0,0 +1,99 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
#ifndef THREAD_SAFE
extern char *strtok_string;
#endif
extern void php3_strlen(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strcmp(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strspn(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strcspn(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strcasecmp(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_str_replace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chop(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_trim(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ltrim(INTERNAL_FUNCTION_PARAMETERS);
extern void soundex(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_explode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_implode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strtok(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strtoupper(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strtolower(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_basename(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_dirname(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strstr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strpos(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strrpos(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strrchr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_substr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_quotemeta(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ucfirst(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ucwords(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strtr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_strrev(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_hebrev(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_hebrev_with_conversion(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_user_sprintf(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_user_printf(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_addslashes(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_stripslashes(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ord(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_newline_to_br(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_setlocale(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_stristr(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chunk_split(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_parsestr(INTERNAL_FUNCTION_PARAMETERS);
#if HAVE_CRYPT
extern php3_module_entry crypt_module_entry;
#define crypt_module_ptr &crypt_module_entry
extern void php3_crypt(INTERNAL_FUNCTION_PARAMETERS);
#else
#define crypt_module_ptr NULL
#endif
extern PHPAPI char *_php3_strtoupper(char *s);
extern PHPAPI char *_php3_strtolower(char *s);
extern char *_StrTr(char *string, char *str_from, char *str_to);
extern PHPAPI char *_php3_addslashes(char *string, int length, int *new_length, int freeit);
extern PHPAPI void _php3_stripslashes(char *string, int *len);
extern PHPAPI void _php3_dirname(char *str, int len);
extern PHPAPI char *php3i_stristr(unsigned char *s, unsigned char *t);
#endif /* _PHPSTRING_H */

View file

@ -0,0 +1,44 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: |
| |
+----------------------------------------------------------------------+
*/
#if HAVE_SYSLOG_H
extern php3_module_entry syslog_module_entry;
#define syslog_module_ptr &syslog_module_entry
extern int php3_minit_syslog(INIT_FUNC_ARGS);
extern int php3_rinit_syslog(INIT_FUNC_ARGS);
extern int php3_rshutdown_syslog(SHUTDOWN_FUNC_ARGS);
extern void php3_openlog(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_syslog(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_closelog(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_define_syslog_variables(INTERNAL_FUNCTION_PARAMETERS);
#else
#define syslog_module_ptr NULL
#endif

42
ext/standard/php3_var.h Normal file
View file

@ -0,0 +1,42 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jani Lehtimäki <jkl@njet.net> |
+----------------------------------------------------------------------+
*/
#ifndef _PHPVAR_H
#define _PHPVAR_H
PHP_FUNCTION(var_dump);
PHP_FUNCTION(serialize);
PHP_FUNCTION(unserialize);
void php3api_var_dump(pval *struc, int level);
void php3api_var_serialize(pval *buf, pval *struc);
int php3api_var_unserialize(pval *rval, char **p, char *max);
#endif /* _PHPVAR_H */

44
ext/standard/phpdir.h Normal file
View file

@ -0,0 +1,44 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHPDIR_H
#define _PHPDIR_H
/* directory functions */
extern void php3_opendir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_closedir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rewinddir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_readdir(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getdir(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHPDIR_H */

70
ext/standard/phpmath.h Normal file
View file

@ -0,0 +1,70 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jim Winstead (jimw@php.net) |
| Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _PHPMATH_H
#define _PHPMATH_H
extern void php3_sin(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_cos(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_tan(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_asin(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_acos(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_atan(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_atan2(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pi(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_exp(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_log(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_log10(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_pow(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_sqrt(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_srand(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rand(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_getrandmax(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_mt_srand(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_mt_rand(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_mt_getrandmax(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_abs(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_ceil(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_floor(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_round(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_decbin(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_dechex(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_decoct(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_bindec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_hexdec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_octdec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_base_convert(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_number_format(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_deg2rad(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rad2deg(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _PHPMATH_H */

109
ext/standard/quot_print.c Normal file
View file

@ -0,0 +1,109 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Kirill Maximov (kir@rus.net |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include "php.h"
#include "quot_print.h"
#include <stdio.h>
/*
* Converting HEX char to INT value
*/
static char _php3_hex2int(int c)
{
if ( isdigit(c) )
{
return c - '0';
}
else if ( c >= 'A' && c <= 'F' )
{
return c - 'A' + 10;
}
else
{
return -1;
}
}
/*
*
* Decoding Quoted-printable string.
*
*/
/* {{{ proto string quoted_printable_decode(string str)
Convert a quoted-printable string to an 8 bit string */
void php3_quoted_printable_decode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg1;
char *str;
int i = 0, j = 0;
if (ARG_COUNT(ht) != 1 || getParameters(ht,1,&arg1)==FAILURE)
{
WRONG_PARAM_COUNT;
}
convert_to_string(arg1);
str = arg1->value.str.val;
while ( str[i] )
{
if ( (str[i] == '=') && str[i+1] && str[i+2] &&
( isdigit((int)str[i+1]) || (str[i+1]<='F' && str[i+1]>='A'))
&&
( isdigit((int)str[i+2]) || (str[i+2]<='F' && str[i+2]>='A'))
)
{
str[j++] = (_php3_hex2int((int)str[i+1]) << 4 )
+ _php3_hex2int((int)str[i+2]);
i += 3;
}
else if ( str[i] == 13 )
{
i++;
}
else
{
str[j++] = str[i++];
}
}
str[j] = '\0';
RETVAL_STRINGL(str, j, 1)
}
/* }}} */

37
ext/standard/quot_print.h Normal file
View file

@ -0,0 +1,37 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Kirill Maximov (kir@rus.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _QUOT_PRINT_H
#define _QUOT_PRINT_H
extern void php3_quoted_printable_decode(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _QUOT_PRINT_H */

343
ext/standard/rand.c Normal file
View file

@ -0,0 +1,343 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Zeev Suraski <zeev@zend.com |
| Pedro Melo <melo@ip.pt> |
| |
| Based on code from: Shawn Cokus <Cokus@math.washington.edu> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#include "php.h"
#include "phpmath.h"
#ifndef RAND_MAX
#define RAND_MAX (1<<15)
#endif
/*
This is the ``Mersenne Twister'' random number generator MT19937, which
generates pseudorandom integers uniformly distributed in 0..(2^32 - 1)
starting from any odd seed in 0..(2^32 - 1). This version is a recode
by Shawn Cokus (Cokus@math.washington.edu) on March 8, 1998 of a version by
Takuji Nishimura (who had suggestions from Topher Cooper and Marc Rieffel in
July-August 1997).
Effectiveness of the recoding (on Goedel2.math.washington.edu, a DEC Alpha
running OSF/1) using GCC -O3 as a compiler: before recoding: 51.6 sec. to
generate 300 million random numbers; after recoding: 24.0 sec. for the same
(i.e., 46.5% of original time), so speed is now about 12.5 million random
number generations per second on this machine.
According to the URL <http://www.math.keio.ac.jp/~matumoto/emt.html>
(and paraphrasing a bit in places), the Mersenne Twister is ``designed
with consideration of the flaws of various existing generators,'' has
a period of 2^19937 - 1, gives a sequence that is 623-dimensionally
equidistributed, and ``has passed many stringent tests, including the
die-hard test of G. Marsaglia and the load test of P. Hellekalek and
S. Wegenkittl.'' It is efficient in memory usage (typically using 2506
to 5012 bytes of static data, depending on data type sizes, and the code
is quite short as well). It generates random numbers in batches of 624
at a time, so the caching and pipelining of modern systems is exploited.
It is also divide- and mod-free.
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation (either version 2 of the License or, at your
option, any later version). This library is distributed in the hope that
it will be useful, but WITHOUT ANY WARRANTY, without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
the GNU Library General Public License for more details. You should have
received a copy of the GNU Library General Public License along with this
library; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307, USA.
The code as Shawn received it included the following notice:
Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. When
you use this, send an e-mail to <matumoto@math.keio.ac.jp> with
an appropriate reference to your work.
It would be nice to CC: <Cokus@math.washington.edu> when you write.
uint32 must be an unsigned integer type capable of holding at least 32
bits; exactly 32 should be fastest, but 64 is better on an Alpha with
GCC at -O3 optimization so try your options and see what's best for you
Melo: we should put some ifdefs here to catch those alphas...
*/
typedef unsigned int uint32;
#define N (624) /* length of state vector */
#define M (397) /* a period parameter */
#define K (0x9908B0DFU) /* a magic constant */
#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */
#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */
#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */
#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */
static uint32 state[N+1]; /* state vector + 1 extra to not violate ANSI C */
static uint32 *next; /* next random value is computed from here */
static int left = -1; /* can *next++ this many times before reloading */
static void seedMT(uint32 seed)
{
/*
We initialize state[0..(N-1)] via the generator
x_new = (69069 * x_old) mod 2^32
from Line 15 of Table 1, p. 106, Sec. 3.3.4 of Knuth's
_The Art of Computer Programming_, Volume 2, 3rd ed.
Notes (SJC): I do not know what the initial state requirements
of the Mersenne Twister are, but it seems this seeding generator
could be better. It achieves the maximum period for its modulus
(2^30) iff x_initial is odd (p. 20-21, Sec. 3.2.1.2, Knuth); if
x_initial can be even, you have sequences like 0, 0, 0, ...;
2^31, 2^31, 2^31, ...; 2^30, 2^30, 2^30, ...; 2^29, 2^29 + 2^31,
2^29, 2^29 + 2^31, ..., etc. so I force seed to be odd below.
Even if x_initial is odd, if x_initial is 1 mod 4 then
the lowest bit of x is always 1,
the next-to-lowest bit of x is always 0,
the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
the 3rd-from-lowest bit of x 4-cycles ... 0 1 1 0 0 1 1 0 ... ,
the 4th-from-lowest bit of x has the 8-cycle ... 0 0 0 1 1 1 1 0 ... ,
...
and if x_initial is 3 mod 4 then
the lowest bit of x is always 1,
the next-to-lowest bit of x is always 1,
the 2nd-from-lowest bit of x alternates ... 0 1 0 1 0 1 0 1 ... ,
the 3rd-from-lowest bit of x 4-cycles ... 0 0 1 1 0 0 1 1 ... ,
the 4th-from-lowest bit of x has the 8-cycle ... 0 0 1 1 1 1 0 0 ... ,
...
The generator's potency (min. s>=0 with (69069-1)^s = 0 mod 2^32) is
16, which seems to be alright by p. 25, Sec. 3.2.1.3 of Knuth. It
also does well in the dimension 2..5 spectral tests, but it could be
better in dimension 6 (Line 15, Table 1, p. 106, Sec. 3.3.4, Knuth).
Note that the random number user does not see the values generated
here directly since reloadMT() will always munge them first, so maybe
none of all of this matters. In fact, the seed values made here could
even be extra-special desirable if the Mersenne Twister theory says
so-- that's why the only change I made is to restrict to odd seeds.
*/
register uint32 x = (seed | 1U) & 0xFFFFFFFFU, *s = state;
register int j;
for(left=0, *s++=x, j=N; --j;
*s++ = (x*=69069U) & 0xFFFFFFFFU);
}
static uint32 reloadMT(void)
{
register uint32 *p0=state, *p2=state+2, *pM=state+M, s0, s1;
register int j;
if(left < -1)
seedMT(4357U);
left=N-1, next=state+1;
for(s0=state[0], s1=state[1], j=N-M+1; --j; s0=s1, s1=*p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
for(pM=state, j=M; --j; s0=s1, s1=*p2++)
*p0++ = *pM++ ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1=state[0], *p0 = *pM ^ (mixBits(s0, s1) >> 1) ^ (loBit(s1) ? K : 0U);
s1 ^= (s1 >> 11);
s1 ^= (s1 << 7) & 0x9D2C5680U;
s1 ^= (s1 << 15) & 0xEFC60000U;
return(s1 ^ (s1 >> 18));
}
static inline uint32 randomMT(void)
{
uint32 y;
if(--left < 0)
return(reloadMT());
y = *next++;
y ^= (y >> 11);
y ^= (y << 7) & 0x9D2C5680U;
y ^= (y << 15) & 0xEFC60000U;
return(y ^ (y >> 18));
}
#if HAVE_LRAND48
#define PHP_RAND_MAX 2147483647
#else
#define PHP_RAND_MAX RAND_MAX
#endif
void php3_srand(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg);
#ifdef HAVE_SRAND48
srand48((unsigned int) arg->value.lval);
#else
#ifdef HAVE_SRANDOM
srandom((unsigned int) arg->value.lval);
#else
srand((unsigned int) arg->value.lval);
#endif
#endif
}
void php3_mt_srand(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(arg);
seedMT(arg->value.lval);
}
void php3_rand(INTERNAL_FUNCTION_PARAMETERS)
{
pval *p_min=NULL, *p_max=NULL;
switch (ARG_COUNT(ht)) {
case 0:
break;
case 2:
if (getParameters(ht, 2, &p_min, &p_max)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(p_min);
convert_to_long(p_max);
if (p_max->value.lval-p_min->value.lval <= 0) {
php3_error(E_WARNING,"rand(): Invalid range: %ld..%ld", p_min->value.lval, p_max->value.lval);
}
break;
default:
WRONG_PARAM_COUNT;
break;
}
return_value->type = IS_LONG;
#ifdef HAVE_LRAND48
return_value->value.lval = lrand48();
#else
#ifdef HAVE_RANDOM
return_value->value.lval = random();
#else
return_value->value.lval = rand();
#endif
#endif
if (p_min && p_max) { /* implement range */
return_value->value.lval = p_min->value.lval +
(int)((double)p_max->value.lval * return_value->value.lval/(PHP_RAND_MAX+(double)p_min->value.lval));
}
}
void php3_mt_rand(INTERNAL_FUNCTION_PARAMETERS)
{
pval *p_min=NULL, *p_max=NULL;
switch (ARG_COUNT(ht)) {
case 0:
break;
case 2:
if (getParameters(ht, 2, &p_min, &p_max)==FAILURE) {
RETURN_FALSE;
}
convert_to_long(p_min);
convert_to_long(p_max);
if (p_max->value.lval-p_min->value.lval <= 0) {
php3_error(E_WARNING,"mtrand(): Invalid range: %ld..%ld", p_min->value.lval, p_max->value.lval);
}
break;
default:
WRONG_PARAM_COUNT;
break;
}
return_value->type = IS_LONG;
/*
* Melo: hmms.. randomMT() returns 32 random bits...
* Yet, the previous php3_rand only returns 31 at most.
* So I put a right shift to loose the lsb. It *seems*
* better than clearing the msb.
* Update:
* I talked with Cokus via email and it won't ruin the algorithm
*/
return_value->value.lval = (long)(randomMT() >> 1);
if (p_min && p_max) { /* implement range */
return_value->value.lval = p_min->value.lval +
(int)((double)p_max->value.lval * return_value->value.lval/(PHP_RAND_MAX+(double)p_min->value.lval));
}
}
void php3_getrandmax(INTERNAL_FUNCTION_PARAMETERS)
{
return_value->type = IS_LONG;
return_value->value.lval = PHP_RAND_MAX;
}
void php3_mt_getrandmax(INTERNAL_FUNCTION_PARAMETERS)
{
return_value->type = IS_LONG;
/*
* Melo: it could be 2^^32 but we only use 2^^31 to maintain
* compatibility with the previous php3_rand
*/
return_value->value.lval = 2147483647; /* 2^^31 */
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

569
ext/standard/reg.c Normal file
View file

@ -0,0 +1,569 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
| Jim Winstead <jimw@php.net> |
| Jaakko Hyvätti <jaakko@hyvatti.iki.fi> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <stdio.h>
#include "php.h"
#include "php3_string.h"
#include "reg.h"
unsigned char third_argument_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE };
function_entry reg_functions[] = {
{"ereg", php3_ereg, third_argument_force_ref },
{"ereg_replace", php3_eregreplace, NULL },
{"eregi", php3_eregi, third_argument_force_ref },
{"eregi_replace", php3_eregireplace, NULL },
{"split", php3_split, NULL},
{"join", php3_implode, NULL},
{"sql_regcase", php3_sql_regcase, NULL},
{NULL, NULL, NULL}
};
php3_module_entry regexp_module_entry = {
"Regular Expressions", reg_functions, NULL, NULL, NULL, NULL, NULL, STANDARD_MODULE_PROPERTIES
};
/* This is the maximum number of (..) constructs we'll generate from a
call to ereg() or eregi() with the optional third argument. */
#define NS 10
/*
* _php3_reg_eprint - convert error number to name
*/
static void _php3_reg_eprint(int err, regex_t *re) {
char *buf = NULL, *message = NULL;
size_t len;
size_t buf_len;
#ifdef REG_ITOA
/* get the length of the message */
buf_len = regerror(REG_ITOA | err, re, NULL, 0);
if (buf_len) {
buf = (char *)emalloc(buf_len * sizeof(char));
if (!buf) return; /* fail silently */
/* finally, get the error message */
regerror(REG_ITOA | err, re, buf, buf_len);
}
#else
buf_len = 0;
#endif
len = regerror(err, re, NULL, 0);
if (len) {
message = (char *)emalloc((buf_len + len + 2) * sizeof(char));
if (!message) {
return; /* fail silently */
}
if (buf_len) {
snprintf(message, buf_len, "%s: ", buf);
buf_len += 1; /* so pointer math below works */
}
/* drop the message into place */
regerror(err, re, message + buf_len, len);
php3_error(E_WARNING, "%s", message);
}
STR_FREE(buf);
STR_FREE(message);
}
static void _php3_ereg(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval *regex, /* Regular expression */
*findin, /* String to apply expression to */
*array = NULL; /* Optional register array */
regex_t re;
regmatch_t subs[NS];
int err, i, match_len, string_len;
int copts = 0;
off_t start, end;
char *buf = NULL;
char *string = NULL;
TLS_VARS;
if (icase)
copts |= REG_ICASE;
switch(ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 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 (getParameters(ht, 3, &regex, &findin, &array) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (!ParameterPassedByReference(ht, 3)) {
php3_error(E_WARNING, "Array to be filled with values must be passed by reference.");
RETURN_FALSE;
}
break;
default:
WRONG_PARAM_COUNT;
}
/* compile the regular expression from the supplied regex */
if (regex->type == IS_STRING) {
err = regcomp(&re, regex->value.str.val, REG_EXTENDED | copts);
} else {
/* we convert numbers to integers and treat them as a string */
if (regex->type == IS_DOUBLE)
convert_to_long(regex); /* get rid of decimal places */
convert_to_string(regex);
/* don't bother doing an extended regex with just a number */
err = regcomp(&re, regex->value.str.val, copts);
}
if (err) {
_php3_reg_eprint(err, &re);
RETURN_FALSE;
}
/* make a copy of the string we're looking in */
convert_to_string(findin);
string = estrndup(findin->value.str.val, findin->value.str.len);
/* actually execute the regular expression */
err = regexec(&re, string, (size_t) NS, subs, 0);
if (err && err != REG_NOMATCH) {
_php3_reg_eprint(err, &re);
regfree(&re);
RETURN_FALSE;
}
match_len = 1;
if (array && err != REG_NOMATCH) {
match_len = (int) (subs[0].rm_eo - subs[0].rm_so);
string_len = strlen(string) + 1;
buf = emalloc(string_len);
if (!buf) {
php3_error(E_WARNING, "Unable to allocate memory in _php3_ereg");
RETURN_FALSE;
}
pval_destructor(array _INLINE_TLS); /* 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);
}
}
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 */
void php3_ereg(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto int eregi(string pattern, string string [, array registers])
Case-insensitive regular expression match */
void php3_eregi(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_ereg(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* this is the meat and potatoes of regex replacement! */
char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended)
{
regex_t re;
regmatch_t subs[NS];
char *buf, /* buf is where we build the replaced string */
*nbuf, /* nbuf is used when we grow the buffer */
*walkbuf; /* used to walk buf when replacing backrefs */
const char *walk; /* used to walk replacement string for backrefs */
int buf_len;
int pos, tmp, string_len, new_l;
int err, copts = 0;
string_len = strlen(string);
if (!string_len)
return (char *)string;
if (icase)
copts = REG_ICASE;
if (extended)
copts |= REG_EXTENDED;
err = regcomp(&re, pattern, copts);
if (err) {
_php3_reg_eprint(err, &re);
return ((char *) -1);
}
/* start with a buffer that is twice the size of the stringo
we're doing replacements in */
buf_len = 2 * string_len + 1;
buf = emalloc(buf_len * sizeof(char));
if (!buf) {
php3_error(E_WARNING, "Unable to allocate memory in _php3_regreplace");
regfree(&re);
return ((char *) -1);
}
err = pos = 0;
buf[0] = '\0';
while (!err) {
err = regexec(&re, &string[pos], (size_t) NS, subs, (pos ? REG_NOTBOL : 0));
if (err && err != REG_NOMATCH) {
_php3_reg_eprint(err, &re);
regfree(&re);
return ((char *) -1);
}
if (!err) {
/* backref replacement is done in two passes:
1) find out how long the string will be, and allocate buf
2) copy the part before match, replacement and backrefs to buf
Jaakko Hyvätti <Jaakko.Hyvatti@iki.fi>
*/
new_l = strlen(buf) + subs[0].rm_so; /* part before the match */
walk = replace;
while (*walk)
if ('\\' == *walk
&& '0' <= walk[1] && '9' >= walk[1]
&& subs[walk[1] - '0'].rm_so > -1
&& subs[walk[1] - '0'].rm_eo > -1) {
new_l += subs[walk[1] - '0'].rm_eo
- subs[walk[1] - '0'].rm_so;
walk += 2;
} else {
new_l++;
walk++;
}
if (new_l + 1 > buf_len) {
buf_len = 1 + buf_len + 2 * new_l;
nbuf = emalloc(buf_len);
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
tmp = strlen(buf);
/* copy the part of the string before the match */
strncat(buf, &string[pos], subs[0].rm_so);
/* copy replacement and backrefs */
walkbuf = &buf[tmp + subs[0].rm_so];
walk = replace;
while (*walk)
if ('\\' == *walk
&& '0' <= walk[1] && '9' >= walk[1]
&& subs[walk[1] - '0'].rm_so > -1
&& subs[walk[1] - '0'].rm_eo > -1) {
tmp = subs[walk[1] - '0'].rm_eo
- subs[walk[1] - '0'].rm_so;
memcpy (walkbuf,
&string[pos + subs[walk[1] - '0'].rm_so],
tmp);
walkbuf += tmp;
walk += 2;
} else
*walkbuf++ = *walk++;
*walkbuf = '\0';
/* and get ready to keep looking for replacements */
if (subs[0].rm_so == subs[0].rm_eo) {
if (subs[0].rm_so + pos >= string_len)
break;
new_l = strlen (buf) + 1;
if (new_l + 1 > buf_len) {
buf_len = 1 + buf_len + 2 * new_l;
nbuf = emalloc(buf_len * sizeof(char));
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
pos += subs[0].rm_eo + 1;
buf [new_l-1] = string [pos-1];
buf [new_l] = '\0';
} else {
pos += subs[0].rm_eo;
}
} else { /* REG_NOMATCH */
new_l = strlen(buf) + strlen(&string[pos]);
if (new_l + 1 > buf_len) {
buf_len = new_l + 1; /* now we know exactly how long it is */
nbuf = emalloc(buf_len * sizeof(char));
strcpy(nbuf, buf);
efree(buf);
buf = nbuf;
}
/* stick that last bit of string on our output */
strcat(buf, &string[pos]);
}
}
/* don't want to leak memory .. */
regfree(&re);
/* whew. */
return (buf);
}
static void _php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS, int icase)
{
pval *arg_pattern,
*arg_replace,
*arg_string;
char *pattern;
char *string;
char *replace;
char *ret;
TLS_VARS;
if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &arg_pattern, &arg_replace, &arg_string) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (arg_pattern->type == IS_STRING) {
if (arg_pattern->value.str.val && arg_pattern->value.str.len)
pattern = estrndup(arg_pattern->value.str.val,arg_pattern->value.str.len);
else
pattern = empty_string;
} else {
convert_to_long(arg_pattern);
pattern = emalloc(2);
pattern[0] = (char) arg_pattern->value.lval;
pattern[1] = '\0';
}
if (arg_replace->type == IS_STRING) {
if (arg_replace->value.str.val && arg_replace->value.str.len)
replace = estrndup(arg_replace->value.str.val, arg_replace->value.str.len);
else
replace = empty_string;
} else {
convert_to_long(arg_replace);
replace = emalloc(2);
replace[0] = (char) arg_replace->value.lval;
replace[1] = '\0';
}
convert_to_string(arg_string);
if (arg_string->value.str.val && arg_string->value.str.len)
string = estrndup(arg_string->value.str.val, arg_string->value.str.len);
else
string = empty_string;
/* do the actual work */
ret = _php3_regreplace(pattern, replace, string, icase, 1);
if (ret == (char *) -1) {
RETVAL_FALSE;
} else {
RETVAL_STRING(ret,1);
STR_FREE(ret);
}
STR_FREE(string);
STR_FREE(replace);
STR_FREE(pattern);
}
/* {{{ proto string ereg_replace(string pattern, string string [, array registers])
Replace regular expression */
void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
/* {{{ proto string eregi_replace(string pattern, string string [, array registers])
Case insensitive replace regular expression */
void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS)
{
_php3_eregreplace(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
}
/* }}} */
/* ("root", "passwd", "uid", "gid", "other:stuff:like:/bin/sh")
= split(":", $passwd_file, 5); */
/* {{{ proto array split(string pattern, string string [, int limit])
split string into array by regular expression */
void php3_split(INTERNAL_FUNCTION_PARAMETERS)
{
pval *spliton, *str, *arg_count = NULL;
regex_t re;
regmatch_t subs[1];
char *strp, *endp;
int err, size, count;
TLS_VARS;
switch (ARG_COUNT(ht)) {
case 2:
if (getParameters(ht, 2, &spliton, &str) == FAILURE)
WRONG_PARAM_COUNT;
count = -1;
break;
case 3:
if (getParameters(ht, 3, &spliton, &str, &arg_count) == FAILURE)
WRONG_PARAM_COUNT;
convert_to_long(arg_count);
count = arg_count->value.lval;
break;
default:
WRONG_PARAM_COUNT;
}
convert_to_string(spliton);
convert_to_string(str);
strp = str->value.str.val;
endp = str->value.str.val + strlen(str->value.str.val);
err = regcomp(&re, spliton->value.str.val, REG_EXTENDED);
if (err) {
php3_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);
php3_error(E_WARNING, "bad regular expression for split()");
_php3_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) {
php3_error(E_WARNING, "unexpected regex error (%d)", err);
regfree(&re);
_php3_hash_destroy(return_value->value.ht);
efree(return_value->value.ht);
RETURN_FALSE;
}
/* otherwise we just have one last element to add to the array */
size = endp - strp;
add_next_index_stringl(return_value, strp, size, 1);
regfree(&re);
return;
}
/* }}} */
/* {{{ proto string sql_regcase(string string)
Make regular expression for case insensitive match */
PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS)
{
pval *string;
char *tmp;
register int i;
if (ARG_COUNT(ht)!=1 || getParameters(ht, 1, &string)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(string);
tmp = (char *) emalloc(string->value.str.len*4+1);
for (i=0; i<string->value.str.len; i++) {
tmp[i*4] = '[';
tmp[i*4+1]=toupper((unsigned char)string->value.str.val[i]);
tmp[i*4+2]=tolower((unsigned char)string->value.str.val[i]);
tmp[i*4+3]=']';
}
tmp[string->value.str.len*4]=0;
return_value->value.str.val = tmp;
return_value->value.str.len = string->value.str.len*4;
return_value->type = IS_STRING;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

48
ext/standard/reg.h Normal file
View file

@ -0,0 +1,48 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _REG_H
#define _REG_H
extern php3_module_entry regexp_module_entry;
#define regexp_module_ptr &regexp_module_entry
extern char *_php3_regreplace(const char *pattern, const char *replace, const char *string, int icase, int extended);
extern void php3_ereg(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregi(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregireplace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_eregreplace(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_split(INTERNAL_FUNCTION_PARAMETERS);
extern PHPAPI void php3_sql_regcase(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _REG_H */

136
ext/standard/soundex.c Normal file
View file

@ -0,0 +1,136 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Bjørn Borud - Guardian Networks AS <borud@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "php.h"
#include <stdlib.h>
#include <errno.h>
#include <ctype.h>
#include "php3_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 */
void soundex(INTERNAL_FUNCTION_PARAMETERS)
{
char l, u;
char *somestring;
int i, j, n;
pval *arg;
/* pad with '0' and terminate with 0 ;-) */
char soundex[5] =
{'0', '0', '0', '0', 0};
static char soundex_table[26] =
{0, /* A */
'1', /* B */
'2', /* C */
'3', /* D */
0, /* E */
'1', /* F */
'2', /* G */
0, /* H */
0, /* I */
'2', /* J */
'2', /* K */
'4', /* L */
'5', /* M */
'5', /* N */
0, /* O */
'1', /* P */
'2', /* Q */
'6', /* R */
'2', /* S */
'3', /* T */
0, /* U */
'1', /* V */
0, /* W */
'2', /* X */
0, /* Y */
'2'}; /* Z */
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (arg->value.str.len==0) {
RETURN_FALSE;
}
somestring = arg->value.str.val;
n = arg->value.str.len;
/* convert chars to upper case and strip non-letter chars */
j = 0;
for (i = 0; i < n; i++) {
u = toupper(somestring[i]);
if ((u > 64) && (u < 91)) {
somestring[j] = u;
j++;
}
}
/* null-terminate string */
somestring[j] = 0;
n = strlen(somestring);
/* prefix soundex string with first valid char */
soundex[0] = somestring[0];
/* remember first char */
l = soundex_table[((somestring[0]) - 65)];
j = 1;
/* build soundex string */
for (i = 1; i < n && j < 4; i++) {
u = soundex_table[((somestring[i]) - 65)];
if (u != l) {
if (u != 0) {
soundex[(int) j++] = u;
}
l = u;
}
}
return_value->value.str.val = estrndup(soundex, 4);
return_value->value.str.len = strlen(soundex);
return_value->type = IS_STRING;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

1590
ext/standard/string.c Normal file

File diff suppressed because it is too large Load diff

296
ext/standard/syslog.c Normal file
View file

@ -0,0 +1,296 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "zend_globals.h"
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if MSVC5
#include "win32/syslog.h"
#else
#include <syslog.h>
#endif
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "php3_syslog.h"
static int syslog_started;
static char *syslog_device;
static void start_syslog(void);
int php3_minit_syslog(INIT_FUNC_ARGS)
{
TLS_VARS;
/* error levels */
REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
REGISTER_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
/* facility: type of program logging the message */
REGISTER_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
REGISTER_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
REGISTER_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
REGISTER_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
#ifdef LOG_NEWS
/* No LOG_NEWS on HP-UX */
REGISTER_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */
#endif
#ifdef LOG_UUCP
/* No LOG_UUCP on HP-UX */
REGISTER_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
#endif
#ifdef LOG_CRON
/* apparently some systems don't have this one */
REGISTER_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
#endif
#ifdef LOG_AUTHPRIV
/* AIX doesn't have LOG_AUTHPRIV */
REGISTER_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
#endif
#ifndef MSVC5
REGISTER_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
#endif
/* options */
REGISTER_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
#ifdef LOG_PERROR
/* AIX doesn't have LOG_PERROR */
REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
#endif
return SUCCESS;
}
int php3_rinit_syslog(INIT_FUNC_ARGS)
{
if (INI_INT("define_syslog_variables")) {
start_syslog();
} else {
syslog_started=0;
}
syslog_device=NULL;
return SUCCESS;
}
int php3_rshutdown_syslog(SHUTDOWN_FUNC_ARGS)
{
if (syslog_device) {
efree(syslog_device);
}
return SUCCESS;
}
static void start_syslog(void)
{
ELS_FETCH();
/* error levels */
SET_VAR_LONG("LOG_EMERG", LOG_EMERG); /* system unusable */
SET_VAR_LONG("LOG_ALERT", LOG_ALERT); /* immediate action required */
SET_VAR_LONG("LOG_CRIT", LOG_CRIT); /* critical conditions */
SET_VAR_LONG("LOG_ERR", LOG_ERR);
SET_VAR_LONG("LOG_WARNING", LOG_WARNING);
SET_VAR_LONG("LOG_NOTICE", LOG_NOTICE);
SET_VAR_LONG("LOG_INFO", LOG_INFO);
SET_VAR_LONG("LOG_DEBUG", LOG_DEBUG);
/* facility: type of program logging the message */
SET_VAR_LONG("LOG_KERN", LOG_KERN);
SET_VAR_LONG("LOG_USER", LOG_USER); /* generic user level */
SET_VAR_LONG("LOG_MAIL", LOG_MAIL); /* log to email */
SET_VAR_LONG("LOG_DAEMON", LOG_DAEMON); /* other system daemons */
SET_VAR_LONG("LOG_AUTH", LOG_AUTH);
SET_VAR_LONG("LOG_SYSLOG", LOG_SYSLOG);
SET_VAR_LONG("LOG_LPR", LOG_LPR);
#ifdef LOG_NEWS
/* No LOG_NEWS on HP-UX */
SET_VAR_LONG("LOG_NEWS", LOG_NEWS); /* usenet new */
#endif
#ifdef LOG_UUCP
/* No LOG_UUCP on HP-UX */
SET_VAR_LONG("LOG_UUCP", LOG_UUCP);
#endif
#ifdef LOG_CRON
/* apparently some systems don't have this one */
SET_VAR_LONG("LOG_CRON", LOG_CRON);
#endif
#ifdef LOG_AUTHPRIV
/* AIX doesn't have LOG_AUTHPRIV */
SET_VAR_LONG("LOG_AUTHPRIV", LOG_AUTHPRIV);
#endif
#ifndef MSVC5
SET_VAR_LONG("LOG_LOCAL0", LOG_LOCAL0);
SET_VAR_LONG("LOG_LOCAL1", LOG_LOCAL1);
SET_VAR_LONG("LOG_LOCAL2", LOG_LOCAL2);
SET_VAR_LONG("LOG_LOCAL3", LOG_LOCAL3);
SET_VAR_LONG("LOG_LOCAL4", LOG_LOCAL4);
SET_VAR_LONG("LOG_LOCAL5", LOG_LOCAL5);
SET_VAR_LONG("LOG_LOCAL6", LOG_LOCAL6);
SET_VAR_LONG("LOG_LOCAL7", LOG_LOCAL7);
#endif
/* options */
SET_VAR_LONG("LOG_PID", LOG_PID);
SET_VAR_LONG("LOG_CONS", LOG_CONS);
SET_VAR_LONG("LOG_ODELAY", LOG_ODELAY);
SET_VAR_LONG("LOG_NDELAY", LOG_NDELAY);
SET_VAR_LONG("LOG_NOWAIT", LOG_NOWAIT);
#ifdef LOG_PERROR
/* AIX doesn't have LOG_PERROR */
SET_VAR_LONG("LOG_PERROR", LOG_PERROR); /*log to stderr*/
#endif
syslog_started=1;
}
/* {{{ proto void define_syslog_variables(void)
Initializes all syslog-related variables */
void php3_define_syslog_variables(INTERNAL_FUNCTION_PARAMETERS)
{
if (!syslog_started) {
start_syslog();
}
}
/* {{{ proto int openlog(string ident, int option, int facility)
Open connection to system logger */
/*
** OpenLog("nettopp", $LOG_PID, $LOG_LOCAL1);
** Syslog($LOG_EMERG, "help me!")
** CloseLog();
*/
void php3_openlog(INTERNAL_FUNCTION_PARAMETERS)
{
pval *ident, *option, *facility;
if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &ident, &option, &facility) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(ident);
convert_to_long(option);
convert_to_long(facility);
if (syslog_device) {
efree(syslog_device);
}
syslog_device = estrndup(ident->value.str.val,ident->value.str.len);
openlog(syslog_device, option->value.lval, facility->value.lval);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int closelog(void)
Close connection to system logger */
void php3_closelog(INTERNAL_FUNCTION_PARAMETERS)
{
closelog();
if (syslog_device) {
efree(syslog_device);
syslog_device=NULL;
}
RETURN_TRUE;
}
/* }}} */
/* {{{ proto int syslog(int priority, string message)
Generate a system log message */
void php3_syslog(INTERNAL_FUNCTION_PARAMETERS)
{
pval *priority, *message;
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &priority, &message) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_long(priority);
convert_to_string(message);
/*
* CAVEAT: if the message contains patterns such as "%s",
* this will cause problems.
*/
syslog(priority->value.lval, message->value.str.val);
RETURN_TRUE;
}
/* }}} */
function_entry syslog_functions[] = {
{"openlog", php3_openlog, NULL},
{"syslog", php3_syslog, NULL},
{"closelog", php3_closelog, NULL},
{"define_syslog_variables", php3_define_syslog_variables, NULL},
{NULL, NULL, NULL}
};
php3_module_entry syslog_module_entry = {
"Syslog", syslog_functions, php3_minit_syslog, NULL, php3_rinit_syslog, php3_rshutdown_syslog, NULL, STANDARD_MODULE_PROPERTIES
};
#if COMPILE_DL
DLEXPORT php3_module_entry *get_module(void) { return &syslog_module_entry; }
#endif
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

108
ext/standard/type.c Normal file
View file

@ -0,0 +1,108 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf |
| |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include "php.h"
#include "type.h"
/*
* Determines if 'str' is an integer (long), real number or a string
*
* Note that leading zeroes automatically force a STRING type
*/
int php3_check_type(char *str)
{
char *s;
int type = IS_LONG;
s = str;
if (*s == '0' && *(s + 1) && *(s + 1) != '.')
return (IS_STRING);
if (*s == '+' || *s == '-' || (*s >= '0' && *s <= '9') || *s == '.') {
if (*s == '.')
type = IS_DOUBLE;
s++;
while (*s) {
if (*s >= '0' && *s <= '9') {
s++;
continue;
} else if (*s == '.' && type == IS_LONG) {
type = IS_DOUBLE;
s++;
continue;
} else
return (IS_STRING);
}
} else
return (IS_STRING);
return (type);
} /* php3_check_type */
/*
* 0 - simple variable
* 1 - non-index array
* 2 - index array
*/
int php3_check_ident_type(char *str)
{
char *s;
if (!(s = (char *) strchr(str, '[')))
return (GPC_REGULAR);
s++;
while (*s == ' ' || *s == '\t' || *s == '\n') {
s++;
}
if (*s == ']') {
return (GPC_NON_INDEXED_ARRAY);
}
return (GPC_INDEXED_ARRAY);
}
char *php3_get_ident_index(char *str)
{
char *temp;
char *s, *t;
char o;
temp = emalloc(strlen(str));
temp[0] = '\0';
s = (char *) strchr(str, '[');
if (s) {
t = (char *) strrchr(str, ']');
if (t) {
o = *t;
*t = '\0';
strcpy(temp, s + 1);
*t = o;
}
}
return (temp);
}

41
ext/standard/type.h Normal file
View file

@ -0,0 +1,41 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
+----------------------------------------------------------------------+
*/
#ifndef _TYPE_H
#define _TYPE_H
extern int php3_check_type(char *str);
extern int php3_check_ident_type(char *str);
extern char *php3_get_ident_index(char *str);
#define GPC_REGULAR 0x1
#define GPC_INDEXED_ARRAY 0x2
#define GPC_NON_INDEXED_ARRAY 0x4
#define GPC_ARRAY (GPC_INDEXED_ARRAY | GPC_NON_INDEXED_ARRAY)
#endif

103
ext/standard/uniqid.c Normal file
View file

@ -0,0 +1,103 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include <stdlib.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <string.h>
#include <errno.h>
#include <stdio.h>
#if MSVC5
#include "win32/time.h"
#else
#include <sys/time.h>
#endif
#include "uniqid.h"
/* {{{ proto string uniqid(string prefix)
Generate a unique id */
void php3_uniqid(INTERNAL_FUNCTION_PARAMETERS)
{
#ifdef HAVE_GETTIMEOFDAY
pval *prefix;
char uniqid[128];
int sec, usec;
struct timeval tv;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht,1,&prefix)==FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(prefix);
/* Do some bounds checking since we are using a char array. */
if (strlen(prefix->value.str.val) > 114) {
php3_error(E_WARNING, "The prefix to uniqid should not be more than 114 characters.");
return;
}
/* dont need this on windows so lets not do it*/
#if HAVE_USLEEP && !(WIN32|WINNT)
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:
*/
sprintf(uniqid, "%s%08x%05x", prefix->value.str.val, sec, usec);
RETURN_STRING(uniqid,1);
#endif
}
/* }}} */
function_entry uniqid_functions[] = {
{"uniqid", php3_uniqid, NULL},
{NULL, NULL, NULL}
};
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

37
ext/standard/uniqid.h Normal file
View file

@ -0,0 +1,37 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Stig Sæther Bakken <ssb@guardian.no> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifndef _UNIQID_H
#define _UNIQID_H
extern void php3_uniqid(INTERNAL_FUNCTION_PARAMETERS);
#endif /* _UNIQID_H */

439
ext/standard/url.c Normal file
View file

@ -0,0 +1,439 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Author: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
/* php.h includes the correct regex.h */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include "php.h"
#include "url.h"
#ifdef _OSD_POSIX
#ifndef APACHE
#error On this EBCDIC platform, PHP3 is only supported as an Apache module.
#else /*APACHE*/
#ifndef CHARSET_EBCDIC
#define CHARSET_EBCDIC /* this machine uses EBCDIC, not ASCII! */
#endif
#include "ebcdic.h"
#endif /*APACHE*/
#endif /*_OSD_POSIX*/
void free_url(url * theurl)
{
if (theurl->scheme)
efree(theurl->scheme);
if (theurl->user)
efree(theurl->user);
if (theurl->pass)
efree(theurl->pass);
if (theurl->host)
efree(theurl->host);
if (theurl->path)
efree(theurl->path);
if (theurl->query)
efree(theurl->query);
if (theurl->fragment)
efree(theurl->fragment);
efree(theurl);
}
url *url_parse(char *string)
{
regex_t re;
regmatch_t subs[10];
int err;
int length = strlen(string);
char *result;
url *ret = (url *) emalloc(sizeof(url));
if (!ret) {
/*php3_error(E_WARNING,"Unable to allocate memory\n");*/
return NULL;
}
memset(ret, 0, sizeof(url));
/* from Appendix B of draft-fielding-url-syntax-09,
http://www.ics.uci.edu/~fielding/url/url.txt */
err = regcomp(&re, "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?", REG_EXTENDED);
if (err) {
/*php3_error(E_WARNING,"Unable to compile regex: %d\n", err);*/
efree(ret);
return NULL;
}
err = regexec(&re, string, 10, subs, 0);
if (err) {
/*php3_error(E_WARNING,"Error with regex\n");*/
efree(ret);
return NULL;
}
/* no processing necessary on the scheme */
if (subs[2].rm_so != -1 && subs[2].rm_so < length) {
ret->scheme = estrndup(string + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
}
/* the path to the resource */
if (subs[5].rm_so != -1 && subs[5].rm_so < length) {
ret->path = estrndup(string + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so);
}
/* the query part */
if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
ret->query = estrndup(string + subs[7].rm_so, subs[7].rm_eo - subs[7].rm_so);
}
/* the fragment */
if (subs[9].rm_so != -1 && subs[9].rm_so < length) {
ret->fragment = estrndup(string + subs[9].rm_so, subs[9].rm_eo - subs[9].rm_so);
}
/* extract the username, pass, and port from the hostname */
if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
/* extract username:pass@host:port from regex results */
result = estrndup(string + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
length = strlen(result);
regfree(&re); /* free the old regex */
if ((err=regcomp(&re, "^(([^@:]+)(:([^@:]+))?@)?([^:@]+)(:([^:@]+))?", REG_EXTENDED))
|| (err=regexec(&re, result, 10, subs, 0))) {
STR_FREE(ret->scheme);
STR_FREE(ret->path);
STR_FREE(ret->query);
STR_FREE(ret->fragment);
efree(ret);
efree(result);
/*php3_error(E_WARNING,"Unable to compile regex: %d\n", err);*/
return NULL;
}
/* now deal with all of the results */
if (subs[2].rm_so != -1 && subs[2].rm_so < length) {
ret->user = estrndup(result + subs[2].rm_so, subs[2].rm_eo - subs[2].rm_so);
}
if (subs[4].rm_so != -1 && subs[4].rm_so < length) {
ret->pass = estrndup(result + subs[4].rm_so, subs[4].rm_eo - subs[4].rm_so);
}
if (subs[5].rm_so != -1 && subs[5].rm_so < length) {
ret->host = estrndup(result + subs[5].rm_so, subs[5].rm_eo - subs[5].rm_so);
}
if (subs[7].rm_so != -1 && subs[7].rm_so < length) {
ret->port = (unsigned short) strtol(result + subs[7].rm_so, NULL, 10);
}
efree(result);
}
regfree(&re);
return ret;
}
/* {{{ proto array parse_url(string url)
Parse a URL and return its components */
void php3_parse_url(INTERNAL_FUNCTION_PARAMETERS)
{
pval *string;
url *resource;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &string) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(string);
resource = url_parse(string->value.str.val);
if (resource == NULL) {
php3_error(E_WARNING, "unable to parse url (%s)", string->value.str.val);
RETURN_FALSE;
}
/* allocate an array for return */
if (array_init(return_value) == FAILURE) {
free_url(resource);
RETURN_FALSE;
}
/* add the various elements to the array */
if (resource->scheme != NULL)
add_assoc_string(return_value, "scheme", resource->scheme, 1);
if (resource->host != NULL)
add_assoc_string(return_value, "host", resource->host, 1);
if (resource->port != 0)
add_assoc_long(return_value, "port", resource->port);
if (resource->user != NULL)
add_assoc_string(return_value, "user", resource->user, 1);
if (resource->pass != NULL)
add_assoc_string(return_value, "pass", resource->pass, 1);
if (resource->path != NULL)
add_assoc_string(return_value, "path", resource->path, 1);
if (resource->query != NULL)
add_assoc_string(return_value, "query", resource->query, 1);
if (resource->fragment != NULL)
add_assoc_string(return_value, "fragment", resource->fragment, 1);
free_url(resource);
}
/* }}} */
static int php3_htoi(char *s)
{
int value;
int c;
c = s[0];
if (isupper(c))
c = tolower(c);
value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16;
c = s[1];
if (isupper(c))
c = tolower(c);
value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10;
return (value);
}
/* rfc1738:
...The characters ";",
"/", "?", ":", "@", "=" and "&" are the characters which may be
reserved for special meaning within a scheme...
...Thus, only alphanumerics, the special characters "$-_.+!*'(),", and
reserved characters used for their reserved purposes may be used
unencoded within a URL...
For added safety, we only leave -_. unencoded.
*/
static unsigned char hexchars[] = "0123456789ABCDEF";
char *_php3_urlencode(char *s, int len)
{
register int x, y;
unsigned char *str;
str = (unsigned char *) emalloc(3 * strlen(s) + 1);
for (x = 0, y = 0; len--; x++, y++) {
str[y] = (unsigned char) s[x];
if (str[y] == ' ') {
str[y] = '+';
#ifndef CHARSET_EBCDIC
} else if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
(str[y] < 'A' && str[y] > '9') ||
(str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
(str[y] > 'z')) {
str[y++] = '%';
str[y++] = hexchars[(unsigned char) s[x] >> 4];
str[y] = hexchars[(unsigned char) s[x] & 15];
}
#else /*CHARSET_EBCDIC*/
} else if (!isalnum(str[y]) && strchr("_-.", str[y]) != NULL) {
str[y++] = '%';
str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 0x0F];
}
#endif /*CHARSET_EBCDIC*/
}
str[y] = '\0';
return ((char *) str);
}
/* {{{ proto string urlencode(string str)
URL-encodes string */
void php3_urlencode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char *str;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (!arg->value.str.len) {
RETURN_FALSE;
}
str = _php3_urlencode(arg->value.str.val, arg->value.str.len);
RETVAL_STRING(str, 1);
efree(str);
}
/* }}} */
/* {{{ proto string urldecode(string str)
Decodes URL-encoded string */
void php3_urldecode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
int len;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (!arg->value.str.len) {
RETURN_FALSE;
}
len = _php3_urldecode(arg->value.str.val, arg->value.str.len);
RETVAL_STRINGL(arg->value.str.val, len, 1);
}
/* }}} */
int _php3_urldecode(char *str, int len)
{
char *dest = str;
char *data = str;
while (len--) {
if (*data == '+')
*dest = ' ';
else if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) {
#ifndef CHARSET_EBCDIC
*dest = (char) php3_htoi(data + 1);
#else
*dest = os_toebcdic[(char) php3_htoi(data + 1)];
#endif
data += 2;
len -= 2;
} else
*dest = *data;
data++;
dest++;
}
*dest = '\0';
return dest - str;
}
char *_php3_rawurlencode(char *s, int len)
{
register int x, y;
unsigned char *str;
str = (unsigned char *) emalloc(3 * len + 1);
for (x = 0, y = 0; len--; x++, y++) {
str[y] = (unsigned char) s[x];
#ifndef CHARSET_EBCDIC
if ((str[y] < '0' && str[y] != '-' && str[y] != '.') ||
(str[y] < 'A' && str[y] > '9') ||
(str[y] > 'Z' && str[y] < 'a' && str[y] != '_') ||
(str[y] > 'z')) {
str[y++] = '%';
str[y++] = hexchars[(unsigned char) s[x] >> 4];
str[y] = hexchars[(unsigned char) s[x] & 15];
#else /*CHARSET_EBCDIC*/
if (!isalnum(str[y]) && strchr("_-.", str[y]) != NULL) {
str[y++] = '%';
str[y++] = hexchars[os_toascii[(unsigned char) s[x]] >> 4];
str[y] = hexchars[os_toascii[(unsigned char) s[x]] & 15];
#endif /*CHARSET_EBCDIC*/
}
}
str[y] = '\0';
return ((char *) str);
}
/* {{{ proto string rawurlencode(string str)
URL-encodes string */
void php3_rawurlencode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
char *str;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (!arg->value.str.len) {
RETURN_FALSE;
}
str = _php3_rawurlencode(arg->value.str.val, arg->value.str.len);
RETVAL_STRING(str, 1);
efree(str);
}
/* }}} */
/* {{{ proto string rawurldecode(string str)
Decodes URL-encodes string */
void php3_rawurldecode(INTERNAL_FUNCTION_PARAMETERS)
{
pval *arg;
int len;
TLS_VARS;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string(arg);
if (!arg->value.str.len) {
RETURN_FALSE;
}
len = _php3_rawurldecode(arg->value.str.val, arg->value.str.len);
RETVAL_STRINGL(arg->value.str.val, len, 1);
}
/* }}} */
int _php3_rawurldecode(char *str, int len)
{
char *dest = str;
char *data = str;
while (len--) {
if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) {
#ifndef CHARSET_EBCDIC
*dest = (char) php3_htoi(data + 1);
#else
*dest = os_toebcdic[(char) php3_htoi(data + 1)];
#endif
data += 2;
len -= 2;
} else
*dest = *data;
data++;
dest++;
}
*dest = '\0';
return dest - str;
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

60
ext/standard/url.h Normal file
View file

@ -0,0 +1,60 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jim Winstead (jimw@php.net) |
+----------------------------------------------------------------------+
*/
/* $Id$ */
typedef struct url {
char *scheme;
char *user;
char *pass;
char *host;
unsigned short port;
char *path;
char *query;
char *fragment;
} url;
extern void free_url(url *);
extern url *url_parse(char *);
extern int _php3_urldecode(char *, int); /* return value: length of decoded string */
extern char *_php3_urlencode(char *, int);
extern int _php3_rawurldecode(char *, int); /* return value: length of decoded string */
extern char *_php3_rawurlencode(char *, int);
extern void php3_parse_url(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_urlencode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_urldecode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rawurlencode(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rawurldecode(INTERNAL_FUNCTION_PARAMETERS);
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

391
ext/standard/var.c Normal file
View file

@ -0,0 +1,391 @@
/*
+----------------------------------------------------------------------+
| PHP HTML Embedded Scripting Language Version 3.0 |
+----------------------------------------------------------------------+
| Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify |
| it under the terms of one of the following licenses: |
| |
| A) the GNU General Public License as published by the Free Software |
| Foundation; either version 2 of the License, or (at your option) |
| any later version. |
| |
| B) the PHP License as published by the PHP Development Team and |
| included in the distribution in the file: LICENSE |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of both licenses referred to here. |
| If you did not, or have any questions about PHP licensing, please |
| contact core@php.net. |
+----------------------------------------------------------------------+
| Authors: Jani Lehtimäki <jkl@njet.net> |
+----------------------------------------------------------------------+
*/
#ifdef THREAD_SAFE
#include "tls.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "php.h"
#include "fopen-wrappers.h"
#include "reg.h"
#include "post.h"
#include "php3_string.h"
#if HAVE_SETLOCALE
#include <locale.h>
#endif
#include "php3_var.h"
void php3api_var_dump(pval *struc, int level)
{
ulong index;
char *key;
int i, c = 0;
pval *data;
char buf[512];
switch (struc->type) {
case IS_LONG:
i = sprintf(buf, "%*cint(%ld)\n", level, ' ', struc->value.lval);
PHPWRITE(&buf[1], i - 1);
break;
case IS_DOUBLE:
i = sprintf(buf, "%*cfloat(%g)\n", level, ' ', struc->value.dval);
PHPWRITE(&buf[1], i - 1);
break;
case IS_STRING:
i = sprintf(buf, "%*cstring(%d) \"", level, ' ', struc->value.str.len);
PHPWRITE(&buf[1], i - 1);
PHPWRITE(struc->value.str.val, struc->value.str.len);
strcpy(buf, "\"\n");
PHPWRITE(buf, strlen(buf));
break;
case IS_ARRAY:
i = sprintf(buf, "%*carray(%d) {\n", level, ' ', _php3_hash_num_elements(struc->value.ht));
PHPWRITE(&buf[1], i - 1);
goto head_done;
case IS_OBJECT:
i = sprintf(buf, "%*cobject(%d) {\n", level, ' ', _php3_hash_num_elements(struc->value.ht));
PHPWRITE(&buf[1], i - 1);
head_done:
_php3_hash_internal_pointer_reset(struc->value.ht);
for (;; _php3_hash_move_forward(struc->value.ht)) {
if ((i = _php3_hash_get_current_key(struc->value.ht, &key, &index)) == HASH_KEY_NON_EXISTANT)
break;
if (c > 0) {
strcpy(buf, "\n");
PHPWRITE(buf, strlen(buf));
}
c++;
if (_php3_hash_get_current_data(struc->value.ht, (void **) (&data)) != SUCCESS || !data || (data == struc))
continue;
switch (i) {
case HASH_KEY_IS_LONG:{
pval d;
d.type = IS_LONG;
d.value.lval = index;
php3api_var_dump(&d, level + 2);
}
break;
case HASH_KEY_IS_STRING:{
pval d;
d.type = IS_STRING;
d.value.str.val = key;
d.value.str.len = strlen(key);
php3api_var_dump(&d, level + 2);
efree(key);
}
break;
}
php3api_var_dump(data, level + 2);
}
i = sprintf(buf, "%*c}\n", level, ' ');
PHPWRITE(&buf[1], i - 1);
break;
default:
i = sprintf(buf, "%*ci:0\n", level, ' ');
PHPWRITE(&buf[1], i - 1);
}
}
PHP_FUNCTION(var_dump)
{
pval *struc;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &struc) == FAILURE) {
WRONG_PARAM_COUNT;
}
php3api_var_dump(struc, 1);
}
#define STR_CAT(P,S,I) {\
pval *__p = (P);\
ulong __i = __p->value.str.len;\
__p->value.str.len += (I);\
if (__p->value.str.val) {\
__p->value.str.val = (char *)erealloc(__p->value.str.val, __p->value.str.len + 1);\
} else {\
__p->value.str.val = emalloc(__p->value.str.len + 1);\
*__p->value.str.val = 0;\
}\
strcat(__p->value.str.val + __i, (S));\
}
void php3api_var_serialize(pval *buf, pval *struc)
{
char s[256];
ulong slen;
int i, ch;
switch (struc->type) {
case IS_LONG:
slen = sprintf(s, "i:%ld;", struc->value.lval);
STR_CAT(buf, s, slen);
return;
case IS_DOUBLE:
slen = sprintf(s, "d:%g;", struc->value.dval);
STR_CAT(buf, s, slen);
return;
case IS_STRING:{
char *p;
i = buf->value.str.len;
slen = sprintf(s, "s:%d:\"", struc->value.str.len);
STR_CAT(buf, s, slen + struc->value.str.len + 2);
p = buf->value.str.val + i + slen;
if (struc->value.str.len > 0) {
memcpy(p, struc->value.str.val, struc->value.str.len);
p += struc->value.str.len;
}
*p++ = '\"';
*p++ = ';';
*p = 0;
}
return;
case IS_ARRAY:
ch = 'a';
goto got_array;
case IS_OBJECT:
ch = 'o';
got_array:
i = _php3_hash_num_elements(struc->value.ht);
slen = sprintf(s, "%c:%d:{", ch, i);
STR_CAT(buf, s, slen);
if (i > 0) {
char *key;
pval *data;
pval d;
ulong index;
_php3_hash_internal_pointer_reset(struc->value.ht);
for (;; _php3_hash_move_forward(struc->value.ht)) {
if ((i = _php3_hash_get_current_key(struc->value.ht, &key, &index)) == HASH_KEY_NON_EXISTANT) {
break;
}
if (_php3_hash_get_current_data(struc->value.ht, (void **) (&data)) != SUCCESS || !data || (data == struc)) {
continue;
}
switch (i) {
case HASH_KEY_IS_LONG:
d.type = IS_LONG;
d.value.lval = index;
php3api_var_serialize(buf, &d);
break;
case HASH_KEY_IS_STRING:
d.type = IS_STRING;
d.value.str.val = key;
d.value.str.len = strlen(key);
php3api_var_serialize(buf, &d);
efree(key);
break;
}
php3api_var_serialize(buf, data);
}
}
STR_CAT(buf, "}", 1);
return;
default:
STR_CAT(buf, "i:0;", 4);
return;
}
}
int php3api_var_unserialize(pval *rval, char **p, char *max)
{
char *q;
char *str;
int i;
switch (**p) {
case 'i':
if (*((*p) + 1) != ':') {
return 0;
}
q = *p;
while (**p && **p != ';') {
(*p)++;
}
if (**p != ';') {
return 0;
}
(*p)++;
rval->type = IS_LONG;
rval->value.lval = atol(q + 2);
return 1;
case 'd':
if (*((*p) + 1) != ':') {
return 0;
}
q = *p;
while (**p && **p != ';') {
(*p)++;
}
if (**p != ';') {
return 0;
}
(*p)++;
rval->type = IS_DOUBLE;
rval->value.dval = atof(q + 2);
return 1;
case 's':
if (*((*p) + 1) != ':') {
return 0;
}
(*p) += 2;
q = *p;
while (**p && **p != ':') {
(*p)++;
}
if (**p != ':') {
return 0;
}
i = atoi(q);
if (i < 0 || (*p + 3 + i) > max || *((*p) + 1) != '\"' ||
*((*p) + 2 + i) != '\"' || *((*p) + 3 + i) != ';') {
return 0;
}
(*p) += 2;
str = emalloc(i + 1);
if (i > 0) {
memcpy(str, *p, i);
}
str[i] = 0;
(*p) += i + 2;
rval->type = IS_STRING;
rval->value.str.val = str;
rval->value.str.len = i;
return 1;
case 'a':
rval->type = IS_ARRAY;
goto got_array;
case 'o':
rval->type = IS_OBJECT;
got_array:
(*p) += 2;
i = atoi(*p);
rval->value.ht = (HashTable *) emalloc(sizeof(HashTable));
_php3_hash_init(rval->value.ht, i + 1, NULL, PVAL_DESTRUCTOR, 0);
while (**p && **p != ':') {
(*p)++;
}
if (**p != ':' || *((*p) + 1) != '{') {
return 0;
}
for ((*p) += 2; **p && **p != '}' && i > 0; i--) {
pval key;
pval data;
if (!php3api_var_unserialize(&key, p, max)) {
return 0;
}
if (!php3api_var_unserialize(&data, p, max)) {
return 0;
}
switch (key.type) {
case IS_LONG:
_php3_hash_index_update(rval->value.ht, key.value.lval, &data, sizeof(data), NULL);
break;
case IS_STRING:
_php3_hash_add(rval->value.ht, key.value.str.val, key.value.str.len + 1, &data, sizeof(data), NULL);
break;
}
pval_destructor(&key);
}
return *((*p)++) == '}';
default:
return 0;
}
}
PHP_FUNCTION(serialize)
{
pval *struc;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &struc) == FAILURE) {
WRONG_PARAM_COUNT;
}
return_value->type = IS_STRING;
return_value->value.str.val = NULL;
return_value->value.str.len = 0;
php3api_var_serialize(return_value, struc);
}
PHP_FUNCTION(unserialize)
{
pval *buf;
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &buf) == FAILURE) {
WRONG_PARAM_COUNT;
}
if (buf->type == IS_STRING) {
char *p = buf->value.str.val;
if (!php3api_var_unserialize(return_value, &p, p + buf->value.str.len)) {
RETURN_FALSE;
}
} else {
RETURN_FALSE;
}
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
*/

View file

@ -40,44 +40,30 @@
#include <stdlib.h>
#include <stdio.h>
#include "ext/standard/php3_standard.h"
#include "ext/gd/php3_gd.h"
#include "functions/php3_ifx.h"
#include "functions/php3_ldap.h"
#include "functions/php3_mysql.h"
#include "functions/php3_bcmath.h"
#include "functions/php3_msql.h"
#include "functions/basic_functions.h"
#include "functions/phpmath.h"
#include "functions/php3_string.h"
#include "functions/php3_oci8.h"
#include "functions/oracle.h"
#include "functions/base64.h"
#include "functions/php3_dir.h"
#include "functions/dns.h"
#include "functions/php3_pgsql.h"
#include "functions/php3_velocis.h"
#include "functions/php3_sybase.h"
#include "functions/php3_sybase-ct.h"
#include "functions/reg.h"
#include "functions/php3_mail.h"
#include "functions/imap.h"
#include "functions/md5.h"
#include "functions/php3_gd.h"
#include "functions/html.h"
#include "functions/dl.h"
#include "functions/head.h"
#include "functions/post.h"
#include "functions/exec.h"
#include "functions/php3_solid.h"
#include "functions/adabasd.h"
#include "functions/file.h"
#include "functions/dbase.h"
#include "functions/hw.h"
#include "functions/filepro.h"
#include "functions/db.h"
#include "functions/php3_syslog.h"
#include "functions/php3_filestat.h"
#include "functions/php3_browscap.h"
#include "functions/pack.h"
#include "functions/php3_unified_odbc.h"
#include "dl/snmp/php3_snmp.h"
#include "functions/php3_zlib.h"
@ -127,7 +113,6 @@ zend_module_entry *php3_builtin_modules[] =
crypt_module_ptr,
dbm_module_ptr,
bcmath_module_ptr,
browscap_module_ptr,
snmp_module_ptr,
pack_module_ptr,
php3_zlib_module_ptr,

View file

@ -37,8 +37,8 @@
#include "php_globals.h"
#include "php_ini.h"
#include "functions/dl.h"
#include "functions/file.h"
#include "functions/php3_browscap.h"
#include "ext/standard/file.h"
#include "ext/standard/php3_browscap.h"
#include "zend_extensions.h"
#if WIN32

View file

@ -55,10 +55,7 @@
#include "safe_mode.h"
#include "php3_realpath.h"
#include "functions/head.h"
#include "functions/url.h"
#include "functions/base64.h"
#include "functions/fsock.h"
#include "functions/php3_string.h"
#include "ext/standard/php3_standard.h"
#include "zend_compile.h"
#if HAVE_PWD_H

View file

@ -67,12 +67,9 @@
#include "main.h"
#include "control_structures.h"
#include "fopen-wrappers.h"
#include "functions/basic_functions.h"
#include "functions/info.h"
#include "functions/head.h"
#include "ext/standard/php3_standard.h"
#include "functions/post.h"
#include "functions/head.h"
#include "functions/type.h"
#include "snprintf.h"
#if WIN32|WINNT
#include <io.h>

View file

@ -39,7 +39,7 @@
#include <unistd.h>
#endif
#include <sys/stat.h>
#include "functions/pageinfo.h"
#include "ext/standard/pageinfo.h"
#include "safe_mode.h"
/*

67
scripts/armerge Executable file
View file

@ -0,0 +1,67 @@
#!/bin/sh
#
# +----------------------------------------------------------------------+
# | PHP HTML Embedded Scripting Language Version 4.0 |
# +----------------------------------------------------------------------+
# | Copyright (c) 1997-1999 PHP Development Team (See Credits file) |
# +----------------------------------------------------------------------+
# | This program is free software; you can redistribute it and/or modify |
# | it under the terms of one of the following licenses: |
# | |
# | A) the GNU General Public License as published by the Free Software |
# | Foundation; either version 2 of the License, or (at your option) |
# | any later version. |
# | |
# | B) the PHP License as published by the PHP Development Team and |
# | included in the distribution in the file: LICENSE |
# | |
# | This program is distributed in the hope that it will be useful, |
# | but WITHOUT ANY WARRANTY; without even the implied warranty of |
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# | GNU General Public License for more details. |
# | |
# | You should have received a copy of both licenses referred to here. |
# | If you did not, or have any questions about PHP licensing, please |
# | contact core@php.net. |
# +----------------------------------------------------------------------+
# | Authors: Stig Sæther Bakken <ssb@fast.no> |
# +----------------------------------------------------------------------+
#
# Archive merger. Usage: armerge libout.a dir1/libin1.a dir2/libin2.a ...
# Creates the archive libout.a from the files in the rest of the
# parameter list. If the input archives are in separate directories,
# the names of the files inside them are prefixed before they are
# merged into the output archive. The prefix used is the same as the
# directory name with "/" replaced by "_" and a "_" at the end.
#
# $Id$
#
if test "$#" -lt "2"; then
echo "Usage: "`basename $0`" <out-archive> <in-archives...>"
exit 1
fi
out_archive=$1; shift
in_archives=$@
rm -f $out_archive
for archive in $in_archives; do
files=`ar t $archive`
ar x $archive
dir=`dirname $archive`
if test "$dir" = "."; then
ext_files=$files
else
prefix=`echo $dir | sed -e 's#/#_#g'`_
prefix=`echo $prefix | sed -e 's#^\.\._##g'`
ext_files=""
for file in $files; do
mv "$file" "$prefix$file"
ext_files="$ext_files $prefix$file"
done
fi
ar vr $out_archive $ext_files
rm -f $ext_files
done

7
scripts/config-stubs Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
#
# $Id$
for stubfile in ext/*/config.m4; do
echo "sinclude($stubfile)"
done

17
scripts/mkextlib.in Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
outfile=$1; shift
extensions=$@
ext_libs=""
for dir in $extensions; do
archive="$dir/libphpext_$dir.a"
if test ! -r "$archive"; then
echo `basename $0`": could not open $archive" >&2
exit 1
fi
ext_libs="$ext_libs $archive"
done
dir=`dirname $0`
(set -x; $dir/armerge $outfile $ext_libs)

7
scripts/preconfig Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
#
# $Id$
makefiles=`echo ext/*/Makefile.am | sed -e 's/\.am//g'`
rm -f configure.in
sed -e "s#@@EXT_MAKEFILES@@#$makefiles#" configure.in.in > configure.in

13
setup
View file

@ -219,24 +219,25 @@ define_option with-apache 'Build as an Apache module?' yesnodir \
The CGI version also enables Apache users to run different PHP3-enabled\n
pages under different user-ids.'
if test "$option_value_with_apache" != "no"; then
define_option with-mod_charset 'Enable transfer tables used by mod_charset?' yesno no \
' Whether to respect transfer tables used by mod_charset when PHP compiled\n
as Apache module. It is required to allow mod_charset (aka Russian Apache)\n
to work properly.'
fi
if test "$option_value_with_apache" = "no"; then
define_option with-fhttpd 'Build as an fhttpd module?' yesnodir \
'no /usr/local/src/fhttpd fhttpd sources' \
' Whether to build PHP as fhttpd module. If you are running\n
fhttpd, building PHP as a module will give better performance,\n
more control and remote execution capability. More info about fhttpd \n
can be found at http://phobos.illtel.denver.co.us/pub/fhttpd/.'
fi
define_option with-gd 'GD support?' yesnodir \
"yes /usr GD install" \
' Whether to include GD support. If PHP can find the GD libraries\n
on your system, it will be included automatically. You should enter\n
something here if you do not want to include GD support or if you\n
have installed GD in some unusual directory.'
for stub in ext/*/setup.stub; do
test -f $stub && . $stub
done
define_option with-oracle 'Oracle support?' yesnodir \
"no $oradir Oracle home" \