- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathfastcgi.h
126 lines (103 loc) · 4.78 KB
/
fastcgi.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
/*
+----------------------------------------------------------------------+
| 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. |
+----------------------------------------------------------------------+
| Authors: Dmitry Stogov <dmitry@php.net> |
+----------------------------------------------------------------------+
*/
/* FastCGI protocol */
#defineFCGI_VERSION_1 1
#defineFCGI_MAX_LENGTH 0xffff
#defineFCGI_KEEP_CONN 1
/* this is near the perfect hash function for most useful FastCGI variables
* which combines efficiency and minimal hash collisions
*/
#defineFCGI_HASH_FUNC(var, var_len) \
(UNEXPECTED(var_len < 3) ? (unsigned int)var_len : \
(((unsigned int)var[3]) << 2) + \
(((unsigned int)var[var_len-2]) << 4) + \
(((unsigned int)var[var_len-1]) << 2) + \
var_len)
#defineFCGI_GETENV(request, name) \
fcgi_quick_getenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1))
#defineFCGI_PUTENV(request, name, value) \
fcgi_quick_putenv(request, name, sizeof(name)-1, FCGI_HASH_FUNC(name, sizeof(name)-1), value)
typedefenum_fcgi_role {
FCGI_RESPONDER=1,
FCGI_AUTHORIZER=2,
FCGI_FILTER=3
} fcgi_role;
enum {
FCGI_DEBUG=1,
FCGI_NOTICE=2,
FCGI_WARNING=3,
FCGI_ERROR=4,
FCGI_ALERT=5,
};
typedefenum_fcgi_request_type {
FCGI_BEGIN_REQUEST=1, /* [in] */
FCGI_ABORT_REQUEST=2, /* [in] (not supported) */
FCGI_END_REQUEST=3, /* [out] */
FCGI_PARAMS=4, /* [in] environment variables */
FCGI_STDIN=5, /* [in] post data */
FCGI_STDOUT=6, /* [out] response */
FCGI_STDERR=7, /* [out] errors */
FCGI_DATA=8, /* [in] filter data (not supported) */
FCGI_GET_VALUES=9, /* [in] */
FCGI_GET_VALUES_RESULT=10/* [out] */
} fcgi_request_type;
typedefenum_fcgi_protocol_status {
FCGI_REQUEST_COMPLETE=0,
FCGI_CANT_MPX_CONN=1,
FCGI_OVERLOADED=2,
FCGI_UNKNOWN_ROLE=3
} dcgi_protocol_status;
/* FastCGI client API */
typedefvoid (*fcgi_apply_func)(constchar*var, unsigned intvar_len, char*val, unsigned intval_len, void*arg);
#defineFCGI_HASH_TABLE_SIZE 128
#defineFCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1)
#defineFCGI_HASH_SEG_SIZE 4096
typedefstruct_fcgi_requestfcgi_request;
intfcgi_init(void);
voidfcgi_shutdown(void);
intfcgi_is_fastcgi(void);
intfcgi_is_closed(fcgi_request*req);
voidfcgi_close(fcgi_request*req, intforce, intdestroy);
intfcgi_in_shutdown(void);
voidfcgi_terminate(void);
intfcgi_listen(constchar*path, intbacklog);
fcgi_request*fcgi_init_request(intlisten_socket, void(*on_accept)(void), void(*on_read)(void), void(*on_close)(void));
voidfcgi_destroy_request(fcgi_request*req);
voidfcgi_set_allowed_clients(char*ip);
intfcgi_accept_request(fcgi_request*req);
intfcgi_finish_request(fcgi_request*req, intforce_close);
constchar*fcgi_get_last_client_ip(void);
voidfcgi_set_in_shutdown(intnew_value);
voidfcgi_request_set_keep(fcgi_request*req, intnew_value);
#ifndefHAVE_ATTRIBUTE_WEAK
typedefvoid (*fcgi_logger)(inttype, constchar*fmt, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
voidfcgi_set_logger(fcgi_loggerlg);
#endif
intfcgi_has_env(fcgi_request*req);
char*fcgi_getenv(fcgi_request*req, constchar*var, intvar_len);
char*fcgi_putenv(fcgi_request*req, char*var, intvar_len, char*val);
char*fcgi_quick_getenv(fcgi_request*req, constchar*var, intvar_len, unsigned inthash_value);
char*fcgi_quick_putenv(fcgi_request*req, char*var, intvar_len, unsigned inthash_value, char*val);
voidfcgi_loadenv(fcgi_request*req, fcgi_apply_funcload_func, zval*array);
intfcgi_read(fcgi_request*req, char*str, intlen);
intfcgi_write(fcgi_request*req, fcgi_request_typetype, constchar*str, intlen);
intfcgi_flush(fcgi_request*req, intend);
intfcgi_end(fcgi_request*req);
#ifdefPHP_WIN32
voidfcgi_impersonate(void);
#endif
voidfcgi_set_mgmt_var(constchar*name, size_tname_len, constchar*value, size_tvalue_len);
voidfcgi_free_mgmt_var_cb(zval*zv);