php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
SAPI.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Zeev Suraski <zeev@php.net> |
14 +----------------------------------------------------------------------+
15*/
16
17#ifndef SAPI_H
18#define SAPI_H
19
20#include "php.h"
21#include "zend.h"
22#include "zend_API.h"
23#include "zend_llist.h"
24#include "zend_operators.h"
25#include <sys/stat.h>
26
27#define SAPI_OPTION_NO_CHDIR 1
28#define SAPI_POST_BLOCK_SIZE 0x4000
29
30#ifdef PHP_WIN32
31# ifdef SAPI_EXPORTS
32# define SAPI_API __declspec(dllexport)
33# else
34# define SAPI_API __declspec(dllimport)
35# endif
36#elif defined(__GNUC__) && __GNUC__ >= 4
37# define SAPI_API __attribute__ ((visibility("default")))
38#else
39# define SAPI_API
40#endif
41
42#undef shutdown
43
44typedef struct {
45 char *header;
46 size_t header_len;
48
49
57
58
61
63extern SAPI_API sapi_module_struct sapi_module; /* true global */
65
66/* Some values in this structure needs to be filled in before
67 * calling sapi_activate(). We WILL change the `char *' entries,
68 * so make sure that you allocate a separate buffer for them
69 * and that you free them after sapi_deactivate().
70 */
71
72typedef struct {
73 const char *request_method;
77
80
81 /* Do not use request_body directly, but the php://input stream wrapper instead */
83
84 const char *content_type;
85
89
91
93
94 /* for HTTP authentication */
95 char *auth_user;
98
99 /* this is necessary for the CGI SAPI module */
100 char *argv0;
101
104
105 /* this is necessary for CLI module */
106 int argc;
107 char **argv;
110
111typedef struct {
113 struct {
114 bool set;
116 } options_cache[5];
118
126
127#define REQUEST_PARSE_BODY_OPTION_GET(name, fallback) \
128 (SG(request_parse_body_context).options_cache[REQUEST_PARSE_BODY_OPTION_ ## name].set \
129 ? SG(request_parse_body_context).options_cache[REQUEST_PARSE_BODY_OPTION_ ## name].value \
130 : (fallback))
131
152
153
155#ifdef ZTS
156# define SG(v) ZEND_TSRMG_FAST(sapi_globals_offset, sapi_globals_struct *, v)
157SAPI_API extern int sapi_globals_id;
158SAPI_API extern size_t sapi_globals_offset;
159#else
160# define SG(v) (sapi_globals.v)
162#endif
163
165SAPI_API void sapi_shutdown(void);
166SAPI_API void sapi_activate(void);
169SAPI_API void sapi_deactivate(void);
171SAPI_API void sapi_add_request_header(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
173
174/*
175 * This is the preferred and maintained API for
176 * operating on HTTP headers.
177 */
178
179/*
180 * Always specify a sapi_header_line this way:
181 *
182 * sapi_header_line ctr = {0};
183 */
184
185typedef struct {
186 const char *line; /* If you allocated this, you need to free it yourself */
187 size_t line_len;
188 zend_long response_code; /* long due to zend_parse_parameters compatibility */
190
191typedef enum { /* Parameter: */
192 SAPI_HEADER_REPLACE, /* sapi_header_line* */
193 SAPI_HEADER_ADD, /* sapi_header_line* */
194 SAPI_HEADER_DELETE, /* sapi_header_line* */
198
201
202/* Deprecated functions. Use sapi_header_op instead. */
203SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace);
204#define sapi_add_header(a, b, c) sapi_add_header_ex((a),(b),(c),1)
205
206
209SAPI_API void sapi_handle_post(void *arg);
211SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen);
215SAPI_API int sapi_register_default_post_reader(void (*default_post_reader)(void));
216SAPI_API int sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray));
217SAPI_API int sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void));
218
219SAPI_API int sapi_flush(void);
221SAPI_API char *sapi_getenv(const char *name, size_t name_len);
222
225SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len);
227
228SAPI_API int sapi_get_fd(int *fd);
230
231SAPI_API int sapi_get_target_uid(uid_t *);
232SAPI_API int sapi_get_target_gid(gid_t *);
236
238 char *name;
240
243
244 int (*activate)(void);
246
247 size_t (*ub_write)(const char *str, size_t str_length);
248 void (*flush)(void *server_context);
249 zend_stat_t *(*get_stat)(void);
250 char *(*getenv)(const char *name, size_t name_len);
251
252 void (*sapi_error)(int type, const char *error_msg, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
253
255 int (*send_headers)(sapi_headers_struct *sapi_headers);
256 void (*send_header)(sapi_header_struct *sapi_header, void *server_context);
257
258 size_t (*read_post)(char *buffer, size_t count_bytes);
259 char *(*read_cookies)(void);
260
261 void (*register_server_variables)(zval *track_vars_array);
262 void (*log_message)(const char *message, int syslog_type_int);
263 zend_result (*get_request_time)(double *request_time);
265
267
269 void (*treat_data)(int arg, char *str, zval *destArray);
271
273 int php_ini_ignore_cwd; /* don't look for php.ini in the current directory */
274
275 int (*get_fd)(int *fd);
276
278
279 int (*get_target_uid)(uid_t *);
280 int (*get_target_gid)(gid_t *);
281
282 unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len);
283
284 void (*ini_defaults)(HashTable *configuration_hash);
286
287 const char *ini_entries;
289 unsigned int (*input_filter_init)(void);
290};
291
296 void (*post_handler)(char *content_type_dup, void *arg);
297};
298
299/* header_handler() constants */
300#define SAPI_HEADER_ADD (1<<0)
301
302
303#define SAPI_HEADER_SENT_SUCCESSFULLY 1
304#define SAPI_HEADER_DO_SEND 2
305#define SAPI_HEADER_SEND_FAILED 3
306
307#define SAPI_DEFAULT_MIMETYPE "text/html"
308#define SAPI_DEFAULT_CHARSET PHP_DEFAULT_CHARSET
309#define SAPI_PHP_VERSION_HEADER "X-Powered-By: PHP/" PHP_VERSION
310
311#define SAPI_POST_READER_FUNC(post_reader) void post_reader(void)
312#define SAPI_POST_HANDLER_FUNC(post_handler) void post_handler(char *content_type_dup, void *arg)
313
314#define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray)
315#define SAPI_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)
316
318SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
319SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader);
320SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data);
321SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter);
323
324#define STANDARD_SAPI_MODULE_PROPERTIES \
325 NULL, /* php_ini_path_override */ \
326 NULL, /* default_post_reader */ \
327 NULL, /* treat_data */ \
328 NULL, /* executable_location */ \
329 0, /* php_ini_ignore */ \
330 0, /* php_ini_ignore_cwd */ \
331 NULL, /* get_fd */ \
332 NULL, /* force_http_10 */ \
333 NULL, /* get_target_uid */ \
334 NULL, /* get_target_gid */ \
335 NULL, /* input_filter */ \
336 NULL, /* ini_defaults */ \
337 0, /* phpinfo_as_text; */ \
338 NULL, /* ini_entries; */ \
339 NULL, /* additional_functions */ \
340 NULL /* input_filter_init */
341
342#endif /* SAPI_H */
SAPI_API sapi_module_struct sapi_module
Definition SAPI.c:65
SAPI_API int sapi_add_header_ex(const char *header_line, size_t header_line_len, bool duplicate, bool replace)
Definition SAPI.c:628
SAPI_API int sapi_header_op(sapi_header_op_enum op, void *arg)
Definition SAPI.c:666
sapi_globals_struct sapi_globals
Definition SAPI.c:44
SAPI_API int sapi_register_default_post_reader(void(*default_post_reader)(void))
Definition SAPI.c:972
SAPI_API zend_stat_t * sapi_get_stat(void)
Definition SAPI.c:1011
SAPI_API int sapi_register_post_entries(const sapi_post_entry *post_entry)
Definition SAPI.c:933
sapi_header_op_enum
Definition SAPI.h:191
@ SAPI_HEADER_DELETE
Definition SAPI.h:194
@ SAPI_HEADER_DELETE_ALL
Definition SAPI.h:195
@ SAPI_HEADER_REPLACE
Definition SAPI.h:192
@ SAPI_HEADER_SET_STATUS
Definition SAPI.h:196
SAPI_API double sapi_get_request_time(void)
Definition SAPI.c:1088
SAPI_API int sapi_register_treat_data(void(*treat_data)(int arg, char *str, zval *destArray))
Definition SAPI.c:982
SAPI_API char * sapi_get_default_content_type(void)
Definition SAPI.c:337
SAPI_API void sapi_terminate_process(void)
Definition SAPI.c:1104
SAPI_API sapi_module_struct sapi_module
Definition SAPI.c:65
#define SAPI_POST_READER_FUNC(post_reader)
Definition SAPI.h:311
SAPI_API int sapi_send_headers(void)
Definition SAPI.c:843
SAPI_API void sapi_initialize_empty_request(void)
Definition SAPI.c:556
SAPI_API void sapi_add_request_header(const char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg)
Definition SAPI.c:1110
SAPI_API void sapi_activate_headers_only(void)
Definition SAPI.c:386
SAPI_API int sapi_register_input_filter(unsigned int(*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int(*input_filter_init)(void))
Definition SAPI.c:991
SAPI_API int sapi_get_target_gid(gid_t *)
Definition SAPI.c:1079
SAPI_API int sapi_flush(void)
Definition SAPI.c:1001
SAPI_API void sapi_free_header(sapi_header_struct *sapi_header)
Definition SAPI.c:105
SAPI_API char * sapi_getenv(const char *name, size_t name_len)
Definition SAPI.c:1023
#define SAPI_INPUT_FILTER_FUNC(input_filter)
Definition SAPI.h:315
SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry)
Definition SAPI.c:962
SAPI_API void sapi_read_post_data(void)
Definition SAPI.c:170
SAPI_API void sapi_get_default_content_type_header(sapi_header_struct *default_header)
Definition SAPI.c:345
struct _sapi_globals_struct sapi_globals_struct
SAPI_API void sapi_activate(void)
Definition SAPI.c:430
SAPI_API void sapi_deactivate_destroy(void)
Definition SAPI.c:533
SAPI_API int sapi_get_fd(int *fd)
Definition SAPI.c:1051
request_parse_body_option
Definition SAPI.h:119
@ REQUEST_PARSE_BODY_OPTION_post_max_size
Definition SAPI.h:123
@ REQUEST_PARSE_BODY_OPTION_upload_max_filesize
Definition SAPI.h:124
@ REQUEST_PARSE_BODY_OPTION_max_multipart_body_parts
Definition SAPI.h:122
@ REQUEST_PARSE_BODY_OPTION_max_file_uploads
Definition SAPI.h:120
@ REQUEST_PARSE_BODY_OPTION_max_input_vars
Definition SAPI.h:121
SAPI_API size_t sapi_apply_default_charset(char **mimetype, size_t len)
Definition SAPI.c:365
SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen)
Definition SAPI.c:232
struct _sapi_module_struct sapi_module_struct
Definition SAPI.h:60
SAPI_API void sapi_deactivate(void)
Definition SAPI.c:549
SAPI_API int sapi_register_post_entry(const sapi_post_entry *post_entry)
Definition SAPI.c:947
SAPI_API void sapi_handle_post(void *arg)
Definition SAPI.c:161
SAPI_API void sapi_deactivate_module(void)
Definition SAPI.c:494
struct _sapi_post_entry sapi_post_entry
Definition SAPI.h:59
#define SAPI_API
Definition SAPI.h:39
SAPI_API void sapi_startup(sapi_module_struct *sf)
Definition SAPI.c:68
SAPI_API int sapi_force_http_10(void)
Definition SAPI.c:1060
SAPI_API int sapi_get_target_uid(uid_t *)
Definition SAPI.c:1070
#define SAPI_HEADER_ADD
Definition SAPI.h:300
SAPI_API void sapi_shutdown(void)
Definition SAPI.c:89
#define SAPI_TREAT_DATA_FUNC(treat_data)
Definition SAPI.h:314
size_t len
Definition apprentice.c:174
printf(string $format, mixed ... $values)
zend_ffi_type * type
Definition ffi.c:3812
zval * arg
Definition ffi.c:3975
zval * val
Definition ffi.c:4262
char * error_msg
int fd
Definition phpdbg.h:282
unsigned char headers_sent
Definition SAPI.h:138
sapi_request_info request_info
Definition SAPI.h:134
sapi_headers_struct sapi_headers
Definition SAPI.h:135
void * server_context
Definition SAPI.h:133
HashTable * rfc1867_uploaded_files
Definition SAPI.h:142
zend_stat_t global_stat
Definition SAPI.h:139
char * default_charset
Definition SAPI.h:141
double global_request_time
Definition SAPI.h:146
char * default_mimetype
Definition SAPI.h:140
int64_t read_post_bytes
Definition SAPI.h:136
HashTable known_post_content_types
Definition SAPI.h:147
unsigned char post_read
Definition SAPI.h:137
zend_fcall_info_cache fci_cache
Definition SAPI.h:149
sapi_request_parse_body_context request_parse_body_context
Definition SAPI.h:150
zend_long post_max_size
Definition SAPI.h:143
unsigned int(* input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len)
Definition SAPI.h:282
int(* send_headers)(sapi_headers_struct *sapi_headers)
Definition SAPI.h:255
const char * ini_entries
Definition SAPI.h:287
int(* startup)(struct _sapi_module_struct *sapi_module)
Definition SAPI.h:241
size_t(* ub_write)(const char *str, size_t str_length)
Definition SAPI.h:247
int(* deactivate)(void)
Definition SAPI.h:245
void(* terminate_process)(void)
Definition SAPI.h:264
void(* log_message)(const char *message, int syslog_type_int)
Definition SAPI.h:262
void(* treat_data)(int arg, char *str, zval *destArray)
Definition SAPI.h:269
int(* get_target_uid)(uid_t *)
Definition SAPI.h:279
int(* shutdown)(struct _sapi_module_struct *sapi_module)
Definition SAPI.h:242
int php_ini_ignore_cwd
Definition SAPI.h:273
void(* flush)(void *server_context)
Definition SAPI.h:248
unsigned int(* input_filter_init)(void)
Definition SAPI.h:289
char * php_ini_path_override
Definition SAPI.h:266
char * pretty_name
Definition SAPI.h:239
void(* default_post_reader)(void)
Definition SAPI.h:268
void int(* header_handler)(sapi_header_struct *sapi_header, sapi_header_op_enum op, sapi_headers_struct *sapi_headers)
Definition SAPI.h:254
void(* sapi_error)(int type, const char *error_msg,...) ZEND_ATTRIBUTE_FORMAT(printf
Definition SAPI.h:252
void(* ini_defaults)(HashTable *configuration_hash)
Definition SAPI.h:284
char * executable_location
Definition SAPI.h:270
int(* force_http_10)(void)
Definition SAPI.h:277
const zend_function_entry * additional_functions
Definition SAPI.h:288
int(* get_target_gid)(gid_t *)
Definition SAPI.h:280
void(* register_server_variables)(zval *track_vars_array)
Definition SAPI.h:261
size_t(* read_post)(char *buffer, size_t count_bytes)
Definition SAPI.h:258
int(* get_fd)(int *fd)
Definition SAPI.h:275
zend_result(* get_request_time)(double *request_time)
Definition SAPI.h:263
void(* send_header)(sapi_header_struct *sapi_header, void *server_context)
Definition SAPI.h:256
int(* activate)(void)
Definition SAPI.h:244
Definition SAPI.h:292
void(* post_reader)(void)
Definition SAPI.h:295
uint32_t content_type_len
Definition SAPI.h:294
char * content_type
Definition SAPI.h:293
void(* post_handler)(char *content_type_dup, void *arg)
Definition SAPI.h:296
Definition file.h:177
const char * line
Definition SAPI.h:186
zend_long response_code
Definition SAPI.h:188
size_t line_len
Definition SAPI.h:187
char * header
Definition SAPI.h:45
size_t header_len
Definition SAPI.h:46
char * http_status_line
Definition SAPI.h:55
unsigned char send_default_content_type
Definition SAPI.h:53
zend_llist headers
Definition SAPI.h:51
int http_response_code
Definition SAPI.h:52
char * mimetype
Definition SAPI.h:54
sapi_post_entry * post_entry
Definition SAPI.h:90
bool headers_read
Definition SAPI.h:88
zend_long content_length
Definition SAPI.h:76
int current_user_length
Definition SAPI.h:103
bool no_headers
Definition SAPI.h:87
bool headers_only
Definition SAPI.h:86
char * query_string
Definition SAPI.h:74
char * path_translated
Definition SAPI.h:78
char ** argv
Definition SAPI.h:107
char * content_type_dup
Definition SAPI.h:92
char * auth_digest
Definition SAPI.h:97
char * auth_user
Definition SAPI.h:95
struct _php_stream * request_body
Definition SAPI.h:82
char * argv0
Definition SAPI.h:100
const char * request_method
Definition SAPI.h:73
char * current_user
Definition SAPI.h:102
char * cookie_data
Definition SAPI.h:75
char * request_uri
Definition SAPI.h:79
const char * content_type
Definition SAPI.h:84
char * auth_password
Definition SAPI.h:96
struct _zend_fcall_info_cache zend_fcall_info_cache
struct _zend_function_entry zend_function_entry
struct _zval_struct zval
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
struct _zend_llist zend_llist
int32_t zend_long
Definition zend_long.h:42
#define END_EXTERN_C()
#define ZEND_ATTRIBUTE_FORMAT(type, idx, first)
#define BEGIN_EXTERN_C()
struct stat zend_stat_t
Definition zend_stream.h:94
struct _zend_array HashTable
Definition zend_types.h:386
ZEND_RESULT_CODE zend_result
Definition zend_types.h:64
zend_string * name