Exemple #1
0
	void cs_warning(int warn)
	{
		if(warn == XMPP::ClientStream::WarnOldVersion) {
			appendSysMsg("Warning: pre-1.0 protocol server", Qt::red);
		}
		else if(warn == XMPP::ClientStream::WarnNoTLS) {
			appendSysMsg("Warning: TLS not available!", Qt::red);
		}
		stream->continueAfterWarning();
	}
Exemple #2
0
	void tls_handshaken()
	{
		//QCA::Certificate cert = tls->peerCertificate();
		int vr = tls->peerIdentityResult();
		if (vr == QCA::TLS::Valid && !tlsHandler->certMatchesHostname()) vr = QCA::TLS::HostMismatch;

		appendSysMsg("Successful TLS handshake.");
		if(vr == QCA::TLS::Valid)
			appendSysMsg("Valid certificate.");
		else {
			appendSysMsg(QString("Invalid certificate: %1").arg(resultToString(vr)), Qt::red);
			appendSysMsg("Continuing anyway");
		}

		tlsHandler->continueAfterHandshake();
	}
Exemple #3
0
	void cs_authenticated()
	{
		connected = true;
		pb_send->setEnabled(true);
		conn->changePollInterval(10); // slow down after login
		appendSysMsg("Authenticated");
	}
Exemple #4
0
	void stop()
	{
		if(!active)
			return;

		if(connected) {
			pb_go->setEnabled(false);
			appendSysMsg("Disconnecting...");
			stream->close();
		}
		else {
			stream->close();
			appendSysMsg("Disconnected");
			cleanup();
		}
	}
Exemple #5
0
void ChatDlg::updateContact(const Jid &j, bool fromPresence)
{
	// if groupchat, only update if the resource matches
	if (account()->findGCContact(j) && !jid().compare(j)) {
		return;
	}

	if (jid().compare(j, false)) {
		QList<UserListItem*> ul = account()->findRelevant(j);
		UserStatus userStatus = userStatusFor(jid(), ul, false);
		if (userStatus.statusType == XMPP::Status::Offline)
			contactChatState_ = XMPP::StateNone;

		bool statusChanged = false;
		if (status_ != userStatus.statusType || statusString_ != userStatus.status) {
			statusChanged = true;
			status_ = userStatus.statusType;
			statusString_ = userStatus.status;
		}

		contactUpdated(userStatus.userListItem, userStatus.statusType, userStatus.status);

		if (userStatus.userListItem) {
			dispNick_ = JIDUtil::nickOrJid(userStatus.userListItem->name(), userStatus.userListItem->jid().full());
			nicksChanged();
			invalidateTab();

			key_ = userStatus.publicKeyID;
			updatePGP();

			if (fromPresence && statusChanged) {
				QString msg = tr("%1 is %2").arg(Qt::escape(dispNick_)).arg(status2txt(status_));
				if (!statusString_.isEmpty()) {
					QString ss = TextUtil::linkify(TextUtil::plain2rich(statusString_));
					if (PsiOptions::instance()->getOption("options.ui.emoticons.use-emoticons").toBool()) {
						ss = TextUtil::emoticonify(ss);
					}
					if (PsiOptions::instance()->getOption("options.ui.chat.legacy-formatting").toBool()) {
						ss = TextUtil::legacyFormat(ss);
					}
					msg += QString(" [%1]").arg(ss);
				}
				appendSysMsg(msg);
			}
		}

		// Update capabilities
		capsChanged(jid());

		// Reset 'is composing' event if the status changed
		if (statusChanged && contactChatState_ != XMPP::StateNone) {
			if (contactChatState_ == XMPP::StateComposing || contactChatState_ == XMPP::StateInactive) {
				setContactChatState(XMPP::StatePaused);
			}
		}
	}
}
Exemple #6
0
	void cs_connected()
	{
		QString s = "Connected";
		if(conn->havePeerAddress())
			s += QString(" (%1:%2)").arg(conn->peerAddress().toString()).arg(conn->peerPort());
		if(conn->useSSL())
			s += " [ssl]";
		appendSysMsg(s);
	}
Exemple #7
0
void ChatDlg::setContactChatState(ChatState state)
{
	contactChatState_ = state;
	if (state == XMPP::StateGone) {
		appendSysMsg(tr("%1 ended the conversation").arg(Qt::escape(dispNick_)));
	}
	else {
		// Activate ourselves
		if (lastChatState_ == XMPP::StateGone) {
			setChatState(XMPP::StateActive);
		}
	}
	invalidateTab();
}
Exemple #8
0
	void cs_needAuthParams(bool user, bool pass, bool realm)
	{
		QString s = "Need auth parameters -";
		if(user)
			s += " (Username)";
		if(pass)
			s += " (Password)";
		if(realm)
			s += " (Realm)";
		appendSysMsg(s);

		if(user) {
			if(!le_user->text().isEmpty())
				stream->setUsername(le_user->text());
			else
				stream->setUsername(jid.node());
		}
		if(pass) {
			if(!le_pass->text().isEmpty())
				stream->setPassword(le_pass->text());
			else {
				conn->changePollInterval(10); // slow down during prompt
				bool ok;
				QString s = QInputDialog::getText(this, tr("Password"), tr("Enter the password for %1").arg(jid.full()), QLineEdit::Password, QString(), &ok);
				if(!ok) {
					stop();
					return;
				}
				stream->setPassword(s);

				conn->changePollInterval(2); // resume speed
			}
		}
		if(realm)
			stream->setRealm(jid.domain());

		stream->continueAfterParams();
	}
Exemple #9
0
void ChatDlg::appendMessage(const Message &m, bool local)
{
	// figure out the encryption state
	bool encChanged = false;
	bool encEnabled = false;
	if (lastWasEncrypted_ != m.wasEncrypted()) {
		encChanged = true;
	}
	lastWasEncrypted_ = m.wasEncrypted();
	encEnabled = lastWasEncrypted_;

	if (encChanged) {
		if (encEnabled) {
			appendSysMsg(QString("<icon name=\"psi/cryptoYes\"> ") + tr("Encryption Enabled"));
			if (!local) {
				setPGPEnabled(true);
			}
		}
		else {
			appendSysMsg(QString("<icon name=\"psi/cryptoNo\"> ") + tr("Encryption Disabled"));
			if (!local) {
				setPGPEnabled(false);

				// enable warning
				warnSend_ = true;
				QTimer::singleShot(3000, this, SLOT(setWarnSendFalse()));
			}
		}
	}

	QString txt = messageText(m);

	ChatDlg::SpooledType spooledType = m.spooled() ?
	                                   ChatDlg::Spooled_OfflineStorage :
	                                   ChatDlg::Spooled_None;
	if (isEmoteMessage(m))
		appendEmoteMessage(spooledType, m.timeStamp(), local, txt);
	else
		appendNormalMessage(spooledType, m.timeStamp(), local, txt);

	appendMessageFields(m);

	if (local) {
		deferredScroll();
	}

	// if we're not active, notify the user by changing the title
	if (!isActiveTab()) {
		++pending_;
		invalidateTab();
		if (PsiOptions::instance()->getOption("options.ui.flash-windows").toBool()) {
			doFlash(true);
		}
		if (PsiOptions::instance()->getOption("options.ui.chat.raise-chat-windows-on-new-messages").toBool()) {
			if (isTabbed()) {
				TabDlg* tabSet = getManagingTabDlg();
				tabSet->selectTab(this);
				::bringToFront(tabSet, false);
			}
			else {
				::bringToFront(this, false);
			}
		}
	}
	//else {
	//	messagesRead(jid());
	//}

	if (!local) {
		keepOpen_ = true;
		QTimer::singleShot(1000, this, SLOT(setKeepOpenFalse()));
	}
}
Exemple #10
0
	void cs_stanzaWritten()
	{
		appendSysMsg("Stanza sent");
	}
Exemple #11
0
	void cs_delayedCloseFinished()
	{
		appendSysMsg("Disconnected");
		cleanup();
	}
Exemple #12
0
	void cs_connectionClosed()
	{
		appendSysMsg("Disconnected by peer");
		cleanup();
	}
Exemple #13
0
	void cs_securityLayerActivated(int type)
	{
		appendSysMsg(QString("Security layer activated (%1)").arg((type == XMPP::ClientStream::LayerTLS) ? "TLS": "SASL"));
	}
Exemple #14
0
	void start()
	{
		if(active)
			return;

		jid = XMPP::Jid(le_jid->text());
		if(jid.domain().isEmpty() || jid.node().isEmpty() || jid.resource().isEmpty()) {
			QMessageBox::information(this, tr("Error"), tr("Please enter the Full JID to connect with."));
			return;
		}

		int p = cb_proxy->currentIndex();
		XMPP::AdvancedConnector::Proxy proxy;
		if(p > 0) {
			QString s = le_proxyhost->text();
			QString url = le_proxyurl->text();
			if(p != 3 && s.isEmpty()) {
				QMessageBox::information(this, tr("Error"), tr("You must specify a host:port for the proxy."));
				return;
			}
			if(p == 3 && s.isEmpty() && url.isEmpty()) {
				QMessageBox::information(this, tr("Error"), tr("You must at least enter a URL to use http poll."));
				return;
			}
			QString host;
			int port = 0;
			if(!s.isEmpty()) {
				int n = s.indexOf(':');
				if(n == -1) {
					QMessageBox::information(this, tr("Error"), tr("Please enter the proxy host in the form 'host:port'."));
					return;
				}
				host = s.mid(0, n);
				port = s.mid(n+1).toInt();
			}
			if(p == 1)
				proxy.setHttpConnect(host, port);
			else if(p == 2)
				proxy.setSocks(host, port);
			else if(p == 3) {
				proxy.setHttpPoll(host, port, url);
				proxy.setPollInterval(2); // fast during login
			}
			proxy.setUserPass(le_proxyuser->text(), le_proxypass->text());
		}
		bool probe = (p != 3 && ck_probe->isChecked());
		bool useHost = (!probe && !le_host->text().isEmpty());
		QString host;
		int port = 0;
		bool ssl = false;
		if(useHost) {
			QString s = le_host->text();
			int n = s.indexOf(':');
			if(n == -1) {
				QMessageBox::information(this, tr("Error"), tr("Please enter the host in the form 'host:port'."));
				return;
			}
			host = s.mid(0, n);
			port = s.mid(n+1).toInt();

			if(ck_ssl->isChecked())
				ssl = true;
		}
		if(sb_ssfmin->value() > sb_ssfmax->value()) {
			QMessageBox::information(this, tr("Error"), tr("Error: SSF Min is greater than SSF Max."));
			return;
		}

		if((probe || ssl) && !tls) {
			QMessageBox::information(this, tr("Error"), tr("Error: TLS not available.  Disable any TLS options."));
			return;
		}

		// prepare
		conn->setProxy(proxy);
		if(useHost)
			conn->setOptHostPort(host, port);
		else
			conn->setOptHostPort("", 0);
		conn->setOptProbe(probe);
		conn->setOptSSL(ssl);

		if(tls) {
			tls->setTrustedCertificates(QCA::systemStore());
		}

		stream->setNoopTime(55000); // every 55 seconds
		stream->setAllowPlain(ck_plain->isChecked() ? XMPP::ClientStream::AllowPlain : XMPP::ClientStream::NoAllowPlain);
		stream->setRequireMutualAuth(ck_mutual->isChecked());
		stream->setSSFRange(sb_ssfmin->value(), sb_ssfmax->value());
		//stream->setOldOnly(true);
		stream->setCompress(true);
		
		gb_server->setEnabled(false);
		pb_go->setText(tr("&Disconnect"));
		pb_go->setFocus();
		active = true;

		appendSysMsg("Connecting...");
		stream->connectToServer(jid);
	}