OW_HTTPSvrConnection.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
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    // these are public so that authentication modules can access them.
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    // Don't switch the order of the next 2 member vars. The order is important, since Deflate may hold a pointer to Chunked,
00199    // and it's destructor may call functions on Chunked. Yeah, this is a BAD design!
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 } // end namespace OW_NAMESPACE
00233 
00234 #endif

Generated on Thu Feb 9 08:48:00 2006 for openwbem by  doxygen 1.4.6