long bits;
unsigned char a[64];
unsigned long len=64, szlength;
- int factor=1,maxfactor=16;
- int slength, status=0;
- char *b, *buf=NULL, *bufz=NULL;
+ int factor = 1,maxfactor = 16;
+ int status = 0;
+ char *b, *buf = NULL;
+ zend_string *bufz;
- b = ecalloc (1, len + 1);
+ b = ecalloc(1, len + 1);
if (php_stream_seek(stream, 5, SEEK_CUR))
return NULL;
if (php_stream_seek(stream, 8, SEEK_SET))
return NULL;
- slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0);
+ bufz = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0);
/*
* zlib::uncompress() wants to know the output data length
*/
do {
- szlength=slength*(1<<factor++);
- buf = (char *) erealloc(buf,szlength);
- status = uncompress(buf, &szlength, bufz, slength);
+ szlength = bufz->len * (1<<factor++);
+ buf = (char *) erealloc(buf, szlength);
+ status = uncompress(buf, &szlength, bufz->val, bufz->len);
} while ((status==Z_BUF_ERROR)&&(factor<maxfactor));
if (bufz) {
- pefree(bufz, 0);
+ STR_RELEASE(bufz);
}
if (status == Z_OK) {
/* {{{ php_zlib_output_encoding() */
static int php_zlib_output_encoding(TSRMLS_D)
{
- zval **enc;
+ zval *enc;
if (!ZLIBG(compression_coding)) {
- zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
- if (PG(http_globals)[TRACK_VARS_SERVER] && SUCCESS == zend_hash_find(Z_ARRVAL_P(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING"), (void *) &enc)) {
- convert_to_string(*enc);
- if (strstr(Z_STRVAL_PP(enc), "gzip")) {
+ zend_string *name = STR_INIT("_SERVER", sizeof("_SERVER") - 1, 0);
+ zend_is_auto_global(name TSRMLS_CC);
+ STR_RELEASE(name);
+ if (Z_TYPE(PG(http_globals)[TRACK_VARS_SERVER]) == IS_ARRAY &&
+ (enc = zend_hash_str_find(Z_ARRVAL(PG(http_globals)[TRACK_VARS_SERVER]), "HTTP_ACCEPT_ENCODING", sizeof("HTTP_ACCEPT_ENCODING") - 1))) {
+ convert_to_string(enc);
+ if (strstr(Z_STRVAL_P(enc), "gzip")) {
ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_GZIP;
- } else if (strstr(Z_STRVAL_PP(enc), "deflate")) {
+ } else if (strstr(Z_STRVAL_P(enc), "deflate")) {
ZLIBG(compression_coding) = PHP_ZLIB_ENCODING_DEFLATE;
}
}
/* {{{ php_zlib_output_compression_start() */
static void php_zlib_output_compression_start(TSRMLS_D)
{
- zval *zoh;
+ zval zoh;
php_output_handler *h;
switch (ZLIBG(output_compression)) {
(h = php_zlib_output_handler_init(ZEND_STRL(PHP_ZLIB_OUTPUT_HANDLER_NAME), ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC)) &&
(SUCCESS == php_output_handler_start(h TSRMLS_CC))) {
if (ZLIBG(output_handler) && *ZLIBG(output_handler)) {
- MAKE_STD_ZVAL(zoh);
- ZVAL_STRING(zoh, ZLIBG(output_handler), 1);
- php_output_start_user(zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
+ ZVAL_STRING(&zoh, ZLIBG(output_handler));
+ php_output_start_user(&zoh, ZLIBG(output_compression), PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
zval_ptr_dtor(&zoh);
}
}
/* }}} */
/* {{{ php_zlib_encode() */
-static int php_zlib_encode(const char *in_buf, size_t in_len, char **out_buf, size_t *out_len, int encoding, int level TSRMLS_DC)
+static zend_string *php_zlib_encode(const char *in_buf, size_t in_len, int encoding, int level TSRMLS_DC)
{
int status;
z_stream Z;
+ zend_string *out;
memset(&Z, 0, sizeof(z_stream));
Z.zalloc = php_zlib_alloc;
Z.zfree = php_zlib_free;
if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, encoding, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) {
- *out_len = PHP_ZLIB_BUFFER_SIZE_GUESS(in_len);
- *out_buf = emalloc(*out_len);
+ out = STR_ALLOC(PHP_ZLIB_BUFFER_SIZE_GUESS(in_len), 0);
Z.next_in = (Bytef *) in_buf;
- Z.next_out = (Bytef *) *out_buf;
+ Z.next_out = (Bytef *) out->val;
Z.avail_in = in_len;
- Z.avail_out = *out_len;
+ Z.avail_out = out->len;
status = deflate(&Z, Z_FINISH);
deflateEnd(&Z);
if (Z_STREAM_END == status) {
/* size buffer down to actual length */
- *out_buf = erealloc(*out_buf, Z.total_out + 1);
- (*out_buf)[*out_len = Z.total_out] = '\0';
- return SUCCESS;
+ out = STR_REALLOC(out, Z.total_out, 0);
+ out->val[out->len] = '\0';
+ return out;
} else {
- efree(*out_buf);
+ STR_FREE(out);
}
}
- *out_buf = NULL;
- *out_len = 0;
-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", zError(status));
- return FAILURE;
+ return NULL;
}
/* }}} */
}
if (ctx.out.data) {
- RETVAL_STRINGL(ctx.out.data, ctx.out.used, 1);
+ RETVAL_STRINGL(ctx.out.data, ctx.out.used);
if (ctx.out.free) {
efree(ctx.out.data);
}
}
switch (ZLIBG(compression_coding)) {
case PHP_ZLIB_ENCODING_GZIP:
- RETURN_STRINGL("gzip", sizeof("gzip") - 1, 1);
+ RETURN_STRINGL("gzip", sizeof("gzip") - 1);
case PHP_ZLIB_ENCODING_DEFLATE:
- RETURN_STRINGL("deflate", sizeof("deflate") - 1, 1);
+ RETURN_STRINGL("deflate", sizeof("deflate") - 1);
default:
RETURN_FALSE;
}
#define PHP_ZLIB_ENCODE_FUNC(name, default_encoding) \
static PHP_FUNCTION(name) \
{ \
- char *in_buf, *out_buf; \
- int in_len; \
- size_t out_len; \
+ zend_string *in, *out; \
long level = -1; \
long encoding = default_encoding; \
if (default_encoding) { \
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &in_buf, &in_len, &level, &encoding)) { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ll", &in, &level, &encoding)) { \
return; \
} \
} else { \
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl|l", &in_buf, &in_len, &encoding, &level)) { \
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Sl|l", &in, &encoding, &level)) { \
return; \
} \
} \
php_error_docref(NULL TSRMLS_CC, E_WARNING, "encoding mode must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); \
RETURN_FALSE; \
} \
- if (SUCCESS != php_zlib_encode(in_buf, in_len, &out_buf, &out_len, encoding, level TSRMLS_CC)) { \
+ if ((out = php_zlib_encode(in->val, in->len, encoding, level TSRMLS_CC)) == NULL) { \
RETURN_FALSE; \
} \
- RETURN_STRINGL(out_buf, out_len, 0); \
+ RETURN_STR(out); \
}
#define PHP_ZLIB_DECODE_FUNC(name, encoding) \
if (SUCCESS != php_zlib_decode(in_buf, in_len, &out_buf, &out_len, encoding, max_len TSRMLS_CC)) { \
RETURN_FALSE; \
} \
- RETURN_STRINGL(out_buf, out_len, 0); \
+ RETVAL_STRINGL(out_buf, out_len); \
+ efree(out_buf); \
}
/* {{{ proto binary zlib_encode(binary data, int encoding[, int level = -1])
int status;
php_stream_filter_status_t exit_status = PSFS_FEED_ME;
- if (!thisfilter || !thisfilter->abstract) {
+ if (!thisfilter || !Z_PTR(thisfilter->abstract)) {
/* Should never happen */
return PSFS_ERR_FATAL;
}
- data = (php_zlib_filter_data *)(thisfilter->abstract);
+ data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract));
while (buckets_in->head) {
size_t bin = 0, desired;
static void php_zlib_inflate_dtor(php_stream_filter *thisfilter TSRMLS_DC)
{
- if (thisfilter && thisfilter->abstract) {
- php_zlib_filter_data *data = thisfilter->abstract;
+ if (thisfilter && Z_PTR(thisfilter->abstract)) {
+ php_zlib_filter_data *data = Z_PTR(thisfilter->abstract);
if (!data->finished) {
inflateEnd(&(data->strm));
}
int status;
php_stream_filter_status_t exit_status = PSFS_FEED_ME;
- if (!thisfilter || !thisfilter->abstract) {
+ if (!thisfilter || !Z_PTR(thisfilter->abstract)) {
/* Should never happen */
return PSFS_ERR_FATAL;
}
- data = (php_zlib_filter_data *)(thisfilter->abstract);
+ data = (php_zlib_filter_data *)(Z_PTR(thisfilter->abstract));
while (buckets_in->head) {
size_t bin = 0, desired;
static void php_zlib_deflate_dtor(php_stream_filter *thisfilter TSRMLS_DC)
{
- if (thisfilter && thisfilter->abstract) {
- php_zlib_filter_data *data = thisfilter->abstract;
+ if (thisfilter && Z_PTR(thisfilter->abstract)) {
+ php_zlib_filter_data *data = Z_PTR(thisfilter->abstract);
deflateEnd(&(data->strm));
pefree(data->inbuf, data->persistent);
pefree(data->outbuf, data->persistent);
int windowBits = -MAX_WBITS;
if (filterparams) {
- zval **tmpzval;
+ zval *tmpzval;
if ((Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) &&
- zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void **) &tmpzval) == SUCCESS) {
+ (tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) {
zval tmp;
/* log-2 base of history window (9 - 15) */
- tmp = **tmpzval;
- zval_copy_ctor(&tmp);
+ ZVAL_DUP(&tmp, tmpzval);
convert_to_long(&tmp);
if (Z_LVAL(tmp) < -MAX_WBITS || Z_LVAL(tmp) > MAX_WBITS + 32) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter give for window size. (%ld)", Z_LVAL(tmp));
if (filterparams) {
- zval **tmpzval, tmp;
+ zval *tmpzval, tmp;
/* filterparams can either be a scalar value to indicate compression level (shortcut method)
Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */
switch (Z_TYPE_P(filterparams)) {
case IS_ARRAY:
case IS_OBJECT:
- if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) {
- tmp = **tmpzval;
- zval_copy_ctor(&tmp);
+ if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "memory", sizeof("memory") -1))) {
+ ZVAL_DUP(&tmp, tmpzval);
convert_to_long(&tmp);
/* Memory Level (1 - 9) */
}
}
- if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) {
- tmp = **tmpzval;
- zval_copy_ctor(&tmp);
+ if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "window", sizeof("window") - 1))) {
+ ZVAL_DUP(&tmp, tmpzval);
convert_to_long(&tmp);
/* log-2 base of history window (9 - 15) */
}
}
- if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) {
- tmp = **tmpzval;
+ if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "level", sizeof("level") - 1))) {
+ ZVAL_COPY_VALUE(&tmp, tmpzval);
/* Psuedo pass through to catch level validating code */
goto factory_setlevel;
case IS_STRING:
case IS_DOUBLE:
case IS_LONG:
- tmp = *filterparams;
+ ZVAL_COPY_VALUE(&tmp, filterparams);
factory_setlevel:
zval_copy_ctor(&tmp);
convert_to_long(&tmp);