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 <ae@cy.md>
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 /// FastCGI protocol packet header.
22 struct FCGI_RecordHeader
23 {
24 	ubyte version_; /// FastCGI protocol version. Should be FCGI_VERSION_1.
25 	FCGI_RecordType type; /// FastCGI record (packet) type.
26 	BigEndian!ushort requestId; /// Request ID.
27 	BigEndian!ushort contentLength; /// Number of bytes of data following this header.
28 	ubyte paddingLength; /// Number of additional bytes used for padding.
29 	ubyte reserved; /// Unused.
30 }
31 static assert(FCGI_RecordHeader.sizeof == 8);
32 
33 /// Value for version component of FCGI_Header
34 enum FCGI_VERSION_1 = 1;
35 
36 /// Values for type component of FCGI_Header
37 enum FCGI_RecordType : ubyte
38 {
39 	beginRequest    =  1,   /// FCGI_BEGIN_REQUEST     ( webserver-sent                     )
40 	abortRequest    =  2,   /// FCGI_ABORT_REQUEST     ( webserver-sent                     )
41 	endRequest      =  3,   /// FCGI_END_REQUEST
42 	params          =  4,   /// FCGI_PARAMS            ( webserver-sent,             stream )
43 	stdin           =  5,   /// FCGI_STDIN             ( webserver-sent,             stream )
44 	stdout          =  6,   /// FCGI_STDOUT            (                             stream )
45 	stderr          =  7,   /// FCGI_STDERR            (                             stream )
46 	data            =  8,   /// FCGI_DATA              ( webserver-sent,             stream )
47 	getValues       =  9,   /// FCGI_GET_VALUES        ( webserver-sent, management         )
48 	getValuesResult = 10,   /// FCGI_GET_VALUES_RESULT (                 management         )
49 	unknownType     = 11,   /// FCGI_UNKNOWN_TYPE      (                 management         )
50 }
51 
52 /// Value for requestId component of FCGI_Header.
53 enum FCGI_NULL_REQUEST_ID = 0;
54 
55 /// Structure of FCGI_BEGIN_REQUEST packets.
56 struct FCGI_BeginRequestBody
57 {
58 	BigEndian!FCGI_Role role; /// FastCGI application role.
59     FCGI_RequestFlags flags; /// Request flags.
60     ubyte[5] reserved; /// Unused.
61 }
62 
63 /// Mask for flags component of FCGI_BeginRequestBody
64 enum FCGI_RequestFlags : ubyte
65 {
66 	keepConn = 1, /// FCGI_KEEP_CONN
67 }
68 
69 /// Values for role component of FCGI_BeginRequestBody
70 enum FCGI_Role : ushort
71 {
72 	responder  = 1, /// FCGI_RESPONDER
73 	authorizer = 2, /// FCGI_AUTHORIZER
74 	filter     = 3, /// FCGI_FILTER
75 }
76 
77 /// Structure of FCGI_END_REQUEST packets.
78 struct FCGI_EndRequestBody
79 {
80 	BigEndian!uint appStatus; /// Application-supplied status code.
81     FCGI_ProtocolStatus protocolStatus; /// FastCGI status code.
82     ubyte[3] reserved; /// Unused.
83 }
84 
85 /// Values for protocolStatus component of FCGI_EndRequestBody
86 enum FCGI_ProtocolStatus : ubyte
87 {
88 	requestComplete = 0, /// FCGI_REQUEST_COMPLETE
89 	cantMpxConn     = 1, /// FCGI_CANT_MPX_CONN
90 	overloaded      = 2, /// FCGI_OVERLOADED
91 	unknownRole     = 3, /// FCGI_UNKNOWN_ROLE
92 }
93 
94 /// Variable names for FCGI_GET_VALUES / FCGI_GET_VALUES_RESULT records
95 enum FCGI_MAX_CONNS  = "FCGI_MAX_CONNS";
96 enum FCGI_MAX_REQS   = "FCGI_MAX_REQS"; /// ditto
97 enum FCGI_MPXS_CONNS = "FCGI_MPXS_CONNS"; /// ditto
98 
99 /// Structure of FCGI_UNKNOWN_TYPE packets.
100 struct FCGI_UnknownTypeBody
101 {
102     FCGI_RecordType type; /// The record type that was not recognized.
103     ubyte[7] reserved; /// Unused.
104 }