1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge branch 'pr1527' into back_in_the_game

This commit is contained in:
tux3 2015-04-20 12:00:53 +02:00
commit 2d213b7616
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 123 additions and 44 deletions

View File

@ -174,6 +174,7 @@ void Core::make_tox(QByteArray savedata)
toxOptions.proxy_type = TOX_PROXY_TYPE_SOCKS5; toxOptions.proxy_type = TOX_PROXY_TYPE_SOCKS5;
else if (proxyType == ProxyType::ptHTTP) else if (proxyType == ProxyType::ptHTTP)
toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP; toxOptions.proxy_type = TOX_PROXY_TYPE_HTTP;
QByteArray proxyAddrData = proxyAddr.toUtf8(); QByteArray proxyAddrData = proxyAddr.toUtf8();
/// TODO: We're leaking a tiny amount of memory there, go fix that later /// TODO: We're leaking a tiny amount of memory there, go fix that later
char* proxyAddrCopy = new char[proxyAddrData.size()+1]; char* proxyAddrCopy = new char[proxyAddrData.size()+1];
@ -205,7 +206,9 @@ void Core::make_tox(QByteArray savedata)
return; return;
} }
else else
{
qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly."; qWarning() << "Core failed to start with IPv6, falling back to IPv4. LAN discovery may not work properly.";
}
} }
else if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE) else if (toxOptions.proxy_type != TOX_PROXY_TYPE_NONE)
{ {
@ -338,7 +341,9 @@ void Core::start()
setAvatar(data); setAvatar(data);
} }
else else
{
qDebug() << "Core: Error loading self avatar"; qDebug() << "Core: Error loading self avatar";
}
ready = true; ready = true;
@ -369,7 +374,9 @@ void Core::process()
#endif #endif
if (checkConnection()) if (checkConnection())
{
tolerance = CORE_DISCONNECT_TOLERANCE; tolerance = CORE_DISCONNECT_TOLERANCE;
}
else if (!(--tolerance)) else if (!(--tolerance))
{ {
bootstrapDht(); bootstrapDht();
@ -385,13 +392,16 @@ bool Core::checkConnection()
//static int count = 0; //static int count = 0;
bool toxConnected = tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE; bool toxConnected = tox_self_get_connection_status(tox) != TOX_CONNECTION_NONE;
if (toxConnected && !isConnected) { if (toxConnected && !isConnected)
{
qDebug() << "Core: Connected to DHT"; qDebug() << "Core: Connected to DHT";
emit connected(); emit connected();
isConnected = true; isConnected = true;
//if (count) qDebug() << "Core: disconnect count:" << count; //if (count) qDebug() << "Core: disconnect count:" << count;
//count = 0; //count = 0;
} else if (!toxConnected && isConnected) { }
else if (!toxConnected && isConnected)
{
qDebug() << "Core: Disconnected to DHT"; qDebug() << "Core: Disconnected to DHT";
emit disconnected(); emit disconnected();
isConnected = false; isConnected = false;
@ -421,10 +431,14 @@ void Core::bootstrapDht()
const Settings::DhtServer& dhtServer = dhtServerList[j % listSize]; const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
if (tox_bootstrap(tox, dhtServer.address.toLatin1().data(), if (tox_bootstrap(tox, dhtServer.address.toLatin1().data(),
dhtServer.port, CUserId(dhtServer.userId).data(), nullptr) == 1) dhtServer.port, CUserId(dhtServer.userId).data(), nullptr) == 1)
{
qDebug() << QString("Core: Bootstrapping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data() qDebug() << QString("Core: Bootstrapping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data()
+QString(", port ")+QString().setNum(dhtServer.port); +QString(", port ")+QString().setNum(dhtServer.port);
}
else else
{
qDebug() << "Core: Error bootstrapping from "+dhtServer.name; qDebug() << "Core: Error bootstrapping from "+dhtServer.name;
}
j++; j++;
i++; i++;
@ -487,7 +501,8 @@ void Core::onConnectionStatusChanged(Tox*/* tox*/, uint32_t friendId, TOX_CONNEC
{ {
Status friendStatus = status ? Status::Online : Status::Offline; Status friendStatus = status ? Status::Online : Status::Offline;
emit static_cast<Core*>(core)->friendStatusChanged(friendId, friendStatus); emit static_cast<Core*>(core)->friendStatusChanged(friendId, friendStatus);
if (friendStatus == Status::Offline) { if (friendStatus == Status::Offline)
{
static_cast<Core*>(core)->checkLastOnline(friendId); static_cast<Core*>(core)->checkLastOnline(friendId);
for (ToxFile& f : fileSendQueue) for (ToxFile& f : fileSendQueue)
@ -506,7 +521,9 @@ void Core::onConnectionStatusChanged(Tox*/* tox*/, uint32_t friendId, TOX_CONNEC
emit static_cast<Core*>(core)->fileTransferBrokenUnbroken(f, true); emit static_cast<Core*>(core)->fileTransferBrokenUnbroken(f, true);
} }
} }
} else { }
else
{
for (ToxFile& f : fileRecvQueue) for (ToxFile& f : fileRecvQueue)
{ {
if (f.friendId == friendId && f.status == ToxFile::BROKEN) if (f.friendId == friendId && f.status == ToxFile::BROKEN)
@ -563,6 +580,7 @@ void Core::onGroupTitleChange(Tox*, int groupnumber, int peernumber, const uint8
QString author; QString author;
if (peernumber >= 0) if (peernumber >= 0)
author = core->getGroupPeerName(groupnumber, peernumber); author = core->getGroupPeerName(groupnumber, peernumber);
emit core->groupTitleChanged(groupnumber, author, CString::toString(title, len)); emit core->groupTitleChanged(groupnumber, author, CString::toString(title, len));
} }
@ -779,9 +797,12 @@ void Core::onReadReceiptCallback(Tox*, uint32_t friendnumber, uint32_t receipt,
void Core::acceptFriendRequest(const QString& userId) void Core::acceptFriendRequest(const QString& userId)
{ {
uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr); uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr);
if (friendId == UINT32_MAX) { if (friendId == UINT32_MAX)
{
emit failedToAddFriend(userId); emit failedToAddFriend(userId);
} else { }
else
{
saveConfiguration(); saveConfiguration();
emit friendAdded(friendId, userId); emit friendAdded(friendId, userId);
} }
@ -1069,9 +1090,13 @@ void Core::removeFriend(uint32_t friendId, bool fake)
{ {
if (!isReady() || fake) if (!isReady() || fake)
return; return;
if (tox_friend_delete(tox, friendId, nullptr) == false) {
if (tox_friend_delete(tox, friendId, nullptr) == false)
{
emit failedToRemoveFriend(friendId); emit failedToRemoveFriend(friendId);
} else { }
else
{
saveConfiguration(); saveConfiguration();
emit friendRemoved(friendId); emit friendRemoved(friendId);
} }
@ -1081,6 +1106,7 @@ void Core::removeGroup(int groupId, bool fake)
{ {
if (!isReady() || fake) if (!isReady() || fake)
return; return;
tox_del_groupchat(tox, groupId); tox_del_groupchat(tox, groupId);
if (groupCalls[groupId].active) if (groupCalls[groupId].active)
@ -1102,9 +1128,12 @@ void Core::setUsername(const QString& username)
{ {
CString cUsername(username); CString cUsername(username);
if (tox_self_set_name(tox, cUsername.data(), cUsername.size(), nullptr) == false) { if (tox_self_set_name(tox, cUsername.data(), cUsername.size(), nullptr) == false)
{
emit failedToSetUsername(username); emit failedToSetUsername(username);
} else { }
else
{
emit usernameSet(username); emit usernameSet(username);
saveConfiguration(); saveConfiguration();
} }
@ -1171,7 +1200,9 @@ void Core::setStatusMessage(const QString& message)
if (tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr) == false) { if (tox_self_set_status_message(tox, cMessage.data(), cMessage.size(), nullptr) == false) {
emit failedToSetStatusMessage(message); emit failedToSetStatusMessage(message);
} else { }
else
{
saveConfiguration(); saveConfiguration();
emit statusMessageSet(message); emit statusMessageSet(message);
} }
@ -1180,7 +1211,8 @@ void Core::setStatusMessage(const QString& message)
void Core::setStatus(Status status) void Core::setStatus(Status status)
{ {
TOX_USER_STATUS userstatus; TOX_USER_STATUS userstatus;
switch (status) { switch (status)
{
case Status::Online: case Status::Online:
userstatus = TOX_USER_STATUS_NONE; userstatus = TOX_USER_STATUS_NONE;
break; break;
@ -1213,11 +1245,14 @@ QString Core::sanitize(QString name)
QList<QChar> banned = {'/', '\\', ':', '<', '>', '"', '|', '?', '*'}; QList<QChar> banned = {'/', '\\', ':', '<', '>', '"', '|', '?', '*'};
for (QChar c : banned) for (QChar c : banned)
name.replace(c, '_'); name.replace(c, '_');
// also remove leading and trailing periods // also remove leading and trailing periods
if (name[0] == '.') if (name[0] == '.')
name[0] = '_'; name[0] = '_';
if (name.endsWith('.')) if (name.endsWith('.'))
name[name.length()-1] = '_'; name[name.length()-1] = '_';
return name; return name;
} }
@ -1229,18 +1264,21 @@ QByteArray Core::loadToxSave(QString path)
QFile configurationFile(path); QFile configurationFile(path);
qDebug() << "Core::loadConfiguration: reading from " << path; qDebug() << "Core::loadConfiguration: reading from " << path;
if (!configurationFile.exists()) { if (!configurationFile.exists())
{
qWarning() << "The Tox configuration file was not found"; qWarning() << "The Tox configuration file was not found";
return data; return data;
} }
if (!configurationFile.open(QIODevice::ReadOnly)) { if (!configurationFile.open(QIODevice::ReadOnly))
{
qCritical() << "File " << path << " cannot be opened"; qCritical() << "File " << path << " cannot be opened";
return data; return data;
} }
qint64 fileSize = configurationFile.size(); qint64 fileSize = configurationFile.size();
if (fileSize > 0) { if (fileSize > 0)
{
data = configurationFile.readAll(); data = configurationFile.readAll();
/* TODO: Clean this up /* TODO: Clean this up
int error = tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size()); int error = tox_load(tox, reinterpret_cast<uint8_t *>(data.data()), data.size());
@ -1282,7 +1320,8 @@ void Core::saveConfiguration()
QString dir = Settings::getSettingsDirPath(); QString dir = Settings::getSettingsDirPath();
QDir directory(dir); QDir directory(dir);
if (!directory.exists() && !directory.mkpath(directory.absolutePath())) { if (!directory.exists() && !directory.mkpath(directory.absolutePath()))
{
qCritical() << "Error while creating directory " << dir; qCritical() << "Error while creating directory " << dir;
return; return;
} }
@ -1341,17 +1380,21 @@ void Core::switchConfiguration(const QString& profile)
void Core::loadFriends() void Core::loadFriends()
{ {
const uint32_t friendCount = tox_self_get_friend_list_size(tox); const uint32_t friendCount = tox_self_get_friend_list_size(tox);
if (friendCount > 0) { if (friendCount > 0)
{
// assuming there are not that many friends to fill up the whole stack // assuming there are not that many friends to fill up the whole stack
uint32_t *ids = new uint32_t[friendCount]; uint32_t *ids = new uint32_t[friendCount];
tox_self_get_friend_list(tox, ids); tox_self_get_friend_list(tox, ids);
uint8_t clientId[TOX_PUBLIC_KEY_SIZE]; uint8_t clientId[TOX_PUBLIC_KEY_SIZE];
for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i)
if (tox_friend_get_public_key(tox, ids[i], clientId, nullptr)) { {
if (tox_friend_get_public_key(tox, ids[i], clientId, nullptr))
{
emit friendAdded(ids[i], CUserId::toString(clientId)); emit friendAdded(ids[i], CUserId::toString(clientId));
const size_t nameSize = tox_friend_get_name_size(tox, ids[i], nullptr); const size_t nameSize = tox_friend_get_name_size(tox, ids[i], nullptr);
if (nameSize != SIZE_MAX) { if (nameSize != SIZE_MAX)
{
uint8_t *name = new uint8_t[nameSize]; uint8_t *name = new uint8_t[nameSize];
if (tox_friend_get_name(tox, ids[i], name, nullptr)) if (tox_friend_get_name(tox, ids[i], name, nullptr))
emit friendUsernameChanged(ids[i], CString::toString(name, nameSize)); emit friendUsernameChanged(ids[i], CString::toString(name, nameSize));
@ -1359,9 +1402,11 @@ void Core::loadFriends()
} }
const size_t statusMessageSize = tox_friend_get_status_message_size(tox, ids[i], nullptr); const size_t statusMessageSize = tox_friend_get_status_message_size(tox, ids[i], nullptr);
if (statusMessageSize != SIZE_MAX) { if (statusMessageSize != SIZE_MAX)
{
uint8_t *statusMessage = new uint8_t[statusMessageSize]; uint8_t *statusMessage = new uint8_t[statusMessageSize];
if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr)) { if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr))
{
emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage, statusMessageSize)); emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage, statusMessageSize));
} }
delete[] statusMessage; delete[] statusMessage;
@ -1377,9 +1422,8 @@ void Core::loadFriends()
void Core::checkLastOnline(uint32_t friendId) { void Core::checkLastOnline(uint32_t friendId) {
const uint64_t lastOnline = tox_friend_get_last_online(tox, friendId, nullptr); const uint64_t lastOnline = tox_friend_get_last_online(tox, friendId, nullptr);
if (lastOnline != UINT64_MAX) { if (lastOnline != UINT64_MAX)
emit friendLastSeenChanged(friendId, QDateTime::fromTime_t(lastOnline)); emit friendLastSeenChanged(friendId, QDateTime::fromTime_t(lastOnline));
}
} }
int Core::getGroupNumberPeers(int groupId) const int Core::getGroupNumberPeers(int groupId) const
@ -1436,6 +1480,7 @@ QList<QString> Core::getGroupPeerNames(int groupId) const
} }
for (int i=0; i<nPeers; i++) for (int i=0; i<nPeers; i++)
names.push_back(CString::toString(namesArray[i], lengths[i])); names.push_back(CString::toString(namesArray[i], lengths[i]));
return names; return names;
} }
@ -1623,9 +1668,7 @@ bool Core::hasFriendWithPublicKey(const QString &pubkey) const
{ {
// Valid length check // Valid length check
if (pubkey.length() != (TOX_PUBLIC_KEY_SIZE * 2)) if (pubkey.length() != (TOX_PUBLIC_KEY_SIZE * 2))
{
return false; return false;
}
bool found = false; bool found = false;
const size_t friendCount = tox_self_get_friend_list_size(tox); const size_t friendCount = tox_self_get_friend_list_size(tox);
@ -1656,7 +1699,8 @@ QString Core::getFriendAddress(uint32_t friendNumber) const
{ {
// If we don't know the full address of the client, return just the id, otherwise get the full address // If we don't know the full address of the client, return just the id, otherwise get the full address
uint8_t rawid[TOX_PUBLIC_KEY_SIZE]; uint8_t rawid[TOX_PUBLIC_KEY_SIZE];
if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr)) { if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr))
{
qWarning() << "Core::getFriendAddress: Getting public key failed"; qWarning() << "Core::getFriendAddress: Getting public key failed";
return QString(); return QString();
} }
@ -1673,7 +1717,8 @@ QString Core::getFriendAddress(uint32_t friendNumber) const
QString Core::getFriendUsername(uint32_t friendnumber) const QString Core::getFriendUsername(uint32_t friendnumber) const
{ {
size_t namesize = tox_friend_get_name_size(tox, friendnumber, nullptr); size_t namesize = tox_friend_get_name_size(tox, friendnumber, nullptr);
if (namesize == SIZE_MAX) { if (namesize == SIZE_MAX)
{
qWarning() << "Core::getFriendUsername: Failed to get name size for friend "<<friendnumber; qWarning() << "Core::getFriendUsername: Failed to get name size for friend "<<friendnumber;
return QString(); return QString();
} }

View File

@ -107,6 +107,7 @@ QByteArray Core::encryptData(const QByteArray& data, PasswordType passtype)
{ {
if (!pwsaltedkeys[passtype]) if (!pwsaltedkeys[passtype])
return QByteArray(); return QByteArray();
uint8_t encrypted[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH]; uint8_t encrypted[data.size() + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
if (!tox_pass_key_encrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), if (!tox_pass_key_encrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(),
pwsaltedkeys[passtype], encrypted, nullptr)) pwsaltedkeys[passtype], encrypted, nullptr))
@ -121,6 +122,7 @@ QByteArray Core::decryptData(const QByteArray& data, PasswordType passtype)
{ {
if (!pwsaltedkeys[passtype]) if (!pwsaltedkeys[passtype])
return QByteArray(); return QByteArray();
int sz = data.size() - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; int sz = data.size() - TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
uint8_t decrypted[sz]; uint8_t decrypted[sz];
if (!tox_pass_key_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(), if (!tox_pass_key_decrypt(reinterpret_cast<const uint8_t*>(data.data()), data.size(),
@ -237,10 +239,12 @@ void Core::checkEncryptedHistory()
{ {
if (!exists || HistoryKeeper::checkPassword()) if (!exists || HistoryKeeper::checkPassword())
return; return;
dialogtxt = tr("The chat history password failed. Please try another?", "used only when pw set before load() doesn't work"); dialogtxt = tr("The chat history password failed. Please try another?", "used only when pw set before load() doesn't work");
} }
else else
dialogtxt = a; dialogtxt = a;
dialogtxt += "\n" + c; dialogtxt += "\n" + c;
if (pwsaltedkeys[ptMain]) if (pwsaltedkeys[ptMain])
@ -287,7 +291,8 @@ void Core::saveConfiguration(const QString& path)
} }
QSaveFile configurationFile(path); QSaveFile configurationFile(path);
if (!configurationFile.open(QIODevice::WriteOnly)) { if (!configurationFile.open(QIODevice::WriteOnly))
{
qCritical() << "File " << path << " cannot be opened"; qCritical() << "File " << path << " cannot be opened";
return; return;
} }
@ -304,7 +309,8 @@ void Core::saveConfiguration(const QString& path)
else else
fileSize = tox_get_savedata_size(tox); fileSize = tox_get_savedata_size(tox);
if (fileSize > 0 && fileSize <= std::numeric_limits<int32_t>::max()) { if (fileSize > 0 && fileSize <= std::numeric_limits<int32_t>::max())
{
uint8_t *data = new uint8_t[fileSize]; uint8_t *data = new uint8_t[fileSize];
if (encrypt) if (encrypt)

View File

@ -58,35 +58,45 @@ QByteArray ToxDNS::fetchLastTextRecord(const QString& record, bool silent)
qApp->processEvents(); qApp->processEvents();
QThread::msleep(100); QThread::msleep(100);
} }
if (timeout >= 30) { if (timeout >= 30)
{
dns.abort(); dns.abort();
if (!silent) if (!silent)
showWarning(tr("The connection timed out","The DNS gives the Tox ID associated to toxme.se addresses")); showWarning(tr("The connection timed out","The DNS gives the Tox ID associated to toxme.se addresses"));
return result; return result;
} }
if (dns.error() == QDnsLookup::NotFoundError) { if (dns.error() == QDnsLookup::NotFoundError)
{
if (!silent) if (!silent)
showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses")); showWarning(tr("This address does not exist","The DNS gives the Tox ID associated to toxme.se addresses"));
return result; return result;
} }
else if (dns.error() != QDnsLookup::NoError) { else if (dns.error() != QDnsLookup::NoError)
{
if (!silent) if (!silent)
showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses")); showWarning(tr("Error while looking up DNS","The DNS gives the Tox ID associated to toxme.se addresses"));
return result; return result;
} }
const QList<QDnsTextRecord> textRecords = dns.textRecords(); const QList<QDnsTextRecord> textRecords = dns.textRecords();
if (textRecords.isEmpty()) { if (textRecords.isEmpty())
{
if (!silent) if (!silent)
showWarning(tr("No text record found", "Error with the DNS")); showWarning(tr("No text record found", "Error with the DNS"));
return result; return result;
} }
const QList<QByteArray> textRecordValues = textRecords.last().values(); const QList<QByteArray> textRecordValues = textRecords.last().values();
if (textRecordValues.length() != 1) { if (textRecordValues.length() != 1)
{
if (!silent) if (!silent)
showWarning(tr("Unexpected number of values in text record", "Error with the DNS")); showWarning(tr("Unexpected number of values in text record", "Error with the DNS"));
return result; return result;
} }
@ -104,7 +114,8 @@ QString ToxDNS::queryTox1(const QString& record, bool silent)
// Check toxdns protocol version // Check toxdns protocol version
int verx = entry.indexOf("v="); int verx = entry.indexOf("v=");
if (verx) { if (verx)
{
verx += 2; verx += 2;
int verend = entry.indexOf(';', verx); int verend = entry.indexOf(';', verx);
if (verend) if (verend)
@ -114,6 +125,7 @@ QString ToxDNS::queryTox1(const QString& record, bool silent)
{ {
if (!silent) if (!silent)
showWarning(tr("The version of Tox DNS used by this server is not supported", "Error with the DNS")); showWarning(tr("The version of Tox DNS used by this server is not supported", "Error with the DNS"));
return toxId; return toxId;
} }
} }
@ -121,23 +133,29 @@ QString ToxDNS::queryTox1(const QString& record, bool silent)
// Get the tox id // Get the tox id
int idx = entry.indexOf("id="); int idx = entry.indexOf("id=");
if (idx < 0) { if (idx < 0)
{
if (!silent) if (!silent)
showWarning(tr("The DNS lookup does not contain any Tox ID", "Error with the DNS")); showWarning(tr("The DNS lookup does not contain any Tox ID", "Error with the DNS"));
return toxId; return toxId;
} }
idx += 3; idx += 3;
if (entry.length() < idx + static_cast<int>(TOX_HEX_ID_LENGTH)) { if (entry.length() < idx + static_cast<int>(TOX_HEX_ID_LENGTH))
{
if (!silent) if (!silent)
showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
return toxId; return toxId;
} }
toxId = entry.mid(idx, TOX_HEX_ID_LENGTH); toxId = entry.mid(idx, TOX_HEX_ID_LENGTH);
if (!ToxID::isToxId(toxId)) { if (!ToxID::isToxId(toxId))
{
if (!silent) if (!silent)
showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS")); showWarning(tr("The DNS lookup does not contain a valid Tox ID", "Error with the DNS"));
return toxId; return toxId;
} }
@ -178,7 +196,8 @@ QString ToxDNS::queryTox3(const tox3_server& server, const QString &record, bool
// Check toxdns protocol version // Check toxdns protocol version
verx = entry.indexOf("v="); verx = entry.indexOf("v=");
if (verx!=-1) { if (verx!=-1)
{
verx += 2; verx += 2;
int verend = entry.indexOf(';', verx); int verend = entry.indexOf(';', verx);
if (verend!=-1) if (verend!=-1)
@ -194,7 +213,8 @@ QString ToxDNS::queryTox3(const tox3_server& server, const QString &record, bool
// Get and decrypt the tox id // Get and decrypt the tox id
idx = entry.indexOf("id="); idx = entry.indexOf("id=");
if (idx < 0) { if (idx < 0)
{
qWarning() << "queryTox3: Server "<<server.name<<" returned an empty id, using tox1 as a fallback"; qWarning() << "queryTox3: Server "<<server.name<<" returned an empty id, using tox1 as a fallback";
goto fallbackOnTox1; goto fallbackOnTox1;
} }
@ -217,6 +237,7 @@ QString ToxDNS::queryTox3(const tox3_server& server, const QString &record, bool
fallbackOnTox1: fallbackOnTox1:
if (tox_dns3) if (tox_dns3)
tox_dns3_kill(tox_dns3); tox_dns3_kill(tox_dns3);
#if TOX1_SILENT_FALLBACK #if TOX1_SILENT_FALLBACK
toxIdStr = queryTox1(record, silent); toxIdStr = queryTox1(record, silent);
#elif TOX1_ASK_FALLBACK #elif TOX1_ASK_FALLBACK
@ -226,6 +247,7 @@ Should tox1 be used anyway?\n\
If unsure, press No, so that request to ToxDNS service will not be made using unsecure protocol."), QMessageBox::Yes|QMessageBox::No, QMessageBox::No); If unsure, press No, so that request to ToxDNS service will not be made using unsecure protocol."), QMessageBox::Yes|QMessageBox::No, QMessageBox::No);
if (btn == QMessageBox::Yes) if (btn == QMessageBox::Yes)
queryTox1(record, silent); queryTox1(record, silent);
#endif #endif
return toxIdStr; return toxIdStr;
} }
@ -234,12 +256,17 @@ ToxID ToxDNS::resolveToxAddress(const QString &address, bool silent)
{ {
ToxID toxId; ToxID toxId;
if (address.isEmpty()) { if (address.isEmpty())
{
return toxId; return toxId;
} else if (ToxID::isToxId(address)) { }
else if (ToxID::isToxId(address))
{
toxId = ToxID::fromString(address); toxId = ToxID::fromString(address);
return toxId; return toxId;
} else { }
else
{
// If we're querying one of our pinned server, do a tox3 request directly // If we're querying one of our pinned server, do a tox3 request directly
QString servname = address.mid(address.indexOf('@')+1); QString servname = address.mid(address.indexOf('@')+1);
for (const ToxDNS::tox3_server& pin : ToxDNS::pinnedServers) for (const ToxDNS::tox3_server& pin : ToxDNS::pinnedServers)
@ -272,6 +299,7 @@ Should tox1 be used anyway?\n\
If unsure, press No, so that request to ToxDNS service will not be made using unsecure protocol."), QMessageBox::Ok|QMessageBox::No, QMessageBox::No); If unsure, press No, so that request to ToxDNS service will not be made using unsecure protocol."), QMessageBox::Ok|QMessageBox::No, QMessageBox::No);
if (btn == QMessageBox::Ok) if (btn == QMessageBox::Ok)
toxId = ToxID::fromString(queryTox1(address, silent)); toxId = ToxID::fromString(queryTox1(address, silent));
#else #else
return toxId; return toxId;
#endif #endif