00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #ifndef OW_HTTPSVRCONNECTION_HPP_INCLUDE_GUARD_
00037 #define OW_HTTPSVRCONNECTION_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Runnable.hpp"
00040 #include "OW_Mutex.hpp"
00041 #include "OW_MutexLock.hpp"
00042 #include "OW_String.hpp"
00043 #include "OW_HTTPServer.hpp"
00044 #include "OW_HTTPStatusCodes.hpp"
00045 #include "OW_Socket.hpp"
00046 #include "OW_HTTPUtils.hpp"
00047 #include "OW_RequestHandlerIFC.hpp"
00048 #include "OW_CIMProtocolIStreamIFC.hpp"
00049 #include "OW_CommonFwd.hpp"
00050 #include "OW_HttpCommonFwd.hpp"
00051 #include "OW_Reference.hpp"
00052 #include <iosfwd>
00053 #include <fstream>
00054
00055 namespace OW_NAMESPACE
00056 {
00057
00058 class OW_HTTPSVC_API HTTPSvrConnection: public Runnable
00059 {
00060 public:
00061 #ifdef OW_WIN32
00062
00070 HTTPSvrConnection(const Socket& socket, HTTPServer* htin,
00071 HANDLE eventArg, const HTTPServer::Options& opts);
00072 #else
00073
00081 HTTPSvrConnection(const Socket& socket, HTTPServer* htin,
00082 UnnamedPipeRef& upipe,
00083 const HTTPServer::Options& opts);
00084 #endif
00085
00086 ~HTTPSvrConnection();
00090 virtual void run();
00091
00097 bool headerHasKey(const String& key) const
00098 {
00099 return HTTPUtils::headerHasKey(m_requestHeaders, key);
00100 }
00106 String getHeaderValue(const String& key) const
00107 {
00108 return HTTPUtils::getHeaderValue(m_requestHeaders, key);
00109 }
00115 void addHeader(const String& key, const String& value)
00116 {
00117 HTTPUtils::addHeader(m_responseHeaders, key, value);
00118 }
00124 StringArray getRequestLine() const { return m_requestLine; }
00135 void setErrorDetails(const String& details) { m_errDetails = details; }
00136
00140 String getHostName();
00141 protected:
00142 private:
00143
00144 #ifdef OW_WIN32
00145 #pragma warning (push)
00146 #pragma warning (disable: 4251)
00147 #endif
00148
00149 enum requestMethod_t
00150 {
00151 BAD = 0,
00152 POST,
00153 M_POST,
00154 TRACE,
00155 OPTIONS
00156 };
00157 enum httpVerFlag_t
00158 {
00159 HTTP_VER_BAD = 0,
00160 HTTP_VER_10,
00161 HTTP_VER_11
00162 };
00163 StringArray m_requestLine;
00164 HTTPHeaderMap m_requestHeaders;
00165 HTTPServer* m_pHTTPServer;
00166 std::istream* m_pIn;
00167 std::ofstream m_tempFile;
00168 Socket m_socket;
00169 std::ostream& m_ostr;
00170 int m_resCode;
00171 bool m_needSendError;
00172 Array<String> m_responseHeaders;
00173 httpVerFlag_t m_httpVersion;
00174 requestMethod_t m_method;
00175 std::istream& m_istr;
00176 bool m_isClose;
00177 Int64 m_contentLength;
00178 bool m_chunkedIn;
00179 bool m_deflateCompressionIn;
00180 bool m_deflateCompressionOut;
00181 String m_errDetails;
00182 String m_reqHeaderPrefix;
00183 String m_respHeaderPrefix;
00184 bool m_isAuthenticated;
00185 #ifdef OW_WIN32
00186 HANDLE m_event;
00187 #else
00188 IntrusiveReference<UnnamedPipe> m_upipe;
00189 #endif
00190 bool m_chunkedOut;
00191 String m_userName;
00192 bool m_clientIsOpenWBEM2;
00193
00194 RequestHandlerIFCRef m_requestHandler;
00195 HTTPServer::Options m_options;
00196 bool m_shutdown;
00197
00198
00199
00200 Reference<HTTPChunkedOStream> m_HTTPChunkedOStreamRef;
00201 #ifdef OW_HAVE_ZLIB_H
00202 Reference<HTTPDeflateOStream> m_HTTPDeflateOStreamRef;
00203 #endif
00204
00205 Reference<TempFileStream> m_TempFileStreamRef;
00206
00207 #ifdef OW_WIN32
00208 #pragma warning (pop)
00209 #endif
00210
00211 int processRequestLine();
00212 int processHeaders(OperationContext& context);
00213 void trace();
00214 void options(OperationContext& context);
00215 void post(std::istream& istr, OperationContext& context);
00216 void sendError(int resCode);
00217 void beginPostResponse();
00218 void initRespStream(std::ostream*& ostrEntity);
00219 void sendPostResponse(std::ostream* ostrEntity,
00220 TempFileStream& ostrError, OperationContext& context);
00221 int performAuthentication(const String& info, OperationContext& context);
00222 void sendHeaders(int sc, int len = -1);
00223 void cleanUpIStreams(const CIMProtocolIStreamIFCRef& istrm);
00224 CIMProtocolIStreamIFCRef convertToFiniteStream(
00225 std::istream& istr);
00226 String getContentLanguage(OperationContext& context, bool& setByProvider,
00227 bool& clientSpecified);
00228
00229 void doCooperativeCancel();
00230 };
00231
00232 }
00233
00234 #endif