X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_encoding_api.c;h=d3529d14c15edb038d1e51eb41c31d99a5d1a895;hp=9475a176b86c47cf1ee653c581b1234faeb415af;hb=33b7c5dcd9cffebb8486cb57e04958e34bbfe662;hpb=a0bca521b491711e43aef74fe19c23a8eb4d0777 diff --git a/http_encoding_api.c b/http_encoding_api.c index 9475a17..d3529d1 100644 --- a/http_encoding_api.c +++ b/http_encoding_api.c @@ -15,17 +15,12 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "php.h" - -#include "php_http_encoding_api.h" #include "php_http.h" -#include "php_http_api.h" -#ifdef HTTP_HAVE_ZLIB -# include "php_http_send_api.h" -# include "php_http_headers_api.h" -# include -#endif +#include "php_http_api.h" +#include "php_http_encoding_api.h" +#include "php_http_send_api.h" +#include "php_http_headers_api.h" ZEND_EXTERN_MODULE_GLOBALS(http); @@ -79,6 +74,8 @@ PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t enco /* reached the end */ if (!chunk_len) { + /* move over '0' chunked encoding terminator */ + while (*e_ptr == '0') ++e_ptr; break; } @@ -402,11 +399,14 @@ PHP_HTTP_API STATUS _http_encoding_gzencode(int level, const char *data, size_t http_init_gzencode_buffer(&Z, data, data_len, encoded); - if ( (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) && - (Z_STREAM_END == (status = deflate(&Z, Z_FINISH))) && - (Z_OK == (status = deflateEnd(&Z)))) { - *encoded_len = http_finish_gzencode_buffer(&Z, data, data_len, encoded); - return SUCCESS; + if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) { + status = deflate(&Z, Z_FINISH); + deflateEnd(&Z); + + if (Z_STREAM_END == status) { + *encoded_len = http_finish_gzencode_buffer(&Z, data, data_len, encoded); + return SUCCESS; + } } efree(*encoded); @@ -421,11 +421,14 @@ PHP_HTTP_API STATUS _http_encoding_deflate(int level, const char *data, size_t d http_init_deflate_buffer(&Z, data, data_len, encoded); - if ( (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) && - (Z_STREAM_END == (status = deflate(&Z, Z_FINISH))) && - (Z_OK == (status = deflateEnd(&Z)))) { - *encoded_len = http_finish_buffer(Z.total_out, encoded); - return SUCCESS; + if (Z_OK == (status = deflateInit2(&Z, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY))) { + status = deflate(&Z, Z_FINISH); + deflateEnd(&Z); + + if (Z_STREAM_END == status) { + *encoded_len = http_finish_buffer(Z.total_out, encoded); + return SUCCESS; + } } efree(encoded); @@ -472,11 +475,12 @@ PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, ch do { http_init_inflate_buffer(&Z, data, data_len, decoded, decoded_len, &max); if (Z_OK == (status = inflateInit2(&Z, -MAX_WBITS))) { - if (Z_STREAM_END == (status = inflate(&Z, Z_FINISH))) { - if (Z_OK == (status = inflateEnd(&Z))) { - *decoded_len = http_finish_buffer(Z.total_out, decoded); - return SUCCESS; - } + status = inflate(&Z, Z_FINISH); + inflateEnd(&Z); + + if (Z_STREAM_END == status) { + *decoded_len = http_finish_buffer(Z.total_out, decoded); + return SUCCESS; } } } while (++max < HTTP_ENCODING_MAXTRY && status == Z_BUF_ERROR);