X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_buffer.c;h=5a609be7337441b9e74b4f64e6a334cd29b18f1a;hp=7736259a78622a41827124f22d5792a4dd7d272c;hb=7b028d0cbb030f9610084314f67b77907d8474a2;hpb=8d05291f42b3b42159b3fe91492aa4862f3d4405 diff --git a/php_http_buffer.c b/php_http_buffer.c index 7736259..5a609be 100644 --- a/php_http_buffer.c +++ b/php_http_buffer.c @@ -10,7 +10,7 @@ +--------------------------------------------------------------------+ */ -#include "php.h" +#include #include "php_http_buffer.h" PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_init_ex(php_http_buffer_t *buf, size_t chunk_size, int flags) @@ -72,6 +72,19 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_resize_ex(php_http_buffer_t *buf, siz return 0; } +PHP_HTTP_BUFFER_API char *php_http_buffer_account(php_http_buffer_t *buf, size_t to_account) +{ + /* it's probably already too late but check anyway */ + if (to_account > buf->free) { + return NULL; + } + + buf->free -= to_account; + buf->used += to_account; + + return buf->data + buf->used; +} + PHP_HTTP_BUFFER_API size_t php_http_buffer_shrink(php_http_buffer_t *buf) { /* avoid another realloc on fixation */ @@ -356,7 +369,7 @@ PHP_HTTP_BUFFER_API size_t php_http_buffer_chunk_buffer(php_http_buffer_t **s, c return chunk_size; } - if (storage->used >= (chunk_size = storage->size >> 1)) { + if (storage->used >= chunk_size) { *chunk = estrndup(storage->data, chunk_size); php_http_buffer_cut(storage, 0, chunk_size); return chunk_size; @@ -369,7 +382,7 @@ PHP_HTTP_BUFFER_API void php_http_buffer_chunked_output(php_http_buffer_t **s, c { char *chunk = NULL; size_t got = 0; - + while ((got = php_http_buffer_chunk_buffer(s, data, data_len, &chunk, chunk_len))) { passout(opaque, chunk, got TSRMLS_CC); if (!chunk_len) { @@ -384,22 +397,22 @@ PHP_HTTP_BUFFER_API void php_http_buffer_chunked_output(php_http_buffer_t **s, c STR_FREE(chunk); } -PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t *s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC) +PHP_HTTP_BUFFER_API ssize_t php_http_buffer_passthru(php_http_buffer_t **s, size_t chunk_size, php_http_buffer_pass_func_t passin, void *passin_arg, php_http_buffer_pass_func_t passon, void *passon_arg TSRMLS_DC) { - size_t passed_on = 0, passed_in = php_http_buffer_chunked_input(&s, chunk_size, passin, passin_arg TSRMLS_CC); + size_t passed_on = 0, passed_in = php_http_buffer_chunked_input(s, chunk_size, passin, passin_arg TSRMLS_CC); if (passed_in == PHP_HTTP_BUFFER_PASS0) { return passed_in; } - if (passed_in) { - passed_on = passon(passon_arg, s->data, passed_in TSRMLS_CC); + if (passed_in || (*s)->used) { + passed_on = passon(passon_arg, (*s)->data, (*s)->used TSRMLS_CC); if (passed_on == PHP_HTTP_BUFFER_PASS0) { return passed_on; } if (passed_on) { - php_http_buffer_cut(s, 0, passed_on); + php_http_buffer_cut(*s, 0, passed_on); } }