- release 0.18.0
[m6w6/ext-http] / http_filter_api.c
index 53877e2a3f08d3f4c281125009f856fc5813d46b..944bff241a8b7a31a06424b1ddc2dbe16eabb11f 100644 (file)
 
 #include "php_streams.h"
 
-/*
- * TODO: allow use with persistent streams
- */
-
 PHP_MINIT_FUNCTION(http_filter)
 {
        php_stream_filter_register_factory("http.*", &http_filter_factory TSRMLS_CC);
@@ -104,13 +100,17 @@ static HTTP_FILTER_FUNCTION(chunked_decode)
                                *bytes_consumed += ptr->buflen;
                        }
                
-                       phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen);
+                       if ((size_t) -1 == phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen)) {
+                               return PSFS_ERR_FATAL;
+                       }
+                       
                        php_stream_bucket_unlink(ptr TSRMLS_CC);
                        php_stream_bucket_delref(ptr TSRMLS_CC);
-                       
                }
        }
-       phpstr_fix(PHPSTR(buffer));
+       if (!phpstr_fix(PHPSTR(buffer))) {
+               return PSFS_ERR_FATAL;
+       }
 
        /* we have data in our buffer */
        while (PHPSTR_LEN(buffer)) {
@@ -175,7 +175,7 @@ static HTTP_FILTER_FUNCTION(chunked_decode)
                                
                                /* we need eol, so we can be sure we have all hex digits */
                                phpstr_fix(PHPSTR(buffer));
-                               if (eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen)) {
+                               if ((eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen))) {
                                        char *stop = NULL;
                                        
                                        /* read in chunk size */
@@ -191,6 +191,9 @@ static HTTP_FILTER_FUNCTION(chunked_decode)
                                        phpstr_cut(PHPSTR(buffer), 0, eolstr + eollen - PHPSTR_VAL(buffer));
                                        /* buffer->hexlen is 0 now or contains the size of the next chunk */
                                        /* continue */
+                               } else {
+                                       /* we have not enough data buffered to read in chunk size */
+                                       break;
                                }
                        }
                        /* break */
@@ -284,13 +287,8 @@ static php_stream_filter *http_filter_create(const char *name, zval *params, int
        if (!strcasecmp(name, "http.chunked_decode")) {
                http_filter_buffer *b = NULL;
                
-               /* FIXXME: allow usage with persistent streams */
-               if (p) {
-                       return NULL;
-               }
-               
-               if (b = pecalloc(1, sizeof(http_filter_buffer), p)) {
-                       phpstr_init(PHPSTR(b));
+               if ((b = pecalloc(1, sizeof(http_filter_buffer), p))) {
+                       phpstr_init_ex(PHPSTR(b), 4096, p ? PHPSTR_INIT_PERSISTENT : 0);
                        if (!(f = php_stream_filter_alloc(&HTTP_FILTER_OP(chunked_decode), b, p))) {
                                pefree(b, p);
                        }