diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/bz2 | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/bz2')
-rw-r--r-- | ext/bz2/CREDITS | 2 | ||||
-rw-r--r-- | ext/bz2/bz2.c | 636 | ||||
-rw-r--r-- | ext/bz2/bz2.dsp | 112 | ||||
-rw-r--r-- | ext/bz2/bz2_filter.c | 452 | ||||
-rw-r--r-- | ext/bz2/config.m4 | 40 | ||||
-rw-r--r-- | ext/bz2/config.w32 | 18 | ||||
-rw-r--r-- | ext/bz2/package.xml | 38 | ||||
-rw-r--r-- | ext/bz2/php_bz2.def | 7 | ||||
-rw-r--r-- | ext/bz2/php_bz2.h | 74 | ||||
-rw-r--r-- | ext/bz2/tests/001.phpt | 43 | ||||
-rw-r--r-- | ext/bz2/tests/002.phpt | 129 | ||||
-rw-r--r-- | ext/bz2/tests/003.phpt | 40 | ||||
-rw-r--r-- | ext/bz2/tests/003.txt.bz2 | bin | 0 -> 126 bytes | |||
-rw-r--r-- | ext/bz2/tests/004.phpt | 111 | ||||
-rw-r--r-- | ext/bz2/tests/004_1.txt.bz2 | bin | 0 -> 125 bytes | |||
-rw-r--r-- | ext/bz2/tests/004_2.txt.bz2 | bin | 0 -> 123 bytes | |||
-rw-r--r-- | ext/bz2/tests/005.phpt | 71 | ||||
-rw-r--r-- | ext/bz2/tests/bug51997.phpt | 24 | ||||
-rw-r--r-- | ext/bz2/tests/bz2_filter_compress.phpt | 17 | ||||
-rw-r--r-- | ext/bz2/tests/bz2_filter_decompress.phpt | 17 | ||||
-rw-r--r-- | ext/bz2/tests/with_files.phpt | 23 | ||||
-rw-r--r-- | ext/bz2/tests/with_strings.phpt | 27 |
22 files changed, 1881 insertions, 0 deletions
diff --git a/ext/bz2/CREDITS b/ext/bz2/CREDITS new file mode 100644 index 0000000..67dff9f --- /dev/null +++ b/ext/bz2/CREDITS @@ -0,0 +1,2 @@ +Bzip2 +Sterling Hughes diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c new file mode 100644 index 0000000..65b06d7 --- /dev/null +++ b/ext/bz2/bz2.c @@ -0,0 +1,636 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_bz2.h" + +#if HAVE_BZ2 + +/* PHP Includes */ +#include "ext/standard/file.h" +#include "ext/standard/info.h" +#include "ext/standard/php_string.h" + +/* for fileno() */ +#include <stdio.h> + +/* Internal error constants */ +#define PHP_BZ_ERRNO 0 +#define PHP_BZ_ERRSTR 1 +#define PHP_BZ_ERRBOTH 2 + +static PHP_MINIT_FUNCTION(bz2); +static PHP_MSHUTDOWN_FUNCTION(bz2); +static PHP_MINFO_FUNCTION(bz2); +static PHP_FUNCTION(bzopen); +static PHP_FUNCTION(bzread); +static PHP_FUNCTION(bzerrno); +static PHP_FUNCTION(bzerrstr); +static PHP_FUNCTION(bzerror); +static PHP_FUNCTION(bzcompress); +static PHP_FUNCTION(bzdecompress); + +/* {{{ arginfo */ +ZEND_BEGIN_ARG_INFO_EX(arginfo_bzread, 0, 0, 1) + ZEND_ARG_INFO(0, bz) + ZEND_ARG_INFO(0, length) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_bzopen, 0) + ZEND_ARG_INFO(0, file) + ZEND_ARG_INFO(0, mode) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_bzerrno, 0) + ZEND_ARG_INFO(0, bz) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_bzerrstr, 0) + ZEND_ARG_INFO(0, bz) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_bzerror, 0) + ZEND_ARG_INFO(0, bz) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_bzcompress, 0, 0, 2) + ZEND_ARG_INFO(0, source) + ZEND_ARG_INFO(0, blocksize) + ZEND_ARG_INFO(0, workfactor) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_bzdecompress, 0, 0, 1) + ZEND_ARG_INFO(0, source) + ZEND_ARG_INFO(0, small) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_bzwrite, 0, 0, 2) + ZEND_ARG_INFO(0, fp) + ZEND_ARG_INFO(0, str) + ZEND_ARG_INFO(0, length) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO(arginfo_bzflush, 0) + ZEND_ARG_INFO(0, fp) +ZEND_END_ARG_INFO() +/* }}} */ + +static const zend_function_entry bz2_functions[] = { + PHP_FE(bzopen, arginfo_bzopen) + PHP_FE(bzread, arginfo_bzread) + PHP_FALIAS(bzwrite, fwrite, arginfo_bzwrite) + PHP_FALIAS(bzflush, fflush, arginfo_bzflush) + PHP_FALIAS(bzclose, fclose, arginfo_bzflush) + PHP_FE(bzerrno, arginfo_bzerrno) + PHP_FE(bzerrstr, arginfo_bzerrstr) + PHP_FE(bzerror, arginfo_bzerror) + PHP_FE(bzcompress, arginfo_bzcompress) + PHP_FE(bzdecompress, arginfo_bzdecompress) + PHP_FE_END +}; + +zend_module_entry bz2_module_entry = { + STANDARD_MODULE_HEADER, + "bz2", + bz2_functions, + PHP_MINIT(bz2), + PHP_MSHUTDOWN(bz2), + NULL, + NULL, + PHP_MINFO(bz2), + NO_VERSION_YET, + STANDARD_MODULE_PROPERTIES +}; + +#ifdef COMPILE_DL_BZ2 +ZEND_GET_MODULE(bz2) +#endif + +struct php_bz2_stream_data_t { + BZFILE *bz_file; + php_stream *stream; +}; + +/* {{{ BZip2 stream implementation */ + +static size_t php_bz2iop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) +{ + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; + size_t ret; + + ret = BZ2_bzread(self->bz_file, buf, count); + + if (ret == 0) { + stream->eof = 1; + } + + return ret; +} + +static size_t php_bz2iop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) +{ + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *) stream->abstract; + + return BZ2_bzwrite(self->bz_file, (char*)buf, count); +} + +static int php_bz2iop_close(php_stream *stream, int close_handle TSRMLS_DC) +{ + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract; + int ret = EOF; + + if (close_handle) { + BZ2_bzclose(self->bz_file); + } + + if (self->stream) { + php_stream_free(self->stream, PHP_STREAM_FREE_CLOSE | (close_handle == 0 ? PHP_STREAM_FREE_PRESERVE_HANDLE : 0)); + } + + efree(self); + + return ret; +} + +static int php_bz2iop_flush(php_stream *stream TSRMLS_DC) +{ + struct php_bz2_stream_data_t *self = (struct php_bz2_stream_data_t *)stream->abstract; + return BZ2_bzflush(self->bz_file); +} +/* }}} */ + +php_stream_ops php_stream_bz2io_ops = { + php_bz2iop_write, php_bz2iop_read, + php_bz2iop_close, php_bz2iop_flush, + "BZip2", + NULL, /* seek */ + NULL, /* cast */ + NULL, /* stat */ + NULL /* set_option */ +}; + +/* {{{ Bzip2 stream openers */ +PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, + char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC) +{ + struct php_bz2_stream_data_t *self; + + self = emalloc(sizeof(*self)); + + self->stream = innerstream; + self->bz_file = bz; + + return php_stream_alloc_rel(&php_stream_bz2io_ops, self, 0, mode); +} + +PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, + char *path, + char *mode, + int options, + char **opened_path, + php_stream_context *context STREAMS_DC TSRMLS_DC) +{ + php_stream *retstream = NULL, *stream = NULL; + char *path_copy = NULL; + BZFILE *bz_file = NULL; + + if (strncasecmp("compress.bzip2://", path, 17) == 0) { + path += 17; + } + if (mode[0] == '\0' || (mode[0] != 'w' && mode[0] != 'r' && mode[1] != '\0')) { + return NULL; + } + +#ifdef VIRTUAL_DIR + virtual_filepath_ex(path, &path_copy, NULL TSRMLS_CC); +#else + path_copy = path; +#endif + + if (php_check_open_basedir(path_copy TSRMLS_CC)) { + return NULL; + } + + /* try and open it directly first */ + bz_file = BZ2_bzopen(path_copy, mode); + + if (opened_path && bz_file) { + *opened_path = estrdup(path_copy); + } + path_copy = NULL; + + if (bz_file == NULL) { + /* that didn't work, so try and get something from the network/wrapper */ + stream = php_stream_open_wrapper(path, mode, options | STREAM_WILL_CAST, opened_path); + + if (stream) { + int fd; + if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD, (void **) &fd, REPORT_ERRORS)) { + bz_file = BZ2_bzdopen(fd, mode); + } + } + + /* remove the file created by php_stream_open_wrapper(), it is not needed since BZ2 functions + * failed. + */ + if (opened_path && !bz_file && mode[0] == 'w') { + VCWD_UNLINK(*opened_path); + } + } + + if (bz_file) { + retstream = _php_stream_bz2open_from_BZFILE(bz_file, mode, stream STREAMS_REL_CC TSRMLS_CC); + if (retstream) { + return retstream; + } + + BZ2_bzclose(bz_file); + } + + if (stream) { + php_stream_close(stream); + } + + return NULL; +} + +/* }}} */ + +static php_stream_wrapper_ops bzip2_stream_wops = { + _php_stream_bz2open, + NULL, /* close */ + NULL, /* fstat */ + NULL, /* stat */ + NULL, /* opendir */ + "BZip2", + NULL, /* unlink */ + NULL, /* rename */ + NULL, /* mkdir */ + NULL /* rmdir */ +}; + +static php_stream_wrapper php_stream_bzip2_wrapper = { + &bzip2_stream_wops, + NULL, + 0 /* is_url */ +}; + +static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int); + +static PHP_MINIT_FUNCTION(bz2) +{ + php_register_url_stream_wrapper("compress.bzip2", &php_stream_bzip2_wrapper TSRMLS_CC); + php_stream_filter_register_factory("bzip2.*", &php_bz2_filter_factory TSRMLS_CC); + return SUCCESS; +} + +static PHP_MSHUTDOWN_FUNCTION(bz2) +{ + php_unregister_url_stream_wrapper("compress.bzip2" TSRMLS_CC); + php_stream_filter_unregister_factory("bzip2.*" TSRMLS_CC); + + return SUCCESS; +} + +static PHP_MINFO_FUNCTION(bz2) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "BZip2 Support", "Enabled"); + php_info_print_table_row(2, "Stream Wrapper support", "compress.bzip2://"); + php_info_print_table_row(2, "Stream Filter support", "bzip2.decompress, bzip2.compress"); + php_info_print_table_row(2, "BZip2 Version", (char *) BZ2_bzlibVersion()); + php_info_print_table_end(); +} + +/* {{{ proto string bzread(resource bz[, int length]) + Reads up to length bytes from a BZip2 stream, or 1024 bytes if length is not specified */ +static PHP_FUNCTION(bzread) +{ + zval *bz; + long len = 1024; + php_stream *stream; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &bz, &len)) { + RETURN_FALSE; + } + + php_stream_from_zval(stream, &bz); + + if ((len + 1) < 1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "length may not be negative"); + RETURN_FALSE; + } + + Z_STRVAL_P(return_value) = emalloc(len + 1); + Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len); + + if (Z_STRLEN_P(return_value) < 0) { + efree(Z_STRVAL_P(return_value)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read valid bz2 data from stream"); + RETURN_FALSE; + } + + Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0; + Z_TYPE_P(return_value) = IS_STRING; +} +/* }}} */ + +/* {{{ proto resource bzopen(string|int file|fp, string mode) + Opens a new BZip2 stream */ +static PHP_FUNCTION(bzopen) +{ + zval **file; /* The file to open */ + char *mode; /* The mode to open the stream with */ + int mode_len; + + BZFILE *bz; /* The compressed file stream */ + php_stream *stream = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &file, &mode, &mode_len) == FAILURE) { + return; + } + + if (mode_len != 1 || (mode[0] != 'r' && mode[0] != 'w')) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode); + RETURN_FALSE; + } + + /* If it's not a resource its a string containing the filename to open */ + if (Z_TYPE_PP(file) == IS_STRING) { + if (Z_STRLEN_PP(file) == 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty"); + RETURN_FALSE; + } + + if (CHECK_ZVAL_NULL_PATH(*file)) { + RETURN_FALSE; + } + + stream = php_stream_bz2open(NULL, + Z_STRVAL_PP(file), + mode, + REPORT_ERRORS, + NULL); + } else if (Z_TYPE_PP(file) == IS_RESOURCE) { + /* If it is a resource, than its a stream resource */ + int fd; + int stream_mode_len; + + php_stream_from_zval(stream, file); + stream_mode_len = strlen(stream->mode); + + if (stream_mode_len != 1 && !(stream_mode_len == 2 && memchr(stream->mode, 'b', 2))) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode); + RETURN_FALSE; + } else if (stream_mode_len == 1 && stream->mode[0] != 'r' && stream->mode[0] != 'w' && stream->mode[0] != 'a' && stream->mode[0] != 'x') { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode); + RETURN_FALSE; + } + + switch(mode[0]) { + case 'r': + /* only "r" and "rb" are supported */ + if (stream->mode[0] != mode[0] && !(stream_mode_len == 2 && stream->mode[1] != mode[0])) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot read from a stream opened in write only mode"); + RETURN_FALSE; + } + break; + case 'w': + /* support only "w"(b), "a"(b), "x"(b) */ + if (stream->mode[0] != mode[0] && !(stream_mode_len == 2 && stream->mode[1] != mode[0]) + && stream->mode[0] != 'a' && !(stream_mode_len == 2 && stream->mode[1] != 'a') + && stream->mode[0] != 'x' && !(stream_mode_len == 2 && stream->mode[1] != 'x')) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot write to a stream opened in read only mode"); + RETURN_FALSE; + } + break; + default: + /* not reachable */ + break; + } + + if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_FD, (void *) &fd, REPORT_ERRORS)) { + RETURN_FALSE; + } + + bz = BZ2_bzdopen(fd, mode); + + stream = php_stream_bz2open_from_BZFILE(bz, mode, stream); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "first parameter has to be string or file-resource"); + RETURN_FALSE; + } + + if (stream) { + php_stream_to_zval(stream, return_value); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto int bzerrno(resource bz) + Returns the error number */ +static PHP_FUNCTION(bzerrno) +{ + php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRNO); +} +/* }}} */ + +/* {{{ proto string bzerrstr(resource bz) + Returns the error string */ +static PHP_FUNCTION(bzerrstr) +{ + php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRSTR); +} +/* }}} */ + +/* {{{ proto array bzerror(resource bz) + Returns the error number and error string in an associative array */ +static PHP_FUNCTION(bzerror) +{ + php_bz2_error(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_BZ_ERRBOTH); +} +/* }}} */ + +/* {{{ proto string bzcompress(string source [, int blocksize100k [, int workfactor]]) + Compresses a string into BZip2 encoded data */ +static PHP_FUNCTION(bzcompress) +{ + char *source; /* Source data to compress */ + long zblock_size = 0; /* Optional block size to use */ + long zwork_factor = 0;/* Optional work factor to use */ + char *dest = NULL; /* Destination to place the compressed data into */ + int error, /* Error Container */ + block_size = 4, /* Block size for compression algorithm */ + work_factor = 0, /* Work factor for compression algorithm */ + argc; /* Argument count */ + int source_len; /* Length of the source data */ + unsigned int dest_len; /* Length of the destination buffer */ + + argc = ZEND_NUM_ARGS(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &source, &source_len, &zblock_size, &zwork_factor) == FAILURE) { + return; + } + + /* Assign them to easy to use variables, dest_len is initially the length of the data + + .01 x length of data + 600 which is the largest size the results of the compression + could possibly be, at least that's what the libbz2 docs say (thanks to jeremy@nirvani.net + for pointing this out). */ + dest_len = (unsigned int) (source_len + (0.01 * source_len) + 600); + + /* Allocate the destination buffer */ + dest = emalloc(dest_len + 1); + + /* Handle the optional arguments */ + if (argc > 1) { + block_size = zblock_size; + } + + if (argc > 2) { + work_factor = zwork_factor; + } + + error = BZ2_bzBuffToBuffCompress(dest, &dest_len, source, source_len, block_size, 0, work_factor); + if (error != BZ_OK) { + efree(dest); + RETURN_LONG(error); + } else { + /* Copy the buffer, we have perhaps allocate alot more than we need, + so we erealloc() the buffer to the proper size */ + dest = erealloc(dest, dest_len + 1); + dest[dest_len] = 0; + RETURN_STRINGL(dest, dest_len, 0); + } +} +/* }}} */ + +/* {{{ proto string bzdecompress(string source [, int small]) + Decompresses BZip2 compressed data */ +static PHP_FUNCTION(bzdecompress) +{ + char *source, *dest; + int source_len, error; + long small = 0; +#if defined(PHP_WIN32) + unsigned __int64 size = 0; +#else + unsigned long long size = 0; +#endif + bz_stream bzs; + + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &source, &source_len, &small)) { + RETURN_FALSE; + } + + bzs.bzalloc = NULL; + bzs.bzfree = NULL; + + if (BZ2_bzDecompressInit(&bzs, 0, small) != BZ_OK) { + RETURN_FALSE; + } + + bzs.next_in = source; + bzs.avail_in = source_len; + + /* in most cases bz2 offers at least 2:1 compression, so we use that as our base */ + bzs.avail_out = source_len * 2; + bzs.next_out = dest = emalloc(bzs.avail_out + 1); + + while ((error = BZ2_bzDecompress(&bzs)) == BZ_OK && bzs.avail_in > 0) { + /* compression is better then 2:1, need to allocate more memory */ + bzs.avail_out = source_len; + size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32; + dest = safe_erealloc(dest, 1, bzs.avail_out+1, (size_t) size ); + bzs.next_out = dest + size; + } + + if (error == BZ_STREAM_END || error == BZ_OK) { + size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32; + dest = safe_erealloc(dest, 1, (size_t) size, 1); + dest[size] = '\0'; + RETVAL_STRINGL(dest, (int) size, 0); + } else { /* real error */ + efree(dest); + RETVAL_LONG(error); + } + + BZ2_bzDecompressEnd(&bzs); +} +/* }}} */ + +/* {{{ php_bz2_error() + The central error handling interface, does the work for bzerrno, bzerrstr and bzerror */ +static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt) +{ + zval *bzp; /* BZip2 Resource Pointer */ + php_stream *stream; + const char *errstr; /* Error string */ + int errnum; /* Error number */ + struct php_bz2_stream_data_t *self; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &bzp) == FAILURE) { + return; + } + + php_stream_from_zval(stream, &bzp); + + if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) { + RETURN_FALSE; + } + + self = (struct php_bz2_stream_data_t *) stream->abstract; + + /* Fetch the error information */ + errstr = BZ2_bzerror(self->bz_file, &errnum); + + /* Determine what to return */ + switch (opt) { + case PHP_BZ_ERRNO: + RETURN_LONG(errnum); + break; + case PHP_BZ_ERRSTR: + RETURN_STRING((char*)errstr, 1); + break; + case PHP_BZ_ERRBOTH: + array_init(return_value); + + add_assoc_long (return_value, "errno", errnum); + add_assoc_string(return_value, "errstr", (char*)errstr, 1); + break; + } +} +/* }}} */ + +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: fdm=marker + * vim: noet sw=4 ts=4 + */ diff --git a/ext/bz2/bz2.dsp b/ext/bz2/bz2.dsp new file mode 100644 index 0000000..a054c52 --- /dev/null +++ b/ext/bz2/bz2.dsp @@ -0,0 +1,112 @@ +# Microsoft Developer Studio Project File - Name="bz2" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=bz2 - Win32 Debug_TS
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "bz2.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "bz2.mak" CFG="bz2 - Win32 Debug_TS"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "bz2 - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "bz2 - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "bz2 - Win32 Release_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_TS"
+# PROP BASE Intermediate_Dir "Release_TS"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_TS"
+# PROP Intermediate_Dir "Release_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZ2_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_BZ2" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_BZ2=1 /D "PHP_BZ2_EXPORTS" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x407 /d "NDEBUG"
+# ADD RSC /l 0x407 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 libbz2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php5ts.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_bz2.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\php_build\release"
+
+!ELSEIF "$(CFG)" == "bz2 - Win32 Debug_TS"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug_TS"
+# PROP BASE Intermediate_Dir "Debug_TS"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_TS"
+# PROP Intermediate_Dir "Debug_TS"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZ2_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\php_build\includes" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_BZ2" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_BZ2=1 /D "PHP_BZ2_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x407 /d "_DEBUG"
+# ADD RSC /l 0x407 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 php5ts_debug.lib libbz2.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_bz2.dll" /pdbtype:sept /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\release"
+
+!ENDIF
+
+# Begin Target
+
+# Name "bz2 - Win32 Release_TS"
+# Name "bz2 - Win32 Debug_TS"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\bz2.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\bz2_filter.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\php_bz2.h
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/ext/bz2/bz2_filter.c b/ext/bz2/bz2_filter.c new file mode 100644 index 0000000..5ed7921 --- /dev/null +++ b/ext/bz2/bz2_filter.c @@ -0,0 +1,452 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Sara Golemon (pollita@php.net) | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_bz2.h" + +/* {{{ data structure */ + +enum strm_status { + PHP_BZ2_UNITIALIZED, + PHP_BZ2_RUNNING, + PHP_BZ2_FINISHED +}; + +typedef struct _php_bz2_filter_data { + int persistent; + bz_stream strm; + char *inbuf; + size_t inbuf_len; + char *outbuf; + size_t outbuf_len; + + /* Decompress options */ + enum strm_status status; + unsigned int small_footprint : 1; + unsigned int expect_concatenated : 1; +} php_bz2_filter_data; + +/* }}} */ + +/* {{{ Memory management wrappers */ + +static void *php_bz2_alloc(void *opaque, int items, int size) +{ + return (void *)safe_pemalloc(items, size, 0, ((php_bz2_filter_data*)opaque)->persistent); +} + +static void php_bz2_free(void *opaque, void *address) +{ + pefree((void *)address, ((php_bz2_filter_data*)opaque)->persistent); +} +/* }}} */ + +/* {{{ bzip2.decompress filter implementation */ + +static php_stream_filter_status_t php_bz2_decompress_filter( + php_stream *stream, + php_stream_filter *thisfilter, + php_stream_bucket_brigade *buckets_in, + php_stream_bucket_brigade *buckets_out, + size_t *bytes_consumed, + int flags + TSRMLS_DC) +{ + php_bz2_filter_data *data; + php_stream_bucket *bucket; + size_t consumed = 0; + int status; + php_stream_filter_status_t exit_status = PSFS_FEED_ME; + bz_stream *streamp; + + if (!thisfilter || !thisfilter->abstract) { + /* Should never happen */ + return PSFS_ERR_FATAL; + } + + data = (php_bz2_filter_data *)(thisfilter->abstract); + streamp = &(data->strm); + + while (buckets_in->head) { + size_t bin = 0, desired; + + bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); + while (bin < bucket->buflen) { + if (data->status == PHP_BZ2_UNITIALIZED) { + status = BZ2_bzDecompressInit(streamp, 0, data->small_footprint); + + if (BZ_OK != status) { + return PSFS_ERR_FATAL; + } + + data->status = PHP_BZ2_RUNNING; + } + + if (data->status != PHP_BZ2_RUNNING) { + consumed += bucket->buflen; + break; + } + + desired = bucket->buflen - bin; + if (desired > data->inbuf_len) { + desired = data->inbuf_len; + } + memcpy(data->strm.next_in, bucket->buf + bin, desired); + data->strm.avail_in = desired; + + status = BZ2_bzDecompress(&(data->strm)); + + if (status == BZ_STREAM_END) { + BZ2_bzDecompressEnd(&(data->strm)); + if (data->expect_concatenated) { + data->status = PHP_BZ2_UNITIALIZED; + } else { + data->status = PHP_BZ2_FINISHED; + } + } else if (status != BZ_OK) { + /* Something bad happened */ + php_stream_bucket_delref(bucket TSRMLS_CC); + return PSFS_ERR_FATAL; + } + desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ + data->strm.next_in = data->inbuf; + data->strm.avail_in = 0; + consumed += desired; + bin += desired; + + if (data->strm.avail_out < data->outbuf_len) { + php_stream_bucket *out_bucket; + size_t bucketlen = data->outbuf_len - data->strm.avail_out; + out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); + php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC); + data->strm.avail_out = data->outbuf_len; + data->strm.next_out = data->outbuf; + exit_status = PSFS_PASS_ON; + } else if (status == BZ_STREAM_END && data->strm.avail_out >= data->outbuf_len) { + /* no more data to decompress, and nothing was spat out */ + php_stream_bucket_delref(bucket TSRMLS_CC); + return PSFS_PASS_ON; + } + } + + php_stream_bucket_delref(bucket TSRMLS_CC); + } + + if ((data->status == PHP_BZ2_RUNNING) && (flags & PSFS_FLAG_FLUSH_CLOSE)) { + /* Spit it out! */ + status = BZ_OK; + while (status == BZ_OK) { + status = BZ2_bzDecompress(&(data->strm)); + if (data->strm.avail_out < data->outbuf_len) { + size_t bucketlen = data->outbuf_len - data->strm.avail_out; + + bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); + php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); + data->strm.avail_out = data->outbuf_len; + data->strm.next_out = data->outbuf; + exit_status = PSFS_PASS_ON; + } else if (status == BZ_OK) { + break; + } + } + } + + if (bytes_consumed) { + *bytes_consumed = consumed; + } + + return exit_status; +} + +static void php_bz2_decompress_dtor(php_stream_filter *thisfilter TSRMLS_DC) +{ + if (thisfilter && thisfilter->abstract) { + php_bz2_filter_data *data = thisfilter->abstract; + if (data->status == PHP_BZ2_RUNNING) { + BZ2_bzDecompressEnd(&(data->strm)); + } + pefree(data->inbuf, data->persistent); + pefree(data->outbuf, data->persistent); + pefree(data, data->persistent); + } +} + +static php_stream_filter_ops php_bz2_decompress_ops = { + php_bz2_decompress_filter, + php_bz2_decompress_dtor, + "bzip2.decompress" +}; +/* }}} */ + +/* {{{ bzip2.compress filter implementation */ + +static php_stream_filter_status_t php_bz2_compress_filter( + php_stream *stream, + php_stream_filter *thisfilter, + php_stream_bucket_brigade *buckets_in, + php_stream_bucket_brigade *buckets_out, + size_t *bytes_consumed, + int flags + TSRMLS_DC) +{ + php_bz2_filter_data *data; + php_stream_bucket *bucket; + size_t consumed = 0; + int status; + php_stream_filter_status_t exit_status = PSFS_FEED_ME; + bz_stream *streamp; + + if (!thisfilter || !thisfilter->abstract) { + /* Should never happen */ + return PSFS_ERR_FATAL; + } + + data = (php_bz2_filter_data *)(thisfilter->abstract); + streamp = &(data->strm); + + while (buckets_in->head) { + size_t bin = 0, desired; + + bucket = php_stream_bucket_make_writeable(buckets_in->head TSRMLS_CC); + + while (bin < bucket->buflen) { + desired = bucket->buflen - bin; + if (desired > data->inbuf_len) { + desired = data->inbuf_len; + } + memcpy(data->strm.next_in, bucket->buf + bin, desired); + data->strm.avail_in = desired; + + status = BZ2_bzCompress(&(data->strm), flags & PSFS_FLAG_FLUSH_CLOSE ? BZ_FINISH : (flags & PSFS_FLAG_FLUSH_INC ? BZ_FLUSH : BZ_RUN)); + if (status != BZ_RUN_OK && status != BZ_FLUSH_OK && status != BZ_FINISH_OK) { + /* Something bad happened */ + php_stream_bucket_delref(bucket TSRMLS_CC); + return PSFS_ERR_FATAL; + } + desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */ + data->strm.next_in = data->inbuf; + data->strm.avail_in = 0; + consumed += desired; + bin += desired; + + if (data->strm.avail_out < data->outbuf_len) { + php_stream_bucket *out_bucket; + size_t bucketlen = data->outbuf_len - data->strm.avail_out; + + out_bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); + php_stream_bucket_append(buckets_out, out_bucket TSRMLS_CC); + data->strm.avail_out = data->outbuf_len; + data->strm.next_out = data->outbuf; + exit_status = PSFS_PASS_ON; + } + } + php_stream_bucket_delref(bucket TSRMLS_CC); + } + + if (flags & PSFS_FLAG_FLUSH_CLOSE) { + /* Spit it out! */ + status = BZ_FINISH_OK; + while (status == BZ_FINISH_OK) { + status = BZ2_bzCompress(&(data->strm), BZ_FINISH); + if (data->strm.avail_out < data->outbuf_len) { + size_t bucketlen = data->outbuf_len - data->strm.avail_out; + + bucket = php_stream_bucket_new(stream, estrndup(data->outbuf, bucketlen), bucketlen, 1, 0 TSRMLS_CC); + php_stream_bucket_append(buckets_out, bucket TSRMLS_CC); + data->strm.avail_out = data->outbuf_len; + data->strm.next_out = data->outbuf; + exit_status = PSFS_PASS_ON; + } + } + } + + if (bytes_consumed) { + *bytes_consumed = consumed; + } + return exit_status; +} + +static void php_bz2_compress_dtor(php_stream_filter *thisfilter TSRMLS_DC) +{ + if (thisfilter && thisfilter->abstract) { + php_bz2_filter_data *data = thisfilter->abstract; + BZ2_bzCompressEnd(&(data->strm)); + pefree(data->inbuf, data->persistent); + pefree(data->outbuf, data->persistent); + pefree(data, data->persistent); + } +} + +static php_stream_filter_ops php_bz2_compress_ops = { + php_bz2_compress_filter, + php_bz2_compress_dtor, + "bzip2.compress" +}; + +/* }}} */ + +/* {{{ bzip2.* common factory */ + +static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *filterparams, int persistent TSRMLS_DC) +{ + php_stream_filter_ops *fops = NULL; + php_bz2_filter_data *data; + int status = BZ_OK; + + /* Create this filter */ + data = pecalloc(1, sizeof(php_bz2_filter_data), persistent); + if (!data) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zu bytes", sizeof(php_bz2_filter_data)); + return NULL; + } + + /* Circular reference */ + data->strm.opaque = (void *) data; + + data->strm.bzalloc = php_bz2_alloc; + data->strm.bzfree = php_bz2_free; + data->persistent = persistent; + data->strm.avail_out = data->outbuf_len = data->inbuf_len = 2048; + data->strm.next_in = data->inbuf = (char *) pemalloc(data->inbuf_len, persistent); + if (!data->inbuf) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zu bytes", data->inbuf_len); + pefree(data, persistent); + return NULL; + } + data->strm.avail_in = 0; + data->strm.next_out = data->outbuf = (char *) pemalloc(data->outbuf_len, persistent); + if (!data->outbuf) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed allocating %zu bytes", data->outbuf_len); + pefree(data->inbuf, persistent); + pefree(data, persistent); + return NULL; + } + + if (strcasecmp(filtername, "bzip2.decompress") == 0) { + data->small_footprint = 0; + data->expect_concatenated = 0; + + if (filterparams) { + zval **tmpzval = NULL; + + if (Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) { + + if (SUCCESS == zend_hash_find(HASH_OF(filterparams), "concatenated", sizeof("concatenated"), (void **) &tmpzval) ) { + zval tmp, *tmp2; + + tmp = **tmpzval; + zval_copy_ctor(&tmp); + tmp2 = &tmp; + convert_to_boolean_ex(&tmp2); + data->expect_concatenated = Z_LVAL(tmp); + tmpzval = NULL; + } + + zend_hash_find(HASH_OF(filterparams), "small", sizeof("small"), (void **) &tmpzval); + } else { + tmpzval = &filterparams; + } + + if (tmpzval) { + zval tmp, *tmp2; + + tmp = **tmpzval; + zval_copy_ctor(&tmp); + tmp2 = &tmp; + convert_to_boolean_ex(&tmp2); + data->small_footprint = Z_LVAL(tmp); + } + } + + data->status = PHP_BZ2_UNITIALIZED; + fops = &php_bz2_decompress_ops; + } else if (strcasecmp(filtername, "bzip2.compress") == 0) { + int blockSize100k = PHP_BZ2_FILTER_DEFAULT_BLOCKSIZE; + int workFactor = PHP_BZ2_FILTER_DEFAULT_WORKFACTOR; + + if (filterparams) { + zval **tmpzval; + + if (Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) { + if (zend_hash_find(HASH_OF(filterparams), "blocks", sizeof("blocks"), (void**) &tmpzval) == SUCCESS) { + /* How much memory to allocate (1 - 9) x 100kb */ + zval tmp; + + tmp = **tmpzval; + zval_copy_ctor(&tmp); + convert_to_long(&tmp); + if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > 9) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter given for number of blocks to allocate. (%ld)", Z_LVAL_PP(tmpzval)); + } else { + blockSize100k = Z_LVAL(tmp); + } + } + + if (zend_hash_find(HASH_OF(filterparams), "work", sizeof("work"), (void**) &tmpzval) == SUCCESS) { + /* Work Factor (0 - 250) */ + zval tmp; + + tmp = **tmpzval; + zval_copy_ctor(&tmp); + convert_to_long(&tmp); + + if (Z_LVAL(tmp) < 0 || Z_LVAL(tmp) > 250) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter given for work factor. (%ld)", Z_LVAL(tmp)); + } else { + workFactor = Z_LVAL(tmp); + } + } + } + } + + status = BZ2_bzCompressInit(&(data->strm), blockSize100k, 0, workFactor); + fops = &php_bz2_compress_ops; + } else { + status = BZ_DATA_ERROR; + } + + if (status != BZ_OK) { + /* Unspecified (probably strm) error, let stream-filter error do its own whining */ + pefree(data->strm.next_in, persistent); + pefree(data->strm.next_out, persistent); + pefree(data, persistent); + return NULL; + } + + return php_stream_filter_alloc(fops, data, persistent); +} + +php_stream_filter_factory php_bz2_filter_factory = { + php_bz2_filter_create +}; +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/ext/bz2/config.m4 b/ext/bz2/config.m4 new file mode 100644 index 0000000..3e6aa78 --- /dev/null +++ b/ext/bz2/config.m4 @@ -0,0 +1,40 @@ +dnl +dnl $Id$ +dnl + +PHP_ARG_WITH(bz2, for BZip2 support, +[ --with-bz2[=DIR] Include BZip2 support]) + +if test "$PHP_BZ2" != "no"; then + if test -r $PHP_BZ2/include/bzlib.h; then + BZIP_DIR=$PHP_BZ2 + else + AC_MSG_CHECKING(for BZip2 in default path) + for i in /usr/local /usr; do + if test -r $i/include/bzlib.h; then + BZIP_DIR=$i + AC_MSG_RESULT(found in $i) + break + fi + done + fi + + if test -z "$BZIP_DIR"; then + AC_MSG_RESULT(not found) + AC_MSG_ERROR(Please reinstall the BZip2 distribution) + fi + + PHP_CHECK_LIBRARY(bz2, BZ2_bzerror, + [ + PHP_ADD_INCLUDE($BZIP_DIR/include) + PHP_ADD_LIBRARY_WITH_PATH(bz2, $BZIP_DIR/$PHP_LIBDIR, BZ2_SHARED_LIBADD) + AC_DEFINE(HAVE_BZ2,1,[ ]) + ], [ + AC_MSG_ERROR(bz2 module requires libbz2 >= 1.0.0) + ], [ + -L$BZIP_DIR/$PHP_LIBDIR + ]) + + PHP_NEW_EXTENSION(bz2, bz2.c bz2_filter.c, $ext_shared) + PHP_SUBST(BZ2_SHARED_LIBADD) +fi diff --git a/ext/bz2/config.w32 b/ext/bz2/config.w32 new file mode 100644 index 0000000..ae30c84 --- /dev/null +++ b/ext/bz2/config.w32 @@ -0,0 +1,18 @@ +// $Id$ +// vim:ft=javascript + +ARG_WITH("bz2", "BZip2", "no"); + +if (PHP_BZ2 != "no") { + if (CHECK_LIB("libbz2_a.lib;libbz2.lib", "bz2", PHP_BZ2) && + CHECK_HEADER_ADD_INCLUDE("bzlib.h", "CFLAGS_BZ2")) { + EXTENSION("bz2", "bz2.c bz2_filter.c"); + AC_DEFINE('HAVE_BZ2', 1, 'Have BZ2 library'); + // BZ2 extension does this slightly differently from others + if (PHP_BZ2_SHARED) { + ADD_FLAG("CFLAGS_BZ2", "/D PHP_BZ2_EXPORTS "); + } + } else { + WARNING("bz2 not enabled; libraries and headers not found"); + } +} diff --git a/ext/bz2/package.xml b/ext/bz2/package.xml new file mode 100644 index 0000000..107f218 --- /dev/null +++ b/ext/bz2/package.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="ISO-8859-1" ?> +<!-- do not use the "Type" attribute here, that one is only for + generated package.xml files --> +<package> + <name>bz2</name> + <summary>A Bzip2 management extension</summary> + <description> +Bz2 is an extension to create and parse bzip2 compressed data. + </description> + <license>PHP License</license> + <maintainers> + <maintainer> + <user>sterling</user> + <name>Sterling Hughes</name> + <email>sterling@php.net</email> + </maintainer> + </maintainers> + <release> + <version>1.0</version> + <date>2003-05-17</date> + <state>stable</state> + <notes> + Initial Release in PECL + </notes> + </release> + <configureoptions> + <configureoption name="with-bz2" default="autodetect" prompt="path to bz2 installation?"/> + </configureoptions> + <filelist> + <dir role="src" name="/"> + <file role="doc">CREDITS</file> + <file role="src">config.m4</file> + <file role="doc">php_bz2.h</file> + <file role="src">bz2.c</file> + <file role="src">bz2.dsp</file> + </dir> + </filelist> +</package> diff --git a/ext/bz2/php_bz2.def b/ext/bz2/php_bz2.def new file mode 100644 index 0000000..8313553 --- /dev/null +++ b/ext/bz2/php_bz2.def @@ -0,0 +1,7 @@ +EXPORTS + BZ2_bzCompressInit + BZ2_bzCompress + BZ2_bzCompressEnd + BZ2_bzDecompressInit + BZ2_bzDecompress + BZ2_bzDecompressEnd diff --git a/ext/bz2/php_bz2.h b/ext/bz2/php_bz2.h new file mode 100644 index 0000000..8b12eca --- /dev/null +++ b/ext/bz2/php_bz2.h @@ -0,0 +1,74 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 5 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2013 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Sterling Hughes <sterling@php.net> | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_BZ2_H +#define PHP_BZ2_H + +#if HAVE_BZ2 + +extern zend_module_entry bz2_module_entry; +#define phpext_bz2_ptr &bz2_module_entry + +/* Bzip2 includes */ +#include <bzlib.h> + +#else +#define phpext_bz2_ptr NULL +#endif + +#ifdef PHP_WIN32 +# ifdef PHP_BZ2_EXPORTS +# define PHP_BZ2_API __declspec(dllexport) +# elif defined(COMPILE_DL_BZ2) +# define PHP_BZ2_API __declspec(dllimport) +# else +# define PHP_BZ2_API /* nothing special */ +# endif +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHP_BZ2_API __attribute__ ((visibility("default"))) +#else +# define PHP_BZ2_API +#endif + +PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC); +PHP_BZ2_API php_stream *_php_stream_bz2open_from_BZFILE(BZFILE *bz, char *mode, php_stream *innerstream STREAMS_DC TSRMLS_DC); + +#define php_stream_bz2open_from_BZFILE(bz, mode, innerstream) _php_stream_bz2open_from_BZFILE((bz), (mode), (innerstream) STREAMS_CC TSRMLS_CC) +#define php_stream_bz2open(wrapper, path, mode, options, opened_path) _php_stream_bz2open((wrapper), (path), (mode), (options), (opened_path), NULL STREAMS_CC TSRMLS_CC) + +extern php_stream_filter_factory php_bz2_filter_factory; +extern php_stream_ops php_stream_bz2io_ops; +#define PHP_STREAM_IS_BZIP2 &php_stream_bz2io_ops + +/* 400kb */ +#define PHP_BZ2_FILTER_DEFAULT_BLOCKSIZE 4 + +/* BZ2 Internal Default */ +#define PHP_BZ2_FILTER_DEFAULT_WORKFACTOR 0 + +#endif + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + */ diff --git a/ext/bz2/tests/001.phpt b/ext/bz2/tests/001.phpt new file mode 100644 index 0000000..47dbfe8 --- /dev/null +++ b/ext/bz2/tests/001.phpt @@ -0,0 +1,43 @@ +--TEST-- +bzopen() and invalid parameters +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +var_dump(bzopen()); +var_dump(bzopen("", "")); +var_dump(bzopen("", "r")); +var_dump(bzopen("", "w")); +var_dump(bzopen("", "x")); +var_dump(bzopen("", "rw")); +var_dump(bzopen("no_such_file", "r")); + +$fp = fopen(__FILE__,"r"); +var_dump(bzopen($fp, "r")); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: bzopen() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +Warning: bzopen(): '' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d +bool(false) + +Warning: bzopen(): filename cannot be empty in %s on line %d +bool(false) + +Warning: bzopen(): filename cannot be empty in %s on line %d +bool(false) + +Warning: bzopen(): 'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d +bool(false) + +Warning: bzopen(): 'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d +bool(false) + +Warning: bzopen(no_such_file): failed to open stream: No such file or directory in %s on line %d +bool(false) +resource(%d) of type (stream) +Done diff --git a/ext/bz2/tests/002.phpt b/ext/bz2/tests/002.phpt new file mode 100644 index 0000000..c55e22d --- /dev/null +++ b/ext/bz2/tests/002.phpt @@ -0,0 +1,129 @@ +--TEST-- +bzopen() using fd opened in wrong mode +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +@unlink("bz_open_002.txt"); + +$fp = fopen("bz_open_002.txt", "w"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "r"); +var_dump(bzopen($fp, "r")); + +@unlink("bz_open_002.txt"); +$fp = fopen("bz_open_002.txt", "x"); +var_dump(bzopen($fp, "w")); + +@unlink("bz_open_002.txt"); +$fp = fopen("bz_open_002.txt", "x"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "rb"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "wb"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "br"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "br"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "r"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "w"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "rw"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "rw"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "wr"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "wr"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "r+"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "r+"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "w+"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "w+"); +var_dump(bzopen($fp, "w")); + +$fp = fopen("bz_open_002.txt", "a"); +var_dump(bzopen($fp, "r")); + +$fp = fopen("bz_open_002.txt", "a"); +var_dump(bzopen($fp, "w")); + +@unlink("bz_open_002.txt"); + +echo "Done\n"; +?> +--EXPECTF-- +resource(%d) of type (stream) +resource(%d) of type (stream) +resource(%d) of type (stream) + +Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d +bool(false) +resource(%d) of type (stream) +resource(%d) of type (stream) + +Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d + +Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d +bool(false) + +Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d + +Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d +bool(false) + +Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d +bool(false) + +Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'rw' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'rw' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'wr' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'wr' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'r+' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'r+' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'w+' in %s on line %d +bool(false) + +Warning: bzopen(): cannot use stream opened in mode 'w+' in %s on line %d +bool(false) + +Warning: bzopen(): cannot read from a stream opened in write only mode in %s on line %d +bool(false) +resource(%d) of type (stream) +Done diff --git a/ext/bz2/tests/003.phpt b/ext/bz2/tests/003.phpt new file mode 100644 index 0000000..1432600 --- /dev/null +++ b/ext/bz2/tests/003.phpt @@ -0,0 +1,40 @@ +--TEST-- +bzread() tests +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +$fd = bzopen(dirname(__FILE__)."/003.txt.bz2","r"); +var_dump(bzread()); +var_dump(bzread($fd, 1 ,0)); +var_dump(bzread($fd, 0)); +var_dump(bzread($fd, -10)); +var_dump(bzread($fd, 1)); +var_dump(bzread($fd, 2)); +var_dump(bzread($fd, 100000)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: bzread() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: bzread() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +string(0) "" + +Warning: bzread(): length may not be negative in %s on line %d +bool(false) +string(1) "R" +string(2) "is" +string(251) "ing up from the heart of the desert +Rising up for Jerusalem +Rising up from the heat of the desert +Building up Old Jerusalem +Rising up from the heart of the desert +Rising up for Jerusalem +Rising up from the heat of the desert +Heading out for Jerusalem +" +Done diff --git a/ext/bz2/tests/003.txt.bz2 b/ext/bz2/tests/003.txt.bz2 Binary files differnew file mode 100644 index 0000000..034cd4d --- /dev/null +++ b/ext/bz2/tests/003.txt.bz2 diff --git a/ext/bz2/tests/004.phpt b/ext/bz2/tests/004.phpt new file mode 100644 index 0000000..a638188 --- /dev/null +++ b/ext/bz2/tests/004.phpt @@ -0,0 +1,111 @@ +--TEST-- +bzread() tests with invalid files +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +$fd = bzopen(dirname(__FILE__)."/004_1.txt.bz2","r"); +var_dump(bzerror($fd)); +var_dump(bzerrstr($fd)); +var_dump(bzerrno($fd)); + +$fd2 = bzopen(dirname(__FILE__)."/004_2.txt.bz2","r"); +var_dump(bzerror($fd2)); +var_dump(bzerrstr($fd2)); +var_dump(bzerrno($fd2)); + +var_dump(bzread($fd, 10)); +var_dump(bzerror($fd)); +var_dump(bzerrstr($fd)); +var_dump(bzerrno($fd)); + +var_dump(bzread($fd2, 10)); +var_dump(bzerror($fd2)); +var_dump(bzerrstr($fd2)); +var_dump(bzerrno($fd2)); + +var_dump(bzread($fd)); +var_dump(bzerror($fd)); +var_dump(bzerrstr($fd)); +var_dump(bzerrno($fd)); + +var_dump(bzread($fd2)); +var_dump(bzerror($fd2)); +var_dump(bzerrstr($fd2)); +var_dump(bzerrno($fd2)); + +bzclose($fd2); +var_dump(bzread($fd2)); +var_dump(bzerror($fd2)); +var_dump(bzerrstr($fd2)); +var_dump(bzerrno($fd2)); + +echo "Done\n"; +?> +--EXPECTF-- +array(2) { + ["errno"]=> + int(0) + ["errstr"]=> + string(2) "OK" +} +string(2) "OK" +int(0) +array(2) { + ["errno"]=> + int(0) + ["errstr"]=> + string(2) "OK" +} +string(2) "OK" +int(0) +string(0) "" +array(2) { + ["errno"]=> + int(-5) + ["errstr"]=> + string(16) "DATA_ERROR_MAGIC" +} +string(16) "DATA_ERROR_MAGIC" +int(-5) +string(0) "" +array(2) { + ["errno"]=> + int(-4) + ["errstr"]=> + string(10) "DATA_ERROR" +} +string(10) "DATA_ERROR" +int(-4) +string(0) "" +array(2) { + ["errno"]=> + int(-5) + ["errstr"]=> + string(16) "DATA_ERROR_MAGIC" +} +string(16) "DATA_ERROR_MAGIC" +int(-5) +string(0) "" +array(2) { + ["errno"]=> + int(-4) + ["errstr"]=> + string(10) "DATA_ERROR" +} +string(10) "DATA_ERROR" +int(-4) + +Warning: bzread(): %d is not a valid stream resource in %s on line %d +bool(false) + +Warning: bzerror(): %d is not a valid stream resource in %s on line %d +bool(false) + +Warning: bzerrstr(): %d is not a valid stream resource in %s on line %d +bool(false) + +Warning: bzerrno(): %d is not a valid stream resource in %s on line %d +bool(false) +Done diff --git a/ext/bz2/tests/004_1.txt.bz2 b/ext/bz2/tests/004_1.txt.bz2 Binary files differnew file mode 100644 index 0000000..6a5067b --- /dev/null +++ b/ext/bz2/tests/004_1.txt.bz2 diff --git a/ext/bz2/tests/004_2.txt.bz2 b/ext/bz2/tests/004_2.txt.bz2 Binary files differnew file mode 100644 index 0000000..9c19f04 --- /dev/null +++ b/ext/bz2/tests/004_2.txt.bz2 diff --git a/ext/bz2/tests/005.phpt b/ext/bz2/tests/005.phpt new file mode 100644 index 0000000..da29a6d --- /dev/null +++ b/ext/bz2/tests/005.phpt @@ -0,0 +1,71 @@ +--TEST-- +bzcompress()/bzdecompress() tests +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +$string = "Life it seems, will fade away +Drifting further everyday +Getting lost within myself +Nothing matters no one else"; + +var_dump(bzcompress()); +var_dump(bzcompress(1,1,1)); +var_dump(bzcompress($string, 100)); +var_dump(bzcompress($string, 100, -1)); +var_dump(bzcompress($string, 100, 1000)); +var_dump(bzcompress($string, -1, 1)); + +$data = bzcompress($string); +$data2 = bzcompress($string, 1, 10); + +$data3 = $data2; +$data3{3} = 0; + +var_dump(bzdecompress()); +var_dump(bzdecompress(1,1,1)); +var_dump(bzdecompress(1,1)); +var_dump(bzdecompress($data3)); +var_dump(bzdecompress($data3,1)); + +var_dump(bzdecompress($data, -1)); +var_dump(bzdecompress($data, 0)); +var_dump(bzdecompress($data, 1000)); +var_dump(bzdecompress($data)); +var_dump(bzdecompress($data2)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: bzcompress() expects at least 1 parameter, 0 given in %s on line %d +NULL +string(%d) "BZ%a" +int(-2) +int(-2) +int(-2) +int(-2) + +Warning: bzdecompress() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: bzdecompress() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +int(-5) +int(-5) +int(-5) +bool(false) +string(110) "Life it seems, will fade away +Drifting further everyday +Getting lost within myself +Nothing matters no one else" +bool(false) +string(110) "Life it seems, will fade away +Drifting further everyday +Getting lost within myself +Nothing matters no one else" +string(110) "Life it seems, will fade away +Drifting further everyday +Getting lost within myself +Nothing matters no one else" +Done diff --git a/ext/bz2/tests/bug51997.phpt b/ext/bz2/tests/bug51997.phpt new file mode 100644 index 0000000..fea5398 --- /dev/null +++ b/ext/bz2/tests/bug51997.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #51997 (SEEK_CUR with 0 value, returns a warning) +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php + +error_reporting(E_ALL); + +$filename = "testfile.bz2"; +$str = "This is a test string.\n"; +$bz = bzopen($filename, "w"); +bzwrite($bz, $str); +bzclose($bz); + +$bz = bzopen($filename, "r"); +fseek($bz, 0, SEEK_CUR); +print bzread($bz, 10); +print bzread($bz); +bzclose($bz); +unlink($filename); + +--EXPECT-- +This is a test string. diff --git a/ext/bz2/tests/bz2_filter_compress.phpt b/ext/bz2/tests/bz2_filter_compress.phpt new file mode 100644 index 0000000..3de9a9d --- /dev/null +++ b/ext/bz2/tests/bz2_filter_compress.phpt @@ -0,0 +1,17 @@ +--TEST-- +bzip2.compress (with convert.base64-encode) +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php /* $Id$ */ +$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.'; + +$fp = fopen('php://stdout', 'w'); +stream_filter_append($fp, 'bzip2.compress', STREAM_FILTER_WRITE); +stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE); +fwrite($fp, $text); +fclose($fp); + +?> +--EXPECT-- +QlpoNDFBWSZTWRN6QG0AAAoVgECFACA395UgIABIintI1N6mpowIQ0E1MTTAQGYTNcRyMZm5kgW3ib7hVboE7Tmqj3ToGZ5G3q1ZauD2G58hibSck8KS95EEAbx1Cn+LuSKcKEgJvSA2gA== diff --git a/ext/bz2/tests/bz2_filter_decompress.phpt b/ext/bz2/tests/bz2_filter_decompress.phpt new file mode 100644 index 0000000..951d572 --- /dev/null +++ b/ext/bz2/tests/bz2_filter_decompress.phpt @@ -0,0 +1,17 @@ +--TEST-- +bzip2.decompress (with convert.base64-decode) +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php /* $Id$ */ +$text = 'QlpoNDFBWSZTWRN6QG0AAAoVgECFACA395UgIABIintI1N6mpowIQ0E1MTTAQGYTNcRyMZm5kgW3ib7hVboE7Tmqj3ToGZ5G3q1ZauD2G58hibSck8KS95EEAbx1Cn+LuSKcKEgJvSA2gA=='; + +$fp = fopen('php://stdout', 'w'); +stream_filter_append($fp, 'convert.base64-decode', STREAM_FILTER_WRITE); +stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_WRITE); +fwrite($fp, $text); +fclose($fp); + +?> +--EXPECT-- +I am the very model of a modern major general, I've information vegetable, animal, and mineral. diff --git a/ext/bz2/tests/with_files.phpt b/ext/bz2/tests/with_files.phpt new file mode 100644 index 0000000..5691445 --- /dev/null +++ b/ext/bz2/tests/with_files.phpt @@ -0,0 +1,23 @@ +--TEST-- +BZ2 with files +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php // $Id$ + +error_reporting(E_ALL); + +$filename = "testfile.bz2"; +$str = "This is a test string.\n"; +$bz = bzopen($filename, "w"); +bzwrite($bz, $str); +bzclose($bz); + +$bz = bzopen($filename, "r"); +print bzread($bz, 10); +print bzread($bz); +bzclose($bz); +unlink($filename); + +--EXPECT-- +This is a test string. diff --git a/ext/bz2/tests/with_strings.phpt b/ext/bz2/tests/with_strings.phpt new file mode 100644 index 0000000..adf07e1 --- /dev/null +++ b/ext/bz2/tests/with_strings.phpt @@ -0,0 +1,27 @@ +--TEST-- +BZ2 with strings +--SKIPIF-- +<?php if (!extension_loaded("bz2")) print "skip"; ?> +--FILE-- +<?php // $Id$ + +error_reporting(E_ALL); + +# This FAILS +$blaat = <<<HEREDOC +This is some random data +HEREDOC; + +# This Works: (so, is heredoc related) +#$blaat= 'This is some random data'; + +$blaat2 = bzdecompress(bzcompress($blaat)); + +$tests = <<<TESTS + \$blaat === \$blaat2 +TESTS; + +include(dirname(__FILE__) . '/../../../tests/quicktester.inc'); + +--EXPECT-- +OK |