hholzgra                Tue Nov 12 13:29:11 2002 EDT

  Modified files:              
    /php4/ext/standard  php_fopen_wrapper.c 
    /php4/main  SAPI.c SAPI.h php_content_types.c 
  Log:
  HTTP_RAW_POST_DATA BC fixes 
  # hopefully all done, commiting anyway to continue work on my home box
  php://input stream fixes (POST data handerl mangles data, CLI crashbug)
  
  
Index: php4/ext/standard/php_fopen_wrapper.c
diff -u php4/ext/standard/php_fopen_wrapper.c:1.28 
php4/ext/standard/php_fopen_wrapper.c:1.29
--- php4/ext/standard/php_fopen_wrapper.c:1.28  Mon Oct 21 15:08:18 2002
+++ php4/ext/standard/php_fopen_wrapper.c       Tue Nov 12 13:29:11 2002
@@ -17,7 +17,7 @@
    |          Hartmut Holzgraefe <[EMAIL PROTECTED]>                       |
    +----------------------------------------------------------------------+
  */
-/* $Id: php_fopen_wrapper.c,v 1.28 2002/10/21 19:08:18 hholzgra Exp $ */
+/* $Id: php_fopen_wrapper.c,v 1.29 2002/11/12 18:29:11 hholzgra Exp $ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -75,22 +75,24 @@
 {
        size_t read_bytes = 0;
        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(SG(request_info).raw_post_data) { /* data has already been read by 
+a post handler */
+                       read_bytes = SG(request_info).raw_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);
+                               memcpy(buf, SG(request_info).raw_post_data + 
+stream->position, read_bytes);
                        }
-               } else {
+               } else if(sapi_module.read_post) {
                        read_bytes = sapi_module.read_post(buf, count TSRMLS_CC);
                        if(read_bytes <= 0){
                                stream->eof = 1;
                                read_bytes = 0;
                        }
+               } else {
+                       stream->eof = 1;
                }
        }
 
@@ -133,7 +135,7 @@
        
        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);
Index: php4/main/SAPI.c
diff -u php4/main/SAPI.c:1.154 php4/main/SAPI.c:1.155
--- php4/main/SAPI.c:1.154      Fri Nov  8 03:41:52 2002
+++ php4/main/SAPI.c    Tue Nov 12 13:29:11 2002
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: SAPI.c,v 1.154 2002/11/08 08:41:52 hholzgra Exp $ */
+/* $Id: SAPI.c,v 1.155 2002/11/12 18:29:11 hholzgra Exp $ */
 
 #include <ctype.h>
 #include <sys/stat.h>
@@ -174,7 +174,7 @@
                post_reader_func(TSRMLS_C);
        }
 
-       if(PG(always_populate_raw_post_data) && sapi_module.default_post_reader) {
+       if(sapi_module.default_post_reader) {
                sapi_module.default_post_reader(TSRMLS_C);
        }
 }
@@ -294,6 +294,7 @@
        SG(headers_sent) = 0;
        SG(read_post_bytes) = 0;
        SG(request_info).post_data = NULL;
+       SG(request_info).raw_post_data = NULL;
        SG(request_info).current_user = NULL;
        SG(request_info).current_user_length = 0;
        SG(request_info).no_headers = 0;
@@ -355,13 +356,16 @@
                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
+                       /* 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).raw_post_data) {
+               efree(SG(request_info).raw_post_data);
+       } 
        if (SG(request_info).auth_user) {
                efree(SG(request_info).auth_user);
        }
Index: php4/main/SAPI.h
diff -u php4/main/SAPI.h:1.85 php4/main/SAPI.h:1.86
--- php4/main/SAPI.h:1.85       Fri Aug  2 02:53:48 2002
+++ php4/main/SAPI.h    Tue Nov 12 13:29:11 2002
@@ -71,10 +71,10 @@
 typedef struct {
        const char *request_method;
        char *query_string;
-       char *post_data;
+       char *post_data, *raw_post_data;
        char *cookie_data;
        long content_length;
-       uint post_data_length;
+       uint post_data_length, raw_post_data_length;
 
        char *path_translated;
        char *request_uri;
Index: php4/main/php_content_types.c
diff -u php4/main/php_content_types.c:1.23 php4/main/php_content_types.c:1.24
--- php4/main/php_content_types.c:1.23  Fri Nov  8 03:41:52 2002
+++ php4/main/php_content_types.c       Tue Nov 12 13:29:11 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_content_types.c,v 1.23 2002/11/08 08:41:52 hholzgra Exp $ */
+/* $Id: php_content_types.c,v 1.24 2002/11/12 18:29:11 hholzgra Exp $ */
 
 #include "php.h"
 #include "SAPI.h"
@@ -38,25 +38,35 @@
 SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
 {
        char *data = NULL;
+       int length = 0;
 
-       if(PG(always_populate_raw_post_data)) {
-               if(NULL == SG(request_info).post_data) { /* no data yet */
-                       if(NULL == SG(request_info).post_entry) {
-                               /* no post handler registered, so we just swallow the 
data */
-                               sapi_read_standard_form_data(TSRMLS_C);
-                               data = SG(request_info).post_data;
-                               SG(request_info).post_data = NULL;
-                               SG(request_info).post_data_length = 0;
-                       }
-               } else {
-                       /* copy existing post data */
-                       data = estrndup(SG(request_info).post_data, 
SG(request_info).post_data_length);
+       // $HTTP_RAW_POST_DATA registration
+       if(!strcmp(SG(request_info).request_method, "POST")) {
+               if(NULL == SG(request_info).post_entry) {
+                       /* no post handler registered, so we just swallow the data */
+                       sapi_read_standard_form_data(TSRMLS_C);
+                       length = SG(request_info).post_data_length;
+                       data = estrndup(SG(request_info).post_data, length);
+               } else if(PG(always_populate_raw_post_data) && 
+SG(request_info).post_data) {
+                       length = SG(request_info).post_data_length;
+                       data = estrndup(SG(request_info).post_data, length);
                }
-               
                if(data) {
-                       SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, 
SG(request_info).post_data_length);
+                       SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length);
                }
        }
+
+       /* for php://input stream:
+        some post handlers modify the content of request_info.post_data
+        so for now we need a copy for the php://input stream
+        in the long run post handlers should be changed to not touch
+        request_info.post_data for memory preservation reasons
+       */
+       if(SG(request_info).post_data) {
+               SG(request_info).raw_post_data = estrndup(SG(request_info).post_data, 
+SG(request_info).post_data_length);
+               SG(request_info).raw_post_data_length = 
+SG(request_info).post_data_length;
+       }
+
 }
 /* }}} */
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to