xref: /PHP-5.3/sapi/cgi/fastcgi.h (revision a2045ff3)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 5                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2013 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    | Authors: Dmitry Stogov <dmitry@zend.com>                             |
16    +----------------------------------------------------------------------+
17 */
18 
19 /* $Id$ */
20 
21 /* FastCGI protocol */
22 
23 #define FCGI_VERSION_1 1
24 
25 #define FCGI_MAX_LENGTH 0xffff
26 
27 #define FCGI_KEEP_CONN  1
28 
29 typedef enum _fcgi_role {
30 	FCGI_RESPONDER	= 1,
31 	FCGI_AUTHORIZER	= 2,
32 	FCGI_FILTER		= 3
33 } fcgi_role;
34 
35 typedef enum _fcgi_request_type {
36 	FCGI_BEGIN_REQUEST		=  1, /* [in]                              */
37 	FCGI_ABORT_REQUEST		=  2, /* [in]  (not supported)             */
38 	FCGI_END_REQUEST		=  3, /* [out]                             */
39 	FCGI_PARAMS				=  4, /* [in]  environment variables       */
40 	FCGI_STDIN				=  5, /* [in]  post data                   */
41 	FCGI_STDOUT				=  6, /* [out] response                    */
42 	FCGI_STDERR				=  7, /* [out] errors                      */
43 	FCGI_DATA				=  8, /* [in]  filter data (not supported) */
44 	FCGI_GET_VALUES			=  9, /* [in]                              */
45 	FCGI_GET_VALUES_RESULT	= 10  /* [out]                             */
46 } fcgi_request_type;
47 
48 typedef enum _fcgi_protocol_status {
49 	FCGI_REQUEST_COMPLETE	= 0,
50 	FCGI_CANT_MPX_CONN		= 1,
51 	FCGI_OVERLOADED			= 2,
52 	FCGI_UNKNOWN_ROLE		= 3
53 } dcgi_protocol_status;
54 
55 typedef struct _fcgi_header {
56 	unsigned char version;
57 	unsigned char type;
58 	unsigned char requestIdB1;
59 	unsigned char requestIdB0;
60 	unsigned char contentLengthB1;
61 	unsigned char contentLengthB0;
62 	unsigned char paddingLength;
63 	unsigned char reserved;
64 } fcgi_header;
65 
66 typedef struct _fcgi_begin_request {
67 	unsigned char roleB1;
68 	unsigned char roleB0;
69 	unsigned char flags;
70 	unsigned char reserved[5];
71 } fcgi_begin_request;
72 
73 typedef struct _fcgi_begin_request_rec {
74 	fcgi_header hdr;
75 	fcgi_begin_request body;
76 } fcgi_begin_request_rec;
77 
78 typedef struct _fcgi_end_request {
79     unsigned char appStatusB3;
80     unsigned char appStatusB2;
81     unsigned char appStatusB1;
82     unsigned char appStatusB0;
83     unsigned char protocolStatus;
84     unsigned char reserved[3];
85 } fcgi_end_request;
86 
87 typedef struct _fcgi_end_request_rec {
88 	fcgi_header hdr;
89 	fcgi_end_request body;
90 } fcgi_end_request_rec;
91 
92 /* FastCGI client API */
93 
94 typedef struct _fcgi_request {
95 	int            listen_socket;
96 #ifdef _WIN32
97 	int            tcp;
98 #endif
99 	int            fd;
100 	int            id;
101 	int            keep;
102 	int            closed;
103 
104 	int            in_len;
105 	int            in_pad;
106 
107 	fcgi_header   *out_hdr;
108 	unsigned char *out_pos;
109 	unsigned char  out_buf[1024*8];
110 	unsigned char  reserved[sizeof(fcgi_end_request_rec)];
111 
112 	HashTable     *env;
113 } fcgi_request;
114 
115 int fcgi_init(void);
116 void fcgi_shutdown(void);
117 int fcgi_is_fastcgi(void);
118 int fcgi_in_shutdown(void);
119 int fcgi_listen(const char *path, int backlog);
120 void fcgi_init_request(fcgi_request *req, int listen_socket);
121 int fcgi_accept_request(fcgi_request *req);
122 int fcgi_finish_request(fcgi_request *req, int force_close);
123 
124 char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
125 char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
126 
127 int fcgi_read(fcgi_request *req, char *str, int len);
128 
129 int fcgi_write(fcgi_request *req, fcgi_request_type type, const char *str, int len);
130 int fcgi_flush(fcgi_request *req, int close);
131 
132 #ifdef PHP_WIN32
133 void fcgi_impersonate(void);
134 #endif
135 
136 void fcgi_set_mgmt_var(const char * name, size_t name_len, const char * value, size_t value_len);
137 void fcgi_free_mgmt_var_cb(void * ptr);
138 
139 /*
140  * Local variables:
141  * tab-width: 4
142  * c-basic-offset: 4
143  * End:
144  * vim600: sw=4 ts=4 fdm=marker
145  * vim<600: sw=4 ts=4
146  */
147