]> granicus.if.org Git - php/commitdiff
* Add generic POST content-type support. Only application/x-www-form-urlencoded
authorZeev Suraski <zeev@php.net>
Tue, 25 May 1999 21:14:54 +0000 (21:14 +0000)
committerZeev Suraski <zeev@php.net>
Tue, 25 May 1999 21:14:54 +0000 (21:14 +0000)
  supported at this time, but the framework allows for any other types, including
  runtime addition of types.

main/SAPI.c
main/SAPI.h

index b3518736fdb80ad3b34203c88ad1ca7b28c61b37..e43e2dadac9c8446793a2d120bb4fcb53e462b9d 100644 (file)
 #endif
 
 
+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 },
+       { NULL, 0, NULL }
+};
+
+
+static HashTable known_post_content_types;
+
 SAPI_API void (*sapi_error)(int error_type, const char *message, ...);
 
 
@@ -45,7 +57,14 @@ 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++;
+       }
 #ifdef ZTS
        sapi_globals_id = ts_allocate_id(sizeof(sapi_globals_struct), NULL, NULL);
 #endif
@@ -62,6 +81,22 @@ static void sapi_free_header(sapi_header_struct *sapi_header)
 #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);
+
+       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);
+               return;
+       }
+       post_content_type_reader->post_reader(SLS_C);
+}
+
+
+static SAPI_POST_READER_FUNC(sapi_read_standard_form_data)
 {
        int read_bytes, total_read_bytes=0;
        int allocated_bytes=SAPI_POST_BLOCK_SIZE+1;
@@ -95,6 +130,13 @@ SAPI_API void sapi_activate(SLS_D)
        SG(headers_sent) = 0;
        SG(read_post_bytes) = 0;
        SG(request_info).post_data = NULL;
+
+       if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
+               SG(request_info).headers_only = 1;
+       } else {
+               SG(request_info).headers_only = 0;
+       }
+
        if (SG(server_context)) {
                if (SG(request_info).request_method 
                        && !strcmp(SG(request_info).request_method, "POST")) {
@@ -102,11 +144,6 @@ SAPI_API void sapi_activate(SLS_D)
                }
                SG(request_info).cookie_data = sapi_module.read_cookies(SLS_C);
        }
-       if (SG(request_info).request_method && !strcmp(SG(request_info).request_method, "HEAD")) {
-               SG(request_info).headers_only = 1;
-       } else {
-               SG(request_info).headers_only = 0;
-       }
 }
 
 
@@ -216,3 +253,9 @@ SAPI_API int sapi_send_headers()
        }
        return FAILURE;
 }
+
+
+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);
+}
index 6b460c1ac22e32add7b5c4a7fe81b6b5f0ac574a..bf840441bd8fda7559da11be4d21ec65c8f59c41 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "zend.h"
 #include "zend_llist.h"
+#include "zend_operators.h"
 
 #define SAPI_POST_BLOCK_SIZE 4000
 
@@ -66,6 +67,13 @@ 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 +100,8 @@ 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_reader(sapi_post_content_type_reader *post_content_type_reader);
+
 struct _sapi_module_struct {
        char *name;
 
@@ -111,7 +121,6 @@ struct _sapi_module_struct {
 };
 
 
-
 /* header_handler() constants */
 #define SAPI_HEADER_ADD                        (1<<0)
 #define SAPI_HEADER_DELETE_ALL (1<<1)
@@ -124,4 +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)
+
 #endif /* _NEW_SAPI_H */
\ No newline at end of file