Added headers
[tpot/pegasus/.git] / src / Pegasus / Protocol / Handler.h
1 //%/////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM\r
4 //\r
5 // Permission is hereby granted, free of charge, to any person obtaining a copy\r
6 // of this software and associated documentation files (the "Software"), to \r
7 // deal in the Software without restriction, including without limitation the \r
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or \r
9 // sell copies of the Software, and to permit persons to whom the Software is\r
10 // furnished to do so, subject to the following conditions:\r
11 // \r
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN \r
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED\r
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT\r
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR \r
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT \r
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN \r
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
20 //\r
21 //==============================================================================\r
22 //\r
23 // Author: Mike Brasher (mbrasher@bmc.com)\r
24 //\r
25 // Modified By:\r
26 //\r
27 //%/////////////////////////////////////////////////////////////////////////////\r
28 \r
29 ////////////////////////////////////////////////////////////////////////////////\r
30 //\r
31 // Handler.h\r
32 //\r
33 //      This handler processes HTTP messages which have the following format:\r
34 //\r
35 //          lines (one or more CRLF-terminated lines)\r
36 //          terminator (CRLF on line by itself)\r
37 //          message-body (optional depending on message type)\r
38 //\r
39 ////////////////////////////////////////////////////////////////////////////////\r
40 \r
41 #ifndef Pegasus_Handler_h\r
42 #define Pegasus_Handler_h\r
43 \r
44 #include <iostream>\r
45 #include <strstream>\r
46 #include <Pegasus/Common/Config.h>\r
47 #include <Pegasus/Common/Array.h>\r
48 #include <Pegasus/Common/String.h>\r
49 #include <Pegasus/Common/Channel.h>\r
50 #include <Pegasus/Common/Logger.h>\r
51 \r
52 PEGASUS_NAMESPACE_BEGIN\r
53 \r
54 class PEGASUS_PROTOCOL_LINKAGE Handler : public ChannelHandler\r
55 {\r
56 public:\r
57 \r
58     Handler();\r
59 \r
60     virtual ~Handler();\r
61 \r
62     virtual Boolean handleOpen(Channel* channel);\r
63 \r
64     virtual Boolean handleInput(Channel* channel);\r
65 \r
66     virtual Boolean handleOutput(Channel* channel);\r
67 \r
68     virtual void handleClose(Channel* channel);\r
69 \r
70     void clear();\r
71 \r
72     void skipWhitespace(const char*& p);\r
73 \r
74     const char* getFieldValue(const char* fieldName) const;\r
75 \r
76     const char* getFieldValueSubString(const char* str) const;\r
77 \r
78     const char* getContent() const;\r
79 \r
80     Uint32 getContentLength() const;\r
81 \r
82     void print() const;\r
83 \r
84     void log() const;\r
85 \r
86     //void logMessage(LogFileType logFileType, String& subsystem, \r
87     //              Uint32 severity, String& formatMsg) const;\r
88 \r
89     virtual int handleMessage();\r
90 \r
91     static void printMessage(PEGASUS_STD(ostream)& os, const Array<Sint8>& message);\r
92 \r
93     static void setMessageTrace(const Boolean flag)\r
94     {\r
95         _messageTrace = flag;\r
96     }\r
97     static void setMessageLogTrace(const Boolean flag)\r
98     {\r
99         _messageLogTrace = flag;\r
100     }\r
101 \r
102     ;\r
103 \r
104 private:\r
105 \r
106     enum State { WAITING, LINES, CONTENT, DONE };\r
107     State _state;\r
108 \r
109 \r
110 protected:\r
111 \r
112     Array<char> _message;\r
113     Array<Uint32> _lines;\r
114     Uint32 _contentOffset;\r
115     Uint32 _contentLength;\r
116     static Boolean _messageTrace;\r
117     static Boolean _messageLogTrace;\r
118 };\r
119 \r
120 PEGASUS_NAMESPACE_END\r
121 \r
122 #endif /* Pegasus_Handler_h */\r