Qt 4.8
Public Types | Public Functions | Public Variables | List of all members
QSocks5SocketEnginePrivate Class Reference

#include <qsocks5socketengine_p.h>

Inheritance diagram for QSocks5SocketEnginePrivate:
QAbstractSocketEnginePrivate QObjectPrivate QObjectData

Public Types

enum  Socks5Error {
  SocksFailure = 0x01, ConnectionNotAllowed = 0x02, NetworkUnreachable = 0x03, HostUnreachable = 0x04,
  ConnectionRefused = 0x05, TTLExpired = 0x06, CommandNotSupported = 0x07, AddressTypeNotSupported = 0x08,
  LastKnownError = AddressTypeNotSupported, UnknownError
}
 
enum  Socks5Mode { NoMode, ConnectMode, BindMode, UdpAssociateMode }
 
enum  Socks5State {
  Uninitialized = 0, ConnectError, AuthenticationMethodsSent, Authenticating,
  AuthenticatingError, RequestMethodSent, RequestError, Connected,
  UdpAssociateSuccess, BindSuccess, ControlSocketError, SocksError,
  HostNameLookupError
}
 
- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Public Functions

void _q_controlSocketBytesWritten ()
 
void _q_controlSocketConnected ()
 
void _q_controlSocketDisconnected ()
 
void _q_controlSocketError (QAbstractSocket::SocketError)
 
void _q_controlSocketReadNotification ()
 
void _q_controlSocketStateChanged (QAbstractSocket::SocketState)
 
void _q_emitPendingConnectionNotification ()
 
void _q_emitPendingReadNotification ()
 
void _q_emitPendingWriteNotification ()
 
void _q_udpSocketReadNotification ()
 
void checkForDatagrams () const
 
void emitConnectionNotification ()
 
void emitReadNotification ()
 
void emitWriteNotification ()
 
void initialize (Socks5Mode socks5Mode)
 
void parseAuthenticatingReply ()
 
void parseAuthenticationMethodReply ()
 
void parseNewConnection ()
 
void parseRequestMethodReply ()
 
 QSocks5SocketEnginePrivate ()
 
void reauthenticate ()
 
void sendRequestMethod ()
 
void setErrorState (Socks5State state, const QString &extraMessage=QString())
 
void setErrorState (Socks5State state, Socks5Error socks5error)
 
bool waitForConnected (int msecs, bool *timedOut)
 
 ~QSocks5SocketEnginePrivate ()
 
- Public Functions inherited from QAbstractSocketEnginePrivate
 QAbstractSocketEnginePrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Public Variables

QSocks5BindDatabindData
 
QSocks5ConnectDataconnectData
 
bool connectionNotificationPending
 
QSocks5Datadata
 
bool exceptNotificationEnabled
 
Socks5Mode mode
 
QString peerName
 
QNetworkProxy proxyInfo
 
bool readNotificationActivated
 
bool readNotificationEnabled
 
bool readNotificationPending
 
int socketDescriptor
 
Socks5State socks5State
 
QSocks5UdpAssociateDataudpData
 
bool writeNotificationActivated
 
bool writeNotificationEnabled
 
bool writeNotificationPending
 
- Public Variables inherited from QAbstractSocketEnginePrivate
bool hasSetSocketError
 
QHostAddress localAddress
 
quint16 localPort
 
QHostAddress peerAddress
 
quint16 peerPort
 
QAbstractSocketEngineReceiverreceiver
 
QAbstractSocket::SocketError socketError
 
QString socketErrorString
 
QAbstractSocket::NetworkLayerProtocol socketProtocol
 
QAbstractSocket::SocketState socketState
 
QAbstractSocket::SocketType socketType
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Detailed Description

Definition at line 187 of file qsocks5socketengine_p.h.

Enumerations

◆ Socks5Error

◆ Socks5Mode

◆ Socks5State

Enumerator
Uninitialized 
ConnectError 
AuthenticationMethodsSent 
Authenticating 
AuthenticatingError 
RequestMethodSent 
RequestError 
Connected 
UdpAssociateSuccess 
BindSuccess 
ControlSocketError 
SocksError 
HostNameLookupError 

Definition at line 194 of file qsocks5socketengine_p.h.

Constructors and Destructors

◆ QSocks5SocketEnginePrivate()

QSocks5SocketEnginePrivate::QSocks5SocketEnginePrivate ( )

Definition at line 521 of file qsocks5socketengine.cpp.

523  , readNotificationEnabled(false)
524  , writeNotificationEnabled(false)
526  , socketDescriptor(-1)
527  , data(0)
528  , connectData(0)
529 #ifndef QT_NO_UDPSOCKET
530  , udpData(0)
531 #endif
532  , bindData(0)
535  , readNotificationPending(false)
536  , writeNotificationPending(false)
538 {
539  mode = NoMode;
540 }
QSocks5UdpAssociateData * udpData
QSocks5ConnectData * connectData

◆ ~QSocks5SocketEnginePrivate()

QSocks5SocketEnginePrivate::~QSocks5SocketEnginePrivate ( )

Definition at line 542 of file qsocks5socketengine.cpp.

543 {
544 }

Functions

◆ _q_controlSocketBytesWritten()

void QSocks5SocketEnginePrivate::_q_controlSocketBytesWritten ( )

Definition at line 1219 of file qsocks5socketengine.cpp.

Referenced by initialize().

1220 {
1221  QSOCKS5_DEBUG << "_q_controlSocketBytesWritten";
1222 
1223  if (socks5State != Connected
1224  || (mode == ConnectMode
1226  return;
1230  }
1231 }
QTcpSocket * controlSocket
static const int MaxWriteBufferSize
qint64 bytesToWrite() const
Returns the number of bytes that are waiting to be written.
#define QSOCKS5_DEBUG

◆ _q_controlSocketConnected()

void QSocks5SocketEnginePrivate::_q_controlSocketConnected ( )

Definition at line 1160 of file qsocks5socketengine.cpp.

Referenced by initialize().

1161 {
1162  QSOCKS5_DEBUG << "_q_controlSocketConnected";
1163  QByteArray buf(3, 0);
1164  buf[0] = S5_VERSION_5;
1165  buf[1] = 0x01;
1166  buf[2] = data->authenticator->methodId();
1167  data->controlSocket->write(buf);
1169 }
QTcpSocket * controlSocket
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSocks5Authenticator * authenticator
#define S5_VERSION_5
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
#define QSOCKS5_DEBUG

◆ _q_controlSocketDisconnected()

void QSocks5SocketEnginePrivate::_q_controlSocketDisconnected ( )

Definition at line 1264 of file qsocks5socketengine.cpp.

Referenced by initialize().

1265 {
1266  QSOCKS5_D_DEBUG << "_q_controlSocketDisconnected";
1267 }
#define QSOCKS5_D_DEBUG

◆ _q_controlSocketError()

void QSocks5SocketEnginePrivate::_q_controlSocketError ( QAbstractSocket::SocketError  error)

Definition at line 1233 of file qsocks5socketengine.cpp.

Referenced by initialize().

1234 {
1235  QSOCKS5_D_DEBUG << "controlSocketError" << error << data->controlSocket->errorString();
1236 
1238  return; // ignore this error -- comes from the waitFor* functions
1239 
1241  && socks5State == Connected) {
1242  // clear the read buffer in connect mode so that bytes available returns 0
1243  // if there already is a read notification pending then this will be processed first
1247  data->controlSocket->close();
1248  // cause a disconnect in the outer socket
1250  } else if (socks5State == Uninitialized
1255  data->controlSocket->close();
1257  } else {
1258  q_func()->setError(data->controlSocket->error(), data->controlSocket->errorString());
1261  }
1262 }
QTcpSocket * controlSocket
#define error(msg)
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
#define QSOCKS5_D_DEBUG
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
QSocks5ConnectData * connectData
SocketError error() const
Returns the type of error that last occurred.
void clear()
Clears the contents of the byte array and makes it empty.
void setErrorState(Socks5State state, const QString &extraMessage=QString())

◆ _q_controlSocketReadNotification()

void QSocks5SocketEnginePrivate::_q_controlSocketReadNotification ( )

Definition at line 1171 of file qsocks5socketengine.cpp.

Referenced by initialize().

1172 {
1173  QSOCKS5_D_DEBUG << "_q_controlSocketReadNotification socks5state" << s5StateToString(socks5State)
1174  << "bytes available" << data->controlSocket->bytesAvailable();
1175 
1176  if (data->controlSocket->bytesAvailable() == 0) {
1177  QSOCKS5_D_DEBUG << "########## bogus read why do we get these ... on windows only";
1178  return;
1179  }
1180 
1181  switch (socks5State) {
1184  break;
1185  case Authenticating:
1187  break;
1188  case RequestMethodSent:
1190  break;
1191  case Connected: {
1192  QByteArray buf;
1193  if (!data->authenticator->unSeal(data->controlSocket, &buf)) {
1194  // qDebug() << "unseal error maybe need to wait for more data";
1195  }
1196  if (buf.size()) {
1197  QSOCKS5_DEBUG << dump(buf);
1198  connectData->readBuffer += buf;
1200  }
1201  break;
1202  }
1203  case BindSuccess:
1204  // only get here if command is bind
1205  if (mode == BindMode) {
1207  break;
1208  }
1209 
1210  // fall through
1211  default:
1212  qWarning("QSocks5SocketEnginePrivate::_q_controlSocketReadNotification: "
1213  "Unexpectedly received data while in state=%d and mode=%d",
1214  socks5State, mode);
1215  break;
1216  };
1217 }
QTcpSocket * controlSocket
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define QSOCKS5_D_DEBUG
virtual bool unSeal(const QByteArray sealedBuf, QByteArray *buf)
Q_CORE_EXPORT void qWarning(const char *,...)
QSocks5Authenticator * authenticator
static QString s5StateToString(QSocks5SocketEnginePrivate::Socks5State)
static QString dump(const QByteArray &)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QSocks5ConnectData * connectData
#define QSOCKS5_DEBUG

◆ _q_controlSocketStateChanged()

void QSocks5SocketEnginePrivate::_q_controlSocketStateChanged ( QAbstractSocket::SocketState  state)

Definition at line 1269 of file qsocks5socketengine.cpp.

Referenced by initialize().

1270 {
1271  QSOCKS5_D_DEBUG << "_q_controlSocketStateChanged" << state;
1272 }
#define QSOCKS5_D_DEBUG

◆ _q_emitPendingConnectionNotification()

void QSocks5SocketEnginePrivate::_q_emitPendingConnectionNotification ( )

Definition at line 970 of file qsocks5socketengine.cpp.

971 {
974  QSOCKS5_D_DEBUG << "emitting connectionNotification";
975  emit q->connectionNotification();
976 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
#define emit
Definition: qobjectdefs.h:76

◆ _q_emitPendingReadNotification()

void QSocks5SocketEnginePrivate::_q_emitPendingReadNotification ( )

Definition at line 919 of file qsocks5socketengine.cpp.

920 {
922  readNotificationPending = false;
924  QSOCKS5_D_DEBUG << "emitting readNotification";
926  emit q->readNotification();
927  if (!qq)
928  return;
929  // check if there needs to be a new zero read notification
934  }
935  }
936 }
QTcpSocket * controlSocket
The QPointer class is a template class that provides guarded pointers to QObject. ...
Definition: qpointer.h:54
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
#define emit
Definition: qobjectdefs.h:76
QSocks5ConnectData * connectData
SocketError error() const
Returns the type of error that last occurred.
void clear()
Clears the contents of the byte array and makes it empty.
SocketState state() const
Returns the state of the socket.

◆ _q_emitPendingWriteNotification()

void QSocks5SocketEnginePrivate::_q_emitPendingWriteNotification ( )

Definition at line 949 of file qsocks5socketengine.cpp.

950 {
951  writeNotificationPending = false;
954  QSOCKS5_D_DEBUG << "emitting writeNotification";
955  emit q->writeNotification();
956  }
957 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
#define emit
Definition: qobjectdefs.h:76

◆ _q_udpSocketReadNotification()

void QSocks5SocketEnginePrivate::_q_udpSocketReadNotification ( )

Definition at line 1282 of file qsocks5socketengine.cpp.

Referenced by initialize().

1283 {
1284  QSOCKS5_D_DEBUG << "_q_udpSocketReadNotification()";
1285 
1286  // check some state stuff
1288  QSOCKS5_D_DEBUG << "false read ??";
1289  return;
1290  }
1291 
1292  while (udpData->udpSocket->hasPendingDatagrams()) {
1293  QByteArray sealedBuf(udpData->udpSocket->pendingDatagramSize(), 0);
1294  QSOCKS5_D_DEBUG << "new datagram";
1295  udpData->udpSocket->readDatagram(sealedBuf.data(), sealedBuf.size());
1296  QByteArray inBuf;
1297  if (!data->authenticator->unSeal(sealedBuf, &inBuf)) {
1298  QSOCKS5_D_DEBUG << "failed unsealing datagram discarding";
1299  return;
1300  }
1301  QSOCKS5_DEBUG << dump(inBuf);
1302  int pos = 0;
1303  const char *buf = inBuf.constData();
1304  if (inBuf.size() < 4) {
1305  QSOCKS5_D_DEBUG << "bugus udp data, discarding";
1306  return;
1307  }
1308  QSocks5RevivedDatagram datagram;
1309  if (buf[pos++] != 0 || buf[pos++] != 0) {
1310  QSOCKS5_D_DEBUG << "invalid datagram discarding";
1311  return;
1312  }
1313  if (buf[pos++] != 0) { //### add fragmentation reading support
1314  QSOCKS5_D_DEBUG << "don't support fragmentation yet disgarding";
1315  return;
1316  }
1317  if (!qt_socks5_get_host_address_and_port(inBuf, &datagram.address, &datagram.port, &pos)) {
1318  QSOCKS5_D_DEBUG << "failed to get address from datagram disgarding";
1319  return;
1320  }
1321  datagram.data = QByteArray(&buf[pos], inBuf.size() - pos);
1322  udpData->pendingDatagrams.enqueue(datagram);
1323  }
1325 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QSocks5UdpAssociateData * udpData
bool hasPendingDatagrams() const
Returns true if at least one datagram is waiting to be read; otherwise returns false.
Definition: qudpsocket.cpp:490
qint64 pendingDatagramSize() const
Returns the size of the first pending UDP datagram.
Definition: qudpsocket.cpp:502
#define QSOCKS5_D_DEBUG
QQueue< QSocks5RevivedDatagram > pendingDatagrams
virtual bool unSeal(const QByteArray sealedBuf, QByteArray *buf)
static bool qt_socks5_get_host_address_and_port(const QByteArray &buf, QHostAddress *pAddress, quint16 *pPort, int *pPos)
QSocks5Authenticator * authenticator
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void enqueue(const T &t)
Adds value t to the tail of the queue.
Definition: qqueue.h:60
static QString dump(const QByteArray &)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *host=0, quint16 *port=0)
Receives a datagram no larger than maxSize bytes and stores it in data.
Definition: qudpsocket.cpp:583
#define QSOCKS5_DEBUG

◆ checkForDatagrams()

void QSocks5SocketEnginePrivate::checkForDatagrams ( ) const

Definition at line 1275 of file qsocks5socketengine.cpp.

1276 {
1277  // udp should be unbuffered so we need to do some polling at certain points
1279  const_cast<QSocks5SocketEnginePrivate *>(this)->_q_udpSocketReadNotification();
1280 }
QSocks5UdpAssociateData * udpData
bool hasPendingDatagrams() const
Returns true if at least one datagram is waiting to be read; otherwise returns false.
Definition: qudpsocket.cpp:490

◆ emitConnectionNotification()

void QSocks5SocketEnginePrivate::emitConnectionNotification ( )

Definition at line 978 of file qsocks5socketengine.cpp.

Referenced by parseAuthenticationMethodReply(), parseRequestMethodReply(), and reauthenticate().

979 {
981  QSOCKS5_D_DEBUG << "queueing connectionNotification";
983  QMetaObject::invokeMethod(q, "_q_emitPendingConnectionNotification", Qt::QueuedConnection);
984 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ emitReadNotification()

void QSocks5SocketEnginePrivate::emitReadNotification ( )

Definition at line 938 of file qsocks5socketengine.cpp.

Referenced by _q_emitPendingReadNotification(), and parseRequestMethodReply().

939 {
943  QSOCKS5_D_DEBUG << "queueing readNotification";
945  QMetaObject::invokeMethod(q, "_q_emitPendingReadNotification", Qt::QueuedConnection);
946  }
947 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ emitWriteNotification()

void QSocks5SocketEnginePrivate::emitWriteNotification ( )

Definition at line 959 of file qsocks5socketengine.cpp.

960 {
964  QSOCKS5_D_DEBUG << "queueing writeNotification";
966  QMetaObject::invokeMethod(q, "_q_emitPendingWriteNotification", Qt::QueuedConnection);
967  }
968 }
#define Q_Q(Class)
Definition: qglobal.h:2483
#define QSOCKS5_D_DEBUG
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ initialize()

void QSocks5SocketEnginePrivate::initialize ( Socks5Mode  socks5Mode)

Definition at line 546 of file qsocks5socketengine.cpp.

547 {
549 
550  mode = socks5Mode;
551  if (mode == ConnectMode) {
553  data = connectData;
554 #ifndef QT_NO_UDPSOCKET
555  } else if (mode == UdpAssociateMode) {
557  data = udpData;
558  udpData->udpSocket = new QUdpSocket(q);
559 #ifndef QT_NO_BEARERMANAGEMENT
560  udpData->udpSocket->setProperty("_q_networksession", q->property("_q_networksession"));
561 #endif
563  QObject::connect(udpData->udpSocket, SIGNAL(readyRead()),
566 #endif // QT_NO_UDPSOCKET
567  } else if (mode == BindMode) {
569  data = bindData;
570  }
571 
572  data->controlSocket = new QTcpSocket(q);
573 #ifndef QT_NO_BEARERMANAGEMENT
574  data->controlSocket->setProperty("_q_networksession", q->property("_q_networksession"));
575 #endif
591 
592  if (!proxyInfo.user().isEmpty() || !proxyInfo.password().isEmpty()) {
593  QSOCKS5_D_DEBUG << "using username/password authentication; user =" << proxyInfo.user();
595  } else {
596  QSOCKS5_D_DEBUG << "not using authentication";
598  }
599 }
void _q_controlSocketStateChanged(QAbstractSocket::SocketState)
QTcpSocket * controlSocket
The QUdpSocket class provides a UDP socket.
Definition: qudpsocket.h:59
#define error(msg)
#define SLOT(a)
Definition: qobjectdefs.h:226
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object&#39;s name property to value.
Definition: qobject.cpp:3755
QSocks5UdpAssociateData * udpData
#define Q_Q(Class)
Definition: qglobal.h:2483
SocketState
This enum describes the different states in which a socket can be.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QSOCKS5_D_DEBUG
static QIntfbScreen * connected
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
SocketError
This enum describes the socket errors that can occur.
QSocks5Authenticator * authenticator
The QTcpSocket class provides a TCP socket.
Definition: qtcpsocket.h:56
__int64 qint64
Definition: qglobal.h:942
void setProxy(const QNetworkProxy &networkProxy)
Sets the explicit network proxy for this socket to networkProxy.
QString password() const
Returns the password used for authentication.
QSocks5ConnectData * connectData
QString user() const
Returns the user name used for authentication.
void _q_controlSocketError(QAbstractSocket::SocketError)

◆ parseAuthenticatingReply()

void QSocks5SocketEnginePrivate::parseAuthenticatingReply ( )

Definition at line 788 of file qsocks5socketengine.cpp.

789 {
790  bool authComplete = false;
791  if (!data->authenticator->continueAuthenticate(data->controlSocket, &authComplete)) {
792  reauthenticate();
793  return;
794  }
795  if (authComplete)
797 }
QTcpSocket * controlSocket
virtual bool continueAuthenticate(QTcpSocket *socket, bool *completed)
QSocks5Authenticator * authenticator

◆ parseAuthenticationMethodReply()

void QSocks5SocketEnginePrivate::parseAuthenticationMethodReply ( )

Definition at line 753 of file qsocks5socketengine.cpp.

754 {
755  // not enough data to begin
756  if (data->controlSocket->bytesAvailable() < 2)
757  return;
758 
759  QByteArray buf = data->controlSocket->read(2);
760  if (buf.at(0) != S5_VERSION_5) {
761  QSOCKS5_D_DEBUG << "Socks5 version incorrect";
765  return;
766  }
767 
768  bool authComplete = false;
769  if (uchar(buf.at(1)) == S5_AUTHMETHOD_NONE) {
770  authComplete = true;
771  } else if (uchar(buf.at(1)) == S5_AUTHMETHOD_NOTACCEPTABLE) {
772  reauthenticate();
773  return;
774  } else if (buf.at(1) != data->authenticator->methodId()
775  || !data->authenticator->beginAuthenticate(data->controlSocket, &authComplete)) {
776  setErrorState(AuthenticatingError, QLatin1String("Socks5 host did not support authentication method."));
777  socketError = QAbstractSocket::SocketAccessError; // change the socket error
779  return;
780  }
781 
782  if (authComplete)
784  else
786 }
QTcpSocket * controlSocket
qint64 bytesAvailable() const
Returns the number of incoming bytes that are waiting to be read.
#define S5_AUTHMETHOD_NOTACCEPTABLE
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
Definition: qiodevice.cpp:791
unsigned char uchar
Definition: qglobal.h:994
#define QSOCKS5_D_DEBUG
QSocks5Authenticator * authenticator
#define S5_VERSION_5
QAbstractSocket::SocketError socketError
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
virtual bool beginAuthenticate(QTcpSocket *socket, bool *completed)
#define S5_AUTHMETHOD_NONE
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
void setErrorState(Socks5State state, const QString &extraMessage=QString())

◆ parseNewConnection()

void QSocks5SocketEnginePrivate::parseNewConnection ( )

◆ parseRequestMethodReply()

void QSocks5SocketEnginePrivate::parseRequestMethodReply ( )

Definition at line 844 of file qsocks5socketengine.cpp.

845 {
847  QSOCKS5_DEBUG << "parseRequestMethodReply()";
848 
849  QByteArray inBuf;
850  if (!data->authenticator->unSeal(data->controlSocket, &inBuf)) {
851  // ### check error and not just not enough data
852  QSOCKS5_DEBUG << "unSeal failed, needs more data";
853  return;
854  }
855  QSOCKS5_DEBUG << dump(inBuf);
856  if (inBuf.size() < 2) {
857  QSOCKS5_DEBUG << "need more data for request reply header .. put this data somewhere";
858  return;
859  }
860 
861  QHostAddress address;
862  quint16 port = 0;
863 
864  if (inBuf.at(0) != S5_VERSION_5 || inBuf.length() < 3 || inBuf.at(2) != 0x00) {
865  QSOCKS5_DEBUG << "socks protocol error";
867  } else if (inBuf.at(1) != S5_SUCCESS) {
868  Socks5Error socks5Error = Socks5Error(inBuf.at(1));
869  QSOCKS5_DEBUG << "Request error :" << socks5Error;
870  if ((socks5Error == SocksFailure || socks5Error == ConnectionNotAllowed)
871  && !peerName.isEmpty()) {
872  // Dante seems to use this error code to indicate hostname resolution failure
874  } else {
875  setErrorState(RequestError, socks5Error);
876  }
877  } else {
878  // connection success, retrieve the remote addresses
879  int pos = 3;
880  if (!qt_socks5_get_host_address_and_port(inBuf, &address, &port, &pos)) {
881  QSOCKS5_DEBUG << "error getting address";
883  } else {
884  inBuf.remove(0, pos);
885  for (int i = inBuf.size() - 1; i >= 0 ; --i)
886  data->controlSocket->ungetChar(inBuf.at(i));
887  }
888  }
889 
891  // no error
892  localAddress = address;
893  localPort = port;
894 
895  if (mode == ConnectMode) {
897  // notify the upper layer that we're done
898  q->setState(QAbstractSocket::ConnectedState);
900  } else if (mode == BindMode) {
902  q->setState(QAbstractSocket::ListeningState);
903  } else {
905  }
906  } else if (socks5State == BindSuccess) {
907  // no error and we got a connection
908  bindData->peerAddress = address;
909  bindData->peerPort = port;
910 
912  } else {
913  // got an error
916  }
917 }
QTcpSocket * controlSocket
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
void ungetChar(char c)
Puts the character c back into the device, and decrements the current position unless the position is...
Definition: qiodevice.cpp:1462
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define S5_SUCCESS
virtual bool unSeal(const QByteArray sealedBuf, QByteArray *buf)
static bool qt_socks5_get_host_address_and_port(const QByteArray &buf, QHostAddress *pAddress, quint16 *pPort, int *pPos)
unsigned short quint16
Definition: qglobal.h:936
QSocks5Authenticator * authenticator
#define S5_VERSION_5
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
int length() const
Same as size().
Definition: qbytearray.h:356
static QString dump(const QByteArray &)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413
#define QSOCKS5_DEBUG
QByteArray & remove(int index, int len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
void setErrorState(Socks5State state, const QString &extraMessage=QString())

◆ reauthenticate()

void QSocks5SocketEnginePrivate::reauthenticate ( )

Definition at line 722 of file qsocks5socketengine.cpp.

Referenced by parseAuthenticatingReply(), and parseAuthenticationMethodReply().

723 {
725 
726  // we require authentication
727  QAuthenticator auth;
728  emit q->proxyAuthenticationRequired(proxyInfo, &auth);
729 
730  if (!auth.user().isEmpty() || !auth.password().isEmpty()) {
731  // we have new credentials, let's try again
732  QSOCKS5_DEBUG << "authentication failure: retrying connection";
734 
735  delete data->authenticator;
736  proxyInfo.setUser(auth.user());
739 
744  } else {
745  // authentication failure
746 
750  }
751 }
QTcpSocket * controlSocket
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
void connectToHost(const QString &hostName, quint16 port, OpenMode mode=ReadWrite)
Attempts to make a connection to hostName on the given port.
void setUser(const QString &userName)
Sets the user name for proxy authentication to be user.
void abort()
Aborts the current connection and resets the socket.
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
QSocks5Authenticator * authenticator
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
The QAuthenticator class provides an authentication object.
QString user() const
returns the user used for authentication.
quint16 port() const
Returns the port of the proxy host.
QString password() const
Returns the password used for authentication.
QString password() const
returns the password used for authentication.
QString user() const
Returns the user name used for authentication.
void setPassword(const QString &password)
Sets the password for proxy authentication to be password.
#define QSOCKS5_DEBUG
void setErrorState(Socks5State state, const QString &extraMessage=QString())
QString hostName() const
Returns the host name of the proxy host.

◆ sendRequestMethod()

void QSocks5SocketEnginePrivate::sendRequestMethod ( )

Definition at line 799 of file qsocks5socketengine.cpp.

Referenced by parseAuthenticatingReply(), and parseAuthenticationMethodReply().

800 {
801  QHostAddress address;
802  quint16 port = 0;
803  char command = 0;
804  if (mode == ConnectMode) {
805  command = S5_CONNECT;
806  address = peerAddress;
807  port = peerPort;
808  } else if (mode == BindMode) {
809  command = S5_BIND;
810  address = localAddress;
811  port = localPort;
812  } else {
813 #ifndef QT_NO_UDPSOCKET
814  command = S5_UDP_ASSOCIATE;
815  address = localAddress; //data->controlSocket->localAddress();
816  port = localPort;
817 #endif
818  }
819 
820  QByteArray buf;
821  buf.reserve(270); // big enough for domain name;
822  buf[0] = S5_VERSION_5;
823  buf[1] = command;
824  buf[2] = 0x00;
825  if (peerName.isEmpty() && !qt_socks5_set_host_address_and_port(address, port, &buf)) {
826  QSOCKS5_DEBUG << "error setting address" << address << " : " << port;
827  //### set error code ....
828  return;
829  } else if (!peerName.isEmpty() && !qt_socks5_set_host_name_and_port(peerName, port, &buf)) {
830  QSOCKS5_DEBUG << "error setting address" << address << " : " << port;
831  //### set error code ....
832  return;
833  }
834  QSOCKS5_DEBUG << "sending" << dump(buf);
835  QByteArray sealedBuf;
836  if (!data->authenticator->seal(buf, &sealedBuf)) {
837  // ### Handle this error.
838  }
839  data->controlSocket->write(sealedBuf);
842 }
QTcpSocket * controlSocket
bool flush()
This function writes as much as possible from the internal write buffer to the underlying network soc...
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
unsigned short quint16
Definition: qglobal.h:936
QSocks5Authenticator * authenticator
#define S5_VERSION_5
static bool qt_socks5_set_host_address_and_port(const QHostAddress &address, quint16 port, QByteArray *pBuf)
#define S5_BIND
static QString dump(const QByteArray &)
The QHostAddress class provides an IP address.
Definition: qhostaddress.h:70
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
#define S5_CONNECT
static bool qt_socks5_set_host_name_and_port(const QString &hostname, quint16 port, QByteArray *pBuf)
#define QSOCKS5_DEBUG
virtual bool seal(const QByteArray buf, QByteArray *sealedBuf)
#define S5_UDP_ASSOCIATE

◆ setErrorState() [1/2]

void QSocks5SocketEnginePrivate::setErrorState ( Socks5State  state,
const QString extraMessage = QString() 
)

Definition at line 601 of file qsocks5socketengine.cpp.

Referenced by parseAuthenticationMethodReply(), parseRequestMethodReply(), reauthenticate(), and setErrorState().

602 {
604 
605  switch (state) {
606  case Uninitialized:
607  case Authenticating:
609  case RequestMethodSent:
610  case Connected:
611  case UdpAssociateSuccess:
612  case BindSuccess:
613  // these aren't error states
614  return;
615 
616  case ConnectError:
617  case ControlSocketError: {
618  QAbstractSocket::SocketError controlSocketError = data->controlSocket->error();
619  if (socks5State != Connected) {
620  switch (controlSocketError) {
623  QSocks5SocketEngine::tr("Connection to proxy refused"));
624  break;
627  QSocks5SocketEngine::tr("Connection to proxy closed prematurely"));
628  break;
631  QSocks5SocketEngine::tr("Proxy host not found"));
632  break;
634  if (state == ConnectError) {
636  QSocks5SocketEngine::tr("Connection to proxy timed out"));
637  break;
638  }
639  /* fall through */
640  default:
641  q->setError(controlSocketError, data->controlSocket->errorString());
642  break;
643  }
644  } else {
645  q->setError(controlSocketError, data->controlSocket->errorString());
646  }
647  break;
648  }
649 
650  case AuthenticatingError:
652  extraMessage.isEmpty() ?
653  QSocks5SocketEngine::tr("Proxy authentication failed") :
654  QSocks5SocketEngine::tr("Proxy authentication failed: %1").arg(extraMessage));
655  break;
656 
657  case RequestError:
658  // error code set by caller (overload)
659  break;
660 
661  case SocksError:
663  QSocks5SocketEngine::tr("SOCKS version 5 protocol error"));
664  break;
665 
666  case HostNameLookupError:
668  QAbstractSocket::tr("Host not found"));
669  break;
670  }
671 
673  socks5State = state;
674 }
QTcpSocket * controlSocket
QString errorString() const
Returns a human-readable description of the last device error that occurred.
Definition: qiodevice.cpp:1671
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
SocketError
This enum describes the socket errors that can occur.
SocketError error() const
Returns the type of error that last occurred.

◆ setErrorState() [2/2]

void QSocks5SocketEnginePrivate::setErrorState ( Socks5State  state,
Socks5Error  socks5error 
)

Definition at line 676 of file qsocks5socketengine.cpp.

677 {
679  switch (socks5error) {
680  case SocksFailure:
681  q->setError(QAbstractSocket::NetworkError,
682  QSocks5SocketEngine::tr("General SOCKSv5 server failure"));
683  break;
686  QSocks5SocketEngine::tr("Connection not allowed by SOCKSv5 server"));
687  break;
688  case NetworkUnreachable:
689  q->setError(QAbstractSocket::NetworkError,
690  QAbstractSocket::tr("Network unreachable"));
691  break;
692  case HostUnreachable:
694  QAbstractSocket::tr("Host not found"));
695  break;
696  case ConnectionRefused:
698  QAbstractSocket::tr("Connection refused"));
699  break;
700  case TTLExpired:
701  q->setError(QAbstractSocket::NetworkError,
702  QSocks5SocketEngine::tr("TTL expired"));
703  break;
704  case CommandNotSupported:
706  QSocks5SocketEngine::tr("SOCKSv5 command not supported"));
707  break;
710  QSocks5SocketEngine::tr("Address type not supported"));
711  break;
712 
713  default:
715  QSocks5SocketEngine::tr("Unknown SOCKSv5 proxy error code 0x%1").arg(int(socks5error), 16));
716  break;
717  }
718 
719  setErrorState(state, QString());
720 }
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_Q(Class)
Definition: qglobal.h:2483
void setErrorState(Socks5State state, const QString &extraMessage=QString())

◆ waitForConnected()

bool QSocks5SocketEnginePrivate::waitForConnected ( int  msecs,
bool *  timedOut 
)

Definition at line 1715 of file qsocks5socketengine.cpp.

1716 {
1718  return false;
1719 
1720  const Socks5State wantedState =
1721  mode == ConnectMode ? Connected :
1722  mode == BindMode ? BindSuccess :
1724 
1725  QElapsedTimer stopWatch;
1726  stopWatch.start();
1727 
1728  while (socks5State != wantedState) {
1729  if (!data->controlSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
1731  return true;
1732 
1735  *timedOut = true;
1736  return false;
1737  }
1738  }
1739 
1740  return true;
1741 }
QTcpSocket * controlSocket
bool waitForReadyRead(int msecs=30000)
This function blocks until new data is available for reading and the QIODevice::readyRead() signal ha...
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
static int qt_timeout_value(int msecs, int elapsed)
SocketError error() const
Returns the type of error that last occurred.
void start()
Starts this timer.
SocketState state() const
Returns the state of the socket.
void setErrorState(Socks5State state, const QString &extraMessage=QString())

Properties

◆ bindData

QSocks5BindData* QSocks5SocketEnginePrivate::bindData

Definition at line 271 of file qsocks5socketengine_p.h.

Referenced by initialize(), and parseRequestMethodReply().

◆ connectData

QSocks5ConnectData* QSocks5SocketEnginePrivate::connectData

Definition at line 267 of file qsocks5socketengine_p.h.

Referenced by _q_emitPendingReadNotification(), and initialize().

◆ connectionNotificationPending

bool QSocks5SocketEnginePrivate::connectionNotificationPending

◆ data

QSocks5Data* QSocks5SocketEnginePrivate::data

◆ exceptNotificationEnabled

bool QSocks5SocketEnginePrivate::exceptNotificationEnabled

Definition at line 262 of file qsocks5socketengine_p.h.

◆ mode

Socks5Mode QSocks5SocketEnginePrivate::mode

◆ peerName

QString QSocks5SocketEnginePrivate::peerName

Definition at line 272 of file qsocks5socketengine_p.h.

Referenced by parseRequestMethodReply(), and sendRequestMethod().

◆ proxyInfo

QNetworkProxy QSocks5SocketEnginePrivate::proxyInfo

Definition at line 260 of file qsocks5socketengine_p.h.

Referenced by initialize(), and reauthenticate().

◆ readNotificationActivated

bool QSocks5SocketEnginePrivate::readNotificationActivated
mutable

Definition at line 274 of file qsocks5socketengine_p.h.

Referenced by emitReadNotification().

◆ readNotificationEnabled

bool QSocks5SocketEnginePrivate::readNotificationEnabled

◆ readNotificationPending

bool QSocks5SocketEnginePrivate::readNotificationPending

◆ socketDescriptor

int QSocks5SocketEnginePrivate::socketDescriptor

Definition at line 264 of file qsocks5socketengine_p.h.

◆ socks5State

Socks5State QSocks5SocketEnginePrivate::socks5State

◆ udpData

QSocks5UdpAssociateData* QSocks5SocketEnginePrivate::udpData

Definition at line 269 of file qsocks5socketengine_p.h.

Referenced by initialize().

◆ writeNotificationActivated

bool QSocks5SocketEnginePrivate::writeNotificationActivated
mutable

Definition at line 275 of file qsocks5socketengine_p.h.

Referenced by emitWriteNotification().

◆ writeNotificationEnabled

bool QSocks5SocketEnginePrivate::writeNotificationEnabled

◆ writeNotificationPending

bool QSocks5SocketEnginePrivate::writeNotificationPending

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