1 /**
2  * FastCGI definitions.
3  *
4  * License:
5  *   This Source Code Form is subject to the terms of
6  *   the Mozilla Public License, v. 2.0. If a copy of
7  *   the MPL was not distributed with this file, You
8  *   can obtain one at http://mozilla.org/MPL/2.0/.
9  *
10  * Authors:
11  *   Vladimir Panteleev <vladimir@thecybershadow.net>
12  */
13 
14 module ae.net.http.fastcgi.common;
15 
16 import ae.utils.bitmanip;
17 
18 /// Listening socket file number
19 enum FCGI_LISTENSOCK_FILENO = /*STDIN_FILENO*/ 0;
20 
21 struct FCGI_RecordHeader
22 {
23 	ubyte version_;
24 	FCGI_RecordType type;
25 	BigEndian!ushort requestId;
26 	BigEndian!ushort contentLength;
27 	ubyte paddingLength;
28 	ubyte reserved;
29 }
30 static assert(FCGI_RecordHeader.sizeof == 8);
31 
32 /// Value for version component of FCGI_Header
33 enum FCGI_VERSION_1 = 1;
34 
35 /// Values for type component of FCGI_Header
36 enum FCGI_RecordType : ubyte
37 {
38 	//                                                   WS->App   management  stream
39 	beginRequest    =  1,   /// FCGI_BEGIN_REQUEST          x
40 	abortRequest    =  2,   /// FCGI_ABORT_REQUEST          x
41 	endRequest      =  3,   /// FCGI_END_REQUEST
42 	params          =  4,   /// FCGI_PARAMS                 x                    x
43 	stdin           =  5,   /// FCGI_STDIN                  x                    x
44 	stdout          =  6,   /// FCGI_STDOUT                                      x
45 	stderr          =  7,   /// FCGI_STDERR                                      x
46 	data            =  8,   /// FCGI_DATA                   x                    x
47 	getValues       =  9,   /// FCGI_GET_VALUES             x          x
48 	getValuesResult = 10,   /// FCGI_GET_VALUES_RESULT                 x
49 	unknownType     = 11,   /// FCGI_UNKNOWN_TYPE                      x
50 }
51 
52 /// Value for requestId component of FCGI_Header
53 enum FCGI_NULL_REQUEST_ID = 0;
54 
55 struct FCGI_BeginRequestBody
56 {
57 	BigEndian!FCGI_Role role;
58     FCGI_RequestFlags flags;
59     ubyte[5] reserved;
60 }
61 
62 /// Mask for flags component of FCGI_BeginRequestBody
63 enum FCGI_RequestFlags : ubyte
64 {
65 	keepConn = 1, /// FCGI_KEEP_CONN
66 }
67 
68 /// Values for role component of FCGI_BeginRequestBody
69 enum FCGI_Role : ushort
70 {
71 	responder  = 1, /// FCGI_RESPONDER
72 	authorizer = 2, /// FCGI_AUTHORIZER
73 	filter     = 3, /// FCGI_FILTER
74 }
75 
76 struct FCGI_EndRequestBody
77 {
78 	BigEndian!uint appStatus;
79     FCGI_ProtocolStatus protocolStatus;
80     ubyte[3] reserved;
81 }
82 
83 /// Values for protocolStatus component of FCGI_EndRequestBody
84 enum FCGI_ProtocolStatus : ubyte
85 {
86 	requestComplete = 0, /// FCGI_REQUEST_COMPLETE
87 	cantMpxConn     = 1, /// FCGI_CANT_MPX_CONN
88 	overloaded      = 2, /// FCGI_OVERLOADED
89 	unknownRole     = 3, /// FCGI_UNKNOWN_ROLE
90 }
91 
92 /// Variable names for FCGI_GET_VALUES / FCGI_GET_VALUES_RESULT records
93 enum FCGI_MAX_CONNS  = "FCGI_MAX_CONNS";
94 enum FCGI_MAX_REQS   = "FCGI_MAX_REQS";
95 enum FCGI_MPXS_CONNS = "FCGI_MPXS_CONNS";
96 
97 struct FCGI_UnknownTypeBody
98 {
99     FCGI_RecordType type;
100     ubyte[7] reserved;
101 }