-#define HTTP_DEFLATE_WBITS_SET(flags, wbits) \
- switch (flags & 0xf0) \
- { \
- case HTTP_DEFLATE_TYPE_GZIP: \
- wbits = HTTP_WINDOW_BITS_GZIP; \
- break; \
- case HTTP_DEFLATE_TYPE_RAW: \
- wbits = HTTP_WINDOW_BITS_RAW; \
- break; \
- default: \
- wbits = HTTP_WINDOW_BITS_ZLIB; \
- break; \
- }
-
-#define HTTP_INFLATE_WBITS_SET(flags, wbits) \
- if (flags & HTTP_INFLATE_TYPE_RAW) { \
- wbits = HTTP_WINDOW_BITS_RAW; \
- } else { \
- wbits = HTTP_WINDOW_BITS_ANY; \
- }
-
-#define HTTP_DEFLATE_STRATEGY_SET(flags, strategy) \
- switch (flags & 0xf00) \
- { \
- case HTTP_DEFLATE_STRATEGY_FILT: \
- strategy = Z_FILTERED; \
- break; \
- case HTTP_DEFLATE_STRATEGY_HUFF: \
- strategy = Z_HUFFMAN_ONLY; \
- break; \
- case HTTP_DEFLATE_STRATEGY_RLE: \
- strategy = Z_RLE; \
- break; \
- case HTTP_DEFLATE_STRATEGY_FIXED: \
- strategy = Z_FIXED; \
- break; \
- default: \
- strategy = Z_DEFAULT_STRATEGY; \
- break; \
+ *buf = NULL;
+ *len = 0;
+
+ phpstr_init_ex(&buffer, Z->avail_in, PHPSTR_INIT_PREALLOC);
+
+ do {
+ if (PHPSTR_NOMEM == phpstr_resize_ex(&buffer, buffer.size, 0, 1)) {
+ status = Z_MEM_ERROR;
+ } else {
+ Z->avail_out = buffer.free;
+ Z->next_out = (Bytef *) buffer.data + buffer.used;
+#if 0
+ fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ status = inflate(Z, flush);
+
+ buffer.used += buffer.free - Z->avail_out;
+ buffer.free = Z->avail_out;
+#if 0
+ fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
+#endif
+ HTTP_INFLATE_BUFFER_SIZE_ALIGN(buffer.size);
+ }
+ } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < HTTP_INFLATE_ROUNDS);
+
+ if (status == Z_OK || status == Z_STREAM_END) {
+ phpstr_shrink(&buffer);
+ phpstr_fix(&buffer);
+ *buf = buffer.data;
+ *len = buffer.used;
+ } else {
+ phpstr_dtor(&buffer);