aboutsummaryrefslogtreecommitdiff
path: root/src/experimental/fastcgi.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/experimental/fastcgi.h')
-rw-r--r--src/experimental/fastcgi.h133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/experimental/fastcgi.h b/src/experimental/fastcgi.h
new file mode 100644
index 0000000..d290c40
--- /dev/null
+++ b/src/experimental/fastcgi.h
@@ -0,0 +1,133 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_FAST_CGI_H
9#define BU_FAST_CGI_H
10
11#include "bu/string.h"
12#include "bu/hash.h"
13#include "bu/array.h"
14#include "bu/tcpsocket.h"
15#include "bu/tcpserversocket.h"
16
17namespace Bu
18{
19 class Stream;
20
21 class FastCgi
22 {
23 public:
24 FastCgi( int iPort );
25 FastCgi();
26 virtual ~FastCgi();
27
28 static bool isEmbedded();
29
30 typedef Bu::Hash<Bu::String, Bu::String> StrHash;
31 enum RequestType
32 {
33 typeBeginRequest = 1,
34 typeAbortRequest = 2,
35 typeEndRequest = 3,
36 typeParams = 4,
37 typeStdIn = 5,
38 typeStdOut = 6,
39 typeStdErr = 7,
40 typeData = 8,
41 typeGetValues = 9,
42 typeGetValuesResult = 10
43 };
44
45 enum Role
46 {
47 roleResponder = 1,
48 roleAuthorizer = 2,
49 roleFilter = 3
50 };
51
52 enum Flags
53 {
54 flagsKeepConn = 1
55 };
56
57 enum Status
58 {
59 statusRequestComplete = 0,
60 statusCantMpxConn = 1,
61 statusOverloaded = 2,
62 statusUnknownRole = 3
63 };
64
65 typedef struct {
66 uint8_t uVersion;
67 uint8_t uType;
68 uint16_t uRequestId;
69 uint16_t uContentLength;
70 uint8_t uPaddingLength;
71 uint8_t uReserved;
72 } Record;
73
74 typedef struct {
75 uint16_t uRole;
76 uint8_t uFlags;
77 uint8_t reserved[5];
78 } BeginRequestBody;
79
80 typedef struct {
81 uint32_t uStatus;
82 uint8_t uProtocolStatus;
83 uint8_t reserved[3];
84 } EndRequestBody;
85
86 typedef struct Channel {
87 Channel() : uFlags( 0 ) { }
88 StrHash hParams;
89 Bu::String sStdIn;
90 Bu::String sData;
91 uint8_t uFlags;
92 } Channel;
93
94 enum ChannelFlags
95 {
96 chflgParamsDone = 0x01,
97 chflgStdInDone = 0x02,
98 chflgDataDone = 0x04,
99
100 chflgAllDone = 0x03
101 };
102
103 virtual void run();
104
105 void stopRunning() { bRunning = false; }
106
107 virtual void onInit() { };
108 virtual int onRequest( const StrHash &hParams,
109 const Bu::String &sStdIn, Bu::Stream &sStdOut,
110 Bu::Stream &sStdErr )=0;
111 virtual void onUninit() { };
112
113 private:
114 void read( Bu::TcpSocket &s, Record &r );
115 void read( Bu::TcpSocket &s, BeginRequestBody &b );
116 uint32_t readLen( Bu::TcpSocket &s, uint16_t &uUsed );
117 void readPair( Bu::TcpSocket &s, StrHash &hParams, uint16_t &uUsed );
118
119 void write( Bu::TcpSocket &s, Record r );
120 void write( Bu::TcpSocket &s, EndRequestBody b );
121
122 bool hasChannel( int iChan );
123
124 private:
125 Bu::TcpServerSocket *pSrv;
126 bool bRunning;
127 Bu::Array<Channel *> aChannel;
128 };
129
130 Bu::Formatter &operator<<( Bu::Formatter &f, const Bu::FastCgi::Record &r );
131};
132
133#endif