gloox  0.9.9.12
connectionhttpproxy.h
1 /*
2  Copyright (c) 2004-2008 by Jakob Schroeter <js@camaya.net>
3  This file is part of the gloox library. http://camaya.net/gloox
4 
5  This software is distributed under a license. The full license
6  agreement can be found in the file LICENSE in this distribution.
7  This software may not be copied, modified, sold or distributed
8  other than expressed in the named license agreement.
9 
10  This software is distributed without any warranty.
11 */
12 
13 
14 #ifndef CONNECTIONHTTPPROXY_H__
15 #define CONNECTIONHTTPPROXY_H__
16 
17 #include "gloox.h"
18 #include "connectionbase.h"
19 #include "logsink.h"
20 
21 #include <string>
22 
23 namespace gloox
24 {
25 
47  class GLOOX_API ConnectionHTTPProxy : public ConnectionBase, public ConnectionDataHandler
48  {
49  public:
63  ConnectionHTTPProxy( ConnectionBase *connection, const LogSink& logInstance,
64  const std::string& server, int port = -1 );
65 
78  const LogSink& logInstance,
79  const std::string& server, int port = -1 );
80 
84  virtual ~ConnectionHTTPProxy();
85 
86  // reimplemented from ConnectionBase
87  virtual ConnectionError connect();
88 
89  // reimplemented from ConnectionBase
90  virtual ConnectionError recv( int timeout = -1 );
91 
92  // reimplemented from ConnectionBase
93  virtual bool send( const std::string& data );
94 
95  // reimplemented from ConnectionBase
96  virtual ConnectionError receive();
97 
98  // reimplemented from ConnectionBase
99  virtual void disconnect();
100 
101  // reimplemented from ConnectionBase
102  virtual void cleanup();
103 
104  // reimplemented from ConnectionBase
105  virtual void getStatistics( int &totalIn, int &totalOut );
106 
107  // reimplemented from ConnectionDataHandler
108  virtual void handleReceivedData( const ConnectionBase* connection, const std::string& data );
109 
110  // reimplemented from ConnectionDataHandler
111  virtual void handleConnect( const ConnectionBase* connection );
112 
113  // reimplemented from ConnectionDataHandler
114  virtual void handleDisconnect( const ConnectionBase* connection, ConnectionError reason );
115 
116  // reimplemented from ConnectionDataHandler
117  virtual ConnectionBase* newInstance() const;
118 
125  void setServer( const std::string& host, int port = -1 )
126  { m_server = host; m_port = port; }
127 
133  void setProxyAuth( const std::string& user, const std::string& password )
134  { m_proxyUser = user; m_proxyPassword = password; }
135 
140  void setConnectionImpl( ConnectionBase* connection );
141 
147  void setHTTP11( bool http11 ) { m_http11 = http11; }
148 
149  private:
150  ConnectionHTTPProxy &operator=( const ConnectionHTTPProxy& );
151 
152  ConnectionBase *m_connection;
153  const LogSink& m_logInstance;
154 
155  std::string m_proxyUser;
156  std::string m_proxyPassword;
157  std::string m_proxyHandshakeBuffer;
158 
159  bool m_http11;
160 
161  };
162 
163 }
164 
165 #endif // CONNECTIONHTTPPROXY_H__