コード例 #1
0
ファイル: signalproxy.cpp プロジェクト: hades/quassel
QString SignalProxy::IODevicePeer::address() const {
  QAbstractSocket *socket = qobject_cast<QAbstractSocket *>(_device);
  if(socket)
    return socket->peerAddress().toString();
  else
    return QString();
}
コード例 #2
0
ファイル: worker.cpp プロジェクト: sjinks/repwatch_proxy
/**
 * @see http://tools.ietf.org/html/rfc1929
 *
 * Once the SOCKS V5 server has started, and the client has selected the
 * Username/Password Authentication protocol, the Username/Password
 * subnegotiation begins.  This begins with the client producing a
 * Username/Password request:
 *
 *         +----+------+----------+------+----------+
 *         |VER | ULEN |  UNAME   | PLEN |  PASSWD  |
 *         +----+------+----------+------+----------+
 *         | 1  |  1   | 1 to 255 |  1   | 1 to 255 |
 *         +----+------+----------+------+----------+
 *
 * The VER field contains the current version of the subnegotiation,
 * which is X'01'. The ULEN field contains the length of the UNAME field
 * that follows. The UNAME field contains the username as known to the
 * source operating system. The PLEN field contains the length of the
 * PASSWD field that follows. The PASSWD field contains the password
 * association with the given UNAME.
 */
void Worker::authenticate(void)
{
	int size = this->m_buf.size();
	if (-1 == this->m_expected_length) {
		if (size > 1) {
			quint8 ver = static_cast<quint8>(this->m_buf.at(0));
			int ulen   = static_cast<quint8>(this->m_buf.at(1));
			if (size > 2 + ulen) {
				int plen = static_cast<quint8>(this->m_buf.at(ulen + 2));
				this->m_expected_length = ulen + plen + 3;
			}

			if (ver != 1) {
				this->m_state = Worker::FatalErrorState;
				Q_EMIT this->error(Worker::ProtocolVersionMismatch);
				return;
			}
		}
	}

	if (this->m_expected_length != -1 && size > this->m_expected_length) {
		this->m_state = Worker::FatalErrorState;
		Q_EMIT this->error(Worker::TooMuchData);
		return;
	}

	if (size == this->m_expected_length) {
		int ulen = static_cast<quint8>(this->m_buf.at(1));
		int plen = static_cast<quint8>(this->m_buf.at(ulen + 2));
		QByteArray username = ulen ? QByteArray(this->m_buf.constData() + 2, ulen) : QByteArray();
		QByteArray password = plen ? QByteArray(this->m_buf.constData() + 2 + ulen + 1, plen) : QByteArray();
		QByteArray hostname;
		this->m_expected_length = -1;
		this->m_buf.clear();

		QAbstractSocket* sock = qobject_cast<QAbstractSocket*>(this->m_peer);
		if (sock) {
			hostname = sock->peerAddress().toString().toLocal8Bit();
		}

		if (this->m_noauth_allowed && username.isEmpty() && password.isEmpty()) {
			this->acceptAuthentication();
		}
		else {
			Q_EMIT this->authenticateRequest(username, password, hostname);
		}
	}
}
コード例 #3
0
ファイル: controler.cpp プロジェクト: 1KoT1/Labs_networktech
void Controler::newConection(){
	QAbstractSocket * socket = tcpServer->nextPendingConnection();
	qDebug()<<trUtf8("Получено соединение: %1:%2").arg(socket->peerAddress().toString()).arg(socket->peerPort());
}