void do_connect()
	{
		if(udp)
		{
			after_connected();
			return;
		}

		if(proxy.type() == Proxy::HttpConnect)
		{
			HttpConnect *s = new HttpConnect(this);
			bs = s;
			connect(s, SIGNAL(connected()), SLOT(bs_connected()));
			connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
			if(!proxy.user().isEmpty())
				s->setAuth(proxy.user(), proxy.pass());
			s->connectToHost(proxy.host(), proxy.port(), serverAddr.toString(), serverPort);
		}
		else if(proxy.type() == Proxy::Socks)
		{
			SocksClient *s = new SocksClient(this);
			bs = s;
			connect(s, SIGNAL(connected()), SLOT(bs_connected()));
			connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
			if(!proxy.user().isEmpty())
				s->setAuth(proxy.user(), proxy.pass());
			s->connectToHost(proxy.host(), proxy.port(), serverAddr.toString(), serverPort);
		}
		else
		{
			BSocket *s = new BSocket(this);
			bs = s;
			connect(s, SIGNAL(connected()), SLOT(bs_connected()));
			connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
			s->connectToHost(serverAddr.toString(), serverPort);
		}

		connect(bs, SIGNAL(connectionClosed()), SLOT(bs_connectionClosed()));
		connect(bs, SIGNAL(delayedCloseFinished()), SLOT(bs_delayedCloseFinished()));
		connect(bs, SIGNAL(readyRead()), SLOT(bs_readyRead()));
		connect(bs, SIGNAL(bytesWritten(int)), SLOT(bs_bytesWritten(int)));
	}
void AdvancedConnector::do_connect()
{
#ifdef XMPP_DEBUG
	printf("trying %s:%d\n", d->host.latin1(), d->port);
#endif
	int t = d->proxy.type();
	if(t == Proxy::None) {
#ifdef XMPP_DEBUG
		printf("do_connect1\n");
#endif
		BSocket *s = new BSocket;
		d->bs = s;
		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
		s->connectToHost(d->host, d->port);
	}
	else if(t == Proxy::HttpConnect) {
#ifdef XMPP_DEBUG
		printf("do_connect2\n");
#endif
		HttpConnect *s = new HttpConnect;
		d->bs = s;
		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
		if(!d->proxy.user().isEmpty())
			s->setAuth(d->proxy.user(), d->proxy.pass());
		s->connectToHost(d->proxy.host(), d->proxy.port(), d->host, d->port);
	}
	else if(t == Proxy::Socks) {
#ifdef XMPP_DEBUG
		printf("do_connect3\n");
#endif
		SocksClient *s = new SocksClient;
		d->bs = s;
		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));
		if(!d->proxy.user().isEmpty())
			s->setAuth(d->proxy.user(), d->proxy.pass());
		s->connectToHost(d->proxy.host(), d->proxy.port(), d->host, d->port);
	}
}
Beispiel #3
0
void AdvancedConnector::bs_error(int x)
{
#ifdef XMPP_DEBUG
	XDEBUG << "e:" << x;
#endif

	if(d->mode == Connected) {
		d->errorCode = ErrStream;
		emit error();
		return;
	}

	bool proxyError = false;
	int err = ErrConnectionRefused;
	int t = d->proxy.type();

#ifdef XMPP_DEBUG
	qDebug("bse1");
#endif

	// figure out the error
	if(t == Proxy::None) {
		if(x == BSocket::ErrHostNotFound)
			err = ErrHostNotFound;
		else
			err = ErrConnectionRefused;
	}
	else if(t == Proxy::HttpConnect) {
		if(x == HttpConnect::ErrConnectionRefused)
			err = ErrConnectionRefused;
		else if(x == HttpConnect::ErrHostNotFound)
			err = ErrHostNotFound;
		else {
			proxyError = true;
			if(x == HttpConnect::ErrProxyAuth)
				err = ErrProxyAuth;
			else if(x == HttpConnect::ErrProxyNeg)
				err = ErrProxyNeg;
			else
				err = ErrProxyConnect;
		}
	}
	else if(t == Proxy::HttpPoll) {
		if(x == HttpPoll::ErrConnectionRefused)
			err = ErrConnectionRefused;
		else if(x == HttpPoll::ErrHostNotFound)
			err = ErrHostNotFound;
		else {
			proxyError = true;
			if(x == HttpPoll::ErrProxyAuth)
				err = ErrProxyAuth;
			else if(x == HttpPoll::ErrProxyNeg)
				err = ErrProxyNeg;
			else
				err = ErrProxyConnect;
		}
	}
	else if(t == Proxy::Socks) {
		if(x == SocksClient::ErrConnectionRefused)
			err = ErrConnectionRefused;
		else if(x == SocksClient::ErrHostNotFound)
			err = ErrHostNotFound;
		else {
			proxyError = true;
			if(x == SocksClient::ErrProxyAuth)
				err = ErrProxyAuth;
			else if(x == SocksClient::ErrProxyNeg)
				err = ErrProxyNeg;
			else
				err = ErrProxyConnect;
		}
	}

	// no-multi or proxy error means we quit
	if(proxyError) {
		cleanup();
		d->errorCode = err;
		emit error();
		return;
	}

	/*
		if we shall probe the ssl legacy port, and we just did that (port=legacy),
		then try to connect to the normal port instead
	*/
	if(d->opt_ssl == Probe && d->port == XMPP_LEGACY_PORT) {
#ifdef XMPP_DEBUG
		qDebug("bse1.2");
#endif
		BSocket *s = static_cast<BSocket*>(d->bs);
		d->port = XMPP_DEFAULT_PORT;
		s->connectToHost(XMPP_CLIENT_SRV, XMPP_CLIENT_TRANSPORT, d->host, d->port);
	}
	/* otherwise we have no fallbacks and must have failed to connect */
	else {
#ifdef XMPP_DEBUG
		qDebug("bse1.3");
#endif
		cleanup();
		d->errorCode = ErrConnectionRefused;
		emit error();
	}
}
Beispiel #4
0
void AdvancedConnector::connectToServer(const QString &server)
{
#ifdef XMPP_DEBUG
	XDEBUG << "s:" << server;
#endif

	if(d->mode != Idle)
		return;
	if(server.isEmpty())
		return;

	d->errorCode = 0;
	d->mode = Connecting;

	// Encode the servername
	d->host = QUrl::toAce(server);
	if (d->host == QByteArray()) {
		/* server contains invalid characters for DNS name, but maybe valid characters for connecting, like "::1" */
		d->host = server;
	}
	d->port = XMPP_DEFAULT_PORT;

	if(d->proxy.type() == Proxy::HttpPoll) {
		HttpPoll *s = new HttpPoll;
		d->bs = s;

		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(syncStarted()), SLOT(http_syncStarted()));
		connect(s, SIGNAL(syncFinished()), SLOT(http_syncFinished()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));

		if(!d->proxy.user().isEmpty())
			s->setAuth(d->proxy.user(), d->proxy.pass());
		s->setPollInterval(d->proxy.pollInterval());

		if(d->proxy.host().isEmpty())
			s->connectToUrl(d->proxy.url());
		else
			s->connectToHost(d->proxy.host(), d->proxy.port(), d->proxy.url());
	}
	else if (d->proxy.type() == Proxy::HttpConnect) {
		HttpConnect *s = new HttpConnect;
		d->bs = s;

		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));

		if(!d->opt_host.isEmpty()) {
			d->host = d->opt_host;
			d->port = d->opt_port;
		}

		if(!d->proxy.user().isEmpty())
			s->setAuth(d->proxy.user(), d->proxy.pass());

		s->connectToHost(d->proxy.host(), d->proxy.port(), d->host, d->port);
	}
	else if (d->proxy.type() == Proxy::Socks) {
		SocksClient *s = new SocksClient;
		d->bs = s;

		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));

		if(!d->opt_host.isEmpty()) {
			d->host = d->opt_host;
			d->port = d->opt_port;
		}

		if(!d->proxy.user().isEmpty())
			s->setAuth(d->proxy.user(), d->proxy.pass());

		s->connectToHost(d->proxy.host(), d->proxy.port(), d->host, d->port);
	}
	else {
		BSocket *s = new BSocket;
		d->bs = s;
#ifdef XMPP_DEBUG
		XDEBUG << "Adding socket:" << s;
#endif

		connect(s, SIGNAL(connected()), SLOT(bs_connected()));
		connect(s, SIGNAL(error(int)), SLOT(bs_error(int)));

		if(!d->opt_host.isEmpty()) {
			d->host = d->opt_host;
			d->port = d->opt_port;
			s->connectToHost(d->host, d->port);
			return;
		} else if (d->opt_ssl != Never) {
			d->port = XMPP_LEGACY_PORT;
		}

		s->connectToHost(XMPP_CLIENT_SRV, XMPP_CLIENT_TRANSPORT, d->host, d->port);
	}
}