From 5c732098f74535d7cfcafbf00837fe099f2cdaea Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 15:42:53 +0200 Subject: [PATCH 01/18] sipjreen: turn stupid assert into a sensible error message --- src/sip/jreen/jabber.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 9b2b7eeb1..0d7f37f75 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -139,11 +139,13 @@ JabberPlugin::~JabberPlugin() void JabberPlugin::setProxy( const QNetworkProxy &proxy ) { - if(m_currentServer.isEmpty() || !(m_currentPort > 0)) + qDebug() << Q_FUNC_INFO; + + if( ( proxy.type() != QNetworkProxy::NoProxy ) && ( m_currentServer.isEmpty() || !(m_currentPort > 0) ) ) { // patches are welcome in Jreen that implement jdns through proxy - qDebug() << Q_FUNC_INFO << "Jreen proxy only works when you explicitly set host and port"; - Q_ASSERT(false); + emit error( SipPlugin::ConnectionError, + errorMessage( tr( "You need to set hostname and port of your jabber server, if you want to use it through a proxy" ) ) ); return; } From 6c8252cefb63cd15b65c730aa62eb8b3f5497184 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 15:43:35 +0200 Subject: [PATCH 02/18] Bump jreen submodule revision --- thirdparty/jreen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty/jreen b/thirdparty/jreen index 40fd6b0a3..58fb2d4bc 160000 --- a/thirdparty/jreen +++ b/thirdparty/jreen @@ -1 +1 @@ -Subproject commit 40fd6b0a3dbc729fdf1db8490848b43d5b1f57f5 +Subproject commit 58fb2d4bc2abebdf778ca230a84042c7f5694583 From 6118432dd757493322065b19bba5d398c57d4c8c Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 15:44:17 +0200 Subject: [PATCH 03/18] Add proxy support to the sip plugins and the sip handler --- src/libtomahawk/sip/SipHandler.cpp | 12 ++++++++++++ src/libtomahawk/sip/SipHandler.h | 3 +++ src/libtomahawk/sip/SipPlugin.h | 2 +- src/tomahawkapp.cpp | 4 +--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index 2907ddb8e..46b6d18b4 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -367,6 +367,7 @@ SipHandler::connectPlugin( bool startup, const QString &pluginId ) if ( sip->pluginId() == pluginId ) { Q_ASSERT( m_enabledPlugins.contains( sip ) ); // make sure the plugin we're connecting is enabled. should always be the case + sip->setProxy( m_proxy ); sip->connectPlugin( startup ); } } @@ -417,6 +418,17 @@ SipHandler::toggleConnect() connectAll(); } +void +SipHandler::setProxy( const QNetworkProxy& proxy ) +{ + qDebug() << Q_FUNC_INFO; + + m_proxy = proxy; + + foreach( SipPlugin* sip, m_allPlugins ) + sip->setProxy( proxy ); +} + void SipHandler::onPeerOnline( const QString& jid ) diff --git a/src/libtomahawk/sip/SipHandler.h b/src/libtomahawk/sip/SipHandler.h index 8fc7a222b..93b689cb7 100644 --- a/src/libtomahawk/sip/SipHandler.h +++ b/src/libtomahawk/sip/SipHandler.h @@ -67,6 +67,8 @@ public slots: void toggleConnect(); + void setProxy( const QNetworkProxy &proxy ); + // create a new plugin of the given name. the name is the value returned in SipPluginFactory::pluginName // be default sip plugins are NOt connected when created SipPlugin* createPlugin( const QString& factoryName ); @@ -116,6 +118,7 @@ private: QList< SipPlugin* > m_enabledPlugins; QList< SipPlugin* > m_connectedPlugins; bool m_connected; + QNetworkProxy m_proxy; //TODO: move this to source QHash m_peersSipInfos; diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index 156944e21..f6b7b334a 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -87,7 +87,7 @@ public slots: virtual void addContact( const QString &jid, const QString& msg = QString() ) = 0; virtual void sendMsg( const QString& to, const QString& msg ) = 0; - void setProxy( const QNetworkProxy &proxy ); + virtual void setProxy( const QNetworkProxy &proxy ); signals: void error( int, const QString& ); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index e3e614b34..1fcac1d34 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -534,10 +534,8 @@ TomahawkApp::setupSIP() #endif qDebug() << "Connecting SIP classes"; + SipHandler::instance()->setProxy( *TomahawkUtils::proxy() ); SipHandler::instance()->loadFromConfig( true ); - -// m_sipHandler->setProxy( *TomahawkUtils::proxy() ); - } } From 12462ead58ff5d66f699609dee70f7c120789303 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 15:51:16 +0200 Subject: [PATCH 04/18] Oops, fix build --- src/sip/jreen/jabber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 0d7f37f75..d030238bf 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -145,7 +145,7 @@ JabberPlugin::setProxy( const QNetworkProxy &proxy ) { // patches are welcome in Jreen that implement jdns through proxy emit error( SipPlugin::ConnectionError, - errorMessage( tr( "You need to set hostname and port of your jabber server, if you want to use it through a proxy" ) ) ); + tr( "You need to set hostname and port of your jabber server, if you want to use it through a proxy" ) ); return; } From 012b72d4fd66ee72ba161c1184b5bf4d1feebf2d Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 18:54:16 +0200 Subject: [PATCH 05/18] Remove legacy dependency on gnutls --- src/CMakeLists.linux.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/CMakeLists.linux.txt b/src/CMakeLists.linux.txt index 7f902f2b8..fa95ad82d 100644 --- a/src/CMakeLists.linux.txt +++ b/src/CMakeLists.linux.txt @@ -3,14 +3,6 @@ SET( OS_SPECIFIC_LINK_LIBRARIES tomahawklib ) -IF( "${gui}" STREQUAL "no" ) -ELSE() - SET( OS_SPECIFIC_LINK_LIBRARIES - ${OS_SPECIFIC_LINK_LIBRARIES} - gnutls - ) -ENDIF() - FILE( GLOB _icons "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-*.png" ) FOREACH( _file ${_icons} ) STRING( REPLACE "${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon-" "" _res ${_file} ) From 47158465d900b0a3adb43b0fa9b85cfb259cc18a Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Sun, 8 May 2011 19:12:46 +0200 Subject: [PATCH 06/18] * Fixed pipeline. Speeds it up, allows for parallel execution of multiple same-weighted resolvers. --- src/libtomahawk/pipeline.cpp | 82 +++++++++++++++++------------------- thirdparty/jreen | 2 +- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index c3bab44d6..cbd0d47ed 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -188,9 +188,6 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) if ( decQIDState( q ) == 0 ) { - // All resolvers have reported back their results for this query now - qDebug() << "Finished resolving:" << q->toString() << q->numResults(); - if ( !q->solved() ) q->onResolvingFinished(); @@ -243,45 +240,43 @@ Pipeline::shunt( const query_ptr& q ) qDebug() << Q_FUNC_INFO << q->solved() << q->toString() << q->id(); unsigned int lastweight = 0; unsigned int lasttimeout = 0; - - if ( q->solved() ) - { -// qDebug() << "Query solved, pipeline aborted:" << q->toString() -// << "numresults:" << q->results().length(); - - QList< result_ptr > rl; - reportResults( q->id(), rl ); - return; - } - int thisResolver = 0; - int i = 0; - foreach( Resolver* r, m_resolvers ) + bool dispatched = false; + + if ( !q->resolvingFinished() ) { - i++; - if ( r->weight() >= q->lastPipelineWeight() ) - continue; + int i = 0; + foreach( Resolver* r, m_resolvers ) + { + i++; + if ( r->weight() >= q->lastPipelineWeight() ) + continue; - if ( lastweight == 0 ) - { - lastweight = r->weight(); - lasttimeout = r->timeout(); - //qDebug() << "Shunting into weight" << lastweight << "q:" << q->toString(); - } - if ( lastweight == r->weight() ) - { - // snag the lowest timeout at this weight - if ( r->timeout() < lasttimeout ) + if ( lastweight == 0 ) + { + lastweight = r->weight(); lasttimeout = r->timeout(); + //qDebug() << "Shunting into weight" << lastweight << "q:" << q->toString(); + } + if ( lastweight == r->weight() ) + { + // snag the lowest timeout at this weight + if ( r->timeout() < lasttimeout ) + lasttimeout = r->timeout(); - // resolvers aren't allowed to block in this call: - qDebug() << "Dispatching to resolver" << r->name() << q->toString(); + // resolvers aren't allowed to block in this call: + if ( dispatched ) + incQIDState( q ); - thisResolver = i; - r->resolve( q ); + dispatched = true; + qDebug() << "Dispatching to resolver" << r->name() << q->toString(); + + thisResolver = i; + r->resolve( q ); + } + else + break; } - else - break; } if ( lastweight > 0 ) @@ -290,18 +285,19 @@ Pipeline::shunt( const query_ptr& q ) if ( thisResolver < m_resolvers.count() ) { + qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString(); incQIDState( q ); -// qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString(); new FuncTimeout( lasttimeout, boost::bind( &Pipeline::shunt, this, q ), this ); } } else { - //qDebug() << "Reached end of pipeline for:" << q->toString(); // reached end of pipeline - QList< result_ptr > rl; - reportResults( q->id(), rl ); - return; + qDebug() << "Reached end of pipeline for:" << q->toString(); + + decQIDState( q ); + if ( !q->solved() ) + q->onResolvingFinished(); } shuntNext(); @@ -329,7 +325,7 @@ Pipeline::incQIDState( const Tomahawk::query_ptr& query ) state = m_qidsState.value( query->id() ) + 1; } -// qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state; + qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state; m_qidsState.insert( query->id(), state ); return state; @@ -344,12 +340,12 @@ Pipeline::decQIDState( const Tomahawk::query_ptr& query ) int state = m_qidsState.value( query->id() ) - 1; if ( state ) { -// qDebug() << Q_FUNC_INFO << "replacing" << query->id() << state; + qDebug() << Q_FUNC_INFO << "replacing" << query->id() << state; m_qidsState.insert( query->id(), state ); } else { -// qDebug() << Q_FUNC_INFO << "removing" << query->id() << state; + qDebug() << Q_FUNC_INFO << "removing" << query->id() << state; m_qidsState.remove( query->id() ); } diff --git a/thirdparty/jreen b/thirdparty/jreen index 58fb2d4bc..40fd6b0a3 160000 --- a/thirdparty/jreen +++ b/thirdparty/jreen @@ -1 +1 @@ -Subproject commit 58fb2d4bc2abebdf778ca230a84042c7f5694583 +Subproject commit 40fd6b0a3dbc729fdf1db8490848b43d5b1f57f5 From 48d029468dd1eb626787744aee677f7c87e52d02 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 8 May 2011 20:00:18 +0200 Subject: [PATCH 07/18] sipjreen: googlewrapper: hardcode server and port so it works through proxies and with all google apps jids when the domain has no jdns entry --- src/sip/jreen/googlewrapper/googlewrapper.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sip/jreen/googlewrapper/googlewrapper.cpp b/src/sip/jreen/googlewrapper/googlewrapper.cpp index 1ddab26d6..1a1865fb6 100644 --- a/src/sip/jreen/googlewrapper/googlewrapper.cpp +++ b/src/sip/jreen/googlewrapper/googlewrapper.cpp @@ -41,6 +41,8 @@ GoogleWrapper::GoogleWrapper ( const QString& pluginID ) m_ui->emailLabel->setText( tr( "Google Address" ) ); m_ui->jabberBlurb->setText( tr( "Enter your Google login to connect with your friends using Tomahawk!" ) ); m_ui->logoLabel->setPixmap( QPixmap( ":/gmail-logo.png" ) ); + m_ui->jabberServer->setText( "talk.google.com" ); + m_ui->jabberPort->setValue( 5222 ); m_ui->groupBoxJabberAdvanced->hide(); } From f2eb8a7a7513f3c599f173fc85e94fd862778252 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 9 May 2011 00:31:25 +0200 Subject: [PATCH 08/18] * Improved Pipeline. --- src/libtomahawk/pipeline.cpp | 81 ++++++++++++++++++++++++------------ src/libtomahawk/pipeline.h | 5 ++- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index cbd0d47ed..d4a8675bb 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -25,7 +25,7 @@ #include "functimeout.h" #include "database/database.h" -#define CONCURRENT_QUERIES 8 +#define CONCURRENT_QUERIES 4 using namespace Tomahawk; @@ -160,30 +160,31 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) Q_ASSERT( false ); return; } - - if ( !m_qidsState.contains( qid ) ) - { - qDebug() << "reportResults called for unknown QID-state" << qid; - Q_ASSERT( false ); - return; - } } const query_ptr& q = m_qids.value( qid ); if ( !results.isEmpty() ) { //qDebug() << Q_FUNC_INFO << qid; - //qDebug() << "solved query:" << (qlonglong)q.data() << q->toString(); q->addResults( results ); - foreach( const result_ptr& r, q->results() ) { m_rids.insert( r->id(), r ); } if ( q->solved() ) + { + qDebug() << "FINISHED RESOLVING EARLY" << q->toString(); q->onResolvingFinished(); + + setQIDState( q, 0 ); + if ( m_qidsTimeout.contains( q->id() ) ) + m_qidsTimeout.remove( q->id() ); + + shuntNext(); + return; + } } if ( decQIDState( q ) == 0 ) @@ -193,6 +194,10 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) shuntNext(); } + else + { + new FuncTimeout( 500, boost::bind( &Pipeline::timeoutShunt, this, q ), this ); + } } @@ -226,11 +231,22 @@ Pipeline::shuntNext() q->setLastPipelineWeight( 101 ); } - if ( !q.isNull() ) + setQIDState( q, m_resolvers.count() ); + new FuncTimeout( 500, boost::bind( &Pipeline::shunt, this, q ), this ); +} + + +void +Pipeline::timeoutShunt( const query_ptr& q ) +{ + // are we still waiting for a timeout? + if ( m_qidsTimeout.contains( q->id() ) ) { - incQIDState( q ); - shunt( q ); // bump into next stage of pipeline (highest weights are 100) + m_qidsTimeout.remove( q->id() ); + shunt( q ); } + else + qDebug() << Q_FUNC_INFO << q->toString() << "Ignoring timeout"; } @@ -241,7 +257,6 @@ Pipeline::shunt( const query_ptr& q ) unsigned int lastweight = 0; unsigned int lasttimeout = 0; int thisResolver = 0; - bool dispatched = false; if ( !q->resolvingFinished() ) { @@ -264,13 +279,7 @@ Pipeline::shunt( const query_ptr& q ) if ( r->timeout() < lasttimeout ) lasttimeout = r->timeout(); - // resolvers aren't allowed to block in this call: - if ( dispatched ) - incQIDState( q ); - - dispatched = true; qDebug() << "Dispatching to resolver" << r->name() << q->toString(); - thisResolver = i; r->resolve( q ); } @@ -286,18 +295,17 @@ Pipeline::shunt( const query_ptr& q ) if ( thisResolver < m_resolvers.count() ) { qDebug() << "Shunting in" << lasttimeout << "ms, q:" << q->toString(); - incQIDState( q ); - new FuncTimeout( lasttimeout, boost::bind( &Pipeline::shunt, this, q ), this ); + + m_qidsTimeout.insert( q->id(), true ); + new FuncTimeout( lasttimeout, boost::bind( &Pipeline::timeoutShunt, this, q ), this ); } } else { // reached end of pipeline qDebug() << "Reached end of pipeline for:" << q->toString(); - - decQIDState( q ); - if ( !q->solved() ) - q->onResolvingFinished(); + setQIDState( q, 0 ); + return; } shuntNext(); @@ -314,6 +322,24 @@ Pipeline::resolverSorter( const Resolver* left, const Resolver* right ) } +void +Pipeline::setQIDState( const Tomahawk::query_ptr& query, int state ) +{ + QMutexLocker lock( &m_mut ); + + if ( state ) + { + qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state; + m_qidsState.insert( query->id(), state ); + } + else + { + qDebug() << Q_FUNC_INFO << "removing" << query->id() << state; + m_qidsState.remove( query->id() ); + } +} + + int Pipeline::incQIDState( const Tomahawk::query_ptr& query ) { @@ -337,6 +363,9 @@ Pipeline::decQIDState( const Tomahawk::query_ptr& query ) { QMutexLocker lock( &m_mut ); + if ( !m_qidsState.contains( query->id() ) ) + return 0; + int state = m_qidsState.value( query->id() ) - 1; if ( state ) { diff --git a/src/libtomahawk/pipeline.h b/src/libtomahawk/pipeline.h index 2c31bc28b..7f845f2e9 100644 --- a/src/libtomahawk/pipeline.h +++ b/src/libtomahawk/pipeline.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -73,17 +73,20 @@ signals: void idle(); private slots: + void timeoutShunt( const query_ptr& q ); void shunt( const query_ptr& q ); void shuntNext(); void indexReady(); private: + void setQIDState( const Tomahawk::query_ptr& query, int state ); int incQIDState( const Tomahawk::query_ptr& query ); int decQIDState( const Tomahawk::query_ptr& query ); QList< Resolver* > m_resolvers; + QMap< QID, bool > m_qidsTimeout; QMap< QID, unsigned int > m_qidsState; QMap< QID, query_ptr > m_qids; QMap< RID, result_ptr > m_rids; From 7b4c425ec5eac7a56d58c32677f5799bd1a5ffe7 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 9 May 2011 01:10:31 +0200 Subject: [PATCH 09/18] * Print out some more debug in case we run into problems. --- src/libtomahawk/pipeline.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index d4a8675bb..53abe0a05 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -182,6 +182,8 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) if ( m_qidsTimeout.contains( q->id() ) ) m_qidsTimeout.remove( q->id() ); + qDebug() << "Queries running:" << m_qidsState.count(); + shuntNext(); return; } @@ -192,6 +194,10 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) if ( !q->solved() ) q->onResolvingFinished(); + if ( m_qidsTimeout.contains( q->id() ) ) + m_qidsTimeout.remove( q->id() ); + + qDebug() << "Queries running:" << m_qidsState.count(); shuntNext(); } else @@ -305,6 +311,7 @@ Pipeline::shunt( const query_ptr& q ) // reached end of pipeline qDebug() << "Reached end of pipeline for:" << q->toString(); setQIDState( q, 0 ); + qDebug() << "Queries running:" << m_qidsState.count(); return; } @@ -327,7 +334,7 @@ Pipeline::setQIDState( const Tomahawk::query_ptr& query, int state ) { QMutexLocker lock( &m_mut ); - if ( state ) + if ( state > 0 ) { qDebug() << Q_FUNC_INFO << "inserting to qidsstate:" << query->id() << state; m_qidsState.insert( query->id(), state ); From 7ba8581ac36c85b895c63f8a01ae3d841d266469 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 9 May 2011 01:22:49 +0200 Subject: [PATCH 10/18] * Fix potential issue which caused Pipeline to get stuck. --- src/libtomahawk/pipeline.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index 53abe0a05..97606389f 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -312,7 +312,6 @@ Pipeline::shunt( const query_ptr& q ) qDebug() << "Reached end of pipeline for:" << q->toString(); setQIDState( q, 0 ); qDebug() << "Queries running:" << m_qidsState.count(); - return; } shuntNext(); From 733e06b37204bfed2ab27aaa31c72f0b815c342f Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 00:44:39 +0200 Subject: [PATCH 11/18] Add SipInfo class --- src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/sip/sipinfo.cpp | 223 ++++++++++++++++++++++++++++++++ src/libtomahawk/sip/sipinfo.h | 70 ++++++++++ 3 files changed, 295 insertions(+) create mode 100644 src/libtomahawk/sip/sipinfo.cpp create mode 100644 src/libtomahawk/sip/sipinfo.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index aab9a3e60..8079e17e3 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -34,6 +34,7 @@ set( libSources sip/SipPlugin.cpp sip/SipHandler.cpp sip/SipModel.cpp + sip/sipinfo.cpp audio/audioengine.cpp @@ -195,6 +196,7 @@ set( libHeaders sip/SipPlugin.h sip/SipHandler.h sip/SipModel.h + sip/sipinfo.h audio/audioengine.h diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp new file mode 100644 index 000000000..10a410b14 --- /dev/null +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -0,0 +1,223 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "sipinfo.h" + +#include +#include + +#include + +class SipInfoPrivate : public QSharedData { +public: + SipInfoPrivate() + : port( -1 ) + { + } + + SipInfoPrivate( const SipInfoPrivate& other ) : QSharedData( other ), + visible(other.visible), + host(other.host), + port(other.port), + uniqname(other.uniqname), + key(other.key) + { + } + ~SipInfoPrivate() { } + + QVariant visible; + QHostAddress host; + int port; + QString uniqname; + QString key; +}; + +SipInfo::SipInfo() +{ + d = new SipInfoPrivate; +} + +SipInfo::SipInfo(const SipInfo& other): d ( other.d ) +{ + +} + +SipInfo::~SipInfo() +{ + +} + +SipInfo& +SipInfo::operator=( const SipInfo& other ) +{ + d = other.d; + return *this; +} + +void +SipInfo::clear() +{ + d->visible.clear(); + d->host = QHostAddress(); + d->port = -1; + d->uniqname = QString(); + d->key = QString(); +} + +bool +SipInfo::isValid() const +{ + if( !d->visible.isNull() ) + if( + // visible and all data available + ( d->visible.toBool() && !d->host.isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) + // invisible and no data available + || ( !d->visible.toBool() && d->host.isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) + ) + return true; + else + return false; + +} + +void +SipInfo::setVisible(bool visible) +{ + d->visible.setValue(visible); +} + +bool +SipInfo::isVisible() const +{ + Q_ASSERT( isValid() ); + + d->visible.toBool(); +} + +void +SipInfo::setHost( const QHostAddress& host ) +{ + d->host = host; +} + +const QHostAddress +SipInfo::host() const +{ + Q_ASSERT( isValid() ); + + return d->host; +} + +void +SipInfo::setPort( int port ) +{ + d->port = port; +} + +int +SipInfo::port() const +{ + Q_ASSERT( isValid() ); + + return d->port; +} + +void +SipInfo::setUniqname( const QString& uniqname ) +{ + d->uniqname = uniqname; +} + +const QString +SipInfo::uniqname() const +{ + Q_ASSERT( isValid() ); + + return d->uniqname; +} + +void +SipInfo::setKey( const QString& key ) +{ + d->key = key; +} + +const QString +SipInfo::key() const +{ + Q_ASSERT( isValid() ); + + return d->key; +} + +const QString +SipInfo::toJson() const +{ + Q_ASSERT( isValid() ); + + // build variant map + QVariantMap m; + m["visible"] = isVisible(); + if( isVisible() ) + { + m["ip"] = host().toString(); + m["port"] = port(); + m["key"] = key(); + m["uniqname"] = uniqname(); + } + + // serialize + QJson::Serializer serializer; + QByteArray ba = serializer.serialize( m ); + + return QString::fromAscii( ba ); +} + +const SipInfo +SipInfo::fromJson( QString json ) +{ + SipInfo info; + + QJson::Parser parser; + bool ok; + QVariant v = parser.parse( json.toAscii(), &ok ); + if ( !ok || v.type() != QVariant::Map ) + { + qDebug() << Q_FUNC_INFO << "Invalid JSON"; + return info; + } + QVariantMap m = v.toMap(); + + info.setVisible( m["visible"].toBool() ); + if( m["visible"].toBool() ) + { + info.setHost( QHostAddress( m["host"].toString() ) ); + info.setPort( m["port"].toInt() ); + info.setUniqname( m["uniqname"].toString() ); + info.setKey( m["key"].toString() ); + } + + return info; +} + + +QDebug operator<< ( QDebug dbg, const SipInfo& info ) +{ + dbg.nospace() << info.toJson(); + return dbg.maybeSpace(); +} diff --git a/src/libtomahawk/sip/sipinfo.h b/src/libtomahawk/sip/sipinfo.h new file mode 100644 index 000000000..e251fc627 --- /dev/null +++ b/src/libtomahawk/sip/sipinfo.h @@ -0,0 +1,70 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2011, Dominik Schmidt + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SIPINFO_H +#define SIPINFO_H + +#include +#include +#include + +class SipInfoPrivate; + +class SipInfo : public QObject +{ +Q_OBJECT + +public: + // create invalid message + // becomes valid if either visible == false or visible == true and all attributes are set + SipInfo(); + SipInfo(const SipInfo &other); + virtual ~SipInfo(); + SipInfo& operator=(const SipInfo &info); + + void clear(); + bool isValid() const; + + void setVisible( bool visible ); + bool isVisible() const; + + void setHost( const QHostAddress &host ); + const QHostAddress host() const; + + void setPort( int port ); + int port() const; + + void setUniqname( const QString &uniqname ); + const QString uniqname() const; + + void setKey( const QString &key ); + const QString key() const; + + + const QString toJson() const; + static const SipInfo fromJson( QString json ); + +private: + QSharedDataPointer d; +}; + +QDebug operator<<( QDebug dbg, const SipInfo &info ); + + + +#endif // SIPINFO_H \ No newline at end of file From 9cd07349dc4d71c3b2db8f27cbd472f8d85df5cf Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 01:01:01 +0200 Subject: [PATCH 12/18] Don't assert on qDebug( SipInfo() ) --- src/libtomahawk/sip/sipinfo.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp index 10a410b14..445122ed5 100644 --- a/src/libtomahawk/sip/sipinfo.cpp +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -218,6 +218,10 @@ SipInfo::fromJson( QString json ) QDebug operator<< ( QDebug dbg, const SipInfo& info ) { - dbg.nospace() << info.toJson(); + if( !isValid() ) + dbg.nospace() << "info is invalid"; + else + dbg.nospace() << info.toJson(); + return dbg.maybeSpace(); } From 9c306007934ea420be6d7e3bb33e5ff0301ac22e Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 02:03:57 +0200 Subject: [PATCH 13/18] Use SipInfo in SipHandler & SipPlugin and fix Jabber to use the new API --- src/diagnosticsdialog.cpp | 8 ++--- src/libtomahawk/sip/SipHandler.cpp | 43 ++++++++++++-------------- src/libtomahawk/sip/SipHandler.h | 5 ++-- src/libtomahawk/sip/SipPlugin.h | 3 ++ src/libtomahawk/sip/sipinfo.cpp | 2 +- src/sip/jreen/jabber.cpp | 48 +++++++++++------------------- 6 files changed, 48 insertions(+), 61 deletions(-) diff --git a/src/diagnosticsdialog.cpp b/src/diagnosticsdialog.cpp index 865cce92f..3a4a6db71 100644 --- a/src/diagnosticsdialog.cpp +++ b/src/diagnosticsdialog.cpp @@ -122,13 +122,13 @@ void DiagnosticsDialog::updateLogView() } } - QVariantMap sipInfo = SipHandler::instance()->sipInfo( peerId ); - if( sipInfo.value( "visible").toBool() ) + SipInfo sipInfo = SipHandler::instance()->sipInfo( peerId ); + if( sipInfo.isVisible() ) log.append( QString(" %1: %2:%3 (%4)\n") .arg( peerId ) - .arg( sipInfo.value( "ip" ).toString() ) - .arg( sipInfo.value( "port" ).toString() ) + .arg( sipInfo.host().toString() ) + .arg( sipInfo.port() ) .arg( connected ? "connected" : "not connected") ); else diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index 46b6d18b4..d22e21bc7 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -80,7 +80,7 @@ const QPixmap SipHandler::avatar( const QString& name ) const } } -const QVariantMap +const SipInfo SipHandler::sipInfo(const QString& peerId) const { return m_peersSipInfos.value( peerId ); @@ -193,6 +193,7 @@ SipHandler::hookUpPlugin( SipPlugin* sip ) QObject::connect( sip, SIGNAL( peerOnline( QString ) ), SLOT( onPeerOnline( QString ) ) ); QObject::connect( sip, SIGNAL( peerOffline( QString ) ), SLOT( onPeerOffline( QString ) ) ); QObject::connect( sip, SIGNAL( msgReceived( QString, QString ) ), SLOT( onMessage( QString, QString ) ) ); + QObject::connect( sip, SIGNAL( sipInfoReceived( QString, SipInfo ) ), SLOT( onSipInfo( QString, SipInfo ) ) ); QObject::connect( sip, SIGNAL( error( int, QString ) ), SLOT( onError( int, QString ) ) ); QObject::connect( sip, SIGNAL( stateChanged( SipPlugin::ConnectionState ) ), SLOT( onStateChanged( SipPlugin::ConnectionState ) ) ); @@ -483,39 +484,27 @@ SipHandler::onPeerOffline( const QString& jid ) qDebug() << "SIP offline:" << jid; } - void -SipHandler::onMessage( const QString& from, const QString& msg ) +SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) { - qDebug() << Q_FUNC_INFO; - qDebug() << "SIP Message:" << from << msg; + qDebug() << Q_FUNC_INFO << "SIP Message:" << peerId << info; - QJson::Parser parser; - bool ok; - QVariant v = parser.parse( msg.toAscii(), &ok ); - if ( !ok || v.type() != QVariant::Map ) - { - qDebug() << "Invalid JSON in XMPP msg"; - return; - } - - QVariantMap m = v.toMap(); /* If only one party is externally visible, connection is obvious If both are, peer with lowest IP address initiates the connection. This avoids dupe connections. */ - if ( m.value( "visible" ).toBool() ) + if ( info.isVisible() ) { if( !Servent::instance()->visibleExternally() || - Servent::instance()->externalAddress() <= m.value( "ip" ).toString() ) + Servent::instance()->externalAddress() <= info.host().toString() ) { - qDebug() << "Initiate connection to" << from; - Servent::instance()->connectToPeer( m.value( "ip" ).toString(), - m.value( "port" ).toInt(), - m.value( "key" ).toString(), - from, - m.value( "uniqname" ).toString() ); + qDebug() << "Initiate connection to" << peerId; + Servent::instance()->connectToPeer( info.host().toString(), + info.port(), + info.key(), + peerId, + info.uniqname() ); } else { @@ -527,7 +516,13 @@ SipHandler::onMessage( const QString& from, const QString& msg ) qDebug() << Q_FUNC_INFO << "They are not visible, doing nothing atm"; } - m_peersSipInfos.insert( from, m ); + m_peersSipInfos.insert( peerId, info ); +} + +void +SipHandler::onMessage( const QString& from, const QString& msg ) +{ + qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/sip/SipHandler.h b/src/libtomahawk/sip/SipHandler.h index 93b689cb7..2076a859a 100644 --- a/src/libtomahawk/sip/SipHandler.h +++ b/src/libtomahawk/sip/SipHandler.h @@ -52,7 +52,7 @@ public: const QPixmap avatar( const QString& name ) const; //TODO: implement a proper SipInfo class and maybe attach it to the source - const QVariantMap sipInfo( const QString& peerId ) const; + const SipInfo sipInfo( const QString& peerId ) const; public slots: void checkSettings(); @@ -87,6 +87,7 @@ signals: void pluginRemoved( SipPlugin* p ); private slots: + void onSipInfo( const QString& peerId, const SipInfo& info ); void onMessage( const QString&, const QString& ); void onPeerOffline( const QString& ); void onPeerOnline( const QString& ); @@ -121,7 +122,7 @@ private: QNetworkProxy m_proxy; //TODO: move this to source - QHash m_peersSipInfos; + QHash m_peersSipInfos; QHash m_usernameAvatars; }; diff --git a/src/libtomahawk/sip/SipPlugin.h b/src/libtomahawk/sip/SipPlugin.h index f6b7b334a..3ac9fd2cc 100644 --- a/src/libtomahawk/sip/SipPlugin.h +++ b/src/libtomahawk/sip/SipPlugin.h @@ -20,6 +20,8 @@ #ifndef SIPPLUGIN_H #define SIPPLUGIN_H +#include "sipinfo.h" + #include #include #include @@ -96,6 +98,7 @@ signals: void peerOnline( const QString& ); void peerOffline( const QString& ); void msgReceived( const QString& from, const QString& msg ); + void sipInfoReceived( const QString& peerId, const SipInfo& info ); // new data for own source void avatarReceived ( const QPixmap& avatar ); diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp index 445122ed5..ca192e22a 100644 --- a/src/libtomahawk/sip/sipinfo.cpp +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -218,7 +218,7 @@ SipInfo::fromJson( QString json ) QDebug operator<< ( QDebug dbg, const SipInfo& info ) { - if( !isValid() ) + if( !info.isValid() ) dbg.nospace() << "info is invalid"; else dbg.nospace() << info.toJson(); diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index d030238bf..314e84c3a 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -556,13 +556,9 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message) QString from = message.from().full(); QString msg = message.body(); - if ( msg.isEmpty() ) - return; + SipInfo info = SipInfo::fromJson( msg ); - QJson::Parser parser; - bool ok; - QVariant v = parser.parse( msg.toAscii(), &ok ); - if ( !ok || v.type() != QVariant::Map ) + if ( !info.isValid() ) { QString to = from; QString response = QString( tr("I'm sorry -- I'm just an automatic presence used by Tomahawk Player" @@ -572,11 +568,12 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message) // this is not a sip message, so we send it directly through the client m_client->send( Jreen::Message ( Jreen::Message::Chat, Jreen::JID(to), response) ); + emit msgReceived( from, msg ); return; } qDebug() << Q_FUNC_INFO << "From:" << message.from().full() << ":" << message.body(); - emit msgReceived( from, msg ); + emit sipInfoReceived( from, info ); } @@ -770,35 +767,26 @@ void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context) iq.accept(); qDebug() << Q_FUNC_INFO << "Got SipMessage ..."; - qDebug() << "ip" << sipMessage->ip(); - qDebug() << "port" << sipMessage->port(); - qDebug() << "uniqname" << sipMessage->uniqname(); - qDebug() << "key" << sipMessage->key(); - qDebug() << "visible" << sipMessage->visible(); + qDebug() << Q_FUNC_INFO << "ip" << sipMessage->ip(); + qDebug() << Q_FUNC_INFO << "port" << sipMessage->port(); + qDebug() << Q_FUNC_INFO << "uniqname" << sipMessage->uniqname(); + qDebug() << Q_FUNC_INFO << "key" << sipMessage->key(); + qDebug() << Q_FUNC_INFO << "visible" << sipMessage->visible(); - - QVariantMap m; + SipInfo info; + info.setVisible( sipMessage->visible() ); if( sipMessage->visible() ) { - m["visible"] = true; - m["ip"] = sipMessage->ip(); - m["port"] = sipMessage->port(); - m["key"] = sipMessage->key(); - m["uniqname"] = sipMessage->uniqname(); - } - else - { - m["visible"] = false; + info.setHost( QHostAddress( sipMessage->ip() ) ); + info.setPort( sipMessage->port() ); + info.setUniqname( sipMessage->uniqname() ); + info.setKey( sipMessage->key() ); } + Q_ASSERT( info.isValid() ); - QJson::Serializer ser; - QByteArray ba = ser.serialize( m ); - QString msg = QString::fromAscii( ba ); - - QString from = iq.from().full(); - qDebug() << Q_FUNC_INFO << "From:" << from << ":" << msg; - emit msgReceived( from, msg ); + qDebug() << Q_FUNC_INFO << "From:" << iq.from().full() << ":" << info; + emit sipInfoReceived( iq.from().full(), info ); } } } From 2e69f91671ae58a7c964ea7235d308e47b94db35 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 02:59:46 +0200 Subject: [PATCH 14/18] Use QHostInfo instead of QHostAddress --- src/diagnosticsdialog.cpp | 2 +- src/libtomahawk/sip/SipHandler.cpp | 4 ++-- src/libtomahawk/sip/sipinfo.cpp | 23 ++++++++++++----------- src/libtomahawk/sip/sipinfo.h | 16 +++++++--------- src/sip/jreen/jabber.cpp | 8 +++++++- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/diagnosticsdialog.cpp b/src/diagnosticsdialog.cpp index 3a4a6db71..085df8f22 100644 --- a/src/diagnosticsdialog.cpp +++ b/src/diagnosticsdialog.cpp @@ -127,7 +127,7 @@ void DiagnosticsDialog::updateLogView() log.append( QString(" %1: %2:%3 (%4)\n") .arg( peerId ) - .arg( sipInfo.host().toString() ) + .arg( sipInfo.host().hostName() ) .arg( sipInfo.port() ) .arg( connected ? "connected" : "not connected") ); diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index d22e21bc7..e8baf12d3 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -497,10 +497,10 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) if ( info.isVisible() ) { if( !Servent::instance()->visibleExternally() || - Servent::instance()->externalAddress() <= info.host().toString() ) + Servent::instance()->externalAddress() <= info.host().hostName() ) { qDebug() << "Initiate connection to" << peerId; - Servent::instance()->connectToPeer( info.host().toString(), + Servent::instance()->connectToPeer( info.host().hostName(), info.port(), info.key(), peerId, diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp index ca192e22a..3e1273845 100644 --- a/src/libtomahawk/sip/sipinfo.cpp +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -41,7 +41,7 @@ public: ~SipInfoPrivate() { } QVariant visible; - QHostAddress host; + QHostInfo host; int port; QString uniqname; QString key; @@ -73,7 +73,7 @@ void SipInfo::clear() { d->visible.clear(); - d->host = QHostAddress(); + d->host = QHostInfo(); d->port = -1; d->uniqname = QString(); d->key = QString(); @@ -82,12 +82,13 @@ SipInfo::clear() bool SipInfo::isValid() const { + qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->uniqname << d->key; if( !d->visible.isNull() ) if( // visible and all data available - ( d->visible.toBool() && !d->host.isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) + ( d->visible.toBool() && !d->host.hostName().isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) // invisible and no data available - || ( !d->visible.toBool() && d->host.isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) + || ( !d->visible.toBool() && d->host.hostName().isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) ) return true; else @@ -110,12 +111,12 @@ SipInfo::isVisible() const } void -SipInfo::setHost( const QHostAddress& host ) +SipInfo::setHost( const QHostInfo& host ) { d->host = host; } -const QHostAddress +const QHostInfo SipInfo::host() const { Q_ASSERT( isValid() ); @@ -168,14 +169,12 @@ SipInfo::key() const const QString SipInfo::toJson() const { - Q_ASSERT( isValid() ); - // build variant map QVariantMap m; m["visible"] = isVisible(); if( isVisible() ) { - m["ip"] = host().toString(); + m["ip"] = host().hostName(); m["port"] = port(); m["key"] = key(); m["uniqname"] = uniqname(); @@ -198,7 +197,7 @@ SipInfo::fromJson( QString json ) QVariant v = parser.parse( json.toAscii(), &ok ); if ( !ok || v.type() != QVariant::Map ) { - qDebug() << Q_FUNC_INFO << "Invalid JSON"; + qDebug() << Q_FUNC_INFO << "Invalid JSON: " << json; return info; } QVariantMap m = v.toMap(); @@ -206,7 +205,9 @@ SipInfo::fromJson( QString json ) info.setVisible( m["visible"].toBool() ); if( m["visible"].toBool() ) { - info.setHost( QHostAddress( m["host"].toString() ) ); + QHostInfo hostInfo; + hostInfo.setHostName( m["host"].toString() ); + info.setHost( hostInfo ); info.setPort( m["port"].toInt() ); info.setUniqname( m["uniqname"].toString() ); info.setKey( m["key"].toString() ); diff --git a/src/libtomahawk/sip/sipinfo.h b/src/libtomahawk/sip/sipinfo.h index e251fc627..0a9b48cf5 100644 --- a/src/libtomahawk/sip/sipinfo.h +++ b/src/libtomahawk/sip/sipinfo.h @@ -21,7 +21,7 @@ #include #include -#include +#include class SipInfoPrivate; @@ -30,12 +30,10 @@ class SipInfo : public QObject Q_OBJECT public: - // create invalid message - // becomes valid if either visible == false or visible == true and all attributes are set SipInfo(); - SipInfo(const SipInfo &other); + SipInfo(const SipInfo& other); virtual ~SipInfo(); - SipInfo& operator=(const SipInfo &info); + SipInfo& operator=(const SipInfo& info); void clear(); bool isValid() const; @@ -43,16 +41,16 @@ public: void setVisible( bool visible ); bool isVisible() const; - void setHost( const QHostAddress &host ); - const QHostAddress host() const; + void setHost( const QHostInfo& host ); + const QHostInfo host() const; void setPort( int port ); int port() const; - void setUniqname( const QString &uniqname ); + void setUniqname( const QString& uniqname ); const QString uniqname() const; - void setKey( const QString &key ); + void setKey( const QString& key ); const QString key() const; diff --git a/src/sip/jreen/jabber.cpp b/src/sip/jreen/jabber.cpp index 314e84c3a..e99f32a63 100644 --- a/src/sip/jreen/jabber.cpp +++ b/src/sip/jreen/jabber.cpp @@ -556,6 +556,9 @@ void JabberPlugin::onNewMessage(const Jreen::Message& message) QString from = message.from().full(); QString msg = message.body(); + if(msg.isEmpty()) + return; + SipInfo info = SipInfo::fromJson( msg ); if ( !info.isValid() ) @@ -777,7 +780,10 @@ void JabberPlugin::onNewIq(const Jreen::IQ& iq, int context) info.setVisible( sipMessage->visible() ); if( sipMessage->visible() ) { - info.setHost( QHostAddress( sipMessage->ip() ) ); + + QHostInfo hi; + hi.setHostName( sipMessage->ip() ); + info.setHost( hi ); info.setPort( sipMessage->port() ); info.setUniqname( sipMessage->uniqname() ); info.setKey( sipMessage->key() ); From 06f33c5d81062c8b12fdde27b5802ac993388bd7 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 11:27:08 +0200 Subject: [PATCH 15/18] Add missing return, compiled here fine :\ --- src/libtomahawk/sip/sipinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp index 3e1273845..b63b8cae0 100644 --- a/src/libtomahawk/sip/sipinfo.cpp +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -107,7 +107,7 @@ SipInfo::isVisible() const { Q_ASSERT( isValid() ); - d->visible.toBool(); + return d->visible.toBool(); } void From eade3c5f26239991908a3dc5b60ef33c2740f2f9 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 11:33:03 +0200 Subject: [PATCH 16/18] Fix broken if-else --- src/libtomahawk/sip/sipinfo.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/sip/sipinfo.cpp b/src/libtomahawk/sip/sipinfo.cpp index b63b8cae0..5764376f7 100644 --- a/src/libtomahawk/sip/sipinfo.cpp +++ b/src/libtomahawk/sip/sipinfo.cpp @@ -84,6 +84,7 @@ SipInfo::isValid() const { qDebug() << Q_FUNC_INFO << d->visible << d->host.hostName() << d->port << d->uniqname << d->key; if( !d->visible.isNull() ) + { if( // visible and all data available ( d->visible.toBool() && !d->host.hostName().isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) @@ -91,9 +92,9 @@ SipInfo::isValid() const || ( !d->visible.toBool() && d->host.hostName().isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) ) return true; - else - return false; + } + return false; } void From f171c8901b749884686a21bf738faa3c9bfe5816 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 11:40:46 +0200 Subject: [PATCH 17/18] Export SipInfo class --- src/libtomahawk/sip/sipinfo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/sip/sipinfo.h b/src/libtomahawk/sip/sipinfo.h index 0a9b48cf5..31b5c5e6e 100644 --- a/src/libtomahawk/sip/sipinfo.h +++ b/src/libtomahawk/sip/sipinfo.h @@ -25,7 +25,9 @@ class SipInfoPrivate; -class SipInfo : public QObject +#include "../dllmacro.h" + +class DLLEXPORT SipInfo : public QObject { Q_OBJECT From 1d6153044c65e059a7918359ea76e6e48b9b649d Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 9 May 2011 14:45:38 +0200 Subject: [PATCH 18/18] Export QDebug operator<<( QDebug dbg, const SipInfo &info ) --- src/libtomahawk/sip/sipinfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/sip/sipinfo.h b/src/libtomahawk/sip/sipinfo.h index 31b5c5e6e..7ebb4e2d1 100644 --- a/src/libtomahawk/sip/sipinfo.h +++ b/src/libtomahawk/sip/sipinfo.h @@ -63,7 +63,7 @@ private: QSharedDataPointer d; }; -QDebug operator<<( QDebug dbg, const SipInfo &info ); +DLLEXPORT QDebug operator<<( QDebug dbg, const SipInfo &info );