RCFProto
 All Classes Functions Typedefs
HttpConnectFilter.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_HTTPCONNECTFILTER_HPP
20 #define INCLUDE_RCF_HTTPCONNECTFILTER_HPP
21 
22 #include <memory>
23 #include <boost/shared_ptr.hpp>
24 
25 #include <RCF/Filter.hpp>
26 #include <RCF/ByteBuffer.hpp>
27 #include <RCF/HttpFrameFilter.hpp>
28 
29 namespace RCF {
30 
31  class NtlmWrapper;
32 
33  class HttpConnectFilter : public Filter
34  {
35  public:
36 
37  HttpConnectFilter();
38  HttpConnectFilter(const std::string serverAddr, int serverPort);
39 
40  void resetState();
41 
42  void read(
43  const ByteBuffer &byteBuffer,
44  std::size_t bytesRequested);
45 
46  void write(const std::vector<ByteBuffer> &byteBuffers);
47 
48  void onReadCompleted(const ByteBuffer &byteBuffer);
49 
50  void onWriteCompleted(std::size_t bytesTransferred);
51 
52  int getFilterId() const;
53 
54  enum AuthType
55  {
56  AuthType_None,
57  AuthType_Basic,
58  AuthType_Digest,
59  AuthType_Ntlm,
60  AuthType_Negotiate
61  };
62 
63  private:
64 
65  void sendProxyRequest();
66  void tryNextAuthType();
67 
68  void doNtlmHandshake();
69  void doProxyAuthRetry();
70 
71  std::string mServerAddr;
72  int mServerPort;
73 
74  bool mPassThrough;
75 
76  std::vector<ByteBuffer> mOrigWriteBuffers;
77 
78  std::string mHttpProxyRequest;
79  std::string mHttpProxyResponse;
80 
81  HttpMessage mHttpMessage;
82 
83  std::size_t mWritePos;
84  std::size_t mReadPos;
85 
86  std::vector<char> mReadVector;
87 
88  // List of (Auth type, realm) returned by the proxy.
89  std::vector< std::pair<AuthType, std::string> >
90  mProxyAuthTypes;
91 
92  std::size_t mCurrentAuthType;
93 
94  std::auto_ptr<NtlmWrapper> mNtlmWrapper;
95  };
96 
97 } // namespace RCF
98 
99 #endif // ! INCLUDE_RCF_HTTPCONNECTFILTER_HPP