aboutsummaryrefslogtreecommitdiff
path: root/src/stable/protocolhttp.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/stable/protocolhttp.h146
1 files changed, 73 insertions, 73 deletions
diff --git a/src/stable/protocolhttp.h b/src/stable/protocolhttp.h
index 87dc49b..51ca58c 100644
--- a/src/stable/protocolhttp.h
+++ b/src/stable/protocolhttp.h
@@ -18,89 +18,89 @@
18 18
19namespace Bu 19namespace Bu
20{ 20{
21 /** 21 /**
22 * An HTTP Protocol handler. Yes, I know that HTTP stands for Hyper Text 22 * An HTTP Protocol handler. Yes, I know that HTTP stands for Hyper Text
23 * Transfer Protocol, and that the Protocol part is redundant, but in this 23 * Transfer Protocol, and that the Protocol part is redundant, but in this
24 * case the word Protocol is refering to the Libbu++ construct Bu::Protocol, 24 * case the word Protocol is refering to the Libbu++ construct Bu::Protocol,
25 * and not a means of encoding conversations. Anyway, this class represents 25 * and not a means of encoding conversations. Anyway, this class represents
26 * a general HTTP server processor. Every time a request comes in it calls 26 * a general HTTP server processor. Every time a request comes in it calls
27 * the onRequest function in a subclass with the method and URI that were 27 * the onRequest function in a subclass with the method and URI that were
28 * requested. The sub-class can then do whatever it needs to to send back 28 * requested. The sub-class can then do whatever it needs to to send back
29 * a response. 29 * a response.
30 *@ingroup Serving 30 *@ingroup Serving
31 */ 31 */
32 class ProtocolHttp : public Protocol 32 class ProtocolHttp : public Protocol
33 { 33 {
34 public: /* Types */ 34 public: /* Types */
35 typedef Bu::List<Bu::String> TokenList; 35 typedef Bu::List<Bu::String> TokenList;
36 36
37 public: /* Interface */ 37 public: /* Interface */
38 ProtocolHttp(); 38 ProtocolHttp();
39 virtual ~ProtocolHttp(); 39 virtual ~ProtocolHttp();
40 40
41 virtual void onNewConnection( Bu::Client *pClient ); 41 virtual void onNewConnection( Bu::Client *pClient );
42 virtual void onNewData( Bu::Client *pClient ); 42 virtual void onNewData( Bu::Client *pClient );
43 43
44 virtual void onRequest( 44 virtual void onRequest(
45 const Bu::String &sMethod, const Bu::String &sPath )=0; 45 const Bu::String &sMethod, const Bu::String &sPath )=0;
46 46
47 class Response 47 class Response
48 { 48 {
49 friend class Bu::ProtocolHttp; 49 friend class Bu::ProtocolHttp;
50 public: 50 public:
51 Response( int iCode ); 51 Response( int iCode );
52 Response( int iCode, const Bu::String &sReason ); 52 Response( int iCode, const Bu::String &sReason );
53 virtual ~Response(); 53 virtual ~Response();
54 54
55 void setHeader( const Bu::String &sKey, const Bu::String &sVal ); 55 void setHeader( const Bu::String &sKey, const Bu::String &sVal );
56 void setContent( const Bu::String &sCont ); 56 void setContent( const Bu::String &sCont );
57 57
58 private: 58 private:
59 int iCode; 59 int iCode;
60 Bu::String sReason; 60 Bu::String sReason;
61 typedef Bu::Hash<Bu::String,Bu::String> StringHash; 61 typedef Bu::Hash<Bu::String,Bu::String> StringHash;
62 StringHash hHeaders; 62 StringHash hHeaders;
63 Bu::String sContent; 63 Bu::String sContent;
64 }; 64 };
65 65
66 void sendResponse( const Response &rRes ); 66 void sendResponse( const Response &rRes );
67 67
68 private: 68 private:
69 enum TokenType 69 enum TokenType
70 { 70 {
71 ttOutOfData, 71 ttOutOfData,
72 ttString, 72 ttString,
73 ttNewline, 73 ttNewline,
74 ttDoubleNewline, 74 ttDoubleNewline,
75 ttSeperator 75 ttSeperator
76 }; 76 };
77 /** 77 /**
78 * Read an HTTP line, this is up to the first CRLF that isn't followed 78 * Read an HTTP line, this is up to the first CRLF that isn't followed
79 * by a continuation character, converting it to one line as it reads. 79 * by a continuation character, converting it to one line as it reads.
80 *@param line All data read will be appended to line, even if no 80 *@param line All data read will be appended to line, even if no
81 * end-of-line is read. 81 * end-of-line is read.
82 *@returns True if an end-of-line is read and the line should be 82 *@returns True if an end-of-line is read and the line should be
83 * processed, false if the end-of-line has not been reached, and more 83 * processed, false if the end-of-line has not been reached, and more
84 * data needs to be read before this operation can continue. 84 * data needs to be read before this operation can continue.
85 */ 85 */
86 TokenType getToken( Bu::String &line ); 86 TokenType getToken( Bu::String &line );
87 bool isWS( char buf ); 87 bool isWS( char buf );
88 bool isSeperator( char buf ); 88 bool isSeperator( char buf );
89 89
90 void earlyResponse(); 90 void earlyResponse();
91 void lateResponse(); 91 void lateResponse();
92 92
93 private: /* state */ 93 private: /* state */
94 Bu::Client *pClient; 94 Bu::Client *pClient;
95 TokenList lTokens; 95 TokenList lTokens;
96 96
97 int iState; 97 int iState;
98 98
99 Bu::String sMethod; 99 Bu::String sMethod;
100 Bu::String sPath; 100 Bu::String sPath;
101 int iMajor; 101 int iMajor;
102 int iMinor; 102 int iMinor;
103 }; 103 };
104} 104}
105 105
106#endif 106#endif