- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathSAPI.h
342 lines (273 loc) · 10.8 KB
/
SAPI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Zeev Suraski <zeev@php.net> |
+----------------------------------------------------------------------+
*/
#ifndefSAPI_H
#defineSAPI_H
#include"php.h"
#include"zend.h"
#include"zend_API.h"
#include"zend_llist.h"
#include"zend_operators.h"
#include<sys/stat.h>
#defineSAPI_OPTION_NO_CHDIR 1
#defineSAPI_POST_BLOCK_SIZE 0x4000
#ifdefPHP_WIN32
# ifdefSAPI_EXPORTS
# defineSAPI_API __declspec(dllexport)
# else
# defineSAPI_API __declspec(dllimport)
# endif
#elif defined(__GNUC__) &&__GNUC__ >= 4
# defineSAPI_API __attribute__ ((visibility("default")))
#else
# defineSAPI_API
#endif
#undef shutdown
typedefstruct {
char*header;
size_theader_len;
} sapi_header_struct;
typedefstruct {
zend_llistheaders;
inthttp_response_code;
unsigned charsend_default_content_type;
char*mimetype;
char*http_status_line;
} sapi_headers_struct;
typedefstruct_sapi_post_entrysapi_post_entry;
typedefstruct_sapi_module_structsapi_module_struct;
BEGIN_EXTERN_C()
externSAPI_APIsapi_module_structsapi_module; /* true global */
END_EXTERN_C()
/* Some values in this structure needs to be filled in before
* calling sapi_activate(). We WILL change the `char *' entries,
* so make sure that you allocate a separate buffer for them
* and that you free them after sapi_deactivate().
*/
typedefstruct {
constchar*request_method;
char*query_string;
char*cookie_data;
zend_longcontent_length;
char*path_translated;
char*request_uri;
/* Do not use request_body directly, but the php://input stream wrapper instead */
struct_php_stream*request_body;
constchar*content_type;
boolheaders_only;
boolno_headers;
boolheaders_read;
sapi_post_entry*post_entry;
char*content_type_dup;
/* for HTTP authentication */
char*auth_user;
char*auth_password;
char*auth_digest;
/* this is necessary for the CGI SAPI module */
char*argv0;
char*current_user;
intcurrent_user_length;
/* this is necessary for CLI module */
intargc;
char**argv;
intproto_num;
} sapi_request_info;
typedefstruct {
boolthrow_exceptions;
struct {
boolset;
zend_longvalue;
} options_cache[5];
} sapi_request_parse_body_context;
typedefenum {
REQUEST_PARSE_BODY_OPTION_max_file_uploads=0,
REQUEST_PARSE_BODY_OPTION_max_input_vars,
REQUEST_PARSE_BODY_OPTION_max_multipart_body_parts,
REQUEST_PARSE_BODY_OPTION_post_max_size,
REQUEST_PARSE_BODY_OPTION_upload_max_filesize,
} request_parse_body_option;
#defineREQUEST_PARSE_BODY_OPTION_GET(name, fallback) \
(SG(request_parse_body_context).options_cache[REQUEST_PARSE_BODY_OPTION_ ## name].set \
? SG(request_parse_body_context).options_cache[REQUEST_PARSE_BODY_OPTION_ ## name].value \
: (fallback))
typedefstruct_sapi_globals_struct {
void*server_context;
sapi_request_inforequest_info;
sapi_headers_structsapi_headers;
int64_tread_post_bytes;
unsigned charpost_read;
unsigned charheaders_sent;
zend_stat_tglobal_stat;
char*default_mimetype;
char*default_charset;
HashTable*rfc1867_uploaded_files;
zend_longpost_max_size;
intoptions;
boolsapi_started;
doubleglobal_request_time;
HashTableknown_post_content_types;
zvalcallback_func;
zend_fcall_info_cachefci_cache;
sapi_request_parse_body_contextrequest_parse_body_context;
} sapi_globals_struct;
BEGIN_EXTERN_C()
#ifdefZTS
# defineSG(v) ZEND_TSRMG_FAST(sapi_globals_offset, sapi_globals_struct *, v)
SAPI_APIexternintsapi_globals_id;
SAPI_APIexternsize_tsapi_globals_offset;
#else
# defineSG(v) (sapi_globals.v)
externSAPI_APIsapi_globals_structsapi_globals;
#endif
SAPI_APIvoidsapi_startup(sapi_module_struct*sf);
SAPI_APIvoidsapi_shutdown(void);
SAPI_APIvoidsapi_activate(void);
SAPI_APIvoidsapi_deactivate_module(void);
SAPI_APIvoidsapi_deactivate_destroy(void);
SAPI_APIvoidsapi_deactivate(void);
SAPI_APIvoidsapi_initialize_empty_request(void);
SAPI_APIvoidsapi_add_request_header(constchar*var, unsigned intvar_len, char*val, unsigned intval_len, void*arg);
END_EXTERN_C()
/*
* This is the preferred and maintained API for
* operating on HTTP headers.
*/
/*
* Always specify a sapi_header_line this way:
*
* sapi_header_line ctr = {0};
*/
typedefstruct {
constchar*line; /* If you allocated this, you need to free it yourself */
size_tline_len;
zend_longresponse_code; /* long due to zend_parse_parameters compatibility */
} sapi_header_line;
typedefenum { /* Parameter: */
SAPI_HEADER_REPLACE, /* sapi_header_line* */
SAPI_HEADER_ADD, /* sapi_header_line* */
SAPI_HEADER_DELETE, /* sapi_header_line* */
SAPI_HEADER_DELETE_ALL, /* void */
SAPI_HEADER_SET_STATUS/* int */
} sapi_header_op_enum;
BEGIN_EXTERN_C()
SAPI_APIintsapi_header_op(sapi_header_op_enumop, void*arg);
/* Deprecated functions. Use sapi_header_op instead. */
SAPI_APIintsapi_add_header_ex(constchar*header_line, size_theader_line_len, boolduplicate, boolreplace);
#definesapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1)
SAPI_APIintsapi_send_headers(void);
SAPI_APIvoidsapi_free_header(sapi_header_struct*sapi_header);
SAPI_APIvoidsapi_handle_post(void*arg);
SAPI_APIvoidsapi_read_post_data(void);
SAPI_APIsize_tsapi_read_post_block(char*buffer, size_tbuflen);
SAPI_APIintsapi_register_post_entries(constsapi_post_entry*post_entry);
SAPI_APIintsapi_register_post_entry(constsapi_post_entry*post_entry);
SAPI_APIvoidsapi_unregister_post_entry(constsapi_post_entry*post_entry);
SAPI_APIintsapi_register_default_post_reader(void (*default_post_reader)(void));
SAPI_APIintsapi_register_treat_data(void (*treat_data)(intarg, char*str, zval*destArray));
SAPI_APIintsapi_register_input_filter(unsigned int (*input_filter)(intarg, constchar*var, char**val, size_tval_len, size_t*new_val_len), unsigned int (*input_filter_init)(void));
SAPI_APIintsapi_flush(void);
SAPI_APIzend_stat_t*sapi_get_stat(void);
SAPI_APIchar*sapi_getenv(constchar*name, size_tname_len);
SAPI_APIchar*sapi_get_default_content_type(void);
SAPI_APIvoidsapi_get_default_content_type_header(sapi_header_struct*default_header);
SAPI_APIsize_tsapi_apply_default_charset(char**mimetype, size_tlen);
SAPI_APIvoidsapi_activate_headers_only(void);
SAPI_APIintsapi_get_fd(int*fd);
SAPI_APIintsapi_force_http_10(void);
SAPI_APIintsapi_get_target_uid(uid_t*);
SAPI_APIintsapi_get_target_gid(gid_t*);
SAPI_APIdoublesapi_get_request_time(void);
SAPI_APIvoidsapi_terminate_process(void);
END_EXTERN_C()
struct_sapi_module_struct {
char*name;
char*pretty_name;
int (*startup)(struct_sapi_module_struct*sapi_module);
int (*shutdown)(struct_sapi_module_struct*sapi_module);
int (*activate)(void);
int (*deactivate)(void);
size_t (*ub_write)(constchar*str, size_tstr_length);
void (*flush)(void*server_context);
zend_stat_t*(*get_stat)(void);
char*(*getenv)(constchar*name, size_tname_len);
void (*sapi_error)(inttype, constchar*error_msg, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
int (*header_handler)(sapi_header_struct*sapi_header, sapi_header_op_enumop, sapi_headers_struct*sapi_headers);
int (*send_headers)(sapi_headers_struct*sapi_headers);
void (*send_header)(sapi_header_struct*sapi_header, void*server_context);
size_t (*read_post)(char*buffer, size_tcount_bytes);
char*(*read_cookies)(void);
void (*register_server_variables)(zval*track_vars_array);
void (*log_message)(constchar*message, intsyslog_type_int);
zend_result (*get_request_time)(double*request_time);
void (*terminate_process)(void);
char*php_ini_path_override;
void (*default_post_reader)(void);
void (*treat_data)(intarg, char*str, zval*destArray);
char*executable_location;
intphp_ini_ignore;
intphp_ini_ignore_cwd; /* don't look for php.ini in the current directory */
int (*get_fd)(int*fd);
int (*force_http_10)(void);
int (*get_target_uid)(uid_t*);
int (*get_target_gid)(gid_t*);
unsigned int (*input_filter)(intarg, constchar*var, char**val, size_tval_len, size_t*new_val_len);
void (*ini_defaults)(HashTable*configuration_hash);
intphpinfo_as_text;
constchar*ini_entries;
constzend_function_entry*additional_functions;
unsigned int (*input_filter_init)(void);
};
struct_sapi_post_entry {
char*content_type;
uint32_tcontent_type_len;
void (*post_reader)(void);
void (*post_handler)(char*content_type_dup, void*arg);
};
/* header_handler() constants */
#defineSAPI_HEADER_ADD (1<<0)
#defineSAPI_HEADER_SENT_SUCCESSFULLY 1
#defineSAPI_HEADER_DO_SEND 2
#defineSAPI_HEADER_SEND_FAILED 3
#defineSAPI_DEFAULT_MIMETYPE "text/html"
#defineSAPI_DEFAULT_CHARSET PHP_DEFAULT_CHARSET
#defineSAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
#defineSAPI_POST_READER_FUNC(post_reader) void post_reader(void)
#defineSAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg)
#defineSAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray)
#defineSAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len)
BEGIN_EXTERN_C()
SAPI_APISAPI_POST_READER_FUNC(sapi_read_standard_form_data);
SAPI_APISAPI_POST_READER_FUNC(php_default_post_reader);
SAPI_APISAPI_TREAT_DATA_FUNC(php_default_treat_data);
SAPI_APISAPI_INPUT_FILTER_FUNC(php_default_input_filter);
END_EXTERN_C()
#defineSTANDARD_SAPI_MODULE_PROPERTIES \
NULL, /* php_ini_path_override */ \
NULL, /* default_post_reader */ \
NULL, /* treat_data */ \
NULL, /* executable_location */ \
0, /* php_ini_ignore */ \
0, /* php_ini_ignore_cwd */ \
NULL, /* get_fd */ \
NULL, /* force_http_10 */ \
NULL, /* get_target_uid */ \
NULL, /* get_target_gid */ \
NULL, /* input_filter */ \
NULL, /* ini_defaults */ \
0, /* phpinfo_as_text; */ \
NULL, /* ini_entries; */ \
NULL, /* additional_functions */ \
NULL/* input_filter_init */
#endif/* SAPI_H */