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:
@@ -5,6 +5,7 @@
|
|||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QNetworkProxy>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
@@ -40,6 +41,8 @@ Servent::Servent( QObject* parent )
|
|||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
|
setProxy( QNetworkProxy::NoProxy );
|
||||||
|
|
||||||
{
|
{
|
||||||
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
|
boost::function<QSharedPointer<QIODevice>(result_ptr)> fac =
|
||||||
boost::bind( &Servent::localFileIODeviceFactory, this, _1 );
|
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 ) )
|
if( !listen( ha, m_port ) && !listen( ha, ++m_port ) )
|
||||||
{
|
{
|
||||||
qDebug() << "Failed to listen on port" << m_port;
|
qDebug() << "Failed to listen on port" << m_port;
|
||||||
|
qDebug() << "Error string is " << errorString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
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
|
// --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() )
|
switch( TomahawkSettings::instance()->externalAddressMode() )
|
||||||
{
|
{
|
||||||
case TomahawkSettings::Lan:
|
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() == "127.0.0.1" ) continue;
|
||||||
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
if( ha.toString().contains( ":" ) ) continue; //ipv6
|
||||||
|
QMetaObject::invokeMethod( this, "setExternalAddress", Qt::QueuedConnection, Q_ARG( QHostAddress, ha ), Q_ARG( unsigned int, m_port ) );
|
||||||
m_externalAddress = ha;
|
|
||||||
m_externalPort = m_port;
|
|
||||||
qDebug() << "LANHACK: set external address to lan address" << ha.toString();
|
qDebug() << "LANHACK: set external address to lan address" << ha.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -100,6 +103,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
|
|||||||
|
|
||||||
case TomahawkSettings::DynDns:
|
case TomahawkSettings::DynDns:
|
||||||
qDebug() << "External address mode set to 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_externalHostname = TomahawkSettings::instance()->externalHostname();
|
||||||
m_externalPort = TomahawkSettings::instance()->externalPort();
|
m_externalPort = TomahawkSettings::instance()->externalPort();
|
||||||
qDebug() << m_externalHostname << m_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 ) ),
|
connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ),
|
||||||
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
|
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
emit ready();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@@ -331,7 +331,7 @@ DNSResolver::DNSResolver()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DNSResolver::resolve( QString &host, QString &type )
|
DNSResolver::resolve( QString &host, QString type )
|
||||||
{
|
{
|
||||||
connect(m_dnsSharedRequest, SIGNAL(resultsReady()), SLOT(resultsReady()));
|
connect(m_dnsSharedRequest, SIGNAL(resultsReady()), SLOT(resultsReady()));
|
||||||
if( type == "SRV" )
|
if( type == "SRV" )
|
||||||
@@ -367,6 +367,7 @@ DNSResolver::resultsReady()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
qDebug() << "DNS resolve request was NOT successful! Error: " << (int)(m_dnsSharedRequest->error());
|
||||||
QString badResult( "NONE" );
|
QString badResult( "NONE" );
|
||||||
emit result( badResult );
|
emit result( badResult );
|
||||||
}
|
}
|
||||||
|
@@ -30,7 +30,7 @@ namespace TomahawkUtils
|
|||||||
explicit DNSResolver();
|
explicit DNSResolver();
|
||||||
~DNSResolver() {}
|
~DNSResolver() {}
|
||||||
|
|
||||||
void resolve( QString &host, QString &type );
|
void resolve( QString &host, QString type );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void result( QString &result );
|
void result( QString &result );
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -15,6 +16,7 @@ JabberPlugin::setProxy( QNetworkProxy* proxy )
|
|||||||
bool
|
bool
|
||||||
JabberPlugin::connect( bool startup )
|
JabberPlugin::connect( bool startup )
|
||||||
{
|
{
|
||||||
|
qDebug() << "JabberPlugin::connect";
|
||||||
if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() )
|
if ( startup && !TomahawkSettings::instance()->jabberAutoConnect() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -23,13 +25,24 @@ JabberPlugin::connect( bool startup )
|
|||||||
QString password = TomahawkSettings::instance()->jabberPassword();
|
QString password = TomahawkSettings::instance()->jabberPassword();
|
||||||
unsigned int port = TomahawkSettings::instance()->jabberPort();
|
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
|
// 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";
|
qDebug() << "Setting jabber server to talk.google.com";
|
||||||
server = "talk.google.com";
|
server = "talk.google.com";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( server.isEmpty() )
|
||||||
|
server = splitJid[1];
|
||||||
|
|
||||||
if ( port < 1 || port > 65535 || jid.isEmpty() || password.isEmpty() )
|
if ( port < 1 || port > 65535 || jid.isEmpty() || password.isEmpty() )
|
||||||
{
|
{
|
||||||
qDebug() << "Jabber credentials look wrong, not connecting";
|
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( disconnected() ), SIGNAL( disconnected() ) );
|
||||||
QObject::connect( p, SIGNAL( authError( int, QString ) ), SLOT( onAuthError( int, QString ) ) );
|
QObject::connect( p, SIGNAL( authError( int, QString ) ), SLOT( onAuthError( int, QString ) ) );
|
||||||
|
|
||||||
p->go();
|
p->resolveHostSRV();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <utils/tomahawkutils.h>
|
||||||
|
|
||||||
using namespace gloox;
|
using namespace gloox;
|
||||||
using namespace std;
|
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 )
|
Jabber_p::Jabber_p( const QString& jid, const QString& password, const QString& server, const int port )
|
||||||
: QObject()
|
: QObject()
|
||||||
|
, m_server()
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
|
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 ) );
|
m_client = QSharedPointer<gloox::Client>( new gloox::Client( m_jid, password.toStdString(), port ) );
|
||||||
if( !server.isEmpty() )
|
m_server = server;
|
||||||
m_client->setServer( server.toStdString() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
void
|
||||||
Jabber_p::setProxy( QNetworkProxy* proxy )
|
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
|
void
|
||||||
Jabber_p::go()
|
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->registerConnectionListener( this );
|
||||||
m_client->rosterManager()->registerRosterListener( this );
|
m_client->rosterManager()->registerRosterListener( this );
|
||||||
m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this );
|
m_client->logInstance().registerLogHandler( LogLevelWarning, LogAreaAll, this );
|
||||||
@@ -121,7 +150,7 @@ Jabber_p::go()
|
|||||||
|
|
||||||
// Handle proxy
|
// Handle proxy
|
||||||
|
|
||||||
if ( m_client->connect( false ) )
|
if( m_client->connect( false ) )
|
||||||
{
|
{
|
||||||
emit connected();
|
emit connected();
|
||||||
QTimer::singleShot( 0, this, SLOT( doJabberRecv() ) );
|
QTimer::singleShot( 0, this, SLOT( doJabberRecv() ) );
|
||||||
|
@@ -68,6 +68,8 @@ public:
|
|||||||
|
|
||||||
void setProxy( QNetworkProxy* proxy );
|
void setProxy( QNetworkProxy* proxy );
|
||||||
|
|
||||||
|
void resolveHostSRV();
|
||||||
|
|
||||||
/// GLOOX IMPLEMENTATION STUFF FOLLOWS
|
/// GLOOX IMPLEMENTATION STUFF FOLLOWS
|
||||||
virtual void onConnect();
|
virtual void onConnect();
|
||||||
virtual void onDisconnect( gloox::ConnectionError e );
|
virtual void onDisconnect( gloox::ConnectionError e );
|
||||||
@@ -120,6 +122,7 @@ signals:
|
|||||||
void authError( int, const QString& );
|
void authError( int, const QString& );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void resolveResult( QString & );
|
||||||
void go();
|
void go();
|
||||||
void sendMsg( const QString& to, const QString& msg );
|
void sendMsg( const QString& to, const QString& msg );
|
||||||
void broadcastMsg( const QString& msg );
|
void broadcastMsg( const QString& msg );
|
||||||
@@ -137,6 +140,7 @@ private:
|
|||||||
QMap<gloox::Presence::PresenceType, QString> m_presences;
|
QMap<gloox::Presence::PresenceType, QString> m_presences;
|
||||||
QMap<QString, gloox::Presence::PresenceType> m_peers;
|
QMap<QString, gloox::Presence::PresenceType> m_peers;
|
||||||
QSharedPointer<gloox::VCardManager> m_vcardManager;
|
QSharedPointer<gloox::VCardManager> m_vcardManager;
|
||||||
|
QString m_server;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // JABBER_H
|
#endif // JABBER_H
|
||||||
|
@@ -408,7 +408,7 @@ TomahawkApp::setupSIP()
|
|||||||
if( !arguments().contains( "--nosip" ) )
|
if( !arguments().contains( "--nosip" ) )
|
||||||
{
|
{
|
||||||
m_xmppBot = new XMPPBot( this );
|
m_xmppBot = new XMPPBot( this );
|
||||||
|
qDebug() << "Connecting SIP classes";
|
||||||
m_sipHandler->connect( true );
|
m_sipHandler->connect( true );
|
||||||
// m_sipHandler->setProxy( *TomahawkUtils::proxy() );
|
// m_sipHandler->setProxy( *TomahawkUtils::proxy() );
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user