summaryrefslogtreecommitdiff
path: root/src/fastcgi.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fastcgi.h')
-rw-r--r--src/fastcgi.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/fastcgi.h b/src/fastcgi.h
new file mode 100644
index 0000000..83e9b83
--- /dev/null
+++ b/src/fastcgi.h
@@ -0,0 +1,120 @@
1#ifndef BU_FAST_CGI_H
2#define BU_FAST_CGI_H
3
4#include "bu/fstring.h"
5#include "bu/hash.h"
6#include "bu/array.h"
7#include "bu/socket.h"
8#include "bu/serversocket.h"
9
10namespace Bu
11{
12 class Stream;
13
14 class FastCgi
15 {
16 public:
17 FastCgi( int iPort );
18 FastCgi();
19 virtual ~FastCgi();
20
21 static bool isEmbedded();
22
23 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
24 enum RequestType
25 {
26 typeBeginRequest = 1,
27 typeAbortRequest = 2,
28 typeEndRequest = 3,
29 typeParams = 4,
30 typeStdIn = 5,
31 typeStdOut = 6,
32 typeStdErr = 7,
33 typeData = 8,
34 typeGetValues = 9,
35 typeGetValuesResult = 10
36 };
37
38 enum Role
39 {
40 roleResponder = 1,
41 roleAuthorizer = 2,
42 roleFilter = 3
43 };
44
45 enum Flags
46 {
47 flagsKeepConn = 1
48 };
49
50 enum Status
51 {
52 statusRequestComplete = 0,
53 statusCantMpxConn = 1,
54 statusOverloaded = 2,
55 statusUnknownRole = 3
56 };
57
58 typedef struct {
59 uint8_t uVersion;
60 uint8_t uType;
61 uint16_t uRequestId;
62 uint16_t uContentLength;
63 uint8_t uPaddingLength;
64 uint8_t uReserved;
65 } Record;
66
67 typedef struct {
68 uint16_t uRole;
69 uint8_t uFlags;
70 uint8_t reserved[5];
71 } BeginRequestBody;
72
73 typedef struct {
74 uint32_t uStatus;
75 uint8_t uProtocolStatus;
76 uint8_t reserved[3];
77 } EndRequestBody;
78
79 typedef struct Channel {
80 Channel() : uFlags( 0 ) { }
81 StrHash hParams;
82 Bu::FString sStdIn;
83 Bu::FString sData;
84 uint8_t uFlags;
85 } Channel;
86
87 enum ChannelFlags
88 {
89 chflgParamsDone = 0x01,
90 chflgStdInDone = 0x02,
91 chflgDataDone = 0x04,
92
93 chflgAllDone = 0x03
94 };
95
96 virtual void run();
97
98 virtual void init() { };
99 virtual int request( const StrHash &hParams,
100 const Bu::FString &sStdIn, Bu::Stream &sStdOut,
101 Bu::Stream &sStdErr )=0;
102 virtual void deinit() { };
103
104 private:
105 void read( Bu::Socket &s, Record &r );
106 void read( Bu::Socket &s, BeginRequestBody &b );
107 uint32_t readLen( Bu::Socket &s, uint16_t &uUsed );
108 void readPair( Bu::Socket &s, StrHash &hParams, uint16_t &uUsed );
109
110 void write( Bu::Socket &s, Record r );
111 void write( Bu::Socket &s, EndRequestBody b );
112
113 private:
114 Bu::ServerSocket *pSrv;
115 bool bRunning;
116 Bu::Array<Channel *> aChannel;
117 };
118};
119
120#endif