- add flush() to HttpDeflateStream and HttpInflateStream
[m6w6/ext-http] / http_encoding_api.c
index f896be4ca8f57c701e5e7712f211934b0389e776..a31b5b79772cc0533c2af23274674cdb158db89d 100644 (file)
@@ -43,10 +43,12 @@ PHP_MINIT_FUNCTION(http_encoding)
 
 PHP_RINIT_FUNCTION(http_encoding)
 {
-       if (HTTP_G(send).inflate.start_auto) {
+       getGlobals(G);
+       
+       if (G->send.inflate.start_auto) {
                php_ob_set_internal_handler(_http_ob_inflatehandler, 0x1000, "http inflate", 0 TSRMLS_CC);
        }
-       if (HTTP_G(send).deflate.start_auto) {
+       if (G->send.deflate.start_auto) {
                php_ob_set_internal_handler(_http_ob_deflatehandler, 0x8000, "http deflate", 0 TSRMLS_CC);
        }
        return SUCCESS;
@@ -54,6 +56,8 @@ PHP_RINIT_FUNCTION(http_encoding)
 
 PHP_RSHUTDOWN_FUNCTION(http_encoding)
 {
+       getGlobals(G);
+       
        if (G->send.deflate.stream) {
                http_encoding_deflate_stream_free((http_encoding_stream **) &G->send.deflate.stream);
        }
@@ -388,7 +392,7 @@ PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s
                case Z_OK:
                case Z_STREAM_END:
                        /* cut processed chunk off the buffer */
-                       phpstr_cut(PHPSTR(s->stream.opaque), 0, data_len - s->stream.avail_in);
+                       phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
                        
                        /* size buffer down to actual size */
                        *encoded_len -= s->stream.avail_out;
@@ -432,7 +436,7 @@ retry_raw_inflate:
                        case Z_OK:
                        case Z_STREAM_END:
                                /* cut off */
-                               phpstr_cut(PHPSTR(s->stream.opaque), 0, data_len - s->stream.avail_in);
+                               phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
                                
                                /* size down */
                                *decoded_len -= s->stream.avail_out;
@@ -490,31 +494,9 @@ PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s,
 
 PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
 {
-       int status;
-       
-       *decoded_len = 0x800;
-       *decoded = emalloc_rel(*decoded_len);
-       
-       s->stream.avail_in = 0;
-       s->stream.next_in = NULL;
-       s->stream.avail_out = *decoded_len;
-       s->stream.next_out = (Bytef *) *decoded;
-       
-       switch (status = inflate(&s->stream, Z_SYNC_FLUSH))
-       {
-               case Z_OK:
-               case Z_STREAM_END:
-                       *decoded_len = 0x800 - s->stream.avail_out;
-                       *decoded = erealloc_rel(*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;
+       /* noop */
+       *decoded = estrndup("", *decoded_len = 0);
+       return SUCCESS;
 }
 
 PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
@@ -657,7 +639,7 @@ void _http_ob_deflatehandler(char *output, uint output_len, char **handled_outpu
                        break;
                }
                
-               flags |= (G->send.deflate.start_flags &~ 0xf);
+               flags |= (G->send.deflate.start_flags &~ 0xf0);
                G->send.deflate.stream = http_encoding_deflate_stream_init(NULL, flags);
        }
        
@@ -695,7 +677,7 @@ void _http_ob_inflatehandler(char *output, uint output_len, char **handled_outpu
                        zend_error(E_ERROR, "ob_inflatehandler() can only be used once");
                        return;
                }
-               G->send.inflate.stream = http_encoding_inflate_stream_init(NULL, (HTTP_G(send).inflate.start_flags &~ 0xf));
+               G->send.inflate.stream = http_encoding_inflate_stream_init(NULL, (HTTP_G(send).inflate.start_flags &~ 0xf0));
        }
        
        if (G->send.inflate.stream) {