1 | /* |
2 | +----------------------------------------------------------------------+ |
3 | | PHP Version 5 | |
4 | +----------------------------------------------------------------------+ |
5 | | Copyright (c) 1997-2015 The PHP Group | |
6 | +----------------------------------------------------------------------+ |
7 | | This source file is subject to version 3.01 of the PHP license, | |
8 | | that is bundled with this package in the file LICENSE, and is | |
9 | | available through the world-wide-web at the following url: | |
10 | | http://www.php.net/license/3_01.txt | |
11 | | If you did not receive a copy of the PHP license and are unable to | |
12 | | obtain it through the world-wide-web, please send a note to | |
13 | | license@php.net so we can mail you a copy immediately. | |
14 | +----------------------------------------------------------------------+ |
15 | | Author: | |
16 | +----------------------------------------------------------------------+ |
17 | */ |
18 | |
19 | /* $Id$ */ |
20 | |
21 | #include "php.h" |
22 | #include "SAPI.h" |
23 | #include "rfc1867.h" |
24 | |
25 | #include "php_content_types.h" |
26 | |
27 | /* {{{ php_post_entries[] |
28 | */ |
29 | static sapi_post_entry php_post_entries[] = { |
30 | { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, |
31 | { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, |
32 | { NULL, 0, NULL, NULL } |
33 | }; |
34 | /* }}} */ |
35 | |
36 | static zend_bool populate_raw_post_data(TSRMLS_D) |
37 | { |
38 | if (!SG(request_info).request_body) { |
39 | return (zend_bool) 0; |
40 | } |
41 | |
42 | if (!PG(always_populate_raw_post_data)) { |
43 | return (zend_bool) !SG(request_info).post_entry; |
44 | } |
45 | |
46 | return (zend_bool) (PG(always_populate_raw_post_data) > 0); |
47 | } |
48 | |
49 | /* {{{ SAPI_POST_READER_FUNC |
50 | */ |
51 | SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) |
52 | { |
53 | if (!strcmp(SG(request_info).request_method, "POST" )) { |
54 | if (NULL == SG(request_info).post_entry) { |
55 | /* no post handler registered, so we just swallow the data */ |
56 | sapi_read_standard_form_data(TSRMLS_C); |
57 | } |
58 | |
59 | if (populate_raw_post_data(TSRMLS_C)) { |
60 | size_t length; |
61 | char *data = NULL; |
62 | |
63 | php_stream_rewind(SG(request_info).request_body); |
64 | length = php_stream_copy_to_mem(SG(request_info).request_body, &data, PHP_STREAM_COPY_ALL, 0); |
65 | php_stream_rewind(SG(request_info).request_body); |
66 | |
67 | if (length > INT_MAX) { |
68 | sapi_module.sapi_error(E_WARNING, |
69 | "HTTP_RAW_POST_DATA truncated from %lu to %d bytes" , |
70 | (unsigned long) length, INT_MAX); |
71 | length = INT_MAX; |
72 | } |
73 | SET_VAR_STRINGL("HTTP_RAW_POST_DATA" , data, length); |
74 | |
75 | sapi_module.sapi_error(E_DEPRECATED, |
76 | "Automatically populating $HTTP_RAW_POST_DATA is deprecated and " |
77 | "will be removed in a future version. To avoid this warning set " |
78 | "'always_populate_raw_post_data' to '-1' in php.ini and use the " |
79 | "php://input stream instead." ); |
80 | } |
81 | } |
82 | } |
83 | /* }}} */ |
84 | |
85 | /* {{{ php_startup_sapi_content_types |
86 | */ |
87 | int php_startup_sapi_content_types(TSRMLS_D) |
88 | { |
89 | sapi_register_default_post_reader(php_default_post_reader TSRMLS_CC); |
90 | sapi_register_treat_data(php_default_treat_data TSRMLS_CC); |
91 | sapi_register_input_filter(php_default_input_filter, NULL TSRMLS_CC); |
92 | return SUCCESS; |
93 | } |
94 | /* }}} */ |
95 | |
96 | /* {{{ php_setup_sapi_content_types |
97 | */ |
98 | int php_setup_sapi_content_types(TSRMLS_D) |
99 | { |
100 | sapi_register_post_entries(php_post_entries TSRMLS_CC); |
101 | |
102 | return SUCCESS; |
103 | } |
104 | /* }}} */ |
105 | |
106 | /* |
107 | * Local variables: |
108 | * tab-width: 4 |
109 | * c-basic-offset: 4 |
110 | * End: |
111 | * vim600: sw=4 ts=4 fdm=marker |
112 | * vim<600: sw=4 ts=4 |
113 | */ |
114 | |