From cf58b7ef1615d2456fc2e3aa9319d8aae11f880f Mon Sep 17 00:00:00 2001 From: Zeev Suraski Date: Tue, 25 May 1999 22:28:24 +0000 Subject: [PATCH] Add container for file-upload. It's not quite implemented yet. --- main/SAPI.c | 37 ++++++++++++++++++++++++++++++++----- main/SAPI.h | 15 +++++++-------- main/rfc1867.c | 24 ++++++++++++++++++++++++ main/rfc1867.h | 12 ++++++++++++ php4dllts.dsp | 10 +++++++++- 5 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 main/rfc1867.c create mode 100644 main/rfc1867.h diff --git a/main/SAPI.c b/main/SAPI.c index 9ae0d1973a..97af485ce9 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -21,6 +21,8 @@ #include "TSRM.h" #endif +#include "rfc1867.h" + #if WIN32||WINNT #define STRCASECMP stricmp #else @@ -33,7 +35,8 @@ static SAPI_POST_READER_FUNC(sapi_read_standard_form_data); #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" 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 }, + { 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 } }; @@ -80,19 +83,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) { sapi_post_content_type_reader *post_content_type_reader; uint content_type_length = strlen(SG(request_info).content_type); char *content_type = estrndup(SG(request_info).content_type, content_type_length); - - zend_str_tolower(content_type, content_type_length); + char *p; + char oldchar=0; + + /* dedicated implementation for increased performance: + * - Make the content type lowercase + * - Trim descriptive data, stay with the content-type only + */ + for (p=content_type; ppost_reader(SLS_C); + if (oldchar) { + *(p-1) = oldchar; + } + post_content_type_reader->post_reader(content_type SLS_CC); + efree(content_type); } diff --git a/main/SAPI.h b/main/SAPI.h index fbbddf5f5d..1dfb6c7cb0 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -67,13 +67,6 @@ typedef struct { } sapi_globals_struct; -typedef struct _sapi_post_content_type_reader { - char *content_type; - uint content_type_len; - void (*post_reader)(SLS_D); -} sapi_post_content_type_reader; - - #ifdef ZTS # define SLS_D sapi_globals_struct *sapi_globals # define SLS_DC , SLS_D @@ -92,6 +85,12 @@ SAPI_API extern int sapi_globals_id; extern SAPI_API sapi_globals_struct sapi_globals; #endif +typedef struct _sapi_post_content_type_reader { + char *content_type; + uint content_type_len; + void (*post_reader)(char *content_type_dup SLS_DC); +} sapi_post_content_type_reader; + SAPI_API void sapi_startup(sapi_module_struct *sf); SAPI_API void sapi_activate(SLS_D); @@ -134,6 +133,6 @@ struct _sapi_module_struct { #define SAPI_DEFAULT_CONTENT_TYPE "Content-Type: text/html" -#define SAPI_POST_READER_FUNC(post_reader) void post_reader(SLS_D) +#define SAPI_POST_READER_FUNC(post_reader) void post_reader(char *content_type_dup SLS_DC) #endif /* _NEW_SAPI_H */ \ No newline at end of file diff --git a/main/rfc1867.c b/main/rfc1867.c new file mode 100644 index 0000000000..aba13d1b60 --- /dev/null +++ b/main/rfc1867.c @@ -0,0 +1,24 @@ +#include "rfc1867.h" + +SAPI_POST_READER_FUNC(rfc1867_post_reader) +{ + char *boundary; + uint boundary_len; + char input_buffer[FILE_UPLOAD_INPUT_BUFFER_SIZE]; + uint read_bytes; + + boundary = strstr(content_type_dup, "boundary"); + if (!boundary || !(boundary=strchr(boundary, '='))) { + sapi_module.sapi_error(E_COMPILE_ERROR, "Missing boundary in multipart/form-data POST data"); + return; + } + boundary++; + boundary_len = strlen(boundary); + + for (;;) { + read_bytes = sapi_module.read_post(input_buffer, FILE_UPLOAD_INPUT_BUFFER_SIZE-100 SLS_CC); + if (read_bytes<=0) { + break; + } + } +} diff --git a/main/rfc1867.h b/main/rfc1867.h new file mode 100644 index 0000000000..77e3254084 --- /dev/null +++ b/main/rfc1867.h @@ -0,0 +1,12 @@ +#ifndef _RFC1867_H +#define _RFC1867_H + +#include "SAPI.h" + +#define MULTIPART_CONTENT_TYPE "multipart/form-data" + +SAPI_POST_READER_FUNC(rfc1867_post_reader); + +#define FILE_UPLOAD_INPUT_BUFFER_SIZE 8192 + +#endif /* _RFC1867_H */ \ No newline at end of file diff --git a/php4dllts.dsp b/php4dllts.dsp index 3b6cefeff5..96515fa6bb 100644 --- a/php4dllts.dsp +++ b/php4dllts.dsp @@ -69,7 +69,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PHP4DLLTS_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\libzend" /I "." /I "regex\\" /I "..\tsrm" /I "..\bindlib_w32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4DLLTS_EXPORTS" /D "MSVC5" /D "PHP_EXPORTS" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D "SAPI_EXPORTS" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\libzend" /I "." /I "regex\\" /I "..\tsrm" /I "..\bindlib_w32" /D "NDEBUG" /D "_WINDOWS" /D "_USRDLL" /D "PHP4DLLTS_EXPORTS" /D "MSVC5" /D "PHP_EXPORTS" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D "SAPI_EXPORTS" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x40d /d "NDEBUG" @@ -143,6 +143,10 @@ SOURCE=.\request_info.c # End Source File # Begin Source File +SOURCE=.\rfc1867.c +# End Source File +# Begin Source File + SOURCE=.\safe_mode.c # End Source File # Begin Source File @@ -223,6 +227,10 @@ SOURCE=.\request_info.h # End Source File # Begin Source File +SOURCE=.\rfc1867.h +# End Source File +# Begin Source File + SOURCE=.\safe_mode.h # End Source File # Begin Source File -- 2.40.0