Qt 4.8
Public Functions | Properties | List of all members
QSocks5PasswordAuthenticator Class Reference

#include <qsocks5socketengine_p.h>

Inheritance diagram for QSocks5PasswordAuthenticator:
QSocks5Authenticator

Public Functions

bool beginAuthenticate (QTcpSocket *socket, bool *completed)
 
bool continueAuthenticate (QTcpSocket *socket, bool *completed)
 
QString errorString ()
 
char methodId ()
 
 QSocks5PasswordAuthenticator (const QString &userName, const QString &password)
 
- Public Functions inherited from QSocks5Authenticator
 QSocks5Authenticator ()
 
virtual bool seal (const QByteArray buf, QByteArray *sealedBuf)
 
virtual bool unSeal (const QByteArray sealedBuf, QByteArray *buf)
 
virtual bool unSeal (QTcpSocket *sealedSocket, QByteArray *buf)
 
virtual ~QSocks5Authenticator ()
 

Properties

QString password
 
QString userName
 

Detailed Description

Definition at line 167 of file qsocks5socketengine_p.h.

Constructors and Destructors

◆ QSocks5PasswordAuthenticator()

QSocks5PasswordAuthenticator::QSocks5PasswordAuthenticator ( const QString userName,
const QString password 
)

Definition at line 468 of file qsocks5socketengine.cpp.

469 {
470  this->userName = userName;
471  this->password = password;
472 }

Functions

◆ beginAuthenticate()

bool QSocks5PasswordAuthenticator::beginAuthenticate ( QTcpSocket socket,
bool *  completed 
)
virtual

Reimplemented from QSocks5Authenticator.

Definition at line 479 of file qsocks5socketengine.cpp.

480 {
481  *completed = false;
482  QByteArray uname = userName.toLatin1();
483  QByteArray passwd = password.toLatin1();
484  QByteArray dataBuf(3 + uname.size() + passwd.size(), 0);
485  char *buf = dataBuf.data();
486  int pos = 0;
487  buf[pos++] = S5_PASSWORDAUTH_VERSION;
488  buf[pos++] = uname.size();
489  memcpy(&buf[pos], uname.data(), uname.size());
490  pos += uname.size();
491  buf[pos++] = passwd.size();
492  memcpy(&buf[pos], passwd.data(), passwd.size());
493  return socket->write(dataBuf) == dataBuf.size();
494 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
#define S5_PASSWORDAUTH_VERSION
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ continueAuthenticate()

bool QSocks5PasswordAuthenticator::continueAuthenticate ( QTcpSocket socket,
bool *  completed 
)
virtual

Reimplemented from QSocks5Authenticator.

Definition at line 496 of file qsocks5socketengine.cpp.

497 {
498  *completed = false;
499 
500  if (socket->bytesAvailable() < 2)
501  return true;
502 
503  QByteArray buf = socket->read(2);
504  if (buf.at(0) == S5_PASSWORDAUTH_VERSION && buf.at(1) == 0x00) {
505  *completed = true;
506  return true;
507  }
508 
509  // must disconnect
510  socket->close();
511  return false;
512 }
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
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
void close()
Closes the I/O device for the socket, disconnects the socket&#39;s connection with the host...
#define S5_PASSWORDAUTH_VERSION
char at(int i) const
Returns the character at index position i in the byte array.
Definition: qbytearray.h:413

◆ errorString()

QString QSocks5PasswordAuthenticator::errorString ( )
virtual

Reimplemented from QSocks5Authenticator.

Definition at line 514 of file qsocks5socketengine.cpp.

515 {
516  return QLatin1String("Socks5 user name or password incorrect");
517 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString

◆ methodId()

char QSocks5PasswordAuthenticator::methodId ( )
virtual

Reimplemented from QSocks5Authenticator.

Definition at line 474 of file qsocks5socketengine.cpp.

475 {
476  return 0x02;
477 }

Properties

◆ password

QString QSocks5PasswordAuthenticator::password
private

Definition at line 179 of file qsocks5socketengine_p.h.

◆ userName

QString QSocks5PasswordAuthenticator::userName
private

Definition at line 178 of file qsocks5socketengine_p.h.


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