From 0406b38f1c98a0b2b3b6857fb1294d4009e8cef1 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Tue, 10 Jul 2012 19:23:12 -0400 Subject: [PATCH] * Merged 4-is-not-JSON bug to stable. --- src/DiagnosticsDialog.cpp | 2 +- src/accounts/xmpp/sip/XmppSip.cpp | 6 ++---- src/libtomahawk/sip/SipHandler.cpp | 17 +++++++++-------- src/libtomahawk/sip/SipInfo.cpp | 18 ++++++++---------- src/libtomahawk/sip/SipInfo.h | 4 ++-- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/DiagnosticsDialog.cpp b/src/DiagnosticsDialog.cpp index 17a084632..1ed6e2255 100644 --- a/src/DiagnosticsDialog.cpp +++ b/src/DiagnosticsDialog.cpp @@ -241,7 +241,7 @@ DiagnosticsDialog::updateAccountLabel( Tomahawk::Accounts::Account* account ) accountInfo.append( QString(" %1: %2:%3 %4" /*" (%5)"*/ "\n") .arg( peerId ) - .arg( sipInfo.host().hostName() ) + .arg( sipInfo.host() ) .arg( sipInfo.port() ) .arg( versionString ) // .arg( connected ? "connected" : "not connected") diff --git a/src/accounts/xmpp/sip/XmppSip.cpp b/src/accounts/xmpp/sip/XmppSip.cpp index dfad484d3..f0678838c 100644 --- a/src/accounts/xmpp/sip/XmppSip.cpp +++ b/src/accounts/xmpp/sip/XmppSip.cpp @@ -450,7 +450,7 @@ XmppSipPlugin::sendMsg( const QString& to, const QString& msg ) TomahawkXmppMessage *sipMessage; if ( m["visible"].toBool() ) { - sipMessage = new TomahawkXmppMessage( m["ip"].toString(), m["port"].toInt(), m["uniqname"].toString(), m["key"].toString() ); + sipMessage = new TomahawkXmppMessage( info.host(), info.port(), info.uniqname(), info.key() ); } else sipMessage = new TomahawkXmppMessage(); @@ -914,9 +914,7 @@ XmppSipPlugin::onNewIq( const Jreen::IQ& iq ) info.setVisible( sipMessage->visible() ); if ( sipMessage->visible() ) { - QHostInfo hi; - hi.setHostName( sipMessage->ip() ); - info.setHost( hi ); + info.setHost( sipMessage->ip() ); info.setPort( sipMessage->port() ); info.setUniqname( sipMessage->uniqname() ); info.setKey( sipMessage->key() ); diff --git a/src/libtomahawk/sip/SipHandler.cpp b/src/libtomahawk/sip/SipHandler.cpp index 22dc967df..bc354fa00 100644 --- a/src/libtomahawk/sip/SipHandler.cpp +++ b/src/libtomahawk/sip/SipHandler.cpp @@ -136,11 +136,11 @@ SipHandler::onPeerOnline( const QString& jid ) conn->setId( nodeid ); Servent::instance()->registerOffer( key, conn ); - m["visible"] = true; - m["ip"] = Servent::instance()->externalAddress(); - m["port"] = Servent::instance()->externalPort(); - m["key"] = key; - m["uniqname"] = nodeid; + info.setVisible( true ); + info.setHost( Servent::instance()->externalAddress() ); + info.setPort( Servent::instance()->externalPort() ); + info.setKey( key ); + info.setUniqname( nodeid ); qDebug() << "Asking them to connect to us:" << m; } @@ -183,10 +183,11 @@ SipHandler::onSipInfo( const QString& peerId, const SipInfo& info ) if ( info.isVisible() ) { if( !Servent::instance()->visibleExternally() || - Servent::instance()->externalAddress() <= info.host().hostName() ) + Servent::instance()->externalAddress() < info.host() || + ( Servent::instance()->externalAddress() == info.host() && Servent::instance()->externalPort() < info.port() ) ) { - qDebug() << "Initiate connection to" << peerId; - Servent::instance()->connectToPeer( info.host().hostName(), + tDebug() << "Initiate connection to" << peerId << "at" << info.host(); + Servent::instance()->connectToPeer( info.host(), info.port(), info.key(), peerId, diff --git a/src/libtomahawk/sip/SipInfo.cpp b/src/libtomahawk/sip/SipInfo.cpp index b877fdc3e..b0a39001a 100644 --- a/src/libtomahawk/sip/SipInfo.cpp +++ b/src/libtomahawk/sip/SipInfo.cpp @@ -44,7 +44,7 @@ public: ~SipInfoPrivate() { } QVariant visible; - QHostInfo host; + QString host; int port; QString uniqname; QString key; @@ -81,7 +81,7 @@ void SipInfo::clear() { d->visible.clear(); - d->host = QHostInfo(); + d->host = QString(); d->port = -1; d->uniqname = QString(); d->key = QString(); @@ -96,9 +96,9 @@ SipInfo::isValid() const { if( // visible and all data available - ( d->visible.toBool() && !d->host.hostName().isNull() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) + ( d->visible.toBool() && !d->host.isEmpty() && ( d->port > 0 ) && !d->uniqname.isNull() && !d->key.isNull() ) // invisible and no data available - || ( !d->visible.toBool() && d->host.hostName().isNull() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) + || ( !d->visible.toBool() && d->host.isEmpty() && ( d->port < 0 ) && d->uniqname.isNull() && d->key.isNull() ) ) return true; } @@ -124,13 +124,13 @@ SipInfo::isVisible() const void -SipInfo::setHost( const QHostInfo& host ) +SipInfo::setHost( const QString& host ) { d->host = host; } -const QHostInfo +const QString SipInfo::host() const { Q_ASSERT( isValid() ); @@ -195,7 +195,7 @@ SipInfo::toJson() const m["visible"] = isVisible(); if( isVisible() ) { - m["ip"] = host().hostName(); + m["ip"] = host(); m["port"] = port(); m["key"] = key(); m["uniqname"] = uniqname(); @@ -227,9 +227,7 @@ SipInfo::fromJson( QString json ) info.setVisible( m["visible"].toBool() ); if( m["visible"].toBool() ) { - QHostInfo hostInfo; - hostInfo.setHostName( m["host"].toString() ); - info.setHost( hostInfo ); + info.setHost( m["host"].toString() ); 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 d354aab70..4b5ea2b48 100644 --- a/src/libtomahawk/sip/SipInfo.h +++ b/src/libtomahawk/sip/SipInfo.h @@ -43,8 +43,8 @@ public: void setVisible( bool visible ); bool isVisible() const; - void setHost( const QHostInfo& host ); - const QHostInfo host() const; + void setHost( const QString& host ); + const QString host() const; void setPort( int port ); int port() const;