Back to index

php5  5.3.10
php_content_types.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Author:                                                              |
00016    +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: php_content_types.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 #include "SAPI.h"
00023 #include "rfc1867.h"
00024 
00025 #include "php_content_types.h"
00026 
00027 /* {{{ php_post_entries[]
00028  */
00029 static sapi_post_entry php_post_entries[] = {
00030        { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data,   php_std_post_handler },
00031        { MULTIPART_CONTENT_TYPE,    sizeof(MULTIPART_CONTENT_TYPE)-1,    NULL,                         rfc1867_post_handler },
00032        { NULL, 0, NULL, NULL }
00033 };
00034 /* }}} */
00035 
00036 /* {{{ SAPI_POST_READER_FUNC
00037  */
00038 SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader)
00039 {
00040        char *data;
00041        int length;
00042 
00043        /* $HTTP_RAW_POST_DATA registration */
00044        if (!strcmp(SG(request_info).request_method, "POST")) {
00045               if (NULL == SG(request_info).post_entry) {
00046                      /* no post handler registered, so we just swallow the data */
00047                      sapi_read_standard_form_data(TSRMLS_C);
00048               }
00049 
00050               /* For unknown content types we create HTTP_RAW_POST_DATA even if always_populate_raw_post_data off,
00051                * this is in-effecient, but we need to keep doing it for BC reasons (for now) */
00052               if ((PG(always_populate_raw_post_data) || NULL == SG(request_info).post_entry) && SG(request_info).post_data) {
00053                      length = SG(request_info).post_data_length;
00054                      data = estrndup(SG(request_info).post_data, length);
00055                      SET_VAR_STRINGL("HTTP_RAW_POST_DATA", data, length);
00056               }
00057        }
00058 
00059        /* for php://input stream:
00060         some post handlers modify the content of request_info.post_data
00061         so for now we need a copy for the php://input stream
00062         in the long run post handlers should be changed to not touch
00063         request_info.post_data for memory preservation reasons
00064        */
00065        if (SG(request_info).post_data) {
00066               SG(request_info).raw_post_data = estrndup(SG(request_info).post_data, SG(request_info).post_data_length);
00067               SG(request_info).raw_post_data_length = SG(request_info).post_data_length;
00068        }
00069 }
00070 /* }}} */
00071 
00072 /* {{{ php_startup_sapi_content_types
00073  */
00074 int php_startup_sapi_content_types(TSRMLS_D)
00075 {
00076        sapi_register_default_post_reader(php_default_post_reader);
00077        sapi_register_treat_data(php_default_treat_data);
00078        sapi_register_input_filter(php_default_input_filter, NULL);
00079        return SUCCESS;
00080 }
00081 /* }}} */
00082 
00083 /* {{{ php_setup_sapi_content_types
00084  */
00085 int php_setup_sapi_content_types(TSRMLS_D)
00086 {
00087        sapi_register_post_entries(php_post_entries TSRMLS_CC);
00088 
00089        return SUCCESS;
00090 }
00091 /* }}} */
00092 
00093 /*
00094  * Local variables:
00095  * tab-width: 4
00096  * c-basic-offset: 4
00097  * End:
00098  * vim600: sw=4 ts=4 fdm=marker
00099  * vim<600: sw=4 ts=4
00100  */