* Wrong address split ip:port
* Q_ASSERTs
This commit is contained in:
Klaus Basan
2014-04-27 01:31:07 +02:00
parent f967ed40ba
commit b6c45b3f20
3 changed files with 23 additions and 7 deletions

View File

@@ -34,7 +34,8 @@ int main(int argc, char *argv[])
qDebug() << "3 + la/ra .. P2P DBus server"; qDebug() << "3 + la/ra .. P2P DBus server";
qDebug() << "la .. local audio, audio runs in this core here (default)"; qDebug() << "la .. local audio, audio runs in this core here (default)";
qDebug() << "ra .. remote audio, audio runs in the GUI or elsewhere"; qDebug() << "ra .. remote audio, audio runs in the GUI or elsewhere";
QString input = cin.readLine().toLower(); qDebug() << "x .. exit";
QString input = cin.readLine().toLower().trimmed();
// configure DBus server // configure DBus server
QString dBusAddress = BlackCore::CDBusServer::sessionDBusServer(); QString dBusAddress = BlackCore::CDBusServer::sessionDBusServer();
@@ -47,6 +48,10 @@ int main(int argc, char *argv[])
dBusAddress = cin.readLine().toLower(); dBusAddress = cin.readLine().toLower();
dBusAddress = BlackCore::CDBusServer::p2pAddress(dBusAddress); dBusAddress = BlackCore::CDBusServer::p2pAddress(dBusAddress);
} }
else if (input.startsWith("x"))
{
return 0;
}
// with remote audio // with remote audio
bool remoteAudio = input.contains("ra"); bool remoteAudio = input.contains("ra");

View File

@@ -245,7 +245,14 @@ namespace BlackCore
if (config.requiresDBusConnection()) if (config.requiresDBusConnection())
{ {
this->initDBusConnection(dbusAddress); this->initDBusConnection(dbusAddress);
Q_ASSERT(this->m_dbusConnection.isConnected()); if (!this->m_dbusConnection.isConnected())
{
QString notConnected("DBus connection failed");
QString e = this->m_dbusConnection.lastError().message();
if (!e.isEmpty()) notConnected.append(" ").append(e);
Q_ASSERT_X(false, "CRuntime::init", notConnected.toUtf8().constData());
qCritical() << notConnected;
}
} }
times.insert("DBus", time.restart()); times.insert("DBus", time.restart());

View File

@@ -6,8 +6,10 @@
#include <QDebug> #include <QDebug>
#include <QMetaClassInfo> #include <QMetaClassInfo>
#include "blackmisc/networkutils.h"
#include "dbus_server.h" #include "dbus_server.h"
namespace BlackCore namespace BlackCore
{ {
@@ -198,21 +200,23 @@ namespace BlackCore
*/ */
QString CDBusServer::p2pAddress(const QString &host, const QString &port) QString CDBusServer::p2pAddress(const QString &host, const QString &port)
{ {
QString h = host.isEmpty() ? "127.0.0.1" : host; QString h = host.isEmpty() ? "127.0.0.1" : host.trimmed();
QString p = port; QString p = port;
if (port.isEmpty()) if (port.isEmpty())
{ {
if (host.contains(":")) if (h.contains(":"))
{ {
QStringList parts = host.split(host); QStringList parts = h.split(":");
h = parts.at(0); Q_ASSERT_X(parts.length() == 2, "p2pAdress", "Wrong IP string split");
p = parts.at(1); h = parts.at(0).trimmed();
p = parts.at(1).trimmed();
} }
else else
{ {
p = "45000"; p = "45000";
} }
} }
Q_ASSERT_X(BlackMisc::CNetworkUtils::isValidIPv4Address(p), "p2pAdress", "Wrong IP in String");
QString p2p = QString("tcp:host=%1,port=%2").arg(h).arg(p); QString p2p = QString("tcp:host=%1,port=%2").arg(h).arg(p);
return p2p; return p2p;
} }