/**
 * Process unregister actions with database and close the legacy connection.
 */
void GatewayTask::processUnregister(const XMPP::Jid& user)
{
    ICQ::Session *conn = d->jidIcqTable.value(user.bare());
    if ( conn ) {
        d->icqJidTable.remove(conn);
        d->jidIcqTable.remove(user.bare());
        d->jidResources.remove(user.bare());
        delete conn;
    }
    UserManager::instance()->del(user);
}
void GatewayTask::processVCardRequest(const XMPP::Jid& user, const QString& uin, const QString& requestID)
{
    ICQ::Session *session = d->jidIcqTable.value( user.bare() );
    if ( !session ) {
        emit incomingVCard(user, uin, requestID, XMPP::vCard() );
        return;
    }
    QString key = user.bare()+"-"+uin;
    Private::vCardRequestInfo info;
    info.requestID = requestID;
    info.resource = user.resource();
    d->vCardRequests.insert(key, info);
    session->requestShortUserDetails(uin);
}
void JabberAvatarPepFetcher::avatarDataQueryFinished(const XMPP::Jid &jid, const QString &node, const XMPP::PubSubItem &item)
{
	if (jid.bare() != MyContact.id() || node != XMLNS_AVATAR_DATA || item.id() != AvatarId)
		return; // not our data :(

	JabberProtocol *jabberProtocol = qobject_cast<JabberProtocol *>(MyContact.contactAccount().protocolHandler());
	if (jabberProtocol)
		disconnect(jabberProtocol->client()->pepManager(), SIGNAL(itemPublished(XMPP::Jid,QString,XMPP::PubSubItem)), this, SLOT(avatarDataQueryFinished(XMPP::Jid,QString,XMPP::PubSubItem)));

	XMPP::Base64 base64;
	QByteArray imageData = base64.decode(item.payload().text());

	Avatar contactAvatar = AvatarManager::instance()->byContact(MyContact, ActionCreateAndAdd);
	contactAvatar.setLastUpdated(QDateTime::currentDateTime());
	contactAvatar.setNextUpdate(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t() + 7200));

	QPixmap pixmap;

	if (!imageData.isEmpty())
		pixmap.loadFromData(imageData);

	contactAvatar.setPixmap(pixmap);

	done();
	deleteLater();
}
void JabberAvatarPepFetcher::avatarMetadataQueryFinished(const XMPP::Jid &jid, const QString &node, const XMPP::PubSubItem &item)
{
	if (jid.bare() != MyContact.id() || node != XMLNS_AVATAR_METADATA)
		return; // not our data :(

	AvatarId = item.id();
	if (AvatarId == "current")
	{
		Avatar contactAvatar = AvatarManager::instance()->byContact(MyContact, ActionCreateAndAdd);
		contactAvatar.setLastUpdated(QDateTime::currentDateTime());
		contactAvatar.setNextUpdate(QDateTime::fromTime_t(QDateTime::currentDateTime().toTime_t() + 7200));
		contactAvatar.setPixmap(QPixmap());

		done();
		deleteLater();
		return;
	}

	JabberProtocol *jabberProtocol = qobject_cast<JabberProtocol *>(MyContact.contactAccount().protocolHandler());
	if (jabberProtocol)
	{
		disconnect(jabberProtocol->client()->pepManager(), SIGNAL(itemPublished(XMPP::Jid,QString,XMPP::PubSubItem)), this, SLOT(avatarMetadataQueryFinished(XMPP::Jid,QString,XMPP::PubSubItem)));
		connect(jabberProtocol->client()->pepManager(), SIGNAL(itemPublished(XMPP::Jid,QString,XMPP::PubSubItem)), this, SLOT(avatarDataQueryFinished(XMPP::Jid,QString,XMPP::PubSubItem)));
		jabberProtocol->client()->pepManager()->get(MyContact.id(), XMLNS_AVATAR_DATA, item.id());
	}
}
void GatewayTask::processUserStatusRequest(const XMPP::Jid& user)
{
    ICQ::Session *session = d->jidIcqTable.value( user.bare() );
    if ( !session ) {
        return;
    }
    if ( session->onlineStatus() == ICQ::Session::Offline ) {
        emit offlineNotifyFor(user);
    } else {
        int show;
        switch ( session->onlineStatus() ) {
            case ICQ::Session::Away:
                show = XMPP::Presence::Away;
                break;
            case ICQ::Session::NotAvailable:
                show = XMPP::Presence::NotAvailable;
                break;
            case ICQ::Session::FreeForChat:
                show = XMPP::Presence::Chat;
                break;
            case ICQ::Session::DoNotDisturb:
                show = XMPP::Presence::DoNotDisturb;
                break;
            default:
                show = XMPP::Presence::None;
                break;
        }
        emit onlineNotifyFor(user, show);
    }
}
示例#6
0
YaProfile::YaProfile(PsiAccount* account, const XMPP::Jid& jid)
	: QObject(account)
	, account_(account)
	, jid_(jid.bare())
	, lastMessage_(QDateTime::currentDateTime().addDays(-1))
{
	init();
}
/**
 * Sends @a message from jabber-user @a user to ICQ user with specified @a uin
 */
void GatewayTask::processSendMessage(const XMPP::Jid& user, const QString& uin, const QString& message)
{
    ICQ::Session *conn = d->jidIcqTable.value( user.bare() );
    if ( !conn ) {
        return;
    }
    conn->sendMessage(uin, message);
}
void GatewayTask::processAuthDeny(const XMPP::Jid& user, const QString& uin)
{
    ICQ::Session *conn = d->jidIcqTable.value( user.bare() );
    if ( !conn ) {
        return;
    }
    conn->authDeny(uin);
}
/**
 * This slot is triggered when jabber user @a user requests to remove a contact @a uin from server.
 */
void GatewayTask::processUnsubscribeRequest(const XMPP::Jid& user, const QString& uin)
{
    ICQ::Session *conn = d->jidIcqTable.value( user.bare() );
    if ( !conn ) {
        return;
    }
    conn->contactDel(uin);
}
/**
 * This slot is triggered when jabber user @a user goes offline.
 */
void GatewayTask::processUserOffline(const XMPP::Jid& user)
{
    ICQ::Session *conn = d->jidIcqTable.value( user.bare() );
    emit offlineNotifyFor(user);
    if ( !conn ) {
        return;
    }

    QStringListIterator ci(conn->contactList());
    while ( ci.hasNext() ) {
        emit contactOffline( user, ci.next() );
    }

    d->jidIcqTable.remove( user.bare() );
    d->icqJidTable.remove(conn);
    d->jidResources.remove( user.bare() );
    conn->disconnect();
    conn->deleteLater();
}
/**
 * Process legacy roster request from jabber user @a user.
 */
void GatewayTask::processCmd_RosterRequest(const XMPP::Jid& user)
{
    ICQ::Session *session = d->jidIcqTable.value( user.bare() );
    if ( !session ) {
        return;
    }

    QStringList contacts = session->contactList();
    QStringListIterator i(contacts);
    QList<XMPP::RosterXItem> items;
    while ( i.hasNext() ) {
        QString uin = i.next();
        QString name = session->contactName(uin);
        XMPP::RosterXItem item(uin, XMPP::RosterXItem::Add, name);
        items << item;
    }
    emit rosterAdd(user, items);
}
void GatewayTask::processRegister(const XMPP::Jid& user, const QString& uin, const QString& password)
{
    if ( d->jidIcqTable.contains(user.bare()) ) {
        ICQ::Session *conn = d->jidIcqTable.value(user.bare());
        d->jidIcqTable.remove(user.bare());
        d->jidResources.remove(user.bare());
        d->icqJidTable.remove(conn);

        delete conn;
    }

    UserManager::instance()->add(user.bare(), uin, password);
    UserManager::instance()->setOption(user.bare(), "first_login", QVariant(true));
    emit gatewayMessage( user, tr("You have been successfully registered") );
}
HistoryDlg::HistoryDlg(const XMPP::Jid& j, PsiAccount* pa)
: pa_(pa), jidFull_(j), from_(0), count_(30)
{
	setupUi(this);
	setModal(false);
	setAttribute(Qt::WA_DeleteOnClose);
	pa_->dialogRegister(this, jidFull_);
	setWindowTitle(tr("History for ") + j.full());
#ifndef Q_WS_MAC
	setWindowIcon(IconsetFactory::icon("psi/history").icon());
#endif


	DateTree->setHeaderLabel(tr("Date"));
	DateTree->setSortingEnabled(true);
	DateTree->setColumnHidden(1,true);
	connect(DateTree, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(doDateContextMenu(const QPoint &)));

	EventsTree->setColumnCount(4);
	QStringList headers;
	headers << tr("Type") << tr("Time") << tr("Origin") << tr("Text");
	EventsTree->setHeaderLabels(headers);
	EventsTree->sortItems(1,Qt::AscendingOrder);
	EventsTree->setSortingEnabled(true);
	EventsTree->setWordWrap(true);
	EventsTree->hideColumn(2);

	connect(EventsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), SLOT(actionOpenEvent(QTreeWidgetItem *, int)));
	connect(EventsTree, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(doEventContextMenu(const QPoint &)));
	connect(tb_previousMonth, SIGNAL(clicked()), SLOT(doPrev()));
	connect(tb_latest, SIGNAL(clicked()), SLOT(doLatest()));
	connect(tb_nextMonth, SIGNAL(clicked()), SLOT(doNext()));
	connect(pb_find, SIGNAL(clicked()), SLOT(doFind()));
	connect(pb_export, SIGNAL(clicked()), SLOT(doExport()));
	connect(pb_close, SIGNAL(clicked()), SLOT(close()));

	jid_ = j.bare();
	doLatest();

	X11WM_CLASS("history");
}
示例#14
0
void PEPManager::get(const XMPP::Jid &jid, const QString &node, const QString &id)
{
	PEPGetTask* g = new PEPGetTask(client_->rootTask(), jid.bare(), node, id);
	connect(g, SIGNAL(finished()), SLOT(getFinished()));
	g->go(true);
}
示例#15
0
void JabberClient::connect(const XMPP::Jid &jid, const QString &password, bool auth)
{
	/*
	 * Close any existing connection.
	 */
	if (jabberClient)
		jabberClient->close();

	MyJid = jid;
	Password = password;

	/*
	 * Return an error if we should force TLS but it's not available.
	 */
	if ((forceTLS() || useSSL() || probeSSL()) && !QCA::isSupported("tls"))
	{
		qDebug("no TLS");
		// no SSL support, at the connecting stage this means the problem is client-side
		QMessageBox *m = new QMessageBox(QMessageBox::Critical, tr("Jabber SSL Error"), tr("SSL support could not be initialized for account %1. This is most likely because the QCA TLS plugin is not installed on your system.").arg(jid.bare()), QMessageBox::Ok, 0, Qt::Popup);
		m->setModal(true);
		m->show();
		return;
	}

	/*
	 * Instantiate connector, responsible for dealing with the socket.
	 * This class uses KDE's socket code, which in turn makes use of
	 * the global proxy settings.
	 */
	JabberClientConnector = new XMPP::AdvancedConnector;

	JabberClientConnector->setOptSSL(useSSL());

	if (useXMPP09())
	{
		if (overrideHost())
			JabberClientConnector->setOptHostPort(Server, Port);

		JabberClientConnector->setOptProbe(probeSSL());

	}

	/*
	 * Setup authentication layer
	 */
	if ((forceTLS() || useSSL()) && QCA::isSupported("tls"))
	{
		JabberTLS = new QCA::TLS;
		JabberTLS->setTrustedCertificates(CertificateHelpers::allCertificates(CertificateHelpers::getCertificateStoreDirs()));
		JabberTLSHandler = new QCATLSHandler(JabberTLS);
		JabberTLSHandler->setXMPPCertCheck(true);

		QObject::connect(JabberTLSHandler, SIGNAL(tlsHandshaken()), SLOT(slotTLSHandshaken()));
	}

	/*
	 * Instantiate client stream which handles the network communication by referring
	 * to a connector (proxying etc.) and a TLS handler (security layer)
	 */
	JabberClientStream = new XMPP::ClientStream(JabberClientConnector, JabberTLSHandler);

	{
		using namespace XMPP;
		QObject::connect(JabberClientStream, SIGNAL(needAuthParams(bool, bool, bool)),
				   this, SLOT(slotCSNeedAuthParams(bool, bool, bool)));
		QObject::connect(JabberClientStream, SIGNAL(authenticated()),
				   this, SLOT(slotCSAuthenticated()));
		QObject::connect(JabberClientStream, SIGNAL(connectionClosed()),
				   this, SLOT(slotCSDisconnected()));
		QObject::connect(JabberClientStream, SIGNAL(delayedCloseFinished()),
				   this, SLOT(slotCSDisconnected()));
		QObject::connect(JabberClientStream, SIGNAL(warning(int)),
				   this, SLOT(slotCSWarning(int)));
		QObject::connect(JabberClientStream, SIGNAL(error(int)),
				   this, SLOT(slotCSError(int)));
	}

	JabberClientStream->setOldOnly(useXMPP09());

	/*
	 * Initiate anti-idle timer (will be triggered every 55 seconds).
	 */
	JabberClientStream->setNoopTime(55000);

	/*
	 * Allow plaintext password authentication or not?
	 */
	JabberClientStream->setAllowPlain(allowPlainTextPassword());

	/*
	 * Setup client layer.
	 */
	jabberClient = new XMPP::Client(this);

	/*
	 * Setup privacy manager
	 */
	///privacyManager = new PrivacyManager ( rootTask() );

	/*
	 * Enable file transfer (IP and server will be set after connection
	 * has been established.
	 */
	if (fileTransfersEnabled())
	{
		jabberClient->setFileTransferEnabled(true);
		{
			using namespace XMPP;
			QObject::connect(jabberClient->fileTransferManager(), SIGNAL(incomingReady()),
					   this, SLOT(slotIncomingFileTransfer()));
		}
	}

	/*if (jingleEnabled())
	{*/

#ifdef JINGLE_SUPPORT
		jabberClient->setJingleEnabled(true);

		{
			using namespace XMPP;
			QObject::connect ( jabberClient->jingleSessionManager(), SIGNAL ( incomingSession() ),
					   this, SLOT ( slotIncomingJingleSession () ) );
		}
#else
		jabberClient->setJingleEnabled(false);
#endif
	/*}*/

	/* This should only be done here to connect the signals, otherwise it is a
	 * bad idea.
	 */
	{
		using namespace XMPP;
		QObject::connect(jabberClient, SIGNAL(subscription(const Jid &, const QString &, const QString &)),
				   this, SLOT(slotSubscription(const Jid &, const QString &)));
		QObject::connect(jabberClient, SIGNAL(rosterRequestFinished(bool, int, const QString &)),
				   this, SLOT(slotRosterRequestFinished(bool, int, const QString &)));
		QObject::connect(jabberClient, SIGNAL(rosterItemAdded(const RosterItem &)),
				   this, SLOT(slotNewContact(const RosterItem &)));
		QObject::connect(jabberClient, SIGNAL(rosterItemUpdated(const RosterItem &)),
				   this, SLOT(slotContactUpdated(const RosterItem &)));
		QObject::connect(jabberClient, SIGNAL(rosterItemRemoved(const RosterItem &)),
				   this, SLOT(slotContactDeleted(const RosterItem &)));
		QObject::connect(jabberClient, SIGNAL(resourceAvailable(const Jid &, const Resource &)),
				   this, SLOT(slotResourceAvailable(const Jid &, const Resource &)));
		QObject::connect(jabberClient, SIGNAL(resourceUnavailable(const Jid &, const Resource &)),
				   this, SLOT(slotResourceUnavailable(const Jid &, const Resource &)));
		QObject::connect(jabberClient, SIGNAL(messageReceived(const Message &)),
				   this, SLOT(slotReceivedMessage(const Message &)));
		QObject::connect(jabberClient, SIGNAL(groupChatJoined(const Jid &)),
				   this, SLOT(slotGroupChatJoined(const Jid &)));
		QObject::connect(jabberClient, SIGNAL(groupChatLeft(const Jid &)),
				   this, SLOT(slotGroupChatLeft(const Jid &)));
		QObject::connect(jabberClient, SIGNAL(groupChatPresence(const Jid &, const Status &)),
				   this, SLOT(slotGroupChatPresence(const Jid &, const Status &)));
		QObject::connect(jabberClient, SIGNAL(groupChatError(const Jid &, int, const QString &)),
				   this, SLOT(slotGroupChatError(const Jid &, int, const QString &)));
		//QObject::connect(jabberClient, SIGNAL(debugText(const QString &)),
		//		   this, SLOT(slotPsiDebug(const QString &)));
		QObject::connect(jabberClient, SIGNAL(xmlIncoming(const QString&)),
				   this, SLOT(slotIncomingXML(const QString &)));
		QObject::connect(jabberClient, SIGNAL(xmlOutgoing(const QString&)),
				   this, SLOT(slotOutgoingXML(const QString &)));
	}

	jabberClient->setClientName(clientName());
	jabberClient->setClientVersion(clientVersion());
	jabberClient->setOSName(osName());

	// Set caps information
	jabberClient->setCapsNode(capsNode());
	jabberClient->setCapsVersion(capsVersion());

	// Set Disco Identity
	//jabberClient->setIdentity( discoIdentity());


	DiscoItem::Identity identity;
	identity.category = "client";
	identity.type = "pc";
	identity.name = "Kadu";
	jabberClient->setIdentity(identity);

	QStringList features;
//	features << "http://jabber.org/protocol/commands";
	features << "http://jabber.org/protocol/rosterx";
//	features << "http://jabber.org/protocol/muc";
	features << "jabber:x:data";
	jabberClient->setFeatures(Features(features));

	jabberClient->setTimeZone(timeZoneName(), timeZoneOffset());

	jabberClient->connectToServer(JabberClientStream, jid, auth);
}
void GatewayTask::processUserOnline(const XMPP::Jid& user, int showStatus)
{
    bool first_login = UserManager::instance()->getOption(user.bare(), "first_login").toBool();

    if ( d->icqHost.isEmpty() || !d->icqPort ) {
        qCritical("[GT] processLogin: icq host and/or port values are not set. Aborting...");
        return;
    }
    ICQ::Session::OnlineStatus icqStatus = xmmpToIcqStatus(XMPP::Presence::Show(showStatus));

    if ( d->jidIcqTable.contains( user.bare() ) ) {
        ICQ::Session *conn = d->jidIcqTable.value( user.bare() );
        conn->setOnlineStatus(icqStatus);
        d->jidResources.insert(user.bare(), user);
        return;
    }

    if ( UserManager::instance()->isRegistered(user.bare()) ) {
        QString uin = UserManager::instance()->getUin(user.bare());
        QString password = UserManager::instance()->getPassword(user.bare());

        ICQ::Session *conn = new ICQ::Session(this);
        conn->setUin(uin);
        conn->setPassword(password);
        conn->setServerHost(d->icqHost);
        conn->setServerPort(d->icqPort);
        conn->setOnlineStatus(ICQ::Session::Online);

        QObject::connect( conn, SIGNAL( statusChanged(int) ),
                          SLOT( processIcqStatus(int) ) );
        QObject::connect( conn, SIGNAL( userOnline(QString,int) ),
                          SLOT( processContactOnline(QString,int) ) );
        QObject::connect( conn, SIGNAL( userOffline(QString) ),
                          SLOT( processContactOffline(QString) ) );
        QObject::connect( conn, SIGNAL( authGranted(QString) ),
                          SLOT( processAuthGranted(QString) ) );
        QObject::connect( conn, SIGNAL( authDenied(QString) ),
                          SLOT( processAuthDenied(QString) ) );
        QObject::connect( conn, SIGNAL( authRequest(QString) ),
                          SLOT( processAuthRequest(QString) ) );
        QObject::connect( conn, SIGNAL( incomingMessage(QString,QString) ),
                          SLOT( processIncomingMessage(QString,QString) ) );
        QObject::connect( conn, SIGNAL( incomingMessage(QString,QString,QDateTime) ),
                          SLOT( processIncomingMessage(QString,QString,QDateTime) ) );
        QObject::connect( conn, SIGNAL( connected() ),
                          SLOT( processIcqSignOn() ) );
        QObject::connect( conn, SIGNAL( disconnected() ),
                          SLOT( processIcqSignOff() ) );
        QObject::connect( conn, SIGNAL( error(QString) ),
                          SLOT( processIcqError(QString) ) );
        QObject::connect( conn, SIGNAL( shortUserDetailsAvailable(QString) ),
                          SLOT( processShortUserDetails(QString) ) );

        if ( first_login ) {
            QObject::connect( conn, SIGNAL( rosterAvailable() ), SLOT( processIcqFirstLogin() ) );
        }

        d->jidIcqTable.insert(user.bare(), conn);
        d->icqJidTable.insert(conn, user.bare());
        d->jidResources.insert(user.bare(), user);

        QTextCodec *codec;
        if ( UserManager::instance()->hasOption(user.bare(), "encoding") ) {
            codec = QTextCodec::codecForName( UserManager::instance()->getOption(user.bare(), "encoding").toByteArray() );
            if ( codec == 0 ) {
                codec = QTextCodec::codecForName("windows-1251");
            }
        } else {
            codec = QTextCodec::codecForName("windows-1251");
        }
        Q_ASSERT( codec != 0 );
        conn->setCodecForMessages(codec);
        conn->connect();
    }
}