1 karl 1.36 //%2005////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.29 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.22 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.29 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.36 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 mike 1.2 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
13 kumpf 1.11 // of this software and associated documentation files (the "Software"), to
14 // deal in the Software without restriction, including without limitation the
15 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
16 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
|
18 david.dillard 1.37 //
|
19 kumpf 1.11 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
20 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
21 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
22 kumpf 1.11 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
23 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
25 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 //==============================================================================
29 //
30 // Author: Mike Brasher (mbrasher@bmc.com)
31 //
32 // Modified By:
33 // Nag Boranna, Hewlett-Packard Company(nagaraja_boranna@hp.com)
34 // Jenny Yu, Hewlett-Packard Company (jenny_yu@hp.com)
|
35 brian.campbell 1.27 // Brian G. Campbell, EMC (campbell_brian@emc.com) - PEP140/phase1
|
36 a.arora 1.32 // Amit K Arora, IBM (amita@in.ibm.com) for Bug#1097, #2541
|
37 david.dillard 1.33 // David Dillard, VERITAS Software Corp. (david.dillard@veritas.com)
|
38 kumpf 1.34 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
39 mike 1.2 //
40 //%/////////////////////////////////////////////////////////////////////////////
41
42 #ifndef Pegasus_HTTPConnection_h
43 #define Pegasus_HTTPConnection_h
44
45 #include <iostream>
|
46 brian.campbell 1.27 #include <Pegasus/Common/Exception.h>
|
47 mike 1.2 #include <Pegasus/Common/Config.h>
48 #include <Pegasus/Common/MessageQueue.h>
49 #include <Pegasus/Common/Pair.h>
50 #include <Pegasus/Common/String.h>
51 #include <Pegasus/Common/Message.h>
|
52 kumpf 1.14 #include <Pegasus/Common/ArrayInternal.h>
|
53 mike 1.2 #include <Pegasus/Common/Monitor.h>
54 #include <Pegasus/Common/AuthenticationInfo.h>
55 #include <Pegasus/Common/TLS.h>
56 #include <Pegasus/Common/HTTPAcceptor.h>
|
57 kumpf 1.13 #include <Pegasus/Common/Linkage.h>
|
58 a.arora 1.25 #include <Pegasus/Common/AutoPtr.h>
|
59 brian.campbell 1.31 #include <Pegasus/Common/ContentLanguages.h>
|
60 mike 1.2
61 PEGASUS_NAMESPACE_BEGIN
62
|
63 mday 1.12 class HTTPConnector;
64
|
65 mday 1.3 class MessageQueueService;
|
66 mday 1.16
|
67 mike 1.2 struct HTTPConnectionRep;
68
69 /** This message is sent from a connection to its owner (so that the
70 owner can do any necessary cleanup).
71 */
72 class CloseConnectionMessage : public Message
73 {
|
74 kumpf 1.39 public:
|
75 mike 1.2
|
76 kumpf 1.39 CloseConnectionMessage(Sint32 socket_)
77 : Message(CLOSE_CONNECTION_MESSAGE), socket(socket_) { }
|
78 mike 1.2
|
79 kumpf 1.39 Sint32 socket;
|
80 mike 1.2 };
81
82 /** This class represents an HTTP listener.
83 */
|
84 mday 1.15 class Monitor;
85
|
86 mday 1.5 class PEGASUS_COMMON_LINKAGE HTTPConnection : public MessageQueue
|
87 mike 1.2 {
|
88 kumpf 1.39 public:
89 typedef MessageQueue Base;
|
90 david.dillard 1.37
|
91 kumpf 1.39 /** Constructor. */
92 HTTPConnection(
|
93 david.dillard 1.38 Monitor* monitor,
94 AutoPtr<MP_Socket>& socket,
95 MessageQueue * ownerMessageQueue,
96 MessageQueue * outputMessageQueue,
97 Boolean exportConnection);
|
98 david.dillard 1.37
|
99 mday 1.4
|
100 kumpf 1.39 /** Destructor. */
101 ~HTTPConnection();
|
102 mday 1.4
|
103 kumpf 1.39 /** This method is called whenever a SocketMessage is enqueued
104 on the input queue of the HTTPConnection object.
105 */
106 virtual void handleEnqueue(Message *);
|
107 brian.campbell 1.30
|
108 kumpf 1.39 virtual void handleEnqueue();
|
109 brian.campbell 1.31
|
110 kumpf 1.39 /** Return socket this connection is using. */
111 Sint32 getSocket() { return _socket->getSocket();}
|
112 mike 1.2
|
113 kumpf 1.39 MP_Socket& getMPSocket() { return *_socket;}
|
114 mike 1.2
|
115 kumpf 1.39 /** Return the number of outstanding requests for all HTTPConnection
116 instances.
117 */
118 Uint32 getRequestCount();
119
120 Boolean run(Uint32 milliseconds);
121
122 MessageQueue & get_owner(void)
123 {
124 return *_ownerMessageQueue;
125 }
126
127 // was the request for chunking ?
128 Boolean isChunkRequested();
129
130 // ATTN-RK-P1-20020521: This is a major hack, required to get the CIM
131 // server and tests to run successfully. The problem is that the
132 // HTTPAcceptor is deleting an HTTPConnection before all the threads
133 // that are queued up to run in that HTTPConnection instance have had
134 // a chance to finish. This hack makes the HTTPAcceptor spin until
135 // the HTTPConnection event threads have completed, before deleting
136 kumpf 1.39 // the HTTPConnection. Note that this fix is not perfect, because
137 // there is a window between when the HTTPConnection queue lookup is
138 // done and when the refcount is incremented. If the HTTPAcceptor
139 // deletes the HTTPConnection in that window, the soon-to-be-launched
140 // HTTPConnection event thread will fail (hard).
141 AtomicInt refcount;
142
143 CIMException cimException;
144
145 // list of content languages
146 ContentLanguages contentLanguages;
147
148 private:
149
150 void _clearIncoming();
151
152 /**
|
153 david.dillard 1.37 @exception Exception Indicates an error occurred.
|
154 kumpf 1.39 */
155 void _getContentLengthAndContentOffset();
|
156 mike 1.2
|
157 kumpf 1.39 void _closeConnection();
|
158 mike 1.2
|
159 kumpf 1.39 void _handleReadEvent();
|
160 mike 1.2
|
161 kumpf 1.39 Boolean _handleWriteEvent(Message &message);
|
162 brian.campbell 1.27
|
163 kumpf 1.39 void _handleReadEventFailure(String &httpStatusWithDetail,
164 String cimError = String());
165 void _handleReadEventTransferEncoding();
166 Boolean _isClient();
167
168 Monitor* _monitor;
169
170 AutoPtr<MP_Socket> _socket;
171 MessageQueue* _ownerMessageQueue;
172 MessageQueue* _outputMessageQueue;
173
174 Sint32 _contentOffset;
175 Sint32 _contentLength;
176 Array<char> _incomingBuffer;
177 AutoPtr<AuthenticationInfo> _authInfo;
178 static AtomicInt _requestCount;
179
180 // _connectionRequestCount contains the number of
181 // requests that have been received on this connection.
182 Uint32 _connectionRequestCount;
183
184 kumpf 1.39 // The _responsePending flag has been added to help
185 // isolate "client connection" problems. When the
186 // HTTPConnection object is created, this flag is
187 // initialized to false. It is set to true when a
188 // request is received on the connection and set to
189 // false when a response is sent. If _responsePending
190 // is true when a close connection request is processed,
191 // a "DISCARDED_DATA" trace entry will be written.
192 Boolean _responsePending;
193
194 Mutex _connection_mut;
195
196 // The _connectionClosePending flag will be set to true if
197 // the connection receives a close connection socket message.
198 // This flag is used to set the connection status to
199 // either Monitor::IDLE (_connectionClosePending == false)
200 // or Monitor::DYING (_connectionClosePending == true) when
201 // returning control of the connection to the Monitor.
202 Boolean _connectionClosePending;
203
|
204 kumpf 1.40 // The _acceptPending flag is set to true if a server-side
205 // connection is accepted but an SSL handshake has not been
206 // completed.
207 Boolean _acceptPending;
208
|
209 kumpf 1.39 int _entry_index;
210
211 // When used by the client, it is an offset (from start of http message)
212 // representing last NON completely parsed chunk of a transfer encoding.
213 // When used by the server, it is the message index that comes down
214 // from the providers/repository representing each message chunk
215 Uint32 _transferEncodingChunkOffset;
216
217 // list of transfer encoding values from sender
218 Array<String> _transferEncodingValues;
219
220 // list of TE values from client
221 Array<String> _transferEncodingTEValues;
222
223 // 2 digit prefix on http header if mpost was used
224 String _mpostPrefix;
225
226 friend class Monitor;
227 friend class HTTPAcceptor;
228 friend class HTTPConnector;
|
229 mike 1.2 };
|
230 mday 1.16
|
231 mike 1.2 PEGASUS_NAMESPACE_END
232
233 #endif /* Pegasus_HTTPConnection_h */
|