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

feat(core): Add error parsing for Tox_Err_File_Control

This commit is contained in:
Anthony Bilinski 2022-03-17 23:12:36 -07:00
parent 040beae56a
commit 978bcde572
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 82 additions and 12 deletions

View File

@ -190,13 +190,15 @@ void CoreFile::pauseResumeFile(uint32_t friendId, uint32_t fileId)
emit fileTransferAccepted(*file); emit fileTransferAccepted(*file);
} }
Tox_Err_File_Control err;
if (file->pauseStatus.localPaused()) { if (file->pauseStatus.localPaused()) {
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE, tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_PAUSE,
nullptr); &err);
} else { } else {
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME,
nullptr); &err);
} }
PARSE_ERR(err);
} }
void CoreFile::cancelFileSend(uint32_t friendId, uint32_t fileId) void CoreFile::cancelFileSend(uint32_t friendId, uint32_t fileId)
@ -209,9 +211,13 @@ void CoreFile::cancelFileSend(uint32_t friendId, uint32_t fileId)
return; return;
} }
Tox_Err_File_Control err;
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, &err);
if (!PARSE_ERR(err)) {
return;
}
file->status = ToxFile::CANCELED; file->status = ToxFile::CANCELED;
emit fileTransferCancelled(*file); emit fileTransferCancelled(*file);
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFile(friendId, fileId); removeFile(friendId, fileId);
} }
@ -224,9 +230,13 @@ void CoreFile::cancelFileRecv(uint32_t friendId, uint32_t fileId)
qWarning("cancelFileRecv: No such file in queue"); qWarning("cancelFileRecv: No such file in queue");
return; return;
} }
Tox_Err_File_Control err;
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, &err);
if (!PARSE_ERR(err)) {
return;
}
file->status = ToxFile::CANCELED; file->status = ToxFile::CANCELED;
emit fileTransferCancelled(*file); emit fileTransferCancelled(*file);
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFile(friendId, fileId); removeFile(friendId, fileId);
} }
@ -239,9 +249,13 @@ void CoreFile::rejectFileRecvRequest(uint32_t friendId, uint32_t fileId)
qWarning("rejectFileRecvRequest: No such file in queue"); qWarning("rejectFileRecvRequest: No such file in queue");
return; return;
} }
Tox_Err_File_Control err;
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, &err);
if (!PARSE_ERR(err)) {
return;
}
file->status = ToxFile::CANCELED; file->status = ToxFile::CANCELED;
emit fileTransferCancelled(*file); emit fileTransferCancelled(*file);
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_CANCEL, nullptr);
removeFile(friendId, fileId); removeFile(friendId, fileId);
} }
@ -259,9 +273,13 @@ void CoreFile::acceptFileRecvRequest(uint32_t friendId, uint32_t fileId, QString
qWarning() << "acceptFileRecvRequest: Unable to open file"; qWarning() << "acceptFileRecvRequest: Unable to open file";
return; return;
} }
Tox_Err_File_Control err;
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, &err);
if (!PARSE_ERR(err)) {
return;
}
file->status = ToxFile::TRANSMITTING; file->status = ToxFile::TRANSMITTING;
emit fileTransferAccepted(*file); emit fileTransferAccepted(*file);
tox_file_control(tox, file->friendId, file->fileNum, TOX_FILE_CONTROL_RESUME, nullptr);
} }
ToxFile* CoreFile::findFile(uint32_t friendId, uint32_t fileId) ToxFile* CoreFile::findFile(uint32_t friendId, uint32_t fileId)
@ -321,7 +339,9 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI
if (!filesize) { if (!filesize) {
qDebug() << QString("Received empty avatar request %1:%2").arg(friendId).arg(fileId); qDebug() << QString("Received empty avatar request %1:%2").arg(friendId).arg(fileId);
// Avatars of size 0 means explicitely no avatar // Avatars of size 0 means explicitely no avatar
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr); Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err);
PARSE_ERR(err);
emit core->friendAvatarRemoved(core->getFriendPublicKey(friendId)); emit core->friendAvatarRemoved(core->getFriendPublicKey(friendId));
return; return;
} }
@ -329,7 +349,9 @@ void CoreFile::onFileReceiveCallback(Tox* tox, uint32_t friendId, uint32_t fileI
qWarning() << qWarning() <<
QString("Received avatar request from %1 with size %2.").arg(friendId).arg(filesize) + QString("Received avatar request from %1 with size %2.").arg(friendId).arg(filesize) +
QString(" The max size allowed for avatars is %3. Cancelling transfer.").arg(ToxClientStandards::MaxAvatarSize); QString(" The max size allowed for avatars is %3. Cancelling transfer.").arg(ToxClientStandards::MaxAvatarSize);
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr); Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err);
PARSE_ERR(err);
return; return;
} }
static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH, static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH,
@ -380,15 +402,21 @@ void CoreFile::handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept
qDebug() << QString("Received avatar request %1:%2. Rejected since it is in cache.") qDebug() << QString("Received avatar request %1:%2. Rejected since it is in cache.")
.arg(friendId) .arg(friendId)
.arg(fileId); .arg(fileId);
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr); Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err);
PARSE_ERR(err);
return; return;
} }
Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_RESUME, &err);
if (!PARSE_ERR(err)) {
return;
}
// It's an avatar and we don't have it, autoaccept the transfer // It's an avatar and we don't have it, autoaccept the transfer
qDebug() << QString("Received avatar request %1:%2. Accepted.") qDebug() << QString("Received avatar request %1:%2. Accepted.")
.arg(friendId) .arg(friendId)
.arg(fileId); .arg(fileId);
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_RESUME, nullptr);
ToxFile file{fileId, friendId, "<avatar>", "", filesize, ToxFile::RECEIVING}; ToxFile file{fileId, friendId, "<avatar>", "", filesize, ToxFile::RECEIVING};
file.fileKind = TOX_FILE_KIND_AVATAR; file.fileKind = TOX_FILE_KIND_AVATAR;
@ -499,7 +527,9 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil
ToxFile* file = coreFile->findFile(friendId, fileId); ToxFile* file = coreFile->findFile(friendId, fileId);
if (!file) { if (!file) {
qWarning("onFileRecvChunkCallback: No such file in queue"); qWarning("onFileRecvChunkCallback: No such file in queue");
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr); Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err);
PARSE_ERR(err);
return; return;
} }
@ -509,7 +539,9 @@ void CoreFile::onFileRecvChunkCallback(Tox* tox, uint32_t friendId, uint32_t fil
file->status = ToxFile::CANCELED; file->status = ToxFile::CANCELED;
emit coreFile->fileTransferCancelled(*file); emit coreFile->fileTransferCancelled(*file);
} }
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr); Tox_Err_File_Control err;
tox_file_control(tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, &err);
PARSE_ERR(err);
coreFile->removeFile(friendId, fileId); coreFile->removeFile(friendId, fileId);
return; return;
} }

View File

@ -50,6 +50,7 @@ namespace ToxcoreErrorParser {
bool parseErr(Tox_Err_Set_Typing error, int line); bool parseErr(Tox_Err_Set_Typing error, int line);
bool parseErr(Tox_Err_Conference_Delete 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_Get_Port error, int line);
bool parseErr(Tox_Err_File_Control error, int line);
bool parseErr(Tox_Err_File_Get error, int line); bool parseErr(Tox_Err_File_Get error, int line);
bool parseErr(Tox_Err_File_Send error, int line); bool parseErr(Tox_Err_File_Send error, int line);
} // namespace ToxcoreErrorParser } // namespace ToxcoreErrorParser

View File

@ -413,6 +413,43 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_Get_Port error, int line)
return false; return false;
} }
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Control error, int line)
{
switch (error) {
case TOX_ERR_FILE_CONTROL_OK:
return true;
case TOX_ERR_FILE_CONTROL_FRIEND_NOT_FOUND:
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
return false;
case TOX_ERR_FILE_CONTROL_FRIEND_NOT_CONNECTED:
qCritical() << line << ": This client is currently not connected to the friend.";
return false;
case TOX_ERR_FILE_CONTROL_NOT_FOUND:
qCritical() << line << ": No file transfer with the given file number was found for the given friend.";
return false;
case TOX_ERR_FILE_CONTROL_NOT_PAUSED:
qCritical() << line << ": A RESUME control was sent, but the file transfer is running normally.";
return false;
case TOX_ERR_FILE_CONTROL_DENIED:
qCritical() << line << ": A RESUME control was sent, but the file transfer was paused by the other party.";
return false;
case TOX_ERR_FILE_CONTROL_ALREADY_PAUSED:
qCritical() << line << ": A PAUSE control was sent, but the file transfer was already paused.";
return false;
case TOX_ERR_FILE_CONTROL_SENDQ:
qCritical() << line << ": Packet queue is full.";
}
qCritical() << line << "Unknown Tox_Err_File_Control error code:" << error;
return false;
}
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Get error, int line) bool ToxcoreErrorParser::parseErr(Tox_Err_File_Get error, int line)
{ {
switch (error) { switch (error) {