[PHP4BETA] CVS update: php4

From: Date: Sun, 09 May 1999 18:40:59 +0000
Subject: [PHP4BETA] CVS update: php4
Groups: php.version4 
Request: Send a blank email to php-version4+get-731@lists.php.net to get a copy of this message
Date: Sunday May 9, 1999 @ 14:40 Author: andi Update of /repository/php4 In directory php:/tmp/cvs-serv14456 Modified Files: SAPI.c SAPI.h cgi_main.c Log Message: * 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 Index: php4/SAPI.c diff -u php4/SAPI.c:1.12 php4/SAPI.c:1.13 --- php4/SAPI.c:1.12 Sun May 9 04:47:48 1999 +++ php4/SAPI.c Sun May 9 14:40:59 1999 @@ -58,14 +58,43 @@ } +#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); } } Index: php4/SAPI.h diff -u php4/SAPI.h:1.11 php4/SAPI.h:1.12 --- php4/SAPI.h:1.11 Sun May 9 04:47:48 1999 +++ php4/SAPI.h Sun May 9 14:40:59 1999 @@ -4,6 +4,7 @@ #include "zend.h" #include "zend_llist.h" +#define SAPI_POST_BLOCK_SIZE 4000 #if WIN32||WINNT # ifdef SAPI_EXPORTS @@ -55,6 +56,7 @@ void *server_context; sapi_request_info request_info; sapi_headers_struct sapi_headers; + uint read_post_bytes; unsigned char headers_sent; } sapi_globals_struct; @@ -99,7 +101,7 @@ int (*send_headers)(sapi_headers_struct *sapi_headers SLS_DC); void (*send_header)(sapi_header_struct *sapi_header, void *server_context); - char *(*read_post)(SLS_D); + int (*read_post)(char *buffer, uint count_bytes SLS_DC); char *(*read_cookies)(SLS_D); }; Index: php4/cgi_main.c diff -u php4/cgi_main.c:1.9 php4/cgi_main.c:1.10 --- php4/cgi_main.c:1.9 Sun May 9 04:47:48 1999 +++ php4/cgi_main.c Sun May 9 14:40:59 1999 @@ -85,20 +85,19 @@ } -static char *sapi_cgi_read_post(SLS_D) +static int sapi_cgi_read_post(char *buffer, uint count_bytes SLS_DC) { uint read_bytes=0, tmp_read_bytes; - char *result = (char *) emalloc(SG(request_info).content_length+1); - while (read_bytes < SG(request_info).content_length) { - tmp_read_bytes = read(0, result+read_bytes, SG(request_info).content_length-read_bytes); + count_bytes = MIN(count_bytes, SG(request_info).content_length-SG(read_post_bytes)); + while (read_bytes < count_bytes) { + tmp_read_bytes = read(0, buffer+read_bytes, count_bytes-read_bytes); if (tmp_read_bytes<=0) { break; } read_bytes += tmp_read_bytes; } - result[read_bytes]=0; - return result; + return read_bytes; } -- PHP 4 Beta

« previous php.version4 (#731) next »