feat(core): Extend and deduplicate Tox_Err_File_Send error parsing

reviewable/pr6578/r3
Anthony Bilinski 2022-03-17 22:43:14 -07:00
parent 350fa9b462
commit aff5663351
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 40 additions and 22 deletions

View File

@ -26,11 +26,16 @@
#include "src/model/status.h"
#include "src/model/toxclientstandards.h"
#include "util/compatiblerecursivemutex.h"
#include "util/toxcoreerrorparser.h"
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QRegularExpression>
#include <QThread>
#include <tox/tox.h>
#include <cassert>
#include <memory>
@ -109,26 +114,7 @@ void CoreFile::sendAvatarFile(uint32_t friendId, const QByteArray& data)
Tox_Err_File_Send error;
const uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_AVATAR, filesize,
file_id, file_name, nameLength, &error);
switch (error) {
case TOX_ERR_FILE_SEND_OK:
break;
case TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED:
qCritical() << "Friend not connected";
return;
case TOX_ERR_FILE_SEND_FRIEND_NOT_FOUND:
qCritical() << "Friend not found";
return;
case TOX_ERR_FILE_SEND_NAME_TOO_LONG:
qCritical() << "Name too long";
return;
case TOX_ERR_FILE_SEND_NULL:
qCritical() << "Send null";
return;
case TOX_ERR_FILE_SEND_TOO_MANY:
qCritical() << "Too many outgoing transfers";
return;
default:
if (!PARSE_ERR(error)) {
return;
}
@ -150,8 +136,8 @@ void CoreFile::sendFile(uint32_t friendId, QString filename, QString filePath,
Tox_Err_File_Send sendErr;
uint32_t fileNum = tox_file_send(tox, friendId, TOX_FILE_KIND_DATA, filesize,
nullptr, fileName.data(), fileName.size(), &sendErr);
if (sendErr != TOX_ERR_FILE_SEND_OK) {
qWarning() << "sendFile: Can't create the Tox file sender (" << sendErr << ")";
if (!PARSE_ERR(sendErr)) {
emit fileSendFailed(friendId, fileName.getQString());
return;
}

View File

@ -50,4 +50,6 @@ namespace ToxcoreErrorParser {
bool parseErr(Tox_Err_Set_Typing error, int line);
bool parseErr(Tox_Err_Conference_Delete error, int line);
bool parseErr(Tox_Err_Get_Port error, int line);
bool parseErr(Tox_Err_File_Send error, int line);
} // namespace ToxcoreErrorParser

View File

@ -412,3 +412,33 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_Get_Port error, int line)
qCritical() << line << "Unknown Tox_Err_Get_Port error code:" << error;
return false;
}
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send error, int line)
{
switch (error) {
case TOX_ERR_FILE_SEND_OK:
return true;
case TOX_ERR_FILE_SEND_NULL:
qCritical() << line << ": One of the arguments to the function was NULL when it was not expected.";
return false;
case TOX_ERR_FILE_SEND_FRIEND_NOT_FOUND:
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
return false;
case TOX_ERR_FILE_SEND_FRIEND_NOT_CONNECTED:
qCritical() << line << ": This client is currently not connected to the friend.";
return false;
case TOX_ERR_FILE_SEND_NAME_TOO_LONG:
qCritical() << line << ": Filename length exceeded TOX_MAX_FILENAME_LENGTH bytes.";
return false;
case TOX_ERR_FILE_SEND_TOO_MANY:
qCritical() << line << ": Too many ongoing transfers.";
return false;
}
qCritical() << line << "Unknown Tox_Err_File_Send error code:" << error;
return false;
}