From 92f23bc20bb8f270ac84699d3082f891051a0b7a Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 2 May 2011 14:40:35 +0200 Subject: [PATCH] sipjreen: regressions--: subscription handling UPDATE JREEN to make it work! --- src/sip/jreen/jabber.cpp | 102 +++++++++++++++++++++++++++++++++++++-- src/sip/jreen/jabber.h | 7 ++- thirdparty/jreen | 2 +- 3 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 10a769774..4d8c165fe 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -68,6 +68,9 @@ JabberPlugin::JabberPlugin() // add VCardUpdate extension to own presence m_client->presence().addExtension( new Jreen::VCardUpdate() ); + // initaliaze the roster + m_roster = new Jreen::SimpleRoster( m_client ); + // initialize the AvatarManager m_avatarManager = new AvatarManager( m_client ); @@ -91,9 +94,14 @@ JabberPlugin::JabberPlugin() connect(m_client, SIGNAL(serverFeaturesReceived(QSet)), SLOT(onConnect())); connect(m_client, SIGNAL(disconnected(Jreen::Client::DisconnectReason)), SLOT(onDisconnect(Jreen::Client::DisconnectReason))); connect(m_client, SIGNAL(newMessage(Jreen::Message)), SLOT(onNewMessage(Jreen::Message))); - connect(m_client, SIGNAL(newPresence(Jreen::Presence)), SLOT(onNewPresence(Jreen::Presence))); + connect(m_client, SIGNAL(newIQ(Jreen::IQ)), SLOT(onNewIq(Jreen::IQ))); + connect(m_roster, SIGNAL(presenceReceived(Jreen::RosterItem::Ptr,Jreen::Presence)), + SLOT(onPresenceReceived(Jreen::RosterItem::Ptr,Jreen::Presence))); + connect(m_roster, SIGNAL(subscriptionReceived(Jreen::RosterItem::Ptr,Jreen::Presence)), + SLOT(onSubscriptionReceived(Jreen::RosterItem::Ptr,Jreen::Presence))); + connect(m_avatarManager, SIGNAL(newAvatar(QString)), SLOT(onNewAvatar(QString))); } @@ -201,7 +209,6 @@ JabberPlugin::onConnect() m_client->setPingInterval(1000); // load roster - m_roster = new Jreen::SimpleRoster( m_client ); m_roster->load(); //FIXME: this implementation is totally broken atm, so it's disabled to avoid harm :P @@ -497,8 +504,10 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message) } -void JabberPlugin::onNewPresence( const Jreen::Presence& presence) +void JabberPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ) { + Q_UNUSED(item); + Jreen::JID jid = presence.from(); QString fulljid( jid.full() ); @@ -540,6 +549,93 @@ void JabberPlugin::onNewPresence( const Jreen::Presence& presence) } } +void JabberPlugin::onSubscriptionReceived(const Jreen::RosterItem::Ptr& item, const Jreen::Presence& presence) +{ + qDebug() << Q_FUNC_INFO << "presence type: " << presence.subtype(); + if(item) + qDebug() << Q_FUNC_INFO << presence.from().full() << "subs" << item->subscription() << "ask" << item->ask(); + else + qDebug() << Q_FUNC_INFO << "item empty"; + + // don't do anything if the contact is already subscribed to us + if( presence.subtype() != Jreen::Presence::Subscribe || + ( + item && (item->subscription() == Jreen::RosterItem::From || item->subscription() == Jreen::RosterItem::Both) + ) + ) + { + return; + } + + // check if the requester is already on the roster + if(item && + ( + item->subscription() == Jreen::RosterItem::To || + ( item->subscription() == Jreen::RosterItem::None && !item->ask().isEmpty() ) + ) + ) + { + qDebug() << Q_FUNC_INFO << presence.from().bare() << "already on the roster so we assume ack'ing subscription request is okay..."; + m_roster->allowSubscription(presence.from(), true); + + return; + } + + qDebug() << Q_FUNC_INFO << presence.from().bare() << "open subscription request box"; + + // preparing the confirm box for the user + QMessageBox *confirmBox = new QMessageBox( + QMessageBox::Question, + tr( "Authorize User" ), + QString( tr( "Do you want to grant %1 access to your Collection?" ) ).arg(presence.from().bare()), + QMessageBox::Yes | QMessageBox::No, + 0 + ); + + // add confirmBox to m_subscriptionConfirmBoxes + m_subscriptionConfirmBoxes.insert( presence.from(), confirmBox ); + + // display the box and wait for the answer + confirmBox->open( this, SLOT( onSubscriptionRequestConfirmed( int ) ) ); +} + +void +JabberPlugin::onSubscriptionRequestConfirmed( int result ) +{ + qDebug() << Q_FUNC_INFO << result; + + QList< QMessageBox* > confirmBoxes = m_subscriptionConfirmBoxes.values(); + Jreen::JID jid; + + foreach( QMessageBox* currentBox, confirmBoxes ) + { + if( currentBox == sender() ) + { + jid = m_subscriptionConfirmBoxes.key( currentBox ); + } + } + + qDebug() << Q_FUNC_INFO << "box confirmed for" << jid.bare(); + + // we got an answer, deleting the box + m_subscriptionConfirmBoxes.remove( jid ); + sender()->deleteLater(); + + QMessageBox::StandardButton allowSubscription = static_cast( result ); + + if ( allowSubscription == QMessageBox::Yes ) + { + qDebug() << Q_FUNC_INFO << jid.bare() << "accepted by user, adding to roster"; + addContact(jid, ""); + } + else + { + qDebug() << Q_FUNC_INFO << jid.bare() << "declined by user"; + } + + m_roster->allowSubscription( jid, allowSubscription == QMessageBox::Yes ); +} + void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context) { if( context == RequestDisco ) diff --git a/src/sip/jreen/jabber.h b/src/sip/jreen/jabber.h index 17d4cc31b..faa73c179 100644 --- a/src/sip/jreen/jabber.h +++ b/src/sip/jreen/jabber.h @@ -38,6 +38,7 @@ #include #include +#include #define MYNAME "SIPJREEN" #define TOMAHAWK_FEATURE QLatin1String( "tomahawk:sip:v1" ) @@ -79,7 +80,10 @@ private slots: void onDisconnect(Jreen::Client::DisconnectReason reason); void onAuthError(int code, const QString &msg); - void onNewPresence( const Jreen::Presence& presence ); + void onPresenceReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ); + void onSubscriptionReceived( const Jreen::RosterItem::Ptr &item, const Jreen::Presence& presence ); + void onSubscriptionRequestConfirmed( int result ); + void onNewMessage( const Jreen::Message& message ); void onError( const Jreen::Connection::SocketError& e ) { @@ -112,6 +116,7 @@ private: Jreen::MUCRoom *m_room; Jreen::SimpleRoster *m_roster; QHash m_peers; + QHash m_subscriptionConfirmBoxes; enum IqContext { NoContext, RequestDisco, RequestedDisco, SipMessageSent, RequestedVCard }; QStringList m_legacy_peers; AvatarManager *m_avatarManager; diff --git a/thirdparty/jreen b/thirdparty/jreen index ed1680de0..8f995f246 160000 --- a/thirdparty/jreen +++ b/thirdparty/jreen @@ -1 +1 @@ -Subproject commit ed1680de066ec7a414117f94e92a9f1b9b40fb24 +Subproject commit 8f995f246637f533feb7124744e113034a32b505