X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_filter_api.c;h=23b71190acebb730a3d5002b734d4f108299e9ed;hp=f7e99ec3a12c13bd488bc13468a62e55c37c1f5a;hb=ad5f896b03adaa073134a00108a9cdf00720673a;hpb=32e91737086db53bb1fd9ed9f79d693c43ec459f diff --git a/http_filter_api.c b/http_filter_api.c index f7e99ec..23b7119 100644 --- a/http_filter_api.c +++ b/http_filter_api.c @@ -6,16 +6,12 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2006, Michael Wallner | + | Copyright (c) 2004-2010, Michael Wallner | +--------------------------------------------------------------------+ */ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - #define HTTP_WANT_ZLIB #include "php_http.h" @@ -78,7 +74,7 @@ PHP_MINIT_FUNCTION(http_filter) php_stream_bucket_append(buckets_out, __buck TSRMLS_CC); \ } -typedef struct { +typedef struct _http_chunked_decode_filter_buffer_t { phpstr buffer; ulong hexlen; } HTTP_FILTER_BUFFER(chunked_decode); @@ -109,7 +105,7 @@ static HTTP_FILTER_FUNCTION(chunked_decode) *bytes_consumed += ptr->buflen; } - if ((size_t) -1 == phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen)) { + if (PHPSTR_NOMEM == phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen)) { return PSFS_ERR_FATAL; } @@ -169,8 +165,8 @@ static HTTP_FILTER_FUNCTION(chunked_decode) /* ignore preceeding CRLFs (too loose?) */ while (off < PHPSTR_LEN(buffer) && ( - PHPSTR_VAL(buffer)[off] == 0xa || - PHPSTR_VAL(buffer)[off] == 0xd)) { + PHPSTR_VAL(buffer)[off] == '\n' || + PHPSTR_VAL(buffer)[off] == '\r')) { ++off; } if (off) { @@ -317,8 +313,10 @@ static HTTP_FILTER_FUNCTION(deflate) if (ptr->buflen) { http_encoding_deflate_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len); if (encoded) { - out_avail = 1; - NEW_BUCKET(encoded, encoded_len); + if (encoded_len) { + out_avail = 1; + NEW_BUCKET(encoded, encoded_len); + } efree(encoded); } } @@ -335,8 +333,10 @@ static HTTP_FILTER_FUNCTION(deflate) http_encoding_deflate_stream_flush(buffer, &encoded, &encoded_len); if (encoded) { - out_avail = 1; - NEW_BUCKET(encoded, encoded_len); + if (encoded_len) { + out_avail = 1; + NEW_BUCKET(encoded, encoded_len); + } efree(encoded); } } @@ -347,8 +347,10 @@ static HTTP_FILTER_FUNCTION(deflate) http_encoding_deflate_stream_finish(buffer, &encoded, &encoded_len); if (encoded) { - out_avail = 1; - NEW_BUCKET(encoded, encoded_len); + if (encoded_len) { + out_avail = 1; + NEW_BUCKET(encoded, encoded_len); + } efree(encoded); } } @@ -382,8 +384,10 @@ static HTTP_FILTER_FUNCTION(inflate) if (ptr->buflen) { http_encoding_inflate_stream_update(buffer, ptr->buf, ptr->buflen, &decoded, &decoded_len); if (decoded) { - out_avail = 1; - NEW_BUCKET(decoded, decoded_len); + if (decoded_len) { + out_avail = 1; + NEW_BUCKET(decoded, decoded_len); + } efree(decoded); } } @@ -400,8 +404,10 @@ static HTTP_FILTER_FUNCTION(inflate) http_encoding_inflate_stream_flush(buffer, &decoded, &decoded_len); if (decoded) { - out_avail = 1; - NEW_BUCKET(decoded, decoded_len); + if (decoded_len) { + out_avail = 1; + NEW_BUCKET(decoded, decoded_len); + } efree(decoded); } } @@ -412,8 +418,10 @@ static HTTP_FILTER_FUNCTION(inflate) http_encoding_inflate_stream_finish(buffer, &decoded, &decoded_len); if (decoded) { - out_avail = 1; - NEW_BUCKET(decoded, decoded_len); + if (decoded_len) { + out_avail = 1; + NEW_BUCKET(decoded, decoded_len); + } efree(decoded); } } @@ -484,20 +492,18 @@ static php_stream_filter *http_filter_create(const char *name, zval *params, int HTTP_FILTER_BUFFER(deflate) *b = NULL; if (params) { - switch (Z_TYPE_P(params)) - { + switch (Z_TYPE_P(params)) { case IS_ARRAY: case IS_OBJECT: - if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void **) &tmp)) { + if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) { break; } default: { - zval *orig = *tmp; + zval *num = http_zsep(IS_LONG, *tmp); - convert_to_long_ex(tmp); - flags |= (Z_LVAL_PP(tmp) & 0x0fffffff); - if (orig != *tmp) zval_ptr_dtor(tmp); + flags |= (Z_LVAL_P(num) & 0x0fffffff); + zval_ptr_dtor(&num); } } }