]> granicus.if.org Git - php/commitdiff
* Make read_post() read input by chunks instead of returning a single string.
authorAndi Gutmans <andi@php.net>
Sun, 9 May 1999 18:40:59 +0000 (18:40 +0000)
committerAndi Gutmans <andi@php.net>
Sun, 9 May 1999 18:40:59 +0000 (18:40 +0000)
  This will allow us to efficiently support file upload through SAPI in the future.
* Fixes

cgi_main.c
ext/standard/basic_functions.c
ext/standard/post.c
main/SAPI.c
main/SAPI.h

index e34d0e7e37851f404f4bd71138c0ca0bad7ffd2e..6760dbfba9816bf5864a3ac6bf85e1be2de4d29b 100644 (file)
@@ -85,20 +85,19 @@ static void sapi_cgi_send_header(sapi_header_struct *sapi_header, void *server_c
 }
 
 
-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;
 }
 
 
index 471bb121fd2b00d12ba6dd88933df8e48db27aa0..0e0c2cb80e7ae055291921896d58a23dca1f0d68 100644 (file)
@@ -1809,11 +1809,11 @@ PHP_FUNCTION(register_shutdown_function)
 
 ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini)
 {
-       syntax_highlighter_ini->highlight_comment = INI_STR("highlight_comment");
-       syntax_highlighter_ini->highlight_default = INI_STR("highlight_default");
-       syntax_highlighter_ini->highlight_html = INI_STR("highlight_html");
-       syntax_highlighter_ini->highlight_keyword = INI_STR("highlight_keyword");
-       syntax_highlighter_ini->highlight_string = INI_STR("highlight_string");
+       syntax_highlighter_ini->highlight_comment = INI_STR("highlight.comment");
+       syntax_highlighter_ini->highlight_default = INI_STR("highlight.default");
+       syntax_highlighter_ini->highlight_html = INI_STR("highlight.html");
+       syntax_highlighter_ini->highlight_keyword = INI_STR("highlight.keyword");
+       syntax_highlighter_ini->highlight_string = INI_STR("highlight.string");
 }
 
 
index 7edcc70788d53ae17961fd7a345576c506bd4a8a..52260585d938d4bc0256e82919f98a9907282085 100644 (file)
@@ -320,6 +320,7 @@ void php3_treat_data(int arg, char *str)
 {
        char *res = NULL, *var, *val;
        pval *array_ptr;
+       int free_buffer;
        ELS_FETCH();
        PLS_FETCH();
        SLS_FETCH();
@@ -353,20 +354,28 @@ void php3_treat_data(int arg, char *str)
                        break;
        }
 
-       if (arg == PARSE_POST) {
+       if (arg == PARSE_POST) {                        /* POST data */
                res = php3_getpost(array_ptr PLS_CC);
-       } else if (arg == PARSE_GET) {          /* Get data */
+               free_buffer = 0;
+       } else if (arg == PARSE_GET) {          /* GET data */
                var = SG(request_info).query_string;
                if (var && *var) {
                        res = (char *) estrdup(var);
+                       free_buffer = 1;
+               } else {
+                       free_buffer = 0;
                }
        } else if (arg == PARSE_COOKIE) {               /* Cookie data */
                var = SG(request_info).cookie_data;
                if (var && *var) {
                        res = (char *) estrdup(var);
+                       free_buffer = 1;
+               } else {
+                       free_buffer = 0;
                }
        } else if (arg == PARSE_STRING) {               /* String data */
                res = str;
+               free_buffer = 1;
        }
        if (!res) {
                return;
@@ -397,7 +406,9 @@ void php3_treat_data(int arg, char *str)
                        var = strtok(NULL, PG(arg_separator));
                }
        }
-       efree(res);
+       if (free_buffer) {
+               efree(res);
+       }
 }
 
 
index a5b9b21b9d144dff4e27048a718f172a9a7bcfdf..1649458b97b1d5c2c4441bc6641c3d6e35432239 100644 (file)
@@ -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);
        }
 }
index 03bc4f7868633475bf69bed1cf4e88ec698fd795..0ea9b8d8c730d1a85e962ff8cd2676e58dcf4fba 100644 (file)
@@ -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 @@ typedef struct {
        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 @@ struct _sapi_module_struct {
        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);
 };