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_Send_Chunk

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

View File

@ -502,7 +502,9 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId,
qWarning("onFileDataCallback: Failed to read from file");
file->status = ToxFile::CANCELED;
emit coreFile->fileTransferCancelled(*file);
tox_file_send_chunk(tox, friendId, fileId, pos, nullptr, 0, nullptr);
Tox_Err_File_Send_Chunk err;
tox_file_send_chunk(tox, friendId, fileId, pos, nullptr, 0, &err);
PARSE_ERR(err);
coreFile->removeFile(friendId, fileId);
return;
}
@ -510,8 +512,9 @@ void CoreFile::onFileDataCallback(Tox* tox, uint32_t friendId, uint32_t fileId,
file->hashGenerator->addData(reinterpret_cast<const char*>(data.get()), length);
}
if (!tox_file_send_chunk(tox, friendId, fileId, pos, data.get(), nread, nullptr)) {
qWarning("onFileDataCallback: Failed to send data chunk");
Tox_Err_File_Send_Chunk err;
tox_file_send_chunk(tox, friendId, fileId, pos, data.get(), nread, &err);
if (!PARSE_ERR(err)) {
return;
}
if (file->fileKind != TOX_FILE_KIND_AVATAR) {

View File

@ -53,4 +53,5 @@ namespace ToxcoreErrorParser {
bool parseErr(Tox_Err_File_Control 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_Chunk error, int line);
} // namespace ToxcoreErrorParser

View File

@ -501,3 +501,45 @@ bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send error, int line)
qCritical() << line << "Unknown Tox_Err_File_Send error code:" << error;
return false;
}
bool ToxcoreErrorParser::parseErr(Tox_Err_File_Send_Chunk error, int line)
{
switch (error) {
case TOX_ERR_FILE_SEND_CHUNK_OK:
return true;
case TOX_ERR_FILE_SEND_CHUNK_NULL:
qCritical() << line << ": The length parameter was non-zero, but data was NULL.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_FOUND:
qCritical() << line << ": The friend_number passed did not designate a valid friend.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_FRIEND_NOT_CONNECTED:
qCritical() << line << ": This client is currently not connected to the friend.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_NOT_FOUND:
qCritical() << line << ": No file transfer with the given file number was found for the given friend.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_NOT_TRANSFERRING:
qCritical() << line << ": File transfer was found but isn't in a transferring state.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_INVALID_LENGTH:
qCritical() << line << ": Attempted to send more or less data than requested.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_SENDQ:
qCritical() << line << ": Packet queue is full.";
return false;
case TOX_ERR_FILE_SEND_CHUNK_WRONG_POSITION:
qCritical() << line << ": Position parameter was wrong.";
return false;
}
qCritical() << line << "Unknown Tox_Err_File_Send_Chunk error code:" << error;
return false;
}