mirror of
https://github.com/php/php-src.git
synced 2024-11-24 18:34:21 +08:00
Add container for file-upload. It's not quite implemented yet.
This commit is contained in:
parent
6155d91e7a
commit
cf58b7ef16
35
main/SAPI.c
35
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);
|
||||
char *p;
|
||||
char oldchar=0;
|
||||
|
||||
zend_str_tolower(content_type, content_type_length);
|
||||
/* dedicated implementation for increased performance:
|
||||
* - Make the content type lowercase
|
||||
* - Trim descriptive data, stay with the content-type only
|
||||
*/
|
||||
for (p=content_type; p<content_type+content_type_length; p++) {
|
||||
switch (*p) {
|
||||
case ';':
|
||||
case ',':
|
||||
case ' ':
|
||||
content_type_length = p-content_type;
|
||||
oldchar = *p;
|
||||
*p = 0;
|
||||
break;
|
||||
default:
|
||||
*p = tolower(*p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_CORE_ERROR, "Unsupported content type: '%s'", content_type);
|
||||
sapi_module.sapi_error(E_COMPILE_ERROR, "Unsupported content type: '%s'", content_type);
|
||||
return;
|
||||
}
|
||||
post_content_type_reader->post_reader(SLS_C);
|
||||
if (oldchar) {
|
||||
*(p-1) = oldchar;
|
||||
}
|
||||
post_content_type_reader->post_reader(content_type SLS_CC);
|
||||
efree(content_type);
|
||||
}
|
||||
|
||||
|
||||
|
15
main/SAPI.h
15
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 */
|
24
main/rfc1867.c
Normal file
24
main/rfc1867.c
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
12
main/rfc1867.h
Normal file
12
main/rfc1867.h
Normal file
@ -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 */
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user