cvs: php4 /ext/standard file.c /ext/zlib php_zlib.h zlib.c zlib_fopen_wrapper.c /main php_streams.h streams.c
| From: | Wez Furlong | Date: | Thu, 21 Mar 2002 01:11:52 +0000 |
| Subject: | cvs: php4 /ext/standard file.c /ext/zlib php_zlib.h zlib.c zlib_fopen_wrapper.c /main php_streams.h streams.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-10505@lists.php.net to get a copy of this message | ||
wez Wed Mar 20 20:11:52 2002 EDT
Modified files:
/php4/ext/standard file.c
/php4/ext/zlib php_zlib.h zlib.c zlib_fopen_wrapper.c
/php4/main php_streams.h streams.c
Log:
Convert the gzfile related functions into aliases for their equivalents
in ext/standard/file.c, so a gzopen()ed file pointer can be used in
fread, fseek etc.
Improved behaviour of zlib stream.
Moved passthru code into streams.c
# I'm not happy about BG(mmap_file)
Nuked gzgetss_state as no longer needed.
Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.218 php4/ext/standard/file.c:1.219 --- php4/ext/standard/file.c:1.218 Wed Mar 20 09:38:10 2002 +++ php4/ext/standard/file.c Wed Mar 20 20:11:52 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.218 2002/03/20 14:38:10 wez Exp $ */ +/* $Id: file.c,v 1.219 2002/03/21 01:11:52 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1326,55 +1326,6 @@ } /* }}} */ -/* {{{ php_passthru_stream */ -static size_t php_passthru_stream(php_stream *stream TSRMLS_DC) -{ - size_t bcount = 0; - int ready = 0; - char buf[8192]; -#ifdef HAVE_MMAP - int fd; -#endif - -#ifdef HAVE_MMAP - if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET) - && php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 0)) - { - struct stat sbuf; - off_t off; - void *p; - size_t len; - - fstat(fd, &sbuf); - - if (sbuf.st_size > sizeof(buf)) { - off = php_stream_tell(stream); - len = sbuf.st_size - off; - p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off); - if (p != (void *) MAP_FAILED) { - BG(mmap_file) = p; - BG(mmap_len) = len; - PHPWRITE(p, len); - BG(mmap_file) = NULL; - munmap(p, len); - bcount += len; - ready = 1; - } - } - } -#endif - if(!ready) { - int b; - - while ((b = php_stream_read(stream, buf, sizeof(buf))) > 0) { - PHPWRITE(buf, b); - bcount += b; - } - } - return bcount; -} -/* }}} */ - /* {{{ proto int readfile(string filename [, int use_include_path]) Output a file or a URL */ PHP_FUNCTION(readfile) @@ -1407,7 +1358,7 @@ use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (stream) { - size = php_passthru_stream(stream TSRMLS_CC); + size = php_stream_passthru(stream); php_stream_close(stream); RETURN_LONG(size); } @@ -1460,7 +1411,7 @@ what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", &type, 1, le_stream); ZEND_VERIFY_RESOURCE(what); - size = php_passthru_stream((php_stream*)what TSRMLS_CC); + size = php_stream_passthru((php_stream*)what); RETURN_LONG(size); } /* }}} */ Index: php4/ext/zlib/php_zlib.h diff -u php4/ext/zlib/php_zlib.h:1.26 php4/ext/zlib/php_zlib.h:1.27 --- php4/ext/zlib/php_zlib.h:1.26 Wed Mar 20 08:21:55 2002 +++ php4/ext/zlib/php_zlib.h Wed Mar 20 20:11:52 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zlib.h,v 1.26 2002/03/20 13:21:55 wez Exp $ */ +/* $Id: php_zlib.h,v 1.27 2002/03/21 01:11:52 wez Exp $ */ #ifndef PHP_ZLIB_H #define PHP_ZLIB_H @@ -25,8 +25,6 @@ #include <zlib.h> ZEND_BEGIN_MODULE_GLOBALS(zlib) - int gzgetss_state; - /* variables for transparent gzip encoding */ int compression_coding; z_stream stream; @@ -44,17 +42,6 @@ PHP_RINIT_FUNCTION(zlib); PHP_MINFO_FUNCTION(zlib); PHP_FUNCTION(gzopen); -PHP_FUNCTION(gzclose); -PHP_FUNCTION(gzeof); -PHP_FUNCTION(gzread); -PHP_FUNCTION(gzgetc); -PHP_FUNCTION(gzgets); -PHP_FUNCTION(gzgetss); -PHP_FUNCTION(gzwrite); -PHP_FUNCTION(gzrewind); -PHP_FUNCTION(gztell); -PHP_FUNCTION(gzseek); -PHP_FUNCTION(gzpassthru); PHP_FUNCTION(readgzfile); PHP_FUNCTION(gzfile); PHP_FUNCTION(gzcompress); Index: php4/ext/zlib/zlib.c diff -u php4/ext/zlib/zlib.c:1.118 php4/ext/zlib/zlib.c:1.119 --- php4/ext/zlib/zlib.c:1.118 Wed Mar 20 09:38:13 2002 +++ php4/ext/zlib/zlib.c Wed Mar 20 20:11:52 2002 @@ -18,7 +18,7 @@ | Jade Nicoletti <nicoletti@nns.ch> | +----------------------------------------------------------------------+ */ -/* $Id: zlib.c,v 1.118 2002/03/20 14:38:13 wez Exp $ */ +/* $Id: zlib.c,v 1.119 2002/03/21 01:11:52 wez Exp $ */ #define IS_EXT_MODULE #ifdef HAVE_CONFIG_H @@ -86,27 +86,27 @@ /* {{{ php_zlib_functions[] */ function_entry php_zlib_functions[] = { - PHP_FE(readgzfile, NULL) - PHP_FE(gzrewind, NULL) - PHP_FE(gzclose, NULL) - PHP_FE(gzeof, NULL) - PHP_FE(gzgetc, NULL) - PHP_FE(gzgets, NULL) - PHP_FE(gzgetss, NULL) - PHP_FE(gzread, NULL) - PHP_FE(gzopen, NULL) - PHP_FE(gzpassthru, NULL) - PHP_FE(gzseek, NULL) - PHP_FE(gztell, NULL) - PHP_FE(gzwrite, NULL) - PHP_FALIAS(gzputs, gzwrite, NULL) - PHP_FE(gzfile, NULL) - PHP_FE(gzcompress, NULL) - PHP_FE(gzuncompress, NULL) - PHP_FE(gzdeflate, NULL) - PHP_FE(gzinflate, NULL) - PHP_FE(gzencode, NULL) - PHP_FE(ob_gzhandler, NULL) + PHP_FE(readgzfile, NULL) + PHP_NAMED_FE(gzrewind, PHP_FN(rewind), NULL) + PHP_NAMED_FE(gzclose, PHP_FN(fclose), NULL) + PHP_NAMED_FE(gzeof, PHP_FN(feof), NULL) + PHP_NAMED_FE(gzgetc, PHP_FN(fgetc), NULL) + PHP_NAMED_FE(gzgets, PHP_FN(fgets), NULL) + PHP_NAMED_FE(gzgetss, PHP_FN(fgetss), NULL) + PHP_NAMED_FE(gzread, PHP_FN(fread), NULL) + PHP_FE(gzopen, NULL) + PHP_NAMED_FE(gzpassthru, PHP_FN(fpassthru), NULL) + PHP_NAMED_FE(gzseek, PHP_FN(fseek), NULL) + PHP_NAMED_FE(gztell, PHP_FN(ftell), NULL) + PHP_NAMED_FE(gzwrite, PHP_FN(fwrite), NULL) + PHP_NAMED_FE(gzputs, PHP_FN(fwrite), NULL) + PHP_FE(gzfile, NULL) + PHP_FE(gzcompress, NULL) + PHP_FE(gzuncompress, NULL) + PHP_FE(gzdeflate, NULL) + PHP_FE(gzinflate, NULL) + PHP_FE(gzencode, NULL) + PHP_FE(ob_gzhandler, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -246,25 +246,6 @@ } /* }}} */ -/* {{{ php_gzopen_wrapper - */ -static gzFile php_gzopen_wrapper(char *path, char *mode, int options TSRMLS_DC) -{ - php_stream *stream = NULL; - int fd; - - stream = php_stream_open_wrapper(path, mode, options | REPORT_ERRORS, NULL); - if (stream) { - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_CAST_RELEASE|PHP_STREAM_AS_FD|PHP_STREAM_CAST_TRY_HARD, (void**)&fd, 1)) - { - return gzdopen(fd, mode); - } - php_stream_close(stream); - } - return NULL; -} -/* }}} */ - /* {{{ proto array gzfile(string filename [, int use_include_path]) Read und uncompress entire .gz-file into an array */ PHP_FUNCTION(gzfile) @@ -327,7 +308,7 @@ PHP_FUNCTION(gzopen) { pval **arg1, **arg2, **arg3; - gzFile *zp; + php_stream *stream; char *p; int use_include_path = 0; @@ -350,282 +331,16 @@ convert_to_string_ex(arg1); convert_to_string_ex(arg2); p = estrndup(Z_STRVAL_PP(arg2),Z_STRLEN_PP(arg2)); - - /* - * We need a better way of returning error messages from - * php_gzopen_wrapper(). - */ - zp = php_gzopen_wrapper(Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE TSRMLS_CC); - if (!zp) { - php_error(E_WARNING,"gzopen(\"%s\",\"%s\") - %s", - Z_STRVAL_PP(arg1), p, strerror(errno)); - efree(p); - RETURN_FALSE; - } - ZLIBG(gzgetss_state)=0; - efree(p); - ZEND_REGISTER_RESOURCE(return_value, zp, le_zp); -} -/* }}} */ - -/* {{{ proto int gzclose(int zp) - Close an open .gz-file pointer */ -PHP_FUNCTION(gzclose) -{ - pval **arg1; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - zend_list_delete(Z_LVAL_PP(arg1)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int gzeof(int zp) - Test for end-of-file on a .gz-file pointer */ -PHP_FUNCTION(gzeof) -{ - pval **arg1; - gzFile *zp; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - if ((gzeof(zp))) { - RETURN_TRUE; - } else { + stream = php_stream_gzopen(Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + if (!stream) { RETURN_FALSE; } -} -/* }}} */ - -/* {{{ proto string gzgets(int zp, int length) - Get a line from .gz-file pointer */ -PHP_FUNCTION(gzgets) -{ - pval **arg1, **arg2; - gzFile *zp; - int len; - char *buf; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - memset(buf,0,len+1); - if (!(gzgets(zp, buf, len) != NULL)) { - efree(buf); - RETVAL_FALSE; - } else { - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(buf,0,&Z_STRLEN_P(return_value),1 TSRMLS_CC); - } else { - Z_STRVAL_P(return_value) = buf; - Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); - } - Z_TYPE_P(return_value) = IS_STRING; - } - return; -} -/* }}} */ - -/* {{{ proto string gzgetc(int zp) - Get a character from .gz-file pointer */ -PHP_FUNCTION(gzgetc) -{ - pval **arg1; - gzFile *zp; - int c; - char *buf; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * 2); - if ((c=gzgetc(zp)) == (-1)) { - efree(buf); - RETVAL_FALSE; - } else { - buf[0]=(char)c; - buf[1]='\0'; - Z_STRVAL_P(return_value) = buf; - Z_STRLEN_P(return_value) = 1; - Z_TYPE_P(return_value) = IS_STRING; - } - return; -} -/* }}} */ - -/* Strip any HTML tags while reading */ -/* {{{ proto string gzgetss(int zp, int length [, string allowable_tags]) - Get a line from file pointer and strip HTML tags */ -PHP_FUNCTION(gzgetss) -{ - pval **fd, **bytes, **allow=NULL; - gzFile *zp; - int len; - char *buf; - char *allowed_tags=NULL; - int allowed_tags_len=0; - - switch(ZEND_NUM_ARGS()) { - case 2: - if(zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) { - RETURN_FALSE; - } - break; - case 3: - if(zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - allowed_tags = Z_STRVAL_PP(allow); - allowed_tags_len = Z_STRLEN_PP(allow); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - convert_to_long_ex(bytes); - - len = Z_LVAL_PP(bytes); - - ZEND_FETCH_RESOURCE(zp, gzFile *, fd, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * (len + 1)); - /*needed because recv doesnt set null char at end*/ - memset(buf,0,len+1); - if (!(gzgets(zp, buf, len) != NULL)) { - efree(buf); - RETURN_FALSE; - } - - /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), &ZLIBG(gzgetss_state), allowed_tags, allowed_tags_len); - RETURN_STRING(buf, 0); - -} -/* }}} */ - -/* {{{ proto int gzwrite(int zp, string str [, int length]) - Binary-safe .gz-file write */ -PHP_FUNCTION(gzwrite) -{ - pval **arg1, **arg2, **arg3=NULL; - gzFile *zp; - int ret; - int num_bytes; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - num_bytes = Z_STRLEN_PP(arg2); - break; - case 3: - if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - convert_to_long_ex(arg3); - num_bytes = MIN(Z_LVAL_PP(arg3), Z_STRLEN_PP(arg2)); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - /* strip slashes only if the length wasn't specified explicitly */ - if (!arg3 && PG(magic_quotes_runtime)) { - php_stripslashes(Z_STRVAL_PP(arg2), &num_bytes TSRMLS_CC); - } - - ret = gzwrite(zp, Z_STRVAL_PP(arg2),num_bytes); - RETURN_LONG(ret); + efree(p); + php_stream_to_zval(stream, return_value); } /* }}} */ -/* {{{ proto int gzputs(int zp, string str [, int length]) - An alias for gzwrite */ -/* }}} */ - -/* {{{ proto int gzrewind(int zp) - Rewind the position of a .gz-file pointer */ -PHP_FUNCTION(gzrewind) -{ - pval **arg1; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - gzrewind(zp); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int gztell(int zp) - Get .gz-file pointer's read/write position */ -PHP_FUNCTION(gztell) -{ - pval **arg1; - long pos; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - pos = gztell(zp); - RETURN_LONG(pos); -} -/* }}} */ - -/* {{{ proto int gzseek(int zp, int offset) - Seek on a file pointer */ -PHP_FUNCTION(gzseek) -{ - pval **arg1, **arg2; - int ret; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - ret = gzseek(zp, Z_LVAL_PP(arg2), SEEK_SET); - RETURN_LONG(ret); -} -/* }}} */ - /* * Read a file and write the ouput to stdout */ @@ -634,9 +349,8 @@ PHP_FUNCTION(readgzfile) { pval **arg1, **arg2; - char buf[8192]; - gzFile *zp; - int b, size; + php_stream * stream; + int size; int use_include_path = 0; @@ -659,84 +373,15 @@ } convert_to_string_ex(arg1); - /* - * We need a better way of returning error messages from - * php_gzopen_wrapper(). - */ - zp = php_gzopen_wrapper(Z_STRVAL_PP(arg1),"r", use_include_path|ENFORCE_SAFE_MODE TSRMLS_CC); - if (!zp){ - php_error(E_WARNING,"ReadGzFile(\"%s\") - %s",Z_STRVAL_PP(arg1),strerror(errno)); + stream = php_stream_gzopen(Z_STRVAL_PP(arg1), "rb", use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + if (!stream) { 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 */ -PHP_FUNCTION(gzpassthru) -{ - pval **arg1; - gzFile *zp; - char buf[8192]; - int size, b; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - size = 0; - while((b = gzread(zp, buf, sizeof(buf))) > 0) { - PHPWRITE(buf,b); - size += b ; - } -/* gzclose(zp); */ - zend_list_delete(Z_LVAL_PP(arg1)); + php_stream_passthru(stream); + php_stream_close(stream); RETURN_LONG(size); } /* }}} */ - -/* {{{ proto string gzread(int zp, int length) - Binary-safe file read */ -PHP_FUNCTION(gzread) -{ - pval **arg1, **arg2; - gzFile *zp; - int len; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - Z_STRVAL_P(return_value) = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - - Z_STRLEN_P(return_value) = gzread(zp, Z_STRVAL_P(return_value), len); - Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; - - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value),&Z_STRLEN_P(return_value),1 TSRMLS_CC); - } - Z_TYPE_P(return_value) = IS_STRING; -} - -/* }}} */ - /* {{{ proto string gzcompress(string data [, int level]) Gzip-compress a string */ Index: php4/ext/zlib/zlib_fopen_wrapper.c diff -u php4/ext/zlib/zlib_fopen_wrapper.c:1.17 php4/ext/zlib/zlib_fopen_wrapper.c:1.18 --- php4/ext/zlib/zlib_fopen_wrapper.c:1.17 Wed Mar 20 08:21:55 2002 +++ php4/ext/zlib/zlib_fopen_wrapper.c Wed Mar 20 20:11:52 2002 @@ -12,10 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Hartmut Holzgraefe <hartmut@six.de> | + | Author: Wez Furlong <wez@thebrainroom.com>, based on work by: | + | Hartmut Holzgraefe <hartmut@six.de> | +----------------------------------------------------------------------+ */ -/* $Id: zlib_fopen_wrapper.c,v 1.17 2002/03/20 13:21:55 wez Exp $ */ +/* $Id: zlib_fopen_wrapper.c,v 1.18 2002/03/21 01:11:52 wez Exp $ */ #define IS_EXT_MODULE #define _GNU_SOURCE @@ -57,6 +58,11 @@ static int php_gziop_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *)stream->abstract; + + assert(self != NULL); + if (offset == 0 && whence == SEEK_CUR) + return gztell(self->gz_file); + return gzseek(self->gz_file, offset, whence); } @@ -90,14 +96,14 @@ if (strncmp("zlib:", path, 5) == 0) path += 5; - self->stream = php_stream_open_wrapper(path, mode, options, opened_path); + self->stream = php_stream_open_wrapper(path, mode, STREAM_MUST_SEEK|options, opened_path); if (self->stream) { int fd; if (SUCCESS == php_stream_cast(self->stream, PHP_STREAM_AS_FD, (void**)&fd, REPORT_ERRORS)) { self->gz_file = gzdopen(fd, mode); if (self->gz_file) { - stream = php_stream_alloc(&php_stream_gzio_ops, self, 0, mode); + stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) return stream; gzclose(self->gz_file); Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.24 php4/main/php_streams.h:1.25 --- php4/main/php_streams.h:1.24 Wed Mar 20 09:38:13 2002 +++ php4/main/php_streams.h Wed Mar 20 20:11:52 2002 @@ -193,6 +193,7 @@ PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC); #define php_stream_gets(stream, buf, maxlen) _php_stream_gets((stream), (buf), (maxlen) TSRMLS_CC) +/* CAREFUL! this is equivalent to puts NOT fputs! */ PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC); #define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC) @@ -207,6 +208,10 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC); #define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) + +/* output all data from a stream */ +PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC); +#define php_stream_passthru(stream) _php_stream_passthru((stream) STREAMS_CC TSRMLS_CC) /* maybe implement someday */ Index: php4/main/streams.c diff -u php4/main/streams.c:1.38 php4/main/streams.c:1.39 --- php4/main/streams.c:1.38 Wed Mar 20 09:21:30 2002 +++ php4/main/streams.c Wed Mar 20 20:11:52 2002 @@ -26,7 +26,7 @@ #include "php_network.h" #include "php_open_temporary_file.h" #include "ext/standard/file.h" - +#include "ext/standard/basic_functions.h" /* for BG(mmap_file) (not strictly required) */ #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif @@ -285,6 +285,54 @@ zend_error(E_WARNING, "streams of type %s do not support seeking", stream->ops->label); return -1; } + +PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC) +{ + size_t bcount = 0; + int ready = 0; + char buf[8192]; +#ifdef HAVE_MMAP + int fd; +#endif + +#ifdef HAVE_MMAP + if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET) + && php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 0)) + { + struct stat sbuf; + off_t off; + void *p; + size_t len; + + fstat(fd, &sbuf); + + if (sbuf.st_size > sizeof(buf)) { + off = php_stream_tell(stream); + len = sbuf.st_size - off; + p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off); + if (p != (void *) MAP_FAILED) { + BG(mmap_file) = p; + BG(mmap_len) = len; + PHPWRITE(p, len); + BG(mmap_file) = NULL; + munmap(p, len); + bcount += len; + ready = 1; + } + } + } +#endif + if(!ready) { + int b; + + while ((b = php_stream_read(stream, buf, sizeof(buf))) > 0) { + PHPWRITE(buf, b); + bcount += b; + } + } + return bcount; +} + PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC) {
Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.218 php4/ext/standard/file.c:1.219 --- php4/ext/standard/file.c:1.218 Wed Mar 20 09:38:10 2002 +++ php4/ext/standard/file.c Wed Mar 20 20:11:52 2002 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.218 2002/03/20 14:38:10 wez Exp $ */ +/* $Id: file.c,v 1.219 2002/03/21 01:11:52 wez Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1326,55 +1326,6 @@ } /* }}} */ -/* {{{ php_passthru_stream */ -static size_t php_passthru_stream(php_stream *stream TSRMLS_DC) -{ - size_t bcount = 0; - int ready = 0; - char buf[8192]; -#ifdef HAVE_MMAP - int fd; -#endif - -#ifdef HAVE_MMAP - if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET) - && php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 0)) - { - struct stat sbuf; - off_t off; - void *p; - size_t len; - - fstat(fd, &sbuf); - - if (sbuf.st_size > sizeof(buf)) { - off = php_stream_tell(stream); - len = sbuf.st_size - off; - p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off); - if (p != (void *) MAP_FAILED) { - BG(mmap_file) = p; - BG(mmap_len) = len; - PHPWRITE(p, len); - BG(mmap_file) = NULL; - munmap(p, len); - bcount += len; - ready = 1; - } - } - } -#endif - if(!ready) { - int b; - - while ((b = php_stream_read(stream, buf, sizeof(buf))) > 0) { - PHPWRITE(buf, b); - bcount += b; - } - } - return bcount; -} -/* }}} */ - /* {{{ proto int readfile(string filename [, int use_include_path]) Output a file or a URL */ PHP_FUNCTION(readfile) @@ -1407,7 +1358,7 @@ use_include_path | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (stream) { - size = php_passthru_stream(stream TSRMLS_CC); + size = php_stream_passthru(stream); php_stream_close(stream); RETURN_LONG(size); } @@ -1460,7 +1411,7 @@ what = zend_fetch_resource(arg1 TSRMLS_CC,-1, "File-Handle", &type, 1, le_stream); ZEND_VERIFY_RESOURCE(what); - size = php_passthru_stream((php_stream*)what TSRMLS_CC); + size = php_stream_passthru((php_stream*)what); RETURN_LONG(size); } /* }}} */ Index: php4/ext/zlib/php_zlib.h diff -u php4/ext/zlib/php_zlib.h:1.26 php4/ext/zlib/php_zlib.h:1.27 --- php4/ext/zlib/php_zlib.h:1.26 Wed Mar 20 08:21:55 2002 +++ php4/ext/zlib/php_zlib.h Wed Mar 20 20:11:52 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zlib.h,v 1.26 2002/03/20 13:21:55 wez Exp $ */ +/* $Id: php_zlib.h,v 1.27 2002/03/21 01:11:52 wez Exp $ */ #ifndef PHP_ZLIB_H #define PHP_ZLIB_H @@ -25,8 +25,6 @@ #include <zlib.h> ZEND_BEGIN_MODULE_GLOBALS(zlib) - int gzgetss_state; - /* variables for transparent gzip encoding */ int compression_coding; z_stream stream; @@ -44,17 +42,6 @@ PHP_RINIT_FUNCTION(zlib); PHP_MINFO_FUNCTION(zlib); PHP_FUNCTION(gzopen); -PHP_FUNCTION(gzclose); -PHP_FUNCTION(gzeof); -PHP_FUNCTION(gzread); -PHP_FUNCTION(gzgetc); -PHP_FUNCTION(gzgets); -PHP_FUNCTION(gzgetss); -PHP_FUNCTION(gzwrite); -PHP_FUNCTION(gzrewind); -PHP_FUNCTION(gztell); -PHP_FUNCTION(gzseek); -PHP_FUNCTION(gzpassthru); PHP_FUNCTION(readgzfile); PHP_FUNCTION(gzfile); PHP_FUNCTION(gzcompress); Index: php4/ext/zlib/zlib.c diff -u php4/ext/zlib/zlib.c:1.118 php4/ext/zlib/zlib.c:1.119 --- php4/ext/zlib/zlib.c:1.118 Wed Mar 20 09:38:13 2002 +++ php4/ext/zlib/zlib.c Wed Mar 20 20:11:52 2002 @@ -18,7 +18,7 @@ | Jade Nicoletti <nicoletti@nns.ch> | +----------------------------------------------------------------------+ */ -/* $Id: zlib.c,v 1.118 2002/03/20 14:38:13 wez Exp $ */ +/* $Id: zlib.c,v 1.119 2002/03/21 01:11:52 wez Exp $ */ #define IS_EXT_MODULE #ifdef HAVE_CONFIG_H @@ -86,27 +86,27 @@ /* {{{ php_zlib_functions[] */ function_entry php_zlib_functions[] = { - PHP_FE(readgzfile, NULL) - PHP_FE(gzrewind, NULL) - PHP_FE(gzclose, NULL) - PHP_FE(gzeof, NULL) - PHP_FE(gzgetc, NULL) - PHP_FE(gzgets, NULL) - PHP_FE(gzgetss, NULL) - PHP_FE(gzread, NULL) - PHP_FE(gzopen, NULL) - PHP_FE(gzpassthru, NULL) - PHP_FE(gzseek, NULL) - PHP_FE(gztell, NULL) - PHP_FE(gzwrite, NULL) - PHP_FALIAS(gzputs, gzwrite, NULL) - PHP_FE(gzfile, NULL) - PHP_FE(gzcompress, NULL) - PHP_FE(gzuncompress, NULL) - PHP_FE(gzdeflate, NULL) - PHP_FE(gzinflate, NULL) - PHP_FE(gzencode, NULL) - PHP_FE(ob_gzhandler, NULL) + PHP_FE(readgzfile, NULL) + PHP_NAMED_FE(gzrewind, PHP_FN(rewind), NULL) + PHP_NAMED_FE(gzclose, PHP_FN(fclose), NULL) + PHP_NAMED_FE(gzeof, PHP_FN(feof), NULL) + PHP_NAMED_FE(gzgetc, PHP_FN(fgetc), NULL) + PHP_NAMED_FE(gzgets, PHP_FN(fgets), NULL) + PHP_NAMED_FE(gzgetss, PHP_FN(fgetss), NULL) + PHP_NAMED_FE(gzread, PHP_FN(fread), NULL) + PHP_FE(gzopen, NULL) + PHP_NAMED_FE(gzpassthru, PHP_FN(fpassthru), NULL) + PHP_NAMED_FE(gzseek, PHP_FN(fseek), NULL) + PHP_NAMED_FE(gztell, PHP_FN(ftell), NULL) + PHP_NAMED_FE(gzwrite, PHP_FN(fwrite), NULL) + PHP_NAMED_FE(gzputs, PHP_FN(fwrite), NULL) + PHP_FE(gzfile, NULL) + PHP_FE(gzcompress, NULL) + PHP_FE(gzuncompress, NULL) + PHP_FE(gzdeflate, NULL) + PHP_FE(gzinflate, NULL) + PHP_FE(gzencode, NULL) + PHP_FE(ob_gzhandler, NULL) {NULL, NULL, NULL} }; /* }}} */ @@ -246,25 +246,6 @@ } /* }}} */ -/* {{{ php_gzopen_wrapper - */ -static gzFile php_gzopen_wrapper(char *path, char *mode, int options TSRMLS_DC) -{ - php_stream *stream = NULL; - int fd; - - stream = php_stream_open_wrapper(path, mode, options | REPORT_ERRORS, NULL); - if (stream) { - if (SUCCESS == php_stream_cast(stream, PHP_STREAM_CAST_RELEASE|PHP_STREAM_AS_FD|PHP_STREAM_CAST_TRY_HARD, (void**)&fd, 1)) - { - return gzdopen(fd, mode); - } - php_stream_close(stream); - } - return NULL; -} -/* }}} */ - /* {{{ proto array gzfile(string filename [, int use_include_path]) Read und uncompress entire .gz-file into an array */ PHP_FUNCTION(gzfile) @@ -327,7 +308,7 @@ PHP_FUNCTION(gzopen) { pval **arg1, **arg2, **arg3; - gzFile *zp; + php_stream *stream; char *p; int use_include_path = 0; @@ -350,282 +331,16 @@ convert_to_string_ex(arg1); convert_to_string_ex(arg2); p = estrndup(Z_STRVAL_PP(arg2),Z_STRLEN_PP(arg2)); - - /* - * We need a better way of returning error messages from - * php_gzopen_wrapper(). - */ - zp = php_gzopen_wrapper(Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE TSRMLS_CC); - if (!zp) { - php_error(E_WARNING,"gzopen(\"%s\",\"%s\") - %s", - Z_STRVAL_PP(arg1), p, strerror(errno)); - efree(p); - RETURN_FALSE; - } - ZLIBG(gzgetss_state)=0; - efree(p); - ZEND_REGISTER_RESOURCE(return_value, zp, le_zp); -} -/* }}} */ - -/* {{{ proto int gzclose(int zp) - Close an open .gz-file pointer */ -PHP_FUNCTION(gzclose) -{ - pval **arg1; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - zend_list_delete(Z_LVAL_PP(arg1)); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int gzeof(int zp) - Test for end-of-file on a .gz-file pointer */ -PHP_FUNCTION(gzeof) -{ - pval **arg1; - gzFile *zp; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - if ((gzeof(zp))) { - RETURN_TRUE; - } else { + stream = php_stream_gzopen(Z_STRVAL_PP(arg1), p, use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + if (!stream) { RETURN_FALSE; } -} -/* }}} */ - -/* {{{ proto string gzgets(int zp, int length) - Get a line from .gz-file pointer */ -PHP_FUNCTION(gzgets) -{ - pval **arg1, **arg2; - gzFile *zp; - int len; - char *buf; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - memset(buf,0,len+1); - if (!(gzgets(zp, buf, len) != NULL)) { - efree(buf); - RETVAL_FALSE; - } else { - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(buf,0,&Z_STRLEN_P(return_value),1 TSRMLS_CC); - } else { - Z_STRVAL_P(return_value) = buf; - Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); - } - Z_TYPE_P(return_value) = IS_STRING; - } - return; -} -/* }}} */ - -/* {{{ proto string gzgetc(int zp) - Get a character from .gz-file pointer */ -PHP_FUNCTION(gzgetc) -{ - pval **arg1; - gzFile *zp; - int c; - char *buf; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * 2); - if ((c=gzgetc(zp)) == (-1)) { - efree(buf); - RETVAL_FALSE; - } else { - buf[0]=(char)c; - buf[1]='\0'; - Z_STRVAL_P(return_value) = buf; - Z_STRLEN_P(return_value) = 1; - Z_TYPE_P(return_value) = IS_STRING; - } - return; -} -/* }}} */ - -/* Strip any HTML tags while reading */ -/* {{{ proto string gzgetss(int zp, int length [, string allowable_tags]) - Get a line from file pointer and strip HTML tags */ -PHP_FUNCTION(gzgetss) -{ - pval **fd, **bytes, **allow=NULL; - gzFile *zp; - int len; - char *buf; - char *allowed_tags=NULL; - int allowed_tags_len=0; - - switch(ZEND_NUM_ARGS()) { - case 2: - if(zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) { - RETURN_FALSE; - } - break; - case 3: - if(zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(allow); - allowed_tags = Z_STRVAL_PP(allow); - allowed_tags_len = Z_STRLEN_PP(allow); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - - convert_to_long_ex(bytes); - - len = Z_LVAL_PP(bytes); - - ZEND_FETCH_RESOURCE(zp, gzFile *, fd, -1, "Zlib file", le_zp); - - buf = emalloc(sizeof(char) * (len + 1)); - /*needed because recv doesnt set null char at end*/ - memset(buf,0,len+1); - if (!(gzgets(zp, buf, len) != NULL)) { - efree(buf); - RETURN_FALSE; - } - - /* strlen() can be used here since we are doing it on the return of an fgets() anyway */ - php_strip_tags(buf, strlen(buf), &ZLIBG(gzgetss_state), allowed_tags, allowed_tags_len); - RETURN_STRING(buf, 0); - -} -/* }}} */ - -/* {{{ proto int gzwrite(int zp, string str [, int length]) - Binary-safe .gz-file write */ -PHP_FUNCTION(gzwrite) -{ - pval **arg1, **arg2, **arg3=NULL; - gzFile *zp; - int ret; - int num_bytes; - - switch (ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - num_bytes = Z_STRLEN_PP(arg2); - break; - case 3: - if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(arg2); - convert_to_long_ex(arg3); - num_bytes = MIN(Z_LVAL_PP(arg3), Z_STRLEN_PP(arg2)); - break; - default: - WRONG_PARAM_COUNT; - /* NOTREACHED */ - break; - } - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - /* strip slashes only if the length wasn't specified explicitly */ - if (!arg3 && PG(magic_quotes_runtime)) { - php_stripslashes(Z_STRVAL_PP(arg2), &num_bytes TSRMLS_CC); - } - - ret = gzwrite(zp, Z_STRVAL_PP(arg2),num_bytes); - RETURN_LONG(ret); + efree(p); + php_stream_to_zval(stream, return_value); } /* }}} */ -/* {{{ proto int gzputs(int zp, string str [, int length]) - An alias for gzwrite */ -/* }}} */ - -/* {{{ proto int gzrewind(int zp) - Rewind the position of a .gz-file pointer */ -PHP_FUNCTION(gzrewind) -{ - pval **arg1; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - gzrewind(zp); - RETURN_TRUE; -} -/* }}} */ - -/* {{{ proto int gztell(int zp) - Get .gz-file pointer's read/write position */ -PHP_FUNCTION(gztell) -{ - pval **arg1; - long pos; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - pos = gztell(zp); - RETURN_LONG(pos); -} -/* }}} */ - -/* {{{ proto int gzseek(int zp, int offset) - Seek on a file pointer */ -PHP_FUNCTION(gzseek) -{ - pval **arg1, **arg2; - int ret; - gzFile *zp; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - ret = gzseek(zp, Z_LVAL_PP(arg2), SEEK_SET); - RETURN_LONG(ret); -} -/* }}} */ - /* * Read a file and write the ouput to stdout */ @@ -634,9 +349,8 @@ PHP_FUNCTION(readgzfile) { pval **arg1, **arg2; - char buf[8192]; - gzFile *zp; - int b, size; + php_stream * stream; + int size; int use_include_path = 0; @@ -659,84 +373,15 @@ } convert_to_string_ex(arg1); - /* - * We need a better way of returning error messages from - * php_gzopen_wrapper(). - */ - zp = php_gzopen_wrapper(Z_STRVAL_PP(arg1),"r", use_include_path|ENFORCE_SAFE_MODE TSRMLS_CC); - if (!zp){ - php_error(E_WARNING,"ReadGzFile(\"%s\") - %s",Z_STRVAL_PP(arg1),strerror(errno)); + stream = php_stream_gzopen(Z_STRVAL_PP(arg1), "rb", use_include_path|ENFORCE_SAFE_MODE, NULL, NULL STREAMS_CC TSRMLS_CC); + if (!stream) { 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 */ -PHP_FUNCTION(gzpassthru) -{ - pval **arg1; - gzFile *zp; - char buf[8192]; - int size, b; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) { - WRONG_PARAM_COUNT; - } - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - size = 0; - while((b = gzread(zp, buf, sizeof(buf))) > 0) { - PHPWRITE(buf,b); - size += b ; - } -/* gzclose(zp); */ - zend_list_delete(Z_LVAL_PP(arg1)); + php_stream_passthru(stream); + php_stream_close(stream); RETURN_LONG(size); } /* }}} */ - -/* {{{ proto string gzread(int zp, int length) - Binary-safe file read */ -PHP_FUNCTION(gzread) -{ - pval **arg1, **arg2; - gzFile *zp; - int len; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_long_ex(arg2); - len = Z_LVAL_PP(arg2); - - ZEND_FETCH_RESOURCE(zp, gzFile *, arg1, -1, "Zlib file", le_zp); - - Z_STRVAL_P(return_value) = emalloc(sizeof(char) * (len + 1)); - /* needed because recv doesnt put a null at the end*/ - - Z_STRLEN_P(return_value) = gzread(zp, Z_STRVAL_P(return_value), len); - Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; - - if (PG(magic_quotes_runtime)) { - Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value),Z_STRLEN_P(return_value),&Z_STRLEN_P(return_value),1 TSRMLS_CC); - } - Z_TYPE_P(return_value) = IS_STRING; -} - -/* }}} */ - /* {{{ proto string gzcompress(string data [, int level]) Gzip-compress a string */ Index: php4/ext/zlib/zlib_fopen_wrapper.c diff -u php4/ext/zlib/zlib_fopen_wrapper.c:1.17 php4/ext/zlib/zlib_fopen_wrapper.c:1.18 --- php4/ext/zlib/zlib_fopen_wrapper.c:1.17 Wed Mar 20 08:21:55 2002 +++ php4/ext/zlib/zlib_fopen_wrapper.c Wed Mar 20 20:11:52 2002 @@ -12,10 +12,11 @@ | obtain it through the world-wide-web, please send a note to | | license@php.net so we can mail you a copy immediately. | +----------------------------------------------------------------------+ - | Author: Hartmut Holzgraefe <hartmut@six.de> | + | Author: Wez Furlong <wez@thebrainroom.com>, based on work by: | + | Hartmut Holzgraefe <hartmut@six.de> | +----------------------------------------------------------------------+ */ -/* $Id: zlib_fopen_wrapper.c,v 1.17 2002/03/20 13:21:55 wez Exp $ */ +/* $Id: zlib_fopen_wrapper.c,v 1.18 2002/03/21 01:11:52 wez Exp $ */ #define IS_EXT_MODULE #define _GNU_SOURCE @@ -57,6 +58,11 @@ static int php_gziop_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) { struct php_gz_stream_data_t *self = (struct php_gz_stream_data_t *)stream->abstract; + + assert(self != NULL); + if (offset == 0 && whence == SEEK_CUR) + return gztell(self->gz_file); + return gzseek(self->gz_file, offset, whence); } @@ -90,14 +96,14 @@ if (strncmp("zlib:", path, 5) == 0) path += 5; - self->stream = php_stream_open_wrapper(path, mode, options, opened_path); + self->stream = php_stream_open_wrapper(path, mode, STREAM_MUST_SEEK|options, opened_path); if (self->stream) { int fd; if (SUCCESS == php_stream_cast(self->stream, PHP_STREAM_AS_FD, (void**)&fd, REPORT_ERRORS)) { self->gz_file = gzdopen(fd, mode); if (self->gz_file) { - stream = php_stream_alloc(&php_stream_gzio_ops, self, 0, mode); + stream = php_stream_alloc_rel(&php_stream_gzio_ops, self, 0, mode); if (stream) return stream; gzclose(self->gz_file); Index: php4/main/php_streams.h diff -u php4/main/php_streams.h:1.24 php4/main/php_streams.h:1.25 --- php4/main/php_streams.h:1.24 Wed Mar 20 09:38:13 2002 +++ php4/main/php_streams.h Wed Mar 20 20:11:52 2002 @@ -193,6 +193,7 @@ PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC); #define php_stream_gets(stream, buf, maxlen) _php_stream_gets((stream), (buf), (maxlen) TSRMLS_CC) +/* CAREFUL! this is equivalent to puts NOT fputs! */ PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC); #define php_stream_puts(stream, buf) _php_stream_puts((stream), (buf) TSRMLS_CC) @@ -207,6 +208,10 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC); #define php_stream_copy_to_mem(src, buf, maxlen, persistent) _php_stream_copy_to_mem((src), (buf), (maxlen), (persistent) STREAMS_CC TSRMLS_CC) + +/* output all data from a stream */ +PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC); +#define php_stream_passthru(stream) _php_stream_passthru((stream) STREAMS_CC TSRMLS_CC) /* maybe implement someday */ Index: php4/main/streams.c diff -u php4/main/streams.c:1.38 php4/main/streams.c:1.39 --- php4/main/streams.c:1.38 Wed Mar 20 09:21:30 2002 +++ php4/main/streams.c Wed Mar 20 20:11:52 2002 @@ -26,7 +26,7 @@ #include "php_network.h" #include "php_open_temporary_file.h" #include "ext/standard/file.h" - +#include "ext/standard/basic_functions.h" /* for BG(mmap_file) (not strictly required) */ #ifdef HAVE_SYS_MMAN_H #include <sys/mman.h> #endif @@ -285,6 +285,54 @@ zend_error(E_WARNING, "streams of type %s do not support seeking", stream->ops->label); return -1; } + +PHPAPI size_t _php_stream_passthru(php_stream * stream STREAMS_DC TSRMLS_DC) +{ + size_t bcount = 0; + int ready = 0; + char buf[8192]; +#ifdef HAVE_MMAP + int fd; +#endif + +#ifdef HAVE_MMAP + if (!php_stream_is(stream, PHP_STREAM_IS_SOCKET) + && php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 0)) + { + struct stat sbuf; + off_t off; + void *p; + size_t len; + + fstat(fd, &sbuf); + + if (sbuf.st_size > sizeof(buf)) { + off = php_stream_tell(stream); + len = sbuf.st_size - off; + p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off); + if (p != (void *) MAP_FAILED) { + BG(mmap_file) = p; + BG(mmap_len) = len; + PHPWRITE(p, len); + BG(mmap_file) = NULL; + munmap(p, len); + bcount += len; + ready = 1; + } + } + } +#endif + if(!ready) { + int b; + + while ((b = php_stream_read(stream, buf, sizeof(buf))) > 0) { + PHPWRITE(buf, b); + bcount += b; + } + } + return bcount; +} + PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen, int persistent STREAMS_DC TSRMLS_DC) {