JabberServerRegisterAccount::JabberServerRegisterAccount(const QString &server, const QString &username, const QString &password, bool legacySSLProbe, bool legacySSL, bool forceSSL, const QString &host, int port)
	: QObject(), Result(0), Server(server), Username(username), Password(password), Jid(QString::null)
{
	Client = new MiniClient;
	connect(Client, SIGNAL(handshaken()), SLOT(clientHandshaken()));
	connect(Client, SIGNAL(error()), SLOT(clientError()));
	Client->connectToServer(XMPP::Jid(Server), legacySSLProbe, legacySSL, forceSSL, host, port);
}
Ejemplo n.º 2
0
void HttpProxyGetStream::processData(const QByteArray &block)
{
	printf("processData: %d bytes\n", block.size());
	if(!d->inHeader) {
		emit dataReady(block);
		return;
	}

	ByteStream::appendArray(&d->recvBuf, block);

	if(d->inHeader) {
		// grab available lines
		while(1) {
			bool found;
			QString line = extractLine(&d->recvBuf, &found);
			if(!found)
				break;
			if(line.isEmpty()) {
				printf("empty line\n");
				d->inHeader = false;
				break;
			}
			d->headerLines += line;
			printf("headerLine: [%s]\n", qPrintable(line));
		}

		// done with grabbing the header?
		if(!d->inHeader) {
			QString str = d->headerLines.first();
			d->headerLines.takeFirst();

			QString proto;
			int code;
			QString msg;
			if(!extractMainHeader(str, &proto, &code, &msg)) {
#ifdef PROX_DEBUG
				fprintf(stderr, "HttpProxyGetStream: invalid header!\n");
#endif
				reset(true);
				error(ErrProxyNeg);
				return;
			}
			else {
#ifdef PROX_DEBUG
				fprintf(stderr, "HttpProxyGetStream: header proto=[%s] code=[%d] msg=[%s]\n", proto.latin1(), code, msg.latin1());
				for(QStringList::ConstIterator it = d->headerLines.begin(); it != d->headerLines.end(); ++it)
					fprintf(stderr, "HttpProxyGetStream: * [%s]\n", (*it).latin1());
#endif
			}

			if(code == 200) { // OK
#ifdef PROX_DEBUG
				fprintf(stderr, "HttpProxyGetStream: << Success >>\n");
#endif

				bool ok;
				int x = getHeader("Content-Length").toInt(&ok);
				if(ok)
					d->length = x;

				QPointer<QObject> self = this;
				emit handshaken();
				if(!self)
					return;
			}
			else {
				int err;
				QString errStr;
				if(code == 407) { // Authentication failed
					err = ErrProxyAuth;
					errStr = tr("Authentication failed");
				}
				else if(code == 404) { // Host not found
					err = ErrHostNotFound;
					errStr = tr("Host not found");
				}
				else if(code == 403) { // Access denied
					err = ErrProxyNeg;
					errStr = tr("Access denied");
				}
				else if(code == 503) { // Connection refused
					err = ErrConnectionRefused;
					errStr = tr("Connection refused");
				}
				else { // invalid reply
					err = ErrProxyNeg;
					errStr = tr("Invalid reply");
				}

#ifdef PROX_DEBUG
				fprintf(stderr, "HttpProxyGetStream: << Error >> [%s]\n", errStr.latin1());
#endif
				reset(true);
				error(err);
				return;
			}

			if(!d->recvBuf.isEmpty()) {
				QByteArray a = d->recvBuf;
				d->recvBuf.clear();
				emit dataReady(a);
			}
		}
	}
}