ConnectionSOCKS5Proxy Class Reference

`#include <connectionsocks5proxy.h>`

Inheritance diagram for ConnectionSOCKS5Proxy:
[legend]

## Public Member Functions

| ConnectionSOCKS5Proxy (ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1, bool ip=false)
| ConnectionSOCKS5Proxy (ConnectionDataHandler *cdh, ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1, bool ip=false)
virtual | ~ConnectionSOCKS5Proxy ()
virtual ConnectionError | connect ()
virtual ConnectionError | recv (int timeout=-1)
virtual bool | send (const std::string &data)
virtual ConnectionError | receive ()
virtual void | disconnect ()
virtual void | cleanup ()
virtual void | getStatistics (long int &totalIn, long int &totalOut)
virtual void | handleReceivedData (const ConnectionBase *connection, const std::string &data)
virtual void | handleConnect (const ConnectionBase *connection)
virtual void | handleDisconnect (const ConnectionBase *connection, ConnectionError reason)
virtual ConnectionBase * | newInstance () const
void | setServer (const std::string &host, int port=-1, bool ip=false)
void | setProxyAuth (const std::string &user, const std::string &password)
void | setConnectionImpl (ConnectionBase *connection)
Public Member Functions inherited from ConnectionBase
| ConnectionBase (ConnectionDataHandler *cdh)
virtual | ~ConnectionBase ()
ConnectionState | state () const
void | registerConnectionDataHandler (ConnectionDataHandler *cdh)
void | setServer (const std::string &server, int port=-1)
const std::string & | server () const
int | port () const
virtual int | localPort () const
virtual const std::string | localInterface () const
Public Member Functions inherited from ConnectionDataHandler
virtual | ~ConnectionDataHandler ()

## Additional Inherited Members

Protected Attributes inherited from ConnectionBase
ConnectionDataHandler * | m_handler
ConnectionState | m_state
std::string | m_server
int | m_port

## Detailed Description

This is an implementation of a simple SOCKS5 Proxying connection (RFC 1928 + RFC 1929).

To use with a SOCKS5 proxy:

Client* c = new Client( ... );
c->setConnectionImpl( new ConnectionSOCKS5Proxy( c,
new ConnectionTCPClient( c->logInstance(), proxyHost, proxyPort ),
c->logInstance(), xmppHost, xmppPort ) );
gloox::ClientBase::logInstance
LogSink & logInstance()
Definition clientbase.h:599
gloox::ClientBase::setConnectionImpl
void setConnectionImpl(ConnectionBase *cb)
Definition clientbase.cpp:1199
gloox::Client
This class implements a basic Jabber/XMPP Client.
Definition client.h:117
gloox::ConnectionSOCKS5Proxy::ConnectionSOCKS5Proxy
ConnectionSOCKS5Proxy(ConnectionBase *connection, const LogSink &logInstance, const std::string &server, int port=-1, bool ip=false)
Definition connectionsocks5proxy.cpp:44
gloox::ConnectionTCPClient
This is an implementation of a simple TCP connection.
Definition connectiontcpclient.h:37

Make sure to pass the proxy host/port to the transport connection (ConnectionTCPClient in this case), and the XMPP host/port to the proxy connection.

The reason why ConnectionSOCKS5Proxy doesn't manage its own ConnectionTCPClient is that it allows it to be used with other transports (like IPv6 or chained HTTP/SOCKS5 proxies).

Note
  This class is also used by the SOCKS5 bytestreams implementation (with slightly different semantics).
  Simple plain-text username/password authentication is supported. GSSAPI authentication is not supported.

Author
  Jakob Schröter js@ca.nosp@m.maya.nosp@m..net

Since
  0.9

Definition at line 53 of file connectionsocks5proxy.h.

## Constructor & Destructor Documentation

## ConnectionSOCKS5Proxy() [1/2]

ConnectionSOCKS5Proxy | ( | ConnectionBase * | connection,
|  | const LogSink & | logInstance,
|  | const std::string & | server,
|  | int | port = -1,
|  | bool | ip = false )

Constructs a new ConnectionSOCKS5Proxy object.

Parameters

  connection | A transport connection. It should be configured to connect to the proxy host and port, not to the (XMPP) host. ConnectionSOCKS5Proxy will own the transport connection and delete it in its destructor.
  logInstance | The log target. Obtain it from ClientBase::logInstance().
  server | A server to connect to. This is the XMPP server's address, not the proxy.
  port | The proxy's port to connect to. This is the (XMPP) server's port, not the proxy's. The default of -1 means that SRV records will be used to find out about the actual host:port.
  ip | Indicates whether `server` is an IP address (true) or a host name (false).

Note
  To properly use this object, you have to set a ConnectionDataHandler using registerConnectionDataHandler(). This is not necessary if this object is part of a 'connection chain', e.g. with ConnectionHTTPProxy.

Definition at line 44 of file connectionsocks5proxy.cpp.

## ConnectionSOCKS5Proxy() [2/2]

ConnectionSOCKS5Proxy | ( | ConnectionDataHandler * | cdh,
|  | ConnectionBase * | connection,
|  | const LogSink & | logInstance,
|  | const std::string & | server,
|  | int | port = -1,
|  | bool | ip = false )

Constructs a new ConnectionSOCKS5Proxy object.

Parameters

  cdh | A ConnectionDataHandler-derived object that will handle incoming data.
  connection | A transport connection. It should be configured to connect to the proxy host and port, not to the (XMPP) host. ConnectionSOCKS5Proxy will own the transport connection and delete it in its destructor.
  logInstance | The log target. Obtain it from ClientBase::logInstance().
  server | A server to connect to. This is the XMPP server's address, not the proxy.
  port | The proxy's port to connect to. This is the (XMPP) server's port, not the proxy's. The default of -1 means that SRV records will be used to find out about the actual host:port.
  ip | Indicates whether `server` is an IP address (true) or a host name (false).

Definition at line 59 of file connectionsocks5proxy.cpp.

## ~ConnectionSOCKS5Proxy()

~ConnectionSOCKS5Proxy | ( |  | ) |

virtual

Virtual destructor

Definition at line 75 of file connectionsocks5proxy.cpp.

## Member Function Documentation

## cleanup()

void cleanup | ( |  | ) |

virtual

This function is called after a disconnect to clean up internal state. It is also called by ConnectionBase's destructor.

Reimplemented from ConnectionBase.

Definition at line 155 of file connectionsocks5proxy.cpp.

## connect()

ConnectionError connect | ( |  | ) |

virtual

Used to initiate the connection.

Returns
  Returns the connection state.

Implements ConnectionBase.

Definition at line 95 of file connectionsocks5proxy.cpp.

## disconnect()

void disconnect | ( |  | ) |

virtual

Disconnects an established connection. NOOP if no active connection exists.

Implements ConnectionBase.

Definition at line 115 of file connectionsocks5proxy.cpp.

## getStatistics()

void getStatistics | ( | long int & | totalIn,
|  | long int & | totalOut )

virtual

Returns current connection statistics.

Parameters

  totalIn | The total number of bytes received.
  totalOut | The total number of bytes sent.

Implements ConnectionBase.

Definition at line 164 of file connectionsocks5proxy.cpp.

## handleConnect()

void handleConnect | ( | const ConnectionBase * | connection | ) |

virtual

This function is called when e.g. the raw TCP connection was established.

Parameters

  connection | The connection.

Implements ConnectionDataHandler.

Definition at line 339 of file connectionsocks5proxy.cpp.

## handleDisconnect()

void handleDisconnect | ( | const ConnectionBase * | connection,
|  | ConnectionError | reason )

virtual

This connection is called when e.g. the raw TCP connection was closed.

Parameters

  connection | The connection.
  reason | The reason for the disconnect.

Implements ConnectionDataHandler.

Definition at line 376 of file connectionsocks5proxy.cpp.

## handleReceivedData()

void handleReceivedData | ( | const ConnectionBase * | connection,
|  | const std::string & | data )

virtual

This function is called for received from the underlying transport.

Parameters

  connection | The connection that received the data.
  data | The data received.

Implements ConnectionDataHandler.

Definition at line 175 of file connectionsocks5proxy.cpp.

## newInstance()

ConnectionBase * newInstance | ( |  | ) | const

virtual

This function returns a new instance of the current ConnectionBase-derived object. The idea is to be able to 'clone' ConnectionBase-derived objects without knowing of what type they are exactly.

Returns
  A new Connection* instance.

Implements ConnectionBase.

Definition at line 81 of file connectionsocks5proxy.cpp.

## receive()

ConnectionError receive | ( |  | ) |

virtual

Use this function to put the connection into 'receive mode', i.e. this function returns only when the connection is terminated.

Returns
  Returns a value indicating the disconnection reason.

Implements ConnectionBase.

Definition at line 130 of file connectionsocks5proxy.cpp.

## recv()

ConnectionError recv | ( | int | timeout = -1 | ) |

virtual

Use this periodically to receive data from the socket.

Parameters

  timeout | The timeout to use for select in microseconds. Default of -1 means blocking.

Returns
  The state of the connection.

Implements ConnectionBase.

Definition at line 122 of file connectionsocks5proxy.cpp.

## send()

bool send | ( | const std::string & | data | ) |

virtual

Use this function to send a string of data over the wire. The function returns only after all data has been sent.

Parameters

  data | The data to send.

Returns
  True if the data has been sent (no guarantee of receipt), false in case of an error.

Implements ConnectionBase.

Definition at line 138 of file connectionsocks5proxy.cpp.

## setConnectionImpl()

void setConnectionImpl | ( | ConnectionBase * | connection | ) |

Sets the underlying transport connection. A possibly existing connection will be deleted.

Parameters

  connection | The ConnectionBase to replace the current connection, if any.

Definition at line 87 of file connectionsocks5proxy.cpp.

## setProxyAuth()

void setProxyAuth | ( | const std::string & | user,
|  | const std::string & | password )

inline

Sets proxy authorization credentials.

Parameters

  user | The user name to use for proxy authorization.
  password | The password to use for proxy authorization.

Definition at line 142 of file connectionsocks5proxy.h.

## setServer()

void setServer | ( | const std::string & | host,
|  | int | port = -1,
|  | bool | ip = false )

inline

Sets the server to proxy to.

Parameters

  host | The server hostname (IP address).
  port | The server port. The default of -1 means that SRV records will be used to find out about the actual host:port.
  ip | Indicates whether `host` is an IP address (true) or a host name (false).

Definition at line 134 of file connectionsocks5proxy.h.

The documentation for this class was generated from the following files:

- connectionsocks5proxy.h
- connectionsocks5proxy.cpp