]> granicus.if.org Git - php/commitdiff
some changes to how request input data (Content-Lenght >0) is handled
authorHartmut Holzgraefe <hholzgra@php.net>
Mon, 21 Oct 2002 16:41:06 +0000 (16:41 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Mon, 21 Oct 2002 16:41:06 +0000 (16:41 +0000)
- webdav-specific stuff removed (should be handled using httpd.conf
  LIMIT or equivalents)
- always_populate_raw_post_data now working on any method, not just
  POST (and webdav methods with allow_webdav_methods), when
Content-Length is greater zero
- raw input data is also available using php://input stream,
  this way one doesn't have to care about memory_limit
- input data is now always consumed (although maybe ignored,
  this fixes we had withproblems with keep-alive connections
@ raw POST data is now available as php://input stream (hartmut)

ext/standard/php_fopen_wrapper.c
main/SAPI.c
main/main.c
main/php_content_types.c
main/php_globals.h

index 6299e28ac18814ba125c5b5e12fba2e82daafcbb..cfaad71e0fdaabbf01e281accf2cbe1d593e6edf 100644 (file)
@@ -66,6 +66,59 @@ php_stream_ops php_stream_output_ops = {
        NULL  /* set_option */
 };
 
+static size_t php_stream_input_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
+{
+       return -1;
+}
+
+static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
+{
+       int read_bytes;
+       if(!stream->eof) {
+               if(SG(request_info).post_data) { /* data has already been read by a post handler */
+                       read_bytes = SG(request_info).post_data_length - stream->position;
+                       if(read_bytes <= count) {
+                               stream->eof = 1;
+                       } else {
+                               read_bytes = count;
+                       }
+                       if(read_bytes) {
+                               memcpy(buf, SG(request_info).post_data + stream->position, read_bytes);
+                       }
+                       return read_bytes;
+               } else {
+                       read_bytes = sapi_module.read_post(buf, count TSRMLS_CC);
+                       if(read_bytes <= 0){
+                               stream->eof = 1;
+                               read_bytes = 0;
+                       }
+                       return read_bytes;
+               }
+       }
+}
+
+static int php_stream_input_close(php_stream *stream, int close_handle TSRMLS_DC)
+{
+       return 0;
+}
+
+static int php_stream_input_flush(php_stream *stream TSRMLS_DC)
+{
+       return -1;
+}
+
+php_stream_ops php_stream_input_ops = {
+       php_stream_input_write,
+       php_stream_input_read,
+       php_stream_input_close,
+       php_stream_input_flush,
+       "Input",
+       NULL, /* seek */
+       NULL, /* cast */
+       NULL, /* stat */
+       NULL  /* set_option */
+};
+
 php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
 {
        FILE * fp = NULL;
@@ -78,6 +131,10 @@ php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, ch
                return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb");
        }
        
+       if (!strcasecmp(path, "input")) {
+               return php_stream_alloc(&php_stream_input_ops, NULL, 0, "rb");
+       }
+       
        if (!strcasecmp(path, "stdin")) {
                fp = fdopen(dup(STDIN_FILENO), mode);
        } else if (!strcasecmp(path, "stdout")) {
index a2a2129ecdbbbd917bb745e9c53127a9449122eb..85132e86ae2b291602872a82fbb5d7dba4eefdf4 100644 (file)
@@ -128,7 +128,7 @@ static void sapi_read_post_data(TSRMLS_D)
        char *content_type = estrndup(SG(request_info).content_type, content_type_length);
        char *p;
        char oldchar=0;
-       void (*post_reader_func)(TSRMLS_D);
+       void (*post_reader_func)(TSRMLS_D) = NULL;
 
 
        /* dedicated implementation for increased performance:
@@ -159,7 +159,6 @@ static void sapi_read_post_data(TSRMLS_D)
                        return;
                }
                SG(request_info).post_entry = NULL;
-               post_reader_func = sapi_module.default_post_reader;
        }
        if (oldchar) {
                *(p-1) = oldchar;
@@ -169,10 +168,10 @@ static void sapi_read_post_data(TSRMLS_D)
 
        if(post_reader_func) {
                post_reader_func(TSRMLS_C);
+       }
 
-               if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
-                       sapi_module.default_post_reader(TSRMLS_C);
-               }
+       if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
+               sapi_module.default_post_reader(TSRMLS_C);
        }
 }
 
@@ -282,6 +281,7 @@ SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len TSRMLS_DC
 SAPI_API void sapi_activate(TSRMLS_D)
 {
        void (*post_reader_func)(TSRMLS_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;
 
@@ -306,39 +306,34 @@ SAPI_API void sapi_activate(TSRMLS_D)
        }
        SG(rfc1867_uploaded_files) = NULL;
 
+       /* handle request mehtod */
        if (SG(server_context)) {
-               if ( SG(request_info).request_method 
-                       &&  (!strcmp(SG(request_info).request_method, "POST")
-                               || (PG(allow_webdav_methods) 
-                                       && (!strcmp(SG(request_info).request_method, "PROPFIND")
-                                       || !strcmp(SG(request_info).request_method, "PROPPATCH")                                
-                                       || !strcmp(SG(request_info).request_method, "MKCOL")
-                                       || !strcmp(SG(request_info).request_method, "PUT")
-                                       || !strcmp(SG(request_info).request_method, "MOVE")
-                                       || !strcmp(SG(request_info).request_method, "COPY")
-                                       || !strcmp(SG(request_info).request_method, "LOCK"))))) {
-                       if (!SG(request_info).content_type) {
+               if ( SG(request_info).request_method) {
+                       if(!strcmp(SG(request_info).request_method, "POST")
+                          && (SG(request_info).content_type)) {
+                               /* HTTP POST -> may contain form data to be read into variables
+                                  depending on content type given
+                               */
+                               sapi_read_post_data(TSRMLS_C);
+                       } else {
+                               /* any other method with content payload will fill 
+                                  $HTTP_RAW_POST_DATA if enabled by always_populate_raw_post_data 
+                                  it is up to the webserver to decide whether to allow a method or not
+                               */
                                SG(request_info).content_type_dup = NULL;
                                if(PG(always_populate_raw_post_data)) {
-                                       SG(request_info).post_entry = NULL;
-                                       post_reader_func = sapi_module.default_post_reader;
-
-                                       if(post_reader_func) {
-                                               post_reader_func(TSRMLS_C);
-
-                                               if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
-                                                       sapi_module.default_post_reader(TSRMLS_C);
-                                               }
+                                       if(sapi_module.default_post_reader) {
+                                               sapi_module.default_post_reader(TSRMLS_C);
                                        }
                                } else {
-                                       sapi_module.sapi_error(E_WARNING, "No content-type in POST request");
+                                       sapi_module.sapi_error(E_WARNING, "No content-type in %s request", SG(request_info).request_method);
                                }
-                       } else {
-                               sapi_read_post_data(TSRMLS_C);
                        }
                } else {
                        SG(request_info).content_type_dup = NULL;
                }
+
+               /* Cookies */
                SG(request_info).cookie_data = sapi_module.read_cookies(TSRMLS_C);
                if (sapi_module.activate) {
                        sapi_module.activate(TSRMLS_C);
@@ -360,6 +355,14 @@ SAPI_API void sapi_deactivate(TSRMLS_D)
        zend_llist_destroy(&SG(sapi_headers).headers);
        if (SG(request_info).post_data) {
                efree(SG(request_info).post_data);
+       }  else         if (SG(server_context)) {
+               if(sapi_module.read_post) { 
+                       // make sure we've consumed all request input data
+                       char dummy[SAPI_POST_BLOCK_SIZE];
+                       while(sapi_module.read_post(dummy, sizeof(dummy)-1 TSRMLS_CC) > 0) {
+                               /* empty loop body */
+                       }
+               }
        }
        if (SG(request_info).auth_user) {
                efree(SG(request_info).auth_user);
index e112e63c1445f5e33cb936d549ed3dce021dd81c..e5933bcc8b988df92717601a021fae96560c7908 100644 (file)
@@ -320,7 +320,6 @@ PHP_INI_BEGIN()
 
        STD_PHP_INI_BOOLEAN("allow_url_fopen",          "1",            PHP_INI_ALL,            OnUpdateBool,                   allow_url_fopen,                        php_core_globals,       core_globals)
        STD_PHP_INI_BOOLEAN("always_populate_raw_post_data",            "0",            PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   always_populate_raw_post_data,                  php_core_globals,       core_globals)
-       STD_PHP_INI_BOOLEAN("allow_webdav_methods",             "0",                            PHP_INI_SYSTEM|PHP_INI_PERDIR,          OnUpdateBool,                   allow_webdav_methods,                   php_core_globals,       core_globals)
 
 PHP_INI_END()
 /* }}} */
index 08c29ac0108b7cf327f6b7721316ca8998e57942..dfbb3ffee652c1e404936238bdec672afc481662 100644 (file)
@@ -39,9 +39,11 @@ SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
 {
        char *data;
 
-       if(!SG(request_info).post_data) sapi_read_standard_form_data(TSRMLS_C);
-       data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length);
-       SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, SG(request_info).post_data_length);
+       if(PG(always_populate_raw_post_data)) {
+               if(!SG(request_info).post_data) sapi_read_standard_form_data(TSRMLS_C);
+               data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length);
+               SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, SG(request_info).post_data_length);
+       }
 }
 /* }}} */
 
index b24b1df8a7b5d5b3a9a2ade64a67c6ea3a24a6b1..bc34330a92b114d20aed8687b85eb37041533e20 100644 (file)
@@ -140,7 +140,6 @@ struct _php_core_globals {
 
        zend_bool always_populate_raw_post_data;
        
-       zend_bool allow_webdav_methods;
 };