Z.avail_in = data_len;
do {
- phpstr_resize(&buffer, data_len << 2);
-
- do {
+ if (phpstr_resize_ex(&buffer, data_len << 2, 0, 1) == (size_t) -1) {
+ status = Z_MEM_ERROR;
+ } else do {
Z.avail_out = (buffer.free -= Z.total_out - buffer.used);
Z.next_out = (Bytef *) buffer.data + (buffer.used = Z.total_out);
status = inflate(&Z, Z_NO_FLUSH);
s->stream.avail_out = *encoded_len;
s->stream.next_out = (Bytef *) *encoded;
- switch (status = deflate(&s->stream, Z_NO_FLUSH))
+ switch (status = deflate(&s->stream, HTTP_ENCODING_STREAM_FLUSH_FLAG(s->flags)))
{
case Z_OK:
case Z_STREAM_END:
s->stream.next_out = (Bytef *) *decoded;
s->stream.avail_out = *decoded_len;
- switch (status = inflate(&s->stream, Z_NO_FLUSH))
+ switch (status = inflate(&s->stream, HTTP_ENCODING_STREAM_FLUSH_FLAG(s->flags)))
{
case Z_OK:
case Z_STREAM_END:
s->stream.avail_out = *encoded_len;
s->stream.next_out = (Bytef *) *encoded;
- switch (status = deflate(&s->stream, Z_SYNC_FLUSH))
+ switch (status = deflate(&s->stream, Z_FULL_FLUSH))
{
case Z_OK:
case Z_STREAM_END:
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
} else
if (!strcasecmp(name, "http.inflate")) {
- int flags = p ? HTTP_ENCODING_STREAM_PERSISTENT : 0;
+ int flags = HTTP_ENCODING_STREAM_FLUSH_SYNC | (p ? HTTP_ENCODING_STREAM_PERSISTENT : 0);
HTTP_FILTER_BUFFER(inflate) *b = NULL;
if ((b = http_encoding_inflate_stream_init(NULL, flags))) {
} else
if (!strcasecmp(name, "http.deflate")) {
- int flags = p ? HTTP_ENCODING_STREAM_PERSISTENT : 0;
+ int flags = HTTP_ENCODING_STREAM_FLUSH_SYNC | (p ? HTTP_ENCODING_STREAM_PERSISTENT : 0);
HTTP_FILTER_BUFFER(deflate) *b = NULL;
if (params) {
zval *orig = *tmp;
convert_to_long_ex(tmp);
- flags |= (Z_LVAL_PP(tmp) & 0x0fffffff);
+ flags |= (Z_LVAL_PP(tmp) & 0x00ffffff);
if (orig != *tmp) zval_ptr_dtor(tmp);
}
}
#define HTTP_INFLATE_TYPE_GZIP 0x00000000
#define HTTP_INFLATE_TYPE_RAW 0x00000001
+#define HTTP_ENCODING_STREAM_FLUSH_NONE 0x00000000
+#define HTTP_ENCODING_STREAM_FLUSH_SYNC 0x00100000
+#define HTTP_ENCODING_STREAM_FLUSH_FULL 0x00200000
+
+#define HTTP_ENCODING_STREAM_FLUSH_FLAG(f) ( \
+ (f) & HTTP_ENCODING_STREAM_FLUSH_FULL ? Z_FULL_FLUSH : \
+ (f) & HTTP_ENCODING_STREAM_FLUSH_SYNC ? Z_SYNC_FLUSH : \
+ Z_NO_FLUSH)
+
#define HTTP_ENCODING_STREAM_PERSISTENT 0x01000000
typedef struct _http_encoding_stream_t {
return buf;
}
-PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size)
+PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size, int allow_error)
{
#if 0
fprintf(stderr, "RESIZE: size=%lu, used=%lu, free=%lu\n", buf->size, buf->used, buf->free);
size *= 2;
}
if (buf->data) {
- char *ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem);
+ char *ptr;
+
+ if (allow_error) {
+ ptr = perealloc_recoverable(buf->data, buf->used + buf->free + size, buf->pmem);
+ } else {
+ ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem);
+ }
if (ptr) {
buf->data = ptr;
PHPSTR_API phpstr *phpstr_fix(phpstr *buf)
{
- if (NOMEM == phpstr_resize_ex(buf, 1, 1)) {
+ if (NOMEM == phpstr_resize_ex(buf, 1, 1, 0)) {
return NULL;
}
buf->data[buf->used] = '\0';
PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length);
/* usually only called from within the internal functions */
-#define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0)
-PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size);
+#define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0, 0)
+PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size, int allow_error);
/* shrink memory chunk to actually used size (+1) */
PHPSTR_API size_t phpstr_shrink(phpstr *buf);