diff options
author | Andi Gutmans <andi@php.net> | 1999-05-09 18:40:59 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 1999-05-09 18:40:59 +0000 |
commit | 4079f914bdad143193e05b2c93ffbbd9e75002ae (patch) | |
tree | c54fe0f50f8700590a78e1ef9c2afa090c5aa412 /main/SAPI.c | |
parent | 14a8e9b6c3206093f3637db8ad742e6437206897 (diff) | |
download | php-git-4079f914bdad143193e05b2c93ffbbd9e75002ae.tar.gz |
* Make read_post() read input by chunks instead of returning a single string.
This will allow us to efficiently support file upload through SAPI in the future.
* Fixes
Diffstat (limited to 'main/SAPI.c')
-rw-r--r-- | main/SAPI.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/main/SAPI.c b/main/SAPI.c index a5b9b21b9d..1649458b97 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -58,14 +58,43 @@ static void sapi_free_header(sapi_header_struct *sapi_header) } +#undef SAPI_POST_BLOCK_SIZE +#define SAPI_POST_BLOCK_SIZE 2 + +static void sapi_read_post_data(SLS_D) +{ + int read_bytes, total_read_bytes=0; + int allocated_bytes=SAPI_POST_BLOCK_SIZE+1; + + SG(request_info).post_data = emalloc(allocated_bytes); + + for (;;) { + read_bytes = sapi_module.read_post(SG(request_info).post_data+total_read_bytes, SAPI_POST_BLOCK_SIZE SLS_CC); + if (read_bytes<=0) { + break; + } + total_read_bytes += read_bytes; + if (read_bytes < SAPI_POST_BLOCK_SIZE) { + break; + } + if (total_read_bytes+SAPI_POST_BLOCK_SIZE >= allocated_bytes) { + allocated_bytes = total_read_bytes+SAPI_POST_BLOCK_SIZE+1; + SG(request_info).post_data = erealloc(SG(request_info).post_data, allocated_bytes); + } + } + SG(request_info).post_data[total_read_bytes] = 0; /* terminating NULL */ +} + + SAPI_API void sapi_activate(SLS_D) { zend_llist_init(&SG(sapi_headers).headers, sizeof(sapi_header_struct), (void (*)(void *)) sapi_free_header, 0); SG(sapi_headers).send_default_content_type = 1; SG(sapi_headers).http_response_code = 200; SG(headers_sent) = 0; + SG(read_post_bytes) = 0; if (SG(server_context)) { - SG(request_info).post_data = sapi_module.read_post(SLS_C); + sapi_read_post_data(SLS_C); SG(request_info).cookie_data = sapi_module.read_cookies(SLS_C); } } |