From 98d95dd88eec996ad2608b357dd03bc7930b3fb4 Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Thu, 16 Sep 1999 23:18:15 +0000 Subject: [PATCH] - Added support for unknown POST content types (Zeev) - Introduce the convert_to_*_ex() API in strlen() --- ChangeLog | 1 + ChangeLog.TODO | 8 ---- cgi_main.c | 4 +- ext/standard/string.c | 8 ++-- main/SAPI.c | 48 ++++++++++++++++----- main/SAPI.h | 7 +++ main/config.w32.h | 6 ++- main/main.c | 3 ++ main/php_content_types.c | 11 +++++ main/rfc1867.c | 2 +- mod_php4.c | 4 +- php4dll.dsp | 54 +++++++++++++++++++++++ php4dllts.dsp | 92 +++++++++++++++++++++++++++++++--------- 13 files changed, 202 insertions(+), 46 deletions(-) diff --git a/ChangeLog b/ChangeLog index 438c3bb4db..7fedf7dfcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG ChangeLog ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Added support for unknown POST content types (Zeev) - Added "wddx" serialization handler for session module (Sascha) (automatically enabled, if you compile with --with-wddx) - Fixed deserializing objects (Thies) diff --git a/ChangeLog.TODO b/ChangeLog.TODO index 413b1ff765..17b9223544 100644 --- a/ChangeLog.TODO +++ b/ChangeLog.TODO @@ -35,12 +35,6 @@ March 1 1999, Version 3.0.7 variables. - Clean up apxs build - Add INSTALL.REDHAT file to walk RedHat users through the install -- Added optional second argument to mysql_fetch_array(); MYSQL_ASSOC will - cause the resulting array to contain the associative indices only, - MYSQL_NUM will cause the array to contain the numeric indices only (like - mysql_fetch_row()) and MYSQL_BOTH would cause them both to be defined - (default). -- Backport the Zend debugging memory manager into the PHP 3.0.x tree. - Add function_exists() function. - Add another version of WDDX module (we need to pick a single implementation here) @@ -76,8 +70,6 @@ March 1 1999, Version 3.0.7 - Fix bug in pdf_close() function - Add WDDX support (see http://www.wddx.org for more info) - Add similar_text() function -- Constructors of parent classes weren't accessible to derived classes (as - of 3.0.6). Fixed. - Introduce simple regex compilation cache diff --git a/cgi_main.c b/cgi_main.c index 6056d4fd8d..4a165b80c5 100644 --- a/cgi_main.c +++ b/cgi_main.c @@ -143,7 +143,9 @@ static sapi_module_struct sapi_module = { sapi_cgi_send_header, /* send header handler */ sapi_cgi_read_post, /* read POST data */ - sapi_cgi_read_cookies /* read Cookies */ + sapi_cgi_read_cookies, /* read Cookies */ + + STANDARD_SAPI_MODULE_PROPERTIES }; diff --git a/ext/standard/string.c b/ext/standard/string.c index 6c3ceb5f46..2e26fa46fd 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -82,13 +82,13 @@ PHP_FUNCTION(bin2hex) Get string length */ PHP_FUNCTION(strlen) { - pval *str; + pval **str; - if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &str) == FAILURE) { + if (ARG_COUNT(ht) != 1 || getParametersEx(1, &str) == FAILURE) { WRONG_PARAM_COUNT; } - convert_to_string(str); - RETVAL_LONG(str->value.str.len); + convert_to_string_ex(str); + RETVAL_LONG((*str)->value.str.len); } /* }}} */ diff --git a/main/SAPI.c b/main/SAPI.c index 852dfd40f3..3b94176b87 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -41,7 +41,6 @@ SAPI_POST_READER_FUNC(sapi_read_standard_form_data); static sapi_post_content_type_reader supported_post_content_types[] = { { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, rfc1867_post_reader }, { NULL, 0, NULL } }; @@ -65,14 +64,11 @@ SAPI_API void (*sapi_error)(int error_type, const char *message, ...); SAPI_API void sapi_startup(sapi_module_struct *sf) { - sapi_post_content_type_reader *post_content_type_reader=supported_post_content_types; - sapi_module = *sf; zend_hash_init(&known_post_content_types, 5, NULL, NULL, 1); - while (post_content_type_reader->content_type) { - sapi_register_post_reader(post_content_type_reader); - post_content_type_reader++; - } + + sapi_register_post_reader(supported_post_content_types); + #ifdef ZTS sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL); #endif @@ -100,6 +96,8 @@ static void sapi_read_post_data(SLS_D) char *content_type = estrndup(SG(request_info).content_type, content_type_length); char *p; char oldchar=0; + void (*post_reader_func)(char *content_type_dup SLS_DC); + /* dedicated implementation for increased performance: * - Make the content type lowercase @@ -120,14 +118,19 @@ static void sapi_read_post_data(SLS_D) } } - if (zend_hash_find(&known_post_content_types, content_type, content_type_length+1, (void **) &post_content_type_reader)==FAILURE) { - sapi_module.sapi_error(E_COMPILE_ERROR, "Unsupported content type: '%s'", content_type); - return; + if (zend_hash_find(&known_post_content_types, content_type, content_type_length+1, (void **) &post_content_type_reader)==SUCCESS) { + post_reader_func = post_content_type_reader->post_reader; + } else { + if (!sapi_module.default_post_reader) { + sapi_module.sapi_error(E_COMPILE_ERROR, "Unsupported content type: '%s'", content_type); + return; + } + post_reader_func = sapi_module.default_post_reader; } if (oldchar) { *(p-1) = oldchar; } - post_content_type_reader->post_reader(content_type SLS_CC); + post_reader_func(content_type SLS_CC); efree(content_type); } @@ -154,6 +157,7 @@ SAPI_POST_READER_FUNC(sapi_read_standard_form_data) } } SG(request_info).post_data[total_read_bytes] = 0; /* terminating NULL */ + SG(request_info).post_data_length = total_read_bytes; } @@ -295,6 +299,20 @@ SAPI_API int sapi_send_headers() } +SAPI_API int sapi_register_post_readers(sapi_post_content_type_reader *post_content_type_readers) +{ + sapi_post_content_type_reader *p=post_content_type_readers; + + while (p->content_type) { + if (sapi_register_post_reader(p)==FAILURE) { + return FAILURE; + } + p++; + } + return SUCCESS; +} + + SAPI_API int sapi_register_post_reader(sapi_post_content_type_reader *post_content_type_reader) { return zend_hash_add(&known_post_content_types, post_content_type_reader->content_type, post_content_type_reader->content_type_len+1, (void *) post_content_type_reader, sizeof(sapi_post_content_type_reader), NULL); @@ -305,3 +323,11 @@ SAPI_API void sapi_unregister_post_reader(sapi_post_content_type_reader *post_co { zend_hash_del(&known_post_content_types, post_content_type_reader->content_type, post_content_type_reader->content_type_len+1); } + + +SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(char *content_type_dup SLS_DC)) +{ + sapi_module.default_post_reader = default_post_reader; + return SUCCESS; +} + diff --git a/main/SAPI.h b/main/SAPI.h index 95d82a8747..0433cca55b 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -63,6 +63,7 @@ typedef struct { char *post_data; char *cookie_data; uint content_length; + uint post_data_length; char *path_translated; char *request_uri; @@ -118,8 +119,10 @@ SAPI_API void sapi_deactivate(SLS_D); SAPI_API int sapi_add_header(char *header_line, uint header_line_len); SAPI_API int sapi_send_headers(); +SAPI_API int sapi_register_post_readers(sapi_post_content_type_reader *post_content_type_readers); SAPI_API int sapi_register_post_reader(sapi_post_content_type_reader *post_content_type_reader); SAPI_API void sapi_unregister_post_reader(sapi_post_content_type_reader *post_content_type_reader); +SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(char *content_type_dup SLS_DC)); struct _sapi_module_struct { char *name; @@ -137,6 +140,8 @@ struct _sapi_module_struct { int (*read_post)(char *buffer, uint count_bytes SLS_DC); char *(*read_cookies)(SLS_D); + + void (*default_post_reader)(char *content_type_dup SLS_DC); }; @@ -157,4 +162,6 @@ struct _sapi_module_struct { SAPI_POST_READER_FUNC(sapi_read_standard_form_data); +#define STANDARD_SAPI_MODULE_PROPERTIES NULL + #endif /* _NEW_SAPI_H */ diff --git a/main/config.w32.h b/main/config.w32.h index a9ffa533f2..4160aa6c65 100644 --- a/main/config.w32.h +++ b/main/config.w32.h @@ -10,7 +10,11 @@ #define HAVE_BINDLIB 1 /* set to enable bcmath */ -#define WITH_BCMATH 0 +#define WITH_BCMATH 1 + +/* set to enable bundled PCRE library */ +#define HAVE_BUNDLED_PCRE 1 + /* should be added to runtime config*/ #define PHP3_URL_FOPEN 1 diff --git a/main/main.c b/main/main.c index 6903623fa2..c135b98e9e 100644 --- a/main/main.c +++ b/main/main.c @@ -64,6 +64,8 @@ #include "zend_highlight.h" #include "zend_indent.h" +#include "php_content_types.h" + #if USE_SAPI #include "serverapi/sapi.h" void *gLock; @@ -876,6 +878,7 @@ int php_module_startup(sapi_module_struct *sf) zuv.short_tags = (unsigned char) PG(short_tags); zuv.asp_tags = (unsigned char) PG(asp_tags); zend_set_utility_values(&zuv); + php_startup_SAPI_content_types(); if (module_startup_modules() == FAILURE) { php_printf("Unable to start modules\n"); diff --git a/main/php_content_types.c b/main/php_content_types.c index 8ee79dc0e5..40787b5b65 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -5,10 +5,21 @@ static sapi_post_content_type_reader php_post_content_types[] = { { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, rfc1867_post_reader }, { NULL, 0, NULL } +}; + + +SAPI_POST_READER_FUNC(php_default_post_reader) +{ + ELS_FETCH(); + + sapi_read_standard_form_data(content_type_dup SLS_CC); + SET_VAR_STRINGL("HTTP_RAW_POST_DATA", SG(request_info).post_data, SG(request_info).post_data_length); } + int php_startup_SAPI_content_types() { sapi_register_post_readers(php_post_content_types); + sapi_register_default_post_reader(php_default_post_reader); return SUCCESS; } diff --git a/main/rfc1867.c b/main/rfc1867.c index d8ba333130..d210d091a9 100644 --- a/main/rfc1867.c +++ b/main/rfc1867.c @@ -253,7 +253,7 @@ SAPI_POST_READER_FUNC(rfc1867_post_reader) sapi_read_standard_form_data(content_type_dup SLS_CC); if (SG(request_info).post_data) { - php_mime_split(SG(request_info).post_data, SG(request_info).content_length, boundary); + php_mime_split(SG(request_info).post_data, SG(request_info).post_data_length, boundary); efree(SG(request_info).post_data); SG(request_info).post_data = NULL; } diff --git a/mod_php4.c b/mod_php4.c index 77fff0e5d4..1d78fa0e58 100644 --- a/mod_php4.c +++ b/mod_php4.c @@ -193,7 +193,9 @@ sapi_module_struct sapi_module = { NULL, /* send header handler */ sapi_apache_read_post, /* read POST data */ - sapi_apache_read_cookies /* read Cookies */ + sapi_apache_read_cookies, /* read Cookies */ + + STANDARD_SAPI_MODULE_PROPERTIES }; diff --git a/php4dll.dsp b/php4dll.dsp index f3ad32234e..6e398f4087 100644 --- a/php4dll.dsp +++ b/php4dll.dsp @@ -384,6 +384,15 @@ SOURCE=.\ext\odbc\php_odbc.c # Begin Source File SOURCE=.\ext\pcre\php_pcre.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # Begin Source File @@ -595,22 +604,67 @@ SOURCE=.\regex\regfree.c # Begin Source File SOURCE=.\ext\pcre\pcrelib\chartables.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\get.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\maketables.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\pcre.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\study.c + +!IF "$(CFG)" == "php4dll - Win32 Debug" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dll - Win32 Release" + +!ENDIF + # End Source File # End Group # Begin Group "Header Files No. 3" diff --git a/php4dllts.dsp b/php4dllts.dsp index 58379866bc..543efb184e 100644 --- a/php4dllts.dsp +++ b/php4dllts.dsp @@ -392,6 +392,15 @@ SOURCE=.\ext\odbc\php_odbc.c # Begin Source File SOURCE=.\ext\pcre\php_pcre.c + +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" + +!ENDIF + # End Source File # Begin Source File @@ -582,51 +591,76 @@ SOURCE=.\ext\standard\uniqid.h SOURCE=.\ext\standard\url.h # End Source File # End Group -# Begin Group "Regular Expressions" +# Begin Group "PCRE" # PROP Default_Filter "" -# Begin Source File +# Begin Group "Source Files No. 3" -SOURCE=.\regex\regcomp.c -# End Source File +# PROP Default_Filter ".c" # Begin Source File -SOURCE=.\regex\regerror.c -# End Source File -# Begin Source File +SOURCE=.\ext\pcre\pcrelib\chartables.c -SOURCE=.\regex\regexec.c -# End Source File -# Begin Source File +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" -SOURCE=.\regex\regfree.c -# End Source File -# End Group -# Begin Group "PCRE" +# ADD CPP /D "STATIC" -# PROP Default_Filter "" -# Begin Group "Source Files No. 3" +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" -# PROP Default_Filter ".c" -# Begin Source File +!ENDIF -SOURCE=.\ext\pcre\pcrelib\chartables.c # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\get.c + +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\maketables.c + +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\pcre.c + +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" + +!ENDIF + # End Source File # Begin Source File SOURCE=.\ext\pcre\pcrelib\study.c + +!IF "$(CFG)" == "php4dllts - Win32 Debug_TS" + +# ADD CPP /D "STATIC" + +!ELSEIF "$(CFG)" == "php4dllts - Win32 Release_TS" + +!ENDIF + # End Source File # End Group # Begin Group "Header Files No. 3" @@ -642,6 +676,26 @@ SOURCE=.\ext\pcre\pcrelib\pcre.h # End Source File # End Group # End Group +# Begin Group "Regular Expressions" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\regex\regcomp.c +# End Source File +# Begin Source File + +SOURCE=.\regex\regerror.c +# End Source File +# Begin Source File + +SOURCE=.\regex\regexec.c +# End Source File +# Begin Source File + +SOURCE=.\regex\regfree.c +# End Source File +# End Group # End Group # Begin Group "Win32" -- 2.40.0