1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-20 12:52:30 +02:00

Add much of the logic for SRV lookups, if only it actually thought it had interfaces to work on -- may be a firewall issue

This commit is contained in:
Jeff Mitchell
2011-02-10 17:40:43 -05:00
parent 5016d05093
commit 4978789dcf
7 changed files with 63 additions and 15 deletions

View File

@@ -5,6 +5,7 @@
#include <QNetworkInterface>
#include <QFile>
#include <QThread>
#include <QNetworkProxy>
#include <QNetworkRequest>
#include <QNetworkReply>
@@ -40,6 +41,8 @@ Servent::Servent( QObject* parent )
{
s_instance = this;
setProxy( QNetworkProxy::NoProxy );
{
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
boost::bind( &Servent::localFileIODeviceFactory, this, _1 );
@@ -75,6 +78,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
if( !listen( ha, m_port ) && !listen( ha, ++m_port ) )
{
qDebug() << "Failed to listen on port" << m_port;
qDebug() << "Error string is " << errorString();
return false;
}
else
@@ -83,6 +87,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
}
// --lanhack means to advertise your LAN IP over jabber as if it were externallyVisible
qDebug() << "Address mode = " << (int)(TomahawkSettings::instance()->externalAddressMode());
switch( TomahawkSettings::instance()->externalAddressMode() )
{
case TomahawkSettings::Lan:
@@ -90,9 +95,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
{
if( ha.toString() == "127.0.0.1" ) continue;
if( ha.toString().contains( ":" ) ) continue; //ipv6
m_externalAddress = ha;
m_externalPort = m_port;
QMetaObject::invokeMethod( this, "setExternalAddress", Qt::QueuedConnection, Q_ARG( QHostAddress, ha ), Q_ARG( unsigned int, m_port ) );
qDebug() << "LANHACK: set external address to lan address" << ha.toString();
break;
}
@@ -100,6 +103,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
case TomahawkSettings::DynDns:
qDebug() << "External address mode set to dyndns...";
//FIXME: ready() is never emitted here, so it will not continue...
m_externalHostname = TomahawkSettings::instance()->externalHostname();
m_externalPort = TomahawkSettings::instance()->externalPort();
qDebug() << m_externalHostname << m_externalPort;
@@ -112,9 +116,6 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ),
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
break;
default:
emit ready();
}
return true;

View File

@@ -331,7 +331,7 @@ DNSResolver::DNSResolver()
}
void
DNSResolver::resolve( QString &host, QString &type )
DNSResolver::resolve( QString &host, QString type )
{
connect(m_dnsSharedRequest, SIGNAL(resultsReady()), SLOT(resultsReady()));
if( type == "SRV" )
@@ -367,6 +367,7 @@ DNSResolver::resultsReady()
}
}
}
qDebug() << "DNS resolve request was NOT successful! Error: " << (int)(m_dnsSharedRequest->error());
QString badResult( "NONE" );
emit result( badResult );
}

View File

@@ -30,7 +30,7 @@ namespace TomahawkUtils
explicit DNSResolver();
~DNSResolver() {}
void resolve( QString &host, QString &type );
void resolve( QString &host, QString type );
signals:
void result( QString &result );

View File

@@ -3,6 +3,7 @@
#include "tomahawksettings.h"
#include <QtPlugin>
#include <QStringList>
void
@@ -15,6 +16,7 @@ JabberPlugin::setProxy( QNetworkProxy* proxy )
bool
JabberPlugin::connect( bool startup )
{
qDebug() << "JabberPlugin::connect";
if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() )
return false;
@@ -23,13 +25,24 @@ JabberPlugin::connect( bool startup )
QString password = TomahawkSettings::instance()->jabberPassword();
unsigned int port = TomahawkSettings::instance()->jabberPort();
QStringList splitJid = jid.split( '@', QString::SkipEmptyParts );
if ( splitJid.size() < 2 )
{
qDebug() << "JID did not have an @ in it, could not find a server part";
return false;
}
// gtalk check
if( server.isEmpty() && ( jid.contains( "@gmail.com" ) || jid.contains( "@googlemail.com" ) ) )
//FIXME: Can remove this once the SRV lookups work
if ( server.isEmpty() && ( splitJid[1] == "gmail.com" || splitJid[1] == "googlemail.com" ) )
{
qDebug() << "Setting jabber server to talk.google.com";
server = "talk.google.com";
}
if ( server.isEmpty() )
server = splitJid[1];
if ( port < 1 || port > 65535 || jid.isEmpty() || password.isEmpty() )
{
qDebug() << "Jabber credentials look wrong, not connecting";
@@ -47,8 +60,8 @@ JabberPlugin::connect( bool startup )
QObject::connect( p, SIGNAL( disconnected() ), SIGNAL( disconnected() ) );
QObject::connect( p, SIGNAL( authError( int, QString ) ), SLOT( onAuthError( int, QString ) ) );
p->go();
p->resolveHostSRV();
return true;
}

View File

@@ -5,6 +5,7 @@
#include <QTimer>
#include <QString>
#include <QRegExp>
#include <utils/tomahawkutils.h>
using namespace gloox;
using namespace std;
@@ -12,6 +13,7 @@ using namespace std;
Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString& server, const int port )
: QObject()
, m_server()
{
qDebug() << Q_FUNC_INFO;
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
@@ -49,8 +51,7 @@ Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString&
}
m_client = QSharedPointer<gloox::Client>( new gloox::Client( m_jid, password.toStdString(), port ) );
if( !server.isEmpty() )
m_client->setServer( server.toStdString() );
m_server = server;
}
@@ -65,6 +66,19 @@ Jabber_p::~Jabber_p()
}
}
void
Jabber_p::resolveHostSRV()
{
if( m_server.isEmpty() )
{
qDebug() << "No server found!";
return;
}
TomahawkUtils::DNSResolver *resolver = TomahawkUtils::dnsResolver();
connect( resolver, SIGNAL(result(QString &)), SLOT(resolveResult(QString &)) );
qDebug() << "Resolving SRV record of " << m_server;
resolver->resolve( m_server, "SRV" );
}
void
Jabber_p::setProxy( QNetworkProxy* proxy )
@@ -98,10 +112,25 @@ Jabber_p::setProxy( QNetworkProxy* proxy )
}
}
void
Jabber_p::resolveResult( QString& result )
{
if ( result != "NONE" )
m_server = result;
qDebug() << "Final host name for XMPP server set to " << m_server;
QMetaObject::invokeMethod( this, "go", Qt::QueuedConnection );
}
void
Jabber_p::go()
{
if( !m_server.isEmpty() )
m_client->setServer( m_server.toStdString() );
else
{
qDebug() << "No server found!";
return;
}
m_client->registerConnectionListener( this );
m_client->rosterManager()->registerRosterListener( this );
m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this );
@@ -121,7 +150,7 @@ Jabber_p::go()
// Handle proxy
if ( m_client->connect( false ) )
if( m_client->connect( false ) )
{
emit connected();
QTimer::singleShot( 0, this, SLOT( doJabberRecv() ) );

View File

@@ -68,6 +68,8 @@ public:
void setProxy( QNetworkProxy* proxy );
void resolveHostSRV();
/// GLOOX IMPLEMENTATION STUFF FOLLOWS
virtual void onConnect();
virtual void onDisconnect( gloox::ConnectionError e );
@@ -120,6 +122,7 @@ signals:
void authError( int, const QString& );
public slots:
void resolveResult( QString & );
void go();
void sendMsg( const QString& to, const QString& msg );
void broadcastMsg( const QString& msg );
@@ -137,6 +140,7 @@ private:
QMap<gloox::Presence::PresenceType, QString> m_presences;
QMap<QString, gloox::Presence::PresenceType> m_peers;
QSharedPointer<gloox::VCardManager> m_vcardManager;
QString m_server;
};
#endif // JABBER_H

View File

@@ -408,7 +408,7 @@ TomahawkApp::setupSIP()
if( !arguments().contains( "--nosip" ) )
{
m_xmppBot = new XMPPBot( this );
qDebug() << "Connecting SIP classes";
m_sipHandler->connect( true );
// m_sipHandler->setProxy( *TomahawkUtils::proxy() );
}