#define HTTP_WINDOW_BITS_ANY 0x0000002f
#define HTTP_WINDOW_BITS_RAW -0x000000f
-STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
{
int status, level, wbits, strategy;
z_stream Z;
return FAILURE;
}
-STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
{
int status, max = 0, wbits = HTTP_WINDOW_BITS_ANY;
z_stream Z;
}
-http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
+PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
{
int status, level, wbits, strategy, free_stream;
return NULL;
}
-http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
+PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC)
{
int status, wbits, free_stream;
return NULL;
}
-STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC)
{
int status;
return FAILURE;
}
-STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC)
{
int status, max = 0;
return FAILURE;
}
-STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC)
+{
+ int status;
+
+ s->stream.avail_in = 0;
+ s->stream.next_in = NULL;
+ s->stream.avail_out = *encoded_len = 0x800;
+ s->stream.next_out = *encoded = emalloc(*encoded_len);
+
+ switch (status = deflate(&s->stream, Z_SYNC_FLUSH))
+ {
+ case Z_OK:
+ case Z_STREAM_END:
+ *encoded_len = 0x800 - s->stream.avail_out;
+ *encoded = erealloc(*encoded, *encoded_len + 1);
+ (*encoded)[*encoded_len] = '\0';
+ return SUCCESS;
+ break;
+ }
+
+ STR_SET(*encoded, NULL);
+ *encoded_len = 0;
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to flush deflate stream: %s", zError(status));
+ return FAILURE;
+}
+
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC)
+{
+ int status;
+
+ s->stream.avail_in = 0;
+ s->stream.next_in = NULL;
+ s->stream.avail_out = *decoded_len = 0x800;
+ s->stream.next_out = *decoded = emalloc(*decoded_len);
+
+ switch (status = inflate(&s->stream, Z_SYNC_FLUSH))
+ {
+ case Z_OK:
+ case Z_STREAM_END:
+ *decoded_len = 0x800 - s->stream.avail_out;
+ *decoded = erealloc(*decoded, *decoded_len + 1);
+ (*decoded)[*decoded_len] = '\0';
+ return SUCCESS;
+ break;
+ }
+
+ STR_SET(*decoded, NULL);
+ *decoded_len = 0;
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to flush inflate stream: %s", zError(status));
+ return FAILURE;
+}
+
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC)
{
int status;
return FAILURE;
}
-STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC)
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC)
{
int status;
return FAILURE;
}
-void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
{
if (s) {
if (s->stream.opaque) {
}
}
-void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
{
if (s) {
if (s->stream.opaque) {
}
}
-void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
{
if (s) {
http_encoding_deflate_stream_dtor(*s);
}
}
-void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
+PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
{
if (s) {
http_encoding_inflate_stream_dtor(*s);
if (PHPSTR_LEN(buffer) < buffer->hexlen) {
/* flush anyway? */
- if (flags == PSFS_FLAG_FLUSH_INC) {
+ if (flags & PSFS_FLAG_FLUSH_INC) {
/* flush all data (should only be chunk data) */
out_avail = 1;
}
/* flush before close, but only if we are already waiting for more data */
- if (flags == PSFS_FLAG_FLUSH_CLOSE && buffer->hexlen && PHPSTR_LEN(buffer)) {
+ if ((flags & PSFS_FLAG_FLUSH_CLOSE) && buffer->hexlen && PHPSTR_LEN(buffer)) {
out_avail = 1;
NEW_BUCKET(PHPSTR_VAL(buffer), PHPSTR_LEN(buffer));
phpstr_reset(PHPSTR(buffer));
}
/* terminate with "0" */
- if (flags == PSFS_FLAG_FLUSH_CLOSE) {
+ if (flags & PSFS_FLAG_FLUSH_CLOSE) {
out_avail = 1;
NEW_BUCKET("0" HTTP_CRLF, lenof("0" HTTP_CRLF));
}
}
/* flush & close */
- if (flags == PSFS_FLAG_FLUSH_CLOSE) {
+ if (flags & PSFS_FLAG_FLUSH_INC) {
+ char *encoded = NULL;
+ size_t encoded_len = 0;
+
+ http_encoding_deflate_stream_flush(buffer, &encoded, &encoded_len);
+ if (encoded) {
+ out_avail = 1;
+ NEW_BUCKET(encoded, encoded_len);
+ efree(encoded);
+ }
+ }
+
+ if (flags & PSFS_FLAG_FLUSH_CLOSE) {
char *encoded = NULL;
size_t encoded_len = 0;
}
/* flush & close */
- if (flags == PSFS_FLAG_FLUSH_CLOSE) {
+ if (flags & PSFS_FLAG_FLUSH_INC) {
+ char *decoded = NULL;
+ size_t decoded_len = 0;
+
+ http_encoding_inflate_stream_flush(buffer, &decoded, &decoded_len);
+ if (decoded) {
+ out_avail = 1;
+ NEW_BUCKET(decoded, decoded_len);
+ efree(decoded);
+ }
+ }
+
+ if (flags & PSFS_FLAG_FLUSH_CLOSE) {
char *decoded = NULL;
size_t decoded_len = 0;
extern PHP_MINIT_FUNCTION(http_encoding);
+/* 100% compression should be fairly good */
#define HTTP_ENCODING_MAXTRY 100
/* safe padding */
#define HTTP_ENCODING_SAFPAD 28
PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC);
#define http_encoding_deflate_stream_update(s, d, dl, e, el) _http_encoding_deflate_stream_update((s), (d), (dl), (e), (el) TSRMLS_CC)
PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len TSRMLS_DC);
+#define http_encoding_deflate_stream_flush(s, e, el) _http_encoding_deflate_stream_flush((s), (e), (el) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC);
#define http_encoding_deflate_stream_finish(s, e, el) _http_encoding_deflate_stream_finish((s), (e), (el) TSRMLS_CC)
PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len TSRMLS_DC);
#define http_encoding_deflate_stream_dtor(s) _http_encoding_deflate_stream_dtor((s) TSRMLS_CC)
PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags TSRMLS_DC);
#define http_encoding_inflate_stream_update(s, d, dl, e, el) _http_encoding_inflate_stream_update((s), (d), (dl), (e), (el) TSRMLS_CC)
PHP_HTTP_API STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len TSRMLS_DC);
+#define http_encoding_inflate_stream_flush(s, d, dl) _http_encoding_inflate_stream_flush((s), (d), (dl) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC);
#define http_encoding_inflate_stream_finish(s, e, el) _http_encoding_inflate_stream_finish((s), (e), (el) TSRMLS_CC)
PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len TSRMLS_DC);
#define http_encoding_inflate_stream_dtor(s) _http_encoding_inflate_stream_dtor((s) TSRMLS_CC)