diff options
author | Stig Bakken <ssb@php.net> | 1999-04-22 02:48:28 +0000 |
---|---|---|
committer | Stig Bakken <ssb@php.net> | 1999-04-22 02:48:28 +0000 |
commit | 2c0ad3ee25cd8e449b02c4668a39f48998507739 (patch) | |
tree | 8064c7ee59309ffed3d9c5b8fd5c329ede193561 /ext/zlib | |
parent | 2a78f92804ae6f3e32cd278afbb9aa8ec3d2f52d (diff) | |
download | php-git-2c0ad3ee25cd8e449b02c4668a39f48998507739.tar.gz |
last bunch of extensions moving to ext/
fhttpd module taken out of functions, functions is ready to go.
The only extensions I have tested are gd+freetype and odbc(solid).
Please try compiling in your favourite extensions and let me know how it
works.
Diffstat (limited to 'ext/zlib')
-rw-r--r-- | ext/zlib/Makefile.am | 6 | ||||
-rw-r--r-- | ext/zlib/Makefile.in | 270 | ||||
-rw-r--r-- | ext/zlib/config.h.stub | 2 | ||||
-rw-r--r-- | ext/zlib/config.m4 | 38 | ||||
-rw-r--r-- | ext/zlib/php3_zlib.h | 63 | ||||
-rw-r--r-- | ext/zlib/setup.stub | 7 | ||||
-rw-r--r-- | ext/zlib/zlib.c | 926 |
7 files changed, 1312 insertions, 0 deletions
diff --git a/ext/zlib/Makefile.am b/ext/zlib/Makefile.am new file mode 100644 index 0000000000..ef7d3ea49c --- /dev/null +++ b/ext/zlib/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_zlib.a +libphpext_zlib_a_SOURCES=zlib.c + diff --git a/ext/zlib/Makefile.in b/ext/zlib/Makefile.in new file mode 100644 index 0000000000..24bf631fea --- /dev/null +++ b/ext/zlib/Makefile.in @@ -0,0 +1,270 @@ +# Makefile.in generated automatically by automake 1.3 from Makefile.am + +# Copyright (C) 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# $Id$ + + +SHELL = /bin/sh + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DISTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +APACHE_INCLUDE = @APACHE_INCLUDE@ +APACHE_TARGET = @APACHE_TARGET@ +APXS = @APXS@ +APXS_LDFLAGS = @APXS_LDFLAGS@ +BINNAME = @BINNAME@ +CC = @CC@ +CFLAGS = @CFLAGS@ +CFLAGS_SHLIB = @CFLAGS_SHLIB@ +DEBUG_CFLAGS = @DEBUG_CFLAGS@ +EXTINFO_DEPS = @EXTINFO_DEPS@ +EXTRA_LIBS = @EXTRA_LIBS@ +EXT_LIBS = @EXT_LIBS@ +EXT_SUBDIRS = @EXT_SUBDIRS@ +FHTTPD_LIB = @FHTTPD_LIB@ +FHTTPD_TARGET = @FHTTPD_TARGET@ +HSREGEX = @HSREGEX@ +INSTALL_IT = @INSTALL_IT@ +LDFLAGS_SHLIB = @LDFLAGS_SHLIB@ +LDFLAGS_SHLIB_EXPORT = @LDFLAGS_SHLIB_EXPORT@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +PACKAGE = @PACKAGE@ +PERL_PATH = @PERL_PATH@ +PHP_BUILD_DATE = @PHP_BUILD_DATE@ +PHP_DEBUG = @PHP_DEBUG@ +PHP_LIBS = @PHP_LIBS@ +PHP_VERSION = @PHP_VERSION@ +PROG_SENDMAIL = @PROG_SENDMAIL@ +RANLIB = @RANLIB@ +RDYNAMIC_LFLAGS = @RDYNAMIC_LFLAGS@ +REGEX_LIB = @REGEX_LIB@ +STRONGHOLD = @STRONGHOLD@ +VERSION = @VERSION@ +WARNING_LEVEL = @WARNING_LEVEL@ +YACC = @YACC@ + +INCLUDES=@INCLUDES@ -I@top_srcdir@ -I@top_srcdir@/libzend +noinst_LIBRARIES=libphpext_zlib.a +libphpext_zlib_a_SOURCES=zlib.c +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../config.h +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I../.. +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +libphpext_zlib_a_LIBADD = +libphpext_zlib_a_OBJECTS = zlib.o +AR = ar +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) +LINK = $(CC) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = tar +GZIP = --best +SOURCES = $(libphpext_zlib_a_SOURCES) +OBJECTS = $(libphpext_zlib_a_OBJECTS) + +all: Makefile $(LIBRARIES) + +.SUFFIXES: +.SUFFIXES: .S .c .o .s +$(srcdir)/Makefile.in: @MAINT@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu --include-deps ext/zlib/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-noinstLIBRARIES: + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +distclean-noinstLIBRARIES: + +maintainer-clean-noinstLIBRARIES: + +.c.o: + $(COMPILE) -c $< + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +libphpext_zlib.a: $(libphpext_zlib_a_OBJECTS) $(libphpext_zlib_a_DEPENDENCIES) + -rm -f libphpext_zlib.a + $(AR) cru libphpext_zlib.a $(libphpext_zlib_a_OBJECTS) $(libphpext_zlib_a_LIBADD) + $(RANLIB) libphpext_zlib.a + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $(SOURCES) $(HEADERS) $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = ext/zlib + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file; \ + done +info: +dvi: +check: all + $(MAKE) +installcheck: +install-exec: + @$(NORMAL_INSTALL) + +install-data: + @$(NORMAL_INSTALL) + +install: install-exec install-data all + @: + +uninstall: + +install-strip: + $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' INSTALL_SCRIPT='$(INSTALL_PROGRAM)' install +installdirs: + + +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(DISTCLEANFILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) + -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) +mostlyclean: mostlyclean-noinstLIBRARIES mostlyclean-compile \ + mostlyclean-tags mostlyclean-generic + +clean: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \ + mostlyclean + +distclean: distclean-noinstLIBRARIES distclean-compile distclean-tags \ + distclean-generic clean + -rm -f config.status + +maintainer-clean: maintainer-clean-noinstLIBRARIES \ + maintainer-clean-compile maintainer-clean-tags \ + maintainer-clean-generic distclean + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ +clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir info dvi installcheck \ +install-exec install-data install uninstall all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/ext/zlib/config.h.stub b/ext/zlib/config.h.stub new file mode 100644 index 0000000000..5d6dcad205 --- /dev/null +++ b/ext/zlib/config.h.stub @@ -0,0 +1,2 @@ +/* Define if you have the zlib library */ +#define HAVE_ZLIB 0 diff --git a/ext/zlib/config.m4 b/ext/zlib/config.m4 new file mode 100644 index 0000000000..d9d3d75554 --- /dev/null +++ b/ext/zlib/config.m4 @@ -0,0 +1,38 @@ +dnl $Id$ + +AC_MSG_CHECKING(whether to include zlib support) +AC_ARG_WITH(zlib, +[ --with-zlib[=DIR] Include zlib support (requires zlib >= 1.0.9). + DIR is the zlib install directory, + defaults to /usr.], +[ + case "$withval" in + no) + AC_MSG_RESULT(no) ;; + yes) + AC_MSG_RESULT(yes) + PHP_EXTENSION(zlib) + AC_CHECK_LIB(z, gzgets, [AC_DEFINE(HAVE_ZLIB) ZLIB_LIBS="-lz"], + [AC_MSG_ERROR(Zlib module requires zlib >= 1.0.9.)]) + EXTRA_LIBS="$EXTRA_LIBS $ZLIB_LIBS" + ;; + *) + test -f $withval/include/zlib/zlib.h && ZLIB_INCLUDE="-I$withval/include/zlib" + test -f $withval/include/zlib.h && ZLIB_INCLUDE="-I$withval/include" + if test -n "$ZLIB_INCLUDE" ; then + AC_MSG_RESULT(yes) + PHP_EXTENSION(zlib) + old_LIBS=$LIBS + LIBS="$LIBS -L$withval/lib" + AC_CHECK_LIB(z, gzgets, [AC_DEFINE(HAVE_ZLIB) ZLIB_LIBS="-L$withval/lib -lz"], + [AC_MSG_ERROR(Zlib module requires zlib >= 1.0.9.)]) + LIBS=$old_LIBS + EXTRA_LIBS="$EXTRA_LIBS $ZLIB_LIBS" + INCLUDES="$INCLUDES $ZLIB_INCLUDE" + else + AC_MSG_RESULT(no) + fi ;; + esac +],[ + AC_MSG_RESULT(no) +]) diff --git a/ext/zlib/php3_zlib.h b/ext/zlib/php3_zlib.h new file mode 100644 index 0000000000..22052fbab4 --- /dev/null +++ b/ext/zlib/php3_zlib.h @@ -0,0 +1,63 @@ +/* + +----------------------------------------------------------------------+ + | 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. | + +----------------------------------------------------------------------+ + | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | + | Stefan Röhrich <sr@linux.de> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#ifndef _PHP3_ZLIB_H +#define _PHP3_ZLIB_H + +#if COMPILE_DL +#undef HAVE_ZLIB +#define HAVE_ZLIB 1 +#endif + +#if HAVE_ZLIB + +extern php3_module_entry php3_zlib_module_entry; +#define php3_zlib_module_ptr &php3_zlib_module_entry + +extern int php3_minit_zlib(INIT_FUNC_ARGS); +extern int php3_mshutdown_zlib(SHUTDOWN_FUNC_ARGS); +extern void php3_info_zlib(void); +extern void php3_gzopen(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzclose(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzeof(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzread(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzgetc(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzgets(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzgetss(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzwrite(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzrewind(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gztell(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzseek(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzpassthru(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_readgzfile(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_gzfile(INTERNAL_FUNCTION_PARAMETERS); + +#else +#define php3_zlib_module_ptr NULL +#endif /* HAVE_ZLIB */ + +#endif /* _PHP3_ZLIB_H */ diff --git a/ext/zlib/setup.stub b/ext/zlib/setup.stub new file mode 100644 index 0000000000..158978766c --- /dev/null +++ b/ext/zlib/setup.stub @@ -0,0 +1,7 @@ +# $Source$ +# $Id$ + +define_option with-zlib 'zlib (>= 1.0.9) support? ' yesnodir \ + 'no /usr zlib install' \ +' Whether to use the zlib support to read/write .gz-files.\n + Requires zlib version >= 1.0.9!' diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c new file mode 100644 index 0000000000..e8f80c4450 --- /dev/null +++ b/ext/zlib/zlib.c @@ -0,0 +1,926 @@ +/* + +----------------------------------------------------------------------+ + | 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. | + +----------------------------------------------------------------------+ + | Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> | + | Stefan Röhrich <sr@linux.de> | + +----------------------------------------------------------------------+ + */ +/* $Id$ */ +#if !PHP_31 && defined(THREAD_SAFE) +#undef THREAD_SAFE +#endif +#define IS_EXT_MODULE + +#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 (WIN32|WINNT) +#include <windows.h> +#include <winsock.h> +#define O_RDONLY _O_RDONLY +#if PHP_31 +#include "os/nt/param.h" +#else +#include "win32/param.h" +#endif +#else +#include <sys/param.h> +/* #include <sys/uio.h> */ +#endif +#include "ext/standard/head.h" +#include "safe_mode.h" +#include "ext/standard/php3_standard.h" +#include "php3_zlib.h" +#include "fopen-wrappers.h" +#if HAVE_PWD_H +#if WIN32|WINNT +#include "win32/pwd.h" +#else +#include <pwd.h> +#endif +#endif +#include "snprintf.h" +#if HAVE_ZLIB +#if defined(HAVE_UNISTD_H) && (WIN32|WINNT) +#undef HAVE_UNISTD_H +#endif + +#include <zlib.h> + +#if COMPILE_DL +#if PHP_31 +#include "ext/phpdl.h" +#else +#include "dl/phpdl.h" +#endif +#ifndef PUTS +#define PUTS(a) php3_printf("%s",a) +#endif +#ifndef PUTC +#define PUTC(a) PUTS(a) +#endif +#ifndef PHPWRITE +#define PHPWRITE(a,n) php3_write((a),(n)) +#endif +#endif + + + +#if defined(THREAD_SAFE) +typedef struct zlib_global_struct{ +#endif + int gzgetss_state; + int le_zp; +#if PHP_31 + int magic_quotes_runtime; + int safe_mode; + char *include_path; + char *doc_root; +#endif +#if defined(THREAD_SAFE) +}zlib_global_struct; +#endif + +#if defined(THREAD_SAFE) +DWORD ZLIBtls; +static int numthreads=0; +void *zlib_mutex; + +#define ZLIB_GLOBAL(a) zlib_globals->a + +#define ZLIB_TLS_VARS zlib_global_struct *PHP3_TLS_GET(ZLIBtls,zlib_globals); + +#else +#define ZLIB_GLOBAL(a) a +#define ZLIB_TLS_VARS +#endif + +#if PHP_31 +# define ZLIB_INI(a) ZLIB_GLOBAL(a) +#else +# define ZLIB_INI(a) php3_ini.a +#endif + +function_entry php3_zlib_functions[] = { + {"readgzfile", php3_readgzfile, NULL}, + {"gzrewind", php3_gzrewind, NULL}, + {"gzclose", php3_gzclose, NULL}, + {"gzeof", php3_gzeof, NULL}, + {"gzgetc", php3_gzgetc, NULL}, + {"gzgets", php3_gzgets, NULL}, + {"gzgetss", php3_gzgetss, NULL}, + {"gzread", php3_gzread, NULL}, + {"gzopen", php3_gzopen, NULL}, + {"gzpassthru", php3_gzpassthru, NULL}, + {"gzseek", php3_gzseek, NULL}, + {"gztell", php3_gztell, NULL}, + {"gzwrite", php3_gzwrite, NULL}, + {"gzputs", php3_gzwrite, NULL}, + {"gzfile", php3_gzfile, NULL}, + {NULL, NULL, NULL} +}; + +php3_module_entry php3_zlib_module_entry = { + "zlib", php3_zlib_functions, php3_minit_zlib, php3_mshutdown_zlib, NULL, NULL, php3_info_zlib, STANDARD_MODULE_PROPERTIES +}; + +#if defined(COMPILE_DL) +DLEXPORT php3_module_entry *get_module(void) { return &php3_zlib_module_entry; } +#endif + +int php3_minit_zlib(INIT_FUNC_ARGS) +{ +#ifdef THREAD_SAFE + zlib_global_struct *zlib_globals; + PHP3_MUTEX_ALLOC(zlib_mutex); + PHP3_MUTEX_LOCK(zlib_mutex); + numthreads++; + if (numthreads==1){ + if (!PHP3_TLS_PROC_STARTUP(ZLIBtls)){ + PHP3_MUTEX_UNLOCK(zlib_mutex); + PHP3_MUTEX_FREE(zlib_mutex); + return FAILURE; + } + } + PHP3_MUTEX_UNLOCK(zlib_mutex); + if(!PHP3_TLS_THREAD_INIT(ZLIBtls,zlib_globals,zlib_global_struct)){ + PHP3_MUTEX_FREE(zlib_mutex); + return FAILURE; + } +#endif + /* get our ini variables here */ + cfg_get_long("safe_mode",&ZLIB_INI(safe_mode)); + cfg_get_long("magic_quotes_runtime",&ZLIB_INI(magic_quotes_runtime)); + cfg_get_string("doc_root",&ZLIB_INI(doc_root)); + cfg_get_string("include_path",&ZLIB_INI(include_path)); + + ZLIB_GLOBAL(le_zp) = register_list_destructors(gzclose,NULL); + return SUCCESS; +} + +int php3_mshutdown_zlib(SHUTDOWN_FUNC_ARGS){ +#if defined(THREAD_SAFE) + ZLIB_TLS_VARS; + PHP3_TLS_THREAD_FREE(zlib_globals); + PHP3_MUTEX_LOCK(zlib_mutex); + numthreads--; + if (numthreads<1){ + PHP3_TLS_PROC_SHUTDOWN(ZLIBtls); + PHP3_MUTEX_UNLOCK(zlib_mutex); + PHP3_MUTEX_FREE(zlib_mutex); + return SUCCESS; + } + PHP3_MUTEX_UNLOCK(zlib_mutex); +#endif + return SUCCESS; +} + +void php3_info_zlib(void) +{ + PUTS("Zlib support active (compiled with "); + PUTS(ZLIB_VERSION); + PUTS(", linked with "); + PUTS((char *)zlibVersion()); + PUTS(")."); +} + +static gzFile *php3_gzopen_with_path(char *filename, char *mode, char *path, char **opened_path); + +static gzFile php3_gzopen_wrapper(char *path, char *mode, int options) +{ + ZLIB_TLS_VARS; + if (options & USE_PATH && ZLIB_INI(include_path) != NULL) { + return php3_gzopen_with_path(path, mode, ZLIB_INI(include_path), NULL); + } + else { + if (options & ENFORCE_SAFE_MODE && ZLIB_INI(safe_mode) && (!_php3_checkuid(path,1))) { + return NULL; + } + if (_php3_check_open_basedir(path)) return NULL; + return gzopen(path, mode); + } +} + +/* + * Tries to open a .gz-file with a PATH-style list of directories. + * If the filename starts with "." or "/", the path is ignored. + */ +static gzFile *php3_gzopen_with_path(char *filename, char *mode, char *path, char **opened_path) +{ + char *pathbuf, *ptr, *end; + char trypath[MAXPATHLEN + 1]; + struct stat sb; + gzFile *zp; + ZLIB_TLS_VARS; + + if (opened_path) { + *opened_path = NULL; + } + + /* Relative path open */ + if (*filename == '.') { + if (ZLIB_INI(safe_mode) &&(!_php3_checkuid(filename,2))) { + return(NULL); + } + if (_php3_check_open_basedir(filename)) return NULL; + zp = gzopen(filename, mode); + if (zp && opened_path) { + *opened_path = expand_filepath(filename); + } + return zp; + } + + /* Absolute path open - prepend document_root in safe mode */ +#if WIN32|WINNT + if ((*filename == '\\')||(*filename == '/')||(filename[1] == ':')) { +#else + if (*filename == '/') { +#endif + if (ZLIB_INI(safe_mode)) { + snprintf(trypath,MAXPATHLEN,"%s%s",ZLIB_INI(doc_root),filename); + if (!_php3_checkuid(trypath,2)) { + return(NULL); + } + if (_php3_check_open_basedir(trypath)) return NULL; + zp = gzopen(trypath, mode); + if (zp && opened_path) { + *opened_path = expand_filepath(trypath); + } + return zp; + } else { + if (_php3_check_open_basedir(filename)) return NULL; + return gzopen(filename, mode); + } + } + + if (!path || (path && !*path)) { + if (ZLIB_INI(safe_mode) &&(!_php3_checkuid(filename,2))) { + return(NULL); + } + if (_php3_check_open_basedir(filename)) return NULL; + zp = gzopen(filename, mode); + if (zp && opened_path) { + *opened_path = strdup(filename); + } + return zp; + } + + pathbuf = estrdup(path); + + ptr = pathbuf; + + while (ptr && *ptr) { +#if WIN32|WINNT + end = strchr(ptr, ';'); +#else + end = strchr(ptr, ':'); +#endif + if (end != NULL) { + *end = '\0'; + end++; + } + snprintf(trypath, MAXPATHLEN, "%s/%s", ptr, filename); + if (ZLIB_INI(safe_mode)) { + if (stat(trypath,&sb) == 0 &&(!_php3_checkuid(trypath,2))) { + efree(pathbuf); + return(NULL); + } + } + if ((zp = gzopen(trypath, mode)) != NULL) { + if (_php3_check_open_basedir(trypath)) { + gzclose(zp); + efree(pathbuf); + return NULL; + } + if (opened_path) { + *opened_path = expand_filepath(trypath); + } + efree(pathbuf); + return zp; + } + ptr = end; + } + efree(pathbuf); + return NULL; +} + +/* {{{ proto array gzfile(string filename) +Read und uncompress entire .gz-file into an array */ +void php3_gzfile(INTERNAL_FUNCTION_PARAMETERS) { + pval *filename, *arg2; + gzFile zp; + char *slashed, buf[8192]; + register int i=0; + int use_include_path = 0; + ZLIB_TLS_VARS; + + /* check args */ + switch (ARG_COUNT(ht)) { + case 1: + if (getParameters(ht,1,&filename) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 2: + if (getParameters(ht,2,&filename,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg2); + use_include_path = arg2->value.lval; + break; + default: + WRONG_PARAM_COUNT; + } + convert_to_string(filename); + + zp = php3_gzopen_wrapper(filename->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE); + if (!zp) { + php3_error(E_WARNING,"gzFile(\"%s\") - %s",filename->value.str.val,strerror(errno)); + RETURN_FALSE; + } + + /* Initialize return array */ + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + /* Now loop through the file and do the magic quotes thing if needed */ + memset(buf,0,8191); + while((int)gzgets(zp, buf, 8191)) { + if (ZLIB_INI(magic_quotes_runtime)) { + int len; + + slashed = _php3_addslashes(buf,0,&len,0); /* 0 = don't free source string */ + add_index_stringl(return_value, i++, slashed, len, 0); + } else { + add_index_string(return_value, i++, buf, 1); + } + } + gzclose(zp); +} +/* }}} */ + +/* {{{ proto int gzopen(string filename, string mode [, int use_include_path]) +Open a .gz-file and return a .gz-file pointer */ +void php3_gzopen(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1, *arg2, *arg3; + gzFile *zp; + char *p; + int id; + int use_include_path = 0; + ZLIB_TLS_VARS; + + switch(ARG_COUNT(ht)) { + case 2: + if (getParameters(ht,2,&arg1,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 3: + if (getParameters(ht,3,&arg1,&arg2,&arg3) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg3); + use_include_path = arg3->value.lval; + break; + default: + WRONG_PARAM_COUNT; + } + convert_to_string(arg1); + convert_to_string(arg2); + p = estrndup(arg2->value.str.val,arg2->value.str.len); + + /* + * We need a better way of returning error messages from + * php3_gzopen_wrapper(). + */ + zp = php3_gzopen_wrapper(arg1->value.str.val, p, use_include_path|ENFORCE_SAFE_MODE); + if (!zp) { + php3_error(E_WARNING,"gzopen(\"%s\",\"%s\") - %s", + arg1->value.str.val, p, strerror(errno)); + efree(p); + RETURN_FALSE; + } + ZLIB_GLOBAL(gzgetss_state)=0; + id = php3_list_insert(zp,ZLIB_GLOBAL(le_zp)); + efree(p); + RETURN_LONG(id); +} +/* }}} */ + +/* {{{ proto int gzclose(int zp) +Close an open .gz-file pointer */ +void php3_gzclose(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + int id, type; + gzFile *zp; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id=arg1->value.lval; + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + php3_list_delete(id); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int gzeof(int zp) +Test for end-of-file on a .gz-file pointer */ +void php3_gzeof(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + gzFile *zp; + int id, type; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id = arg1->value.lval; + zp = php3_list_find(id,&type); + if ((!zp || (type!=ZLIB_GLOBAL(le_zp)))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + /* we're at the eof if the file doesn't exist */ + RETURN_TRUE; + } + if ((gzeof(zp))) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto string gzgets(int zp, int length) +Get a line from .gz-file pointer */ +void php3_gzgets(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1, *arg2; + gzFile *zp; + int id, len, type; + char *buf; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + convert_to_long(arg2); + id = arg1->value.lval; + len = arg2->value.lval; + + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + buf = emalloc(sizeof(char) * (len + 1)); + /* needed because recv doesnt put a null at the end*/ + memset(buf,0,len+1); + if (!((int)gzgets(zp, buf, len))) { + efree(buf); + RETVAL_FALSE; + } else { + if (ZLIB_INI(magic_quotes_runtime)) { + return_value->value.str.val = _php3_addslashes(buf,0,&return_value->value.str.len,1); + } else { + return_value->value.str.val = buf; + return_value->value.str.len = strlen(return_value->value.str.val); + } + return_value->type = IS_STRING; + } + return; +} +/* }}} */ + +/* {{{ proto string gzgetc(int zp) +Get a character from .gz-file pointer */ +void php3_gzgetc(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + gzFile *zp; + int id, type, c; + char *buf; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id = arg1->value.lval; + + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + buf = emalloc(sizeof(char) * 2); + if ((c=gzgetc(zp)) == (-1)) { + efree(buf); + RETVAL_FALSE; + } else { + buf[0]=(char)c; + buf[1]='\0'; + return_value->value.str.val = buf; + return_value->value.str.len = 1; + return_value->type = IS_STRING; + } + return; +} +/* }}} */ + +/* Strip any HTML tags while reading */ +/* {{{ proto string gzgetss(int zp, int length) +Get a line from file pointer and strip HTML tags */ +void php3_gzgetss(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *fd, *bytes; + gzFile *zp; + int id, len, br, type; + char *buf, *p, *rbuf, *rp, c, lc; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &fd, &bytes) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(fd); + convert_to_long(bytes); + + id = fd->value.lval; + len = bytes->value.lval; + + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING, "Unable to find gz-file identifier %d", id); + RETURN_FALSE; + } + + buf = emalloc(sizeof(char) * (len + 1)); + /*needed because recv doesnt set null char at end*/ + memset(buf,0,len+1); + if (!((int)gzgets(zp, buf, len))) { + efree(buf); + RETURN_FALSE; + } + + rbuf = estrdup(buf); + c = *buf; + lc = '\0'; + p = buf; + rp = rbuf; + br = 0; + + while (c) { + switch (c) { + case '<': + if (ZLIB_GLOBAL(gzgetss_state) == 0) { + lc = '<'; + ZLIB_GLOBAL(gzgetss_state) = 1; + } + break; + + case '(': + if (ZLIB_GLOBAL(gzgetss_state) == 2) { + if (lc != '\"') { + lc = '('; + br++; + } + } else if (ZLIB_GLOBAL(gzgetss_state) == 0) { + *(rp++) = c; + } + break; + + case ')': + if (ZLIB_GLOBAL(gzgetss_state) == 2) { + if (lc != '\"') { + lc = ')'; + br--; + } + } else if (ZLIB_GLOBAL(gzgetss_state) == 0) { + *(rp++) = c; + } + break; + + case '>': + if (ZLIB_GLOBAL(gzgetss_state) == 1) { + lc = '>'; + ZLIB_GLOBAL(gzgetss_state) = 0; + } else if (ZLIB_GLOBAL(gzgetss_state) == 2) { + if (!br && lc != '\"') { + ZLIB_GLOBAL(gzgetss_state) = 0; + } + } + break; + + case '\"': + if (ZLIB_GLOBAL(gzgetss_state) == 2) { + if (lc == '\"') { + lc = '\0'; + } else if (lc != '\\') { + lc = '\"'; + } + } else if (ZLIB_GLOBAL(gzgetss_state) == 0) { + *(rp++) = c; + } + break; + + case '?': + if (ZLIB_GLOBAL(gzgetss_state)==1) { + br=0; + ZLIB_GLOBAL(gzgetss_state)=2; + break; + } + /* fall-through */ + + default: + if (ZLIB_GLOBAL(gzgetss_state) == 0) { + *(rp++) = c; + } + } + c = *(++p); + } + *rp = '\0'; + efree(buf); + RETVAL_STRING(rbuf,1); + efree(rbuf); +} +/* }}} */ + +/* {{{ proto int gzwrite(int zp, string str [, int length]) +Binary-safe .gz-file write */ +void php3_gzwrite(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1, *arg2, *arg3=NULL; + gzFile *zp; + int ret,id,type; + int num_bytes; + ZLIB_TLS_VARS; + + switch (ARG_COUNT(ht)) { + case 2: + if (getParameters(ht, 2, &arg1, &arg2)==FAILURE) { + RETURN_FALSE; + } + convert_to_string(arg2); + num_bytes = arg2->value.str.len; + break; + case 3: + if (getParameters(ht, 3, &arg1, &arg2, &arg3)==FAILURE) { + RETURN_FALSE; + } + convert_to_string(arg2); + convert_to_long(arg3); + num_bytes = MIN(arg3->value.lval, arg2->value.str.len); + break; + default: + WRONG_PARAM_COUNT; + /* NOTREACHED */ + break; + } + convert_to_long(arg1); + id = arg1->value.lval; + + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + + /* strip slashes only if the length wasn't specified explicitly */ + if (!arg3 && ZLIB_INI(magic_quotes_runtime)) { + _php3_stripslashes(arg2->value.str.val,&num_bytes); + } + + ret = gzwrite(zp, arg2->value.str.val,num_bytes); + RETURN_LONG(ret); +} +/* }}} */ + +/* {{{ proto int gzrewind(int zp) +Rewind the position of a .gz-file pointer */ +void php3_gzrewind(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + int id,type; + gzFile *zp; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id = arg1->value.lval; + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + gzrewind(zp); + RETURN_TRUE; +} +/* }}} */ + +/* {{{ proto int gztell(int zp) +Get .gz-file pointer's read/write position */ +void php3_gztell(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + int id, type; + long pos; + gzFile *zp; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id = arg1->value.lval; + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + pos = gztell(zp); + RETURN_LONG(pos); +} +/* }}} */ + +/* {{{ proto int gzseek(int zp, int offset) +Seek on a file pointer */ +void php3_gzseek(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1, *arg2; + int ret,id,type; + long pos; + gzFile *zp; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + convert_to_long(arg2); + pos = arg2->value.lval; + id = arg1->value.lval; + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + ret = gzseek(zp,pos,SEEK_SET); + RETURN_LONG(ret); +} +/* }}} */ + +/* + * Read a file and write the ouput to stdout + */ +/* {{{ proto int readgzfile(string filename [, int use_include_path]) +Output a .gz-file */ +void php3_readgzfile(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1, *arg2; + char buf[8192]; + gzFile *zp; + int b, size; + int use_include_path = 0; + + + /* check args */ + switch (ARG_COUNT(ht)) { + case 1: + if (getParameters(ht,1,&arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + break; + case 2: + if (getParameters(ht,2,&arg1,&arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg2); + use_include_path = arg2->value.lval; + break; + default: + WRONG_PARAM_COUNT; + } + convert_to_string(arg1); + + /* + * We need a better way of returning error messages from + * php3_gzopen_wrapper(). + */ + zp = php3_gzopen_wrapper(arg1->value.str.val,"r", use_include_path|ENFORCE_SAFE_MODE); + if (!zp){ + php3_error(E_WARNING,"ReadGzFile(\"%s\") - %s",arg1->value.str.val,strerror(errno)); + RETURN_FALSE; + } + size= 0; + while((b = gzread(zp, buf, sizeof(buf))) > 0) { + PHPWRITE(buf,b); + size += b ; + } + gzclose(zp); + RETURN_LONG(size); +} +/* }}} */ + +/* + * Read to EOF on a file descriptor and write the output to stdout. + */ +/* {{{ proto int gzpassthru(int zp) +Output all remaining data from a .gz-file pointer */ +void php3_gzpassthru(INTERNAL_FUNCTION_PARAMETERS) { + pval *arg1; + gzFile *zp; + char buf[8192]; + int id, size, b, type; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg1) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + id = arg1->value.lval; + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + size = 0; + while((b = gzread(zp, buf, sizeof(buf))) > 0) { + PHPWRITE(buf,b); + size += b ; + } +/* gzclose(zp); */ + php3_list_delete(id); + RETURN_LONG(size); +} +/* }}} */ + +/* {{{ proto int gzread(int zp, int length) +Binary-safe file read */ +void php3_gzread(INTERNAL_FUNCTION_PARAMETERS) +{ + pval *arg1, *arg2; + gzFile *zp; + int id, len, type; + ZLIB_TLS_VARS; + + if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &arg1, &arg2) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_long(arg1); + convert_to_long(arg2); + id = arg1->value.lval; + len = arg2->value.lval; + + zp = php3_list_find(id,&type); + if (!zp || (type!=ZLIB_GLOBAL(le_zp))) { + php3_error(E_WARNING,"Unable to find gz-file identifier %d",id); + RETURN_FALSE; + } + return_value->value.str.val = emalloc(sizeof(char) * (len + 1)); + /* needed because recv doesnt put a null at the end*/ + + return_value->value.str.len = gzread(zp, return_value->value.str.val, len); + return_value->value.str.val[return_value->value.str.len] = 0; + + if (ZLIB_INI(magic_quotes_runtime)) { + return_value->value.str.val = _php3_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1); + } + return_value->type = IS_STRING; +} +/* }}} */ + +#endif /* HAVE_ZLIB */ +/* + * Local variables: + * tab-width: 4 + * End: + */ |